Working with Shell Scripts in SAP ABAP Environment

For a beginner in SAP, it might sound strange when I say that we can use Unix Shell Scripts in SAP ECC. Indeed, you read it right! Working with Shell Scripts in SAP ABAP Environment allows us to leverage the benefits of shell scripts within our own SAP landscape. This integration can significantly enhance our ability to automate and manage tasks effectively.

Allow us to take an instance of putting a document at a FTP area utilizing a Shell Content.

Note : We can utilize the standard Capability Modules like FTP_R3_TO_SERVER and a lot more FTP FMs. In any case, we need to exhibit Shell Content here, accordingly we will utilize this situation to become familiar with the usage of Shell Contents in this article.

Steps to Follow:

  1. Get a UNIX Expert to Write a Script for you and upload it in AL11 with an Extension ‘.SH’.

We have composed a content referencing the objective, certifications to get to the envelope on objective FTP area and a few orders to move the document. Then we saved it in ‘/TMP/ENCL’ registry 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
  1. Create an external Operating System Command

We can make an outer Working Framework Order utilizing SM69 T-code. Click on Make button.

external Operating System Command using SM69 T-code

Give Working framework name as AIX for UNIX.

unix file in sap

Enter the area of Shell Content in Working Framework Order field (as featured in yellow beneath).

shell programming in sap
  1. Get back to Program in ABAP

We can utilize Capability Module ‘SXPG_COMMAND_EXECUTE‘ to execute an order made from SM69.

Following is a straightforward Example Report for our utilization case:

REPORT Elearning.co.in

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.

Bingo!!

We have effectively made a report which calls an operating system Order and execute a Unix Content. The above report would peruse the AL11 document in the Application Server which thusly would execute the orders written in it. You can compose anything in the content in AL11 document according to your task need. In another client prerequisite, we utilize the Shell Content to compose document from FTP server to Drain Application Server.

Trust you preferred this article. Cheerful Learning.

If you have any questions, please feel free to leave them in the comments section below. I will personally respond to all your queries, especially those related to working with shell scripts in the SAP ABAP environment.

YOU MAY LIKE THIS

ABAP on SAP HANA. Part III. Debugging in ADT

Power of Parallel Cursor in SAP ABAP

OData in SAP ABAP: Streamlining Data Exchange and Integration

Source link

  • Related Posts

    Handle the Handle Classes correctly

    Let’s delve into the Handle the Handle Classes correctly. Gone are the days where we had the freedom to have import boundaries as tables, designs or single fields. SAP has…

    Steps to add custom Tab in standard MIRO item screen using BADI MRM_ITEM_CUSTFIELDS

    Steps to add custom Tab in standard MIRO item screen using BADI MRM_ITEM_CUSTFIELDS can be utilized to upgrade the standard MIRO detail screen and add the new custom Tab and…

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    You Missed

    Handle the Handle Classes correctly

    • By Varad
    • March 30, 2025
    • 5 views
    Handle the Handle Classes correctly

    Steps to add custom Tab in standard MIRO item screen using BADI MRM_ITEM_CUSTFIELDS

    • By Varad
    • March 29, 2025
    • 21 views
    Steps to add custom Tab in standard MIRO item screen using BADI MRM_ITEM_CUSTFIELDS

    Add custom fields in standard MIRO header screen through BADI_FDCB_SUBBAS01

    • By Varad
    • March 28, 2025
    • 17 views
    Add custom fields in standard MIRO header screen through BADI_FDCB_SUBBAS01

    Steps to stop debugger at ELM BADI CRM_MKTLIST_BADI from Web UI Screen

    • By Varad
    • March 27, 2025
    • 30 views
    Steps to stop debugger at ELM BADI CRM_MKTLIST_BADI from Web UI Screen

    Steps to stop debugger at ELM BADI CRM_MKTLIST_BADI from Web UI Screen

    • By Varad
    • March 26, 2025
    • 33 views
    Steps to stop debugger at ELM BADI CRM_MKTLIST_BADI from Web UI Screen

    How to find BAdIs ?

    • By Varad
    • March 25, 2025
    • 41 views
    How to find BAdIs ?