Skip to content

RELEASE Statement

The RELEASE statement makes records available for a SORT in an INPUT PROCEDURE.

General Format:

RELEASE sort-record-1 [ FROM identifier-1 ]

Syntax:

  1. sort-record-n is a record described in a Sort Description (SD) in the File Section.
  2. identifier-n is a data element, literal, or data returned from a function call.

General Rules:

  1. The RELEASE statement can only be used in the INPUT PROCEDURE of a SORT statement.
  2. The RELEASE statement MOVE's data from identifier-1 to a sort record, which is declared in a Sort Description (SD) in the FILE SECTION of the program.
  3. The RELEASE statement adds the data MOVE’d from identifier-1 to the SORT file.

Code Sample:

       IDENTIFICATION DIVISION. 
       PROGRAM-ID. RELEASE-1. 
       ENVIRONMENT DIVISION. 
       INPUT-OUTPUT SECTION. 
       FILE-CONTROL. 
      *SORT INPUT FILE 
              SELECT MEMBER-FILE ASSIGN TO "MEMBERSHIP.TXT" 
              ORGANIZATION IS LINE SEQUENTIAL 
              ACCESS IS SEQUENTIAL 
              FILE STATUS IS MEMBERSHIP-STAT. 

      *SORT OUTPUT FILE 
              SELECT MEMBER-LIST ASSIGN TO "MEMBERLIST.TXT" 
              ORGANIZATION IS LINE SEQUENTIAL 
              ACCESS IS SEQUENTIAL 
              FILE STATUS IS MEMBERLIST-STAT. 

      *SORTFILE (SD) 
              SELECT MEMBER-SORT ASSIGN TO "SORT-WORK". 

       DATA DIVISION. 
       FILE SECTION. 
       FD MEMBER-FILE. 
       01 MEMBER-INFO PIC X(40). 

       FD MEMBER-LIST. 
       01 SORTED-MEMBER-INFOPIC X(40). 

       SD MEMBER-SORT. 
       01 SORT-DATA. 
              05 MEMBER-FIRST-NAME PIC X(10). 
              05 MEMBER-LAST-NAME  PIC X(20). 
              05 YEAR-JOINED       PIC X(4). 
              05 MEMBER-RANK       PIC X(6). 

       WORKING-STORAGE SECTION. 
       77 MEMBERLIST-STAT PIC XX. 
              88 EOF-MEMBERLIST VALUE "10". 
       77 MEMBERSHIP-STAT PIC XX. 
              88 EOF-MEMBERSHIP VALUE "10". 
       77 OUTPUT-SORT-AT-END PIC X. 
              88 EOF-SORT-FILE VALUE "Y". 
       77 DUMMY PIC X. 

       PROCEDURE DIVISION. 
       MEMBER-SORT-PROC. 

              SORT MEMBER-SORT 
                     ON ASCENDING KEY MEMBER-LAST-NAME 
                     ON DESCENDING KEY MEMBER-RANK 
                     WITH DUPLICATES IN ORDER 
                     INPUT PROCEDURE INPUT-PROC 
                     OUTPUT PROCEDURE OUTPUT-PROC. 

              DISPLAY "SORT-3 FINISHED!" LINE 10 COL 10. 
              ACCEPT DUMMY LINE 10 COL 30. 
              STOP RUN. 

       INPUT-PROC SECTION. 
       INPUT-PROCESS. 

              OPEN INPUT MEMBER-FILE. 
              READ MEMBER-FILE NEXT RECORD.
              PERFORM UNTIL EOF-MEMBERLIST 
                     RELEASE SORT-DATA FROM MEMBER-INFO 

                     READ MEMBER-FILE NEXT RECORD 
                            AT END MOVE "10" TO MEMBERLIST-STAT 
                     END-READ 
              END-PERFORM. 

              CLOSE MEMBER-FILE. 
              EXIT SECTION. 

       OUTPUT-PROC SECTION. 
       OUTPUT-PROCESS. 
              OPEN OUTPUT MEMBER-LIST. 
              PERFORM UNTIL EOF-SORT-FILE 
                     RETURN MEMBER-SORT 
                            AT END MOVE "Y" TO OUTPUT-SORT-AT-END 
                            NOT AT END 
                                   WRITE SORTED-MEMBER-INFO FROM SORT-DATA 
                     END-RETURN 
              END-PERFORM. 

              CLOSE MEMBER-LIST. 
              EXIT SECTION.
Back to top