Mainframe Utility: DELDUPS

Return to Mainframe Utilities Page

Module


ISREDIT MACRO (CL1,CL2,CL3,CL4,CL5,CL6,CL7,CL8,CL9,CL10,CL11,CL12)
ISPEXEC CONTROL ERRORS RETURN
/**** SET MESSAGE DISPLAY ON/OFF BASED ON THE DEBUG SWITCH ***/
ISPEXEC VGET (DBGSWTCH) PROFILE
IF &DBGSWTCH = &STR(ON) THEN CONTROL MSG LIST CONLIST SYMLIST NOFLUSH
ELSE CONTROL NOMSG NOLIST NOFLUSH NOPROMPT
/**********************************************************************/
/* UTILITY NAME : DELDUPS                                             */
/* DATE WRITTEN : 3-13-90                                             */
/* AUTHOR       : DAVE LEIGH                                          */
/* DESCRIPTION  : DELETE DUPLICATE RECORDS IN A FILE.                 */
/*========================== MODIFICATIONS ===========================*/
/* WHO         ¦WHEN     ¦WHY                                         */
/* ---         ¦----     ¦---                                         */
/*             ¦         ¦                                            */
/**********************************************************************/

IF &NRSTR(&CL1) = &NRSTR(HELP) THEN GOTO HELPSEC

IF &NRSTR(&CL1) =    THEN +
    DO
        ISREDIT (LRECL) = LRECL
        SET CL1 = 1
        SET CL2 = &LRECL
    END

IF (&NRSTR(&CL1) >  AND &NRSTR(&CL2) =  ) OR +
   (&NRSTR(&CL3) >  AND &NRSTR(&CL4) =  ) OR +
   (&NRSTR(&CL5) >  AND &NRSTR(&CL6) =  ) OR +
   (&NRSTR(&CL7) >  AND &NRSTR(&CL8) =  ) OR +
   (&NRSTR(&CL9) >  AND &NRSTR(&CL10) = ) OR +
   (&NRSTR(&CL11) > AND &NRSTR(&CL12) = ) THEN +
    DO
        SET ZEDLMSG = &NRSTR(COLUMNS MUST BE SPECIFIED IN PAIRS, +
                             EVEN IF THE SAME COLUMN)
        ISPEXEC SETMSG MSG(UTLZ001)
        EXIT
    END

IF (&DATATYPE(&NRSTR(&CL1))  ¬= NUM AND &NRSTR(&CL1)  >   ) OR +
   (&DATATYPE(&NRSTR(&CL2))  ¬= NUM AND &NRSTR(&CL2)  >   ) OR +
   (&DATATYPE(&NRSTR(&CL3))  ¬= NUM AND &NRSTR(&CL3)  >   ) OR +
   (&DATATYPE(&NRSTR(&CL4))  ¬= NUM AND &NRSTR(&CL4)  >   ) OR +
   (&DATATYPE(&NRSTR(&CL5))  ¬= NUM AND &NRSTR(&CL5)  >   ) OR +
   (&DATATYPE(&NRSTR(&CL6))  ¬= NUM AND &NRSTR(&CL6)  >   ) OR +
   (&DATATYPE(&NRSTR(&CL7))  ¬= NUM AND &NRSTR(&CL7)  >   ) OR +
   (&DATATYPE(&NRSTR(&CL8))  ¬= NUM AND &NRSTR(&CL8)  >   ) OR +
   (&DATATYPE(&NRSTR(&CL9))  ¬= NUM AND &NRSTR(&CL9)  >   ) OR +
   (&DATATYPE(&NRSTR(&CL10)) ¬= NUM AND &NRSTR(&CL10) >   ) OR +
   (&DATATYPE(&NRSTR(&CL11)) ¬= NUM AND &NRSTR(&CL11) >   ) OR +
   (&DATATYPE(&NRSTR(&CL12)) ¬= NUM AND &NRSTR(&CL12) >   ) THEN +
    DO
        SET ZEDLMSG = &NRSTR("DELDUPS" ARGUMENTS MUST BE NUMERIC)
        ISPEXEC SETMSG MSG(UTLZ001)
        EXIT
    END

IF &NRSTR(&CL1)  = 0 OR +
   &NRSTR(&CL2)  = 0 OR +
   &NRSTR(&CL3)  = 0 OR +
   &NRSTR(&CL4)  = 0 OR +
   &NRSTR(&CL5)  = 0 OR +
   &NRSTR(&CL6)  = 0 OR +
   &NRSTR(&CL7)  = 0 OR +
   &NRSTR(&CL8)  = 0 OR +
   &NRSTR(&CL9)  = 0 OR +
   &NRSTR(&CL10) = 0 OR +
   &NRSTR(&CL11) = 0 OR +
   &NRSTR(&CL12) = 0 THEN +
    DO
        SET ZEDLMSG = &NRSTR(ZERO IS NOT A VALID COLUMN)
        ISPEXEC SETMSG MSG(UTLZ001)
        EXIT
    END

IF &CL1  > &CL2  OR +
   &CL3  > &CL4  OR +
   &CL5  > &CL6  OR +
   &CL7  > &CL8  OR +
   &CL9  > &CL10 OR +
   &CL11 > &CL12 THEN +
    DO
        SET ZEDLMSG = &NRSTR(2ND COLUMN IN A PAIR MUST BE > OR = +
                             TO THE 1ST COLUMN IN A PAIR)
        ISPEXEC SETMSG MSG(UTLZ001)
        EXIT
    END

ISREDIT SORT +
        &CL1 &CL2 &CL3 &CL4 &CL5 &CL6 &CL7 &CL8 &CL9 &CL10 &CL11 &C12
IF &LASTCC > 4 THEN +
    DO
        SET ZEDLMSG = &NRSTR(PROBLEM WITH THE "DELDUPS" SORT STEP)
        ISPEXEC SETMSG MSG(UTLZ001)
        EXIT
    END

ISREDIT FIND FIRST P'=' 1
ISREDIT LINE_BEFORE .ZCSR = ' '
ISREDIT FIND FIRST P'=' 1
ISREDIT CHANGE P'=' X'FF' ALL .ZCSR .ZCSR
ISREDIT (FFFFLINE) = LINE .ZCSR

ISREDIT FIND FIRST P'=' 1
IF &LASTCC = 0 THEN +
    DO
        ISREDIT (DLINE) = LINE .ZCSR
        IF &CL2 >    THEN SET SAVE1 = &SUBSTR(&CL1:&CL2,&NRSTR(&DLINE))
        IF &CL4 >    THEN SET SAVE2 = &SUBSTR(&CL1:&CL2,&NRSTR(&DLINE))
        IF &CL6 >    THEN SET SAVE3 = &SUBSTR(&CL1:&CL2,&NRSTR(&DLINE))
        IF &CL8 >    THEN SET SAVE4 = &SUBSTR(&CL1:&CL2,&NRSTR(&DLINE))
        IF &CL10 >   THEN SET SAVE5 = &SUBSTR(&CL1:&CL2,&NRSTR(&DLINE))
        IF &CL12 >   THEN SET SAVE6 = &SUBSTR(&CL1:&CL2,&NRSTR(&DLINE))
    END

ISREDIT FIND NEXT P'=' 1
SET SAVECC = &LASTCC

DO WHILE &SAVECC = 0
    ISREDIT (DLINE) = LINE .ZCSR
    SET PART1 =
    SET PART2 =
    SET PART3 =
    SET PART4 =
    SET PART5 =
    SET PART6 =
    IF &CL2 >    THEN SET PART1 = &SUBSTR(&CL1:&CL2,&NRSTR(&DLINE))
    IF &CL4 >    THEN SET PART2 = &SUBSTR(&CL1:&CL2,&NRSTR(&DLINE))
    IF &CL6 >    THEN SET PART3 = &SUBSTR(&CL1:&CL2,&NRSTR(&DLINE))
    IF &CL8 >    THEN SET PART4 = &SUBSTR(&CL1:&CL2,&NRSTR(&DLINE))
    IF &CL10 >   THEN SET PART5 = &SUBSTR(&CL1:&CL2,&NRSTR(&DLINE))
    IF &CL12 >   THEN SET PART6 = &SUBSTR(&CL1:&CL2,&NRSTR(&DLINE))
    IF &NRSTR(&PART1) = &NRSTR(&SAVE1) AND +
       &NRSTR(&PART2) = &NRSTR(&SAVE2) AND +
       &NRSTR(&PART3) = &NRSTR(&SAVE3) AND +
       &NRSTR(&PART4) = &NRSTR(&SAVE4) AND +
       &NRSTR(&PART5) = &NRSTR(&SAVE5) AND +
       &NRSTR(&PART6) = &NRSTR(&SAVE6) THEN +
        ISREDIT LINE .ZCSR = '&FFFFLINE'
    SET SAVE1 = &NRSTR(&PART1)
    SET SAVE2 = &NRSTR(&PART2)
    SET SAVE3 = &NRSTR(&PART3)
    SET SAVE4 = &NRSTR(&PART4)
    SET SAVE5 = &NRSTR(&PART5)
    SET SAVE6 = &NRSTR(&PART6)
    ISREDIT FIND NEXT P'=' 1
    SET SAVECC = &LASTCC
END

ISREDIT RESET ALL
ISREDIT EXCLUDE ALL
ISREDIT FIND ALL '&FFFFLINE'
ISREDIT DELETE ALL NX
ISREDIT RESET

EXIT
HELPSEC: +                                                              02480000
ISPEXEC SELECT PGM(ISPTUTOR) PARM(HELPSHEL)                             02490000
SET ZEDLMSG = &STR(*** HELP DISPLAYED FOR DELDUPS UTILITY +             02490000
                   *** NO PROCESSING PERFORMED ***)                     02490000
ISPEXEC SETMSG MSG(UTLZ000)                                             02490000
EXIT
            


Documentation

 This utility will delete records in a file that are duplicates with respect to
 up to six different columns (a column may be one physical "card column" or) the
 entire lrecl or anywhere in between.  For instance, you could specify "deldups
 1 80" for an 80 byte file, and the entire file would be sorted on columns 1
 through 80 and duplicate records would be deleted.  You could also specify that
 records that are duplicate for colums 1-8 be deleted (i.e. the) file is sorted
 on colums 1 through 8, and only these colums are compared to see if the record
 is a duplicate of the previous one.  You may specify up to six pairs of
 columns.  The second column in the pair must be >= the first.            


Leave a Reply

Your email address will not be published. Required fields are marked *