CL 400 PRESENTAT..

Post on 20-Apr-2015

539 Views

Category:

Documents

40 Downloads

Preview:

Click to see full reader

Transcript

CL/400 SESSION 1

What is CL• As/400 control language is a set of commands that you use to control operations

and request system related functions.• A single CL statement is called a CL command.around 1500 CL commands exits. • A command can be typed on a command line and can be grouped together or

compiled into an object into CL program.• CL programs can be used to perform repetitive processing,reducing errors and

need for computer operator intervention.

CL program can perform• start jobs by calling program or submitting jobs for batch processing.• Control sequence of processing with in program and among different programs.• Check for existence of objects with in the system and check for authority.• Create and manage system objects(files,programs and commands).

• With in CL program order of statements can be altered depending on the requirement.

• Pass parameters or values to permit or restrict blocks of code execution.

CL programs• CL programs are compiled program objects.• CL is executed interactively as a command.• Can be submitted as batch processing using SBMJOB.

CL IS NOT A HLL

• Handle error conditions used by programs.• Control communication.

• Send messages between programs,users and other programs.

• Manipulate variable information and,bytes string and date formats.

• Change configuration of as/400 and device attached to it.

CL commands

• Command consists of a verb followed by simple subject or adjective subject combination or a subject phrase.

• Each verb and subject uses a standard abbreviation scheme,usually consists of three most signification consonants in a verb,subjects and adjective.

Command parameters

• CL commands allow specification of one or more command parameters that is values to add flexibility of commands.

Entering parameters in keyword notation

• you can enter any parameter using keyword notation.• parameter keyword followed by parameter value enclosed in parenthesis.• When using keyword notation parameters can be in any order.

CL/400 SESSION 2

Example:

1.DSPTAP DEV(TAP1 or DISK1) OUTPUT(*PRINT)

OR

DSPTAP OUTPUT(*PRINT) DEV(TAP1 OR DISK1)

2.CPYF FROMFILE(FILE1) TOFILE(FILE2)FROMMBR(MEMBER1) +

TOMBR(MEMBER2)MBROPT(*ADD)

Entering parameters in positional notation

• positional notation requires that parameters be designed in specific order.

• Every CL command limits the number of positional parameters that can be specified on the command.DSPTAP allows 1 where as CPYF allows 6 members.

Example:

1. DSPTAP TAP1

2.DSPLIB MINDADB

3.CPYF FILE1 FILE2 MEMBER1 MEMBER2 *ADD

CL/400 SESSION 3

MENU INTERFACE

• AS/400 system consists of hundreds of different menus each having unique name.the name of the main system menu is MAIN.

• Menus are accessed using go and menu parameter.GO T* as a generic entry or GO *ALL gives list of menus.

• Every menu and several as/400 screens contain command line on which commands are entered.

• Pressing F4 from empty command line displays major menu in which commands are grouped into different subjects.

Example: CMDFILE

COMMAND INTERFACE Command prompt facilitates entering of parameters for a command.

• Help and standard function keys assist in filling in the prompt.

• ?---can be used to determine the allowable values for parameter input field.

• &---increases the length if the input field

• >---are used to manipulate entries in list parameter values.

CL/400 SESSION 4 creating CL programs

CL SOURCE MEMBER

• Consists of CL commands and comments.• Free format – statements can begin from any part of the source member.• Blank links can be inserted any where to improve readability.• Commands can be entered in positional,keyword or mixed notation.• comments begins with /* and ends with */.• When a command does not fit into one line of source member

statement,continuation characters + or – can be used• Labels of 10 character length help documentation or can target GOTO

commands.

Four sections in CL source member

1.Program information section

2.Program linkage section

3.Declarative section

4.Procedure section

1.Program information section

For programming documentation purposes

Example:

/* comment area */

2.Program linkage section

Makes the beginning of CL program

Example:

PGM /* linkage section */

3.Declarative section

Defines files and variables in CL program.

Example:

DCL /* declarative section */

DCLF

4.Procedure section

Specifies that a CL program will do when execution.

Example:

IF COND () THEN /*STD SEGMENT*/

DO

---

----

ENDDO /* Procedure section */

PROCEDURE FOR CREATING CL PROGRAMING

• Create a library using CRTLIB command

• Create a source physical file using CRTSRCPF command

• For each specific program add a member to the source physical file.

• Type needed CL commands into the source member.

• Compile CL program,creating program object.

STRECTURE OF CL SAMPLE PROGRAM /* comment area */ PGM /* linkage section */ DCL /* declarative section */ DCLF IF COND () THEN /*STD SEGMENT*/ DO --- ---- ENDDO /* Procedure section */ ------ ------- Return Error:----------

/*Error segment */ ------------ ENDPGM

Types of variables

They are three types are variables in CLP:• *CHAR• *DEC• *LOG

Maximum lengths for each of the three types are:• Decimal -- 15 digits, 9 decimal positions• Character -- 9999 characters • Logical -- 1 character

The default lengths for each of the three types are: • Decimal -- 15 digits, 5 decimal positions • Character -- 32 characters • Logical -- 1 character

VARIABLE DECLARATION SAMPLES

DCL VAR(&STATE) TYPE(*CHAR) LEN(2) VALUE(‘AP’)

DCL VAR(&A) TYPE(*DEC) LEN(2 0) VALUE(10)

DCL VAR(&A) TYPE(*LGL) VALUE(‘0’)

DCL VAR(&A) TYPE(*DEC) LEN(2 0) VALUE(10)

DCL VAR(&LIB) TYPE(*CHAR) LEN(10) VALUE(‘KARISHMA’)

CHGVAR

• Assign value to the variable• value can be literal, another variable or an expression• pass parameters from one variable to an another variable.

Example:

• CHGVAR VAR(&B) VALUE(&A) • CHGVAR VAR(&C) VALUE(&A / &B)• CHGVAR VAR(&A) VALUE(5)• CHGVAR VAR(&A) VALUE((&A) + 1)

EXPRESSIONS

• Arithmetic operators: +,-,*,/• character string operators:

• *CAT or || (concatenation)• *BCAT or |> (concatenation with blanks)• *TCAT or |< (concatenation with truncation)

• Relational operators:• *EQ,*GT,*LT,*GE,*LE,*NE OR =,>,<,>=,<=, ¬=

• Logical operators:• *AND,*OR,*NOT i.e &,|,¬(square brackets)

• Logical constants:

‘0’ false ‘1’ true

Types of variables

They are three types are variables in CLP:• *CHAR• *DEC• *LOG

Maximum lengths for each of the three types are:• Decimal -- 15 digits, 9 decimal positions• Character -- 9999 characters • Logical -- 1 character

The default lengths for each of the three types are: • Decimal -- 15 digits, 5 decimal positions • Character -- 32 characters • Logical -- 1 character

FILES IN CLP

• Declare using DCLF command.• To send or receive information to a workstation from a program a display file

is used.• To read records from a database files.• Only one file can be declared for processing and only input operations are

allowed on database file

Examples:

DCLF FILE(MINDADB/DSPLYMULT) RCDFMT(MULREC)

File processing

SNDRCVF RCDFMT(CONCAT) --you r going to see the display file screen

RCVF RCDFMT(RECFMT NAME) –receive data from the display file.

SNDF RCDFMT(RECFMT NAME) – Send data to a display file.

WAIT : The parameter may be specified only if the file is a display device file.

The possible values are:

*YES

The program waits until the input operation from the device is completed; the next command is not processed until then.

*NO

The program does not wait for the input data; commands continue running Until a WAIT command is reached later in the program.

BASICS• Work management on AS/400 describes how machine organizes and process

work.• Every piece of work that runs on the subsystem is called a job.• A subsystem is a single predefined operating environment in which the system

coordinates the workflow and resources.the attributes of the subsystem determine how is to be done under particular environment to run a job.

TYPES OF JOBS

1.INTERACTIVE JOB : Starts when ever signs on and lasts until the user signs off.job is created by the system to interactively react to the users responses.

2.BATCH JOBS : series of actions are submitted to the Job Queue for execution in a single job stream.

CL/400 SESSION 5 WORK MANAGEMENT

JOBS

Qualified job name has three components.

• JOBNUMBER./USERNAME/JOBNAME

3. spooling job is associated with OUTQ.Job puts the output from program to spooled file.Later spool file is written to a printer.

EXAMPLE:1

Job: QPADEV0003 User: KARISHMA Number: 689581

EXAMPLE :2

In spooled files each and every job has Job name/User name/job Number.

Browse/copy spool file . . . . DATAAREA Name, F4 for list

Job . . . . . . . . . . . . . DATAAREA Name

User . . . . . . . . . . . QSECOFR Name, F4 for list

Job number . . . . . . . . *LAST Number, *LAST

Spool number . . . . . . . . *LAST Number, *LAST, *ONLY

Opt File File Nbr Job Number Date Time

data area 5 QPADEV0004 689478 10/07/05 14:51:01

data area 16 QPADEV0004 689478 10/07/05 15:13:38

data area 17 QPADEV0004 689478 10/07/05 15:13:55

SUBMIT JOB

• SBMJOB allows a job to submit a batch job to job queue.

• Running programs and commands in a batch environment offers overall

system performance advantage.

• Batch jobs run at lower priority then interactive jobs.

• The CMD parameter called as *CMDSTR(command string) is the command to be executed in batch mode.

• Job name,library list,printer device,scheduling information can be specified as parameters to SBMJOB.

RTVJOBA TYPE(&JOBJYPE) IF (&JOBJYE='1') DO

SBMJOB CMD(CALLPGM(BLOODMAST)) + PARM(&MODE &CUSTNBR)

RETURN ENDDO ------ ------(PROCESS GOES HERE)

ENDPGM

EXAMPLE:

SBMJOB CMD(call program) SCDDATE(102104) SCDTIME(120000)

/* self submitting program*/

BLOODTEST: PGM PARM(&MODE &CUSTNBR)

DCL &MODE *CHAR 6

DCL &CUSTNBR *DEC (15 5)

DCL &JOBTYPE *CHAR 1

Calling programs• The call command runs a program and passes control to that program.when

calling program ends,control is returned to the next command in the calling program.

• When you call a program parameters can be passed to that program.• When program is called it is placed in the call stack.

Example: PGMA PGMB PGMC

PGM PGM PGM

------- ----------- -----------

------- ----------- ----------

------- ----------- -----------

CALL PGMB CALL PGMC ----------

--------- ----------- ----------

----------- ------------- ----------

ENDPGM RETURN RETURN

Defining parameters in the called program

• Parameters are defined on PARM keyword of CALL or TFRCTL command.• With in a called program incoming parameters to be declared with DCL command

and must appear in PGM command.• The order of parameters passed must be same in the CALL command used in

calling program and the PGM command used in the called program.• Parameters passed may be either constants or variables.• Up to 40 parameters can be specified on CALL and PGM commands.• Parameters Can have Character,Decimal or logical Data.• Character constant less than 33 positions long are passed to the called program

with a length of 32.• Decimal constants are passed as packed decimal data and must be received in the

called program by variable defined as *DEC(15 5)

• When an error condition occurs during the execution of a program,an escape message(*ESCAPE)is sent to the program.escape messages identifies the specific error that are occurred.

• When exception handler is written in the program then such messages with the popup of ugly screens can be avoided.

• Error messages are stored in a message file. IBM supplied file is (WRKMSGF)QSYS/QCPFMSG.

• Errors that result in escape messages can be monitored using MONMSG command.

• MONMSG command can be specified at command level and a program level.• Message identifiers have three charter prefix allowed by four position ID.

CPF0000 • RCVMSG message can be used to receive escape message sent to CL

program.the message that can be resent using SNDPGMMSG command.

CL/400 SESSION 6ERROR HANDLING

MONMSG• The monitor message(MONMSG) command is used to monitor escape

messages,notify,and status messages sent to the program message Queue of the program in which the command being used.

• Up to 1000 MONMSG commands can be specified in a program.• When a MONMSG is compiled in a control language (CL) program, it

establishes a monitor for the arrival of the specified messages.• The specific message identifiers or generic message identifiers can be

monitored. • When the action specified in the MONMSG command has been performed, and

that action does not end with a GOTO or RETURN command,control returns to the command in the program that follows the command that sent the message.

• The action ends with a GOTO command,control branches to the command in the program specified in the GOTO command.if the action ends with a RETURN command,control returns to the program that called the program that contain the MONMSG command.

• When using program level MONMSG the EXEC parameter if specified can contain only GOTO command.

EXAMPLE:1. MONMSG MSGID(CPF0000 CPF0864 ) EXEC(GOTO CMDLBL(END))

OR

/* MONMSG CPF0864 EXEC(GOTO (END)) */

OR

/* MONMSG CPF0864 *N RETURN */ ---- (HERE CONTROL DIRECTLY GOES TO THE RETURN )

2. CHGVAR MSGID(CPF9801) EXEC (CHGVAR (&A) VALUE (1))

3. ADDLIBLE LIB(LIBRARY NAME)

MONMSG CPF1023

NOTE:

ADDLIBLE- Add Library List Entry

CL/400 SESSION 7

RETURN

RETURN VARIABLES

• Program variables that have significant value only upon return from a command or from another program.

• Many CL commands use CL variables to return external value to a program.

JOBQ • job queue is an object(*JOBQ) where batch jobs wait in line for there turn at

batch processing.u can hold,release or assign higher priorities for jobs in the JOBQ.

• LIBRARY LIST provides the search path to locate the objects specified in he job.

COMMANLY USED RETRIEVAL COMMANDS

• RTVCFGSTS F4 : Retrieve Configuration Status (RTVCFGSTS) • RTVJOBA F4 : Retrieve Job Attributes (RTVJOBA)• RTVDTAARA : Retrieve Data Area (RTVDTAARA)• RTVMBRD : Retrieve Member Description (RTVMBRD)• RTVMSG : Retrieve Message (RTVMSG) • RTVNETA : Retrieve Network Attributes (RTVNETA)• RTVOBJD : Retrieve Object Description (RTVOBJD) • RTVSYSVAL : Retrieve System Value (RTVSYSVAL)• RTVUSRPRF : Retrieve User Profile (RTVUSRPRF)

RTVJOBA

• Name of the job ----- JOB• Name of the user running the job ----- USER• Job number ----- NBR• Job output queue ----- OUTQ• Accounting the code of the job ----- ACGCDE• Execution environment ----- TYPE• Run priority ----- RUNPTY• User library list ----- USRLIBL• Current library list ----- CURLIB• Printer device ----- PRTDEV

1. /* SIMPLE DATE PROGRAM*/

PGM

DCL VAR(&DATE) TYPE(*CHAR) LEN(10) +

VALUE('15/07/2005')

DCL VAR(&DATE1) TYPE(*CHAR) LEN(10)

CHGVAR VAR(&DATE1) VALUE(&DATE)

SNDUSRMSG MSG(&DATE1)

ENDPGM

CL/400 SAMPLE PROGRAMS

2. /* PGM FOR RETRIVING SYSDATE*/

PGM DCL VAR(&USER) TYPE(*CHAR) LEN(10) DCL VAR(&DATE) TYPE(*CHAR) LEN(6) DCL VAR(&TIME) TYPE(*CHAR) LEN(8) RTVJOBA USER(&USER) RTVSYSVAL SYSVAL(QDATE) RTNVAR(&DATE) RTVSYSVAL SYSVAL(QTIME) RTNVAR(&TIME) SNDUSRMSG MSG(&DATE) SNDUSRMSG MSG(&TIME) SNDUSRMSG MSG(&USER)ENDPGM

3. /*PGM FOR SIMPLE ADDITON WITH OUT +DISPLAYFILES */

PGM

DCL VAR(&A) TYPE(*DEC) LEN(2 0) VALUE(10)

DCL VAR(&B) TYPE(*DEC) LEN(2 0) VALUE(10)

DCL VAR(&C) TYPE(*DEC) LEN(3 0) VALUE(0)

DCL VAR(&RES) TYPE(*CHAR) LEN(10)

CHGVAR VAR(&C) VALUE(&A / &B)

CHGVAR VAR(&RES) VALUE(&C)

SNDUSRMSG MSG(&RES)

ENDPGM

4. /* PGM FOR MULTIPLICATION WITH OUT USING DSPLIAY +FILES*/

PGM

DCL VAR(&NUM) TYPE(*DEC) LEN(3 0) VALUE(8)

DCL VAR(&COUNT) TYPE(*DEC) LEN(3 0) VALUE(1)

DCL VAR(&MULTIPLY) TYPE(*DEC) LEN(3 0)

DCL VAR(&RESULT) TYPE(*CHAR) LEN(5)

LOOP: CHGVAR VAR(&MULTIPLY) VALUE(&NUM * &COUNT)

CHGVAR VAR(&RESULT) VALUE(&MULTIPLY)

SNDUSRMSG MSG(&RESULT)

CHGVAR VAR(&COUNT) VALUE(&COUNT+1)

IF COND(&COUNT *NE 20) THEN(GOTO CMDLBL(LOOP))

ENDPGM

5./*PGM USING DATA BASE FILES*/

**CAT(||)=CONCAT|*BCAT(|>)BLANK WITH TRUNCATE|*TCAT(<|)TRU &BLKS**/

PGM

DCLF FILE(MINDADB/READPHY) RCDFMT(RECFMT)

DCL VAR(&SALC) TYPE(*CHAR) LEN(15)

DCL VAR(&MSG) TYPE(*CHAR) LEN(55)

LOOP: RCVF RCDFMT(RECFMT)

MONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(END))

CHGVAR VAR(&SALC) VALUE(&EMPSALARY)

CHGVAR VAR(&MSG) VALUE(&EMPNUMBER |> &EMPNAME |> &SALC )

SNDUSRMSG MSG(&MSG)

GOTO CMDLBL(LOOP)

END:

ENDPGM

NOTE:

1.YOU CANNOT WRITE DATA INTO PF USING CL PGM.

2.YOU CANNOT UPDATE DATA IN A PF USING CL PGM.

3.YOU CANNOT DELETE DATA IN A PF USING CL PGM.

4.ONLY FOR READING IS POSSIBLE BY USING CL PROGRAMMING.

5.IT IS POSSIBLE TO READ DATA IN BOTH PF AND LF.

6.NOT POSSIBLE TO RETRIVE NUMARIC DATA BY USING CL PROGRAMMING ONLY METHOD IS TO MOVE NUMARIC DATA INTO CHAR VARIABLE THEN RETRIVE THAT CHAR VARIABLE.

6./* PGM FOR ARITHMETIC OPERATIONS USING DISPLAYFILE

PGM DCLF FILE(MINDADB/DSPLAYADD) RCDFMT(OPCODE) SNDRCVF RCDFMT(OPCODE) IF COND(&OPERATION = '+') THEN(GOTO CMDLBL(OPT1)) UP1: IF COND(&OPERATION = '-') THEN(GOTO CMDLBL(OPT2)) UP2: IF COND(&OPERATION = '*') THEN(GOTO CMDLBL(OPT3)) UP3: IF COND(&OPERATION = '/') THEN(GOTO CMDLBL(OPT4)) UP4: IF COND(&OPERATION = ' ') THEN(GOTO CMDLBL(END)) OPT1: CHGVAR VAR(&NO8) VALUE(&NO5 + &NO6) SNDRCVF RCDFMT(OPCODE) GOTO CMDLBL(UP1)

OPT2: CHGVAR VAR(&NO8) VALUE(&NO5 - &NO6)

SNDRCVF RCDFMT(OPCODE)

GOTO CMDLBL(UP2)

OPT3: CHGVAR VAR(&NO8) VALUE(&NO5 * &NO6)

SNDRCVF RCDFMT(OPCODE)

GOTO CMDLBL(UP3)

OPT4: CHGVAR VAR(&NO8) VALUE(&NO5 / &NO6)

SNDRCVF RCDFMT(OPCODE)

GOTO CMDLBL(UP4)

END:

ENDPGM.

DSPLAY FILE FOR ARITHMETICAL OPERATIONS

A R OPCODE

A*%%TS SD 20050806 163135 QSECOFR REL-V4R4M0 5769-PW1

A 12 34'B ='

A 10 34'A ='

A 14 34'OPT ='

A 16 34'C ='

A NO5 3S 0B 10 50

A NO6 3S 0B 12 50

A NO8 5S 0O 16 50

A OPERATION 1A I 14 50

7./* PGM FOR MULTIPLICATION OF NUMBERS USING + DSPLYFILE*/

PGM

DCLF FILE(MINDADB/DSPLYMULT) RCDFMT(MULREC MULREC1)

SNDRCVF RCDFMT(MULREC)

CHGVAR VAR(&NUM2) VALUE(&NUM)

CHGVAR VAR(&COUNT) VALUE(1)

LOOP: CHGVAR VAR(&RESULT) VALUE(&NUM2 * &COUNT )

SNDRCVF RCDFMT(MULREC1)

CHGVAR VAR(&COUNT) VALUE(&COUNT + 1)

IF COND(&COUNT *NE 20) THEN(GOTO CMDLBL(LOOP))

ENDPGM

DSPLAY FILE FOR MULTIPLICATION

A R MULREC

A*%%TS SD 20050808 141822 QSECOFR REL-V4R4M0 5769-PW1

A 11 29'ENTER A NUMBER :'

A NUM 3S 0B 11 54

A R MULREC1

A*%%TS SD 20050808 141822 QSECOFR REL-V4R4M0 5769-PW1

A NUM2 3S 0B 10 20

A 10 28'*'

A COUNT 3S 0B 10 33

A 10 42'='

A RESULT 5S 0B 10 47

8. /* PGM FOR STRING HANDLING*/

PGM DCLF FILE(MINDADB/DSPLAYFILE) RCDFMT(CONCAT) SNDRCVF RCDFMT(CONCAT) CHGVAR VAR(&RESULT) VALUE(&FIRST *CAT &MIDDLE *CAT + &LAST) SNDRCVF RCDFMT(CONCAT) CHGVAR VAR(&RESULT) VALUE(&FIRST *BCAT &MIDDLE *BCAT + &LAST) SNDRCVF RCDFMT(CONCAT) CHGVAR VAR(&RESULT) VALUE(&FIRST *TCAT &MIDDLE *TCAT + &LAST) SNDRCVF RCDFMT(CONCAT)ENDPGM

DSPLAY FILE FOR STRING HANDLING

A R CONCAT

A*%%TS SD 20050908 114149 QSECOFR REL-V4R4M0 5769-PW1

A 7 34'FNAME :'

A 10 34'MNAME :'

A 13 34'LNAME :'

A 16 34'RESULT :'

A FIRST 8A I 7 50

A MIDDLE 8A I 10 50

A LAST 8A I 13 50

A RESULT 24A O 16 48

9. /* CALLING PROGRAM */

PGM

DCL VAR(&A) TYPE(*DEC) LEN(5 0) VALUE(6)

DCL VAR(&B) TYPE(*DEC) LEN(5 0) VALUE(5)

DCL VAR(&F) TYPE(*DEC) LEN(5 0)

DCL VAR(&E) TYPE(*CHAR) LEN(5)

CALL PGM(MINDADB/CALLPGMB) PARM(&A &B)

SNDUSRMSG MSG('IN PGM A')

/* DSPJOB */

CHGVAR VAR(&F) VALUE(&A + &B)

CHGVAR VAR(&E) VALUE(&F)

SNDUSRMSG MSG(&E)

RETURN

ENDPGM

CALL PGMB:

PGM PARM(&X &Y)

DCL VAR(&X) TYPE(*DEC) LEN(5 0)

DCL VAR(&Y) TYPE(*DEC) LEN(5 0)

CHGVAR VAR(&X) VALUE(25)

CHGVAR VAR(&Y) VALUE(&X + 7)

/* DSPJOB */

SNDUSRMSG MSG('IN PGM B')

CALL PGM(MINDADB/CALLPGMC) PARM(&X &Y)

RETURN

CALLPGMC

PGM PARM(&L &M)

DCL VAR(&L) TYPE(*DEC) LEN(5 0)

DCL VAR(&M) TYPE(*DEC) LEN(5 0)

DCL VAR(&N) TYPE(*DEC) LEN(5 0)

DCL VAR(&NC) TYPE(*CHAR) LEN(5)

CHGVAR VAR(&L) VALUE(50)

CHGVAR VAR(&N) VALUE(&L + &M)

CHGVAR VAR(&NC) VALUE(N)

/* SNDUSRMSG MSG(&NC) */

SNDUSRMSG MSG('IN PGM C')

/* DSPJOB */

RETURN

CL/400 SESSION 8DATA AREAS

• A data area is an object(*DTAARA). Its purpose is to hold a fixed length block of data.the data is either numeric or alphanumeric.

• It stores single peace of commonly required information such as Cheque no/Roll no etc.

• It is a global object,multiple users can access data area.

• Here data stored permanently,after the success execution of the job.

• Data area may be considered as a single record storage area.

• By using CLP commands we can update/delete/retrieve data area.

ADVANTAGES

• CL can change the contents of data area while it cannot change the content of PF.

• Programs can access many data areas.

• Needs no declaration.

• Data area need not exist at program creation time.

• No DDS requires – created using CRTDTAARA command.

COMMANDS• CRTDTAARA DTAARA(lib/data area-name)

TYPE(data area-type)

LENGTH(data area-length decimal position)

VALUE(initial value).

• DLTDTAARA DTAARA(lib/data area-name).

• DSPDTAARA DTAARA(lib/data area-name).

• CHGDTAARA DTAARA(lib/data area-name (sub string-starting-position string length)) VALUE(new value).

• RTVDTAARA DTAARA(lib/data area-name (sub string-starting-position string length)) RTNVAR(&CL-var-name).

The maximum lengths and the defaults for each of the three

Type (TYPE)

*DEC • This data area contains a decimal value.

*CHAR • This data area contains a character string value.

*LGL • This data area contains a logical value of either one (1) or zero (0)

that can be used to represent two.

Types are as follows

o Decimal

- Max -- 24 digits, 9 decimal positions

- Default -- 15 digits, 5 decimal positions

o Character

- Max -- 2000 characters

- Default -- 32 characters

o Logical -- Maximum and default, 1 character

CL/400 SAMPLE PROGRAMS USING DTAARAS1. /* PGM USING DATA AREAS*/

PGM

DCL VAR(&A) TYPE(*DEC) LEN(3 0) VALUE(111)

DCL VAR(&B) TYPE(*DEC) LEN(3 0) VALUE(222)

DCL VAR(&C) TYPE(*DEC) LEN(8 2)

CHGDTAARA DTAARA(MINDADB/NUMBERS) VALUE(0)

DSPDTAARA DTAARA(MINDADB/NUMBERS)

CHGDTAARA DTAARA(MINDADB/NUMBERS) VALUE(&A)

DSPDTAARA DTAARA(MINDADB/NUMBERS)

CHGDTAARA DTAARA(MINDADB/NUMBERS) VALUE(&B)

DSPDTAARA DTAARA(MINDADB/NUMBERS)

CHGVAR VAR(&C) VALUE(&A + &B)

CHGDTAARA DTAARA(MINDADB/NUMBERS) VALUE(&C)

DSPDTAARA DTAARA(MINDADB/NUMBERS)

CHGVAR VAR(&C) VALUE(&A - &B)

CHGDTAARA DTAARA(MINDADB/NUMBERS) VALUE(&C)

DSPDTAARA DTAARA(MINDADB/NUMBERS)

CHGVAR VAR(&C) VALUE(&A * &B)

CHGDTAARA DTAARA(MINDADB/NUMBERS) VALUE(&C)

DSPDTAARA DTAARA(MINDADB/NUMBERS)

CHGVAR VAR(&C) VALUE(&A / &B)

CHGDTAARA DTAARA(MINDADB/NUMBERS) VALUE(&C)

DSPDTAARA DTAARA(MINDADB/NUMBERS)

ENDPGM

2. /*PGM FOR CHANGE DATA AREA

PGM

DCL VAR(&A) TYPE(*CHAR) LEN(10) VALUE(MINDA)

DCL VAR(&B) TYPE(*CHAR) LEN(10) VALUE(ANIL)

DCL VAR(&C) TYPE(*CHAR) LEN(10) VALUE(KUMAR)

CHGDTAARA DTAARA(DATAAREA03 (1 10)) VALUE(&A)

CHGDTAARA DTAARA(DATAAREA03 (11 20)) VALUE(&B)

CHGDTAARA DTAARA(DATAAREA03 (21 30)) VALUE(&C)

DSPDTAARA DTAARA(MINDADB/DATAAREA03)

/* SNDUSRMSG MSG(&A) */

/* SNDUSRMSG MSG(&B) */

ENDPGM

OUTPUT:

Display Data Area

Data area . . . . . . . : DATAAREA03

Library . . . . . . . : MINDADB

Type . . . . . . . . . : *CHAR

Length . . . . . . . . : 50

Text . . . . . . . . . :

Value

Offset *...+....1....+....2....+....3....+....4....+....5

0 'MINDA ANIL KUMAR '

3./* PGM FOR RETRIVAL OF CHAR DATAAREA

PGM

DCL VAR(&B) TYPE(*CHAR) LEN(50)

RTVDTAARA DTAARA(MINDADB/DATAAREA03) RTNVAR(&B)

SNDUSRMSG MSG(&B)

ENDPGM

CREATION OF DATA AREA

Display Data Area

Data area . . . . . . . : DATAAREA03

Library . . . . . . . : MINDADB

Type . . . . . . . . . : *CHAR

Length . . . . . . . . : 50

Text . . . . . . . . . :

Value

Offset *...+....1....+....2....+....3....+....4....+....5

0 'MINDA ANIL KUMAR '

OUTPUT:

MINDA ANIL KUMAR

4./* PGM FOR RETRIVING NUM DATA

PGM

DCL VAR(&A) TYPE(*DEC) LEN(12 0)

DCL VAR(&B) TYPE(*CHAR) LEN(12)

RTVDTAARA DTAARA(MINDADB/AREA14) RTNVAR(&A)

/* DSPDTAARA DTAARA(MINDADB/AREA14) */

CHGVAR VAR(&B) VALUE(&A)

SNDPGMMSG MSG(&B)

ENDPGM

CREATION OF DATA AREA

Display Data Area

Data area . . . . . . . : AREA14

Library . . . . . . . : MINDADB

Type . . . . . . . . . : *DEC

Length . . . . . . . . : 12 0

Text . . . . . . . . . :

Value . . . . . . . . . : 200507280001

OUTPUT:

200507280001

LOCAL DATA AREA(*LDA)

• When a job is started, a local data area is created by the system for use by the job while it is running.

• The job’s LDA is deleted by the system when the job terminates.

• Each job has its own LDA

• The local data area cannot be accessed by an any other job.the library does not have a library associated with it.

• The local data area has length 1024,type character, and is initialized to blanks.

SBMJOB and LDA

• When SBMJOB is used to submit batch job, the submitting jobs *LDA is copied to batch job’s LDA.

• Both *lad’s exists separately and the change of one *lad’s content does not effect’s the other after creation.

LDA is used to

• To pass values from one program to another with in a job.

• To pass values from a calling program to a batch job.

• Open query file command (OPNQRYF)is used to open a file that contains records which satisfy a specified request.some of the requests which can be made on this command are:

• Query select

• Key fields

• Grouping

To use open query file ,use the following sequence of commands:

1.OVRDBF : Here specify name of the file being override.override the file being opened to SHARE(*YES).IF YOU DO NOT USE share ODP,the file will be reopened by the next program that uses it(the OPNQRYF results will be ignored)

CL/400 SESSION 9OPNQRYF

2.OPNQRYF:issue the open query file command.

3.CALL:invokes the high-level language that will process the selected records.

ADVANTAGES

• An open data path is created when a file is opened.so data retrieving is so fast compare to JLF.

• Grouping record together.

DISADVANTAGES

• Here you create one more data base file to store data,but it is not necessary in case of JLF.

OPEN OPTIONS

1. *ALL

2. *INP

3. *OUT

4. *UPD

5. *DLT

*INP

• Open the file for input. *INP is the only value allowed if join processing or group processing is requested, if UNIQUEKEY processing is specified, or if all the fields in the open query file record format specified on the Format specifications prompt (FORMAT parameter) are for input-only use.

*OUT

• Open the file for output. It is the combination of input and update operations.

*UPD

• Open the file for update operations. If an input operation comes before an update, you must specify *INP when *UPD is specified.

*DLT

• Open the file for delete operations. If a delete operation is preceded by an input operation, you must specify *INP when *DLT is specified.

CL/400 SAMPLE PROGRAM USING OPNQRYF

/* PGM FOR OPEN QUERY*/

PGM

MONMSG MSGID(CPF0000)

OVRDBF FILE(EMP1) SHARE(*YES)

OPNQRYF FILE((MINDADB/EMP1)) QRYSLT('EMPNO = 3')

CPYFRMQRYF FROMOPNID(EMP1) TOFILE(MINDADB/QEMP1) +

MBROPT(*REPLACE) CRTFILE(*YES) FMTOPT(*NOCHK)

RUNQRY QRYFILE((MINDADB/QEMP1 *FIRST))

CLOF OPNID(EMP1)

DLTOVR FILE(*ALL)

ENDPGM

EMP1.PF

A UNIQUE

A R EMPREC

A EMPNO 5P

A EMPNAME 15A

A EMPADD 15A

A EMPSAL 10P 2

A K EMPNO

Built-in-functions • Built in functions are actually procedures written by IBM that may be used in

expressions (IF, EVAL, etc.) as if they are variables.  • Built-in-functions (BIF's) are probably the most exciting new feature in RPG

IV .

• %BINARY or %BIN can be used in expressions and as either operand (receiver) of the Change Variable (CHGVAR) command

The following are examples of how the %BINARY built-in function can be used.

Example 1: Converting binary to decimal

/* CONVERTING BINARY(0012) TO DECIMAL */

PGM

DCL VAR(&N) TYPE(*DEC) LEN(2)

DCL VAR(&B2) TYPE(*CHAR) LEN(2) VALUE(X'0012')

DCL VAR(&S) TYPE(*CHAR) LEN(3)

CHGVAR VAR(&N) VALUE(%BIN(&B2))

CHGVAR VAR(&S) VALUE(&N)

SNDUSRMSG MSG(&S)

ENDPGM

OUTPUT:

018

%SUBSTRING

• The sub string built-in function operates on a character string that is contained in a CL character variable or in a local data area. %SUBSTRING or %SST can be used in expressions and as either operand (receiver) of the Change Variable (CHGVAR) command.

• This built-in function produces a sub string from the contents of the specified CL character variable or local data area. The sub string begins at the specified starting position in the value and continues for the length specified.

• This built-in function can be coded as either %SUBSTRING or %SST.

PGM

DCL VAR(&SUBSET) TYPE(*CHAR) LEN(5)

DCL VAR(&ALPHABET) TYPE(*CHAR) LEN(10) +

VALUE('ABCDEFGHIJ')

CHGVAR VAR(&SUBSET) VALUE(%SST(&ALPHABET 3 5))

SNDPGMMSG MSG(&SUBSET)

ENDPGM

OUTPUT:

CDEFGCDEFG

The following are examples of how the %BINARY built-in function can be used.

Example 2: RETRIEVING RESULTING SUBSTRING

%SWITCH

• The built-in function %SWITCH tests one or more of the eight job switches in the current job and returns a logical value of 1 or 0 .

• If every job switch tested by %SWITCH has the value indicated, the result is a 1 (true); ); if any switch tested does not have the value indicated, the result is a 0 (false).

• The 8-character mask is used to indicate which job switches are tested

0 • The corresponding job switch is tested for a 0 (off).

1 • The corresponding job switch is tested for a 1 (on).

X • The corresponding job switch is not tested.

• The value in the switch does not affect the result of %SWITCH

syntax

IF COND(%SWITCH(0X111XX0)) THEN(GOTO C) OR

CHGVAR VAR(&A) VALUE(%SWITCH(0X111XX0))

• If job switches 1, 3, 4, 5, and 8 respectively contain 0, 1, 1, 1, and 0 respectively when %SWITCH(0X111XX0) is specified in the IF command, the result is true and the program branches to the command having label C. If one or more of the switches tested do not have the values indicated in the mask, the result is false and the branch does not occur.

• If the same mask is used in the CHGVAR command and the result is true, the variable &A is set to a '1'; if the result is false, &A is set to a '0'. Note that &A must be declared as a logical variable.

top related