The RPG IV language accepts operation codes on its calculation specifications, but there are actually three distinct syntax structures for calculation specifications. The first structure is the traditional fixed-format syntax that has been a part of RPG since it was first introduced. Fixed format syntax is still supported in RPG IV. The second format is the enhanced or alternate calculation specification that supports what is called the Extended factor 2. The extended factor 2 allows natural expressions to be performed. The first structure is free-format syntax. In Free-format syntax only natural expressions are supported and the entry of the natural expressions is permitted from position 8 through 80 of the source line.
Traditional fixed-format calculations are the most widely used form of statement. This is due primarily to the legacy of RPG and its original fixed-format only coding. Today, RPG IV programmers primarily use a combination of the traditional fixed-format specifications along with the enhanced specifications.
Figure 12.1 contains an example of using the traditional fixed-format calculation specifications.
.....CSRn01Factor1+++++++OpCode(ex)Factor2+++++++Result++++++++Len++DcHiLoEq 0001 C CustNo Chain CustRec 71 0002 C *IN71 ifeq *OFF 0003 C Add 1 Visits 0004 C Update CustRec 0005 C endif
In Figure 12.1, line 1 illustrates the CHAIN operation code, which is the common file access method used in RPG programs. Line 2 uses the deprecated IFEQ operation code to check for a record found condition. If the CHAIN operation is successful, *IN71 will be equal to *OFF, otherwise if the record is not found *IN71 will be equal to *ON. Line 3 increments the field named VISITS which is a field in the customer master file. And finally, on Line 4, the customer master file record CUSTREC is updated; all the fields of the file are rewritten to the database.