The RETURN and END-RETURN statements are used in COBOL to retrieve the next record from a sort/merge file or report writer queue. They are essential for processing sorted or merged data and for report generation.
123456789101112131415161718* Basic RETURN syntax RETURN file-name AT END ... [statements] END-RETURN * Example with SORT SORT SORT-FILE ON ASCENDING KEY ... INPUT PROCEDURE IS INPUT-ROUTINE OUTPUT PROCEDURE IS OUTPUT-ROUTINE. INPUT-ROUTINE. RETURN INPUT-FILE AT END MOVE 'Y' TO EOF-FLAG. OUTPUT-ROUTINE. RETURN SORT-FILE AT END MOVE 'Y' TO EOF-FLAG. * Example with report writer RETURN REPORT-FILE AT END MOVE 'Y' TO END-OF-REPORT.
RETURN is used to retrieve the next record from a sort/merge or report file. Use AT END to handle end-of-file.
1. What is the primary use of the RETURN statement in COBOL?
2. Where is the RETURN statement most commonly used?
3. What does END-RETURN do in COBOL?
4. Which clause is often used with RETURN for error handling?
5. Which of the following is a valid RETURN usage?