Wednesday, June 18, 2008

Control Language Programming

1.OVER RIDING DBF

CHGPF -> Change the maximum member.
ADDPFM- > Add the new member name.
Create override CLP program.

Program:

RUNQRY *N (lib/filename)
OVRDBF FILE (filename) TOFILE (lib/filename) MBR (newMembername)
CALL PGM (rpgpgmname)
DLTOVR FILE (filename)

In over riding DBF, We can add records to the Member which ever created newly.


2.OPNQRYF

OPNQRYF FILE (LIB/FILENAME) QRYSLT (CNDN)

After creating query we can have it in a separate file

CPYFRMQRYF FROMFILE (fileA) TOFILE (fileB) CRTPF (*YES)

Then we have to close the Opened PF.

CLOF OPNID (fileA)

3.CL PROGRAM FOR PF

PGM
DCLF FILE (LIBNAME/FILENAME) RCDFMT (RECORDFORMAT)
LABEL1: RCVF RCDFMT (RECORDFORMAT)
MONMSG MSGID (CPF0864) EXEC (GOTO CMDLBL (EXIT))
SNDUSRMSG MSG (&NAME)
GOTO CMDLBL (LABEL1)
EXIT: CLOF OPNID (FILENAME)
ENDPGM

RCVF is used to receive the information Message from Physical file.


4.CL PROGRAM FOR DISPLAY FILE

Here I have used a display file to show the week days.

And I also used a data area, declared with size 21. And data area is named as ‘WEEK’

It has following information.

Value
Offset *...+....1....+....2....+....3....+....4....+....5
0 'MONTUEWEDTHUFRISATSUN'

And my display file contains two fields, One input (INP) and one output (OUP).

Program for CL is given below,

PGM
DCLF FILE (LIBNAME/filename) RCDFMT (dsprecformat)
DCL VAR (&VAR1) TYPE (*DEC) LEN (2 0)
L1: SNDRCVF RCDFMT (dsprecformat)
IF COND (&IN03 *EQ '0') THEN (DO)
IF COND (&INP *NE 0) THEN (DO)
CHGVAR VAR (&VAR1) VALUE (&INP * 3 - 2)
RTVDTAARA DTAARA (LIBNAME/WEEK (&VAR1 3)) RTNVAR (&OUP)
ENDDO
GOTO CMDLBL (L1)
ENDDO
ENDPGM


Another program for demonstration of Display files with CLP.

PGM
DCLF FILE (PALANI/CLPDSP2)
L1: SNDRCVF
IF COND (&IN03 *EQ '1') THEN (GOTO CMDLBL (RE))
CHGVAR VAR (&C) VALUE (&A + &B)
GOTO L1
RE: RETURN
ENDPGM

Display file has three fields (A, B, C)


5.Passing parameters between two CL programs

Consider the situation, program is written for that.

PGM
DCLF FILE (lib/ PF filename) RCDFMT ( rec format PF)
DCL &IN03 *LGL
FIRST: RCVF RCDFMT (rec format PF)
MONMSG MSGID (CPF0864) EXEC (GOTO CMDLBL(END))
CALL PGM (lib/ CL2 filename) PARM (&EID &PWD &IN03)
IF (&IN03 = '1') THEN (GOTO END)
GOTO CMDLBL (FIRST)
END: ENDPGM

I am going to pass the variable like EID, PWD, IN03 to another program, which is right below

PGM PARM(&EID &PWD &IN03)
DCLF FILE(lib/ display filename) RCDFMT(display recformat)
DCL VAR(&EID) TYPE(*CHAR) LEN(10)
DCL VAR(&PWD) TYPE(*CHAR) LEN(10)
SNDRCVF RCDFMT (display rec format)
ENDPGM


Successfully parameter has been passed. And received in another program.