Free Form RPG Examples
Free Form RPG Examples
The free-form coding style has been available for RPG IV since IBM released V5R1 in the spring of 2001. Since that time, Linoma has used the free-form syntax extensively for in-house development. Based on positive feedback from our developers and well-known experts in the RPG community, we are highly recommending the RPG free-form syntax to our customers. We believe that the free-form syntax is a big improvement to the RPG language and has many productivity advantages. Developers are finally no longer bound by the fixed columns of traditional RPG calculations. Now you can simply enter your RPG logic in a natural left-to-right fashion, similar to the coding style in other modern languages (i.e. Java and Visual Basic). While the free-form syntax only is allowed in the area where C specifications are normally entered, it is definitely a huge step in the right direction. To give you a better understanding of why we are recommending the free-form RPG style, we have compiled a list of benefits we believe it offers over traditional fixed-format syntax: 1. Nested logic can be indented 2. Source code can be entered faster 3. More room to enter long expressions 4. Right-hand comments can immediately follow the logic 5. Free-form will cohabitate with fixed format specs 6. Growing number of source examples only in free-form 7. IBM is focusing its resources on free-form RPG 8. Easier to learn for newcomers 9. Enhances your career These benefits are detailed in the following pages. If you elect to use the free-form style, any existing RPG IV development processes (ie change control) should remain unaffected since the source member type and program behavior will not change. IBMs RPG compiler is intelligent enough to determine the difference between free-form and fixed-format specifications, so you can continue to compile your RPG IV programs as you always have. We believe there is only two reasons why you may not want to code in the free-form style. The first reason is if you have to deploy your programs to an OS/400 release lower than V5R1 since free-form RPG is only supported in V5R1 and higher. The second reason is if you depend on a field cross reference tool that does not recognize the free-form syntax yet (check with your vendor). Otherwise you will be well served by exploring this much-improved coding style. Once youre convinced that the free-form RPG style is right for your organization, we recommend using our RPG Toolbox product to convert your existing RPG logic into this new style. The Toolbox can be downloaded at www.linomasoftware.com. Besides bringing your source code up-to-date with the latest style and methods available, Linomas RPG Toolbox will also help you easily learn the free-form syntax by simply reviewing your source code before and after the conversion. With Linomas RPG Toolbox, you can additionally use our new SEU line commands and source code snippets to easily create, maintain and indent free-form RPG logic.
Page 1 Linoma Software 11811 I Street Omaha, NE 68137 402-334-7513 www.linomasoftware.com sales@linomasoftware.com
C = C 1
The above logic is hard to follow, even though its nested only 3 levels deep. Unfortunately its columnbound nature does not make it easy to trace the logic. You may be tempted to print this example out and use a pencil to draw lines between the IF, ELSE and ENDIF statements for a better understanding. What if this same example was coded in the free-form RPG style: If Test = 3; Work = A + B; If Work = 1; A = A + 1; Else; If Work = 2; B = B + 1; EndIf; EndIf; C = C 1; Else; Return; EndIf;
As you should see from the above free-form example, the power of indenting source makes the free-form logic easier to understand than its fixed-format equivalent. An RPG program will typically have a good deal of nested logic within it. By using the power of indenting nested logic within free-form RPG, your productivity will be greatly enhanced when analyzing and maintaining applications.
Page 2 Linoma Software 11811 I Street Omaha, NE 68137 402-334-7513 www.linomasoftware.com sales@linomasoftware.com
Not considering the keystrokes to enter the expression itself, a single EVAL statement would require 14 keystrokes in fixed-format RPG. What if you keyed the same expression in free-form RPG: 1) 2) 3) 4) Key in an I on a sequence number and press Enter to insert a new line (2 keystrokes) Key in the expression without the proceeding EVAL since it is assumed Key in a semicolon to end the expression (1 keystroke) Press the Enter key (1 keystroke)
Again, not considering the keystrokes to enter the expression itself, it would take only 4 keystrokes to enter the same line in the free-form style. Compared with the fixed-format example, you would save 10 keystrokes when entering this one line of logic. Considering the hundreds of lines of code entered into a typical RPG program, the total keystrokes saved using the free-form style could be significant. Less keystrokes equals more productivity.
Page 3 Linoma Software 11811 I Street Omaha, NE 68137 402-334-7513 www.linomasoftware.com sales@linomasoftware.com
By having more room for long expressions in the free-form coding style, the number of lines needed in your RPG program will be reduced and your expressions will be easier to read and maintain.
Additional problems with traditional right-hand comments are: 1) You have to waste keystrokes in tabbing to the correct column to enter the comment 2) If your display session is set to a width of 80 columns, then you cant see the right-hand comments unless you window to the right 3) The excessive blank space between your logic and the right-hand comment may make it difficult to associate the two together (depending on the quality of your eyesight) These problems can be eliminated when coding in the free-form style since you can immediately follow your logic with comments using the // notation (this is the same notation used in Java). Notice below how much clearer the unabbreviated free-form comment is. Work = A + B; // report total for Nebraska and Iowa
Since comments can be appended to your free-form logic, then more comment text can be entered. Free-form comments will also be visible within 80 column screens (if you dont go too far) and they will be easier to associate with your logic. Instead of inserting your detailed comments above your logic, this same-line approach for free-form comments will keep your source at a reasonable number of lines while making it just as readable and maintainable.
Page 4 Linoma Software 11811 I Street Omaha, NE 68137 402-334-7513 www.linomasoftware.com sales@linomasoftware.com
Page 5 Linoma Software 11811 I Street Omaha, NE 68137 402-334-7513 www.linomasoftware.com sales@linomasoftware.com
Page 6 Linoma Software 11811 I Street Omaha, NE 68137 402-334-7513 www.linomasoftware.com sales@linomasoftware.com