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

internal SORT & "OUTPUT PROCEDURE"


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Anil Minumula

New User


Joined: 24 Feb 2009
Posts: 12
Location: Frankfurt

PostPosted: Wed Feb 15, 2012 1:13 pm
Reply with quote

Code:

 .
 .
 Perform Process-File Until End-of-File
 .
 
 Process-File SECTION.
*------------------------
 IF File-Not-Sorted
    SORT Sorted-File
    DESCENDING Key-Entry-Time
    USING File-Input
    OUTPUT PROCEDURE Output-Proc
    SET File-Sorted TO TRUE
 ELSE
    PERFORM Output-Proc
 END-IF
 PERFORM Process-Latest-Entry
 .
Process-File-Exit.
 EXIT.

Output-Proc SECTION.
 IF NOT End-of-File
    RETURN Sorted-File
    AT END SET End-of-File TO TRUE
 END-IF
.
Output-Proc-Exit.
 EXIT.


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?
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Feb 15, 2012 2:13 pm
Reply with quote

Yes, you can perform a section/paragraph which is an output procedure, as far as the compiler is concerned, but at best you'll have a confusing program, at worst it just won't work.

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.

I've got an idea! Why don't you do a stand-alone sort before your program starts? No confusion then.

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.
Back to top
View user's profile Send private message
Anil Minumula

New User


Joined: 24 Feb 2009
Posts: 12
Location: Frankfurt

PostPosted: Wed Feb 15, 2012 3:00 pm
Reply with quote

Quote:
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.

Quote:
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.

Quote:
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.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Feb 15, 2012 3:40 pm
Reply with quote

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.
Back to top
View user's profile Send private message
Anil Minumula

New User


Joined: 24 Feb 2009
Posts: 12
Location: Frankfurt

PostPosted: Wed Feb 15, 2012 4:15 pm
Reply with quote

Thanks a lot once again Bill.

Just looking at the error log and later using display statement I found the below message/warning from the SORT Utility.

This message is being given when control reaches Output-Proc-Exit para.
Code:
WER177I  TURNAROUND SORT PERFORMED
WER045C  END SORT PHASE
WER493I  ZIIP PROCESSOR USED
WER135I  TASK CALL/E35 TERMINATED PREMATURELY
WER055I  INSERT          8, DELETE          2
WER246I  FILESIZE 160 BYTES
WER054I  RCD IN          0, OUT          0
WER072I  EQUALS, BALANCE IN EFFECT


here is the message description
Code:
WER135I TASK CALL/E35 TERMINATED PREMATURELY

EXPLANATION:  An  E35  exit  routine (COBOL  Output  Procedure)  passed  a
return code of 8, terminating the sort before the sort was able to pass
all of the records. A SORTOUT data set was not present.


Is it that "OUTPUT PROCEDURE" can be executed only one time? ie., if RETURN is executed only once inside this procedure, remaining records are just lost?
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Feb 15, 2012 4:27 pm
Reply with quote

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.


Code:
AAA
BBB
CCC

IF INPUT-CODE NOT EQUAL TO "BBB"
    RETURN SortedFile
END-IF


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.
Back to top
View user's profile Send private message
Anil Minumula

New User


Joined: 24 Feb 2009
Posts: 12
Location: Frankfurt

PostPosted: Wed Feb 15, 2012 4:57 pm
Reply with quote

Thanks a lot for the info Bill.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Feb 15, 2012 5:13 pm
Reply with quote

No problem. Sorry it is not better news for you.
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 Feb 15, 2012 5:58 pm
Reply with quote

Have you had a chance to review SORT with a USING and GIVING clause, combined with the compiler option FASTSRT?

Also, review the COBOL Special-Register SORT-RETURN to test for success, failure, EOF, etc.

Just another option....

Mr. Bill
Back to top
View user's profile Send private message
Jose Mateo

Active User


Joined: 29 Oct 2010
Posts: 121
Location: Puerto Rico

PostPosted: Wed Feb 15, 2012 7:45 pm
Reply with quote

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.
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 How to split large record length file... DFSORT/ICETOOL 10
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts JCL sort card - get first day and las... JCL & VSAM 9
No new posts PuTTY - "User is not a surrogate... IBM Tools 5
No new posts Sort First/last record of a subset th... DFSORT/ICETOOL 7
Search our Forums:

Back to Top