Using an Error Message Subfile with a Window Format

Article ID: 15280

Q: We've recently adopted the use of an error message subfile as the standard error reporting technique for interactive RPG programs. The error message subfile works fine when I use a standard (full-screen) record format. However, I've been unsuccessful in my attempts to use an error message subfile with a window. Do you have a technique that will work?

A: You're not the first, nor will you be the last, to experience confusion when it comes to windows and error message subfiles. The secret to using an error message subfile with a window record format involves window definition formats and window reference formats.

A window definition format describes the window attributes such as its position on the workstation, its size (number of columns and rows), and border properties. These represent the most basic window attributes and allow you to define a simple window format. A more complex window would contain more information.

A window reference format doesn't describe these attributes. Instead, it references the window definition format to obtain the attributes. Perhaps an example will make this clearer. Consider the following display file used as a pop-up window used to look up customer types.

      *  ==============================================================
      *  = Sample display file with message subfile in a window       =
      *  ==============================================================

     A                                      INDARA

      *  --------------------------------------------------------------
      *  -  Window definition format with function key legend         -
      *  --------------------------------------------------------------

     A          R WINDOW1                   WINDOW(3 8 18 54 *NOMSGLIN)
     A                                      OVERLAY
     A                                      WDWTITLE((*TEXT +
     A                                      'Customer Types') +
     A                                      (*COLOR WHT))
     A                                 17  1'F12=Cancel'
     A                                      COLOR(BLU)

      *  --------------------------------------------------------------
      *  -  Subfile record format                                     -
      *  --------------------------------------------------------------

     A          R RCDSFL                    SFL
     A  61                                  SFLNXTCHG
     A            SELECTFLD      1   B  5  4
     A            CUSTTYPE      10   O  5 11
     A            TYPEDESC      30   O  5 19

      *  --------------------------------------------------------------
      *  -  Subfile control record format                             -
      *  --------------------------------------------------------------

     A          R RCDCTL                    CA12(12)
     A                                      SFLCTL(RCDSFL)
     A                                      WINDOW(WINDOW1)
     A                                      OVERLAY
     A  31                                  SFLDSP
     A  31                                  SFLDSPCTL
     A  32                                  SFLCLR
     A                                      SFLSIZ(12)
     A                                      SFLPAG(11)
     A  99                                  SFLEND(*MORE)
     A                                  2  2'Select'
     A                                      COLOR(WHT)
     A                                  2 11'Type'
     A                                      COLOR(WHT)
     A                                  2 19'Description'
     A                                      COLOR(WHT)
     A            SFLRCDNBR      4S 0H      SFLRCDNBR(CURSOR)

      *  --------------------------------------------------------------
      *  -  Error message subfile control record format               -
      *  --------------------------------------------------------------

     A          R MSGSFL                    SFL
     A                                      SFLMSGRCD(18)
     A            MSGKEY                    SFLMSGKEY
     A            PGMQ                      SFLPGMQ

      *  --------------------------------------------------------------
      *  -  Error message subfile control                             -
      *  --------------------------------------------------------------

     A          R MSGCTL                    SFLCTL(MSGSFL)
     A                                      WINDOW(WINDOW1)
     A                                      OVERLAY
     A                                      SFLDSP
     A                                      SFLDSPCTL
     A                                      SFLINZ
     A  99                                  SFLEND
     A                                      SFLSIZ(0002)
     A                                      SFLPAG(0001)
     A            PGMQ                      SFLPGMQ(10)

      *  --------------------------------------------------------------
      *  -  Dummy record format to prevent background erasure         -
      *  --------------------------------------------------------------

     A          R DUMMY                     ASSUME
     A                                  1  2' '

The first record format, Window1, is a record definition format. Notice that it contains the aforementioned window attributes (specified with keyword Window) along with argument *NoMsgLin to prevent display management from reserving a line for messages and the function key legend from appearing when using the format.

The next format, RcdSfl, is the subfile that contains the customer type and its description along with an input-capable field used to select an entry.

RcdCtl is the format used as the subfile control format for subfile RcdSfl, and it appears next. Notice that this format contains keyword Window. However, rather than specify the window attributes with this keyword, I've specified that display management should reference format Window1 (making RcdCtl a window reference format) when displaying the subfile control format. The subfile consequently displays in a window with the attributes specified in format Window1.

The message subfile, MsgSfl, appears next. There's nothing special about this subfile format, but notice that keyword SflMsgRcd specifies that the messages should appear on line 18.

Next appears MsgCtl, the subfile control format for message subfile MsgSfl. Notice that this format is also a window reference format and that it too names format Window1 as the window to reference for attributes. This causes the message to appear on line 18 (specified by keyword SflMsgRcd in format MsgSfl) of the window.

In RPG, you use the following sequence to display the subfile with the error messages in the window:

  • Load the subfile.
  • Set any indicator conditions such as indicator 31 to display subfile RcdSfl and subfile control format RcdCtl.
  • Write format Window1. (This must be done before writing any window reference formats.)
  • Write MsgCtl to display any messages in the program message queue.
  • ExFmt RcdCtl to actually display and read subfile RcdSfl and control format RcdCtl.

ProVIP Sponsors

ProVIP Sponsors