Retrieve message descriptions from a message file

You can retrieve the text of a message from a message file into a variable in a CL procedure.

You can do this using the Retrieve Message (RTVMSG) command. Retrieve Message (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 substitution variable &1 and &2 is contained in the procedure variable &A, in which the values of the procedure variables &FILE and &LIB have been concatenated. When the retrieve command is done, 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 Retrieve Message (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 substitution variable names that are included in the text. The system intends on Retrieve Message (RTVMSG) to return a sendable message.