JCL

COUNT Function: Count number of records in a file

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:

  • RC=12 if RC12 is specified, or by default if RC8 and RC4 are not specified
  • RC=8 if RC8 is specified
  • RC=4 if RC4 is specified

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 Function Syntax

>>-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

Include Omit Condition: Click Here SYNCSORT Manual: Click Here

Admin

Share
Published by
Admin

Recent Posts

Increase Transparency and Collaboration Product Backlog

A well-maintained product backlog is crucial for successful product development. It serves as a single…

4 days ago

Product Backlog – Incremental value to the customer

Incremental value to the customer refers to the gradual delivery of small, functional parts of…

6 days ago

Product Market, Customer’s Desire, Need, and Challenges

A Product Market refers to the group of potential customers who might be interested in…

1 week ago

PAL-EBM Professional Agile Leadership – EBM Certification

The Professional Agile Leadership - Evidence-Based Management (PAL-EBM) certification offered by Scrum.org is designed for…

3 months ago

PAL I Professional Agile Leadership Certification

The Professional Agile Leadership (PAL I) certification, offered by Scrum.org, is designed to equip leaders…

4 months ago

Scrum Master Certification: CSM, PSM, SSM

Choosing the right Scrum Master Certification depends on your current experience and career goals. If…

5 months ago