Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Need to know count ot records using cobol

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
rupesh gullu

New User


Joined: 12 Dec 2008
Posts: 96
Location: Gurgaon

PostPosted: Wed Jun 03, 2009 7:40 pm    Post subject: Need to know count ot records using cobol
Reply with quote

Hi,

I want to know the count of records in i/p file and writei it to output.

e.g if i/p file has following records:
rupesh
rupesh
bill
bill
mike

o/p should be
rupesh 02
bill 02
mike 01

I want to write a cobol code for that. Please help.

Regards,
rupesh
Back to top
View user's profile Send private message

expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Wed Jun 03, 2009 7:45 pm    Post subject:
Reply with quote

Why reinvent the wheel when your SORT product can almost certainly give you the results that you want.
Back to top
View user's profile Send private message
rupesh gullu

New User


Joined: 12 Dec 2008
Posts: 96
Location: Gurgaon

PostPosted: Wed Jun 03, 2009 7:51 pm    Post subject: Reply to: Need to know count ot records using cobol
Reply with quote

Hi Expat,

Sort is wonderful ,I can do it in sort ,but just needs to write a small cobol code for that.

If you can please let me know pseudo code i can try my self.

regards,
rupesh
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Wed Jun 03, 2009 8:00 pm    Post subject:
Reply with quote

Quote:
Sort is wonderful ,I can do it in sort ,but just needs to write a small cobol code for that.

Should I substitute needs with want.
Why do you need to reinvent the wheel again - the current wheel works wonderfully.
Back to top
View user's profile Send private message
rupesh gullu

New User


Joined: 12 Dec 2008
Posts: 96
Location: Gurgaon

PostPosted: Wed Jun 03, 2009 8:07 pm    Post subject: Reply to: Need to know count ot records using cobol
Reply with quote

Hi Expat,

Yes please substitute want for need. I have not worked much in cobol side so wants to explore new things in cobol.

regards,
rupesh gupta
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

PostPosted: Wed Jun 03, 2009 8:18 pm    Post subject: Reply to: Need to know count ot records using cobol
Reply with quote

have You devised the logic yet ??
Back to top
View user's profile Send private message
rupesh gullu

New User


Joined: 12 Dec 2008
Posts: 96
Location: Gurgaon

PostPosted: Wed Jun 03, 2009 8:25 pm    Post subject: Reply to: Need to know count ot records using cobol
Reply with quote

Hi Enrico,

I have following code:
Code:
PERFORM D100-READ-FILE.                     
                                             
IF WS-NO-MORE-FILE-REC                       
   MOVE 'YES' TO WS-EOF-SW                   
   GO TO C100-EXIT                           
END-IF.                                     
                                             
IF WS-NAME-INP  = WS-TEMP                   
   ADD +1 TO WS-RECORD-CNTR                 
   MOVE  WS-NAME-INP    TO WS-NAME-OP       
   MOVE  WS-RECORD-CNTR TO WS-REC-COUNT     
   WRITE COUNT1-REC     FROM COUNT1-RECD     
ELSE                                         
   MOVE SPACES          TO WS-TEMP           
   MOVE ZEROS           TO WS-RECORD-CNTR   
   MOVE WS-NAME-INP  TO WS-TEMP             
   MOVE WS-NAME-INP  TO WS-NAME-OP           
END-IF.                                     


But it gives the following o/p

rupesh 01
rupesh 02
bill 03
bill 04
mike 05

I want
rupesh 02
bill 02
mike 01

regards,
rupesh gupta
Back to top
View user's profile Send private message
Itanium

Active User


Joined: 22 Jan 2006
Posts: 114
Location: India

PostPosted: Wed Jun 03, 2009 8:27 pm    Post subject:
Reply with quote

Change the code as below and try.

Code:

PERFORM D100-READ-FILE.                     
                                             
IF WS-NO-MORE-FILE-REC                       
   MOVE 'YES' TO WS-EOF-SW                   
   GO TO C100-EXIT                           
END-IF.                                     
                                             
IF WS-NAME-INP  = WS-TEMP                   
   ADD +1 TO WS-RECORD-CNTR                 
   MOVE  WS-NAME-INP    TO WS-NAME-OP       
   MOVE  WS-RECORD-CNTR TO WS-REC-COUNT     
ELSE                                         
   WRITE COUNT1-REC     FROM COUNT1-RECD     
   MOVE SPACES          TO WS-TEMP           
   MOVE ZEROS           TO WS-RECORD-CNTR   
   MOVE WS-NAME-INP  TO WS-TEMP             
   MOVE WS-NAME-INP  TO WS-NAME-OP           
END-IF.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Jun 03, 2009 9:10 pm    Post subject:
Reply with quote

would suggest this change also:
Code:

IF WS-NO-MORE-FILE-REC 
   WRITE COUNT1-REC     FROM COUNT1-RECD                     
   MOVE 'YES'             TO WS-EOF-SW                   
   GO                     TO C100-EXIT                           
END-IF


as well as:
Code:

IF WS-NAME-INP  =  WS-NAME-OP                   
   ADD +1                 TO WS-RECORD-CNTR                 
   MOVE  WS-RECORD-CNTR   TO WS-REC-COUNT     
ELSE                                         
   WRITE COUNT1-REC     FROM COUNT1-RECD     
   MOVE ZEROS             TO WS-RECORD-CNTR   
   MOVE WS-NAME-INP       TO WS-NAME-OP           
END-IF

and if you define WS-RECORD-CNTR as part of COUNT1-RECD
you could
Code:

IF WS-NAME-INP  =  WS-NAME-OP                   
   ADD +1                 TO WS-RECORD-CNTR                 
ELSE                                         
   WRITE COUNT1-REC     FROM COUNT1-RECD     
   MOVE ZEROS             TO WS-RECORD-CNTR   
   MOVE WS-NAME-INP       TO WS-NAME-OP           
END-IF

which would make the whole thing:
Code:

PERFORM D100-READ-FILE

IF WS-NO-MORE-FILE-REC 
   WRITE COUNT1-REC     FROM COUNT1-RECD                     
   MOVE 'YES'             TO WS-EOF-SW                   
   GO                     TO C100-EXIT                           
END-IF

IF WS-NAME-INP  =  WS-NAME-OP                   
   ADD +1                 TO WS-RECORD-CNTR                 
ELSE                                         
   WRITE COUNT1-REC     FROM COUNT1-RECD     
   MOVE ZEROS             TO WS-RECORD-CNTR   
   MOVE WS-NAME-INP       TO WS-NAME-OP           
END-IF

or use an EVALUATE
Code:

PERFORM D100-READ-FILE

EVALUATE  TRUE
    WHEN  WS-NO-MORE-FILE-REC 
          WRITE COUNT1-REC     FROM COUNT1-RECD                     
          MOVE 'YES'             TO WS-EOF-SW                   
          GO                     TO C100-EXIT                           
    WHEN  WS-NAME-INP  =  WS-NAME-OP                   
          ADD +1                 TO WS-RECORD-CNTR                 
    WHEN  OTHER
          WRITE COUNT1-REC     FROM COUNT1-RECD     
          MOVE ZEROS             TO WS-RECORD-CNTR   
          MOVE WS-NAME-INP       TO WS-NAME-OP           
END-EVALUTE


i imagine your first line in the output is all spaces.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Wed Jun 03, 2009 9:38 pm    Post subject: Reply to: Need to know count ot records using cobol
Reply with quote

Check whether you can use the REXX function LISTDSI (not sure if this is a VSAM file or not). Otherwise, for VSAM, a small Assembler sub-program, which issues a SHOWCB macro would work.

Both suggestions don't require any I-O.

It seems that to read the entire file just to determine the number of records is very inefficient.
Back to top
View user's profile Send private message
rupesh gullu

New User


Joined: 12 Dec 2008
Posts: 96
Location: Gurgaon

PostPosted: Thu Jun 04, 2009 3:14 pm    Post subject: Reply to: Need to know count ot records using cobol
Reply with quote

Hi,

Thanks all for your reply. I tried using all the logic and I am getting some of the result. But count is not coming correctly.

It is giving the positon from where rec starts instead of how many records are there.

my i/p is :

Code:
MINTU
MINTU
MINTU
MINTU
PREETI
PREETI
PREETI
PREETI
RUPESH
RUPESH
RUPESH


my o/p coming is:

mintu 01
preeti 05
rupesh 09

It should be

mintu 04
preeti 04
rupesh 03



regards,
rupesh gupta
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Jun 04, 2009 3:22 pm    Post subject:
Reply with quote

rather hard to help when you do not supply the code that you used.
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Thu Jun 04, 2009 11:56 pm    Post subject:
Reply with quote

Hello,

Is this now working? If not post the code as requested. . .

One problem is that the counter is not being reset when the name changes. . .
Back to top
View user's profile Send private message
star_dhruv2000

New User


Joined: 03 Nov 2006
Posts: 87
Location: Plymouth, MN USA

PostPosted: Fri Jun 05, 2009 1:05 am    Post subject:
Reply with quote

Try following if your file is sorted as given:

Code:

READ INFILE.
MOVE INREC    TO  WS-INREC.

PERFORM UNTIL FS-INFILE = 10
  IF WS-INREC NOT = INREC THEN
     MOVE INREC    TO  WS-INREC   
     STRING INREC COUNTER DELIMITED BY SIZE INTO OUTREC
     WRITE OUTREC
     INITIALIZE OUTREC COUNTER
  ELSE
     ADD 1 TO COUNTER
  END-IF
  READ INFILE
END-PERFORM.


Happy coding !!!
Cheers icon_smile.gif
Back to top
View user's profile Send private message
rupesh gullu

New User


Joined: 12 Dec 2008
Posts: 96
Location: Gurgaon

PostPosted: Fri Jun 05, 2009 8:45 am    Post subject: Reply to: Need to know count ot records using cobol
Reply with quote

Hi Dick,

Following is my code which i used:

Code:

     IF WS-NAME-INP  = WS-TEMP                     
        ADD +1                 TO WS-RECORD-CNTR   
        MOVE  WS-RECORD-CNTR   TO WS-REC-COUNT                           
     ELSE                                           
        MOVE WS-NAME-INP       TO WS-TEMP           
        MOVE WS-NAME-INP       TO WS-NAME-OP                                         
        ADD +1                 TO WS-RECORD-CNTR
        MOVE  WS-RECORD-CNTR   TO WS-REC-COUNT                                       
        WRITE COUNT1-REC       FROM COUNT1-RECD     
     END-IF.   


Regards,
rupesh gupta
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Fri Jun 05, 2009 8:53 am    Post subject:
Reply with quote

Hello,

The code constantly adds to the counter but never zeros the counter.

The counter needs to be set to zero each time a new name is detected.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Limit duplicate records in the SORT pshongal SYNCSORT 6 Mon Nov 21, 2016 12:54 pm
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Regarding COBOL Stored Procedure opti... selvamsrinivasan85 DB2 4 Fri Nov 04, 2016 8:57 pm
No new posts COBOL Version 6.1 Virendra Shambharkar COBOL Programming 5 Tue Nov 01, 2016 11:24 am
No new posts Cobol list of programs being called biswajit.dattagupta COBOL Programming 5 Tue Nov 01, 2016 2:10 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us