COBOL Prog to read record from RRDS file :
IDENTIFICATION DIVISION.
PROGRAM-ID. FILREAD.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
OBJECT-COMPUTER. IBM-390.
SOURCE-COMPUTER. IBM-390.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INFILE ASSIGN TO DD1
ORGANIZATION IS RELATIVE
ACCESS MODE IS RANDOM
RELATIVE KEY IS WS-RRN
FILE STATUS IS FS1.
DATA DIVISION.
FILE SECTION.
FD INFILE.
01 INREC.
05 EID PIC X(05).
05 FILLER PIC X(01).
05 ENAME PIC X(06).
05 FILLER PIC X(01).
05 ESAL PIC 9(05).
05 FILLER PIC X(62).
WORKING-STORAGE SECTION.
01 FS1 PIC X(02).
01 WS-RRN PIC 9(04).
PROCEDURE DIVISION.
PERFORM OPEN-PARA.
PERFORM READ-PARA.
PERFORM CLOSE-PARA.
STOP RUN.
OPEN-PARA.
OPEN INPUT INFILE
DISPLAY ' OPEN FILE STATUS ' FS1.
MOVE 3 TO WS-RRN
DISPLAY ' VALUE OF WS-RRN ' WS-RRN.
READ-PARA.
IF FS1 = '00'
READ INFILE
INVALID KEY
DISPLAY ' RECORD NOT FOUND '
NOT INVALID KEY
DISPLAY ' RECORD ' INREC
END-READ
END-IF.
CLOSE-PARA.
CLOSE INFILE
DISPLAY ' CLOSE FILE STATUS ' FS1.
JCL TO EXECUTE ABOVE PROGRAM :
//Z57658SA JOB (3P10),'RRDS EXEC JCL',
// CLASS=A,
// MSGCLASS=Q,
// NOTIFY=Z57658
//*
//JCL1 JCLLIB ORDER=Z57658.SOURCE.PROCLIB
//*
//STEP1 EXEC IGYWCLG,MEM=FILEREAD
//COBOL.SYSIN DD DSN=Z57658.SOURCE.COBOL(&MEM),DISP=SHR
//LKED.SYSLMOD DD DSN=Z57658.SOURCE.LOADLIB(&MEM),DISP=SHR
//GO.DD1 DD DSN=Z57658.TEST.RRDS,DISP=SHR
//GO.SYSIN DD *
//*
INPUT DATA FROM RRDS FILE:
'Z57658.TEST.RRDS'
RELATIVE RECORD NUMBER - 1
21400 SANDIP 15500
RELATIVE RECORD NUMBER - 2
21500 MANDIP 25500
RELATIVE RECORD NUMBER - 3
21600 RANDIP 35500
RELATIVE RECORD NUMBER - 4
21700 BALDIP 45500
RELATIVE RECORD NUMBER - 5
21800 KULJIT 55500
RELATIVE RECORD NUMBER - 6
21900 ANKIT 65500
RELATIVE RECORD NUMBER - 7
22000 NITIN 75500
RELATIVE RECORD NUMBER - 8
22100 SAMEER 85500
OUTPUT OF PROGRAM :
********************************* TOP OF DATA ***
OPEN FILE STATUS : 00
VALUE OF WS-RRN 3
RECORD 21600 RANDIP 35500
CLOSE FILE STATUS : 00
******************************** BOTTOM OF DATA *
IDENTIFICATION DIVISION.
PROGRAM-ID. FILREAD.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
OBJECT-COMPUTER. IBM-390.
SOURCE-COMPUTER. IBM-390.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INFILE ASSIGN TO DD1
ORGANIZATION IS RELATIVE
ACCESS MODE IS RANDOM
RELATIVE KEY IS WS-RRN
FILE STATUS IS FS1.
DATA DIVISION.
FILE SECTION.
FD INFILE.
01 INREC.
05 EID PIC X(05).
05 FILLER PIC X(01).
05 ENAME PIC X(06).
05 FILLER PIC X(01).
05 ESAL PIC 9(05).
05 FILLER PIC X(62).
WORKING-STORAGE SECTION.
01 FS1 PIC X(02).
01 WS-RRN PIC 9(04).
PROCEDURE DIVISION.
PERFORM OPEN-PARA.
PERFORM READ-PARA.
PERFORM CLOSE-PARA.
STOP RUN.
OPEN-PARA.
OPEN INPUT INFILE
DISPLAY ' OPEN FILE STATUS ' FS1.
MOVE 3 TO WS-RRN
DISPLAY ' VALUE OF WS-RRN ' WS-RRN.
READ-PARA.
IF FS1 = '00'
READ INFILE
INVALID KEY
DISPLAY ' RECORD NOT FOUND '
NOT INVALID KEY
DISPLAY ' RECORD ' INREC
END-READ
END-IF.
CLOSE-PARA.
CLOSE INFILE
DISPLAY ' CLOSE FILE STATUS ' FS1.
JCL TO EXECUTE ABOVE PROGRAM :
//Z57658SA JOB (3P10),'RRDS EXEC JCL',
// CLASS=A,
// MSGCLASS=Q,
// NOTIFY=Z57658
//*
//JCL1 JCLLIB ORDER=Z57658.SOURCE.PROCLIB
//*
//STEP1 EXEC IGYWCLG,MEM=FILEREAD
//COBOL.SYSIN DD DSN=Z57658.SOURCE.COBOL(&MEM),DISP=SHR
//LKED.SYSLMOD DD DSN=Z57658.SOURCE.LOADLIB(&MEM),DISP=SHR
//GO.DD1 DD DSN=Z57658.TEST.RRDS,DISP=SHR
//GO.SYSIN DD *
//*
INPUT DATA FROM RRDS FILE:
'Z57658.TEST.RRDS'
RELATIVE RECORD NUMBER - 1
21400 SANDIP 15500
RELATIVE RECORD NUMBER - 2
21500 MANDIP 25500
RELATIVE RECORD NUMBER - 3
21600 RANDIP 35500
RELATIVE RECORD NUMBER - 4
21700 BALDIP 45500
RELATIVE RECORD NUMBER - 5
21800 KULJIT 55500
RELATIVE RECORD NUMBER - 6
21900 ANKIT 65500
RELATIVE RECORD NUMBER - 7
22000 NITIN 75500
RELATIVE RECORD NUMBER - 8
22100 SAMEER 85500
OUTPUT OF PROGRAM :
********************************* TOP OF DATA ***
OPEN FILE STATUS : 00
VALUE OF WS-RRN 3
RECORD 21600 RANDIP 35500
CLOSE FILE STATUS : 00
******************************** BOTTOM OF DATA *
Hi Sandip, Can you explain how during Runtime if one wants to access a particular record from a relative file, how will one know what's the relative key for that record?
ReplyDeleteThanks in advance