Guild Companies, Inc.  
 
Midrange Guru - Tech Tips
OS/400 Edition
Volume 2, Number 9 - February 6, 2002

Keeping Users Informed

Hey, Ted:

We have a program that usually runs pretty quickly, but on occasion, it may take as much as five minutes to finish. We don't want to run it in batch because the program needs to finish before the user continues with the next step. Tying up the terminal is a good way to make sure the user doesn't jump the gun.

How can I make a program send a temporary message to let the user know what's going on while a program is running? I'm referring to messages like those that flash up while commands like Copy File (CPYF) or Open Query File (OPNQRYF) are running.

-- Mike

Use the Send Program Message (SNDPGMMSG) command to send a status message to the external message queue.

Here's some code that will work in both OPM and ILE CL programs:











SNDPGMMSG  MSGID(CPF9897) MSGF(QCPFMSG) +
         MSGDTA('Creating work file...') +
         TOPGMQ(*EXT) MSGTYPE(*STATUS)
/* CL commands go here */
 SNDPGMMSG  MSGID(CPF9897) MSGF(QCPFMSG) +
         MSGDTA('Updating database...') +
         TOPGMQ(*EXT) MSGTYPE(*STATUS)
/* CL commands go here */
 SNDPGMMSG  MSGID(CPF9897) MSGF(QCPFMSG) +
         MSGDTA('Printing report...') +
         TOPGMQ(*EXT) MSGTYPE(*STATUS)
/* CL commands go here */

The comments /* CL commands go here */ indicate where you would place commands to carry out the long-running tasks. CPF9897 is a predefined message supplied with the system. Put the real message in the Message data (MSGDTA) parameter.

If you're writing ILE applications, you might want to create a module to send status messages. Here's one that I call STS03CL:

PGM        PARM(&MSG)

DCL        VAR(&MSG) TYPE(*CHAR) LEN(76)

SNDPGMMSG  MSGID(CPF9897) MSGF(QCPFMSG) MSGDTA(&MSG) +
              TOPGMQ(*EXT) MSGTYPE(*STATUS)
ENDPGM

I chose a message length of 76 characters because the system won't show more characters than that on the bottom line of the display.

Use CRTCLMOD to create the module:

CRTCLMOD MODULE(mylib/STS03CL) +
  SRCFILE(mylib/QCLSRC) SRCMBR(STS03CL)

Here's how you would call it from RPG:

D StatusMsg       pr                  extproc('STS03CL')
D   Message                     76    const
C                   callp     StatusMsg ('Doing something ...')
 * long-running task goes here
C                   callp     StatusMsg ('Doing something else...')
 * long-running task goes here
 * more and more code, etc.

Compile your RPG into a module, like this:

CRTRPGMOD ??MODULE(mylib/STS03RG) +
   SRCFILE(mylib/QRPGLESRC) SRCMBR(STS03RG)

Use whatever binding mechanism you like to tie them together. For this example, I combine the modules when I create the program:

CRTPGM PGM(STS03RG) +
   MODULE(STS03RG STS03CL)

-- Ted

Sponsored By
LANSA

LANSA INTEGRATOR SPEEDS DEVELOPMENT & PERFORMANCE OF JAVA

LANSA Partner MDC replaced its hand-written Java remote system integration programs with LANSA Integrator and gained a tenfold increase in performance. InsureIT uses LANSA Integrator to offer XML Java services between heterogeneous insurer & broker systems.

Find out more at http://www.lansa.com/press/20122.htm

THIS ISSUE
SPONSORED BY:
WorksRight Software
LANSA
BACK ISSUES
TABLE OF CONTENTS
Start QINTER Remotely
Keeping Users Informed
Reader Feedback and Insights
  Newsletters | Subscribe | Advertise | About Us | Contact | Search | Home  
  Last Updated: 2/6/02
Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.