Archive for June 2015

AS400 (RPG ILE/RPG4) : MSGF to PF

Wednesday, June 24, 2015 · Posted in

If you have a Message File that contains thousands of records, and needs to find a message you want it's going to take a long time. In this post is the steps to able to extract and query the MSGF like a PF.

1. Create a Spoolfile of the MSGF with DSPMSGD.
2. Create physical file to store the spoolfile. The physical file only have 1 field, a long string field.
3. Copy spoolfile to physical file.
4. Query with WRKQRY to scan trough the file.


Detail steps :-
1. Create a Spoolfile of the MSGF with DSPMSGD.

                      Display Message Description (DSPMSGD)                     
                                                                                
 Type choices, press Enter.                                                     
                                                                                
 Range of message identifiers:                                                  
   Lower value  . . . . . . . . . > *FIRST        Name, *ALL, *FIRST            
   Upper value  . . . . . . . . . > *LAST         Name, *ONLY, *LAST            
 Message file . . . . . . . . . . > MBAMSG        Name                          
   Library  . . . . . . . . . . .     *LIBL       Name, *LIBL, *CURLIB...       
 Detail . . . . . . . . . . . . . > *BASIC        *BASIC, *FULL                 
 Format message text  . . . . . .   *YES          *YES, *NO                     
 Output . . . . . . . . . . . . . > *PRINT        *, *PRINT                     
                                                                                

                                                                         Bottom 
 F3=Exit   F4=Prompt   F5=Refresh   F12=Cancel   F13=How to use this display    
 F24=More keys                                                                  


2. Create physical file to store the spoolfile. The physical file only have 1 field, a long string field.
First Create PF.
                     Create Source Physical File (CRTSRCPF)                     
                                                                                
 Type choices, press Enter.                                                     
                                                                                
 File . . . . . . . . . . . . . . > MBAMSG        Name                          
   Library  . . . . . . . . . . .     *CURLIB     Name, *CURLIB                 
 Record length  . . . . . . . . . > 132           Number                        
 Member, if desired . . . . . . .   *NONE         Name, *NONE, *FILE            
 Text 'description' . . . . . . . > 'Copy of MBAMSG (*MSGF)'                  
                                                                                

                                                                         Bottom 
 F3=Exit   F4=Prompt   F5=Refresh   F10=Additional parameters   F12=Cancel      
 F13=How to use this display        F24=More keys                               
                                                                                

Source of the PF as below.
Columns . . . :    1 121                        Edit                              MYCP20HB/WORKSPACE
 SEU==>                                                                                                                      MBAMSG
        *************** Beginning of data *********************************************************  
0002.00      A          R RMBAMSG                                                                                                  
0003.00       **                                                                                                                   
0003.01      A            FIELD       3000A                                                                                        
        ****************** End of data ************************************************************  

Save and compile the PF
                          Create Physical File (CRTPF)                          
                                                                                
 Type choices, press Enter.                                                     
                                                                                
 Member size:                                                                   
   Initial number of records  . . > 1000000       1-2147483646                  
   Increment number of records  .   1000          Number                        
   Maximum increments . . . . . .   3             Number                        
 Allocate storage . . . . . . . .   *NO           *NO, *YES                     
 Contiguous storage . . . . . . .   *NO           *NO, *YES                     
 Preferred storage unit . . . . .   *ANY          1-255, *ANY, *SSD             
 Records to force a write . . . .   *NONE         Number, *NONE                 
 Maximum file wait time . . . . .   30            Seconds, *IMMED, *CLS         
 Maximum record wait time . . . .   60            Seconds, *NOMAX, *IMMED       
 Share open data path . . . . . .   *NO           *NO, *YES                     
 Max % deleted records allowed  .   *NONE         1-100, *NONE                  
 Reuse deleted records  . . . . .   *NO           *YES, *NO                     
 Sort sequence  . . . . . . . . .   *SRC          Name, *SRC, *JOB...           
   Library  . . . . . . . . . . .                 Name, *LIBL, *CURLIB          
 Language ID  . . . . . . . . . .   *JOB          Character value, *JOB         
                                                                        More... 
 F3=Exit   F4=Prompt   F5=Refresh   F12=Cancel   F13=How to use this display    
 F24=More keys                                                                  


3. Copy spoolfile to physical file.
                           Copy Spooled File (CPYSPLF)                          
                                                                                
 Type choices, press Enter.                                                     
                                                                                
 Spooled file . . . . . . . . . . > QPMSGD        Name                          
 To data base file  . . . . . . . > MBAMSG        Name, *TOSTMF                 
   Library  . . . . . . . . . . . >   MYCP20HB    Name, *LIBL, *CURLIB          
 Job name . . . . . . . . . . . .   *             Name, *                       
   User . . . . . . . . . . . . .                 Name                          
   Number . . . . . . . . . . . .                 000000-999999                 
 Spooled file number  . . . . . . > *LAST         1-999999, *ONLY, *LAST, *ANY  
 Job system name  . . . . . . . .   *ONLY         Name, *ONLY, *CURRENT, *ANY   
 Spooled file created:                                                          
   Creation date  . . . . . . . .   *ONLY         Date, *ONLY, *LAST            
   Creation time  . . . . . . . .                 Time, *ONLY, *LAST            
 To member  . . . . . . . . . . .   *FIRST        Name, *FIRST                  
 Replace or add records . . . . .   *REPLACE      *REPLACE, *ADD                
 Control character  . . . . . . .   *NONE         *NONE, *FCFC, *PRTCTL...      
                                                                                
                                                                                
                                                                        More... 
 F3=Exit   F4=Prompt   F5=Refresh   F12=Cancel   F13=How to use this display    
 F24=More keys                                                                                                                                                 


4. Query with WRKQRY to scan trough the file.

5. Done.

I personally have made a simple utility program which extract this MSGF into a PF (3 column : Message ID, Severity, and Message). This have save me a lot of time and avoid redundant error message being created whenever I couldn't find the error message I needed.

Hope this helps.

In case you are wondering about the code snippet, I used the hilite.me.

Powered by Blogger.