Wednesday, July 13, 2016

How to trigger background job in SAP system from external system


This blog explains the procedure to trigger a background job in SAP system from a third-party system using  shell script(FTP script).

 

 

Brief about the procedure:

 

I am going to illustrate a scenario in which a third party system uses FTP to place file in SAP host and requires to trigger a background job in SAP system after placing the file in SAP host..

 

 

As shown in below diagram the process can be summarized in three steps

  1. You place the file in SAP host using FTP login
  2. You use SSH login to trigger the SAP event in SAP host
  3. The event triggers the Background job in SAP system. You must have defined an event based periodic background job in SAP system



  1. EXT_USER is the OS user id in the external host (third party host) with which the FTP script is running.
  2. SAP_EXT is the OS user id created in SAP host for allowing the third party host to access SAP host to place file and execute sapevt.
     
     
    In typical cases, the third party host uses FTP script to place file in SAP host. So you need add step 2 in your script. After you have added the step 2 in your FTP script, your FTP script will be able to trigger SAP event in SAP system and consequently trigger the background job in SAP system.
     
     
     
    In detail explanation:-
     
    (a)SAP host:
     
    Create a user defined event in SAP system. The event will be used to start the background job. You can create the event using  t-code SM62.
     
    Create the event based background job in SAP system. (SM36/SM37) . Use the event crated in above step in the background job
     
    Create local profile for SAPEVT  executable in SAP system. The profile must contain the values for rdisp/mshost and rdisp/msserv. The profile can be named as sapevt.pfl and placed in /usr/sap//SYS/profile directory in SAP system.
                 Ex.
                       rdisp/mshost = saphost
                       rdisp/msserv = sapmsQAS
     
    Create a user id at OS level on SAP host(ex. SAP_EXT) .Ensure that the user id has executable access to the sapevt excutable located in /usr/sap//SYS/exe/run directory and the local profile created for sapevt  /usr/sap//SYS/profile/sapevt.pfl as well. This user id will be used by third party system for placing files in SAP host and executing sapevet in SAP host
       
    Share the command to be executed from the FTP script (shell script) with the third party application team. The command can be executed on SAP host from the third party system with some remote execution utility(ex. ssh).
             
             Ex.  /usr/sap/QAS/SYS/exe/run/sapevt  EVENT_NAME pf=/usr/sap/QAS/SYS/profile/sapevt.pfl
     
     
    (b)External host:
     
    Password less authentication mechanism must be set up between the OS user account of external host(EXT_USER) and the OS user account of SAP host(SAP_EXT).
     

This is often done by generating  a personal private/public key pair with the help of ssh-keygen command. The public key is then copied onto a remote systems' .ssh/authorized_keys file. Now SSH to the remote systems account is possible without the use of a password. You need to ask your unix team to perform this set up for you.

 

Once a password less authentication is set up, as shown in the diagram EXT_USER account on external host can do a password less logon to SAP_EXT user on sap host.

 

Please note that password less authentication to SAP_EXT user on SAP host is only possible from EXT_USER account of external host. So the password less logon is not possible from any other account of the same host or any other host. So this method of setting a password less authentication is secure.

 

 

Ouput:

 

Shell script executed in third party system to place file and trigger event:


 

Background job executed in SAP system: