how to count the records in a file using sort jcl

Created on May 11, 2021, 12:34 p.m. - by Henry, Iris


I want to count the number of records in a file using the JCL sort utility and have to copy them to a specific position in an output file.

Please help me.


Comments (7)

Parker, Paul
May 12, 2021, 4:18 p.m.

Try with OUTFIL REMOVECC command


Henry, Iris
May 15, 2021, 4:49 a.m.

I tried but not it is not working. if possible Please share example code


Jackson, Nathaniel
May 15, 2021, 4:56 a.m.

Try this code,

//SYSIN    DD    *                                           
 SORT FIELDS=COPY                                             
 OUTFIL REMOVECC,NODETAIL,                                             
 TRAILER1=('NUMBER OF RECORDS ARE:
',COUNT=(M11,LENGTH=8))     
/*     


Henry, Iris
May 15, 2021, 5:25 a.m.

I don't see any record in the output file.  

Actually, my requirement is to count the number of records in a file. And then want to copy that count in a trailer record in the output file.


Jackson, Nathaniel
May 16, 2021, 2:58 a.m.

Remove NODETAIL from the SYSIN command to include the detailed report.

 

And, add specific position(see below code) on the trailer record based on your record layout,

TRAILER1=(30:'NUMBER OF RECORDS ARE:',COUNT=(M11,LENGTH=8)) 


Jack, Peter
May 16, 2021, 3:01 a.m.

it is not clear. Please show me some example code to understand


Jackson, Nathaniel
May 16, 2021, 3:03 a.m.

see this example,

CODE:

//S1    EXEC  PGM=SORT                                       
//SYSOUT    DD  SYSOUT=*                                     
//SORTIN DD *                                                 
DETAIL RECORD 1                                               
DETAIL RECORD 2                                               
DETAIL RECORD 3                                               
DETAIL RECORD 4                                               
DETAIL RECORD 5                                               
/*                                                           
//SORTOUT DD SYSOUT=*                                         
//SYSIN    DD    *                                           
 SORT FIELDS=COPY                                             
 OUTFIL REMOVECC,                                             
 TRAILER1=('NUMBER OF RECORDS ARE:
',COUNT=(M11,LENGTH=8))     
/*     

 

OUTPUT:

DETAIL RECORD 1                     
DETAIL RECORD 2                     
DETAIL RECORD 3                     
DETAIL RECORD 4                     
DETAIL RECORD 5                     
NUMBER OF RECORDS ARE:00000005


Copyright 2020 by ibmmainframer. All Rights Reserved.