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

Need to know count ot records using cobol


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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: 8797
Location: Welsh Wales

PostPosted: Wed Jun 03, 2009 7:45 pm
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
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: 8797
Location: Welsh Wales

PostPosted: Wed Jun 03, 2009 8:00 pm
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Wed Jun 03, 2009 8:18 pm
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
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
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
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Wed Jun 03, 2009 9:38 pm
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
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
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

Moderator Emeritus


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

PostPosted: Thu Jun 04, 2009 11:56 pm
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
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
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

Moderator Emeritus


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

PostPosted: Fri Jun 05, 2009 8:53 am
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 0
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts Replace each space in cobol string wi... COBOL Programming 3
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
Search our Forums:

Back to Top