MainframeMaster

COBOL Tutorial

COBOL RETURN and END-RETURN - Quick Reference

Progress0 of 0 lessons

Overview

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.

Purpose and Usage

  • Sort/Merge Input - Retrieve next record from a sort/merge operation
  • Report Writer - Retrieve next report group for printing
  • AT END Handling - Detect end-of-file conditions
  • Block Syntax - Use END-RETURN to close RETURN blocks

Syntax

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
* 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.

Test Your Knowledge

1. What is the primary use of the RETURN statement in COBOL?

  • To return from a subprogram
  • To retrieve the next record from a SORT or input procedure
  • To end a program
  • To return a value from a function

2. Where is the RETURN statement most commonly used?

  • In the PROCEDURE DIVISION
  • In the FILE SECTION
  • In the WORKING-STORAGE SECTION
  • In the ENVIRONMENT DIVISION

3. What does END-RETURN do in COBOL?

  • Ends the RETURN statement block
  • Ends the program
  • Returns a value
  • None of the above

4. Which clause is often used with RETURN for error handling?

  • ON EXCEPTION
  • INVALID KEY
  • AT END
  • NOT AT END

5. Which of the following is a valid RETURN usage?

  • RETURN input-file AT END ...
  • RETURN sort-file AT END ...
  • RETURN report-file AT END ...
  • All of the above

Frequently Asked Questions