Code for PROGRAM TO SORT THE RECORDS OF FILE in Cobol
IDENTIFICATION DIVISION.
PROGRAM-ID. SRT.
ENVIRONMENT DIVISION.
FILE-CONTROL.
SELECT IN-FILE ASSIGN TO "INPUT.TXT"
ORGANIZATION IS LINE SEQUENTIAL.
SELECT SORT-FILE ASSIGN TO SYSWORK.
SELECT OUT-FILE ASSIGN TO "SORT.TXT"
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD IN-FILE
LABEL RECORDS ARE STANDARD.
01 IN-REC.
05 ROLLNO PIC 99.
05 NAME1 PIC X(10).
SD SORT-FILE.
01 SORT-REC.
05 NO1 PIC 99.
05 PIC X(10).
FD OUT-FILE
LABEL RECORDS ARE STANDARD.
01 OUT-REC.
05 ROLLNO1 PIC 99.
05 NAME2 PIC X(10).
WORKING-STORAGE SECTION.
01 EOF PIC X VALUE 'N'.
PROCEDURE DIVISION.
BEGIN.
SORT SORT-FILE
ON ASCENDING KEY NO1
INPUT PROCEDURE PARA1
GIVING OUT-FILE
STOP RUN.
PARA1.
OPEN INPUT IN-FILE
PERFORM UNTIL EOF='Y'
READ IN-FILE
AT END MOVE 'Y' TO EOF
NOT AT END
MOVE IN-REC TO SORT-REC
RELEASE SORT-REC
END-READ
END-PERFORM
CLOSE IN-FILE.
************************************ OUTPUT *****************************
INPUT.TXT
01APURVA
04NILAY
03KETAN
SORT.TXT
01APURVA
03KETAN
04NILAY