Getting familiar with message subfiles -- Code

Getting familiar with message subfiles -- Code

The following programs demonstrate message subfiles. FYI, Two common mistakes most people make when starting to use message subfiles are: Not specifying the overlay keyword on your display file format and not clearing the message subfile before you attempt to send a message to it for the first time. This example demonstrates two types of error messages: one with straight error text and another where a variable is inserted into the body of the error message. To use this example, you will have to create a message file, two error messages, two CL programs (one to send a message and the other to clear messages and then your example RPG and Display file program.

Step 1: Create the message file and the error messages. Issue the following commands:
CRTMSGF MSGF(MYLIB/TSTMSGF)

ADDMSGD MSGID(ERR0001) MSGF(MYLIB/TSTMSGF) MSG('Example of error message')

ADDMSGD MSGID(ERR0002) MSGF(MYLIB/TSTMSGF) MSG('Entry &1 not valid. Example of substitution variable in error message') FMT((*CHAR 1))

Step 2: Create CL programs to send error messages
PROGRAM ITIC04 - Send error message - called from your RPG program

 
              PGM        PARM(&MSGF &MSGID &MSGDTA)                      
              DCL        VAR(&MSGF) TYPE(*CHAR) LEN(10)                  
              DCL        VAR(&MSGID) TYPE(*CHAR) LEN(7)                  
              DCL        VAR(&MSGDTA) TYPE(*CHAR) LEN(132)               
                                                                         
 /*  CHECK FOR MESSAGE FILE EXISTENCE, IF ERROR, SEND PGM MESSAGE    */  
              CHKOBJ     OBJ(&MSGF) OBJTYPE(*MSGF)                       
              MONMSG     MSGID(CPF0000) EXEC(DO)                         
                SNDPGMMSG  MSG('Program error message file ' *CAT &MSGF  +
                           *TCAT ' not found.')                          
                GOTO       CMDLBL(ENDPGM)                                
              ENDDO                                                      
                                                                         
 /*  SEND ERROR MESSAGE */                                               
              SNDPGMMSG  MSGID(&MSGID) MSGF(&MSGF) MSGDTA(&MSGDTA) +     
                           TOPGMQ(*PRV) MSGTYPE(*DIAG)                   
              MONMSG     MSGID(CPF0000)                                  
                                                                         
  ENDPGM:     ENDPGM  

Step 3: Create CL programs to clear error messages
PROGRAM ITIC05 - Clear error message - called from your RPG program

 
 PGM                                
 RMVMSG     PGMQ(*PRV) CLEAR(*ALL)  
 ENDPGM   

Step 4: Create sample DDS file
DISPLAY FILE NAME MSGDDS

 
A          R DISPLAY                                               
A                                      CA03(03 'EXIT')             
A                                      OVERLAY                     
A                                  3  2'Enter A or any other character' 
A            FLD001         1A  B  3 33                            
A                                 23  2'F3=Exit'                   
A          R MSGSFL                    SFL                         
A                                      SFLMSGRCD(24)               
A            SCMSGK                    SFLMSGKEY                   
A            SCPGMQ                    SFLPGMQ                     
A          R SFLMSGC                   SFLCTL(MSGSFL)              
A                                      SFLDSP                      
A                                      SFLDSPCTL                   
A                                      SFLINZ                      
A N03                                  SFLEND                      
A                                      SFLSIZ(0002)                
A                                      SFLPAG(0001)  

Step 5: Create sample RPG program
PROGRAM NAME MSGRPG

   
FMSGDSP  CF  E                    WORKSTN                          
C*                                                                 
C*  INITIALIZE MESSAGE SUBFILE                                     
C                     EXSR CLRMSG                                  
C*                                                                 
C                     EXSR DSPPNL                                  
C*                                                                 
C                     MOVE *ON       *INLR                         
C***************************************************************** 
C*  DSPPNL - DISPLAY PROMPT SCREEN                                 
C***************************************************************** 
C           DSPPNL    BEGSR                                        
C*                                                                 
C*  DO WHILE EXIT SCREEN IS NOT REQUESTED                          
C           *IN03     DOUEQ*ON                                     
C*                                                                 
C*  WRITE ERROR MESSAGES SUBFILE                                   
C                     WRITESFLMSGC                                 
C*                                                                 
C                     EXFMTDISPLAY
C*                                                                
C           *IN03     IFEQ *ON                                    
C                     LEAVE                                       
C                     END                                         
C*                                                                
C*  CLEAR ERROR MESSAGES                                          
C                     EXSR CLRMSG                                 
C*                                                                
C                     EXSR EDIT                                   
C*                                                                
C* IF NO ERRORS ON SCREEN CONTINUE PROCESSING                     
C           *IN99     IFEQ *OFF                                   
C                     END                                         
C*                                                                
C                     END                                         
C*                                                                
C                     ENDSR                                       
C*                                                                
C*****************************************************************
C*  EDIT - PERFORM SCREEN EDITING                                 
C*****************************************************************
C*                                                                
C           EDIT      BEGSR                                       
C*                                                                
C* STRAIGHT ERROR MESSAGE                                         
C           FLD001    IFEQ 'A'                                    
C                     MOVEL'ERR0001' #MSGID                       
C                     EXSR SNDMSG                                 
C                     END                                         
C*                                                                
C* ERROR MESSAGE WITH SUBSTITUTION VARIABLE ADDED TO MESSAGE      
C           FLD001    IFNE 'A'                                    
C                     MOVEL'ERR0002' #MSGID                       
C                     MOVELFLD001    #MSGDT    P                  
C                     EXSR SNDMSG                                 
C                     END                                         
C*                                                                
C                     ENDSR                                       
C*                                                                
C*****************************************************************
C*  CLRMSG - CLEAR MESSAGE SUBFILE                                
C*****************************************************************
C*                                                                 
C           CLRMSG    BEGSR                                        
C*                                                                 
C                     MOVEL'*'       SCPGMQ    P                   
C                     CALL 'ITIC05'                                
C*                                                                 
C* SET OFF GENERAL ERROR INDICATOR                                 
C                     MOVE *OFF      *IN,99                        
C*                                                                 
C                     ENDSR                                        
C*                                                                 
C***************************************************************** 
C*  SNDMSG - SEND MESSAGE TO MESSAGE SUBFILE                       
C***************************************************************** 
C*                                                                 
C           SNDMSG    BEGSR                                        
C*                                                                 
C*  PARMS: #MSGF  - MESSAGE FILE (10)                              
C*         #MSGID - MESSAGE ID (7)                                 
C*         #MSGDT - MESSAGE DATA (132)                             
C*                                                                 
C                     CALL 'ITIC04'                         
C                     PARM 'TSTMSGF' #MSGF  10              
C                     PARM           #MSGID  7              
C                     PARM           #MSGDT132              
C*                                                          
C* CLEAR MESSAGE VARIABLE & SETON GENERAL ERROR INDICATOR   
C                     MOVEL*BLANKS   #MSGDT                 
C                     MOVEL*ON       *IN99                  
C*                                                          
C                     ENDSR  
C*

Step 6: Call program MSGRPG

Dig deeper on iSeries programming commands

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchEnterpriseLinux

SearchDataCenter

Close