Tag Archives: abap

ABAP – UUIDs and random strings

If you want to generate a random string in ABAP, you can use the following FM where you can specify the length of the generated random string: CRR_GET_RANDOM_STRING

If you want a random and unique string, then you need to use the UUID generation class cl_system_uuid which can be accessed in either instance or static form. See the API for the UUID generation document attached to SAP Note 935047 – Creating and using GUIDs (UUIDs) or click on the download below.

 

Download – UsingTheUUIDABAPInterface2.pdf – 30.0 kB – 399   downloads

Download – SAPNote0000935047_CreateUseUUIDs.pdf – 38.1 kB – 372   downloads

 

ABAP Substract 2 timestamps

A Google search turns up this recommendation: http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/840ad679-0601-0010-cd8e-9989fd650822#q-8: use the class CL_ABAP_TSTMP. You can also see an example of how to use the class in this thread: http://scn.sap.com/thread/85476.

 cl_abap_tstmp=>systemtstmp_syst2utc(
    exporting
      syst_date = <wa_joblist>-strtdate
      syst_time = <wa_joblist>-strttime
    importing
      utc_tstmp = start_stamp ).

  cl_abap_tstmp=>systemtstmp_syst2utc(
    exporting
      syst_date = sy-datum
      syst_time = sy-uzeit
    importing
      utc_tstmp = now_stamp ).

  seconds = cl_abap_tstmp=>subtract(
      tstmp1 = now_stamp
      tstmp2 = start_stamp ).
See also: http://stackoverflow.com/questions/10539133/difference-between-2-timestamps

Debug SAP after popup – dialog box

So you know how to debug and all is going well until a pop-up (dialog box) appears and exits your debugging session. There is a simple trick to switch on debugging once you reach a pop-up, proceed as follows:

Create a TXT file and save it on your desktop with the following command:

[Function]
Command=/H
Type=SystemCommand

Then if you want to activate debugging on a pop-up/dialog box, simply drag and drop the TXT file from your desktop onto the pop-up/dialog box in SAP. Next time you press enter you will be back in your debugging session. Happiness.

FM to modify DTP filters

The article: Three Ways to Dynamically Update “Data Transfer Process” Filter Values describes different methods to determine DTP filters dynamically. In particular there is a method that sets the DTP in change mode, modifies the DTP filter then reactivates the DTP.

You can download the code of the function here in Saplink format.
Download – FUGR_ZBW_CHANGE_DTP_FILTERS.slnk – 9.8 kB – 433   downloads

Locate the PSA for a Data Source

Business scenario:
For a given BW master data object, I needed to identify deletions that take place in the source system. However for this particular object, the data source does not provide you with a deletion flag. Instead, the object is simply removed from the source tables.

psa

I therefore created a transformation in BW that flags as ‘deleted’ those master data records that do not appear any more in the PSA table of the daily FULL load.

The transformation i created is a loop-back transformation (the source and target of the transformation are the same object). In the source routine, the PSA table of the objects data source is checked.

To identify the PSA table dynamically I used the functions described in the Following SDN Article. (If you use SAPLINK, the report described in the article is available for download below.
You can download the code of the function here in Saplink format.
Download – PROG_ZBW_IDENTIFY_PSA.slnk – 5.2 kB – 294   downloads

See also SAP FM ZAIB2_PSA_TAB_AND_REQ_GET returns lots of info (PSA table, last request et al)

Some information on how to access PSA data:
When the system detects an incompatible change to the transfer structure, a new version of the PSA, meaning a new PSA table, is created. Data is written to the new table when the next request is updated.

The original table remains unchanged and is given a version. You can continue to use all of the PSA functions for each request that was written to the old table.
Data is read from a PSA table in the appropriate format.

1.  If the request was written to the PSA table before the transfer structure was changed, the system uses the format that the transfer structure had before the change.

2.  If the request was been written to the PSA table after the transfer structure was changed, the system uses the format that the transfer structure has after the changed

ABAP Unit Testing

If you want to start using ABAP Unit Testing, the links below will help you. They were useful to me when I started experimenting it.

 

ABAP unit tests enable writing and running white box tests during the development of complex BW transformation rules and routines. This How-To document shows you the tools you need to develop BW transformations according to a test-driven paradigm. Step by step, we describe a prototype implementation of an ABAP unit test for a selected BW transformation.