Category: ABAP

Useful ABAP code snippets that can be used in real life projects.

How to Run ABAP Program in Background Manually?

Sometimes your program may contain logic that must run long time. In such case, you can’t easily run it by pressing ‘Execute’ program, because SAP has defined maximum number of seconds that is able to run any programs this way (it’s called foreground processing). In such case, you must execute the program differently. You have...

Hello World! in ABAP for SAP Developers

Do you want to create your first ABAP program? Watch this video ” Hello World in ABAP for SAP Developers” and learn it by yourself. If you need a system, where you can practice your ABAP knowledge, download instructions on how to install your free local SAP system here: http://abapacademy.com/howtoinstallsaptrial/

How to trigger DATA_CHANGED event in CL_GUI_ALV_GRID

If you have problem getting changed data in ALV from DATA_CHANGED event, you must do the following:

Get class or interface definition information

Get information of class definiton: SEO_CLASS_TYPEINFO_GET Get information of interface definiton: SEO_INTERFACE_TYPEINFO_GET Get method definiton: SEO_METHOD_SIGNATURE_GET

Exit screen when obligatory fields are not filled

Define function button in GUI status with functional type ‘E’ – Exit command. In Process after input call module at exit command as follows: PROCESS AFTER INPUT.MODULE cancel AT EXIT-COMMAND. And implement module: MODULE cancel INPUT.* Just leave the screen without checking any obligatory fields  LEAVE TO SCREEN 0.ENDMODULE. ” CANCEL_POPUP INPUT

Dynamic SORT of dynamic internal table

Use the following example in your program: * Dynamically sort data using table keyDATA: ls_sort_key_field TYPE abap_sortorder. DATA: lt_sort_key_field TYPE abap_sortorder_tab.LOOP AT it_key INTO ls_key.  ls_sort_key_field-name = ls_key-fieldname.  APPEND ls_sort_key_field TO lt_sort_key_field.ENDLOOP.TRY.  SORT BY (lt_sort_key_field).   CATCH cx_sy_dyn_table_ill_comp_val.*    Unable to process dynamic sort ENDTRY.

Dynamic call FOR ALL ENTRIES

How to dynamically call FOR ALL ENTRIES DATA: lt_table TYPE STANDARD TABLE OF fieldname. CONCATENATE lv_key_field ‘= lt_table-table_line’   INTO lv_where SEPARATED BY space.   APPEND lv_where TO lt_where. SELECT fieldname   FROM (lv_table)   INTO TABLE lt_output   FOR ALL ENTRIES IN lt_table   WHERE (lt_where).

Dump CX_RSR_X_MESSAGE during 3.x load into InfoCube

Problem During 3.x load into InfoCube (DataSource -> PSA -> InfoCube), loading status stays in the yellow status. Looking into ST22, the following short dump comes up with the exception CX_RSR_X_MESSAGE. Diagnosis The data update was not finished. A short dump has probably been logged in BI. This provides information about the error. System Response “Caller...

How to debug dynamically called program in background?

There might be a problem when you need to debug such a program, because you never know, when your code will be called.Here is the trick:     DATA: lv_counter TYPE i. *   Call neverending loop in your code    WHILE lv_counter = 0.           “this will stop, when you change lv_counter            “to s/thing else in debugger    ...

How to get database size in DB6 using ABAP

After long research of searching function modules,... here is the example:      DATA lt_db6 TYPE STANDARD TABLE OF db6pmdb02. FIELD-SYMBOLS: <ls_db6> LIKE LINE OF lt_db6.  CALL FUNCTION 'DB6_HIS_OVERVIEW'* EXPORTING* CONNECTION = TABLES it_db6pmdb02 = lt_db6 EXCEPTIONS no_history_found = 1 invalid_parameter_set = 2 adbc_error = 3 system_error = 4 OTHERS = 5.  READ TABLE lt_db6...