Calling Unix Shell Scripts From ABAP
Unix Shell scripts along with ABAP can be used to perform many tasks.
Unix Shell scripts along with ABAP can be used to perform many tasks. These can be used for sending internet mail w/o using SAP Connect, archiving files, passing data from one system to another, etc.
The following example demonstrates how to use shell script for moving a file from one folder to another folder. This can be used for archiving the processed files.
Requirement : SAP installed on Unix or its clones. SAP version 4.0 or above. Unix Setup to be done by Unix Admin (1) Create a folder under unix Eg: /home/ABAP/scripts/ Make sure this folder has Read Write and Execute permissions.(Mode 777) (2) Create a file Archive_file.sh in Unix using any editor. (2) Type mv $1 $2 in the file. Make you type the command as shown. (3)Save it. (4) Make sure the file has read write execute permissions (Mode 777) SAP Configuration (1) Run transaction SM69 (2) Hit F5 and then Hit F6 (3) Enter Command Name : ZSHELL (4) Operating System will default to Unix or HP-UX etc. (5)Enter Operating System Command : sh (6)Additional Parameters allowed : X (7) Save it. ABAP Code ---------------------------------------- report zsrchsap. *-This is a demo report for Search Sap *-Author : Sandeep Kulkarni *-Date : 09/20/2001 parameters : p_sfile(60) lower case "File to be moved "Eg : /home/in/SFILE1.txt p_dfile(60) lower case. "File's Destination "Eg: /home/archive/SFILE1.txt data : t_btcxpm like btcxpm occurs 0, p_addparam like sxpgcolist-parameters. concatenate '/home/ABAP/scripts/Archive_file.sh' p_sfile p_dfile into p_addparam separated by space. refresh t_btcxpm. clear t_btcxpm. call function 'SXPG_CALL_SYSTEM' exporting commandname = 'ZSHELL' additional_parameters = p_addparam tables exec_protocol = t_btcxpm exceptions no_permission = 1 command_not_found = 2 parameters_too_long = 3 security_risk = 4 wrong_check_call_interface = 5 program_start_error = 6 program_termination_error = 7 x_error = 8 parameter_expected = 9 too_many_parameters = 10 illegal_command = 11 others = 12. if sy-subrc = 0. write : / 'File',p_sfile,'moved to',p_dfile. else. write : / 'Error Occured'. endif. ------------------------------------