Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Function Module For Executing File In Other OS

Former Member
0 Likes
995

Hi,

I need to execute .sh file in SUN operating system.If there is any function module to execute?Please help me.Its very urgent.My OS is windows.

7 REPLIES 7
Read only

former_member209217
Active Contributor
0 Likes
874

Hi Satish,

Try this Function Module SXPG_COMMAND_EXECUTE( For Executing External OS Commands)

Regards,

Lakshman.

Read only

0 Likes
874

Hi Lakshman,

Please tell the use of addparam in that functional module.Anything i need to pass?

Read only

0 Likes
874

Hi Satish,

Chk this link

https://wiki.sdn.sap.com/wiki/display/Snippets/WrapperClassforexecutingExternal+Commands

Read only

0 Likes
874

Hi Satish,

The additional parameters field of the function module 'SXPG_COMMAND_EXECUTE' depends on the external system your going to call. You can pass details like server name, user name or incase of unix system, the parameter file path etc, concatenated into a single variable and pass to that parameter in the function module.

Regards,

Vik

Read only

Former Member
0 Likes
874

HI,

Try Function 'GUI_EXEC' for yopur requirement. As I've run this for DOS through SAP.

DOS Execution :

CALL FUNCTION 'GUI_EXEC'

EXPORTING

COMMAND = 'C:\ABC.BAT'.

Regds,

Anil

Read only

venkat_o
Active Contributor
0 Likes
874

Hi Sathish, <li> Use CL_GUI_FRONTEND_SERVICES->EXECUTE method to run OS applications or <li> Use GUI_EXEC function module. Thanks Venkat.O

Read only

Former Member
0 Likes
874

If the file to be executed is in another independent server.

1. First, you need to connect to that server with username, password using FM: FTP_CONNECT.

2. After logging-in successfully, execute the command using FM: FTP_COMMAND.

Here is a sample code which invokes change directory command cd /user/JOHN in remote system,

which changes present working directory (pwd) to /user/JOHN.

  • ENCRYPT PASSWORD

data : w_key type i value 26101957,

CALL 'AB_RFC_X_SCRAMBLE_STRING'

ID 'SOURCE' FIELD f_password

ID 'KEY' FIELD w_key

ID 'SCR' FIELD 'X'

ID 'DESTINATION' FIELD f_password

ID 'DSTLEN' FIELD w_pwd_len.

CALL FUNCTION 'FTP_CONNECT'

EXPORTING

USER = user

PASSWORD = password

  • ACCOUNT =

HOST = remote_server_name

RFC_DESTINATION = 'SAPFTPA'

  • GATEWAY_USER =

  • GATEWAY_PASSWORD =

  • GATEWAY_HOST =

IMPORTING

HANDLE = handle

EXCEPTIONS

NOT_CONNECTED = 1

OTHERS = 2

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

concatenate 'cd' '/user/ into command separated by space.

CALL FUNCTION 'FTP_COMMAND'

EXPORTING

HANDLE = handle

COMMAND = command

  • COMPRESS =

  • VERIFY =

  • RFC_DESTINATION = 'SAPFTPA'

  • IMPORTING

  • FILESIZE =

  • FILEDATE =

  • FILETIME =

TABLES

DATA = result

EXCEPTIONS

TCPIP_ERROR = 1

COMMAND_ERROR = 2

DATA_ERROR = 3

OTHERS = 4

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.