I know it sounds strange to a novice SAP user, however SAP ECC allows us to use Unix Shell Scripts. You did read it correctly, yes! We may enjoy the advantages of Shell Scripts within the SAP environment.
Let’s look at an example of utilizing a Shell Script to upload a file to an FTP site.
Note: Among many other FTP FMs, we can utilize the standard Function Modules, such as FTP_R3_TO_SERVER. However, since we’re here to demonstrate Shell Script, we’ll use this scenario to learn how to use Shell Scripts in this post.
Steps to Follow:
- Get a UNIX Expert to Write a Script for you and upload it in AL11 with an Extension ‘.SH’.
We have written a script mentioning the destination, credentials to access the folder on destination FTP location and some commands to transfer the file. Then we saved it in ‘/TMP/ENCL‘ directory on AL11 with the name ‘FTP.SH‘.
Following is an example of the script:
Dir="/test/output/" Dest=/TEST/ HOST=999.99.999.99 #IP of destination server USER=user PASSWD=pwd cd $Dir ftp -n -i -v $HOST <<END_SCRIPT quote USER $USER quote PASS $PASSWD bin #hash prompt cd $Dest mput $1 quit END_SCRIPT
Make an external command for the operating system
Using the SM69 T-code, we can generate an external operating system command. Press the “Create” button.

For UNIX, specify the operating system name as AIX.
Enter the location of Shell Script in Operating System Command field (as highlighted in yellow below).

In the Operating System Command field, type the Shell Script’s location (as noted in yellow below).
Return to the ABAP program.
To run a command generated from SM69, we can utilize Function Module “SXPG_COMMAND_EXECUTE.”
Here is a straightforward Sample Report for our use case:
REPORT ztechnicalgyanguru_ftp_ss.
DATA : lv_file TYPE btcxpgpar VALUE '/tmp/demo.txt'. " File to be transferred
CONSTANTS : c_ftp TYPE sxpgcolist-name VALUE 'ZFTP_TEST'. " Command name
***Move the Files to the shared folder
CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
EXPORTING
commandname = c_ftp
additional_parameters = lv_file
stdout = 'X'
stderr = 'X'
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
wrong_asynchronous_parameters = 12
cant_enq_tbtco_entry = 13
jobcount_generation_error = 14
OTHERS = 15.
IF sy-subrc <> 0.
* Implement suitable error handling here
MESSAGE 'Error Occurred' TYPE 'E'.
EXIT.
ELSE.
MESSAGE 'FTP successful' TYPE 'S'.
ENDIF.
Success!
We have successfully produced a report that runs a Unix script and issues an OS command. The aforementioned report would read the AL11 file from the App Server, causing the commands within to be executed. You can modify the script in the AL11 file to suit the needs of your project.We use the Shell Script to write a file from an FTP server to the SAP Application Server in order to fulfill another client demand.
I hope this essay was enjoyable to you. Happy Acquiring.
In the comment section below, feel free to ask any questions you may have. I would be happy to answer any questions you may have.







