COUNT Operator (for Beginners)


Summary

COUNT operator prints the count of records in a file and sets the return code based on the criteria match.

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)

Required Operands


  • FROM - FROM parameter specifies ddname of the input file.

Optional Operands


  • USING - USING operand specifies the first 4-characters of the ddname (xxxxCNTL) for the DFSORT control statement file.
  • 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.
  • NOTEMPTY - Sets RC=0 if the input file or subset is not empty.
  • HIGHER (x) - Sets RC=0 if the record count is equal to or lower than x.
  • LOWER (y) - Sets RC=0 if the record count is equal to or higher than y.
  • EQUAL (v) - Sets RC=0 if the record count is not equal v.
  • NOTEQUAL (w) - Sets RC=0 if the record count is equal w.
  • RC4 - RC4 is used to set RC=4 if the record count satisfies the specified criteria.
  • RC8 - RC8 is used to set RC=8 if the record count satisfies the specified criteria.
  • RC12 - RC12 is used to set RC=12 if the record count satisfies the specified criteria.
  • SUB (q) - Subtracts a value from the derived record count.
  • ADD (r) - Adds a value from the derived record count.
  • WRITE (countdd) - Specifies the ddname of the count file created by ICETOOL for this operation.
  • TEXT - Specify a string that is to be printed before the output records count.
  • DIGITS (d) - Specify the number of digits for the count in the output count file.
  • EDCOUNT (fromattling) - Specifies how the count is to be formatted for printing.
  • WIDTH (n) - Specifies the record length and LRECL for the count file.

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.