PROGRAM-ID. MERGE-SEQFILES.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INFILE1 ASSIGN TO DISK
ORGANIZATION IS LINE SEQUENTIAL.
SELECT INFILE2 ASSIGN TO DISK
ORGANIZATION IS LINE SEQUENTIAL.
SELECT OUTFILE ASSIGN TO DISK
ORGANIZATION IS LINE SEQUENTIAL.
SELECT WFILE ASSIGN TO DISK.
DATA DIVISION.
FILE SECTION.
FD INFILE1
LABEL RECORDS ARE STANDARD
VALUE OF FILE-ID IS "STD1.DAT".
01 FILE1-REC.
02 RNO PIC X(5).
02 SN PIC X(15).
02 CL PIC X(4).
02 MARKS PIC 9(3).
FD INFILE2
LABEL RECORDS ARE STANDARD
VALUE OF FILE-ID IS "STD2.DAT".
01 FILE2-REC.
02 RNO PIC X(5).
02 SN PIC X(15).
02 CL PIC X(4).
02 MARKS PIC 9(3).
FD OUTFILE
LABEL RECORDS ARE STANDARD
VALUE OF FILE-ID IS "MRGSTD.DAT".
01 OUT-REC PIC X(27).
SD WFILE.
01 S-REC.
02 SRNO PIC X(5).
02 SSN PIC X(15).
02 SCL PIC X(4).
02 SMARKS PIC 9(3).
PROCEDURE DIVISION.
MAIN-PARA.
MERGE WFILE ON ASCENDING KEY SSN
In order to COBOL editor we have to use: ne filename.cob.
ReplyDeleteTo compile: cobol filename.cob
To run: Runcob filename
To save: Press F3 then press E
In the above program there are four files:file1,file2,file3 and wfile.
ReplyDeleteFile1 and file2 are input files. The program merges these two file at the same it sort the data based on key ssn.
1.Press dos prompt
2.type std1.dat
type the dat keeping in mind the size of the data.
3.press F3 the E
4.type std2.dat
enter the data in second file.
5.compile the program
6.Run the program
To see the sorted data
7.f3 E
8.type mrgstd.dat
There you will get the output..