Skip to main content

Message Subfile

Message Subfile:

Message Subfiles (or Subfile Messages) are very useful for screens where it needs to display multiple messages to the user giving the flexibility to the user to view all the messages by taking PAGE DOWN/PAGE UP. 

These messages can be sent using SNDPGMMSG in CL Program. And, RMVMSG can be used to clear these messages from the Message Queue. 

Message Subfile would then load the messages from the Specified Program Message Queue and display them on the screen. 

However, When we use RPG, it require writing CL Program to execute SNDPGMMSG & RMVMSG to Send or Remove Messages to/from the queue. 

Below APIs become very useful to do the same from RPG program rather than having to create another program to do this. 

  • QMHSNDPM - Send Program Message API.
  • QMHRMVPM - Remove Program Message API.

We will see how to create Message Subfile before going on to using these APIs to send the messages to Queue.

When adding new Record Format in DSPF, Select the type as 'SFLMSG' (Subfile message record). This would prompt for 'Subfile control record' similar to Subfiles. 

There are few Important Keywords to remember when it comes to Message Subfiles. 

SFLMSGRCD - Specify the Line Number where the Message to be displayed on the screen.
SFLPGMQ - Type the name of the field that contains the name of the program message queue. Variable used here needs to be assigned with the Program Name. 

Other Subfile keywords (SFLDSP, SFLDSPCTL, SFLINZ, SFLPAG, SFLSIZ) to be defined similar to the usual subfiles. Click Here to see more about Subfile Keywords. 

Below is the Sample code for Subfile Message (DSPF)

     A* Subfile Message  

     A          R PPMSFL01                  SFL

     A                                      SFLMSGRCD(24)

     A            MSGKEY                    SFLMSGKEY

     A            PGMQ                      SFLPGMQ(10)

     A* Subfile Message Control Format

     A          R PPMCTL01                  SFLCTL(PPMSFL01)

     A                                      SFLDSP

     A                                      SFLDSPCTL

     A                                      SFLINZ

     A                                      SFLSIZ(0002)

     A                                      SFLPAG(0001)

     A            PGMQ                      SFLPGMQ(10)    


We will now see How to define the Prototypes for these APIs and how to call them to send the message and remove the message.

QMHSNDPM (Send Program Message):

QMHSNDPM API require 9 Mandatory parameters. see the Prototype declaration below.

  Dcl-PR SendProgramMessage ExtPgm('QMHSNDPM') ;

    MessageIdentifier Char(7)

    MessageFileName Char(20)

    MessageData Char(80) ;

    LengthOfMessageData Packed(10 : 0) ;

    MessageType Char(10) ;

    CallStackEntry Char(10) ;

    CallStackCounter Packed(10 : 0) ;

    MessageKey Char(4) ;

    ErrorData LikeDs(QUSEC) ;

  END-PR;     


Message Identifier - Predefined Message Identifier from Message File.

Message FileName - Message File along with Library Name (*LIBL can be used). First 10 digits for Message file and next 10 digits are for Library Name.

Message Data - If first two parameters are passed, This field would be used to pass the Data for the Variables used in the Message Identifier in Message File. If first two parameters are Blanks, Message passed in this parameter would be displayed. 

Length Of Message Data - Length of Message Data passed in the previous parameter. 

Message Type - Type of the message sent (*CMD - Command, *COMP - Completion, *DIAG - Diagnostic, *ESCAPE - Escape, *INFO - Informational, *NOTIFY - Notify, *RQS - Request and *STATUS - Status)

Call Stack Entry - Used to Identify the Program Message Queue. '*' to be used to use the current Call stack entry.

Call Stack Counter - Number to identify which Program Message Queue to send the message to. '0' indicates the last Program in the Call stack, '1' to indicate the previous program. Alternatively, any integer to identify the Program in the respective position. 

Message Key - This is Output parameter. 

Error Data - Error info. Error Data structure can be used from QUSEC in QSYSINC/QRPGLESRC. 

            MessageIdentifier = 'MSG0001' ;

            MessageFileName = 'PPTESTMSGF*LIBL     ' ;

            MessageData = *Blanks ;

            LengthOfMessageData = %Len(%Trim(MessageData)) ;

            MessageType = '*INFO' ;

            CallStackEntry = '*' ;

            CallStackCounter = 0 ;

            MessageKey = *Blanks ;


            SendProgramMessage(MessageIdentifier

                              :MessageFileName

                              :MessageData

                              :LengthOfMessageData

                              :MessageType

                              :CallStackEntry

                              :CallStackCounter

                              :MessageKey

                              :ErrorData) ; 


This can be called from RPG when ever there is an error and these messages would be displayed on EXFMT. Message Subfile control format to be written before EXFMT. 

      Write PPMCTL01 ; // Message Subfile Control Format

      Write PPFTR01 ; // Subfile Footer Record Format

      Exfmt PPCTL01 ; // Subfile Control Format


Messages need to be cleared whenever user does some action on the screen. So that these messages will not be shown again. 

QMHRMVPM (Remove Program Message):

QMHRMVPM requires 5 mandatory parameters. See the prototype declaration below. 

  Dcl-PR RemoveMessage ExtPgm('QMHRMVPM') ;

    CallStackEntry Char(10) ;

    CallStackCounter Packed(10 : 0) ;

    MesssgeKey Char(4) ;

    MessagestoRemove Char(10) ;

    ErrorData LikeDs(QUSEC) ;

  End-PR;    


Call Stack Entry - Used to Identify the Program Message Queue. '*' to be used to use the current Call stack entry.

Call Stack Counter - Number to identify which Program Message Queue to send the message to. '0' indicates the last Program in the Call stack, '1' to indicate the previous program. Alternatively, any integer to identify the Program in the respective position. 

Message Key - This is Output parameter. 

Messages to Remove - Used to define a message or group of messages to be removed. *ALL - to remove all the messages

Error Data - Error info. Error Data structure can be used from QUSEC in QSYSINC/QRPGLESRC. 

      CallStackEntry = '*' ;

      CallStackCounter = 0 ;

      MessageKey = *Blanks ;

      MessagestoRemove = '*ALL' ;


      RemoveMessage(CallStackEntry

                   :CallStackCounter

                   :MessageKey

                   :MessagestoRemove

                   :ErrorData) ;



Comments

Popular posts from this blog

All about READ in RPGLE & Why we use it with SETLL/SETGT?

READ READ is one of the most used Opcodes in RPGLE. As the name suggests main purpose of this Opcode is to read a record from Database file. What are the different READ Opcodes? To list, Below are the five Opcodes.  READ - Read a Record READC - Read Next Changed Record READE - Read Equal Key Record READP - Read Prior Record READPE - Read Prior Equal Record We will see more about each of these later in this article. Before that, We will see a bit about SETLL/SETGT .  SETLL (Set Lower Limit) SETLL accepts Key Fields or Relative Record Number (RRN) as Search Arguments and positions the file at the Corresponding Record (or Next Record if exact match isn't found).  SETGT (Set Greater Than) SETGT accepts Key Fields or Relative Record Number (RRN) as Search Arguments and positions the file at the Next Record (Greater Than the Key value). Syntax: SETLL SEARCH-ARGUMENTS/KEYFIELDS FILENAME SETGT  SEARCH-ARGUMENTS/KEYFIELDS FILENAME One of the below can be passed as Search Arguments. Key Fiel

What we need to know about CHAIN (RPGLE) & How is it different from READ?

CHAIN READ & CHAIN, These are one of the most used (& useful) Opcodes by any RPG developer. These Opcodes are used to read a record from file. So, What's the difference between CHAIN & READ?   CHAIN operation retrieves a record based on the Key specified. It's more like Retrieving Random record from a Database file based on the Key fields.  READ operation reads the record currently pointed to from a Database file. There are multiple Opcodes that start with READ and all are used to read a record but with slight difference. We will see more about different Opcodes and How they are different from each other (and CHAIN) in another article. Few differences to note.  CHAIN requires Key fields to read a record where as READ would read the record currently pointed to (SETLL or SETGT are used to point a Record).  If there are multiple records with the same Key data, CHAIN would return the same record every time. READE can be used to read all the records with the specified Ke

Extract a portion of a Date/Time/Timestamp in RPGLE - IBM i

%SUBDT Extracting Year, Month, Day, Hour, Minutes, Seconds or Milli seconds of a given Date/Time/Timestamp is required most of the times.  This can be extracted easily by using %SUBDT. BIF name looks more similar to %SUBST which is used to extract a portion of string by passing from and two positions of the original string. Instead, We would need to pass a value (i.e., Date, Time or Timestamp ) and Unit (i.e., *YEARS, *MONTHS, *DAYS, *HOURS, *MINUTES, *SECONDS or *MSECONDS) to %SUBDT.  Valid unit should be passed for the type of the value passed. Below are the valid values for each type. Date - *DAYS, *MONTHS, *YEARS Time - *HOURS, *MINUTES, *SECONDS Timestamp - *DAYS, *MONTHS, *YEARS, *HOURS, *MINUTES, *SECONDS, *MSECONDS Syntax: %SUBDT(value : unit { : digits { : decpos} }) Value and Unit are the mandatory arguments.  Digits and Decimal positions are optional and can only be used with *SECONDS for Timestamp. We can either pass the full form for the unit or use the short form. Below i