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.

Unknown Friday 31 May 2013
Checking Record Locks While Updating PF in Subfiles





Checking Record Locks While Updating PF in Subfiles





RPGLE

Check for %STATUS after doing a CHAIN(E) to file.

If %STATUS = 01218, then record is locked.

RPG

Check for status code 01218 in the file information data structure (INFDS).

Declare INFDS to “F” specification in “Keywords” column – INFDS FILEDS

Now, declare FILEDS as below

I FIELDS                 DS
I                                     *STATUS       STAT

Now, in program, after CHAIN, check for STAT = 01218




Unknown Thursday 30 May 2013
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.

Unknown
Subfile Validations




SUBFILE VALIDATIONS

Invalid Options in Subfile

If ProgramRRN > 0

READC SUBFILE
DOW NOT%EOF(Display File)
         
                    Eval ErrorMessage = ‘Error’
                    Reverse Image, Position Cursor = ‘ON’

                    SFLNXTCHG = ON
                    Update SUBFILE
                    SFLNXTCHG = OFF

READC SUBFILE
ENDDO

EndIf

Valid Options in Subfile

READC SUBFILE
DOW NOT%EOF(Display File)
         
*****
*****

READC SUBFILE
ENDDO

(Do not make SFLNXTCHG = ON and update subfile here, since we are going to process subfile options)

 

F4 Prompt In Subfiles

 

Use keyword RTNCSRLOC to use F4 as below:

A                                      RTNCSRLOC(&@RCD1 &@FLD1 &@POS1)

A            @RCD1         10A  H
A            @FLD1         10A  H
A            @POS1          4S 0H
Use field “FLD1” to check for Field where F4 is taken.



 

Unknown