Mainframe Utility: COUNTKEY

Return to Mainframe Utilities Page

Module


/*********************************************************************/
/* CLIST COUNTKEY - COUNT THE KEY OCCURANCES WITHIN A FILE           */
/* AUTHOR : DAVID LEIGH DATE : 5-31-89                               */
/*********************************************************************/
PROC 0 HELP DSN() COL1() COL2() VIEW(E) BATCH

/**** 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
IF &HELP = &STR(HELP) THEN GOTO HELPSEC

ISPEXEC VGET (INVOKE) SHARED
IF &INVOKE =    THEN SET INVOKE = COUNTKEY
SET OUTDSN = &STR(&SYSUID..TEMP.&INVOKE..OUTPUT)
SET CARDDSN = &STR(&SYSUID..TEMP.&INVOKE..SYSIN)
SET OUTSYS = &STR(&SYSUID..TEMP.&INVOKE..SYSOUT)
SET DIALOG = OFF

IF &DSN =    OR &COL1 =     OR &COL2 =    THEN +
    DO
        SET DIALOG = ON
        ISPEXEC VPUT (INVOKE VIEW DSN COL1 COL2 OUTDSN) SHARED
        ISPEXEC DISPLAY PANEL(UTILCTKY)
        IF &LASTCC > 0 THEN +
            DO
                SET ZEDLMSG = &STR(EXITED "&INVOKE" UTILITY WITHOUT)+
                              &STR( PROCESSING)
                ISPEXEC SETMSG MSG(UTLZ000)
                EXIT
            END
        ISPEXEC VGET (INVOKE VIEW DSN COL1 COL2 OUTDSN) SHARED
    END

SET ZEDLMSG = &STR(*** PREPARING FOR CALL TO SYNCSORT ***)
ISPEXEC CONTROL DISPLAY LOCK
ISPEXEC DISPLAY MSG(UTLZ000W)

SET RP = &STR())
SET LP = &STR((
SET SLEN = &COL2 - &COL1 + 1

IF &SLEN > 9 THEN +
    DO
        SET LRECL = &SLEN + 12
        SET EQL = &SLEN
    END
ELSE +
    DO
        SET LRECL = 21
        SET EQL = 9
    END

SET PAD = &LRECL - &SLEN
IF &PAD < 1 THEN SET PAD = 1

SET SPCE = &SLEN - 9
IF &SPCE < 0 THEN SET SPCE = 0
SET SPCE = &SPCE + 1
SET SPCE1 = &SPCE + 9 - &SLEN + 2
SET SPCE2 = &SPCE + 3

LISTDSI '&DSN'
IF &LASTCC = 16 THEN +
    DO
        SET ZEDLMSG = &STR("&DSN" PROBLEM: &SYSDSN('&DSN'))
        ISPEXEC SETMSG MSG(UTLZ001)
        EXIT
    END

IF &SYSINDEX(&STR(V),&STR(&SYSRECFM)) = 1 THEN +
    SET RDW = 4
ELSE +
    SET RDW = 0

FREE DDNAME(SORTWK01 SYSIN SORTIN SORTOUT SYSOUT SYSPRINT SORTMSG +
            SORTWK02 SORTWK03 SORTWK04)

DELETE '&CARDDSN'
ALLOC DD(SYSIN) DSN('&CARDDSN') +
                NEW CATALOG +
                UNIT(SYSDA) VOLUME(WRK$$$) +
                SPACE(1,1) TRACKS RELEASE +
                RECFM(F B) LRECL(80) BLKSIZE(23440) DSORG(PS)

OPENFILE SYSIN  OUTPUT
IF &RDW = 4 THEN +
    SET SYSIN  = &STR( INREC FIELDS=&LP.1,4,&EVAL(&RDW+&COL1),)+
                 &STR(&SLEN,&PAD.X&RP)
ELSE +
    SET SYSIN  = &STR( INREC FIELDS=&LP&EVAL(&RDW+&COL1),)+
                 &STR(&SLEN,&PAD.X&RP)
PUTFILE SYSIN
SET SYSIN  = &STR( SORT FIELDS=&LP.&EVAL(&RDW+1),)+
             &STR(&SLEN,CH,A&RP)
PUTFILE SYSIN
SET SYSIN  = &STR( OUTFIL FILES=OUT,)
PUTFILE SYSIN
SET SYSIN  = &STR( HEADER1=&LP'KEY VALUE',&SPCE.X,'OCCURANCES',/,)
PUTFILE SYSIN
SET SYSIN  = &STR(            &EQL'=',X,'=========='&RP,)
PUTFILE SYSIN
SET SYSIN  = &STR( NODETAIL,)
PUTFILE SYSIN
SET SYSIN  = &STR( SECTIONS=&LP.&EVAL(&RDW+1),)+
             &STR(&SLEN,)
PUTFILE SYSIN
SET SYSIN  = &STR( TRAILER3=&LP.&EVAL(&RDW+1),)+
             &STR(&SLEN,&SPCE1.X,COUNT&RP&RP,)
PUTFILE SYSIN
SET SYSIN  = &STR( TRAILER1=&LP&EQL'=',X,'==========',/,)
PUTFILE SYSIN
SET SYSIN  = &STR(             'TOTAL   ',&SPCE2.X,COUNT&RP)
PUTFILE SYSIN
CLOSFILE SYSIN

IF &RDW = 0 THEN +
    DO
        ISPEXEC SELECT CMD(%BLKSIZE &LRECL 0 DEVICE(3380) BATCH)
        ISPEXEC VGET BLKSIZE SHARED
        SET RECFM = (F B A)
    END
ELSE +
    DO
        SET LRECL = &LRECL + 4
        SET BLKSIZE = 23476
        SET RECFM = (V B A)
    END
DELETE '&OUTDSN'
DELETE '&OUTSYS'
SET SSCC = 0

IF &BATCH = BATCH THEN GOTO BATCH_SECTION

ALLOC DD(SORTIN)   DSN('&DSN') +
                   SHR KEEP
ALLOC DD(SORTWK01) UNIT(SYSDA) VOLUME(WRK$$$) +
                   SPACE(1,1) CYLINDERS
ALLOC DD(SORTWK02) UNIT(SYSDA) VOLUME(WRK$$$) +
                   SPACE(1,1) CYLINDERS
ALLOC DD(SORTWK03) UNIT(SYSDA) VOLUME(WRK$$$) +
                   SPACE(1,1) CYLINDERS
ALLOC DD(SORTWK04) UNIT(SYSDA) VOLUME(WRK$$$) +
                   SPACE(1,1) CYLINDERS
ALLOC DD(SORTOUT)  DSN('&OUTDSN') +
                   NEW CATALOG +
                   UNIT(SYSDA) VOLUME(WRK$$$) +
                   SPACE(5,5) TRACKS RELEASE +
                 RECFM(&RECFM) LRECL(&LRECL) BLKSIZE(&BLKSIZE) DSORG(PS)
ALLOC DD(SYSOUT)  DSN('&OUTSYS') +
                  NEW CATALOG +
                  UNIT(SYSDA) VOLUME(WRK$$$) +
                  SPACE(1,1) TRACKS RELEASE +
                  RECFM(F B) LRECL(121) BLKSIZE(23474) DSORG(PS)

SET ZEDLMSG = &STR(*** TALLYING UNIQUE VALUES BETWEEN +
                   &COL1 AND &COL2 ***)
ISPEXEC CONTROL DISPLAY LOCK
ISPEXEC DISPLAY MSG(UTLZ000W)

ISPEXEC SELECT PGM(SYNCSORT) PARM('CORE=MAX')

SET SSCC = &LASTCC

IF &SSCC ¬= 0 THEN +
    DO
        SET ZEDLMSG = &STR(*** SYNCSORT UNSUCCESSFUL. RC = &SSCC ***)
        ISPEXEC SETMSG MSG(UTLZ001)
        ISPEXEC EDIT DATASET('&OUTSYS')
        GOTO FINAL
    END

IF &VIEW = E THEN +
    ISPEXEC EDIT DATASET('&OUTDSN')
    IF &LASTCC > 8 THEN +
        ISPEXEC BROWSE DATASET('&OUTDSN')
ELSE +
    IF &VIEW = B THEN +
        ISPEXEC BROWSE DATASET('&OUTDSN')
GOTO FINAL

BATCH_SECTION: +
FREE DDNAME(SORTWK01 SYSIN SORTIN SORTOUT SYSOUT SYSPRINT SORTMSG +
            SORTWK02 SORTWK03 SORTWK04)
SET TEMPJCL = &STR(&SYSUID..TEMP.&INVOKE..JCL)
DELETE '&TEMPJCL'
FREE DD(TEMPDD)
ALLOC DD(TEMPDD) DSN('&TEMPJCL') +
                 NEW CATALOG +
                 UNIT(SYSDA) VOLUME(WRK$$$) +
                 SPACE(1,1) TRACKS RELEASE +
                 RECFM(F B) LRECL(80) BLKSIZE(23440) DSORG(PS)
FREE DD(TEMPDD ISPFILE)
ALLOC DD(ISPFILE) DSN('&TEMPJCL') OLD
ISPEXEC FTOPEN
ISPEXEC FTINCL COUNTKEY
SET INCLCC = &LASTCC
ISPEXEC FTCLOSE
FREE DD(ISPFILE)

IF &INCLCC = 0 THEN +
    DO
        SET ZEDSMSG = &STR(&INVOKE JOB SUBMITTED)
        SET ZEDLMSG = &STR(A BATCH JOB WAS SUBMITTED TO PROCESS YOUR +
                           "&INVOKE" REQUEST)
        ISPEXEC SETMSG MSG(UTLZ000)
        SUBMIT '&TEMPJCL'
    END
ELSE +
    DO
        SET ZEDSMSG = &STR(COULD NOT CREATE JCL)
        SET ZEDLMSG = &STR(CC "&INCLCC" RETURNED FROM JCL CREATION +
                           PROCESS)
        ISPEXEC SETMSG MSG(UTLZ001)
    END

FINAL: +
FREE DDNAME(SORTWK01 SYSIN SORTIN SORTOUT SYSOUT SYSPRINT SORTMSG +
            SORTWK02 SORTWK03 SORTWK04)
EXIT

HELPSEC: +
CLEAR
WRITE *** HELP FOR CLIST 'COUNTKEY' ***
WRITE
WRITE THE COUNTKEY CLIST ALLOWS THE USER TO SEARCH THROUGH SPECIFIED
WRITE COLUMNS WITHIN A DATASET AND COUNT THE NUMBER OF OCCURANCES OF
WRITE EACH UNIQUE STRING FOUND WITHIN THE SPECIFIED COLUMNS.  THE
WRITE RESULTS ARE PLACED IN A FILE AND THE USER IS THEN TAKEN INTO THAT
WRITE FILE.
WRITE
WRITE BASIC SYNTAX :
WRITE
WRITE COMMAND ===> TSO COUNTKEY
WRITE
WRITE THIS EXAMPLE WILL TAKE YOU INTO AN ISPF PANEL WHERE YOU MAY ENTER
WRITE A DATASET NAME, TWO COLUMN NUMBERS AND CHANGE OR LEAVE THE DEFAULT
WRITE VALUES FOR THE OUTPUT DATASET AND HOW OR IF YOU WANT TO
WRITE AUTOMATICALLY VIEW THE OUTPUT FROM THE UTILITY.
WRITE
WRITE OTHER EXAMPLES :
WRITE
WRITE COMMAND ===> TSO COUNTKEY DSN(XXXXX.XXXXXX.XXXXX)
WRITE
WRITE THIS EXAMPLE WILL TAKE YOU INTO THE ISPF PANEL WHERE THE DATASET
WRITE NAME WILL BE PREPOPULATED BUT YOU WILL HAVE TO ENTER THE COLUMN
WRITE NUMBERS.
WRITE
WRITE COMMAND ===> TSO COUNTKEY DSN(XXXXX.XXXXXX.XXXXX) COL1(1) COL2(2)
WRITE
WRITE THIS EXAMPLE WILL INVOKE THE UTILITY WITHOUT THE ISPF PANEL.  IN
WRITE THIS MODE, YOU WILL HAVE NO CHOICE AS TO THE OUTPUT VIEWING MODE,
WRITE OR THE OUTPUT DATASET.
WRITE
WRITE IF A DATASET CONTAINED THE FOLLOWING :
WRITE
WRITE =COLS> ----+----1----+
WRITE 000001 A9999BBBC888
WRITE 000002 A9999BBBC888
WRITE 000003 A9999BCBC888
WRITE 000004 A9999BDBC888
WRITE 000005 B9999BEBC888
WRITE 000006 B9999BFBC888
WRITE 000007 B9999BBBC888
WRITE 000008 B9999BABC888
WRITE 000009 C9999BSBC888
WRITE 000010 D9999BEBC888
WRITE 000011 D9999BSBC888
WRITE 000012 E9999BBBC888
WRITE
WRITE YOU COULD RUN COUNT KEY ON COLUMNS 1 5 AND GET THE FOLLOWING :
WRITE
WRITE KEY VALUE           NUMBER OF OCCURANCES
WRITE ---------           --------------------
WRITE A9999               0000000000000004
WRITE B9999               0000000000000004
WRITE C9999               0000000000000001
WRITE D9999               0000000000000002
WRITE E9999               0000000000000001
WRITE ----------------------------------------
WRITE TOTAL               0000000000000011
WRITE
WRITE FOR HELP WITH THE PANEL, EXECUTE COUNTKEY IN SUCH A WAY AS TO
WRITE ACCESS THE COUNTKEY PANEL AND THEN TYPE "HELP" IN THE COMMAND
WRITE LINE.
WRITE
WRITE YOU MAY ALSO EXECUTE THIS FUNCTION AS AN EDIT MACRO NAMED
WRITE "KEYCOUNT".  WHILE IN AN EDIT SESSION, TYPE "KEYCOUNT HELP" ON THE
WRITE COMMAND LINE FOR HELP IN HOW TO USE IT.
WRITE
WRITE *** END OF HELP *** NO PROCESSING PERFORMED ***
EXIT
            


Documentation


 This utility takes input of a dataset name (on an input panel) and two column
 numbers.  The two column numbers represent the beginning and ending columns of
 a physical 'field' within the record.  The unique string combinations found
 within this field are then tallied up, and the results placed in a dataset.
 The 'results' dataset will be automatically edited upon completion of the 'key
 count'.
            


Leave a Reply

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