On the FMT parameter on the Add Message Description (ADDMSGD) command, you can specify substitution variables for either first- or second-level messages.
For example:
File &1 not found
contains the substitution variable &1. When the message is displayed or retrieved, the variable &1 is replaced with the name of the file that could not be found. This name is supplied by the sender of the message. For example:
File ORDHDRP not found
Compare this to:
File not found
Substitution variables can make your message more specific and more meaningful.
The substitution variable must begin with & (ampersand) and be followed by n, where n is any number from 1 through 99. For example, for the message:
File &1 not found
the substitution variable is defined as:
FMT((*CHAR 10))
When you assign numbers to substitution variables, you must begin with the number 1 and use the numbers consecutively. For example, &1, &2, &3, and so on. However, you do not have to use all the substitution variables defined for a message description in the message that is sent.
For example, the message:
File &3 not available
is valid even though &1 and &2 are not used in the messages. However, to do this, you must define &1, &2, and &3 on the FMT parameter of the Add Message Description (ADDMSGD) command. For the preceding message, the FMT parameter could be:
FMT((*CHAR 10) (*CHAR 2) (*CHAR 10))
where the first value describes &1, the second &2, and the third &3. The description for &1 and &2 must be present if &3 is used. In addition, when this message is sent, the MSGDTA parameter on the Send Program Message (SNDPGMMSG) command should include all the data described on the FMT parameter. To send the preceding message, the MSGDTA parameter should be at least 22 characters long.
For the preceding message, you could also specify the FMT parameter as:
FMT((*CHAR 0) (*CHAR 0) (*CHAR 10))
Because &1 and &2 are not used in the message, they can be described with a length of 0. Then no message data needs to be sent. (The MSGDTA parameter on the SNDPGMMSG command needs to be only 10 characters long in this case.)
An example of using &3 in the message and including &1 and &2 in the FMT parameter is when &1 and &2 are specified on the DMPLST parameter. (The DMPLST parameter specifies that the data is to be dumped when this message is sent as an escape message to a program that is not monitoring for it.)
The substitution variables do not have to be specified in the message in the same order in which they are defined in the FMT parameter. For example, three values can be defined in the FMT parameter as:
FMT((*CHAR 10) (*CHAR 10) (*CHAR 7))
The substitution variables can be used in the message as follows:
Object &1 of type &3 in library &2 is not available
If this message is sent in a CL procedure or program, you can concatenate the values used for the message data such as:
SNDPGMMSG .....MSGDTA(&OBJ *CAT &LIB *CAT &OBJTYPE)
You must specify the format of the message data field for the substitution variable by specifying data type and, optionally, length on the Add Message Description (ADDMSGD) command. The valid data types for message data fields are:
The following data types are valid only in IBM-supplied message descriptions and should not be used for other messages: