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:
sort-record-n
is a record described in a Sort Description (SD) in the File Section.identifier-n
is a data element, literal, or data returned from a function call.
General Rules:
- The
RELEASE
statement can only be used in theINPUT PROCEDURE
of aSORT
statement. - The
RELEASE
statementMOVE
's data fromidentifier-1
to a sort record, which is declared in a Sort Description (SD) in theFILE SECTION
of the program. - The
RELEASE
statement adds the dataMOVE
’d fromidentifier-1
to theSORT
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.