ERRMSGID shows the same field-level error as ERRMSG, except the text comes
from a message file and may carry replacement values:
A CUST 6 0I 4 12
A 51 ERRMSGID(USR0002 APPMSGF 51 &MSGDTA)
A MSGDTA 6A P
The arguments are the message id, the message file, an optional response
indicator, and an optional &field naming the program-to-system field
(usage P) that holds the message's replacement data. The response indicator
and the &field are each optional and either may be written without the other.
Everything else behaves exactly as for
ERRMSG - message line,
reverse image, cursor placement, response-indicator reset, and first-field-wins
when several fields are in error.
Describing the message file
rpgc reads a message file from ADDMSGD source - the same source a shop already
keeps for CRTMSGF. Put it in a file named after the message file with a
.msgf extension, alongside your source or on
--dds-path, exactly as .dspf
and .pf are resolved:
CRTMSGF MSGF(APPLIB/APPMSGF) TEXT('Application messages')
ADDMSGD MSGID(USR0001) MSGF(APPLIB/APPMSGF) MSG('Quantity must be > 0')
ADDMSGD MSGID(USR0002) MSGF(APPLIB/APPMSGF) MSG('Customer &1 not found') FMT((*CHAR 6))
Only what the message line needs is read: MSGID, MSG, and FMT. A
CRTMSGF line, SECLVL message help, other keywords, and comments are accepted
and skipped, so a real source member loads without editing. CL continuation
(+ / -) is honored.
Replacement data
FMT describes the layout of the replacement data, and the placeholders &1,
&2, … in the message text are filled from it positionally: the first FMT
entry takes the first positions of the &field's value, the second the next,
and so on. Data shorter than the layout is treated as blank-padded. A
placeholder with no matching FMT entry is left in the text as written - there
is no value to put in its place.
Only *CHAR replacement data is supported. Other FMT types (*DEC,
*BIN, …) are rejected at compile time rather than rendered as a wrong value:
[ERROR] APPMSGF.msgf:2:0 - Message 'USR0002' declares FMT(*DEC …). rpgc can lay out only *CHAR replacement data, because non-character replacement values are binary in the display file's program-to-system field and its bytes are not addressable at runtime.
Convert the value to character in the program (for example with %EDITC) and
describe it as *CHAR.
Unresolved references
A message file that cannot be found, or a message id that is not described in it, fails the compile with a diagnostic anchored at the DDS line - the message is never silently left blank:
[ERROR] CUSTMAINT.dspf:12:45 - Cannot find message file 'APPMSGF' (looked for APPMSGF.msgf in the source directory and on --dds-path), needed by ERRMSGID.
[ERROR] CUSTMAINT.dspf:12:45 - Message 'USR0002' is not described in message file 'APPMSGF'.