43
CL Programming Function and Messaging SyedIbrahim Abbas

Iseries CL programming and Messaging

Embed Size (px)

DESCRIPTION

MessagesBuilt in funciton

Citation preview

Page 1: Iseries CL programming and Messaging

CL Programming Function and Messaging

SyedIbrahim Abbas

Page 2: Iseries CL programming and Messaging

Built in FUnction

Page 3: Iseries CL programming and Messaging

Built In Function • %SUBSTRING • %SWITCH • %BINARY

Page 4: Iseries CL programming and Messaging

SUBSTRING • 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

Page 5: Iseries CL programming and Messaging

• 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

Page 6: Iseries CL programming and Messaging

%SWITCH • 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

Page 7: Iseries CL programming and Messaging

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

Page 8: Iseries CL programming and Messaging

Change switch settings

• CHGJOB command allows you to change many job attributes

• SWS parameter is used to change switch settings

Page 9: Iseries CL programming and Messaging

• 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

Page 10: Iseries CL programming and Messaging

%BINARY • It interprets the contents of a char variable as a signed binary

integer • Syntax include

– Variable name – Start position – Length

Page 11: Iseries CL programming and Messaging

Retrieving values in to CL Program

Page 12: Iseries CL programming and Messaging

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..

Page 13: Iseries CL programming and Messaging

Parameter

• 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

Page 14: Iseries CL programming and Messaging

RTVSYSVAL – System Information

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

Page 15: Iseries CL programming and Messaging

Example

• 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

Page 16: Iseries CL programming and Messaging

Parameter

• 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

Page 17: Iseries CL programming and Messaging

Message queues

Page 18: Iseries CL programming and Messaging

Messages • 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)

Page 19: Iseries CL programming and Messaging

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

Page 20: Iseries CL programming and Messaging

• 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

Page 21: Iseries CL programming and Messaging

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

Page 22: Iseries CL programming and Messaging

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

Page 23: Iseries CL programming and Messaging

MONMSG

• Parameters – 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

Page 24: Iseries CL programming and Messaging

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

Page 25: Iseries CL programming and Messaging

• 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.

Page 26: Iseries CL programming and Messaging

Global Monitor

• MONMSG command can be codes as the first command in the CL program after any DCL’s

• 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

Page 27: Iseries CL programming and Messaging

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

Page 28: Iseries CL programming and Messaging

• 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

Page 29: Iseries CL programming and Messaging

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

Page 30: Iseries CL programming and Messaging
Page 31: Iseries CL programming and Messaging

Sending Message

Page 32: Iseries CL programming and Messaging

Commands

Page 33: Iseries CL programming and Messaging

SNDMSG

• Send Information or inquiry messages

Page 34: Iseries CL programming and Messaging

SNDBRKMSG

• This command send message to one or more workstation message queue • This message may “break into” the user’s session, interrupting with a

message

Page 35: Iseries CL programming and Messaging

SNDPGMMSG

Page 36: Iseries CL programming and Messaging

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

• It contains more parameter

Page 37: Iseries CL programming and Messaging

• 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

Page 38: Iseries CL programming and Messaging
Page 39: Iseries CL programming and Messaging
Page 40: Iseries CL programming and Messaging
Page 41: Iseries CL programming and Messaging

SNDUSRMSG

• 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

Page 42: Iseries CL programming and Messaging
Page 43: Iseries CL programming and Messaging