COUNT function can be used to print messages containing the count of records in a data set. It can also be used to subtract a value from the count or add a value to the count, to create an output data set containing text and the count, or to set RC=12, RC=8, RC=4, or RC=0 based on meeting criteria for the number of records in a data set.
If the criteria are met (for example, HIGHER(20) is specified and the record count is 21 or more), ICETOOL sets the following return code for the COUNT operator:
If the criteria are not met (for example, HIGHER(20) is specified and the record count is 20 or less), ICETOOL sets RC=0 for the COUNT operator.
COUNT FROM(DD2) HIGHER(20) RC4 USING(CTL2)
Sets RC=4 if more than 20 records are included from DD2, or sets RC=0 if 20 or fewer records are included from DD2.
COUNT FROM(DD1) EMPTY
Sets RC=12 if DD1 is empty, or sets RC=0 if DD1 is not empty.
>>-COUNT--FROM(indd)--+-------------+--+-------------+---------->
'-USING(xxxx)-' '-VSAMTYPE(x)-'
>--+-----------------+--+------+--+-------------+--+--------+--->
+-LOCALE(name)----+ +-RC4--+ +-EMPTY-------+ +-SUB(q)-+
+-LOCALE(CURRENT)-+ +-RC8--+ +-NOTEMPTY----+ '-ADD(r)-'
'-LOCALE(NONE)----' '-RC12-' +-HIGHER(x)---+
+-LOWER(y)----+
+-EQUAL(v)----+
'-NOTEQUAL(w)-'
>--+----------------+--+----------------+----------------------->
'-WRITE(countdd)-' '-TEXT('string')-'
>--+---------------------+--+----------+-----------------------><
+-DIGITS(d)-----------+ '-WIDTH(n)-'
'-EDCOUNT(formatting)-' There are multiple ways to find the number of records in a file. One way is to add a sequence number field to the record. Or just use a COPY and look at the job output to see how many records SORT found or use the COUNT function of SORT.
Example 1:Count the number of records in the input file by using COUNT.
COUNT FROM(IN2) WRITE(CT2) TEXT('Count is ') -
EDCOUNT(A1,U10) WIDTH(100)
Prints a message containing the count of records in the IN2 data set. Writes an 100-byte record with the specified string and an edited count to the CT2 data set. If IN2 contains 1234567 records, the 80-byte output record in CT2 would look like this:
Output: Count is 1,234,567 Example 2:Count the number of records in the input file by using COUNT with the arithmetic operation.
COUNT FROM(IN3) WRITE(CT3) DIGITS(8) SUB(2) Subtracts 2 from the count of records in the IN3 data set. Prints a message containing the modified count. Writes a 8-byte record with the modified count to the CT3 data set. If IN3 contains 9999 records, the 8-byte output record in CT3 would look like this: Output: 00009999
Example 3: Count the number of records in the input file by using COUNT.
//STEP010 EXEC PGM=ICETOOL //TOOLMSG DD SYSOUT=* //DFSMSG DD SYSOUT=* //DD01 DD DSN=... input file // DISP=SHR //TOOLIN DD * COUNT FROM(DD01) /* Output: 00009999
Example 4:Count the number of records in the input file by using TRAILER and COUNT.
//STEP1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=... input file
//SORTOUT DD DSN=... output file
//SYSIN DD *
SORT FIELDS=COPY
OUTFIL REMOVECC,NODETAIL,
TRAILER1=('Count of records: ',COUNT=(M11,LENGTH=8))
/*
Output: Count of records: 00009999 Example 5: If you have two fields, one State field in positions 1-15 and City field in positions 16-30, and you want to count the number of records and store as a third field then use sequence number starting from 1 and increment by 1, you could use START=1 and INCR=1 as shown in the following statements:
//STEP1 EXEC PGM=SORT //SYSOUT DD SYSOUT=* //SORTIN DD DSN=... input file //SORTOUT DD DSN=... output file //SYSIN DD * SORT FIELDS=COPY OUTREC OVERLAY=(32:SEQNUM,5,ZD,START=1,INCR=1) /* Output XXXXXX 00001 YYYYYY 00002 …… …… ZZZZZZ 00026
The Product Owner role has shifted from just being a requirements proxy to a strategic,…
Business Value: In the world of Agile development, the user story has long been the…
The SAFe Scrum Master certification has become one of the most sought-after credentials for Agile…
The Professional Scrum with Kanban (PSK) course enhances your organization's ability to deliver value efficiently…
Effective User interviews play a crucial role in Scrum methodology, helping Product Owners and Scrum…
Product Owners should be well-versed in various user research tools and techniques to effectively understand…