Sreekanth_8927

Script for triggering SAP job if file pattern does not exist.

Discussion created by Sreekanth_8927 on May 3, 2017
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.

:SET &EVENT_RUNID# = SYS_ACT_ME_NR()


!**** variables to trigger OS job failure *** !!
:SET &UC4RUNID# = SYS_ACT_RESTART_ME_NR ()
:SET &HOSTNAME# = GET_ATT(HOST)
:SET &STATE# = GET_UC_OBJECT_STATUS(,&UC4RUNID#,'STATUS')
:SET &JOBNAME# = sys_act_me_name()
!******************************************************************* !!

:SET &TEMP_VAR_NAME# = STR_CAT("VAR_",&EVENT_RUNID#)
:SET &VAR_CREATION# = CREATE_OBJECT("VARA",&TEMP_VAR_NAME#JOBS\TEMP_VARIABLES")
:PRINT &TEMP_VAR_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 "Trigger JOBPLAN : &JOBPLAN#"
: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
:SET &FILECOUNT# = GET_FILESYSTEM(&HOST_AGENT_NAME#, "&ZFILE_PATH_TMP#/&ZFILE_PATTERN_INPUT#", PATH_FILE_COUNT,, "N")
:SET &FILECOUNT# = FORMAT(&FILECOUNT#,"0")

! Processing logic if Out folder is empty

:IF &FILECOUNT# <=0

:            SET &FILENAME# = STR_TRIM(&FILENAME#)
:            PRINT "File to be processed : &FILENAME#"

! Check if only one file exist in out folder
:                SET &FILECOUNT# = GET_FILESYSTEM(&HOST_AGENT_NAME#, "&ZFILE_PATH_TMP#/&ZFILE_PATTERN_INPUT#", PATH_FILE_COUNT,, "N")
:                IF &FILECOUNT# = 1

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

:                  SET &JOBPLANRUNID# = ACTIVATE_UC_OBJECT(&JOBPLAN#,WAIT,,,,PASS_VALUES)
:                  SET &JOBPLANRC# = GET_UC_OBJECT_STATUS(,&JOBPLANRUNID#,"STATUS")
:                  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
:ELSE
:    PRINT &FILECOUNT#
:    set &RET# = ACTIVATE_UC_OBJECT(&BLOCK_NOTIFY_OUT_NOT_EMPTY#,WAIT,,,,PASS_VALUES)
:  ENDIF

:  DELETE_VAR &TEMP_VAR_NAME#

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.

Thanks.

Outcomes