Status messages are the messages that wink and blink at users during certain system functions like Copy File (CPYF) or Open Query File (OPNQRYF). They are helpful when a long-running function is occurring and you want to tell the user that something good is happening or you want to show progress as you perform different logical steps. With some simple coding, you can make your program a lot more informative to the end user.
Status messages are sent to the external message queue (*EXT). Every job has an external message queue that the system creates automatically. Fully understanding the external message queue is not easy, but, fortunately, you only have to name it to use it. You don't have to worry about whether your program is running interactively or in batch. If you send a status message in a batch job, it is just ignored.
There is room for only one status message at a time on a display. To clear off a status message, you must do one of the following:
o Use one of the commands that sends a status message.
o Send another status message.
o Send a blank message. The system provides CPI9801 for this purpose. It is a totally blank message with no message data that is actually sent to the display.
o Return to a command entry display, which automatically clears the status line. Note that if a CL program returns to another program (not a command entry display), the message is not cleared when the CL program ends.
When you send a status message, users cannot put the cursor on the message and request help as they can with many system messages. Consequently, there is no way for users to determine which message ID is being used when they see a status message. Furthermore, when you send CPI9801, no one can tell that you just sent blanks to the display.
To send a status message, the message must exist in a message file. You can add a specific message description for each status message. I prefer to use CPF9898, which is a blank message provided by the system, and control the text of the message by using the MSGDTA parameter.
Assume you want to use Display Object Description (DSPOBJD) in a CL program to create an outfile. This operation takes some time, so you want to send a status message to inform the user of what is happening. The code you would need is shown in 1. You either remember the details of the two commands or look up a sample each time you want to send a status message.
Assume you want to use Display Object Description (DSPOBJD) in a CL program to create an outfile. This operation takes some time, so you want to send a status message to inform the user of what is happening. The code you would need is shown in Figure 1. You either remember the details of the two commands or look up a sample each time you want to send a status message.
A much simpler command, Send Status Message (SNDSTSMSG), is in both QUSRTOOL and the TAAProductivity Tools. (For more information, see the "Obtaining and Installing the SNDSTSMSG Command" sidebar.) If you can remember the command name, you just key in the code shown in 2. The special value *REMOVE sends the CPI9801 message to blank out the status line. The SNDSTSMSG tool uses CPF9898, which automatically places a period at the end of the message.
A much simpler command, Send Status Message (SNDSTSMSG), is in both QUSRTOOL and the TAAProductivity Tools. (For more information, see the "Obtaining and Installing the SNDSTSMSG Command" sidebar.) If you can remember the command name, you just key in the code shown in Figure 2. The special value *REMOVE sends the CPI9801 message to blank out the status line. The SNDSTSMSG tool uses CPF9898, which automatically places a period at the end of the message.
You cannot use the Send Program Message (SNDPGMMSG) command from a high-level language (HLL) program by using QCMDEXC because SNDPGMMSG is restricted to a CL program. You can, however, use the QMHSNDPM API or call a CL program and use SNDPGMMSG. Once again, QUSRTOOL makes it easier. You can call the command processing program (CPP) of SNDSTSMSG directly using code, as shown in 3, then do your long-running function.
You cannot use the Send Program Message (SNDPGMMSG) command from a high-level language (HLL) program by using QCMDEXC because SNDPGMMSG is restricted to a CL program. You can, however, use the QMHSNDPM API or call a CL program and use SNDPGMMSG. Once again, QUSRTOOL makes it easier. You can call the command processing program (CPP) of SNDSTSMSG directly using code, as shown in Figure 3, then do your long-running function.
If you happen to be using a command (such as CPYF or OPNQRYF) that sends a status message, the end user may be confused by messages blinking on and off the screen. You can prevent status messages from being displayed using the technique shown in 4.
If you happen to be using a command (such as CPYF or OPNQRYF) that sends a status message, the end user may be confused by messages blinking on and off the screen. You can prevent status messages from being displayed using the technique shown in Figure 4.
The bad thing about this type of coding is that, if your program terminates abnormally, the second Change Job (CHGJOB) command may never get executed. The result is that the user's job is set for STSMSG(*NONE). In another article, I'll talk about how to recover automatically.
Jim Sloan is president of Jim Sloan, Inc., a consulting company. Now a retired IBMer, Sloan was a software planner on the S/38 when it began as a piece of paper. He also worked on the planning and early releases of the AS/400. In addition, Jim wrote the TAA tools that exist in QUSRTOOL and is now the owner of the TAA Productivity Tools product. He has been a speaker at COMMON for many years.
Programmer's Toolbox
Obtaining and Installing the SNDSTSMSG Command
The SNDSTSMSG command can be found in the TAA Tools in the QUSRTOOL library, which is shipped with every AS/400 through V3R1M0. The TAATools of QUSRTOOL will no longer be shipped with V3R6.
The QUSRTOOL library must be unpackaged and each tool within the library must be created. If you haven't unpackaged the QUSRTOOL library, see source member AAAMAP in source file QATTINFO, library QUSRTOOL for instructions. If you haven't created all the tools or at least the SNDSTSMSG command, see source member CRTTAATOOL in source file QATTINFO, library QUSRTOOL for instructions.
The SNDSTSMSG command can also be found in TAA Productivity Tools, a licensed product from Jim Sloan, Inc. TAA Productivity Tools ships with both source and object code already created. There's no need to create the tools as with the QUSRTOOL library (the SNDSTSMSG command will already exist in library TAATOOL).
For more information about TAA Productivity Tools, contact
Jim Sloan, Inc.
c/o Barsa Consulting Group, Inc.
914-939-6100
Programmer's Toolbox
Figure 1: Sending a Status Message with SNDPGMMSG
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('DSPOBJD + outfile being created')
TOPGMQ(*EXT)+ MSGTYPE(*STATUS) DSPOBJD OBJ(lib/object) OBJTYPE(object-type)
+ OUTPUT(*OUTFILE)OUTFILE(QTEMP/DSPOBJDP) SNDPGMMSG MSGID(CPI9801)
MSGF(QCPFMSG) TOPGMQ(*EXT) + MSGTYPE(*STATUS)
Programmer's Toolbox
Figure 2: Sending a Status Message with SNDSTSMSG
SNDSTSMSG MSG('DSPOBJD outfile being created') DSPOBJD OBJ(XXX/YYYY)OBJTYPE(*ALL) OUTPUT(*OUTFILE)+ OUTFILE(QTEMP/DSPOBJDP) SNDSTSMSG MSG(*REMOVE)
Programmer's Toolbox
Figure 3: Sending a Status Message from Within an RPG Program
I 'Please wait' C MSG * * Send status message... C MOVELMSG STSMSG80 C CALL 'SNDSTS' C PARM STSMSG ** Do some long running function here ... * * * Remove status message...C MOVEL'*REMOVE 'STSMSG P C CALL 'SNDSTS' C PARM STSMSG
Programmer's Toolbox
Figure 4: Preventing Status Messages from Displaying
DCL VAR(&STSMSG) TYPE(*CHAR) LEN(7) /* Retrieve current value */RTVJOBA STSMSG(&STSMSG) / * Turn off status messages */CHGJOB STSMSG(*NONE) /* Run a command which causes a status message */CPYF FROMFILE(FILE_A) TOFILE(FILE_B) + MBROPT(*REPLACE)/* Put back previous value */ CHGJOB STSMSG(&STSMSG)
LATEST COMMENTS
MC Press Online