Reading Record from multiple PF in CL |
If we want to declare more than one file in a CL program then we have to use the Open Identifier(OPNID) by specifying the unique value in OPNID parameter for each individual file declaration we can read multiple files in a CL program.
CL program for Reading multiple PF
PGM DCL VAR(&NO) TYPE(*DEC) LEN(5 0) DCL VAR(&NM) TYPE(*CHAR) LEN(20) DCL VAR(&ID) TYPE(*DEC) LEN(5 0) DCL VAR(&NAME) TYPE(*CHAR) LEN(20) DCLF FILE(CLPF1) DCLF FILE(CLPF2) OPNID(F2) RCVF CHGVAR VAR(&NO) VALUE(&ROLLNO) CHGVAR VAR(&NM) VALUE(&NAME) RCVF OPNID(F2) CHGVAR VAR(&ID) VALUE(&F2_STUID) CHGVAR VAR(&NAME) VALUE(&F2_STUNAME) ENDPGM
Explanation of the above code
DCL VAR(&NO) TYPE(*DEC) LEN(5 0) DCL VAR(&NM) TYPE(*CHAR) LEN(20) DCL VAR(&ID) TYPE(*DEC) LEN(5 0) DCL VAR(&NAME) TYPE(*CHAR) LEN(20)
DCLF FILE(CLPF1) DCLF FILE(CLPF2) OPNID(F2)
RCVF CHGVAR VAR(&NO) VALUE(&ROLLNO) CHGVAR VAR(&NM) VALUE(&NAME) RCVF OPNID(F2) CHGVAR VAR(&ID) VALUE(&F2_STUID) CHGVAR VAR(&NAME) VALUE(&F2_STUNAME) ENDPGM
Another CL program for Reading multiple PF
PGM DCL VAR(&NO) TYPE(*DEC) LEN(5 0) DCL VAR(&NM) TYPE(*CHAR) LEN(20) DCL VAR(&ID) TYPE(*DEC) LEN(5 0) DCL VAR(&NAME) TYPE(*CHAR) LEN(20) DCLF FILE(CLPF1) DCLF FILE(CLPF2) OPNID(F2) READ: RCVF MONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(FIL)) CHGVAR VAR(&NO) VALUE(&ROLLNO) CHGVAR VAR(&NM) VALUE(&NAME) GOTO CMDLBL(READ) FIL: RCVF OPNID(F2) MONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(END)) CHGVAR VAR(&ID) VALUE(&F2_STUID) CHGVAR VAR(&NAME) VALUE(&F2_STUNAME) GOTO CMDLBL(FIL) END: ENDPGM
Explanation of the above code
Now, this program is also having 4 variables and having declared the two files but here we are using the concept of labels and GOTO. When this procedure is receiving the message id CPF0864 given in the program which means end of file has been reached and then the program would be navigated to GOTO label in EXEC section. So, whenever the line is executable the pointer will always come to that line and the program will keep reading the file until it reaches the executable line. The MONMSG command follows the Receive File (RCVF) command and, therefore, is only monitoring for messages sent by the RCVF command. this example specifies MSGID(CPF0864), the MONMSG monitors for this condition. When it receives the message, the GOTO CMDLBL(END) command is run.
Third CL program for Reading multiple PF
PGM DCL VAR(&NO) TYPE(*DEC) LEN(5 0) DCL VAR(&NM) TYPE(*CHAR) LEN(20) DCL VAR(&ID) TYPE(*DEC) LEN(5 0) DCL VAR(&NAME) TYPE(*CHAR) LEN(20) DCLF FILE(CLPF1) DCLF FILE(CLPF2) OPNID(F2) DOWHILE COND(1 = 1) RCVF MONMSG MSGID(CPF0864) EXEC(LEAVE) CHGVAR VAR(&NO) VALUE(&ROLLNO) CHGVAR VAR(&NM) VALUE(&NAME) ENDDO DOWHILE COND(1 = 1) RCVF OPNID(F2) MONMSG MSGID(CPF0864) EXEC(LEAVE) CHGVAR VAR(&ID) VALUE(&F2_STUID) CHGVAR VAR(&NAME) VALUE(&F2_STUNAME) ENDDO ENDPGM