Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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.
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 IS NOT A HLL
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 are compiled program objects. CL is executed interactively as a command. Can be submitted as batch processing using SBMJOB.
CL programs
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.
CL/400 SESSION 2
Command parameters
CL commands allow specification of one or more command parameters that is values to add flexibility of commands.
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)
Example:
1. DSPTAP TAP1 2.DSPLIB MINDADB 3.CPYF FILE1 FILE2 MEMBER1 MEMBER2 *ADD
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 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.
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 */
Types of variables
They are three types are variables in CLP:
DCL
DCL
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 CHGVAR CHGVAR CHGVAR VAR(&B) VALUE(&A) VAR(&C) VALUE(&A / &B) VAR(&A) VALUE(5) 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:
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.
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.
3. spooling job is associated with OUTQ.Job puts the output from program to spooled file.Later spool file is written to a printer.
JOBS
Qualified job name has three components.
JOBNUMBER./USERNAME/JOBNAME
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 . . . . . . . . . . . . . User . . . . . . . . . . . Job number . . . . . . . . Spool number . . . . . . . . Opt File data area data area data area File Nbr 5 16 17 DATAAREA QSECOFR *LAST *LAST Name Name, F4 for list Number, *LAST Number, *LAST, *ONLY Date Time 10/07/05 14:51:01 10/07/05 15:13:38 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.
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
RTVJOBA TYPE(&JOBJYPE) IF (&JOBJYE='1') DO SBMJOB CMD(CALLPGM(BLOODMAST)) + PARM(&MODE &CUSTNBR) RETURN ENDDO -----------(PROCESS GOES HERE) ENDPGM
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. PGMA PGM ------------------CALL PGMB ------------------ENDPGM PGMB PGM ------------------------------CALL PGMC ----------------------RETURN PGMC PGM --------------------------------------------------------RETURN
Example:
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
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.
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
PGM
DCL VAR(&DATE) TYPE(*CHAR) LEN(10) + VALUE('15/07/2005') DCL VAR(&DATE1) TYPE(*CHAR) LEN(10)
CHGVAR
VAR(&DATE1) VALUE(&DATE)
2.
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 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
DCL
LOOP:
CHGVAR
CHGVAR
VAR(&RESULT) VALUE(&MULTIPLY)
SNDUSRMSG MSG(&RESULT)
CHGVAR
VAR(&COUNT) VALUE(&COUNT+1)
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.
UP3:
IF UP4: IF COND(&OPERATION = ' ') THEN(GOTO CMDLBL(END)) OPT1: CHGVAR VAR(&NO8) VALUE(&NO5 + &NO6) SNDRCVF RCDFMT(OPCODE) GOTO CMDLBL(UP1)
CHGVAR VAR(&NO8) VALUE(&NO5 - &NO6) SNDRCVF RCDFMT(OPCODE) GOTO CMDLBL(UP2) OPT3: CHGVAR VAR(&NO8) VALUE(&NO5 * &NO6)
OPT2:
SNDRCVF
RCDFMT(OPCODE)
SNDRCVF
RCDFMT(OPCODE)
GOTO CMDLBL(UP4)
END: ENDPGM.
R OPCODE
REL-V4R4M0 5769-PW1
A
A A A NO5 NO6 NO8
16 34'C
3S 0B 10 50 3S 0B 12 50 5S 0O 16 50
='
OPERATION
1A I 14 50
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
A*%%TS SD 20050908 114149 QSECOFR A A A A A A A A FIRST MIDDLE LAST RESULT 7 34'FNAME 10 34'MNAME 13 34'LNAME 16 34'RESULT 8A I 7 50 8A I 10 50 8A I 13 50 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 DCL CHGVAR CHGVAR /* DSPJOB */ SNDUSRMSG MSG('IN PGM B') CALL PGM(MINDADB/CALLPGMC) PARM(&X &Y) VAR(&X) TYPE(*DEC) LEN(5 0) VAR(&Y) TYPE(*DEC) LEN(5 0) VAR(&X) VALUE(25) VAR(&Y) VALUE(&X + 7)
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
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).
The maximum lengths and the defaults for each of the three Type (TYPE)
*DEC
*CHAR *LGL This data area contains a character string value. This data area contains a decimal value.
This data area contains a logical value of either one (1) or zero (0) that can be used to represent two.
- Default -- 32 characters
DCL
DCL DCL
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
DCL
DCL DCL
/*
SNDUSRMSG MSG(&B)
*/
ENDPGM
Text . . . . . . . . . :
Value Offset 0 *...+....1....+....2....+....3....+....4....+....5 'MINDA ANIL KUMAR '
OUTPUT:
MINDA ANIL KUMAR
OUTPUT:
200507280001
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.
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)
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.
ENDPGM
EMP1.PF
UNIQUE
A
A A A
R EMPREC
EMPNO 5P
A
A
EMPSAL
K EMPNO
10P 2
Built-in-functions
Built in functions are actually procedures written by IBM that may be used in
The following are examples of how the %BINARY built-in function can be used.
%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.
The following are examples of how the %BINARY built-in function can be used.
OUTPUT:
CDEFGCDEFG
%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.