OUTPUT PROCEDURE Output-Proc
SET File-Sorted TO TRUE
IF NOT End-of-File
AT END SET End-of-File TO TRUE
Our program is supposed to do an internal sort, pseudo code looks like above.
The first call of Output-Proc immediately followed by SORT is working fine, but when it is invoked the second time using the PERFORM statement, the RETURN command is failing. The program Abends with code U4083 and REASON CODE=00000002.
Can we invoke an Output Procedure using a perform?
Is the Sorted-File closed immediately after encountering Output-Proc-Exit's EXIT statement?
I've got an idea! Why don't you do a stand-alone sort before your program starts? No confusion then.
Sorry! our program is quiet old which had no problems all these years, as this SORT functionality was not used in the recent past. Couple of days back due to a strange constellation, this part of the functionality was used in production & The program failed. Reason was the above programming logic. I would definitely like to recode it without using internal sort. am only trying to understand the cause first.
No, there is no relationship between the EXIT statement and the file being sorted. On top of that, an EXIT statement does nothing. Consult your manual.
Yes EXIT does nothing. what i meant by saying "Output-Proc-Exit's EXIT statement" is point control goes out of Output-Proc.
At the very least you have to explain what you are trying to do, why you think it would work, and how it is not working.
Referring again to the above code.
1. After performing SORT, Output-Procedure is invoked
2. The first record is RETURNed and output-procedure is exited
3. Control comes back to "Process-File section "
4. In the second iteration of "Process-File", Output-Procedure is invoked using a PERFORM
5. Here when the RETURN statement is executed, program ends with erro code U4083 reason 02.
OK, you were unlucky with the constellation. The code never worked, but was never executed.
The OUTPUT PROCEDURE only logically relates to the SORT. Once the SORT executes, it sorts the input and you end up with a sorted file stitting in the sort work area. For each record in sorted order the OUTPUT PROCEDURE is executed. You can then do processing to decide if you want the current record to appear on the output file created by the sort. If you execute RETURN, you get a record on the output file. If it finishes the procedure without executing a RETURN the current record in the sort work area is ignored. The result is a sorted file only including the records selected by RETURN. When all records are so processed, that is the end of the OUTPUT PROCEDURE - full stop.
You can't perform the output procedure to "get the next record" or anything like that.
It seems the person who coded the thing originally did not understand how it worked, and it was never tested for the constellation situation.
You'll have to re-work it, correcting the faulty understanding.
If the OUTPUT PROCEDURE is being PERFORMed as well as being used by the SORT, I don't know exactly what it will do, but it will not work. Maybe it will somehow cause the message from Syncsort.
IF INPUT-CODE NOT EQUAL TO "BBB"
If those three records represent the data which has been sorted but not yet written to the output file, then the OUTPUT PROCEDURE will be executed for each record. For AAA and CCC the RETURN will be executed and those records will be written to the output file. BBB will not be written.
All of that happens in relation to the SORT. The SORT is using the PROCEDURE as an E35 output exit, where SORT can be told to include or exclude the current record, as each is passed in sorted order to the exit. An "8" indicates that no more records are to be processed. You don't need to do anything to get all this, just have the OUTPUT PROCEDURE.
If you perform the output procedure, it will not work. It certainly will not do what the original coder intended. Exactly what it would do isn't very relevant. It may well still have an "8" lying around and branch back to Syncsort, causing those messages, who knows? It is not worth finding out because it is not and can never do anything useful for your program.
Joined: 29 Oct 2010 Posts: 111 Location: Puerto Rico
Good day to all!
Your problem is with the RETURN statement been executed outside the SORT procedure because the RETURN statement can only use within the range of an output procedure associated with a SORT or MERGE statement.