Execute system command from ABAP

Sometimes it’s useful to call the operating system command from SAP. There are many ways you can do it (regarding authorizations). The standard way is to define a system command in the transaction SM49 or SM69 and call it from those transactions or with function module SXPG_CALL_SYSTEM or other similar SXPG*.

There are many examples of system call in the Internet using the old-style reference on the output internal table (tabl-*sys*), but I prefer to use something less cryptic:

REPORT ztest.

DATA:
  lv_command(50) TYPE c,
  lv_line(150)   TYPE c,
  lt_tab         LIKE TABLE OF lv_line.

lv_command = 'ls -l'.
CALL 'SYSTEM' ID 'COMMAND' FIELD lv_command
              ID 'TAB'     FIELD lt_tab.
 
LOOP AT lt_tab INTO lv_line.
  WRITE: / lv_line.
ENDLOOP.
Scroll to Top