View previous topic :: View next topic
|
Author |
Message |
rupesh gullu
New User
Joined: 12 Dec 2008 Posts: 96 Location: Gurgaon
|
|
|
|
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 |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
Why reinvent the wheel when your SORT product can almost certainly give you the results that you want. |
|
Back to top |
|
|
rupesh gullu
New User
Joined: 12 Dec 2008 Posts: 96 Location: Gurgaon
|
|
|
|
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 |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
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 |
|
|
rupesh gullu
New User
Joined: 12 Dec 2008 Posts: 96 Location: Gurgaon
|
|
|
|
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 |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
have You devised the logic yet ?? |
|
Back to top |
|
|
rupesh gullu
New User
Joined: 12 Dec 2008 Posts: 96 Location: Gurgaon
|
|
|
|
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 |
|
|
Itanium
Active User
Joined: 22 Jan 2006 Posts: 114 Location: India
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
rupesh gullu
New User
Joined: 12 Dec 2008 Posts: 96 Location: Gurgaon
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
rather hard to help when you do not supply the code that you used. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
star_dhruv2000
New User
Joined: 03 Nov 2006 Posts: 87 Location: Plymouth, MN USA
|
|
|
|
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 |
|
Back to top |
|
|
rupesh gullu
New User
Joined: 12 Dec 2008 Posts: 96 Location: Gurgaon
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
|