RETURN-CODE
Part of the Programs That Work Together section of Coddy's COBOL Programming journey. Lesson 7 of 16.
A subprogram reports how its work went in RETURN-CODE, a field every program has without declaring it. It moves a number there before GOBACK:
WHEN LS-AMOUNT > 1000
MOVE 4 TO RETURN-CODEAfter the CALL, the caller's RETURN-CODE holds that number:
CALL "CHKAMT" USING AMOUNT
EVALUATE RETURN-CODE
WHEN 0 DISPLAY "Approved"Mainframe shops share a scale: 0 is fine, 4 a warning, 8 an error, 12 and up severe. The RETURN-CODE a program ends with becomes its job step's return code, which a job reads to decide what runs next.
A subprogram keeps its RETURN-CODE from one call to the next, so set it on every path, 0 included. In GnuCOBOL, DISPLAY RETURN-CODE prints a signed binary number such as +000000004: test it or move it to a field of your own.
Challenge
EasyCHKAMT sets RETURN-CODE to 0, 4 or 8 for a payment amount. After the CALL, print Approved for 0, Needs review for 4 and Rejected for any other code.
Example input, one line per ACCEPT: 250.
Try it yourself
IDENTIFICATION DIVISION.
PROGRAM-ID. PAYCHK.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 AMOUNT PIC 9(5).
PROCEDURE DIVISION.
ACCEPT AMOUNT
CALL "CHKAMT" USING AMOUNT
*> Print the result for RETURN-CODE here
STOP RUN.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.