ISREDIT MACRO     /* CATM0401 EDIT TEMP3 */
 
/* 06/16/2004 JL.NELSON ADDED EXIT CODE
/* 07/08/2004 JL.NELSON ADDED quotes to WHOHAS - CORRECT OUTPUT
/* 07/20/2004 JL.NELSON ADDED whoami to get return code of zero
/* 10/26/2004 JL.NELSON Shift ID DSNAME (left blank for expansion)
/* 11/30/2004 JL.NELSON Changed to use CACM042T for table TBLMBR
/* 02/08/2005 JL.NELSON Changed constants to variables before rename
/* 06/01/2005 JL.NELSON Changed DSN truncation to avoid 860 errors
/* 06/08/2005 JL.NELSON Pass MAXCC in ZISPFRC variable
/* 06/15/2005 JL.NELSON Set return code to end job step
/* 03/15/2006 JL.NELSON Made changes to avoid SUBSTR abend 920/932.
/* 03/21/2006 JL.NELSON Use NRSTR avoid abend 900 if ampersand in data.
/* 03/30/2006 JL.NELSON Test for empty member LINENUM Rcode = 4.
/* 04/19/2006 JL.NELSON Added TRUNC_DATA routine to drop blanks RC=864
/* 05/23/2008 C.STERN   Check for new V528 SMS identifiers in TEMP3 and
/*                      prevent them from being inserted into TEMP4.
/* 06/02/2009 CL.FENTON Changes on how TBLMBR is processed.
/* 04/19/2011 CL.FENTON Changed generation of cmd when masking
/*            characters or ending with a period in OLD field.  If
/*            masking character or ending period is available, cmd
/*            specified without quotes and with DATA(MASK).
/* 08/29/2016 CL.FENTON Correct issue with TBLMBR.
 
SET PGMNAME = &STR(CATM0001 08/29/16)
 
NGLOBAL PGMNAME RETURN_CODE DATA
 
SET SYSPROMPT = OFF                /* CONTROL NOPROMPT          */
SET SYSFLUSH  = OFF                /* CONTROL NOFLUSH           */
SET SYSASIS   = ON                 /* CONTROL ASIS - caps off   */
 
/* ***************************************    */
/* VARIABLES ARE PASSED TO THIS MACRO         */
/* CONSLIST                                   */
/* COMLIST                                    */
/* TERMMSGS                                   */
/* ***************************************    */
 
ISPEXEC CONTROL NONDISPL ENTER
ISPEXEC CONTROL ERRORS RETURN
 
ERROR DO
  SET RETURN_CODE = &LASTCC
  IF &LASTCC GE 16 THEN +
    WRITE &PGMNAME LASTCC = &LASTCC &ZERRLM
  RETURN
  END
 
SET TM01LMCL = 12
SET TM01LMFR = 12
SET TM01LMIN = 12
SET TM01LMOP = 12
SET TM01LMPE = 12
SET TM01VGET = 12
 
SET RETURN_CODE = 0
 
ISPEXEC VGET ( -
  CONSLIST  -
  COMLIST   -
  SYMLIST   -
  TERMMSGS  -
  TBLMBR    -
  ) ASIS
 
SET TM01VGET = &RETURN_CODE
IF &RETURN_CODE NE 0 THEN DO
  WRITE &PGMNAME VGET RC = &RETURN_CODE  &ZERRSM
  WRITE &PGMNAME CONSLIST/&CONSLIST COMLIST/&COMLIST SYMLIST/&SYMLIST +
    TERMMSGS/&TERMMSGS
  WRITE &PGMNAME TBLMBR/&TBLMBR
  SET RETURN_CODE = &RETURN_CODE + 16
  GOTO ERR_EXIT
  END
 
SET SYSSYMLIST = &SYMLIST          /* CONTROL SYMLIST/NOSYMLIST */
SET SYSCONLIST = &CONSLIST         /* CONTROL CONLIST/NOCONLIST */
SET SYSLIST    = &COMLIST          /* CONTROL LIST/NOLIST       */
SET SYSMSG     = &TERMMSGS         /* CONTROL MSG/NOMSG         */
 
/* *************************************** */
/* MAIN PROCESS                            */
/* *************************************** */
 
ISREDIT (MEMBER) = MEMBER
ISREDIT (DSNAME) = DATASET
SET RETURN_CODE = 0
 
ISREDIT (LASTLINE) = LINENUM .ZLAST
 
IF &RETURN_CODE GT 0 THEN DO    /* Empty RC = 4
  IF &LASTLINE EQ 0 THEN +
    WRITE &PGMNAME Empty file RCode = &RETURN_CODE +
      DSN=&DSNAME  MEMBER=&MEMBER  &ZERRSM
  ELSE +
    WRITE &PGMNAME LINENUM Error RCode = &RETURN_CODE +
      DSN=&DSNAME  MEMBER=&MEMBER  &ZERRSM
  SET RETURN_CODE = &RETURN_CODE +16
  GOTO ERR_EXIT
  END
 
SET RETURN_CODE = 0
 
ISPEXEC LMINIT DATAID(TEMP4) DDNAME(TSSALL) ENQ(EXCLU)
 
SET TM01LMIN = &RETURN_CODE
IF &RETURN_CODE NE 0 THEN DO
  WRITE &PGMNAME LMINIT_TEMP4_RC &RETURN_CODE  &ZERRSM
  SET RETURN_CODE = &RETURN_CODE + 16
  GOTO ERR_EXIT
  END
 
ISPEXEC LMOPEN DATAID(&TEMP4) OPTION(OUTPUT)
 
SET TM01LMOP = &RETURN_CODE
IF &RETURN_CODE NE 0 THEN DO
  WRITE &PGMNAME LMOPEN_TEMP4_RC &RETURN_CODE  &ZERRSM
  SET RETURN_CODE = &RETURN_CODE + 16
  GOTO ERR_EXIT
  END
 
/***************************************************************** */
/*  THE FOLLOWING ISREDIT X STATEMENTS ARE USED TO EXCLUDE         */
/*  DATASETS COVERED BY OTHER FINDINGS.                            */
/***************************************************************** */
 
WRITE &PGMNAME Number of records before DELETE = &LASTLINE
 
/* *************************************** */
/* PROCESS TABLE VARIBLES                  */
/* *************************************** */
 
SET TBLMBR = &NRSTR(&TBLMBR)
/*SET TBLMBR = &NRSTR(&TBLMBR.#)
SET TCNT = 2
SET TLEN = &LENGTH(&NRSTR(&TBLMBR))
 
TABLE_LOOP: +
SET RETURN_CODE = 0
 
IF &TCNT GT &TLEN THEN DO
  ISREDIT DELETE ALL NX
  ISREDIT RESET
  GOTO START_SORT
  END
 
SET ECNT = &SYSINDEX(&STR(#),&NRSTR(&TBLMBR),&TCNT)
 
IF &TCNT GT 0 AND &TCNT LT &ECNT THEN +
  SET TABLEDATA = &SUBSTR(&TCNT:&ECNT,&NRSTR(&TBLMBR))
ELSE DO
  SET TABLEDATA = &STR(    )
  SET ECNT = &TLEN
  END
 
SET ITER = &SUBSTR(1:3,&NRSTR(&TABLEDATA))
 
SET RETURN_CODE = 0
 
ISREDIT X ALL '&ITER' 1
 
IF &RETURN_CODE GT 4 THEN +
  WRITE &PGMNAME X ALL '&ITER' RC &RETURN_CODE  &ZERRSM
/*  DO
/*  ISREDIT LINE_AFTER .ZL = '&ITER'
/*  ISREDIT X ALL '&ITER' 1 2
/*  END
 
IF &ECNT GT &TCNT THEN SET TCNT = &ECNT + 1
ELSE SET TCNT = &TLEN + 1
 
GOTO TABLE_LOOP
 
 
START_SORT: +
SET RETURN_CODE = 0
 
ISREDIT SORT 1 50 A
 
IF &RETURN_CODE GT 4 THEN DO    /* SORT_RC = 8 No records to sort
  WRITE &PGMNAME SORT TEMP3 RC &RETURN_CODE  &ZERRSM
  SET RETURN_CODE = &RETURN_CODE +16
  GOTO ERR_EXIT
  END
 
/* ISREDIT CURSOR = .ZLAST 1
/* ISREDIT (ROW,COL) = CURSOR
/* ISREDIT CURSOR = 1 0
 
ISREDIT RESET
ISREDIT (LASTLINE) = LINENUM .ZLAST
WRITE &PGMNAME Number of records after SORT = &LASTLINE
 
SET MEMBER = &STR( )
SET TSS    = &STR( )
 
SET WCNT = 0
SET LINE = 0
 
LOOP: +
SET RETURN_CODE = 0
 
SET LINE = &LINE + 1
 
IF &LINE GT &LASTLINE THEN GOTO END_EDIT
 
ISREDIT (DATA) = LINE &LINE
 
SET OLD=&SUBSTR(4:50,&NRSTR(&DATA))
 
IF &NRSTR(&OLD) EQ &STR( ) THEN +
  GOTO LOOP
 
IF &NRSTR(&OLD) EQ &NRSTR(&TSS) THEN +
  GOTO LOOP
 
IF &NRSTR(&OLD) EQ &NRSTR(IGDCSSGA) THEN DO
  GOTO LOOP
  END
 
IF &NRSTR(&OLD) EQ &NRSTR(IGDCSSCA) THEN DO
  GOTO LOOP
  END
 
IF &NRSTR(&OLD) EQ &NRSTR(IGDCSMCA) THEN DO
  GOTO LOOP
  END
 
IF &NRSTR(&OLD) EQ &NRSTR(IGDCSDCA) THEN DO
  GOTO LOOP
  END
 
IF &NRSTR(&OLD) EQ &NRSTR(IGDICMDS) THEN DO
  GOTO LOOP
  END
 
IF &SUBSTR(1:2,&NRSTR(&DATA)) NE &NRSTR(&MEMBER) THEN DO
  SET MEMBER = &SUBSTR(1:2,&NRSTR(&DATA))
  SET CMD = &STR(TSS WHOAMI ITER(&MEMBER))
  SET RETURN_CODE = 0
 
  ISPEXEC LMPUT DATAID(&TEMP4) MODE(INVAR) DATALOC(CMD) +
    DATALEN(&LENGTH(&NRSTR(&CMD)))
 
  SET TM01LMPE = &RETURN_CODE
  END
 
/* SET CMD = TSS WHOH DSN(&NRSTR(&TSS)) changed to get correct XAUTHs
/* SET DSN = &TSS  lastcc = 860
 
IF &NRSTR(&OLD) NE &STR( ) THEN DO
  SET DATA = &NRSTR(&OLD)
  SYSCALL TRUNC_DATA
  SET OLD = &NRSTR(&DATA)
  END
ELSE GOTO LOOP
 
SET TSS = &NRSTR(&OLD)
 
IF &SYSINDEX(&STR(*),&NRSTR(&OLD)) EQ 0 AND +
   &SYSINDEX(&STR(+),&NRSTR(&OLD)) EQ 0 AND +
   &SYSINDEX(&STR(%),&NRSTR(&OLD)) EQ 0 AND +
   &SYSINDEX(&STR(. ),&NRSTR(&OLD )) EQ 0 THEN DO
  SET CMD = &NRSTR(TSS WHOH DSN('&OLD'))
  END
ELSE DO
  SET CMD = &NRSTR(TSS WHOH DSN(&OLD)DATA(MASK))
  END
 
SET RETURN_CODE = 0
 
ISPEXEC LMPUT DATAID(&TEMP4) MODE(INVAR) DATALOC(CMD) +
  DATALEN(&LENGTH(&NRSTR(&CMD)))
 
SET TM01LMPE = &RETURN_CODE
IF &RETURN_CODE GT 4 THEN DO
  WRITE &PGMNAME LMPUT_TEMP4_RC &RETURN_CODE  &ZERRSM
  SET RETURN_CODE = &RETURN_CODE + 16
  GOTO ERR_EXIT
  END
 
SET WCNT = &WCNT + 1
 
GOTO LOOP
 
 
END_EDIT: +
SET RETURN_CODE = 0
 
WRITE &PGMNAME Number of records written to TEMP4 = &WCNT
 
SET RETURN_CODE = 0
 
ISPEXEC LMCLOSE DATAID(&TEMP4)
 
SET TM01LMCL = &RETURN_CODE
SET RETURN_CODE = 0
 
ISPEXEC LMFREE DATAID(&TEMP4)
 
SET TM01LMFR = &RETURN_CODE
SET RETURN_CODE = 0
 
ERR_EXIT: +
IF &MAXCC GE 16 OR +
   &RETURN_CODE GT 0 THEN DO
  ISPEXEC VGET (ZISPFRC) SHARED
  IF &MAXCC GT &ZISPFRC THEN +
    SET ZISPFRC = &MAXCC
  ELSE +
    SET ZISPFRC = &RETURN_CODE
  ISPEXEC VPUT (ZISPFRC) SHARED
  WRITE &PGMNAME ZISPFRC = &ZISPFRC
  END
 
SET TM001RC = &RETURN_CODE
 
ISPEXEC VPUT ( -
  TM01LMCL     -
  TM01LMFR     -
  TM01LMIN     -
  TM01LMOP     -
  TM01LMPE     -
  TM01VGET     -
  TM001RC      -
  ) ASIS
 
ISREDIT SAVE
ISREDIT END
 
EXIT CODE(0)
ISREDIT MEND
 
 
/* *************************************** */
/*  SYSCALL SUBROUTINES                    */
/* *************************************** */
 
TRUNC_DATA: PROC 0
 
SET RETURN_CODE = 0
 
SET DL = &LENGTH(&NRSTR(&DATA))
DO SI = 1 TO &DL +
  WHILE &SUBSTR(&SI,&NRSTR(&DATA)) EQ &STR( )
  END
 
DO EI = &DL TO 1 BY -1 +
  WHILE &SUBSTR(&EI,&NRSTR(&DATA)) EQ &STR( )
  END
 
IF &SI LT &EI THEN DO
  SET DATA = &SUBSTR(&SI:&EI,&NRSTR(&DATA))
  END
 
RETURN CODE(&LASTCC)
END
