Count the records and print at end.

In this Mainframe Forum - You can post your queries on DFSORT, ICETOOL , SyncSort & JCL Utilities

Moderators: Frank Yaeger, Moderator Group

Post Reply
User avatar
anilanju
Member
Posts: 47
Joined: Mon Nov 10, 2008 6:59 pm

Count the records and print at end.

Post by anilanju » Wed Jun 17, 2009 3:27 pm

Hi

i need to count the number of recors in a fil and write them in the end
of the file.

example:

HTEST
123968711BM
234968711CM
234968896BM
567968858DM
567968889AM
TRILER

HERE in trailer i want the number of records to be printed.example here total is 5.

rec lenght: 38
rec format: FB

Regards

Alissa Margulies
Member
Posts: 25
Joined: Tue Apr 28, 2009 10:53 pm
Location: USA
Contact:

Post by Alissa Margulies » Wed Jun 17, 2009 7:38 pm

Are the HEADER and TRAILER records already part of the data set? If so, here is a SyncSort for z/OS job that will produce the record count:

Code: Select all

//SORT1 EXEC PGM=SORT                       
//SORTOUT DD SYSOUT=*                       
//SYSOUT  DD SYSOUT=*                       
//SORTIN  DD *                              
HTEST                                       
123968711BM                                 
234968711CM                                 
234968896BM                                 
567968858DM                                 
567968889AM                                 
TRILER                                      
//SYSIN   DD *                              
   OMIT COND=(1,6,CH,EQ,C'TRILER')          
   SORT FIELDS=COPY                         
   OUTFIL FILES=OUT,                        
    TRAILER1=(1:C'TOTAL RECORD COUNT IS',1X,
    COUNT-1=(EDIT=(IIIT))),REMOVECC         
/*                                          
This is the output produced from the above job:

Code: Select all

HTEST                     
123968711BM               
234968711CM               
234968896BM               
567968858DM               
567968889AM               
TOTAL RECORD COUNT IS    5
Alissa Margulies
SyncSort Mainframe Product Services
zos_tech@syncsort.com
201-930-8260

User avatar
anilanju
Member
Posts: 47
Joined: Mon Nov 10, 2008 6:59 pm

Post by anilanju » Wed Jun 17, 2009 8:46 pm

Hi Alissa

Thank you very much. :D

Regards

skolusu
Member
Posts: 43
Joined: Sat Jul 26, 2008 12:38 am

Post by skolusu » Wed Jun 17, 2009 9:00 pm

anilanju,

If you want to update the existing trailer record without creating a new one, then use the following DFSORT JCL

Code: Select all

//STEP0100 EXEC PGM=SORT                                        
//SYSOUT   DD SYSOUT=*                                          
//SORTIN   DD *                                                 
HTEST                                                           
123968711BM                                                     
234968711CM                                                     
234968896BM                                                     
567968858DM                                                     
567968889AM                                                     
TRILER                                                          
//SORTOUT  DD SYSOUT=*                                          
//SYSIN    DD *                                                 
  SORT FIELDS=COPY                                              
  INREC IFOUTLEN=38,IFTHEN=(WHEN=INIT,OVERLAY=(39:SEQNUM,5,ZD)),
  IFTHEN=(WHEN=(1,6,CH,EQ,C'TRILER'),                           
  OVERLAY=(10:39,5,ZD,SUB,+2,M10,LENGTH=5))                     
/*
The output from this job is

Code: Select all

HTEST         
123968711BM   
234968711CM   
234968896BM   
567968858DM   
567968889AM   
TRILER       5
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

User avatar
anilanju
Member
Posts: 47
Joined: Mon Nov 10, 2008 6:59 pm

Post by anilanju » Thu Jun 18, 2009 4:55 pm

Hi

The code is working fine.

but i just have small query.
OMIT COND=(1,1,CH,EQ,C'T')
SORT FIELDS=COPY
OUTFIL FILES=OUT,
TRAILER1=(1:C'T',1X,
COUNT-1=(EDIT=(IIIIIIT))),REMOVECC
END

from this the trailer record i am getting is
T 103235

i want these spaces to be removed, as the number of records is not fixed.

i want the output as
T103235, so whenever the count changes, it moves
for example:if count is 1000025 then it should be
T1000025.

Alissa Margulies
Member
Posts: 25
Joined: Tue Apr 28, 2009 10:53 pm
Location: USA
Contact:

Post by Alissa Margulies » Thu Jun 18, 2009 8:15 pm

One alternative is to print the leading zeros:

Code: Select all

//SYSIN DD *                          
  OMIT COND=(1,1,CH,EQ,C'T')          
  SORT FIELDS=COPY                    
  OUTFIL FILES=OUT,                   
    TRAILER1=(1:C'T',                   
    COUNT-1=(EDIT=(TTTTTTT))),REMOVECC                                
/*                                    
Producing these results:

Code: Select all

HTEST      
123968711BM
234968711CM
234968896BM
567968858DM
567968889AM
T0000005   
Another alternative is to modify Kolusu's job as follows:

Code: Select all

//SYSIN    DD *                                                 
  SORT FIELDS=COPY                                              
  INREC IFOUTLEN=38,
    IFTHEN=(WHEN=INIT,OVERLAY=(39:SEQNUM,5,ZD)),
    IFTHEN=(WHEN=(1,1,CH,EQ,C'T'),                                
    OVERLAY=(2:39,5,ZD,SUB,+2,M10,LENGTH=5),HIT=NEXT),            
    IFTHEN=(WHEN=(1,1,CH,EQ,C'T'),                                
    BUILD=(1,1,2,5,JFY=(SHIFT=LEFT)))                             
/*                             
Which produces these results:

Code: Select all

HTEST      
123968711BM
234968711CM
234968896BM
567968858DM
567968889AM
T5         
Alissa Margulies
SyncSort Mainframe Product Services
zos_tech@syncsort.com
201-930-8260

skolusu
Member
Posts: 43
Joined: Sat Jul 26, 2008 12:38 am

Post by skolusu » Thu Jun 18, 2009 8:59 pm

Alissa Margulies,

You really don't need the extra IFTHEN. you can do it in the same pass.

Code: Select all

//SYSIN    DD *                                                    
  SORT FIELDS=COPY                                                 
  INREC IFOUTLEN=38,IFTHEN=(WHEN=INIT,OVERLAY=(39:SEQNUM,5,ZD)),   
  IFTHEN=(WHEN=(1,6,CH,EQ,C'T'),                                   
  OVERLAY=(39:39,5,ZD,SUB,+2,M10,LENGTH=5,2:39,5,JFY=(SHIFT=LEFT)))
/*
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

academyindia4

Topic deleted by Admin

Post by academyindia4 » Mon Jan 25, 2016 10:31 pm

<< Content deleted By Admin >>

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others