%MSG (message-id : message-file { : replacement-text } )
%MSG is used as the second operand of the SND-MSG operation. %MSG does not return a value, and it cannot be specified anywhere other than for the SND-MSG operation.
%MSG specifies the message to send.
The first operand is the message ID. It must be a character expression in the job CCSID. The message ID is 7 characters long. If the length of the operand is longer than 7, the remaining characters must be blank. At run-time, the message ID must exist in the message file.
- MYMSGF
- MYLIB/MYMSGF
- *LIBL/MYMSGF
The third operand is optional. It specifies the replacement text for the message. It can be a character value in the job CCSID or a data structure.
Examples of %MSG
The following examples assume that message file MYLIBL/MYMSGF exists, and that library MYLIB is in the library list.
If you want to try the examples, you can create the message file using the following CL commands.
- Message ABC0001 has no replacement text.
- Message ABC0002 has one replacement value. The type matches a CHAR(10) value in RPG.
- Message ABC0003 has two replacement values. The type of the first replacement value matches a CHAR(25) value in RPG and the type of the second replacement value matches an PACKED(5:2) value in RPG.
CRTMSGF MYLIB/MYMSGF
ADDMSGD MSGID(ABC0001)
MSGF(MYLIB/MYMSGF)
MSG('MSGID = ABC0001') /* 1 */
ADDMSGD MSGID(ABC0002)
MSGF(MYLIB/MYMSGF)
MSG('MSGID = ABC0002, &1')
FMT((*CHAR 10)) /* 2 */
ADDMSGD MSGID(ABC0003)
MSGF(MYLIB/MYMSGF)
MSG('MSGID = ABC0003, &1, &2.')
FMT((*CHAR 25) (*DEC 5 2)) /* 3 */
The following example sends informational message ABC0001 in message file MYMSGF.
The joblog shows "MSGID = ABC0001".
SND-MSG %MSG('ABC0001' : 'MYMSGF');
The following example sends escape message ABC0002 in message file MYMSGF. Since the replacement text for this message has type CHAR(10), a character expression can be used as the replacement text operand for %MSG.
The joblog shows "MSGID = ABC0002, Error!".
SND-MSG *ESCAPE %MSG('ABC0002' : 'MYMSGF' : 'Error!');
The following example sends informational message ABC0003 in message file MYMSGF. Since the replacement text for this message has two values, a data structure is used to specify the replacement text. Each subfield of the data structure matches a replacement value.
The joblog shows "MSGID = ABC0003, Radio, 15.99.".
DCL-DS ABC0003_text qualified;
item CHAR(25);
price PACKED(5:2);
END-DS;
ABC0003_text.item = 'Radio';
ABC0003_text.price = 15.99;
SND-MSG *INFO %MSG('ABC0003' : 'MYMSGF' : ABC0003_text);