COUNT Operator (for Experienced)


Summary

For basic information, go through the COUNT Operator (for Beginners)

  • COUNT operator prints message with the count of records in a file.
  • COUNT can be used to -
    • Subtract a value from the count.
    • Add a value to the count.
    • Create an output file containing user-defined text and the count or just the count.
    • Sets RC=12, RC=8, or RC=4 if the record count meets specified criteria or RC=0 if the record count does not meet specified criteria.

Syntax -

Count all records in the input file -

  COUNT FROM(indd)

Count using DFSORT control card -

  COUNT FROM(indd) USING(xxxx)

Setting RC using parameters -

  COUNT FROM(indd) EMPTY

Sets RC=12 if indd file is empty (indd has no records), or sets RC=0 if indd is not empty (indd has at least one record). Similarly for NOEMPTY, HIGHER, LOWER, EQUAL, NOTEQUAL parameters.

Setting RC explicitlt using parameters -

  COUNT FROM(indd) HIGHER(1000) RC8 USING(xxxx)

Sets RC=8 if more than 1000 records are selected from indd based on control card USING(xxxx), or sets RC=0 if 1000 or fewer records are included from indd.

Creating custom record with the count -

  COUNT FROM(indd) WRITE(count) -
  DIGITS(d)  - 
  WIDTH(record-length)

Creating custom record with the count and user-defined text -

  COUNT FROM(indd) WRITE(count) TEXT('string') -
  DIGITS(d) | EDCOUNT(fromatting) - 
  WIDTH(record-length)
COUNT Operator

Required Operands


FROM -

  • FROM parameter specifies ddname of the input file.
  • indd DD statement is mandatory if FROM operand specified.

Optional Operands


USING -

  • USING operand specifies the first 4-characters of the ddname (xxxxCNTL) for the DFSORT control statement file.
  • XXXX name is the user-defined name.
  • xxxxCNTL DD statement is mandatory if USING(xxxx) is specified.
  • Either TO, USING, or both operands can code at the same time.

VSAMTYPE -

  • VSAMTYPE operand specifies the record format for a VSAM input file (F or V).

EMPTY -

  • Sets RC=0 if the input file or subset is empty.
  • Sets RC=12 (or RC=8 when RC8 is specified, or RC=4 when RC4 is specified) if the input file or subset is not empty.

NOTEMPTY -

  • Sets RC=0 if the input file or subset is not empty.
  • Sets RC=12 (or RC=8 when RC8 is specified, or RC=4 when RC4 is specified) if the input file or subset is empty.

HIGHER (x) -

  • Sets RC=0 if the record count is equal to or lower than x.
  • Sets RC=12 (or RC=8 when RC8 is specified, or RC=4 when RC4 is specified) if the record count is higher than x.
  • x value can be in between 0 to 562949953421310.

LOWER (y) -

  • Sets RC=0 if the record count is equal to or higher than y.
  • Sets RC=12 (or RC=8 when RC8 is specified, or RC=4 when RC4 is specified) if the record count is lower than y.
  • y value can be in between 0 to 562949953421310.

EQUAL (v) -

  • Sets RC=0 if the record count is not equal v.
  • Sets RC=12 (or RC=8 when RC8 is specified, or RC=4 when RC4 is specified) if the record count is equal to v.
  • v value can be in between 0 to 562949953421310.

NOTEQUAL (w) -

  • Sets RC=0 if the record count is equal w.
  • Sets RC=12 (or RC=8 when RC8 is specified, or RC=4 when RC4 is specified) if the record count is equal to w.
  • w value can be in between 0 to 562949953421310.

RC4 -

  • RC4 is used to set RC=4 if the record count satisfies the specified criteria.
  • RC4 can be specified only with EMPTY, NOTEMPTY, HIGHER(x), LOWER(y), EQUAL(v), or NOTEQUAL(w) operands.
  • RC4 overrides the default RC=12 for this COUNT operator if the record count satisfies the given criteria.

RC8 -

  • RC8 is used to set RC=8 if the record count satisfies the specified criteria.
  • RC8 can be specified only with EMPTY, NOTEMPTY, HIGHER(x), LOWER(y), EQUAL(v), or NOTEQUAL(w) operands.
  • RC8 overrides the default RC=12 for this COUNT operator if the record count satisfies the given criteria.

RC12 -

  • RC12 is used to set RC=12 if the record count satisfies the specified criteria.
  • RC12 can be specified only with EMPTY, NOTEMPTY, HIGHER(x), LOWER(y), EQUAL(v), or NOTEQUAL(w) operands.

SUB (q) -

  • Subtracts a value from the derived record count.
  • The record count is set to 0 if SUB reduces the record count below 0.
  • 'q' value can be between 1 to 999.

ADD (r) -

  • Adds a value from the derived record count.
  • 'r' value can be between 1 to 999.

WRITE (countdd) -

  • Specifies the ddname of the count file created by ICETOOL for this operation.
  • A countdd DD statement should be present.
  • RECFM is set to FB.

TEXT -

  • Specify a string that is to be printed before the output records count.
  • The string can be 1 to 50 characters.

DIGITS (d) -

  • Specify the number of digits for the count in the output count file.
  • ā€˜dā€™ value can be 1 to 15.

EDCOUNT (fromattling) -

  • Specifies how the count is to be formatted for printing.
  • The formatting items are - mask, E'pattern', L'string', F'string', T'string', LZ and Udd.

WIDTH (n) -

  • Specifies the record length and LRECL for the count file.
  • n value range from 1 to 32760.

Example -


Scenario - count the employee records whose country is 'IN' (from 60th byte of length 2) to output dataset.

INPUT - MATEPK.INPUT.PSFILE

 BROWSE    MATEPK.INPUT.PSFILE                        Line 00000000 Col 001 080 
 Command ===>                                                  Scroll ===> CSR  
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* Top of Data **********************************
001  PAWAN         MAINFRAME           JPM       AP        IN                   
002  SRINIVAS      TESTING             ORACLE    TG        IN                   
003  SRIDHAR       SAS                 CG        OR        US                   
004  VENKATESH     ABAP                CSC       CA        US                   
005  RAVI          HADOOP              CTS       FL        US                   
006  PRASAD        HR                  INFOSYS   MI        US                   
007  RAJA          TESTING             IBM       CA        US                   
******************************** Bottom of Data ********************************

JCL -

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
***************************** Top of Data ******************************
//MATEPKCO JOB (123),'MATEPK',CLASS=A,MSGCLASS=A,MSGLEVEL=(1,1),        
//             NOTIFY=&SYSUID                                           
//*                                                                     
//STEP01   EXEC PGM=ICETOOL                                             
//INDD     DD DSN=MATEPK.INPUT.PSFILE,DISP=SHR                          
//TOOLIN   DD *                                                         
  COUNT FROM(INDD) USING(CTL1)                                          
/*                                                                      
//CTL1CNTL DD *                                                         
  INCLUDE COND=(60,2,CH,EQ,C'IN')                                       
/*                                                                      
//TOOLMSG  DD SYSOUT=*                                                  
//DFSMSG   DD SYSOUT=*                                                  
//                                                                      
**************************** Bottom of Data ****************************

TOOLMSG (SDSF SPOOL) - Verify TOOLMSG for the return code of the submitted job.

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9
********************************* TOP OF DATA ********************************************
1ICE600I 0 DFSORT ICETOOL UTILITY RUN STARTED                                   
                                                                                
 ICE650I 0 VISIT http://www.ibm.com/storage/dfsort FOR ICETOOL PAPERS, EXAMPLES AND MORE 
                                                                                
 ICE632I 0 SOURCE FOR ICETOOL STATEMENTS:  TOOLIN                               
                                                                                
                                                                                
 ICE630I 0 MODE IN EFFECT:  STOP                                                
                                                                                
            COUNT FROM(INDD) USING(CTL1)                                        
ICE606I 0 DFSORT CALL 0001 FOR COPY  FROM INDD     TO E35 EXIT USING CTL1CNTL COMPLETED 
ICE628I 0 RECORD COUNT:  000000000000002                                        
ICE602I 0 OPERATION RETURN CODE:  00                                            
                                                                                
 ICE601I 0 DFSORT ICETOOL UTILITY RUN ENDED - RETURN CODE:  00                  
******************************** BOTTOM OF DATA ******************************************

Explaining Solution -

  • INDD - Specifies the ddname for input file.
  • TOOLIN DD * - Specifies the ICETOOL statements for DFSORT.
  • CTL1CNTL DD * - Specifies the DFSORT statements for processing.
  • TOOLMSG - Specifies where to write the ICETOOL processing messages.
  • DFSMSG - Specifies where to write the DFSORT processing messages.
  • COUNT FROM(INDD) USING(CTL1) - Counts the records from INDD based on the DFSORT statements specified in CTL1.
  • INCLUDE COND=(60,2,CH,EQ,C'IN') ā€“ condition to filter the rows that are having 'IN' from position 60 - 61.