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

How to count number of records in a dataset using cobol pgm


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
kris22_24

New User


Joined: 28 Oct 2006
Posts: 18

PostPosted: Mon Apr 23, 2007 10:52 pm
Reply with quote

How to count number of records in a data set using cobol program?
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Mon Apr 23, 2007 10:56 pm
Reply with quote

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
View user's profile Send private message
kris22_24

New User


Joined: 28 Oct 2006
Posts: 18

PostPosted: Mon Apr 23, 2007 10:59 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Apr 23, 2007 11:08 pm
Reply with quote

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
View user's profile Send private message
kris22_24

New User


Joined: 28 Oct 2006
Posts: 18

PostPosted: Mon Apr 23, 2007 11:37 pm
Reply with quote

sorry, i dint understand what exactly should do.. can u please write in detail with codings...
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Mon Apr 23, 2007 11:44 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Apr 24, 2007 1:21 am
Reply with quote

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
View user's profile Send private message
nandu404

New User


Joined: 20 Sep 2006
Posts: 4

PostPosted: Thu Apr 26, 2007 11:25 am
Reply with quote

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
View user's profile Send private message
socker_dad

Active User


Joined: 05 Dec 2006
Posts: 177
Location: Seattle, WA

PostPosted: Thu Apr 26, 2007 8:59 pm
Reply with quote

Or you could simply pick up a COBOL programming manual and actually READ it..... icon_idea.gif
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Fri Apr 27, 2007 12:54 pm
Reply with quote

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
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Fri Apr 27, 2007 5:45 pm
Reply with quote

How does IEBGENER count? Where's the output show?
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Fri Apr 27, 2007 5:51 pm
Reply with quote

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
View user's profile Send private message
Ajay Baghel

Active User


Joined: 25 Apr 2007
Posts: 206
Location: Bangalore

PostPosted: Mon Apr 30, 2007 12:53 pm
Reply with quote

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

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 2
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts To get the count of rows for every 1 ... DB2 3
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts FINDREP - Only first record from give... DFSORT/ICETOOL 3
Search our Forums:

Back to Top