Using APIs to Send Impromptu Messages
October 9, 2002 Ted Holt
Hey, Ted:
I would like to use the error message APIs QMHRMVPM and QMHSNDPM in an RPG IV program to send messages to an error-message subfile.
| 
 | 
I do not want to have to define the messages in a message file. I would prefer to use constant definitions from within my RPG program. Is this possible?
I’ve searched written manuals and have not yet found a way to do this.
— Russell
Any message that is not sent as an *ESCAPE, *STATUS, or *NOTIFY message can be sent as an impromptu message, Russell. Here’s a short program you can play with. The display file is the JKL001D file from the March 29, 2002, “Odds and Ends” column.
A DSPSIZ(24 80 *DS3) A R FORMAT01 A CA03(03) A OVERLAY A 1 31'Generate Some Report' A 1 72DATE A EDTCDE(Y) A 2 72TIME A 5 8'Enter range of dates in MMDDYY for- A mat. You may leave ending date' A 6 8'blank if the report is to be run f- A or only one day.' A 8 8'Beginning date ...................- A ...........:' A SBGNDATE 6Y 0B 8 55EDTCDE(4) A 9 8'Ending date ......................- A ...........:' A SENDDATE 6Y 0B 9 55EDTCDE(4) A 22 6'F3=Cancel request' A 22 27'Enter=Generate report' A A R MSGSFL SFL A SFLMSGRCD(24) A MSGKEY SFLMSGKEY A PGMNAM SFLPGMQ A A R MSGCTL SFLCTL(MSGSFL) A SFLSIZ(0010) A SFLPAG(0001) A OVERLAY A SFLDSP A SFLDSPCTL A SFLINZ A N87 SFLEND A PGMNAM SFLPGMQ(10)
Notice the SFLPGMQ keywords in both the subfile and subfile control formats. I attached the field name PGMNAM to both of them. (This is a habit from my RPG III days, when the maximum allowable length of variable names was six characters.) This variable gets its value from the program status data structure of the RPG program.
Here’s the RPG source code. I compiled it with Create Bound RPG Program (CRTBNDRPG) command to run in the default activation group. I only included one test for an error. In a production environment, there would be more, of course.
FJKL001D   cf   e             workstn
D Error           s               n
D ErrorDS         ds            16
D   BytesProv                   10i 0 inz(%size(ErrorDS))
D   BytesAvail                  10i 0
D   ExceptionID                  7
D                sds
D  PgmNam           *proc
D
D Msg             s             78
D
D SendMsg         pr                  extpgm('QMHSNDPM')
D   MsgID                        7a   const
D   MsgF                        20a   const
D   MsgData                     30a   const
D   MsgDataLen                  10i 0 const
D   MsgType                     10a   const
D   CallStackEnt                10a   const
D   CallStackCtr                10i 0 const
D   MsgKey                       4a   const
D   Error                             like(ErrorDS)
D ClrMsgQ         pr                  extpgm('QMHRMVPM')
D   MsgQueue                   276a   const
D   CallStack                   10i 0 const
D   MsgKey                       4a   const
D   MsgRmv                      10a   const
D   Error                             like(ErrorDS)
 /free
   dow '0' = '0';
     exfmt format01;
     // clear msg subfile
     callp  ClrMsgQ ('*': *zero: *blanks: '*ALL': ErrorDS);
     if *in03;
        leave;
     endif;
     // ++++++++ calcs to verify data go here ++++++++
     error = *off;
     if (sbgndate = *zero);
        error = *on;
        msg = 'Beginning date must not be blank.';
     endif;
     // ----------------------------------------------
     if not error;
        leave;
     endif;
     callp  SendMsg (*blanks: *blanks :
            Msg : %size(Msg):
            '*INFO': '*':
             0: *blanks: ErrorDS);
     write msgctl;
   enddo;
  if not *in03;
    // do what needs to be done
  endif;
  *inlr = *on;
 /end-free
I hope this helps.
— Ted
| Sponsored By  inFORM DECISIONS | 
| ELIMINATE THE COSTS OF PRE-PRINTED FORMS, LABOR AND POSTAGE WITH iSeries based e-Forms, e-Checks, e-Mail, e-FAX, and Document Retrieval from the Web are available as individual modules or as a complete e-Document processing ‘Suite’. Click to Download the Complete Suite or Individual Modules today | 

 
							  
								
 
					