TSO-ISPF JCL COBOL VSAM DB2 CICS Tools Articles Job Portal Forum Quiz Interview Q&A

COBOL - Sort Validation


Determining whether the sort or merge was successful:

The DFSORT program returns a completion code of either 0 (successful completion) or 16 (unsuccessful completion) after each sort or merge has finished. The completion code is stored in the SORT-RETURN special register.

You should test for successful completion after each SORT or MERGE statement. For example:

  SORT SORT-WORK-2
    ON ASCENDING KEY SORT-KEY
    INPUT PROCEDURE IS 600-SORT3-INPUT-PROC
    OUTPUT PROCEDURE IS 700-SORT3-OUTPUT-PROC.

IF SORT-RETURN NOT=0
    DISPLAY "SORT ENDED ABNORMALLY. SORT-RETURN = " SORT-RETURN.

If you do not reference SORT-RETURN anywhere in your program, the COBOL run time tests the completion code. If it is 16, COBOL issues a runtime diagnostic message.
By default, DFSORT diagnostic messages are sent to the SYSOUT data set.

If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!

Are you looking for Job Change? Job Portal