Você está na página 1de 43

CL Programming Function Messaging

SyedIbrahim Abbas


Built in FUnction

Built In Function

It produces a character string, which is the subset of another string %SST short name It has three parameters
Character variable name Start position Length

It produces a substring from the contents of the specified char variable or local data area The substring begins at the start position and continues for the length specified You can also define start position and length as numeric variable

Whenever a job is created 8 job switches are automatically defined for the job The Switch settings are initially determined by the job description used to start the job The job switch settings are set to 00000000 by default The switch settings are simple logical values of either 0/1, it can be turned ON(1) or OFF(0) independently each other

Comparing Switch settings

You need an exact match for a true result X means to ignore the position for the comparision Return 1 if settings are equal or 0

Change switch settings

CHGJOB command allows you to change many job attributes SWS parameter is used to change switch settings

Here program is setting switch 1 on U1 means job switch 1 In second pgm its testing job switch 5 is on U5 indicator corresponds job switch 5

It interprets the contents of a char variable as a signed binary integer Syntax include
Variable name Start position Length

Retrieving values in to CL Program

RTVJOBA Job Information

Each job has variety of attributes which can be retrieved in to CL program variable using RTVJOBA
Job name Date User name Output Queue Etc..


You can use F4 func key to prompt the RTVJOBA command It will display all the possible parameter Use CL declared variable to retrieve job attributes After retrieving you can use that in program logic

RTVSYSVAL System Information

System values can be retrieved using RTVSYSVAL command Use CL declared variable to store system value


To retrieve system date and date format RTVSYSVAL can retrieve one system value at a time. SYSVAL parameter specifies the value to be retrieved RTNVAR parameter specifies the name of the variable to place the value


RTVSYSVAL system command can be prompted using F4 List of available values can be displayed by prompting system value To find length position the cursor on RTNVAR and Press F1

Message queues

A message can be immediate or pre-defined Immediate message is created by the sender at the time that the message is sent A pre-defined message is created and stored outside the program that uses it Pre-defined messages are stored in message files, and are referenced by their individual message number The system comes with an extensive set of predefined message that support communication between programs and also bet system and its users WRKMSGF MSGF(*ALL)

Message Types
*INFO Informational *INQ Inquiry *NOTIFY Notify *COMP completion *DIAG Diagnostic *STATUS Status *ESCAPE Escape *RPY Reply *COPY Senders Copy *RQS - Request

All messages that are send or received on the system are send to a message queue We need to it to read the message except for break and escape message

Program Message Queue

Every program that executes has a program message queue associated with it When a program is first called, OS/400 creates a program message queue for that program The OS communicate with other programs via their program message queue

Escape Message

When an escape message is send to a CL program, it indicates tat an error has occurred in the program sending the message, and that requested function were not performed If your program receives an escape message, it will crash unless you monitor it You can monitor using MONMSG and then determine how to handle it

MSGID : used to list the escape message that you wish to monitor CMPDTA optional EXEC optional

CMPDTA allows you to check for a particular string in the MSGDTA portion of the message . If its match then it will execute the EXEC parameter command MSGDTA Each message contains execution time variable information that can be inserted in to the message. This is the message data EXEC parameter lets you to specify a CL command to execute when a particular message is detected

Example Pgm

MONMSG only applies to command immediately preceding it Here an error will occur with CHGVAR command if &valueB is diveided by 0 It this message is not monitored , the program would not have continued the execution after the CHGVAR commad that caused the error condition

If the exec parameter is not provided, the error message is simply soaked up and ignored by the program and execute the next command Only the escape message will cause your program to crash if you have not monitored for it. A crash means the program will stop executing at the command that caused the escape message.

Global Monitor

MONMSG command can be codes as the first command in the CL program after any DCLs This global monitor will trap the occurrence of that message anywhere in the program If an error occurs in many places in a program, it may be better use a global monitor, rather than creating a MONMSG for each potential error

Ranges of message

MONMSG can also monitor ranges of message System message stored in the QCPFMSG file are divided in to blocks The format is 3 alpha char followed by 4 digits or char The first 3 char designate the application and last 4 digits are just number to identify the message

No message id ends in 00, that is , there is no message CPF0000, or MCH5000 and so on MONMSG allows you to specify that ends in 00, so we can identify a range of message to monitor If you code for a global monitor for all CPF and MCH message , your program will tolerate vritually any error condition

Individual Monitors

DLFT will issue message CPF2105 if the file being deleted is not exist Individual monitors override the global monitor If any message other than CPF2105 specified, the global monitor will able to trap the other message

Sending Message



Send Information or inquiry messages


This command send message to one or more workstation message queue This message may break into the users session, interrupting with a message


All Types of message can se send through SNDPGMMSG You can send immediate message and Pre-defined message

It contains more parameter

You can merge date from your program to your message You can specify a character string or a variable that is to be included in the message You can also send different types of message


Information or inquiry message It allows the CL variable to receive the reply in to the program, rather than the reply going to the message queue