|
|||||||||||
|
Chicago-Soft
|
Summary Edit Macro by Joe Braun Attached is an edit macro written to eliminate duplicate records within a MVS dataset using the ISPF editor. The Syncsort OS v3.4 SORT utility does the work using the option SUM FIELDS = NONE. The REXX code is used to capture information about the currently edited file and allocate resources in TSO before executing the SORT program. The ISREDIT MACRO (PROCESS) puts the command line data into the variable PROCESS for later PARSING. For example you could issue the following command to summarize a sequential dataset based on columns 50 through 60: COMMAND ===> SUMMARY 50 60 The next ISREDIT statement puts the logical record length of the currently edited dataset into the variable LREC. The IF structure branches control when there are command line arguments. If there are no command line arguments the default of an entire record is used for summarization. Next the MACRO uses TSO FREE and ALLOCATE to create a file to contain the data we are cuurently editing. We LOOP through the currently edited file and QUEUE the data in memory before writing it to SORTIN with the EXECIO statement. Next we create the SYSIN dataset using command line arguments or defaults for the record span. SORT is called to perform the work. After SORT has summarized the dataset into the SORTOUT data definition we use ISREDIT delete to clear the currently edited file. EXECIO DISKR is used to read the SORTOUT data into an ARRAY called SRT. ISREDIT is then LOOPED through to replace the currently edited dataset with the summarized data. The datasets are FREE d, released from usage, and the MACRO is exited. Subroutine PROCARG: PROCESS variable is parsed into L1 L2 and L3 variables. IF structures perform verification on command line arguments and fill system variable with information to aid user in correcting command line syntax. Download this exec in text format (SUMEDIT.TXT)
Fig. 1 Summary Edit Macro
/* THIS REXX USES SORT TO ELIMINATE DUPLICATES IN ISPF EDIT. THE EDIT MACRO NAME IS 'SUMMARY'
BECAUSE 'SUM' IS TOO CLOSE TO THE TSO SUBMIT ABBREV. 'SUB'. */
"ISREDIT MACRO (PROCESS)"
"ISREDIT (LREC) = LRECL"
DELSTACK
IF PROCESS /= '' THEN CALL PROCARG /* SUBROUTINE */
IF PROCESS = '' THEN DO
L1=1 /* BEGINNING SORT FIELD */
L2=LREC /* END OF SORT FIELD */
END
SPAN = L2 + 1 - L1
X=OUTTRAP(ON)
"FREE FI(SORTIN,SORTOUT,SORTMSG,SYSIN)"
"ALLOC FI(SORTIN) NEW DATACLAS(SEQFB) LRECL("LREC") REUSE"
CNT = 1
"ISREDIT (LASTLN) = LINENUM .ZLAST"
DO WHILE CNT <= LASTLN
"ISREDIT (SORTIN) = LINE "CNT
RCC = RC
CNT = CNT + 1
IF RCC = 0 THEN QUEUE SORTIN
END
QUEUE
"EXECIO * DISKW SORTIN(FINIS"
DELSTACK
"ALLOC DD(SYSIN) NEW DATACLAS(SEQFB) LRECL(80) REUSE"
QUEUE ' SORT FIELDS=('L1','SPAN',CH,A),DYNALLOC=(SWORK,1),FILSZ=E99'
QUEUE ' SUM FIELDS=NONE'
QUEUE ' END '
QUEUE
"EXECIO * DISKW SYSIN(FINIS"
DELSTACK
"ALLOC FI(SORTOUT) NEW DATACLAS(SEQFB) LRECL("LREC") REUSE" "ALLOC
FI(SORTMSG) DUMMY"
SORT /* SYNCSORT - LINK LISTED */
"ISREDIT DELETE 1 .ZLAST" /* CLEAN THE EDIT SLATE */
"EXECIO * DISKR SORTOUT(STEM SRT. FINIS"
CNT = 1
DO WHILE CNT /= SRT.0 + 1
SORTOUT = SRT.CNT
LCNT = RIGHT(CNT-1,6,0)
"ISREDIT LINE_AFTER "LCNT" = (SORTOUT)"
CNT = CNT + 1
END
"FREE FI(SORTIN,SORTOUT,SORTMSG,SYSIN)"
X=OUTTRAP(OFF)
EXIT 0000
PROCARG: /* SUB-PROCEDURE FOR ARGUMENTS */
PARSE VAR PROCESS L1 L2 L3
L1RC=VERIFY(L1,'0123456789') /* ENSURE NUMERIC L1 */
L2RC=VERIFY(L2,'0123456789') /* ENSURE NUMERIC L1 */
L1BK=INDEX(L1,' ')
L2BK=INDEX(L2,' ')
CUMRC = L1RC + L2RC + L1BK + L2BK
/* IS FIELD ONE GREATER THAN ZERO? */
IF L3 /= '' THEN DO
ZEDSMSG = 'PARM # > 2 '
ZEDLMSG = 'NUMBER OF PARMS EXCEEDS TWO '
"ISPEXEC SETMSG MSG(ISRZ001)"
EXIT 0000
END
/* ARE FIELDS NUMERIC? */
IF CUMRC > 0 THEN DO
ZEDSMSG = 'PARMS NOT NUMERIC'
ZEDLMSG = 'SORT FIELD PARAMETERS CONTAINED NON-NUMERIC DATA'
"ISPEXEC SETMSG MSG(ISRZ001)"
EXIT 0000
END
/* IS FIELD TWO GREATER THAN LRECL? */
IF L2 > LREC THEN DO
ZEDSMSG = 'FIELD EXCEEDS LRECL'
ZEDLMSG = 'SECOND SORT FIELD PARAMETER GREATER THAN LRECL '
"ISPEXEC SETMSG MSG(ISRZ001)"
EXIT 0000
END
/* IS FIELD ONE GREATER THAN ZERO? */
IF L1 < 1 THEN DO
ZEDSMSG = 'FIELD EQUALS ZERO'
ZEDLMSG = 'FIRST SORT FIELD PARAMETER IS LESS THAN ONE '
"ISPEXEC SETMSG MSG(ISRZ001)"
EXIT 0000
END
/* IS FIELD ONE GREATER THAN ZERO? */
IF L1 > L2 THEN DO
ZEDSMSG = 'FIELD SEQUENCE'
ZEDLMSG = 'FIRST SORT FIELD GREATER THAN SECOND FIELD '
"ISPEXEC SETMSG MSG(ISRZ001)"
EXIT 0000
END
RETURN /* RETURN TO CALLING POINT IN MAIN-LINE OF PROGRAM */
Joseph M. Braun is employed as a Systems Analyst for a large midwestern financial services company.
|
|
||||||||
home · current
articles
· archives · forums · |