Вы находитесь на странице: 1из 87

Control Language

Programming

P.S. Nair 1
CLP Structure
• PGM Command
• Declare Commands
• CL Processing Commands
• Logic Control Commands

P.S. Nair 2
CLP Structure
• Built-in Functions
• Program Control Commands
• The ENDPGM Command
• Comment Lines
• Labels in CLP

P.S. Nair 3
The PGM Command
• Each statement in CLP is CL Command
• The PGM command used to Identify start of
CLP
• Valid only within CLP
• Must be the First Command in the Program
• Example : PGM PARM(CL-variable name)
• PARM indicates one or more parameters
passed to this pgm from a CALLING pgm.
P.S. Nair 4
Declare Commands
• All Variables and Files used in PGM
should be Declared
• DCL is used to Declare Variables
• DCLF is used to Declare File
• Declare Commands should precede all
other Commands except PGM

P.S. Nair 5
CL Processing Commands
• CL Processing Commands used for
– Manipulating Variables
– Copy Files, Sort Files
– Create Duplicate Objects
– Override with Database Files
– Send Program Messages
– Send and Receive Display Files
– Send User Messages

P.S. Nair 6
Most Frequently used CL
Commands for CL Processing
• CHGDTAARA
• CHGSYSVAL
• CHGVAR
• CPYF
• CRTDUPOBJ
• MONMSG
• RTVSYSVAL

P.S. Nair 7
Examples

• Example for CHGDTAARA - Changing the Data Area Value

• CHGDTAARA DTAARA(MYLIB/MYDATA) VALUE(GOODNIGHT)


• This command changes the value of the data area named MYDATA in
• library MYLIB to GOODNIGHT.

• Note: Data area Can be created using CRTDTAARA command.


• CRTDTAARA DTAARA(MYDATA) TYPE(*DEC)
• Following are the types.
• *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

P.S. Nair 8
Examples
• Example for CHGSYSVAL - Changing the System Value of a
Character

• CHGSYSVAL SYSVAL(QHOUR) VALUE('12')


• This command changes the value of the system value
QHOUR (which is a subvalue of the QTIME system value) to 12.
Because QHOUR is a character variable, 2 characters long, the
system value is set to the character representation of 12, which
is hex F1F2 and, therefore, must be enclosed in apostrophes.

• Then what will be the value of QTIME?


• QTIME system value will be updated because QHOUR is a
subvalue of QTIME.

P.S. Nair 9
Examples
• Example for CHGVAR - Changing Decimal
Variables
• CHGVAR &A &B
• The value of variable &A is set to the
value of the variable &B. If &B has a
value of 37.2, then the value of &A
becomes 37.2 also.

P.S. Nair 10
Examples
• Example for CPYF - Physical File to
Physical File
• CPYF FROMFILE(PERSONNEL/PAYROLL)
TOFILE(TESTPAY/PAYROLL)
MBROPT(*ADD) CRTFILE(*YES) ERRLVL(10)
• This command copies all of the records in
the physical file named PAYROLL in the
PERSONNEL library to the file PAYROLL in
the TESTPAY library.
• P.S. Nair 11
Examples
• Example for CRTDUPOBJ – Creating
Duplicate Objects
• CRTDUPOBJ OBJ(FILEA) FROMLIB(LIB1)
OBJTYPE(*FILE) TOLIB(LIB2) DATA(*YES)
The file named FILEA in library LIB1 is
duplicated and stored in library LIB2.
Authorities granted for FILEA are granted to
the new FILEA in LIB2, and data associated
with FILEA is copied to the newly created
FILEA in LIB2.
P.S. Nair 12
Examples
• Example for MONMSG – Sending Error
Messages

• MONMSG MSGID(CPF0000 CPC0000


CPD0000) EXEC(GOTO CMDLBL(LABEL))

• When any of the messages is received


from any of the commands running in the
program, control branches in the program to
the command identified
P.S. Nair
by the label LABEL. 13
Examples
• Example for RTVSYSVAL – Retrieving
System Value
• RTVSYSVAL SYSVAL(QDATE)
RTNVAR(&DATE)
• This command retrieves the date value
from the system value QDATE and copies it
into the CL variable &DATE. The CL variable
must be declared as a 6-character variable to
match the attributes of the QDATE system
value.
P.S. Nair 14
Logic Control Commands
• Unlike traditional JCL, CLP allows the Use of Logic Control Commands like
IF, DO, and GOTO

• IF COND(&VAR1 *GT &VAR4) THEN(DO)
• SNDPGMMSG MSG('Hi, Variable 1 is Greater')
• ENDDO
• ELSE CMD(DO)
• SNDPGMMSG MSG('Hi, Varibale 2 is greater')
• ENDDO
• /* Looping Structure
• BACK:
• IF COND(&VAR1 *LE 10) THEN(DO)
• CHGVAR VAR(&VAR1) VALUE(&VAR1 + 1)
• GOTO CMDLBL(BACK)
• ENDDO
P.S. Nair 15
The ENDPGM Command
• ENDPGM command is used to END program

• The Command is Optional

• It is valid only within CLP

• It is considered to be good practice to


– Start program with PGM command
– End program with ENDPGM command

P.S. Nair 16
Comment Lines
• Character pair /* and */ are used as
Delimiters

• Example :
• /* This is a Commented Line */

P.S. Nair 17
Labels in CLP
• Label Identifies the Statements in CLP to
which Processing is Directed
• Used along with GOTO statement

• Example :
GOTO END
END: ENDPGM

P.S. Nair 18
CL VARIABLES

P.S. Nair 19
Declaring Variables
• Declaration of Variable means
– Declaration of Name of Variable
– It’s Type
– It’s Length
– It’s Initial Value
• DCL VAR(&variable name)
• TYPE(*DEC, *CHAR, or *LGL)
• LEN(length) VALUE(initial-value)
• Examples:
• DCL VAR(&PAR1) TYPE(*CHAR) LEN(15) VALUE(134.5)
• DCL VAR(&PAR2) TYPE(*CHAR) LEN(15 ) VALUE(134.5 )
• DCL VAR(&VAR1) TYPE(*DEC ) LEN(15 5) VALUE(134.5 )

P.S. Nair 20
Declaration of Files
• File used in CLP must be declared
• DCLF command is used for Declaration of File
• DCLF FILE(library-name/file-name)
RCDFMT(*ALL or record-format-name)
• Only ONE DCLF command is allowed in CLP
• DCLF is valid only within CLP
• Declare a File
• DCLF FILE(LIB/File name)
RCDFMT(RCD1)
P.S. Nair 21
Changing Variables
• CHGVAR command is used for changing the
value of Variable.
• To a Constant :
• CHGVAR VAR(&CITY) VALUE(‘Pune’)
• To the Value of Another Variable
• CHGVAR VAR(&A) VALUE(&B)
• To the Value of an Expression
• CHGVAR VAR(&A) VALUE( &A + 20 )

P.S. Nair 22
CL EXPRESSIONS and
OPERATORS

P.S. Nair 23
EXPRESSIONS
• Expression is a Group of Symbols used to
express certain Values

• Examples of CL commands which use


expressions:
• CHGVAR VAR(&var1) VALUE( 1 + 2 )
• CHGVAR VAR(&var1) VALUE(&var2 + 3)
• CHGVAR VAR(&var1) VALUE(&var2
+&var3)
P.S. Nair 24
Operators
• Operators are Symbols that Instruct
System to Perform Various Types of Basic
Operations on Data
• Example :
• IF COND(&a *EQ &b)
THEN(CALL pgmb)

• Operators can be used in a CLP to Specify


the relationship between logical
expression P.S. Nair 25
Types of Operators
• Logical Operators : *AND, *OR
• Arithmetic Operators : +, -, *, /
• Character Operators : *CAT, || , *BCAT, |
>, | <, *TCAT
• Relational Operators : *EQ, *GT, *LT, *GE,
*LE, *NG, *NL

P.S. Nair 26
Using Logical Operators

• These are used to Specify the relationship between


Operands in a Logical Expression
• Used to Evaluate True or False Condition
• Logical Expression usually contains 2 Operands
• These 2 Operands must be separated by a Logical
Operators
• Examples :
• IF COND(&a = &b) THEN( CALL pgm1)
• IF COND(&a >= &b) THEN( CALL pgm2)
• IF COND(&a < > &b) THEN( CALL pgm3)
• IF COND(&a *LT &b) THEN( CALL pgm4)
P.S. Nair 27
Using Arithmetic Operators
• Arithmetic operators are used for performing calculations in
Arithmetic expressions

• Arithmetic expressions are often used


– In COND parameter of IF command
– In VALUE parameter of CHGVAR command
• Example:
– IF COND(( &a + &b) = &c) THEN ( CALL PGMA)
– CHGVAR VAR(&var) VALUE(&var * 10)
– CHGVAR VAR(&variable) VALUE(&variable / 400)

P.S. Nair 28
Using Character Operators
• Character Operators are used for
Concatenating 2 character string
expressions

• In CLP, Character Operators are Used


– In PRTTXT parameter of CHGJOB command
– VALUE parameter of CHGVAR command
– MSG parameter of SNDMSG, SNDBRKMSG,
SNDPGMMSG, SNDUSRMSG
P.S. Nair 29
Using Character Operators
• *CAT : Concatenation
• Concatenates one or more strings .
• CHGVAR VAR(&VAR2) VALUE(&VAR5 *CAT &VAR8)
• IF VAR5 -> ‘AA’ and VAR8 -> ‘BB’ then o/p will be VAR2 ->
‘AABB’

• *BCAT : Blank Insertion with Concatenation


• Concatenates one or more strings by inserting blanks in between
the string .
• PGM
DCL &RCDCNT TYPE(*CHAR) LEN(3)
CALL PGMA PARM(&RCDCNT)
SNDPGMMSG MSG('PGMA completed' *BCAT &RCDCNT
*BCAT + ’Records Processed') MSGTYPE(*COMP)
ENDPGM
P.S. Nair 30
Using Character Operators Examples
*TCAT : Blank Truncation with Concatenation
• *TCAT will concatenate 2 values and remove all intervening
blanks.
– Example 1:
• CHGVAR VAR(&TODAY) VALUE(&TODAY1 *TCAT
&TODAY2)
• If TODAY1 -> ‘TUESbb’ (b Denotes Blanks) ,TODAY2
-> ‘DAY’
• o/p in TODAY will be ‘TUESDAY’ bb-blanks will be
truncated and concatenated
– Example 2:
• SNDPGMMSG MSG('Device ' *CAT &DEVICE *TCAT '
Mode ' + *CAT &MODE *TCAT ' had security failure, +
session max changed to zero') + TOMSGQ(QSYSOPR)
P.S. Nair 31
CL BUILT-IN FUNCTIONS

P.S. Nair 32
Built-In Functions
• %SWITCH function is Used to test Job
Switches that Condition Processing in CLP

• A Job Switch can have one of 3 Logical


Values:
– 0 - OFF
– 1 - ON
– X - To be Ignored

P.S. Nair 33
% SWITCH in CLP
The 8 job Switches in CLP match the External Indicators U1 -
U8 in RPG
• % SWITCH can be specified in COND parameter of IF
command
• Example1:
IF COND ( %SWITCH ( 1XXXXXX1 ) )
THEN ( CALL RPGPGM1 )
• Example2:
• PGM DCL &A *LGL
CHGVAR VAR(&A) VALUE(%SWITCH(10000001))
.
.
ENDPGM
P.S. Nair 34
%Substring Built-in Function
• %SST function can be used to Manipulate a
character string in a Character Variable to
form a Substring
• To use a %SST function, variable should be
declared as Character
• Example :
%SST ( &DATE 1 4 )
1 : Starting Position
4 : Length of Characters to be Extracted
P.S. Nair 35
% SST In CLP
• %SST is usually specified in COND parm of IF command
• Example:
• IF COND( %SST ( &Variable 1 7 ) *EQ ‘CARITOR’)
• % SST is usually used in VAR and VALUE parameters of CHGVAR
command
• Example1:
• CHGVAR VAR ( %SST ( YYMM 3 2 ) ) VALUE ( % SST (&SYSDATE
12))
• Example 2:
If Var5 = ‘JDEdwards’ -> After applying below logic, Var2 will have
‘JD’
• CHGVAR VAR(&VAR2) VALUE(%SST(&VAR5 1 2 ))

CHGVAR VAR(&VAR2) VALUE(%SUBSTRING(&VAR5 1 2))

P.S. Nair 36
CONTROL STRUCTURES

P.S. Nair 37
Controlling CLP Processing
• A CLP is processed in a Consecutive
sequence unless it is altered by Logic
Control Commands
• Logic Control Commands can be
Conditional or Unconditional
• Unconditional Branching alters Processing
regardless of Conditions
• Conditional Branching alters Processing
under certain conditions
P.S. Nair 38
Unconditional Branching
• GOTO command is classic example of Unconditional Branching

• GOTO command should always be used with a Label

• Syntax : GOTO CMDLBL( label-name )


CMDLBL is a required Parameter
• Example:

• BACK:
• IF COND(&VAR1 *LE 10) THEN(DO)
• CHGVAR VAR(&VAR1) VALUE(&VAR1 + 1)
• GOTO CMDLBL(BACK)
• ENDDO

P.S. Nair 39
Conditional Branching
• IF and ELSE commands are Conditional Branching
commands
• The IF command evaluates the condition of an Expression.
• If the condition is met, certain commands are executed

• Syntax: IF COND ( logical-expression )


• THEN ( CL-Command )
• Example:
• IF COND(&VAR *GT &VAR2) THEN(DO)
• ENDDO

P.S. Nair 40
ELSE command
• The IF command may be paired with the ELSE command.
• ELSE command indicates what Commands to Run if the
Condition is not met

• Syntax: ELSE CMD ( CL - Command )

• Example:
• IF COND(&VAR1 *GT &VAR4) THEN(SNDPGMMSG
MSG(EREWREREW))
• ELSE CMD(SNDPGMMSG MSG('Hi, Varibale 2 is
greater'))
P.S. Nair 41
Using DO group
• The DO command triggers the Execution of a Group of Commands
• The commands listed after the DO command are executed until
ENDDO command is reached
• Each DO command must have ENDDO command.
• ENDDO command terminates the command group
• Example:
• IF COND(&VAR1 *GT &VAR4) THEN(DO)
• SNDPGMMSG MSG('Hi, Variable 1 is Greater')
• ENDDO
• The commands between the DO and ENDDO are often termed as DO
group
• DO group is executed consecutively when the DO command is
triggered
P.S. Nair 42
CALLING PROGRAMS and
PASSING PARAMETERS

P.S. Nair 43
Processing Jobs
• One of the most Important functions of CLP is to Process
Jobs and CALL programs

• A JOB is a Unit of work submitted or Run by Users to


Perform Tasks

• The 4 Commands that allows CALLING programs and


Run jobs
• 1) CALL command 3) RETURN
• 2) TFRCTL command 4) SBMJOB

P.S. Nair 44
Calling Programs
• The CALL command Runs a Program and
Passes control to that Program
• Optionally, CALL command passes
parameter values to the CALLED program
to be processed
• Syntax: CALL PGM(Library / Program Name)
PARM(Parameter Value)

P.S. Nair 45
Using CALL command
• Qualify an Object with the CALL command
– CALL PGM ( USRLIB / FBRCALLR )

• The Library List will be used to Search the


Program if an Object is not Qualified
– CALL PGM ( FBRCALLR )

P.S. Nair 46
Transferring Control
• TFRCTL command calls the Program specified in
Command

• TFRCTL passes control to Program specified in


Command

• TFRCTL removes the transferring Program from the


Program Stack

• The Program stack is the Stack of Programs Active at


the Time
P.S. Nair 47
Transferring Control
• When CALL command is used the CALLING program remains
Active in the Program Stack
• Syntax: TFRCTL PGM(Library Name/Program Name ) +
• PARM(CL - Variable name)
• With the TFRCTL command , Control returns to the previously
called program that is higher in the Program Stack when the
Transferred Program Ends
• Example :
• TFRCTL PGM (TESTLIB /Program1)
• TFRCTL PGM (Program 1)

P.S. Nair 48
Transferring Control

P.S. Nair 49
Returning Control
• The RETURN command ends the
Program

• If the RETURN command is executed the


Commands after RETURN will be Ignored

• RETURN command has no parameters

P.S. Nair 50
Submitting Jobs
• SBMJOB command submits a Job to a
JOB QUEUE to be Processed later as a
BATCH JOB

• A batch job does not require a User


Intervention

• Batch Job runs in the Back Ground and


does not tie up User’s
P.S. Nair
Terminal 51
The SYNTAX of SBMJOB
• In it’s Simplest Form,
• SBMJOB CMD ( CL - Command )
• The most often Used parameters in the SBMJOB command are :
– CMD ( CL - Command )
– JOB ( Job Name )
– JOBD ( Job Description )
– JOBQ ( Job Queue Name )
– JOBPTY ( Job Priority )

• Example:
• SBMJOB CMD(CPYF FROMFILE(LIB1/FILE1) TOFILE(LIB2/FILE1) +
• MBROPT(*ADD) CRTFILE(*YES)) JOB(TESTJOB) JOBQ(QINTER) +
• JOBPTY(1) HOLD(*YES)

P.S. Nair 52
Processing Database Files

P.S. Nair 53
Working with Database Files
• CL programs also Process and Manipulate Database
Files

• Database Files include Physical and Logical files - Only


One file can be declared in CLP either it should be DSPF
or database file.

• We can use CRTPF and CRTLF command to create a


database file

P.S. Nair 54
List of CL Commands to
Process Database Files

• Create Physical File : CRTPF


• Create Logical File : CRTLF
• Override with Database File : OVRDBF
• Delete Override : DLTOVR
• Clear Physical File Member : CLRPFM
• Delete File : DLTF

P.S. Nair 55
Create Physical File Command
• The Create Physical File (CRTPF) command creates a
physical file in the database.

• Syntax for CRTPF

• CRTPF file ( lib name/physical file name) +


• srcfile ( lib name / src file name ) +
• srcmbr ( source-member-name) +
• rcdlen ( record length ) +
• share ( *yes , *no ) +
• lvlchk ( *yes , or *no ) +
• text ( ‘text description’)
P.S. Nair 56
Example - CRTPF
• Examples for CRTPF - Creating a Physical File
• CRTPF FILE(LIB1/PAYTAX)
SRCFILE(SRCLIB/PAYTXS)
• This command creates a physical file named
PAYTAX in the LIB1 library. The source
descriptions in the member PAYTXS in source
file PAYTXS in the SRCLIB library are used to
create the physical file.

P.S. Nair 57
Create Logical File Command

• The Create Logical File (CRTLF) command creates a


logical file in the database.
• Syntax for CRTLF

• CRTLF file (lib name / physical file name)+


• srcfile ( lib name/source file name)+
• srcmbr ( source member name ) +
• share ( *no *yes ) +
• lvlchk ( *yes, or *no ) +
• aut (*change, *all, *use, or *exclude)+
• text( ‘text description’)
P.S. Nair 58
Example - CRTLF
• Examples for CRTLF - Creating a Logical File
• CRTLF FILE(LIB1/PAYTAX)
SRCFILE(SRCLIB/PAYTXS)
• This command creates a logical file named
PAYTAX in the LIB1 library. The source
descriptions in the member PAYTXS in source
file PAYTXS in the SRCLIB library are used to
create the logical file.

P.S. Nair 59
Overriding Database Files
• OVRDBF can direct the system to Process a file other than
the file named in the called program
• OVRDBF can be used to change the attributes of the file
that is being Processed
• Syntax for OVRDBF
• OVRDBF file ( overriden - file-name)
• tofile ( library / file name )
• frcratio ( no of records being
• forced as a block )
• nbrrcds ( no of records being
• moved as a block )
• share ( *yes or *no )
• seqonly ( *yes or *no )
P.S. Nair 60
Using OVRDBF
• OVRDBF is used to qualify the Library where a File is located
• OVRDBF file ( APMAST ) tofile ( TESTLIB / APMAST )

• To override the file named in the called program, and instead to use the
file specified in TOFILE parameter of OVRDBF command

• OVRDBF file ( APMAST ) tofile ( *LIBL / APWORK )

• To override certain attributes of the file being Processed, and instead to


use the attributes specified in the OVRDBF command
• SHARE ( *No ) can be overridden to SHARE ( *Yes )

P.S. Nair 61
Deleting Overrides
• When a File is overridden by the OVRDBF command,
the Override remains effective in CLP until it is explicitly
deleted

• DLTOVR command allows to Cancel overrides.

• Syntax for DLTOVR


• DLTOVR file ( overridden-file-name, *ALL, or *PRTF )

• Example : DLTOVR FILE(APMAST)

P.S. Nair 62
CLRPFM
• The Clear Physical File Member (CLRPFM) command
removes all the data (including deleted records) from the
specified member of a physical file.

• Example for CLRPFM - To remove all the data from a


file
• CLRPFM FILE(LIB1/FIRST) MBR(NAME)
• This command clears the member named NAME in
the physical file FIRST, found in the current library for
the job LIB1.

P.S. Nair 63
DLTF
• The Delete File (DLTF) command deletes the
specified database files or device files from the
system. Deleting the files also frees the storage
space allocated to the file.

• Example for DLTF - Deleting a Specific File


• DLTF FILE(BILLING/ORDERS)

P.S. Nair 64
Processing DISPLAY FILES In
Interactive CLPs

P.S. Nair 65
Concept of Display File
• Display file is set of Formatted Screens

• Display files are mainly Used for


Communications between Programs and
Users In Interactive mode

P.S. Nair 66
Using Messages in CLP
• CL uses Messages to Establish
Communication between Programs and
Users

• Two Types of Messages :


– System Defined Messages
– User Defined Messages

P.S. Nair 67
System Defined Messages
• System Defined Messages are Predefined by the System and Stored in
Messages Files

• System Defined Messages Include


– Escape Messages
Indicates that a severe error has occurred and the program that
sent the message has ended in error. Type of the message is
*ESCAPE.
– Notify Messages
Can be used as an *INQ or *ESCAPE message depending on
the recipient. Type of the message is *NOTIFY.
– Status Messages
Advises the Interactive user of a job’s progress.Can also function
as an *ESCAPE message. Type of the message is *STATUS.

P.S. Nair 68
User Defined Messages
• User Defined Messages are Defined and Created by Users

• User Defined Messages Include


– Predefined User Messages stored in Message Files
Can be created/stored in files and used when ever required to
pass the information . CRTMSGF is the
command used to create the message file.
CRTMSGF MSGF(ITS1991/TEST)
WRKMSGF MSGF(ITS1991/TEST) is the command used to
work with the message file to add , change and
delete messages in the file.
Each message is associated with an message identifier.

– Immediate Messages
P.S. Nair 69
CL Commands for Sending and
Monitoring Messages
• SNDMSG : Send Message
• SNDMSG command is used by a Workstation User to send a User Defined,
Immediate Message to One or More Message Queues
• The message sent can be Informational or for Inquiry
• An Inquiry message requires reply from User .

SNDMSG MSG ( ‘message text’ ) TOUSR ( ‘user profile name’) +
TOMSGQ ( ‘message queue name’) +
MSGTYPE ( *INFO or *INQ ) +
RPYMSGQ ( message queue name )
• SNDMSG command can be used in Interactive Mode and in CL Program
• SNDMSG is more commonly used in Interactive Mode
• The Receivers of the Messages must Use DSPMSG command to display
the Messages

P.S. Nair 70
Send Break Message
• SNDBRKMSG : Send Break Message
• The SNDBRKMSG command sends Immediate messages to
Workstation Message Queues in Break Mode
• The Break Mode interrupts active work station Users and Displays
the message to be displayed
• SNDBRKMSG command can be used in Interactive Mode and in CL
Program
• SNDBRKMSG is more commonly used in Interactive Mode

SNDBRKMSG MSG ( ‘message text’) TOMSGQ ( ‘message queue


name’) +
MSGTYPE ( *INFO or *INQ ) RPYMSGQ ( message
queue name )
P.S. Nair 71
SNDUSRMSG command
• SNDUSRMSG : Send User Message
• The SNDUSRMSG command sends a Predefined or Immediate
Message to a Message Queue

• SNDUSRMSG can be Used only in CLPs

SNDUSRMSG MSG ( ‘message text’) MSGID ( message id ) +


MSGF ( message file name ) MSGTYPE ( *INFO or
*INQ ) +
TOUSE ( User profile name ) TOMSGQ (message
queue name) + MSGRPY ( CL variable name

P.S. Nair 72
SNDPGMMSG
• SNDPGMMSG command is used by CLP to send a Program
• Message to a :
– Workstation User
– System Operator
– User Message Queue
• SNDPGMMSG MSG(‘ message text’) MSGID ( message - ID ) +
• MSGF ( message-file-name ) +
• TOUSE ( user profile name ) +
• TOMSGQ ( message queue name ) +
• MSGTYPE ( *INFO or *INQ ) +
• RPYMSGQ ( message queue name )

P.S. Nair 73
Monitoring Messages
• MONMSG : Monitor Message
• MONMSG command is used to monitor the anticipated
messages in a CLP and to take actions accordingly
• To provide an Escape when an Error Message is
Encountered
• To specify actions to be taken when certain messages occur
during the execution of CLP

MONMSG MSGID ( message ID ) +


CMPDATA ( *none or comparison data ) +
EXEC ( CL - Command )
P.S. Nair 74
Retrieve JOB Attributes

P.S. Nair 75
RTVJOBA

• RTVJOBA is used in a CLP to retrieve attributes of a Job


and place the values in specified CL Variable
• RTVJOBA is valid only in CLP
• It is used to Retrieve Job name,User name, Job type, Date
format, Output Queue, Date etc.
• Example :
• RTVJOBA JOB(&JOBID) OUTQ(&OUTQ) DATE(&DATE)
+ TYPE(&JOBTYPE) SBMMSGQ(&PSMSGQ)
DATFMT(&FMT)

P.S. Nair 76
Advanced CL

P.S. Nair 77
Open Query File
• Most powerful CL command
• Creates temporary Access Path to a file
• This access path can be used only by the
job which executes the OPNQRYF
command
• A HLL can be used to access the records
from the derived file (file containing a
subset of records of original file)
P.S. Nair 78
Uses of Open Query File
• Select a subset of available records
• Order records by one or more fields in the
record
• Join records from different files into one
access path
• Group records together
• Calculate new fields that do not exist in the
physical file
P.S. Nair 79
Data Area
• Definition - Data Area is the Single Field File
with just Single record
• A Data Area is an AS/400 object (*DTAARA)
which can store a small amount of information.
• It is used to store simple and frequently
changing information/data.
• A Data Area can be changed, displayed and
retrieved by CL commands, CL programs or HLL
programs like RPG/400.

P.S. Nair 80
Data Area - Uses
• Passing information between programs
• Passing information within a program
• Supplying reference data that are
processed by programs
– Example: Current Interest Rates which can
change from day to day or Stock Rates which
can change from time to time.

P.S. Nair 81
Data Area - Processing
• Data areas can be processed using CL commands
• These commands can be executed from the command line or from
any CL programs
• Creating a data Area (CRTDTAARA)
• Data Areas are created using the CL command CRTDTAARA
(Create Data Area)
– Syntax : CRTDTAARA DTAARA(library-name/data-area
name) TYPE(data-area-type)
LEN(data-area length decimal-positions)
VALUE(‘initial value’)
TEXT(‘description’)

P.S. Nair 82
Data Area - Processing (Cont . .
.)
– Parameters
• DTAARA parameter specifies the name of the data area.
• TYPE parameter specifies the type of the data area.
• Valid types are,
• *CHAR - for character type
• *LGL - for logical type and
• *DEC - for decimal type
• LEN parameter specifies the length of the data area.
• Max.length of decimal is 15 positions
before the decimal point and 9 positions
after it. Max. length of character type is 2000.
• VALUE is a optional parameter is used to specify the initial
value to be present in the data area.
P.S. Nair 83
Data Area - Processing (Cont .)
• Printing or displaying contents of Data Area
• Contents of a Data Area can be printed or displayed using
DSPDTAARA (Display Data Area ) command
– Syntax: DSPDTAARA DTAARA(library-name/data-area-
name) OUTPUT(display-or-
print)
OUTFMT(output-format)
• Parameters
• OUTPUT parameter can either contain a *, if you want to
display the data area on the screen(default) or *PRINT if you
want to print the output.
• OUTFMT parameter lets you specify the format of the output
, either the default *CHAR format or *HEX format

P.S. Nair 84
Data Area - Processing (Cont .)
• Retrieving the contents of a data area (RTVDTAARA)
• The contents of the data area or a portion of *char data area
can be
• retrieved into a CL variable using the RTVDTAARA command.
– Syntax : RTVDTAARA DTAARA(library-name data-area-name
(substring-start-position substring-length)) RTNVAR(&CL-
variable name)
– Parameters
• DTAARA parameter specifies the name of the data area
whose value is to be retrieved.
• RTNVAR parameter specifies the CL variable name into
which the contents of the data area is to be retrieved.
• The default of the copy is *ALL unless you specify the length
and starting position of the data area content to be copied

P.S. Nair 85
Data Area - Processing (Cont .)
• Changing the content of Data Area (CHGDTAARA)
• The entire contents of the entire data area or a portion of the
*CHAR data area can be changed by using CHGDTAARA(change
data area
• command)
– Syntax: CHGDTAARA DTAARA(library-name data-area-name
(substring-start-position substring-length)) VALUE(new
value)
• Deleting a Data Area
• A Data Area can be deleted using the DLTDTAARA(Delete
Data Area)
• command.
– Syntax: DLTDTAARA DTAARA(library-name/ data-area-name)
P.S. Nair 86
Local Data Area
• Automatically provided by AS/400 for each job in the system.
• Not a permanent Object
• Created when a job is started and disappears when the job ends
• RTVDTAARA,CHGDTAARA and DSPDTAARA can be used on
Local Data Area using the DTAARA(*LDA)
• Explicit Creation/Deletion of LDA is not possible
• When using SBMJOB the submitting job’s *LDA is copied to the
submitted job’s LDA. After the job is submitted , its *LDA exists
separately from that of the submitting job
• *LDA can be used to pass values from one program to another

P.S. Nair 87

Вам также может понравиться