View previous topic :: View next topic
|
Author |
Message |
raviprabhu
New User
Joined: 20 Oct 2006 Posts: 29
|
|
|
|
Code: |
Sort
:
:
INPUT PROCEDURE 0100-READ-FILE
OUTPUT PROCEDURE 0200-WRITE-FILE
0100-READ-FILE
START FILE-TEMP KEY IS >= WS-BUILDkey
PERFORM UNTIL WS-EOF3 = 'Y'
READ FILE-TEMP NEXT RECORD
AT END MOVE 'Y' TO WS-EOF3
NOT AT END
MOVE FILE-TEMP-REC TO SORT-RECORD
END-READ
END-PERFORM.
MOVE 'N' TO WS-EOF3.
0200-WRITE-FILE
PERFORM UNTIL WS-EOF2 = 'Y'
RETURN SORT-FILE
AT END
MOVE 'Y' TO WS-EOF2
NOT AT END
MOVE SPACES TO WS-TEMP-INPUT-AREA
MOVE SORT-RECORD TO SORT-FILE-TEMP-REC
WRITE SORT-FILE-TEMP-REC
END-RETURN
END-PERFORM |
The input to sort KSDS file and ouput is flat file.
The 0100-read-file para is working fine but in 0200-write-file para while 'RETURN' the control is always is 'AT END' and does not go to 'Not At End'.
Am I missing anything ?
Code'd |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
RELEASE. |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1248 Location: Richfield, MN, USA
|
|
|
|
raviprabhu,
Please use Code tags. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
And when the output procedure completes, you should make sure sort-return is zeros. |
|
Back to top |
|
|
raviprabhu
New User
Joined: 20 Oct 2006 Posts: 29
|
|
|
|
sorry..I did not understand the comments.. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
At the top of the page is a link to IBM Manuals. From that list read in the COBOL Language Reference about the SORT verb.
Somehow, you knew that you needed to RETURN the sorted records, but did not RELEASE them to the sort, so nothing was sorted.
When the code completes the "output procedure" the code needs to make sure the sort ran successfully (i.e. sort-return = zeros).
Look at your original post and notice that it is now highlighted and aligned (Coded"). JCL, SQL, data, code, that need to keep their alignment need to have the Code tag applied. Someone has done this for you. In the future, you should do this before posting. Use the Preview function to ensure the post appears as you want. Then Submit. |
|
Back to top |
|
|
raviprabhu
New User
Joined: 20 Oct 2006 Posts: 29
|
|
|
|
Code: |
0100-READ-FILE
START FILE-TEMP KEY IS >= WS-BUILDkey
PERFORM UNTIL WS-EOF3 = 'Y'
READ FILE-TEMP NEXT RECORD
AT END MOVE 'Y' TO WS-EOF3
NOT AT END
MOVE FILE-TEMP-REC TO SORT-RECORD
RELEASE SORT-RECORD
END-READ
END-PERFORM.
MOVE 'N' TO WS-EOF3. |
when I use release in 0100-read para the program abends with U1003.
Is the release correct where i Have coded. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
At a glance, this appears ok.
How is the SD coded?
What does the JCL look like?
Is there any other diagnostic info presented?
Also note that Bolding does not work within the code tag |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Hi Dick,
Sorry, fixed the bolding already :-)
Hi raviprabhu,
You don't just get U1003. We need to see what else you got, again in the Code tags please. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
instead of this:
Code: |
0100-READ-FILE
START FILE-TEMP KEY IS >= WS-BUILDkey
PERFORM UNTIL WS-EOF3 = 'Y'
READ FILE-TEMP NEXT RECORD
AT END MOVE 'Y' TO WS-EOF3
NOT AT END
MOVE FILE-TEMP-REC TO SORT-RECORD
RELEASE SORT-RECORD
END-READ
END-PERFORM.
MOVE 'N' TO WS-EOF3.
|
why not this:
Code: |
0100-READ-FILE.
MOVE 'N' TO WS-EOF3
START FILE-TEMP KEY IS >= WS-BUILDkey
END-START
PERFORM UNTIL WS-EOF3 = 'Y'
READ FILE-TEMP NEXT RECORD
AT END MOVE 'Y' TO WS-EOF3
END-READ
IF WS-EOF3 = 'N'
THEN
MOVE FILE-TEMP-REC TO SORT-RECORD
RELEASE SORT-RECORD
END-IF
END-PERFORM.
MOVE 'N' TO WS-EOF3.
0100-EXIT.
EXIT.
|
can't remember and not going to look-it-up,
but I have always ended Paragraph names with a period.
I think it is required.
The NOT-AT-END is the same as the IF 'N' = WS-EOF3.
also, instead of continually using WS-EOF3,
use WS-EOF-INPUT and WS-EOF-OUTPUT
(actually, anything, just use two variables,
that way if you abend, you can tell from the variables where you are.)
and a final comment. why make this a cobol program?
just use SORT with an INPUT BUILD.
lost easier to debug, and may be easier for you, since you seem to be COBOL challanged. |
|
Back to top |
|
|
Peter cobolskolan
Active User
Joined: 06 Feb 2012 Posts: 104 Location: Sweden
|
|
|
|
Quote: |
The input to sort KSDS file.. . |
Why sort a KSDS-file? |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
To get the data into a different order than the KSDS key. We hope :-) |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
You should sort the SD (rather than an FD) to get the info you want in the new sequence.
Or, use the KSDS as inpout to a sort and a "temporary" file for thoutput of this sort. Only include the sort fields and the data fields needed.
When you use the SORT with input and output procedure, the input should not be modified. |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1050 Location: Richmond, Virginia
|
|
|
|
I have always preferred an external sort, even if I had to split the COBOL program. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hi Phil,
Quote: |
I have always preferred an external sort |
Many people / places do.
I just follow whatever standards are being used at the current site(s). . .
If it is not dictates, i look at the process to determine which way i believe is better.
@ravi - are you now able to proceed? |
|
Back to top |
|
|
|