MESSAGE Subfiles



MESSAGE Subfiles

Create the message file and the error messages. Issue the following commands:

MESSAGE SUBFILE:

CRTMSGF MSGF(MYLIB/TSTMSGF)

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


DISPLAY FILE:

Message Subfile:

A          R MSGSFL                       SFL         
A                                                        SFLMSGRCD(24)
A            M@MSGK                      SFLMSGKEY   
A            M@PGMQ                      SFLPGMQ(10) 

Message Subfile Control:

A          R MSGCTL                       SFLCTL(MSGSFL) 
A  41                                         SFLDSP         
A  43                                         SFLDSPCTL      
A  40                                         SFLCLR         
A  42                                         SFLEND         
A                                                        SFLSIZ(0010)   
A                                                        SFLPAG(0001)   


RPG PROGRAM:

Initialize Message Subfile in Extended ‘F’ Specification as below

F                                     SFILE(MSGSFL:W$RRN1)

Subroutine - Clear Message Subfile

C     #CLRMG        BegSr                                             
 *                                                                     
C                   SetOn                                       40              
C                   SetOff                                       414243                 
C                   Write     MsgCtl                                  
C                   SetOff                                       4041 
C                   SetOn                                       4243 
C                   Z-Add     *ZERO         W$RRN1           
 *                                                                    
C                   EndSr                                             

Clear Subroutine:

Setoff           SFLDSP, SFLDSPCTL
Seton  SFLCLR
Setoff SFLEND
Clear   MSGCTL
Setoff SFLDSP, SFLCLR
Seton  SFLDSPCTL,SFLEND

Subroutine - Write Message Subfile

C     #SDMSG        BegSr                                        
 *                                                               
C                   SetOn                                        41
C                   Call             'SSM720C1'                         
C                   Parm                              P$MGID            7  
C                   Parm           'CCCMSGF   '  P$MSGF          10  
C                   Parm                                       P$MGVL           80  
C                   Parm                                       P$MSGK            4  
C                   Parm                                       P$CSTS             1  
 *                                                               
C                   Eval            M@MSGK = P$MSGK                    
C                   Add             1             W$RRN1               
C                   Write           MsgSfl                             
 *                                                               
C                   Eval            P$MGVL = *BLANK                    
 *                                                                
C                   EndSr                                        

CL PROGRAM:

PGM                       PARM(&MSGID &MSGF &MSGVAL &MSGKEY &CMPSTS)  
DCL                        VAR(&MSGID) TYPE(*CHAR) LEN(7)              
DCL                        VAR(&MSGF) TYPE(*CHAR) LEN(10)              
DCL                       VAR(&MSGVAL) TYPE(*CHAR) LEN(80)            
DCL                        VAR(&MSGKEY) TYPE(*CHAR) LEN(4)             
DCL                        VAR(&CMPSTS) TYPE(*CHAR) LEN(1)             
CHGVAR                  VAR(&CMPSTS) VALUE('0')                     
SNDPGMMSG           MSGID(&MSGID) MSGF(*LIBL/&MSGF) +           
                                      MSGDTA(&MSGVAL) KEYVAR(&MSGKEY)           
MONMSG                 MSGID(CPF0000) EXEC(CHGVAR VAR(&CMPSTS) +   
                                      VALUE('1'))                                
EXIT:       ENDPGM                                                 


Using RRN to Chain to Subfiles

We can use RRN to chain to subfile to read all records (this might be particularly useful in EDITABLE subfiles since we may have to read all records)

Rrn = 1
DoWhile Rrn <= SubfileRrn
Rrn     Chain  Subfile
         
(….xxx….)
Update Subfile
Rrn = Rrn + 1
EndDo

(Update the subfile if you want errors to be highlighted)


All records can also be read from a subfile by making SFLNXTCHG = ON and then doing a READC.

No comments