|
|||||||||||
|
Chicago-Soft
|
DROPDUP by Randy ShannonI often need to remove duplicate entries from a PDS member or dataset. While the SORT utility will allow removal of these duplicates with the SUM FIELDS=NONE statement; it would be far easier if this could be accomplished from within EDIT. This situation led to the creation of the DROPDUP macro. This macro is designed for use from within EDIT and assumes that the data has been sorted prior to execution on the key fields. Type Dropdup as a Primary command. If you wish to drop records which contain duplicate data in specific columns, simply pass the beginning clumn and ending column as parameters. Dropdup will compare only the data in these columns. If no beginning and ending columns are specified, column 1 is used as the beginning column and maximum edit member LRECL is used as the ending column, in effect comparing the entire record. Assume LRECL=80 Example ->Dropdup
12 66 DROPDUP Macro Download this macro in text format (DROPDUP.TXT)
/*REXX*/
ADDRESS ISREDIT
'MACRO (begcol endcol)'
numcheck = DATATYPE(begcol,N) /* DETERMINE IF ANY PARMS HAVE */
IF numcheck ^= 1 THEN /* BEEN PASSED. CHECK NUMERIC */
begcol = 1
numcheck = DATATYPE(endcol,N)
IF numcheck ^= 1 THEN
'ISREDIT (endcol) = LRECL'
'ISREDIT (currline) = LINENUM .ZFIRST' /* SAVE STARTING RECORD # */
'ISREDIT (lastline) = LINENUM .ZLAST' /* SAVE ENDING RECORD # */
'ISREDIT (cl,cc) = CURSOR' /* SAVE CURSOR POSITION */
delcnt = 0
DO WHILE currline < lastline /* CONTROL LOOP PROCESS */
'ISREDIT (LINE1) = LINE' currline /* GET FIRST RECORD */
line1 = SUBSTR(line1,begcol, (endcol - begcol) + 1)
nextline = currline + 1
'ISREDIT (line2) = LINE' nextline /* GET NEXT RECORD */
line2 = substr(line2,begcol,(endcol - begcol) + 1)
IF line1 == line2 THEN /* IF LINES ARE DUPS */
DO
'ISREDIT DELETE' nextline /* DELETE THE DUPLICATE */
lastline = lastline - 1
delcnt = delcnt + 1
END
ELSE
currline = currline + 1
END
'ISREDIT RESET'
IF cl > lastline THEN /* RESET CURSOR LINE TO THE LAST */
cl = lastline /* RECORD IF PREV LINE DELETED */
'ISREDIT CURSOR = &CL &CC' /* RESTORE CURSOR POSITION */
IF delcnt = 0 THEN
DO
zedsmsg = 'NO DUPS FOUND'
zedlmsg = 'NO DUPLICATE LINES WERE DETECTED'
END
ELSE
DO
zedsmsg = delcnt 'DUPS DEL'
zedsmsg = delcnt 'DUPLICATE LINES WERE REMOVED'
END
ADDRESS ISPEXEC
'SETMSG MSG (ISRZ000)'
EXIT
Randy Shannon is a Sr. Project Analyst/R&D with Century Telephone Enterprises, Inc., Monroe, Louisiana
|
|
||||||||
home · current
articles
· archives · forums · |