10-28-2005 6:37 AM
Hi..
The requirement is as follows :
SAP drops a file into a folder and triggers a UNIX script using a File Port partner destination.
Unix script will perform a secure copy to the Webmethods server. If a Unix script error occurs, an Rfc function will be called to send an error notification to a particular contact person.
Can anyone help me how is the unix script triggered from SAP ?
Thanks in advance
10-28-2005 7:28 AM
Hi Sumi,
You should create an external OS command (transaction SM59) which starts the script. You can then execute this command from within you ABAP program using FM SXPG_COMMAND_EXECUTE.
Regards,
John.
09-19-2006 6:25 PM
Hi John,
I have a similar requirement. I read ur solution. I am not able to understand creating external OS command in SM59. Can please elaborate?
Thanks,
Umesh
09-19-2006 9:04 PM
You can execute this sample code:
Data: unix_cmd(50).
unix_cmd = 'chmod 664 /sapdata/DEV/home/travelers'.
translate unix_cmd to lower case.
call 'SYSTEM' id 'COMMAND' field unix_cmd.
write: / sy-subrc.
OR
***********************************************************************
Create and run a UNIX command programmatically
***********************************************************************
The destination must be set up and configured from tcode SM59
see note OSS 63930
*
rfcexec, this service must be started from UNIX
UX syntax to start service:
rfcexec -aUNIX_COMMAND -g sap01 -x sapgw00 &
*
rfcexec - program, /sapmnt/DEV/exe
UNIX_COMMAND - program ID from SM59, case sensitive
sap01 - AP_Gateway_hostname
sapgw00 - Gateway_Service
*
Transaction SMGW, monitor the gateway (Goto/Logged on clients)
*
*Number LU name TP Name Syst.type Host name Host address
*
0 sap01 sapgw00 LOCAL_R3 sap01 10.1.193.50
233 sap01 UNIX_COMMAND REGISTER_TP sap01 10.1.193.50
***********************************************************************
Could replace this unsupported SAP syntax, Call 'SYSTEM'
*
*data: begin of tabl occurs 0,
line(200),
*end of tabl.
*call 'SYSTEM' id 'COMMAND' field comm
id 'TAB' field tabl-sys.
***********************************************************************
data: command(256).
data : begin of ret occurs 10, " results of unix command
text(80),
end of ret .
***********************************************************************
data: i_connected_systems type table of gwy_system.
data: w_connected_systems type gwy_system.
data: w_message(80).
*
parameter: p_junk(4) default 'Junk'.
***********************************************************************
*
*
start-of-selection.
*
call function 'GWY_READ_CONNECTED_SYSTEMS'
EXPORTING
GWHOST =
GWSERV =
DISCONNECT =
tables
connected_systems = i_connected_systems
EXCEPTIONS
GWY_UNKNOWN_OPCODE = 1
GWY_COMMUNICATION_FAILURE = 2
GWY_GET_TAB_FAILED = 3
GWY_NEWLINE_FAILED = 4
GWY_TABLEN_TOO_SHORT = 5
GWY_GET_OPCODE_FAILED = 6
GWY_GET_GWHOST_FAILED = 7
GWY_GET_GWSERV_FAILED = 8
GWY_MONITOR_DISABLED = 9
OTHERS = 10
.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
read table i_connected_systems into w_connected_systems
with key tpname = 'UNIX_COMMAND'.
if sy-subrc ne 0.
perform display_error_messages.
stop.
endif.
***********************************************************************
*COMMAND = 'ls '. " command
*COMMAND = 'ls -lt'. " command, newest at top
command = 'ls -osra'.
call function 'RFC_REMOTE_PIPE'
DESTINATION 'SERVER_EXEC'
destination 'UNIX_COMMAND'
exporting
command = command
read = 'X'
tables
pipedata = ret.
loop at ret.
write ret.
endloop.
*
*
end-of-selection.
*
&----
*& Form Display_error_messages
&----
form display_error_messages .
data: begin of listtab occurs 0,
field(80),
end of listtab.
listtab-field = 'Program UNIX_COMMAND is not registered.'.
append listtab.
listtab-field = 'Tell Basis person about the error'.
append listtab.
listtab-field = ' '.
append listtab.
listtab-field = 'UX syntax to start service: '.
append listtab.
listtab-field = 'rfcexec -aUNIX_COMMAND -g sap01 -x sapgw00'.
append listtab.
listtab-field = ' '.
append listtab.
listtab-field = 'Program aborted,'.
listtab-field+19 = sy-cprog.
append listtab.
call function 'POPUP_WITH_TABLE_DISPLAY_OK'
exporting
endpos_col = 70
endpos_row = 20
startpos_col = 10
startpos_row = 10
titletext = 'Registered program error'
IMPORTING
CHOISE =
tables
valuetab = listtab
EXCEPTIONS
BREAK_OFF = 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.
endform. " Display_error_messages
Bruce
09-19-2006 9:08 PM
Hi Sumi,
You can also go through this PDF file.
http://esnips.com/doc/e42b73d3-ad7c-4549-9c4a-635cf2b12cfe/calling-UNIX-commands-in-ABAP.pdf
Regards,
SP.
09-19-2006 9:16 PM
Hi,
Go through the link for sample programs...
http://www.guidancetech.com/people/holland/sap/abap/
Regards,
Azaz Ali.
09-19-2006 10:27 PM
Hey now, if you're gonna link to my site (guidancetech.com), I should at least get some of the SDN points!
Most of those sample programs were things I found on the 'net back in the mid 1990's so are probably very outdated, although they may still work. Use them at your own risk...
One of these days I need to clean those pages up.
Rich