Using APIs to Send Impromptu Messages, Take Two
January 17, 2007 Hey, Ted
The code for this story is available for download here.
In your article, Using APIs to Send Impromptu Messages, you show how to use a message subfile to display impromptu error messages from an RPG program. The logic works great if you call the message-handling APIs from the main logic. However, when I move the API calls into subprocedures, your technique breaks down. What do I need to do?
The problem is that you are now sending messages from a different call stack entry. (I hesitate to use the terms “higher” and “lower” when talking about call stack entries, as they tend to confuse.) Fortunately, this is easy to fix.
Here are the calls from the article you mention.
SendMsg (*blanks: *blanks : Msg : %size(Msg): '*INFO': '*': 0: *blanks: ErrorDS); ClrMsgQ ('*': *zero: *blanks: '*ALL': ErrorDS);
Notice the sixth and seventh parameters of QMHSNDPM, and first two parameters of QMHRMVPM. These refer to the call stack entry and call stack counter. The asterisk in the first of those two parameters and the zero in the second one together point to the current call stack entry.
The simple solution is to replace the asterisk with the program name, which you already have because you need it for the display file.
QMHSNDPM (*blanks: *blanks : Msg : %size(Msg): '*INFO': PgmNam: 0: *blanks: ErrorDS); QMHRMVPM (PgmNam: *zero: *blanks: '*ALL': ErrorDS);
I have revised the example program from the previous article so that it uses subprocedures. The RPG and DDS code are available for download.
I’m glad to see you using subprocedures. I keep telling myself that I am going to quit using subroutines completely, but I haven’t done so yet.