View previous topic :: View next topic
|
Author |
Message |
kris22_24
New User
Joined: 28 Oct 2006 Posts: 18
|
|
|
|
How to count number of records in a data set using cobol program? |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
move zero to count
perform until eof
read file
at end set eof to true
not at end add 1 to count
end-read
end-perform
display count. |
|
Back to top |
|
|
kris22_24
New User
Joined: 28 Oct 2006 Posts: 18
|
|
|
|
i want to check the data sets with these conditions...if "AN, BN,CN,DN,EN,FN,GN,UN,PN,SN,MN,NN" these are present i want to count how many records are present? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Using the code suggested above, include an array of 2 fields - the 2-char alpha-code and a counter. Initialize the alpha-codes from your list or build them dynamically. Set the counters to zero.
As the program reads the records, add 1 to the appropriate counter in the array. |
|
Back to top |
|
|
kris22_24
New User
Joined: 28 Oct 2006 Posts: 18
|
|
|
|
sorry, i dint understand what exactly should do.. can u please write in detail with codings... |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
kris22_24 wrote: |
sorry, i dint understand what exactly should do.. can u please write in detail with codings... |
Since you are unfamiliar with COBOL, why don't you add an INCLUDE card to the sort solution you got a couple weeks back in How to count number of records in VSAM data set? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
If you need a quick solution, the SORT/INCLUDE will get the result you want.
If you want to learn more about COBOL, you can put together the basic program Bill described and run it - this will count all of the records in the file. Once you have the code that reads/counts all of the records, you might try the following approaches to learn some other techniques.
To then count by alpha-code, you could try the array approach (as you will need to learn about array processing anyway if you are going to be a COBOL programmer). You could also sort the records by alpha-code and summarize record counts by alpha-code and this approach would not require an array.
I'd suggest that you try all 3 sets of code - they will be small and will not take a long time to work on. Once you have the first set of code working (the overall read/count) the other 2 will be clones and take less code as you will only be adding the additonal code to implement these 2 ways of getting the summaries. When you have all 3 running correctly, set them aside to use as examples later.
If you post what you have as you work on this, we can offer suggestions when there are questions. When you post program code or jcl, it is a good idea to post using the "Code" tab at the top of the reply panel - this makes the info much more readable. |
|
Back to top |
|
|
nandu404
New User
Joined: 20 Sep 2006 Posts: 4
|
|
|
|
Hi,
You could code an IF condition in your COBOL program with the required values and increment the counter inside that.
(if you don't want to use SORT card) |
|
Back to top |
|
|
socker_dad
Active User
Joined: 05 Dec 2006 Posts: 177 Location: Seattle, WA
|
|
|
|
Or you could simply pick up a COBOL programming manual and actually READ it..... |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
Dare I ask why on earth you would want to reinvent the wheel.
HOMEWORK perhaps ?
SORT, IEBGENER, just to name two quick ways to get the count and you only have to code a couple of lines of control statements. |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
How does IEBGENER count? Where's the output show? |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
The output shows in SYSPRINT, but then here it executes ICEGENER.
Yeah, I know, it's not an ideal solution, but then the OP wasn't clear on the reason for wanting to do this. |
|
Back to top |
|
|
Ajay Baghel
Active User
Joined: 25 Apr 2007 Posts: 206 Location: Bangalore
|
|
|
|
Use the following job:
//Your job card i.e job statement
//*------------------------------------------------------------------*
//* COUNTS THE NO OF RECORDS IN THE FILE. *
//*------------------------------------------------------------------*
//TOOL EXEC PGM=ICETOOL,REGION=128M
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//INFILE DD DSN=MYDATASET,DISP=OLD
//TOOLIN DD *
COUNT FROM(INFILE)
/*
check for the outout count in the TOOLMSG |
|
Back to top |
|
|
|