TexAS400 Tutorial



RPG Lesson 2 - Converting RPG-III to RPG IV

First RPG IV Program

Hopefully you were able to complete the previous topic and compile a simple RPG III program. Though introduced in 1994, RPG IV is known as the "new" RPG. Because of the huge number of programs written in RPG III, the industry has been slow to adopt RPG IV. It is undoubtedly the way of the future on the AS/400.

RPG III is more accurately known as RPG/400 when it runs on an AS/400. RPG IV supports the "Integrated Language Environment" concept introduced in 1994. This is known as ILE and allows program modules to be bound together at compile time so that an RPG IV program can use routines written in C or any other language. So RPG III is essentially the same as RPG/400 and RPG IV is essentially the same as RPG ILE.

Before you go any further, read this short article:

Converting RPG-III to RPG-ILE

Now you are emotionally ready to convert your program TUTR001 to RPG IV.

First you must create a place for your program statements. Since RPG IV statements are longer than other program source statements, the command to create the source physical file is slightly different. To create the appropriately named place for RPG IV source:

CRTSRCPF FILE(USER999/QRPGLESRC) RCDLEN(112)

Of course, change the USER999 to your user ID. This command creates a source physical file named QRPGLESRC to hold your programs written in RPG IV. The name is the AS/400 standard for RPG IV or RPG ILE source code. It starts with "Q" followed by RPGLE (short for RPG ILE) and then SRC for source.

Now, use the AS400 command to convert the old program to RPG ILE. Key CVTRPGSRC (Convert RPG Source) and hit F4 to see the prompts. Your screen should look like:


                         Convert RPG Source (CVTRPGSRC)                 
                                                                        
 Type choices, press Enter.                                             
                                                                        
 From file  . . . . . . . . . . .                 Name                  
   Library  . . . . . . . . . . .     *LIBL       Name, *LIBL, *CURLIB  
 From member  . . . . . . . . . .                 Name, generic*, *ALL  
 To file  . . . . . . . . . . . .   QRPGLESRC     Name, *NONE, QRPGLESRC
   Library  . . . . . . . . . . .     *LIBL       Name, *LIBL, *CURLIB  
 To member  . . . . . . . . . . .   *FROMMBR      Name, *FROMMBR        
Now fill in the values to indicate that you want to convert the program located in source physical file QRPGSRC in library USER999 that is named TUTR001 and that you want the converted program to be in the same library with the name TUTR002.

                         Convert RPG Source (CVTRPGSRC
                                                      
 Type choices, press Enter.                           
                                                      
 From file  . . . . . . . . . . .   qrpgsrc       Name
   Library  . . . . . . . . . . .     user999     Name
 From member  . . . . . . . . . .   tutr001       Name
 To file  . . . . . . . . . . . .   QRPGLESRC     Name
   Library  . . . . . . . . . . .     user999     Name
 To member  . . . . . . . . . . .   tutr002       Name
Hit ENTER and the command will copy and modify your program.

You can now use PDM to look at the converted program. From the PGM screen key in 3 and hit ENTER. Then fill in the screen to look like:


                       Specify Members to Work With
                                                   
 Type choices, press Enter.                        
                                                   
   File  . . . . . . . . . .   QRPGLESRC    Name, F
                                                   
     Library . . . . . . . .     USER999    *LIBL, 
                                                   
   Member:                                         
     Name  . . . . . . . . .   *ALL         *ALL
     Type  . . . . . . . . .   *ALL         *ALL
Hit enter and you will see your converted program in the list of programs:

                          Work with Members Using PDM       
                                                            
File  . . . . . .   QRPGLESRC                               
  Library . . . .     USER000              Position to  . . 
                                                            
Type options, press Enter.                                  
 2=Edit         3=Copy  4=Delete 5=Display       6=Print    
 8=Display description  9=Save  13=Change text  14=Compile  
                                                            
Opt  Member      Type        Text                           
     TUTR002     RPGLE       Change the first record in CUST
Notice that the "Type" is RPGLE. That tells the AS400 to compile this as RPG ILE instead of RPG III.

Key a 2 next to the program name (TUTR002) and hit ENTER and you will see the source code:


0001.00 FCUST      UF   E             DISK                                     
0002.00 C                   READ      CUST                                   90
0003.00 C                   MOVE      *BLANK        CSADR1                     
0004.00 C                   MOVEL     '456 OAK'     CSADR1                     
0005.00 C                   UPDATE    CSREC                                    
0006.00 C                   MOVE      *ON           *INLR                      
0007.00 C                   RETURN                                             
        ****************** End of data ****************************************
 
You can see that not much has changed. RPG IV has more room for operand names so the UPDAT and RETRN are now spelled out. The other values are spread out a bit more.

You can compile and run this program. You should try that now. Remember that you compile by using option 14. You can then CALL TUTR002 to run it.

Now copy this program and modify it to reflect the new coding style of RPG IV. Copy the program using PDM. Simply key 3 as the option:


                           Work with Members Using PDM                
                                                                      
 File  . . . . . .   QRPGLESRC                                        
   Library . . . .     USER000              Position to  . . . . .    
                                                                      
 Type options, press Enter.                                           
  2=Edit         3=Copy  4=Delete 5=Display       6=Print     7=Rename
  8=Display description  9=Save  13=Change text  14=Compile  15=Create
                                                                      
 Opt  Member      Type        Text                                    
  3   TUTR002     RPGLE       Change the first record in CUST file    



When you hit ENTER, fill in TUTR003 as the new name:

                                 Copy Members                      
                                                                   
 From file . . . . . . . :   QRPGLESRC                             
   From library  . . . . :     USER000                             
                                                                   
 Type the file name and library name to receive the copied members.
                                                                   
   To file . . . . . . . .   QRPGLESRC    Name, F4 for list        
     To library  . . . . .     USER000                             
                                                                   
 To rename copied member, type New Name, press Enter.              
                                                                   
 Member         New Name                                           
 TUTR002        TUTR003                                            
Now hit ENTER again and PDM will copy TUTR002 and name it TUTR003.

Edit TUTR003 by keying 2 as the option.

One way RPG IV is different is that lower case letters are allowed. This doesn't change the functionality of the program but it certainly makes it feel more modern.

You must tell SEU that you want to use lower case letters. When you are editing the TUTR003 program, hit F13 (well actually Shift-F1) and you will get the options for the editor:


                              Change Session Defaults                    
                                                                         
 Type choices, press Enter.                                              
                                                                         
   Amount to roll . . . . . . . . . . .   C            H=Half, F=Full    
                                                       C=Cursor, D=Data  
                                                       1-999             
   Uppercase input only . . . . . . . .   N            Y=Yes, N=No       
   Tabs on  . . . . . . . . . . . . . .   N            Y=Yes, N=No       
   Increment of insert record . . . . .   0.01         0.01-999.99       
   Full screen mode . . . . . . . . . .   N            Y=Yes, N=No       
                                                                         
   Source type  . . . . . . . . . . . .   RPGLE                          
   Syntax checking:                                                      
     When added/modified  . . . . . . .   Y            Y=Yes, N=No       
     From sequence number . . . . . . .                0000.00-9999.99   
     To sequence number . . . . . . . .                0000.00-9999.99   
                                                                         
                                                                         
   Set records to date  . . . . . . . .     /  /       YY/MM/DD 
It is best to change the first value to C. This affects how the screen scrolls when you PAGE-UP and PAGE-DOWN. Make sure the "Uppercase input only" selection is N. This allows you to key lowercase characters.

For now, make 2 changes in the style. First, use lower case characters when you want. Second, use the EVAL operand in place of MOVE and MOVEL. EVAL is short for EVALUATE and like the old BASIC "LET". It is not only more like other modern languages, it has other enhancements that make string handling easy.

Also, since there is more room, change the address to 456 OAK STREET.

The modified program should look like:


0001.00 FCUST      UF   E             disk                                     
0002.00 C                   Read      CUST                                   90
0004.00 C                   Eval      CSADR1 = '456 OAK STREET'                
0005.00 C                   Update    CSREC                                    
0006.00 C                   Eval      *inlr = *on                              
0007.00 C                   Return                                             
Since the EVAL instruction works a little differently from the MOVE, it is no longer necessary to move blanks to CSADR1 before moving 456 OAK STREET to it.

Now compile and run the program. After running TUTR003 you can look at the file with:

RUNQRY QRYFILE(CUST)

and see that the address has changed to 456 OAK STREET.

Boy, in just 10 minutes you have learned a new language!

You should be getting more comfortable with PDM, SEU, compiling programs and looking at spool files. If so, you are on your way to being a productive programmer.

Remember that all examples are in the USER000 library for your viewing pleasure.

 

 

Back to Table of Contents   |   Main Page