PROGRAM TO PROCESS KSDS FILE Dynamically (use of START and READ NEXT):
IDENTIFICATION DIVISION.
PROGRAM-ID. KSREDNXT.
AUTHOR. SANDIP WALSINGE.
DATE-WRITTEN. 2020-05-04.
DATE-COMPILED. 2020-05-04.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. IBM-390.
OBJECT-COMPUTER. IBM-390.
SPECIAL-NAMES.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INFILE ASSIGN TO DD1
ORGANIZATION IS INDEXED
ACCESS MODE IS DYNAMIC
RECORD KEY IS EIDI
FILE STATUS IS FS1.
DATA DIVISION.
FILE SECTION.
FD INFILE.
01 INREC.
05 EIDI PIC X(05).
05 FILLER PIC X(01).
05 ENAMEI PIC X(06).
05 FILLER PIC X(01).
05 ESALI PIC 9(05).
05 FILLER PIC X(62).
WORKING-STORAGE SECTION.
01 WS-VARIABLES.
05 WS-COUNT PIC 9(04) VALUE ZERO.
05 WS-REC.
10 WS-EID PIC X(05).
10 FILLER PIC X(01).
10 WS-ENAME PIC X(06).
10 FILLER PIC X(01).
10 WS-SAL PIC 9(05).
10 FILLER PIC X(64).
05 FS1 PIC X(02).
05 FS2 PIC X(02).
05 FILE-END PIC X(01).
88 EOF VALUE 'Y'.
88 NOT-EOF VALUE 'N'.
PROCEDURE DIVISION.
SET NOT-EOF TO TRUE
PERFORM OPEN-PARA
PERFORM PROC-PARA UNTIL EOF
PERFORM CLOS-PARA
PERFORM STOP-PARA.
OPEN-PARA.
OPEN INPUT INFILE
DISPLAY 'OPEN INFILE STATUS : ' FS1
MOVE '21600' TO EIDI
EXIT.
PROC-PARA.
IF FS1 = '00'
START INFILE
KEY IS EQUAL TO EIDI
INVALID KEY
DISPLAY ' KEY IS INVALID '
NOT INVALID KEY
DISPLAY ' VALID KEY PROVIDED ' EIDI
PERFORM READ-NEXT-PARA
END-START
END-IF.
EXIT.
READ-NEXT-PARA.
READ INFILE NEXT RECORD
INTO WS-REC
AT END
SET EOF TO TRUE
NOT AT END
DISPLAY ' RECORD READ ' WS-REC
ADD 1 TO WS-COUNT
END-READ
EXIT.
CLOS-PARA.
CLOSE INFILE
DISPLAY 'CLOSE INFILE STATUS : ' FS1
EXIT.
STOP-PARA.
DISPLAY ' TOTAL READ COUNT : ' WS-COUNT.
STOP RUN.
JCL TO EXECUTE ABOVE COBOL PROGRAM:
//Z57658SA JOB (3P10),'KSDS EXEC JCL',
// CLASS=A,
// MSGCLASS=Q,
// NOTIFY=Z57658
//*
//JCL1 JCLLIB ORDER=Z57658.SOURCE.PROCLIB
//*
//STEP1 EXEC IGYWCLG,MEM=KSREDNXT
//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.KSDS,DISP=SHR
//GO.SYSIN DD *
//*
INPUT DATA FROM KSDS FILE:
View Z57658.TEST.KSDS
Command ===>
Type KSDS
Key
<===>----10---+----2----+----3--
****** **** Top of data ****
000001 21000 MANJIT 15500
000002 21400 SANDIP 25500
000003 21500 MANDIP 35500
000004 21600 RANDIP 45500
000005 21700 BALDIP 55500
000006 21800 KULDIP 65500
000007 21900 NITIN 75500
000008 22000 ANKIT 85500
****** **** End of data ****
OUTPUT OF PROGRAM :
********************************* TOP OF DATA *
OPEN INFILE STATUS : 00
VALID KEY PROVIDED 21600
RECORD READ 21600 RANDIP 45500
RECORD READ 21700 BALDIP 55500
RECORD READ 21800 KULDIP 65500
RECORD READ 21900 NITIN 75500
RECORD READ 22000 ANKIT 85500
CLOSE INFILE STATUS : 00
TOTAL READ COUNT : 0005
******************************** BOTTOM OF DATA
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
IDENTIFICATION DIVISION.
PROGRAM-ID. KSREDNXT.
AUTHOR. SANDIP WALSINGE.
DATE-WRITTEN. 2020-05-04.
DATE-COMPILED. 2020-05-04.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. IBM-390.
OBJECT-COMPUTER. IBM-390.
SPECIAL-NAMES.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INFILE ASSIGN TO DD1
ORGANIZATION IS INDEXED
ACCESS MODE IS DYNAMIC
RECORD KEY IS EIDI
FILE STATUS IS FS1.
DATA DIVISION.
FILE SECTION.
FD INFILE.
01 INREC.
05 EIDI PIC X(05).
05 FILLER PIC X(01).
05 ENAMEI PIC X(06).
05 FILLER PIC X(01).
05 ESALI PIC 9(05).
05 FILLER PIC X(62).
WORKING-STORAGE SECTION.
01 WS-VARIABLES.
05 WS-COUNT PIC 9(04) VALUE ZERO.
05 WS-REC.
10 WS-EID PIC X(05).
10 FILLER PIC X(01).
10 WS-ENAME PIC X(06).
10 FILLER PIC X(01).
10 WS-SAL PIC 9(05).
10 FILLER PIC X(64).
05 FS1 PIC X(02).
05 FS2 PIC X(02).
05 FILE-END PIC X(01).
88 EOF VALUE 'Y'.
88 NOT-EOF VALUE 'N'.
PROCEDURE DIVISION.
SET NOT-EOF TO TRUE
PERFORM OPEN-PARA
PERFORM PROC-PARA UNTIL EOF
PERFORM CLOS-PARA
PERFORM STOP-PARA.
OPEN-PARA.
OPEN INPUT INFILE
DISPLAY 'OPEN INFILE STATUS : ' FS1
MOVE '21600' TO EIDI
EXIT.
PROC-PARA.
IF FS1 = '00'
START INFILE
KEY IS EQUAL TO EIDI
INVALID KEY
DISPLAY ' KEY IS INVALID '
NOT INVALID KEY
DISPLAY ' VALID KEY PROVIDED ' EIDI
PERFORM READ-NEXT-PARA
END-START
END-IF.
EXIT.
READ-NEXT-PARA.
READ INFILE NEXT RECORD
INTO WS-REC
AT END
SET EOF TO TRUE
NOT AT END
DISPLAY ' RECORD READ ' WS-REC
ADD 1 TO WS-COUNT
END-READ
EXIT.
CLOS-PARA.
CLOSE INFILE
DISPLAY 'CLOSE INFILE STATUS : ' FS1
EXIT.
STOP-PARA.
DISPLAY ' TOTAL READ COUNT : ' WS-COUNT.
STOP RUN.
JCL TO EXECUTE ABOVE COBOL PROGRAM:
//Z57658SA JOB (3P10),'KSDS EXEC JCL',
// CLASS=A,
// MSGCLASS=Q,
// NOTIFY=Z57658
//*
//JCL1 JCLLIB ORDER=Z57658.SOURCE.PROCLIB
//*
//STEP1 EXEC IGYWCLG,MEM=KSREDNXT
//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.KSDS,DISP=SHR
//GO.SYSIN DD *
//*
INPUT DATA FROM KSDS FILE:
View Z57658.TEST.KSDS
Command ===>
Type KSDS
Key
<===>----10---+----2----+----3--
****** **** Top of data ****
000001 21000 MANJIT 15500
000002 21400 SANDIP 25500
000003 21500 MANDIP 35500
000004 21600 RANDIP 45500
000005 21700 BALDIP 55500
000006 21800 KULDIP 65500
000007 21900 NITIN 75500
000008 22000 ANKIT 85500
****** **** End of data ****
OUTPUT OF PROGRAM :
********************************* TOP OF DATA *
OPEN INFILE STATUS : 00
VALID KEY PROVIDED 21600
RECORD READ 21600 RANDIP 45500
RECORD READ 21700 BALDIP 55500
RECORD READ 21800 KULDIP 65500
RECORD READ 21900 NITIN 75500
RECORD READ 22000 ANKIT 85500
CLOSE INFILE STATUS : 00
TOTAL READ COUNT : 0005
******************************** BOTTOM OF DATA
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
gracias, excelente Post. !!!
ReplyDeleteSolo falto el UNTIL FS1 = '10' en el perform read-next-para