Function ABAP4_CALL_TRANSACTION will attempt to start an SAP transaction in a new window. It will work only if the maximum number of user sessions is not reached yet. The call should be done with addition “STARTING NEW TASK” and DESTINATION ‘NONE’. You can check the number of currently open sessions/windows before with the function TH_USER_INFO.
January 29, 2007
January 26, 2007
If your program is running in a background, you can detect this by checking the system variable SY-BATCH. But if you want more information, there are some functions that are useful when working with background jobs:
GET_JOB_RUNTIME_INFO – FM to request the parameters of current job (if your program is running currently in background)
And as always, you can work with the database tables directly. Two of them, TBTCO (job headers) and TBTCP (job steps) are a good starting point.
January 24, 2007
One of common questions on SAP-related forums is how to get the last day of given month. While there are many functions that you can use, why not to define a simple macro?
* Macro to get the last day of month DEFINE TO_LAST_DAY. &1+6(2) = '01'. &1 = &1 + 31. &1+6(2) = '01'. &1 = &1 - 1. END-OF-DEFINITION.
Use it like that:
data: lf_date type d. lf_date = sy-datum. to_last_day lf_date.
January 23, 2007
I never had a need to work with random numbers, but this is being asked periodically on SAP-related forums. Functions RANDOM_C and RANDOM_I4 will return a random number. If you need a unique string (for example, to use in a table key), use the function GUID_CREATE. I used this one when I wanted to have a unique key for a log table that is being filled by many instances of my ABAP program running in parallel and I did not want to use the SAP’s number ranges feature.
January 18, 2007
Transaction STERM helps in translating and browsing the terminology database. If you are online, you can always browse through SAP terminology on SAP Help site. But if you want to use the SAP glossary without being connected to the system (for example, at your home computer), use the glossary download program: GLOS_DOWNLOAD_HTML. You can learn SAP terms during sleepless nights then…
January 16, 2007
Function MD_STOCK_REQUIREMENTS_LIST_API will return a list, that is normally shown in the transaction MD04 in interactive mode. To check for specific planning elements, you should know their requirements type. Those can be found in the ABAP include program MM61XVAL. The descriptions are in German, but I guess those can be translated in the transaction STERM.
In the characteristics value table AUSP some values can be stored as floating point numbers. If you want to output them in a more readable way, not like xxxx.xx e-xx, you can use the function CTCV_PREPARE_VALUES_TO_DISPLAY. NOTE: You should call CTCV_INIT_USER_DATA first to initialise some internal stuff.
January 14, 2007
Suppose you need to distribute some quantity evenly in a given time period (like a week). SAP doesn that for you in standard transactions. For example, when you create planned independent requirements (tcode MD61), you can enter the data in week buckets and then ask SAP to split the numbers into smaller day buckets. If you want to do this yourself in an ABAP program, and you don’t want to involve complex logic with rounding and plant calenders, use the function REQUIREMENTS_SPLITTING.
January 13, 2007
With ABAP, you can do simple date calculations. If you need some advanced things like adding a month (not simple 30 days) to a date, SAP provides many function modules to do the job. Here’s my list of ABAP date functions, their names usually explain what they do:
HOLIDAY_GET – holidays list for a plant
L_MC_TIME_DIFFERENCE – Calculate time difference in minutes
WEEK_GET_FIRST_DAY – convert YYYYWW to date
January 11, 2007
If you have several SAP application servers in a system, there may be a need to get a list of them. For example, you have a requirement to run an ABAP program on a particular server (sometimes it makes sense, like for server statistics). Following function will help:
TH_SERVER_LIST – returns a list in a table
TH_DISPLAY_SERVER_LIST – interactive display. You can use this one, if transactions like SM04/SM50/SM51 don’t work for you.