Displays the records count (COUNT Operator)


COUNT operator displays the count of file records (that satisfies the condition) in the spool. It can be used to -

  • Subtracts a value from the count.
  • Adds a value to the count.
  • Creates an output file that contains user-defined text and the count or just the count.
  • Sets RC=12, RC=8, or RC=4 if the record count met the coded criteria or RC=0 if the record count does not met the coded 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)

Required Operands


  • FROM - specifies ddname of the input file. It is mandatory if FROM is coded.

Optional Operands


  • USING - specifies the first 4-characters of the ddname (xxxxCNTL) for the DFSORT control statement. XXXX name is the user-defined name. xxxxCNTL DD statement is mandatory if USING(xxxx) is coded. Either TO, USING, or both operands can code at the same time.
  • VSAMTYPE - specifies the record format for a VSAM input file. It should be either F (fixed-length) or V (variable-length) record processing.
  • EMPTY - Sets RC=0 if the input file is empty. Sets RC=12 (or RC=8 when RC8 is specified, or RC=4 when RC4 is specified) if the input file is not empty.
  • NOTEMPTY - Sets RC=0 if the input file is not empty. Sets RC=12 (or RC=8 when RC8 is specified, or RC=4 when RC4 is specified) if the input file is empty.
  • HIGHER (x), LOWER (y), EQUAL (v), NOTEQUAL (w) - Sets RC=0 if the record count satisfies the given condition. 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, y, v, and w should be specified as n, +n, or -n where n can be 1 to 31 digits. x, y, v and w values can be in between 0 to 562949953421310.
  • RC4, RC8, RC12 - used to set the respective values( RC4 sets RC=4, RC8 sets RC=8 and RC12 sets RC=12) if the record count satisfies the coded criteria. It can be coded only when EMPTY, NOTEMPTY, HIGHER(x), LOWER(y), EQUAL(v), or NOTEQUAL(w) operands are coded. It overrides the default RC=12 for this COUNT operator if the record count satisfies the given criteria.
  • 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. 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 file. n value range from 1 to 32760.

Example -


Scenario - Count the records whose country is 'IN' (from 60th byte of length 2).

INPUT - MATEPK.INPUT.PSFILE

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
001  PAWAN         MAINFRAME           JPM       AP        IN        0000100000
002  SRINIVAS      TESTING             ORACLE    TG        IN        0000095000
003  SRIDHAR       SAS                 CG        OR        US        0000080000
004  VENKATESH     ABAP                CSC       CA        IN        0000053000
005  RAVI          HADOOP              CTS       FL        US        0000072000
006  PRASAD        HR                  INFOSYS   MI        US        0000066000
007  RAJA          TESTING             IBM       CA        US        0000047000

JCL -

----+----1----+----2----+----3----+----4----+----5----+
...
//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 (SDSF SPOOL) - Verify TOOLMSG for the return code of the submitted job.

COUNT TOOLMSG