Monday, June 10, 2013

How to run a unix command on your SAP application server


Hi Folks,
today i want to share with you how you can directly run shell commends on your application server.
Please excuse me if i speak only of unix servers. I know sap can run on windows too, but i am not interested in this kind of installation for many reasons.

So let'ìs suppose your sap systems runs on unix. (Any of the many supported unices: linux, aix, solaris whatever...)

The program you need is very very simple.

REPORT  Z_UNIX.

DATA  UNIXCMD(200) TYPE C.
DATA: BEGIN OF ITAB occurs 0,
                LINE(200),
             end of ITAB.

PARAMETERS UNIXCOMM LIKE UNIXCMD
                    DEFAULT 'ls -ls /usr/sap/trans/data' LOWER CASE.

* Executing the system commands witin ABAP.

call 'SYSTEM' id 'COMMAND' field  UNIXCOMM
       id 'TAB'   field  ITAB-*SYS*.

EDITOR-CALL FOR ITAB DISPLAY-MODE.

The explanation is very simple. Call 'system' id command runs a shell command.
It would be nice to see the correspondgin "kernel" coding. I guess they do an exec or something like this.

Fiels itab-*sys* passes the table to the kernel command.
Editor call shows the result in a nice graphical mode.

Here is its input ( for example with an ls command)









And the corresponding output:

Of course you can only run and access what the user your Application server is running as can run and access.


NOTE that with the wrong command you can destroy your systems. Don't do this at work!!! Only at home!
(Wasn't is "don't do this at home"... well ehm... :-) )