CL Programming

Retrieving Messages in a CL Procedure

You can use the Retrieve Message (RTVMSG) command to retrieve the text of a message from a message file into a variable. RTVMSG operates on predefined message descriptions. You can specify the message identifier and message file name in addition to the following:

For example, the following command adds the message description for the message USR1001 to the message file USRMSG:

ADDMSGD   MSGID(USR1001) MSGF(QGPL/USRMSG) +
          MSG('File &1 not found in library &2') +
          SECLVL('Change file name or library name') +
          SEV(40) FMT((*CHAR 10) (*CHAR 10))

The following commands result in the substitution of the file name INVENT in the 10-character variable &FILE and the library name QGPL in the 10-character variable &LIB in the retrieved message USR1001.

DCL &FILE TYPE(*CHAR) LEN(10) VALUE(INVENT)
DCL &LIB TYPE(*CHAR) LEN(10) VALUE(QGPL)
DCL &A TYPE(*CHAR) LEN(20)
DCL &MSG TYPE(*CHAR) LEN(50)
CHGVAR VAR(&A) VALUE(&FILE||&LIB)
RTVMSG   MSGID(USR1001) MSGF(QGPL/USRMSG) +
         MSGDTA(&A) MSG(&MSG)

The data for &1 and &2; is contained in the procedure variable &A, in which the values of the procedure variables &FILE and &LIB have been concatenated. The following message is placed in the CL variable &MSG:

   File INVENT not found in library QGPL

If the MSGDTA parameter is not used in the RTVMSG command, the following message is placed in the CL variable &MSG:

   File not found in library

After the message is placed in the variable &MSG, you could do the following:

Note:
You cannot retrieve the message text with the variable names that are included in the text. The system intends on RTVMSGD to return a sendable message.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]