Evaluate Weigh the pros and cons of technologies, products and projects you are considering.

How to create a message subfile

How can I create a message subfile?

Message subfiles are an easy and useful way to display error, warning, and informational messages to the screen. They are easy to set up in your DDS and call in your RPG programs. You simply send messages to the program message queue via a call to the Send Program message API and the message subfile takes care of displaying the messages at the bottom of the screen.


Add these 2 record formats to your display file DDS: 
A* MESSAGE SUBFILE RECORD                                                 
A          R MSGSFL                                                 
A                                      SFL                         
A                                      SFLMSGRCD(24)               
A            MSGKEY                    SFLMSGKEY                   
A            MSPGMQ                    SFLPGMQ                     
A* MESSAGE SUBFILE CONTROL RECORD                             
A          R MSGCTL                    SFLCTL(MSGSFL)               
A N03                                  SFLEND                       
A                                      SFLDSP                       
A                                      SFLDSPCTL                   
A                                      SFLINZ                       
A                                      SFLSIZ(0010)   
A                                      SFLPAG(0001)   
A            MSPGMQ                    SFLPGMQ(10)                                                                     

Then add this code to your RPG program. 

     D clrpgmmsg       pr                  extpgm('QMHRMVPM') 
     D   callstkent                  10a   const 
     D   callstkcntr                 10i 0 const 
     D   messagekey                   4a 
     D   messageRmv                  10a 
     D   errorcode                     *   const 

     D sndpgmmsg       pr                  extpgm('QMHSNDPM') 
     D   messageid                    7a   const 
     D   qualmsgf                    20a   const 
     D   msgdata                    256a   const 
     D   msgdtalen                   10i 0 const 
     D   msgtype                     10a   const 
     D   callstkent                  10a   const 
     D   callstkcntr                 10i 0 const 
     D   messagekey                   4a 
     D   errorcode                     *   const 

     D   messageid     s              7a 
     D   qualmsgf      s             20a 
     D   msgdata       s            256a 
     D   msgdtalen     s             10i 0 
     D   msgtype       s             10a 
     D   callstkent    s             10a 
     D   callstkcnt    s             10i 0 
     D   messagekey    s              4a 
     D   messageRmv    s             10a 

       mspgmq = '*'; 

       // clear program message queue     
       messageRmv = '*ALL'; 
              callstkent = '*'; 
       callstkcntr = 0; 
       messagekey = ' '; 
           callstkent: callstkcnt: messagekey: 
           messageRmv : *null ); 

       // send message to program message queue     
       messageid = 'CPF9898'; 
       qualmsgf   = 'QCPFMSG   *LIBL     '; 
       msgdata     = 'This is an error message'; 
       msgdtalen  = %len(%trim(msgdata)); 
       msgtype    = '*DIAG'; 
       callstkent = '*'; 
       callstkcntr = 0; 
       messagekey = ' '; 
       sndpgmmsg( messageid: qualmsgf: 
           msgdata : msgdtalen: msgtype: 
           callstkent: callstkcnt: messagekey: 
           *null ); 

       // now write the subfile message control record 
       // and the screen record 
       write(E) MSGCTL;   
       exfmt fmt01; 


The code to clear the message queue and send a message to the message queue would be great candidates to drop into procedures in a common service program.

More on this topic

Visit the ITKnowledge Exchange and get answers to your DB2 questions fast.

Check out this Search400.com Featured Topic: Expert advice on DB2 

Search400.com's targeted search engine: Get relevant information on DB2/400. 

The Best Web Links: Tips, tutorials and more. 


Dig Deeper on DB2 UDB (universal databases)

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.