IBM Support

Example of a Message Subfile in ILE RPG IV Program

Troubleshooting


Problem

The following demonstrates the use of a message subfile in an ILE RPG IV program.

Resolving The Problem

A "message subfile" is a feature in IBM i systems, specifically within programming languages like RPG, where a dedicated area on a display screen is used to present multiple error messages or informational messages to a user all at once, allowing the program to display a collection of messages instead of just one at a time; essentially acting as a dedicated message display area within a larger application screen.
 
The following demonstrates the use of a message subfile in an ILE RPG IV program:

DDS Source TESTDSPF:
     A                                      CF03(03)
     A                                      HELP
     A          R FMT1
     A                                      OVERLAY
     A                                  2  3'FULL SCREEN'
     A            FLD1          10   B  3  3
      *
     A          R MSGSFL                    SFL
     A                                      SFLMSGRCD(24)
     A            MSGKEY                    SFLMSGKEY
     A            PGMQ                      SFLPGMQ
     A          R MSGSFLC                   SFLCTL(MSGSFL)
     A                                      SFLSIZ(0002)
     A                                      SFLPAG(0001)
     A                                      OVERLAY
     A                                      SFLDSP
     A                                      SFLDSPCTL
     A                                      SFLINZ
     A  98                                  SFLEND
     A            PGMQ                      SFLPGMQ 
Here is the RPGLE program called TESTRPGLE1:
**FREE
Dcl-F testdspf   WORKSTN;
Dcl-S DTA             Char(62);
Dcl-S MSGID           Char(7);
Dcl-S MSGF            Char(10);
Dcl-S MSGDTA          Char(62);
Dcl-S MSGOPT          Char(1);
// Prototype for TESTCL
Dcl-Pr Pgm_TESTCL ExtPgm('TESTCL');
   MSGID           Char(7);
   MSGF            Char(10);
   MSGDTA          Char(62);
   MSGOPT          Char(1);
End-Pr;
//
DTA = 'THIS IS A TEST MSG  ';
// SEND MSG0001 FROM MESSAGE FILE CPF9898 TO PROGRAM MESSAGE QUEUE
MSGID = 'CPF9898';
%Subst(MSGF:1:7) = 'QCPFMSG';
MSGDTA = DTA;
MSGOPT = 'I';
SEND();
// SETON SFLEND INDICATOR FOR MESSAGE SUBFILE
*IN98 = '1';
// WRITE MESSAGE SUBFILE
Write MSGSFLC;
// WRITE/READ REGULAR SCREEN FORMAT
Exfmt FMT1;
// CLEAR THE PROGRAM MESSAGE QUEUE
MSGOPT = 'C';
SEND();
//
// WRITE MESSAGE SUBFILE
Write MSGSFLC;
// WRITE/READ REGULAR SCREEN FORMAT
Exfmt FMT1;
*INLR = '1';
//***************************************************************
BegSr *INZSR;
   // MOVE THE PROGRAM NAME TO THE PROGRAM MESSAGE QUEUE FIELD
   %Subst(PGMQ:1:10) = 'TESTRPGLE1';
EndSr;
//***************************************************************
// THIS SUBROUTINE CALLS A CL PROGRAM THAT SENDS THE MESSAGE
// TO THE PROGRAM MESSAGE QUEUE.
//***************************************************************
Dcl-Proc SEND;
   Pgm_TESTCL(MSGID : MSGF : MSGDTA : MSGOPT);
End-Proc SEND;       
Here is the CL program called TESTCL:
         PGM        PARM(&MSGID &MSGF &MSGDTA &MSGOPT)
         DCL        VAR(&MSGID) TYPE(*CHAR) LEN(7)
         DCL        VAR(&MSGF) TYPE(*CHAR) LEN(10)
         DCL        VAR(&MSGOPT) TYPE(*CHAR) LEN(1)
         DCL        VAR(&MSGDTA) TYPE(*CHAR) LEN(62)

         IF         COND(&MSGOPT *EQ 'I') THEN(SNDPGMMSG MSGID(&MSGID) MSGF(&MSGF) +
                      MSGDTA(&MSGDTA) TOPGMQ(*SAME (TESTRPGLE1 *NONE *NONE)))
         IF         COND(&MSGOPT *EQ 'C') THEN(RMVMSG PGMQ(*PRV (*)) CLEAR(*ALL))
         ENDPGM   
Compile the ILE RPG IV program using CRTBNGRPG DFTACTGRP(*NO)
NOTE: The CL is using SNDPGMMSG. The message is sent to the message queue of the call stack entry 
that is immediately previous to the one identified by the second element of this parameter.
However, if the message queue immediately previous to the one identified by the second element is 
for an Integrated Language Environment (ILE) program entry procedure (PEP), the message is sent to the message queue that precedes the 
PEP message queue in the stack. So, if you want it to go to TESTRPGLE1, you will have to specify
TOPGMQ(*SAME (TESTRPGLE1 *NONE *NONE))
  
Call from command line: 
call testrpgle1
image-20241123112654-1


                                                                  

[{"Type":"MASTER","Line of Business":{"code":"LOB68","label":"Power HW"},"Business Unit":{"code":"BU070","label":"IBM Infrastructure"},"Product":{"code":"SWG60","label":"IBM i"},"ARM Category":[{"code":"a8m3p0000006x8GAAQ","label":"CL"},{"code":"a8m0z0000000CHtAAM","label":"Programming ILE Languages"}],"ARM Case Number":"","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"All Versions"}]

Historical Number

7695510

Document Information

Modified date:
23 November 2024

UID

nas8N1010286