IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

SORT to count Number of Records in a File


IBM Mainframe Forums -> JCL & VSAM
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Ankita Maheshwari

New User


Joined: 12 May 2010
Posts: 23
Location: Pune

PostPosted: Wed May 12, 2010 3:24 pm
Reply with quote

I want to count no. of records in a file using JCL sort and need to copy them to a specific position in a file.

Please suggest how can this be done.
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Wed May 12, 2010 3:27 pm
Reply with quote

Welcome...

show sample records and expected output.

Quote:
count no. of records in a file using JCL sort and need to copy them to a specific position in a file


Your wording is not clear to me.

What is LRECL\RECFM of the file?
What is the sort product you are using?
Back to top
View user's profile Send private message
Ankita Maheshwari

New User


Joined: 12 May 2010
Posts: 23
Location: Pune

PostPosted: Wed May 12, 2010 3:34 pm
Reply with quote

I want to use simple sort to count number of records in a file. And then want to copy that count in a file at a specific position.
Back to top
View user's profile Send private message
Ankita Maheshwari

New User


Joined: 12 May 2010
Posts: 23
Location: Pune

PostPosted: Wed May 12, 2010 3:36 pm
Reply with quote

Input file: Has 11 records
Output file needs to be in the format:

TRAILER 'some date' 'some date' 000000011(this is the count of records)
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Wed May 12, 2010 4:58 pm
Reply with quote

Still did not understand what is 'some date' 'some date' but below step will assist you.

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

Code:


DETAIL RECORD 1                     
DETAIL RECORD 2                     
DETAIL RECORD 3                     
DETAIL RECORD 4                     
DETAIL RECORD 5                     
NUMBER OF RECORDS ARE:00000005
Back to top
View user's profile Send private message
Ankita Maheshwari

New User


Joined: 12 May 2010
Posts: 23
Location: Pune

PostPosted: Wed May 12, 2010 5:08 pm
Reply with quote

In the output i do not want:

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

I only want:

NUMBER OF RECORDS ARE:00000005

Please tell me what changes to be made for expected output.
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Wed May 12, 2010 5:13 pm
Reply with quote

use..
Code:

//SYSIN    DD    *                                           
 SORT FIELDS=COPY                                             
 OUTFIL REMOVECC,NODETAIL,                                             
 TRAILER1=('NUMBER OF RECORDS ARE:
',COUNT=(M11,LENGTH=8))     
/*     
Back to top
View user's profile Send private message
gcicchet

Senior Member


Joined: 28 Jul 2006
Posts: 1702
Location: Australia

PostPosted: Wed May 12, 2010 5:14 pm
Reply with quote

Hi,

just change to
Code:
  OUTFIL REMOVECC,NODETAIL,   



Gerry
Back to top
View user's profile Send private message
Ankita Maheshwari

New User


Joined: 12 May 2010
Posts: 23
Location: Pune

PostPosted: Wed May 12, 2010 5:21 pm
Reply with quote

THANKS, it is working, i am placing total count into a file. Now the requirement is to place that count at 30th position in the file. Can this sort card be changed to add the specific position? Also can i specify two files in sortin?
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Wed May 12, 2010 6:22 pm
Reply with quote

Change this to....
Code:
TRAILER1=(30:'NUMBER OF RECORDS ARE:',COUNT=(M11,LENGTH=8))   
How many files do you have? Did you try concatenating all of them?
Back to top
View user's profile Send private message
Ankita Maheshwari

New User


Joined: 12 May 2010
Posts: 23
Location: Pune

PostPosted: Wed May 12, 2010 6:35 pm
Reply with quote

actually, i have two files........

one contain data as:

000000011

and other contain data as:

TRAILER 20100202 20100202

The output file i require is

TRAILER 20100202 20100202 000000011.

Please tell me how can i concatenate these two files in the format which is needed in output file.

Thanks
Ankita
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Wed May 12, 2010 6:42 pm
Reply with quote

Ankita Maheshwari,

You have not shown how your input records look like. Now it looks like a change in requirement. Till now it was like you are trying to count the records in the input file, but it looks like the input file itself has the 'COUNT'.

Tell exactly what you're trying to do if you are looking for some useful suggestions.
Back to top
View user's profile Send private message
Ankita Maheshwari

New User


Joined: 12 May 2010
Posts: 23
Location: Pune

PostPosted: Wed May 12, 2010 6:53 pm
Reply with quote

ok.....

i count no. of records and placed them in a input file.

Now i need to concat that input file to another file.

Formats of all the file are:

File with count:

000000011

File with other data:

TRAILER 20100202 20100202

The output file should look like:

TRAILER 20100202 20100202 000000011

Please help.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Thu May 13, 2010 2:36 pm
Reply with quote

Code:
TRAILER 20100202 20100202
Where is this data coming from? Looks like date fields. How do you generate this file? There may be a possiblity where you can get your final output file from your original input file itself rather than concatenating intermediate outputs.(Only if you are willing to explain more)
Back to top
View user's profile Send private message
Ankita Maheshwari

New User


Joined: 12 May 2010
Posts: 23
Location: Pune

PostPosted: Thu May 13, 2010 3:43 pm
Reply with quote

As you can see there are two files from where i am recieving the data, and the dates can only be taken from the file i have mentioned. Date file is generated after running a SQL query. This SQL query fetches the date from a table. The two input files are:

File with count:

000000011

File with other data:

TRAILER 20100202 20100202


I am not finiding a way to concat both the files this way:

TRAILER 20100202 20100202 000000011
Back to top
View user's profile Send private message
Ankita Maheshwari

New User


Joined: 12 May 2010
Posts: 23
Location: Pune

PostPosted: Thu May 13, 2010 4:11 pm
Reply with quote

Code:
//******************************************************
//* STEP TO COUNT NO. OF RECORDS IN A FILE                             
//*                                                                     
//***********************************************************
//S002    EXEC PGM=ICETOOL                                             
//IN3     DD  DSN=PFC0010.EXTRACT.REPROCES.BLANK,                 
//            DISP=SHR                                                 
//CT3     DD  DSN=PFC0010.EXTRACT.REPROCES.BLANK1,               
//            DISP=(NEW,CATLG,DELETE),                                 
//            UNIT=SYSDA,                                               
//            SPACE=(80,(100,50),RLSE),                                 
//            AVGREC=K,                                                 
//            DCB=(RECFM=FB,LRECL=80,BLKSIZE=0,DSORG=PS)               
//TOOLMSG DD  SYSOUT=*                                                 
//DFSMSG  DD  SYSOUT=*                                                 
//TOOLIN  DD  *                                                         
COUNT FROM(IN3) WRITE(CT3)                                             
/*                                                                     
//***********************************************************
//*                    GENERATE OUTPUT HEADER FILE                     
//***********************************************************
//S004    EXEC PGM=SORT                                                 
//SORTIN  DD  DSN=PFC0010.EXTRACT.REPROCES.DATE,                 
//            DISP=SHR                                                 
//SORTOUT DD DSN=PFC0010.EXTRACT.REPROCES.BLANK3.HEADER,         
//            DISP=(NEW,CATLG,DELETE),                                 
//            UNIT=SYSDA,                                               
//            SPACE=(80,(100,50),RLSE),                                 
//            AVGREC=K,                                                 
//            DCB=(RECFM=FB,LRECL=80,BLKSIZE=0,DSORG=PS)               
//SYSOUT   DD  SYSOUT=*                                                 
//SYSUDUMP DD  SYSOUT=*                                                 
//SYSIN    DD  *                                                       
  SORT FIELDS=COPY                                                     
  OUTREC  FIELDS=(3:C'HEADER',11:1,8,20:9,8,29:C'SBT')                 
/*                                                                     
//***********************************************************
//*                    GENERATE OUTPUT TRAILER FILE                     
//***********************************************************

In this step i want to add one more file which contain the counts and then want to merge the file.


Code:
//S005    EXEC PGM=SORT                                                 
//SORTIN  DD  DSN=PFC0010.EXTRACT.REPROCES.BLANK3.HEADER,         
//            DISP=SHR                                                 
//SORTOUT DD  DSN=PFC0010.EXTRACT.REPROCES.TRAILER,               
//            DISP=(NEW,CATLG,DELETE),                                 
//            UNIT=SYSDA,                                               
//            SPACE=(80,(100,50),RLSE),                                 
//            AVGREC=K,                                                 
//            DCB=(RECFM=FB,LRECL=80,BLKSIZE=0,DSORG=PS)               
//SYSOUT   DD  SYSOUT=*                                                 
//SYSUDUMP DD  SYSOUT=*                                                 
//SYSIN    DD  *                                                       
  SORT FIELDS=COPY                                                     
  OUTREC  FIELDS=(4:C'TRAILER',12:11,8,21:20,8)                         
/*                                                                     
//**********************************************************

Please refer this JCL
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Thu May 13, 2010 9:37 pm
Reply with quote

if You will learn to use the code tags people willing to answer will have less trouble in understanding You JCLs
Back to top
View user's profile Send private message
sril.krishy

Active User


Joined: 30 Jul 2005
Posts: 183
Location: hyderabad

PostPosted: Thu May 13, 2010 11:56 pm
Reply with quote

Hi,
Search for SYMNAMES in the forum. It may help to get the desired results.

Thanks
Krishy
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Fri May 14, 2010 8:49 am
Reply with quote

Ankita Maheshwari wrote:
As you can see there are two files from where i am recieving the data, and the dates can only be taken from the file i have mentioned. Date file is generated after running a SQL query. This SQL query fetches the date from a table. The two input files are:

File with count:

000000011

File with other data:

TRAILER 20100202 20100202


I am not finiding a way to concat both the files this way:

TRAILER 20100202 20100202 000000011


Ankita, there is no need of two step solution for this.
Concatenate both files(one with data, other with one record with date)
Use below step to to get desired result.
Code:

//S1    EXEC  PGM=SORT                                                 
//SYSOUT    DD  SYSOUT=*                                               
//SORTIN DD *                *THIS IS YOUR DATA FILE                   
DETAIL RECORD 1                                                       
DETAIL RECORD 2                                                       
DETAIL RECORD 3                                                       
DETAIL RECORD 4                                                       
DETAIL RECORD 5                                                       
/*                                                                     
//       DD *                *THIS IS YOUR DATE FILE WITH ONE RECORD   
TRAILER 20100202 20100202                                             
//SORTOUT DD SYSOUT=*                                                 
//SYSIN    DD    *                                                     
 SORT FIELDS=COPY                                                     
 OUTFIL REMOVECC,NODETAIL,                                             
 TRAILER1=(1,26,COUNT-1=(M11,LENGTH=8))  *NOTE HERE COUNT IS SUBTRACTED
/*                                       *BY 1                                                       

Output will be
Code:

TRAILER 20100202 20100202 00000005   
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Fri May 14, 2010 11:21 am
Reply with quote

Ankita Maheshwari,

SyncSort provides DB2 SQL query support since its 1.2 release. May be if you let us know what is this all about, we can offer some useful suggestions. Show us the SQL which you are running. And how are these dates related to the count which you obtain from the other file?
Back to top
View user's profile Send private message
Ankita Maheshwari

New User


Joined: 12 May 2010
Posts: 23
Location: Pune

PostPosted: Fri May 14, 2010 12:06 pm
Reply with quote

thanks, it worked fine icon_smile.gif

Just a question.................

why did we used : OUTFIL REMOVECC,NODETAIL,

Thanks
Ankita
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Fri May 14, 2010 12:10 pm
Reply with quote

Ankita Maheshwari wrote:
thanks, it worked fine icon_smile.gif

Just a question.................

why did we used : OUTFIL REMOVECC,NODETAIL,

Thanks
Ankita

because you did not wanted detail records to come in output.. icon_smile.gif
Back to top
View user's profile Send private message
Ankita Maheshwari

New User


Joined: 12 May 2010
Posts: 23
Location: Pune

PostPosted: Fri May 14, 2010 12:23 pm
Reply with quote

thanks icon_smile.gif
Back to top
View user's profile Send private message
donateeye
Warnings : 2

New User


Joined: 01 Jun 2007
Posts: 62
Location: chennai

PostPosted: Fri May 14, 2010 2:07 pm
Reply with quote

Why not try writing a simple program available in your installation (COB or PL/1) which could do the trick for you.
Back to top
View user's profile Send private message
Ankita Maheshwari

New User


Joined: 12 May 2010
Posts: 23
Location: Pune

PostPosted: Fri May 14, 2010 2:09 pm
Reply with quote

actually the requirement is to do it from the JCL.......... so no need to write a COBOL program nyways..........
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> JCL & VSAM

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts To get the count of rows for every 1 ... DB2 3
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts Access to non cataloged VSAM file JCL & VSAM 18
Search our Forums:

Back to Top