Script for triggering SAP job if file pattern does not exist

Discussion created by Sreekanth_8927 on May 3, 2017
Latest reply on May 3, 2017 by Wolfgang_Brueckler_1288
Hello All,

We have requirement to trigger an SAP Job if particular file pattern does not exist in the file path. This SAP job creates an file with one pattern, later the created file is send to another system and archived.

Setup is like this, we are planning to have an Unix event to search for a file with specific pattern in directory,  if  file does not exists, it will trigger the Job plan that contains SAP job (creates file), send job (sends created file to other system), archive job (archives once the file is sent).

In case there is a file available with specific pattern in the directory then the unix event has to block the work flow and send an notification.

In Unix event, I pass the following variables in Variables & Prompts :

&BLOCK_NOTIFY_WORKFLOW# -- notification if the workflow is blocked
&HOST_AGENT_NAME#  -- host agent that triggers
&JOBPLAN# -- Subsequent job plan that is started 
&LOGIN_OBJ# -- login obj that is used to trigger the event
&MAIL_NOTIFICATION_UC4# -- notification email  
&UC4RUNID# -- 
&ZFILE_PATTERN_INPUT# -- File pattern to be checked in Directory
&ZFILE_PATH_OUTBOX# -- Directory path,

In process tab,  I attach an Include that contains.


!**** variables to trigger OS job failure *** !!
:SET &JOBNAME# = sys_act_me_name()
!******************************************************************* !!


!Remember process starter
!put it also in variables & prompts to make it accessible by childs
:SET &ZPROCESS_STARTER# = sys_act_me_name()

! Print the variable values for this job run

:PRINT "Job Run ID      : &EVENT_RUNID#"
:PRINT "Outbox Path      : &ZFILE_PATH_OUBOX#"
:PRINT "Archive Path    : &ZFILE_PATH_ARCHIVE#"
:PRINT "Search Pattern  : &ZFILE_PATTERN_INPUT#"
:PRINT "Temp Variable   : &TEMP_VAR_NAME#"

! Check if the Out folder is empty or not
! Block or cancel the event if the out folder is not empty

! Processing logic if Out folder is empty


:            PRINT "File to be processed : &FILENAME#"

! Check if only one file exist in out folder
:                IF &FILECOUNT# = 1

! Activate the Main job plan to process 1 SAP jobs, send job and the archive job

:                  PRINT "JOBPLAN return code: &JOBPLANRC#"
:                  IF &JOBPLANRC# >= 1900
:                    PRINT "File Processing Completed Successfully. Ready for Next Run"
:                  ELSE
:                      IF &JOBPLANRC# = 1850 or 1851
:                         PRINT "Workflow was cancelled, no notification"
:                  ELSE
!                   < INCLUDE MAIN> and halt event with notification
:                    set &RET# = activate_uc_object(&BLOCK_NOTIFY_WORKFLOW#, WAIT,,,,PASS_VALUES)
:                      ENDIF
:                  ENDIF
:                ENDIF
!:          ENDPROCESS


I have the written the Include script for send and archive, it works fine
But I am missing the logic somewhere for Unix file check. I need experts help in correcting the above mentioned script.

Request experts to help me in fixing it.