For those ABAPers who start their programming life with C, they might be curious about how the ABAP keyword are implemented by C in ABAP Kernel, at least it holds true for me. This blog explains a small tip about how you can find the corresponding C implementation.
For example I would like to figure out how keyword ASSERT is implemented.
And this tips starts from the code in that blog.
Write a report with only one line:
REPORT ZREG.
ASSERT 1 = 0.
Execute the report, and go to ST22 to find the detail position which assertion failure is reported. In my server it is //bas/CGCS/src/krn/abap/runt/abassert.c
I wrote a small report to view the source code of this file.
REPORT zlinux.
PARAMETERS: command TYPE string LOWER CASE DEFAULT 'ls -l //bas/CGC5/src/krn/abap/runt'.
DATA: commtext(120) ,
      itab(255)     OCCURS 10 WITH HEADER LINE,
      lv_folder     TYPE string.

START-OF-SELECTION.

  PERFORM init.
  CALL 'SYSTEM' ID 'COMMAND' FIELD commtext ID 'TAB' FIELD itab[].
  LOOP AT itab ASSIGNING FIELD-SYMBOL(<line>).

    FIND REGEX '^.*\.c|^.*\.cpp|^.*\.h' IN <line>.
    IF sy-subrc = 0.
      WRITE: / <line> COLOR COL_NEGATIVE.
      DATA(lv_line) = CONV char255( <line> ).
      HIDE lv_line.
    ELSE.
      WRITE: / <line>.
    ENDIF.
  ENDLOOP.

AT LINE-SELECTION.
   PERFORM display_source.

FORM display_source.
  SPLIT lv_line AT space INTO TABLE DATA(lt_file).
  DATA(index) = lines( lt_file ).
  DATA(lv_file_name) = lv_folder && '/' && lt_file[ index ].
  DATA(lv_op) = |cat { lv_file_name } |.
  SUBMIT zlinux WITH command EQ lv_op.
ENDFORM.

FORM init.
  commtext = command.
  SPLIT commtext AT space INTO TABLE DATA(lt_table).
  CHECK lines( lt_table ) = 3.
  lv_folder = lt_table[ 3 ].
ENDFORM.

You have two approaches to use this tool.

1. Use command “ls -l <folder name>”. In my example, folder name could be found from ST22 information, which is //bas/CGC5/src/krn/abap/runt
Execute the report, and the ls – l result will be displayed there.
Then find the abassert.c, double click it:
Then the whole source code of this file is displayed, you can download it locally and review it with your favorite source code view tool.
2. or you can directly use cat command plus the absolute path of the file in Linux system. In my example, it is cat //bas/CGC5/src/krn/abap/runt/abassert.c:
Now still the source code could be displayed:
By the way, you can learn some useful tips in the comment of abassert.c file, for example this profile parameter: abap/aab_log_field_size_limit
You can open it via tcode RZ11 and read detail document there.
Enjoy!
To report this post you need to login first.

4 Comments

You must be Logged on to comment or reply to a post.

  1. Peter Inotai

    Hi Jerry,

    Very interesting trick (as always). Thanks for sharing it.

    BTW ACID was a much cooler name as Checkpoint groups. It’s a pity, that it was changed.

    Best regards,

    Peter

    (1) 
    1. Jerry Wang Post author

      Hi Peter,

      Same here 🙂 At the first sight of “ACID”, Atomicity, Consistency, Isolation, Durability come to my mind…

      Best regards,

      Jerry

      (1) 

Leave a Reply