While searching the ResourceLibrary topics list for message handling ideas for the AS/400, I came across several conversations on this subject which had been taken from the BBS. Someone was trying to figure out how to display a message on the screen in an interactive program in a way similar to the method of using message members on the S/36. He was given many suggestions, but none of them included the use of the IBM-supplied subroutine SUBR23R3 - Message Retrieval Subroutine. This routine is used in conjunction with message files. First you create the message file (CRTMSGF); then create your messages (ADDMSGD); then on an error in your RPG/400 program you simply tell SUBR23R3 which message to retrieve by calling the subroutine with the required parameters.
After creating your message file using USR9999 (9999 = any 4 digit ID number) for your MSGID codes, use OVRMSGF in your CL to use your own message file instead of the default QUSERMSG. (You could also add your message to QUSERMSG and eliminate this step, but I prefer to keep my messages separate.)
OVRMSGF MSGF(QUSERMSG) +
There are five parameters which you must pass to the subroutine from your RPG/400 program. For more information on these parameters, see the section on Calling Special Subroutines in Chapter 10 of the RPG/400 User's Guide.
4-digit numeric field which will be prefixed with 'USR' and used to
retrieve your message (similar to MIC).
Name of the alpha field where the message text will be placed (I used
the same name as an output-only field on the screen conditioned by my
1-byte numeric field that designates message level. Level 1 for this
example - message text is less than 132 characters.
1-byte number field that will contain the return code from the call to
4-byte number field that contains the length of the message text.
In the first cycle routine in your program, initialize the parm values.
Z-ADD0 MSG# 40
MOVE *BLANKS MSGTXT 75
Z-ADD1 LVL 10
Z-ADD0 RTNCD 10
Z-ADD75 TXTLEN 40
When an error is encountered on the screen, just load MSG# with the MIC you
want to retrieve from the message file and call the subroutine.
ERROR IFEQ 'Y'
MSGTXT now contains the message text retrieved from message USR0001 in the specified message file.
Laura Collins-Sultani Virginia Beach, Virginia