29
Fri, Nov
0 New Articles

An Introduction to ILE RPG: Part 3

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Brief: Our third installment on ILE RPG covers changes to I-specs, C-specs and O-specs. All three have been modified to accommodate the longer field name, field length and decimal position entries. We'll focus on C-specs where free- form expressions can greatly simplify the code for both logical and arithmetic comparisons and calculations. You'll see that the basic components of RPG/400 have been retained but significant new function has been added to the language with these changes.

Last month we continued our review of the new Integrated Language Environment RPG (ILE RPG) which will be announced as part of V3R1M0.

We saw the elimination of Extension specifications (E-specs) with array and table definition moved to the new Definition specifications (D-specs). Named constant and data structure definition has been moved from Input specifications (I-specs) to D-specs. Our programs should be more maintainable with the ability to consolidate all data definition into a single location-D-specs. Substantial productivity gains should result from the introduction of the OVERLAY and PREFIX keywords and the ability to use length notation in data structures.

What's left? We'll see minor changes to I-specs and Output specifications (O- specs). However, radical changes abound in Calculation specifications (C- specs). For example, ILE RPG C-specs can use symbolic operators that may not be familiar to RPG programmers. Combine this with lowercase variable names and free-form expressions-C-specs don't look the same.

Let's take a quick look at I-specs and then move on to explore the tremendous productivity gains offered by the changes in C-specs. We'll finish with a review of O-specs.

Input Specifications (I-specs)

Several major changes have been made to I-specs in ILE RPG. Most obvious are the changes required to accommodate 10-character file and field names, longer field lengths, and two positions for the number of decimal digits. While adjusting to these changes will be almost intuitive, other changes will require some education.

The ability to specify date and time format and separator characters has been added to I-specs for program described files.

As we discussed last month, data structures, data structure subfields and named constants are no longer defined in I-specs. Their definition has been moved to the new D-specs.

Externally Described Files

Most native RPG/400 programs do not require I-specs for files. The same is true of ILE RPG programs. The only time you need to code I-specs for externally described files is when you want to assign indicators or rename fields. When you start using ILE RPG, hopefully your files will all be externally described so you do not have to use program described files.

Contrary to conventional wisdom, our shop does use control level indicators for reports since there is no easier way to produce subtotals and we have found negligible performance differences between input primary and full procedural files. Without getting into a debate about whether or not control level indicators should be used, let's refer to 1 for a sample of assigning these indicators in RPG/400 and ILE RPG.

Contrary to conventional wisdom, our shop does use control level indicators for reports since there is no easier way to produce subtotals and we have found negligible performance differences between input primary and full procedural files. Without getting into a debate about whether or not control level indicators should be used, let's refer to Figure 1 for a sample of assigning these indicators in RPG/400 and ILE RPG.

In this simple example, we have assigned record identifying indicator 01 to record format ARPCM1 in our ARPCM customer master file. In addition, control level indicator L6 has been assigned to the customer number field ARCUST.

Except for positioning and the ability to specify 10-character record format and field names, the RPG/400 and ILE RPG I-spec record and field layouts are identical for externally described files.

If you are using I-specs to rename all of the fields in a record format, you can accomplish this globally by specifying the new PREFIX keyword on the F- specs. (See Part 1 of this series if you need a refresher.) Also, field names with lengths that exceed six characters no longer need to be renamed since ILE RPG supports 10-character field names.

Program Described Files

2 shows that the only changes to the I-spec record layout for a program described file are support for a 10-character file name and 99,999-byte record length. In the example, we have assigned record identifying indicator 01 to records with the character A in position 1 and record identifying indicator 02 to records with the character C in position 1.

Figure 2 shows that the only changes to the I-spec record layout for a program described file are support for a 10-character file name and 99,999-byte record length. In the example, we have assigned record identifying indicator 01 to records with the character A in position 1 and record identifying indicator 02 to records with the character C in position 1.

The I-spec field layout shows similar changes to accommodate 10-character field names, from and to positions up to 99,999, and decimal positions up to 30. The 14 positions for the field name will make it easier to specify array indices.

In the RPG/400 example, the field TRDATE is defined as a character field with a length of eight. In the ILE RPG example, we have modified the definition of this field by adding *MDY in positions 31 to 34 to denote an external date/time type of MMDDYY, a slash (/) in position 35 to indicate the date/time separator character, and a D in position 36 to define the data type of date. These additions define the field TRDATE as a date field in MMDDYY format with a slash (/) as the separator character.

ILE RPG now directly supports date (D), time (T) and timestamp (Z) data types. *DMY, *YMD, *JUL, *HMS and several other formats can be specified. We'll go into more detail on the use of these data types next month.

Figures 3 and 4 summarize changes to I-specs for program described files.

Calculation Specifications (C-specs)

C-specs have undergone major modification in ILE RPG. Many changes were required to accommodate relaxed limits in ILE RPG, while other changes provide substantial usability improvements.

5 shows factor 1, factor 2 and the result field have all been increased to 14 characters to handle 10-character symbolic names with extra space for an array index when needed. Other changes are also apparent.

Figure 5 shows factor 1, factor 2 and the result field have all been increased to 14 characters to handle 10-character symbolic names with extra space for an array index when needed. Other changes are also apparent.

The operation code has been increased to six characters, but the implementation is not consistent. REDPE has been changed to READPE but, for some reason, the DIV operation has not been changed to DIVIDE. Somewhat confusing, isn't it? The old five-character operation codes will no longer work in C-specs. 6 summarizes changes to operation codes.

The operation code has been increased to six characters, but the implementation is not consistent. REDPE has been changed to READPE but, for some reason, the DIV operation has not been changed to DIVIDE. Somewhat confusing, isn't it? The old five-character operation codes will no longer work in C-specs. Figure 6 summarizes changes to operation codes.

The operation extender has been moved to follow the operation code and must be enclosed in parentheses (). Operation extenders include H for half adjust, N for read with no lock and P for pad with blanks.

As in I-specs, decimal positions up to 30 are now supported in C-specs. In our ILE RPG sample (5), we have modified the number of decimal positions for the field XRATIO from 9 to 15 and its length from 19 to 23.

As in I-specs, decimal positions up to 30 are now supported in C-specs. In our ILE RPG sample (Figure 5), we have modified the number of decimal positions for the field XRATIO from 9 to 15 and its length from 19 to 23.

Only a single conditioning indicator is permitted. If you have old code which uses more than one conditioning indicator, the RPG/400-to-ILE RPG source- conversion utility will automatically put each indicator on a separate statement.

Having to put resulting indicators such as the end-of-file indicator in positions 75 to 76 is going to cause some problems for those of us with 80- character terminals. The only way to key something beyond position 71 in SEU on an 80-character terminal is to prompt the statement or window to the right. And remember, comments are in positions 81 to 100 for all ILE RPG specifications. Perhaps now is the time to start thinking about budgeting to replace those 80- column clunkers with 132-column terminals or PCs.

Free-form Arithmetic Expressions

ILE RPG supports free-form expressions in C-specs. Instead of having to code a complex formula a single step at a time, the new EVAL operation code can be used with an extended factor 2. Standard arithmetic operators supported include:

 
 +       Addition 
 -       Subtraction 
 *       Multiplication 
 /       Division 
 **      Exponentiation 

Factor 1 must be blank. The half adjust operation code extender (H) may be used with EVAL but N and P are not valid. While conditioning indicators may be used, as with all C-specs they should be avoided if possible. If you're using control level indicators in your I-specs, use a single, control level indicator in your C-specs to control execution of a subroutine. Because RPG is not an indicator- optimized compiler, indicators should be referenced as little as possible.

Blanks can be freely interspersed between operands and operators to make the code easier to understand. In some cases, blanks are required-for example to differentiate between exponentiation and multiplication of a reserved word beginning with an asterisk. Consider the following expression:

A**TIME

This expression is interpreted as the field A raised to the power of the field TIME. If multiplication by the new reserved word, *TIME, is intended, the expression should be coded in one of these two ways:

A* *TIME

A * *TIME

We'll address date and time data types including the *TIME reserved word next month. We'll look at some simple samples of EVAL in 7. The first sample replaces a single calculation. The field oecost is computed as the value of the field oeqty times the field impric. The half adjust operation extender has been enclosed in parentheses and moved next to the operation code.

We'll address date and time data types including the *TIME reserved word next month. We'll look at some simple samples of EVAL in Figure 7. The first sample replaces a single calculation. The field oecost is computed as the value of the field oeqty times the field impric. The half adjust operation extender has been enclosed in parentheses and moved next to the operation code.

The second sample is a two-part calculation. The field oewght is computed as the value of the field oeqty times the field imwght, with the field pkwght added to the result. Based upon the rules of precedence, the use of parentheses is optional.

Remember high school algebra? It finally has some value. The order of precedence for arithmetic operations in ILE RPG free-form expressions is the same as it was in high school algebra:

 
 o parentheses 
 o exponentiation 
 o multiplication and division 
 o addition and subtraction 

In the last sample in 7, the field oestax is computed as the value of the field oecost minus the field oedisc, with the field sttax multiplied by the result. The parentheses in this case are required. Without them, the field oedisc would be multiplied by the field sttax and the result would be subtracted from the field oecost, yielding erroneous results.

In the last sample in Figure 7, the field oestax is computed as the value of the field oecost minus the field oedisc, with the field sttax multiplied by the result. The parentheses in this case are required. Without them, the field oedisc would be multiplied by the field sttax and the result would be subtracted from the field oecost, yielding erroneous results.

To make your code more readable, feel free to use parentheses even if they are not required.

Some complex formulae can require several lines of code. Or sometimes it's convenient to break up your code into several lines to make them more readable. 8 shows such an example.

Some complex formulae can require several lines of code. Or sometimes it's convenient to break up your code into several lines to make them more readable. Figure 8 shows such an example.

We want to compute the total of first-, second- and third-shift pay, remembering to add in shift premium before multiplying rate times hours. We can replace seven RPG/400 calculations with a single ILE RPG expression. Nice job, IBM!

If the field tmpay is not large enough to hold the result, a numeric overflow exception occurs and the status code in the program status data structure is set to 103. This produces a run-time halt. If numeric overflow occurs in ILE RPG in arithmetic operations such as Z-ADD which do not involve expressions, truncation without a halt will occur just as it does in RPG/400. Specifying TRUNCNBR(*NO) when compiling an ILE RPG program will force a run-time halt any time numeric overflow occurs.

Continued Literals

The ILE RPG example in 9 contains two expressions with continued literals. The first uses a plus sign (+) continuation character which means the literal is continued with the first non-blank character in positions 36 to 80 of the next line. The second example uses a hyphen (-) continuation character which means the literal is continued in position 36 of the next line even if it contains a blank. The fields des1 and des2 will both have the same value.

The ILE RPG example in Figure 9 contains two expressions with continued literals. The first uses a plus sign (+) continuation character which means the literal is continued with the first non-blank character in positions 36 to 80 of the next line. The second example uses a hyphen (-) continuation character which means the literal is continued in position 36 of the next line even if it contains a blank. The fields des1 and des2 will both have the same value.

An expression can be continued over multiple lines. Continued lines must be blank in positions 7 to 35. No special continuation character is required unless a literal is being continued.

Comment lines with an asterisk (*) in position 7 can be interspersed between continued lines. Blank lines can also be used.

Free-form Logical Expressions

In addition to the EVAL operation, ILE RPG also supports free-form expressions for the new DOU, DOW, IF and WHEN operations. These operations are functionally equivalent to the DOUxx, DOWxx, IFxx and WHENxx operations except instead of comparing factor 1 to factor 2, the extended factor 2 entry is used for the comparison. Valid operators include:

 
 =       Equal to 
 >=      Greater than or equal to 
 >       Greater than 
 <=      Less than or equal to 
 <       Less than 
 <>      Not equal 

The RPG/400 example in 10 shows a DOW loop with two tests. First, Y must be less than 50. Second, the specified element (indexed by X) of the array IN must not be blank. As long as both of these tests are true, the loop continues. If either is not true, the loop ends. The ILE RPG example combines both of these tests into a single DOW statement with the tests separated by an AND. Probably the most difficult part of this example is remembering to use <> in ILE RPG instead of the *NE you would have used in CL.

The RPG/400 example in Figure 10 shows a DOW loop with two tests. First, Y must be less than 50. Second, the specified element (indexed by X) of the array IN must not be blank. As long as both of these tests are true, the loop continues. If either is not true, the loop ends. The ILE RPG example combines both of these tests into a single DOW statement with the tests separated by an AND. Probably the most difficult part of this example is remembering to use <> in ILE RPG instead of the *NE you would have used in CL.

Complex expressions can be constructed using AND and OR. How will you know the difference between the field OR and the operation OR? You might not know at first, but the compiler will. While variables named AND and OR are valid in ILE RPG, they should be avoided at all costs to prevent misunderstanding.

Control level and conditioning indicators may be used. Factor 1 must be blank. No operation extenders are permitted.

The RPG/400 sample in 11 is a little more complex than our previous examples. It utilizes multiple WHxx operations within a SELEC group. The first WHEQ operation tests for TRCODE equal to A while the second tests for TRCODE equal to C or D. An appropriate action description padded with blanks is moved to the field $ACTN.

The RPG/400 sample in Figure 11 is a little more complex than our previous examples. It utilizes multiple WHxx operations within a SELEC group. The first WHEQ operation tests for TRCODE equal to A while the second tests for TRCODE equal to C or D. An appropriate action description padded with blanks is moved to the field $ACTN.

The ILE RPG example again combines multiple tests into a single statement using the WHEN operation with the tests separated by an OR. Thank you, IBM!

We have also changed the MOVEL operation to an EVAL in this example. If only the half adjust operation extender is valid with EVAL, what happened to the pad with blanks? When the EVAL operation is used to set the value of a character field, it functions the same as a MOVEL(P). The result is left-adjusted and padded with blanks on the right. If the expression is longer than the variable, the value is truncated with no error given.

Sometimes intermediate results must be calculated to perform a test. When doing a credit check on an order, you would add the order amount to the customer's Accounts Receivable balance and compare the sum to the customer's credit limit. This requires two separate operations in RPG/400. ILE RPG requires only a single statement as illustrated in 12.

Sometimes intermediate results must be calculated to perform a test. When doing a credit check on an order, you would add the order amount to the customer's Accounts Receivable balance and compare the sum to the customer's credit limit. This requires two separate operations in RPG/400. ILE RPG requires only a single statement as illustrated in Figure 12.

12 shows the IF operation supports arithmetic expressions as part of the extended factor 2 in ILE RPG. As we've shown, so do the DOU, DOW and WHEN operations. The field oecost is first added to the field cmbal and the sum compared to the field cmcred. Comparison operators such as greater than (>) have a lower order of precedence than arithmetic operators; consequently, the arithmetic is done first, followed by the comparison. If AND or OR is used, these logical operations are performed last because they are lowest in order of precedence.

Figure 12 shows the IF operation supports arithmetic expressions as part of the extended factor 2 in ILE RPG. As we've shown, so do the DOU, DOW and WHEN operations. The field oecost is first added to the field cmbal and the sum compared to the field cmcred. Comparison operators such as greater than (>) have a lower order of precedence than arithmetic operators; consequently, the arithmetic is done first, followed by the comparison. If AND or OR is used, these logical operations are performed last because they are lowest in order of precedence.

13 summarizes changes to C-specs.

Figure 13 summarizes changes to C-specs.

Output Specifications (O-specs)

Many of the changes to O-specs are very similar to what we saw in I-specs. 14 shows the expanded space to support ending positions up to 99,999 and names for 10-character files, record formats, fields and except labels. Unlike C-specs, all three conditioning indicators have been retained in O-specs.

Many of the changes to O-specs are very similar to what we saw in I-specs. Figure 14 shows the expanded space to support ending positions up to 99,999 and names for 10-character files, record formats, fields and except labels. Unlike C-specs, all three conditioning indicators have been retained in O-specs.

In the ILE RPG example, we have also modified the definition of our field TRDATE by adding a D in position 52 and *MDY/ in positions 53 to 57 to denote an external date data type of month/day/year with a slash (/) separator character.

15 shows some of the changes in O-specs for coding program described printer files. RPG/400 only supports zero to three space before or space after lines. Our RPG/400 example therefore requires two exception output statements to space five lines before printing-one statement to space three lines and another to space two lines.

Figure 15 shows some of the changes in O-specs for coding program described printer files. RPG/400 only supports zero to three space before or space after lines. Our RPG/400 example therefore requires two exception output statements to space five lines before printing-one statement to space three lines and another to space two lines.

ILE RPG requires only a single line since values from 0 to 255 are supported for space before and space after lines. In addition, skip before and skip after line numbers can now be from 0 to 255.

Constants or edit words can be continued on multiple lines in positions 53 to 80. The line being continued must end with a plus sign (+) or hyphen (-). A plus sign (+) means continuation starts with the first nonblank character in or past position 53 of the next line. A hyphen (-) means continuation starts in position 53 of the next line even if it is blank. The continuation line must contain an O in position 6 and be blank in positions 7 to 52. Blank separator lines and comment lines are permitted between continued lines.

16 summarizes changes to O-specs.

Figure 16 summarizes changes to O-specs.

What's Next?

We've seen many of the changes to the I-specs, C-specs and O-specs were required to accommodate the change from 6-character to 10-character symbolic names and the support of increased file record lengths, field lengths and number of decimal positions. The new EVAL, DOU, DOW, IF and WHEN operations and the introduction of expressions to C-specs provide even more usability improvements to ILE RPG.

In our next article, we introduce built-in functions (BIF) and tackle date/time data types including the new date/time arithmetic operation codes.

Charlie Massoglia, president of Massoglia Technical Consulting, Inc. in Okemos, Michigan, has authored a number of midrange books. His cowboy hat is his trademark for his frequent speaking tours throughout the United States, Canada, Europe and Australia. Charlie can be reached at 517-676-9700.


An Introduction to ILE RPG: Part 3

Figure 1 I-spec Externally Described File

 
 
   *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 
  FFilenameIPEAF....RlenLKlAIOvKlocEDevice+......Kexit++Entry+A....U1........ 
  FARPCM   IP  E                    DISK 
 
  IRcdname+....In............................................................ 
  IARPCM1      01 
 
  I..............Ext-field+......................Field+L1M1..PlMnZr.......... 
  I                                              ARCUSTL6 
 
 
  *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 ...+ 
 FFilename++IPEASFRlen+LKlen+AIDevice+.File_continuation++++++++++++++++++++Comme 
 FARPCM     IP   E             DISK 
 
 IRcdname+++....Ri..........................................................Comme 
 IARPCM1        01 
 
 I..............Ext-field+..................Field+++++++++L1M1..PlMnZr......Comme 
 I                                          ARCUST        L6 

An Introduction to ILE RPG: Part 3

Figure 2 I-spec Program Described File

 
 
   *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 
  IFilenameSqNORiPos1NCCPos2NCCPos3NCC....................................... 
  IARTRAN  NS  01   1 CA 
  I       OR   02   1 CC 
 
  I....................................PFromTo++DFldnmeL1M1FrPlMnZr......... 
  I                                        1   1 TRCODE 
  I                                        2   80TRCUST 
  I                                        9  16 TRDATE 
  I                                    P  17  212TRAMT 
 
 
  *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 ...+ 
 IFilename++SqNORiPos1+NCCPos2+NCCPos3+NCC..................................Comme 
 IARTRAN    NS  01    1 CA 
 I         OR   02    1 CC 
 
 I........................Fmt+SPFrom+To+++DcField+++++++++L1M1FrPlMnZr......Comme 
 I                                  1    1  TRCODE 
 I                                  2    8 0TRCUST 
 I                        *MDY/D    9   16  TRDATE 
 I                             P   17   21 2TRAMT 

An Introduction to ILE RPG: Part 3

Figure 3 Changes to I-spec Record Layout for Program Descri

 
 
     RPG/400   ||   ILE RPG   ||   SEU Format     
     Position  ||   Position  ||   Abbreviation   ||   Explanat 
     ----------+-------------+------------------+------------------------------- 
       7-14    ||     7-16    ||   Filename       ||   File n 
      15-16    ||    17-18    ||   Sq             ||   Sequence check 
         17    ||       19    ||   N              ||   Num 
         18    ||       20    ||   O              ||   Opt 
      19-20    ||    21-22    ||   Ri             ||   Record identifying indica 
      21-24    ||    23-27    ||   Pos1           ||   Posit 
      28-31    ||    31-35    ||   Pos2           
      35-38    ||    39-43    ||   Pos3           
         25    ||       28    ||   N              ||    
         32    ||       36    ||                  
         39    ||       44    ||                  
         26    ||       29    ||   C              ||   C 
         33    ||       37    ||                  
         40    ||       45    ||                  
         27    ||       30    ||   C              ||   Charac 
         34    ||       38    ||                  
         41    ||       46    ||                  
      75-80    ||   81-100    ||                  ||   Comme 

An Introduction to ILE RPG: Part 3

Figure 4 Changes to I-spec Field Layout for Program Describ

 
 
    RPG/400   ||   ILE RPG   ||   SEU Format     
    Position  ||   Position  ||   Abbreviation   ||   Explanat 
    ----------+-------------+------------------+------------------------------- 
       New    ||    31-34    ||   Fmt            ||  External date/time for 
       New    ||       35    ||   S              ||  Date/Time separator charac 
        43    ||       36    ||   P              ||  External data for 
     44-47    ||    37-41    ||   From           ||  From posit 
     48-51    ||    42-46    ||   To             ||  To posit 
        52    ||    47-48    ||   D              ||  Decimal positi 
     53-58    ||    49-62    ||   Field          ||  Field n 
     59-60    ||    63-64    ||   L1             ||  Control level indica 
     61-62    ||    65-66    ||   M1             ||  Matching record indica 
     63-64    ||    67-68    ||   Fr             ||  Field record relation indica 
     65-66    ||    69-70    ||   Pl             ||  Positive field indica 
     67-68    ||    71-72    ||   Mn             ||  Negative field indica 
     69-70    ||    73-74    ||   Zr             ||  Zero field indica 
     75-80    ||   81-100    ||                  ||  Comme 

An Introduction to ILE RPG: Part 3

Figure 5 C-spec Operation Extender and Decimal Positions

 
 
   *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 
  CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments+++++++...... 
  C           K#DS      REDPEARPDS                    50 
  C           *IN50     IFNE *ON 
  C           OECOST    DIV  DSAMT     XRATIO 199H 
  C                     ENDIF 
 
 
  *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 ...+ 
 CL0N01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq....Comme 
 C     K#DS          READPE    ARPDS                                  50 
 C     *IN50         IFNE      *ON 
 C     OECOST        DIV(H)    DSAMT         XRATIO           2315 
 C                   ENDIF 

An Introduction to ILE RPG: Part 3

Figure 6 Renamed and Expanded Operation Codes

 
 
      RPG/400       ||       ILE RP 
      --------------+-------------- 
      BITOF         ||       BITOF 
      CHEKR         ||       CHECK 
      COMIT         ||       COMMI 
      DEFN          ||       DEFIN 
      DELET         ||       DELET 
      EXCPT         ||       EXCEP 
      LOKUP         ||       LOOKU 
      OCUR          ||       OCCU 
      REDPE         ||       READP 
      RETRN         ||       RETUR 
      SELEC         ||       SELEC 
      SETOF         ||       SETOF 
      UNLCK         ||       UNLOC 
      UPDAT         ||       UPDAT 
      WHxx          ||       WHENx 

An Introduction to ILE RPG: Part 3

Figure 7 C-spec Free-Form Expressions

 
 
   *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 
  CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments+++++++...... 
  C           OEQTY     MULT IMPRIC    OECOST    H      Get extended cost 
   * 
  C           OEQTY     MULT IMWGHT    OEWGHT           Get Item Weight 
  C                     ADD  PKWGHT    OEWGHT           Add Package Weight 
   * 
  C           OECOST    SUB  OEDISC    XXCOST           Get Discounted Cost 
  C           XXCOST    MULT STTAX     OESTAX           Get Sales Tax 
 
 
 
  *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 ...+ 
  ... 9 ...+... 0 
 CL0N01Factor1+++++++Opcode(E)+Extended-factor2+++++++++++++++++++++++++++++Comme 
 nts++++++++++++ 
 C                   eval(h)   oecost = oeqty * impric                      Get 
 extended cost 
 
 C                   eval      oewght = (oeqty * imwght) + pkwght           Get 
 line item weight 
 C                   eval      oewght = oeqty * imwght + pkwght             Same 
 as prev ine 
 
 C                   eval      oestax = (oecost - oedisc) * sttax           Get 
 tax on disc cost 
 C                   eval      oestax = oecost - oedisc * sttax 
 Incorrect result 

An Introduction to ILE RPG: Part 3

Figure 8 C-spec Continuation

 
 
   *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 
  CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments+++++++...... 
  C           TMSFT1    MULT EMRATE    TMPAY            Shift 1 pay 
   * 
  C           EMRATE    ADD  EMPRE2    XRATE            Shift2 rate + premium 
  C           TMSFT2    MULT XRATE     XWAGET           Shift2 wages 
  C                     ADD  XWAGET    TMPAY            Shift1+2 pay 
   * 
  C           EMRATE    ADD  EMPRE3    XRATE            Shift3 rate + premium 
  C           TMSFT3    MULT XRATE     XWAGET           Shift3 wages 
  C                     ADD  XWAGET    TMPAY            Shift1+2+3 pay 
 
 
 
  *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 .8 ....+....9 
 CL0N01Factor1+++++++Opcode(E)+Extended-factor2++++++++++++++++++++++Comments++++ 
 C                   eval      tmpay = tmsft1 * emrate               Shift1 wages 
 C                                     + (emrate + empre2) * tmsft2  Shift2 wages 
  *                                                             including premium 
 C                                     + (emrate + empre3) * tmsft3  Shift3 wages 
  *                                                             including premium 

An Introduction to ILE RPG: Part 3

Figure 9 Literals Continuation

 
 
  *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 ...+ 
 CL0N01Factor1+++++++Opcode(E)+Extended-factor2+++++++++++++++++++++++++++++Comme 
 C                   eval      des1 = 'Notice the difference between plus + 
 C                                     sign and hyphen continuation for + 
 C                                     literals.' 
 C                   eval      des2 = 'Notice the difference between plus - 
 C                             sign and hyphen continuation for literals.' 

An Introduction to ILE RPG: Part 3

Figure 10 C-spec DOW and WHEN

 
 
   *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 
  CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments+++++++...... 
  C           Y         DOWLT50 
  C           IN,X      ANDNE*BLANKS 
  C                     MOVE IN,X      OUT,Y 
  C                     ADD  1         X 
  C                     ADD  1         Y 
  C                     ENDDO 
 
 
  *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 ...+ 
 CL0N01Factor1+++++++Opcode(E)+Extended-factor2+++++++++++++++++++++++++++++Comme 
 C                   dow       y < 50 AND in(x) <> ' ' 
 CL0N01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq....Comme 
 C                   move      in(x)         out(x) 
 C                   add       1             x 
 C                   add       1             y 
 C                   enddo 

An Introduction to ILE RPG: Part 3

Figure 11 Complex Logical Expressions

 
 
   *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 
  CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments+++++++...... 
  C                     SELEC 
  C           TRCODE    WHEQ 'A'                        Add transaction 
  C                     MOVEL'Add'     $ACTN     P 
  C           TRCODE    WHEQ 'C'                        Change transaction 
  C           TRCODE    OREQ 'D'                        Delete transaction 
  C                     MOVEL'Update'  $ACTN     P 
  C                     OTHER                           Error transaction 
  C                     MOVEL'Error'   $ACTN     P 
  C                     ENDSL 
 
  *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+....6 .. 8 ...+... 9 ...+... 0 
 CL0N01Factor1+++++++Opcde(E)+Extended-factor2+++++++++++++++Comments 
 C                   select 
 C                   when     trcode = 'A'                   Add transaction 
 C                   eval     $actn = 'Add' 
 C                   when     trcode = 'C' OR trcode = 'D'   Change or delete 
 C                   eval     $actn = 'Update'                transaction 
 C                   other 
 C                   eval     $actn = 'Error'                Error transaction 
 C                   endsl 

An Introduction to ILE RPG: Part 3

Figure 12 C-spec IF

 
 
   *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 
  CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments+++++++...... 
  C           OECOST    ADD  CMBAL     XCHECK           Add order cost to AR 
  C           XCHECK    IFGT CMCRED                      balance.  If credit 
  C                     MOVE 'N'       OEOKAY            limited exceeded, 
  C                     ENDIF                             reject order 
 
 
  *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 ...+ 
 ... 9 ...+... 0 
 CL0N01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq....Comme 
 nts++++++++++++ 
 C                   if        oecost + cmbal > cmcred                      If 
 order cost + bal 
 C                   eval      oeokay = 'N' 
 exceeds credit limit 
 C                   endif 
 reject order. 

An Introduction to ILE RPG: Part 3

Figure 13 Changes to C-specs

 
 
     RPG/400   ||  ILE RPG   ||  SEU Format    
     Position  ||  Position  ||  Abbreviation  ||  Explanat 
    ----------+------------+----------------+------------------------------------ 
        7-8    ||     7-8    ||  L0            ||  Control le 
       9-17    ||    9-11    ||  N01N02N03     ||  Conditioning indicat 
               ||            ||                ||   (reduced to a single indicat 
      18-27    ||   12-25    ||  Factor1       ||  Facto 
      28-32    ||   26-35    ||  Opcde         ||  Operation and exten 
      33-42    ||   36-49    ||  Factor2       ||  Facto 
      43-48    ||   50-63    ||  Result        ||  Result fi 
      49-51    ||   64-68    ||  Len           ||  Field len 
         52    ||   69-70    ||  D             ||  Decimal positi 
         53    ||   26-35    ||  H             ||  Operation exten 
               ||            ||                ||     (e.g., half adju 
      54-55    ||   71-72    ||  Hi            ||  High/No record found indica 
      56-57    ||   73-74    ||  Lo            ||  Low/Error indica 
      58-59    ||   75-76    ||  Eq            ||  Equal/End-of-file indica 
               ||   36-79    ||                ||  Extended facto 
      60-74    ||  81-100    ||  Comments      ||  Comme 

An Introduction to ILE RPG: Part 3

Figure 14 O-spec Program Described Disk File

 
 
   *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 
  OName++++DFBASbSaN01N02N03Excnam........................................... 
  OARTRAN  EADD             ADDTRN 
 
  O................N01N02N03Field+YBEnd+PConstant/editword+++++++++.......... 
  O                         TRCODE     1 
  O                         TRCUST     8 
  O                         TRDATE    16 
  O                         TRAMT     21P 
 
 
  *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 ...+ 
 OFilename++DF..N01N02N03Excnam++++B++A++Sb+Sa+.............................Comme 
 OARTRAN    EADD         ADDTRN 
 
 O..............N01N02N03Field+++++++++YB.End++PConstant/editword/DTformat++Comme 
 O                       TRCODE               1 
 O                       TRCUST               8 
 O                       TRDATE              16D*MDY/ 
 O                       TRAMT               21P 

An Introduction to ILE RPG: Part 3

Figure 15 O-spec Program Described Printer File

 
 
   *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 
  OName++++DFBASbSaN01N02N03Excnam........................................... 
  OQSYSPRT E 3              PRTTRN 
  OQSYSPRT E 21             PRTTRN 
 
  O................N01N02N03Field+YBEnd+PConstant/editword+++++++++.......... 
  O                         TRCODE     1 
  O                         TRCUSTZ   10 
  O                         TRDATE    20 
  O                         TRAMT 3   32 
  O                                   57 'This constant continues' 
  O                                   80 'over a number of lines' 
  O                                  105 'requiring multiple lines' 
  O                                  114 'of code.' 
 
 
  *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 ...+ 
 OFilename++DF..N01N02N03Excnam++++B++A++Sb+Sa+.............................Comme 
 OQSYSPRT   E            PRTTRN      5  2 
 
 O..............N01N02N03Field+++++++++YB.End++PConstant/editword/DTformat++Comme 
 O                       TRCODE               1 
 O                       TRCUST        Z     10 
 O                       TRDATE              20 
 O                       TRAMT         3     32 
 O                                          113 'This constant continues + 
 O                                              over a number of lines + 
  * Comment lines are permitted 
  * in between continuation lines. 
 O                                              using the new continua- 
 O                                              tion feature. 

An Introduction to ILE RPG: Part 3

Figure 16 Changes to O-specs

 
 
    RPG/400   ||  ILE RPG   ||  SEU Format    
    Position  ||  Position  ||  Abbreviation  ||  Explanat 
    ----------+------------+----------------+------------------------------------ 
      7-14    ||    7-16    ||  Name          ||  Filename or Record format n 
        15    ||      17    ||  D             ||  Type of line (header,detail, to 
              ||            ||                ||     or exce 
        16    ||      18    ||  F             ||  Fetch overflow or release dev 
              ||            ||                ||     after out 
        17    ||   40-42    ||  B             ||  Space before(0-2 
        18    ||   43-45    ||  A             ||  Space after(0-2 
     19-20    ||   46-48    ||  Sb            ||  Skip bef 
     21-22    ||   49-51    ||  Sa            ||  Skip af 
     23-31    ||   21-29    ||  N01N02N03     ||  Output indicat 
     32-37    ||   30-39    ||  Excnam        ||  EXCPT n 
     32-37    ||   30-43    ||  Field         ||  Field n 
        38    ||      44    ||  Y             ||  Edit c 
        39    ||      45    ||  B             ||  Blank af 
     40-43    ||   47-51    ||  End           ||  Ending posit 
        44    ||      52    ||  P             ||  Field for 
     45-70    ||   53-80    ||  Constant/     ||  Constant or editw 
              ||            ||   editword     
     75-80    ||  81-100    ||                ||  Comme 
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: