by RahulGaur » Thu Mar 29, 2012 5:38 pm
please see the REXX code as below:
/****************************** Rexx *********************************/
/* */
/* Before executing this EXEC. Ensure that the SDSNLOAD and SDSNEXIT */
/* Libraries are in the STEPLIB. */
/*********************************************************************/
File.0 = 3
File.1 = "JOB1 M 00.00.00 01.59.59 23456 0"
File.2 = "JOB2 M 02.00.00 13.59.59 23456 0"
SAY "Enter date of Report (dd/mm/yy):"
PULL RepDate
/*********************************************************************/
/* Validate the Input date */
/*********************************************************************/
RC = DATE( , RepDate, 'E' )
DB2Date = SUBSTR(RepDate, 1, 2)'.'SUBSTR(RepDate, 4, 2)
DB2Date = DB2Date'.20'SUBSTR(RepDate, 7, 2)
Today = DATE( 'E' )
/*********************************************************************/
/* SQL Statement for MC004B entries in MC081T table */
/*********************************************************************/
SQLStmt = ,
"SELECT M80.JOB_NAME",
" ,TIME( M80.PROG_START_TS )",
" ,M80.VERARB_MENGE1",
" ,M80.VERARB_DATUM",
" ,M80.PROG_START_TS",
" FROM DB.MC080T M80",
" WHERE DATE(M80.PROG_START_TS) = '"DB2Date"'",
" AND M80.PROG_ID IN( 'MC425B', 'MC422B', 'MC420B', 'MC421B' )",
" AND M80.PROG_ENDE_TS IS NOT NULL",
" ORDER BY M80.PROG_START_TS ASC"
/*********************************************************************/
/* Prepare DB2 environment and execute the SQL Statement */
/*********************************************************************/
ADDRESS TSO 'SUBCOM DSNREXX'
IF RC <> 0 THEN
DO
RetCode = RXSUBCOM( 'ADD','DSNREXX', 'DSNREXX')
If RetCode <> 0 THEN
DO
SAY "Error establishing DSNREXX Environment"
EXIT 9
END
END
ADDRESS DSNREXX "CONNECT" "DB6"
IF( SqlCode <> 0 ) THEN
DO
SAY "Error in CONNECT. SQLCODE: "SqlCode
EXIT 9
END
ADDRESS DSNREXX "EXECSQL SET CURRENT PACKAGESET='DSNREXCS'"
IF( SqlCode <> 0 ) THEN
DO
SAY "Error in SET CURRENT PACKAGESET. SQLCODE: "SqlCode
ADDRESS DSNREXX "DISCONNECT"
EXIT 9
END
ADDRESS DSNREXX "EXECSQL DECLARE C1 CURSOR FOR S1"
IF( SqlCode <> 0 ) THEN
DO
SAY "Error in DECLARE. SQLCODE: "SqlCode
ADDRESS DSNREXX "DISCONNECT"
EXIT 9
END
ADDRESS DSNREXX "EXECSQL PREPARE S1 INTO :OUTSQLDA FROM :SQLSTMT"
IF( SqlCode <> 0 ) THEN
DO
SAY "Error in PREPARE. SQLCODE: "SqlCode
ADDRESS DSNREXX "DISCONNECT"
EXIT 9
END
ADDRESS DSNREXX "EXECSQL OPEN C1"
IF( SqlCode <> 0 ) THEN
DO
SAY "Error in OPEN. SQLCODE: "SqlCode
ADDRESS DSNREXX "DISCONNECT"
EXIT 9
END
/*********************************************************************/
/* Store the result of the SQL Statement in a Array for later */
/* processing */
/*********************************************************************/
OutCtr = 0
DO UNTIL( SqlCode <> 0 )
ADDRESS DSNREXX "EXECSQL FETCH C1 USING DESCRIPTOR :OUTSQLDA"
IF( SqlCode < 0 ) THEN
DO
SAY "Error in FETCH. SQLCODE: "SqlCode
ADDRESS DSNREXX "DISCONNECT"
EXIT 9
END
IF( SqlCode = 0 ) THEN
DO
OutLine = ' '
DO I = 1 To OUTSQLDA.SQLD
OutLine = OutLine OUTSQLDA.I.SQLDATA
END
OutCtr = OutCtr + 1
Output.OutCtr = OutLine
END
END
ADDRESS DSNREXX "DISCONNECT"
RetCode = RXSUBCOM( 'DELETE','DSNREXX','DSNREXX')
/*********************************************************************/
/* Parse the output from the SQL statement */
/*********************************************************************/
DO I = 1 TO OutCtr
PARSE VAR Output.I JobName.I Time.I Recs.I AVK.I Tsp.I
Recs.I = STRIP( Recs.I, , '.' )
/*
Say 'SYSID : 'JobName.I
Say 'FILEID : 'FileId.I
Say 'Records : 'Recs.I
Say 'AVK Date : 'AVK.I
Say 'TimeStmp : 'Tsp.I'--'
*/
End
/*********************************************************************/
/* Process each entry in our list one at a time */
/*********************************************************************/
NoOfFilesExpected = File.0
NoOfFilesRecd = 0
DO I = 1 TO File.0
FileArrived = FALSE
PARSE VAR File.I FJobname Multi FStartTime FEndTime FDays FAVK
/******************************************************************/
/* Check if we retrieved a row from MC081T table for this Job */
/******************************************************************/
DO J = 1 TO OutCtr
IF( FJobName = JobName.J ) THEN
IF( Multi = 'M' ) THEN
DO
IF( Time.J >= FStartTime & Time.J <= FEndTime ) THEN
DO
FileArrived = TRUE
LEAVE
END
END
ELSE
DO
FileArrived = TRUE
LEAVE
END
END
IF( FileArrived = TRUE ) THEN
DO
NoOfFilesRecd = NoOfFilesRecd + 1
SAY FJobname" has run at "Time.j
/***************************************************************/
/* Check if AVK date was correct */
/***************************************************************/
/***************************************************************/
/* Add or subtract the number of days from the RepDate */
/***************************************************************/
FAVK = STRIP( FAVK )
BaseDays = DATE( 'B', RepDate, 'E' )
SELECT
WHEN( SUBSTR( FAVK, 1, 1 ) = '+' ) THEN
BaseDays = BaseDays + SUBSTR( FAVK, 2 )
WHEN( SUBSTR( FAVK, 1, 1 ) = '-' ) THEN
BaseDays = BaseDays - SUBSTR( FAVK, 2 )
OTHERWISE
BaseDays = BaseDays
END
AVKDate = DATE( 'E', BaseDays, 'B' )
AVKDateFormated = SUBSTR( AVKDATE, 1, 2 )'.'
AVKDateFormated = AVKDateFormated''SUBSTR( AVKDATE, 4, 2 )'.20'
AVKDateFormated = AVKDateFormated''SUBSTR( AVKDATE, 7, 2 )
IF( AVKDateFormated <> AVK.J ) THEN
DO
SAY " **** WARNING ****"
SAY " **** WARNING **** File Processed with wrong AVK date"
SAY " **** WARNING ****"
END
/***************************************************************/
/* Check if file could have been empty */
/***************************************************************/
IF( Recs.J < 4 ) THEN
DO
SAY " **** WARNING ****"
SAY " **** WARNING **** Check the no. of Records in file"
SAY " **** WARNING ****"
END
END
ELSE
DO
/***************************************************************/
/* If file has not arrived, check if it was expected on the */
/* RepDate */
/***************************************************************/
Dow = GetDow( )
IF( POS( Dow, FDays ) > 0 ) THEN
FileExpected = TRUE
ELSE
DO
FileExpected = FALSE
NoOfFilesExpected = NoOfFilesExpected - 1
END
IF( FileExpected = TRUE ) THEN
DO
/************************************************************/
/* If file was expected and did not arrive, */
/* On current day check if the file is delayed */
/************************************************************/
IF( RepDate <> Today ) THEN
DO
SAY "**** WARNING ****"
SAY "**** WARNING **** "FJobname" did NOT Run between ",
FStartTime" and "FEndTime
SAY "**** WARNING ****"
END
ELSE
DO
CurTime = SUBSTR( TIME( ), 1, 5 )
IF( CurTime > FEndTime ) THEN
DO
SAY "**** WARNING ****"
SAY "**** WARNING **** "FJobname" is DELAYED"
SAY "**** WARNING ****"
END
END
END
END
END
EXIT
GetDow:
Day = DATE( 'W', RepDate, 'E' )
SELECT
WHEN( Day = 'Monday' ) THEN Return '1'
WHEN( Day = 'Tuesday' ) THEN Return '2'
WHEN( Day = 'Wednesday' ) THEN Return '3'
WHEN( Day = 'Thursday' ) THEN Return '4'
WHEN( Day = 'Friday' ) THEN Return '5'
WHEN( Day = 'Saturday' ) THEN Return '6'
WHEN( Day = 'Sunday' ) THEN Return '7'
OTHERWISE Return 'X'
END