Calling Unix Shell Scripts From ABAP

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.

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


    Requires Free Membership to View

: 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. ------------------------------------

This was first published in October 2001

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.