当前位置:网站首页>ABAP interview questions: how to use the System CALL interface of the ABAP programming language, direct execution ABAP server operating System's shell command?

ABAP interview questions: how to use the System CALL interface of the ABAP programming language, direct execution ABAP server operating System's shell command?

2022-08-09 13:03:00 Wang Zixi

Suppose we want to view the details of a certain file directory in the Linux system where the ABAP application server is installed. If you log in directly to the Linux Shell, use the `ls -l` command.

Example: `ls -l //bas/CGC5/src/krn/abap/runt`

In fact, we can use the CALL keyword provided by ABAP to initiate a call to the operating system shell command line directly at the ABAP application layer.The execution result of the latter is returned to the ABAP layer, so that ABAP application developers can perform some processing and develop some tools on this basis.

I wrote a simple ABAP report to wrap this call of the CALL keyword:

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

After execution, you can specify the Linux command to be executed, such as pwd, which is the command line for printing the current working path in Linux, that is, the meaning of Print Working Directory.

The result is /usr/sap/AG3/DVEBMGS54/work

Execute `ps -aux` to print the process details of the current operating system in ABAP:

For the syntax of CALL, you can check SAP official help [document](CALL, System Function Call - ABAP Keyword Documentation).

The CALL keyword is generally used for the internal implementation of the SAP system and cannot be used in the development of SAP ABAP applications.CALL will call the system function cfunc. You can specify a data object containing the function name for cfunc. This data object must be a Flat Character like type.

This function must be entered in the sapactab.h file.Modifying a function or creating a new one requires recompiling and linking the ABAP kernel.Hence the need to be able to access the C source code files.

原网站

版权声明
本文为[Wang Zixi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/221/202208091155128648.html