ReadStatusFileBatchCompare:

/* ***************************************************** *
 *  Snippet to maintain a file that contains the name    *
 *  of the last processed snapshot file of a Batch-      *
 *  Compare processing. Also statistics are written to   *
 *  the status file.                                     *
 *  For the actual processing the file is read           *
 *  and the saved generation number is appended to the   *
 *  snapshot filename. The maximum number of generations *
 *  are supplied with parameter 'MaxGenerations'.        *
 *                                                       *
 *  The file is created in the PROLOG                    *
 *                                                       *
 *  Invocation in PROLOG                                 * 
 *  Statusfile = 'filename'                              *
 *  MaxGenerations = 5                                   *
 *  bc_rc = ReadstatusFileBatchCompare()                 *
 *                                                       *
 *  Example for file on Virtual Disk:                    *
 *  StatusFile = 'TVSMDSK:CONFIG:SCRIPTS/CURRENT.RBA.TXT'*
 *  Example for file as PDS Member                       *
 *  StatusFile = 'PRIV.PDS.CNTL(RBA)'                    *
 *  Example for file referenced by DD-statement          *
 *  StatusFile = '//DDN_PDSINPUT'                        *
 *  Example for file referenced by DLBL-statement        *
 *  StatusFile = 'dlbl name max 7 chars'                 * 
 *                                                       * 
 *  Invocation in EPILOG to save the current generation  * 
 *  and write the statistics.                            * 
 *  bc_rc = WriteStatusFileBatchCompare()                * 
 *                                                       *
 *                                                       * 
 * ***************************************************** */
     
Call Stream StatusFile, 'C', 'OPEN READ'
IF Result <> 'READY:' THEN DO
  SAY result
  call Stream StatusFile, 'D'
  SAY result
  
  /* Ignore error "File not found" */
  
  IF INDEX(result, '0x0000532C') = 0 & INDEX(result, '0x22010002') = 0 & INDEX(result, '0x00130018')
  THEN DO
      SAY ' Unable to access RBA status file.' result
      RETURN 163
  END
END
ELSE DO
	DO FOREVER
		InLine = LINEIN(StatusFile)
		IF LENGTH(InLine) = 0 THEN LEAVE
		IF INDEX(InLine, 'Generation=') > 0 THEN  PARSE VALUE InLine WITH . 'Generation=' Generation
	END
	Call Stream StatusFile, 'C', 'CLOSE'
END

IF Generation > MaxGenerations THEN RETURN '12, Invalid Generation value' Generation

/* Set Input Snapshot Filename according generation */
IF Generation = 0 THEN DO
	/* status file not found or generation = 0: do initial snapshot build */
	PM_I.Input_Snapshot = ''
	Generation = 1
	PM_I.Output_Type = 'FILE'
	PM_I.Output_Target_Name = 'DUMMY'
END
ELSE DO
	PM_I.Input_Snapshot = 'JOURNAL.TCVISION.COMPARE'Generation
	Generation = Generation + 1
	IF Generation > MaxGenerations THEN Generation = 1
END

/* Set Output Snapshot Filename according Generation */
PM_I.Output_Snapshot = 'JOURNAL.TCVISION.COMPARE'Generation

RETURN 0

WriteStatusFileBatchCompare:

/* Here we write the status file if rc = 0 */
if PM_O.RetCode = 0 THEN DO
	Call Stream StatusFile, 'C', 'OPEN WRITE REPLACE'
	IF Result <> 'READY:' THEN DO
		SAY result
		call Stream StatusFile, 'D'
		SAY 'Unable to write Statusfile: 'result
		RETURN '12, Unable to write Statusfile: ' result
	END
	Call Lineout StatusFile, 'Batch compare sucessfully terminated'
	Call Lineout StatusFile, ' Starttime: 'TSTP_Start
	Call Lineout StatusFile, ' Endtime:   'TSTP_End
	Call Lineout StatusFile, ' Duration:  'TSTPDIFF(TSTP_Start, TSTP_End)
	Call Lineout StatusFile, ' Inserted:  'PM_O.BUBC_Inserted
	Call Lineout StatusFile, ' Deleted:   'PM_O.BUBC_Deleted
	Call Lineout StatusFile, ' Updated:   'PM_O.BUBC_Updated
	Call Lineout StatusFile, ' Unchanged: 'PM_O.BUBC_Unchanged
	Call Lineout StatusFile, ' Snap DSN:  'PM_I.Output_Snapshot
		Call Lineout StatusFile, 'Generation='Generation
	Call Stream StatusFile, 'C', 'CLOSE'
	SAY 'Generation set to: 'Generation
END
ELSE SAY '******* Out Generation not changed due rc='PM_O.RetCode PM_O.RetMessage

RETURN 0



