
Only use a GOTO statement to branch to a point within the same subroutine. Never use a GOTO statement to branch from a subroutine to a point in the mainline code.
Use CAS operations in preference to nested IF/ELSE operations; they are easier to follow:

Avoid nesting structured programming operations too deeply—for instance more than three or four levels of nesting in a given subroutine level. If more are needed, use another subroutine.
Keep the amount of code within structured programming constructs as short as possible. RPG III comment lines may be indented to follow the logical programming constructs:

Programs should be as structured as possible. A program is not ‘structured’ just because it only uses structured operation codes. A structured program is one that is modularized in an efficient way, and built up out of the structured programming constructs—SEQUENCE, CONDITION (CASE) or ITERATION, and structured combinations thereof. The constructs might even be implemented logically (for instance with GOTOs and TAGs used in a structured manner) rather than with specific HLL structured operation codes.
Avoid testing compound negative conditions when possible because they are harder to understand.

F3 (IBM i) should result in the user exiting completely from a program. Where a program calls several levels of subprogram, each subprogram may need to test for the exit condition.
Calling Program Exit Conditioning Logic:

Called Program Exit Conditioning Logic:

The RPG III statements used to code the reading of a group of records from a file should be highly standardized.
A standard loop should be used because:
There are two ways of coding such a loop:


Which standard loop is preferable? The second method is probably slightly more efficient because it requires only one READ statement (each READ statement requires a large number of MI instructions to execute). However, the first loop is ‘less tricky’, and therefore, preferable. Here are two examples of using the loop:
Standard Loop Reading a Database File:

Note: If appropriate, the SETLL and initial READE may be combined as a CHAIN.
Standard Loop Reading a Sub file:

Use the RPG III EXFMT operation code in preference to a separate WRITE and READ statements for display files because it is more efficient.
| Copyright © 2011 CA. All rights reserved. | Tell Technical Publications how we can improve this information |