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.

AS400 (RPG ILE/RPG4) : Character to Numeric

Wednesday, September 25, 2013 · Posted in

To convert character to numeric it is possible by using %DEC. It convert character for example '100000.00' to 100000.00.

But when your character having commas, the %DEC cant proceed the conversion. So you need to change the commas(,) in to blanks. For example : '100,000.00' into '100 000.00'. You can achieve this using %XLATE.

Both the %DEC and %XLATE can be combined an achieve the character to numeric conversion. Example code as below :

D Character S 10 INZ('100,000.00)
D Numeric S 9S2
*
C EVAL Numeric = %DEC(%XLATE(',':' ':Character):10:2)
C Character DSPLY
*
C MOVE '1' *INLR C RETURN

Bash Shell Script (Unix Shell)

Monday, July 15, 2013

Bash on ubuntu 12.04 (installed using Wubi, could never be easier)

Floating point arithmetic

  • Using piping ( | )
  • basic=$(echo "scale=2; 250.00" | bc)
    commission=$(echo "scale=2; 50.00" | bc)
    pay=$(echo "scale=2; ${basic}+${commission}" | bc)

    echo "Your pay for this week (RM) ${pay}"

    Output :
    Your pay for this week (RM) 300.00

    Info and discussion about using bc (base conversion)


Read user input (Read)

  • Method 1
  • echo "Enter name : "
    read name

    Output :
    Enter name :
    Tarzan

  • Method 2
  • echo -n "Enter name: "
    read name

    Output :
    Enter name : Tarzan

  • Method 3
  • read -p "Enter name: " name

    Output :
    Enter name : Tarzan



If Statement



Case Statement

read -p "Enter number(1-4): " code

case "$code" in '1')
echo "One. "
;;
'2')
echo "Two. "
;;
'3')
echo "Three. "
;;
'4') echo "Four. "
;;
esac
echo "Code entered ${code}"



Loop Statement

More on loops : Cyberciti,

Other reference links : Free OS, codewiki

Download sample bash file (coming up soon)




Starting with bash

Download Starting with bash.txt
  1. Start up Ubuntu (Im using Ubuntu 12.04)

  2. Open Terminal

  3. Go to Desktop (or any other directory)
  4. Type "cd Desktop" (without quotes) in terminal and press Enter.

  5. Create the bash file
  6. Type "gedit filename.sh" (without quotes) in terminal and press Enter. Where filename is the name of the bash file name.

    gedit is a text editor comes with Ubuntu (and other unix OS). Other editors like vim also used, but normally vim doesn't comes pre-installed to the system. Which may require manual installation and super user rights (Sudo).

    Type in the program, save the file and close the gedit (text editor). The text editor must be close to allow the terminal to ready to process next command.

  7. Make the bash file executable
  8. Type in "sudo chmod +x filename.sh" (without quotes) in terminal and press Enter. Or "chmod 4755 filename.sh" (without quotes) and press Enter.

  9. Run or execute bash program
  10. Type in "./filename.sh" (without quotes) in terminal and press Enter.




Hope this helps.

QRG7064 (RPG3 or RPG/400)

Monday, July 8, 2013 · Posted in

I encounter an error (QRG7064) when compiling an RPG3 program.

The error occurred when any of the file in the F-specs(file specifications) is not used in the C-specs(code specifications).

I dont quite like this feature on RPG3, as it forces me to do an operation/dummy operation in order to compile the file. Maybe there's a better way to overcome the problem, will update once I find out.


Powered by Blogger.