Showcase Article - Converting RPGIII to RPG-ILE

IBM introduced RPG-ILE in 1994 concurrent with release V3R1 of the OS/400 operating system. You may have been scared away from trying RPG-ILE after reading articles about some of its sophisticated features. Topics like activation groups, service programs and module binding may have encouraged you to stay with the familiar RPG III. I'll show you how easy it is to convert and compile your existing programs using RPG-ILE. You'll also see some great benefits from simple additions in the language.

The simplest way to start using ILE is to convert an existing RPG III program. First, you will need a place to put the new source code. The traditional name for an RPG III source file is QRPGSRC. Similarly, the traditional name for an RPG-ILE source is QRPGLESRC.

Suppose there is RPG III source for a program XYZ in library PGMTEST. The source is in QRPGSRC. Before you can convert the program to ILE, you must create a new physical source file for it.

Do this with this command: CRTSRCPF FILE(PGMTEST/QRPGLESRC) RCDLEN(112)

It is important to specify the length. RPG-ILE source code uses records of 112 while traditional RPG uses records of 96 characters.

To convert the program, use the convert RPG source command, CVTRPGSRC. It's this simple:

CVTRPGSRC FROMFILE(PGMTEST/QRPGSRC) FROMMBR(XYZ) TOFILE(PGMTEST/QRPGLESRC)

In a few seconds, the AS/400 will create a new member named XYZ in QRPGLESRC. This new member should have RPGLE as its type.

If you've heard about complicated compiling and binding of modules, you will be happy to learn that you compile this source code in a familiar way. Just use option 14 in PDM to compile the source. The AS/400 sees that the type is RPGLE and executes the CRTBNDRPG command which compiles the program as an executable, stand-alone program.

It's that simple. You don't need to worry about activation groups, service programs or binding of modules to compile and run RPG-ILE.

Figure 1 shows some code snippets from an RPG III program. These snippets include examples of some of the changes in syntax that you will see with RPG-ILE. Figure 2 shows the RPG III source code after it has been converted to RPG-ILE.

Differences between Figure 1 and Figure 2

In the file specs, the overflow indicator for the printer is defined using the keyword OFLIND. In the second file spec, the sub-file syntax has changed.

The E-specification has been replaced with the new D-specification. In this case, the array definition has been replaced with the dimension statement, DIM(100).

The data structures in the I-specifications have also been replaced with D specs. The field names in the D-spec can be 16 characters long. Not only that, you can indent fields to logically group fields that belong together.

The DO and IF statements have not been changed noticeably by the conversion program. In a moment, you'll see that the DO and IF statements have gained flexibility and readability in ILE. The reference to the first element of the array now reads, ARA(1).

Since the operation field is larger in RPG-ILE, some operations are spelled completely. The old operations UPDAT, SELEC and RETRN get spelled out as UPDATE, SELECT and RETURN.

You can see how easy it is to begin to use ILE. You may be asking the question, "Why bother?" Certainly, converting to ILE without taking advantage of the flexibility of the new syntax isn't advantageous.

Same Program, Different Syntax

Figure 3 shows the same code snippets rewritten using new ILE syntax. I've also added a standalone field and a reference to a subroutine.

The most obvious difference is the use of upper and lower case characters. Most people keep externally defined fields in all upper case. Temporary variables are most appropriately defined in the D-specs. I defined the variable, AllRecsReadSw as a 1 character switch to indicate when all records have been read. The "S" means this is a stand alone field. Defining variables in the D-spec is considered good style and it allows you to use up to 16 characters for the field name.

I changed the data structure only slightly be indenting the fields that are subordinate to the CCYY field.

The DO and IF statements are much easier to use and read. The Do-While-Equal syntax is replaced with a Do-While statement. The conditional part of the statement is free format and much easier to understand. The condition can use parentheses to remove any questions about the intent of the logic.

To emphasize this, I coded a slightly complicated Do-While loop. It will execute the subroutine, ReadAllCusts as long as the condition is true. The use of the parentheses makes the logical evaluation of this statement unambiguous.

(AllRcdsReadSw = 'n') and
((*in90 = *off) or
(*in91 = *on))

I changed the MOVE statement for the array to an EVAL statement. EVAL is intended to replace Z-ADD, ADD and MOVE statements.

General Notes on Style

As you experiment with ILE you will discover a more flexible language than RPG III. Here are some generally accepted styles of coding you should begin to use.

� Define all variables in the D-specs
� Use long, meaningful names for the variables and subroutines.
� Use upper and lower case letters in variable names.
� Replace Z-ADD, ADD and MOVE with EVAL instructions.
� Use blank lines to improve readability.
� Use the new IF and DO syntax. Include parentheses to clarify logic.
� Use upper and lower case letters for comments.

I have intentionally kept this simple to encourage you to try out RPG-ILE. Once you convert and compile an ILE program you will want to learn more about ILE. Go online to the Midrange Computing company store at www.mc-store.com and choose a book appropriate to your background.


Figure 1 - Here are some RPG III code snippets.


     FQPRINT  O   F     132     OF     PRINTER                            
      * SUBFILE                                                           
     FXXD001  CF  E                    WORKSTN                            
     F                                        R1    KSFILE SFL1           
      * ARRAY                                                             
     E                    AAA       100  5  A            100 ENTRIES OF 5 
      * DATA STRUCTURE                                                    
     I            DS                                                      
     I                                        1   40CCYY                  
     I                                        1   20CC                    
     I                                        3   40YY                    
      * DO AND IF STATEMENT                                               
     C           *IN90     DOWEQ*OFF                                      
     C           YY        IFGT 80                                        
     C           MM        OREQ 12                                        
     C                     ADD  1         CC                              
     C                     ENDIF                                          
     C                     ENDDO                                          
      * REFERENCE 1ST ELEMENT OF ARRAY                                    
     C                     MOVE *BLANKS   ARA,1                           



Figure 2 - This is the result of converting the code snippets to RPG-ILE.

      FQPRINT    O    F  132        PRINTER OFLIND(*INOF)                                          
       * SUBFILE                                                                                   
      FXXD001    CF   E             WORKSTN                                                        
      F                                     SFILE(SFL1:R1)                                         
       * ARRAY                                                                                     
      D AAA             S              5    DIM(100) ASCEND   100 ENTRIES OF 5  
       * DATA STRUCTURE                                                                            
      D                 DS                                                                         
      D  CCYY                   1      4  0                                                        
      D  CC                     1      2  0                                                        
      D  YY                     3      4  0                                                        
       * DO AND IF STATEMENT                                                                       
      C     *IN90         DOWEQ     *OFF                                                           
      C     YY            IFGT      80                                                             
      C     MM            OREQ      12                                                             
      C                   ADD       1             CC                                               
      C                   ENDIF                                                                    
      C                   ENDDO                                                                    
       * REFERENCE 1ST ELEMENT OF ARRAY                                                            
      C                   MOVE      *BLANKS       ARA(1)                                            
 

Figure 3 - Here are the code snippets written in ILE style.

     D                 DS                                                  
     D  CCYY                   1      4  0                                 
     D    CC                   1      2  0                                 
     D    YY                   3      4  0                                 
      * Stand Alone Field                                                  
     D AllRcdsReadSw   S              1                                    
      * Do and If statements                                               
     C                   DoW       *in90 = *off                            
     C                   If        (YY  >  80) or                          
     C                             (MM  =  12)                             
     C                   Eval      CC = CC + 1                             
     C                   EndIf                                             
     C                   EndDo                                             
      * Reference 1st element of array                                     
     C                   Eval      ARA(1) =  *blanks                       
     C                   DoW       (AllRcdsReadSw = 'n') and               
     C                             ((*in90 = *off)       or                
     C                              (*in91 = *on))                         
     C                   ExSr      ReadAllCusts                            
     C                   EndDo 

Back to Showcase Articles��� |��� Back to Main Page���|���Contact Info