HP RPG/XL Programmer's Guide (30318-90001)

9- 1
Chapter 9 Writing More Efficient RPG Programs
This chapter discusses some of the ways you can increase the efficiency
of your RPG programs. More efficient programs execute faster and require
fewer system resources and memory.
Establishing and Using Standards
Standards provide the framework for building efficient RPG programs.
Programming standards decrease development and maintenance time and
improve the legibility of programs. System standards, such as file
naming conventions and account and group standards make it easier to
build and maintain multi-program applications.
The next six sections in this chapter suggest general RPG programming
standards you may want to adopt.
Using Comments
This section contains tips on how to use comments in an RPG program. A
general rule of thumb is that a well-documented program is one-third
comments.
* Enter comments for all Input and Output record types.
* Enter comments for all Calculation Specification GOTO operations.
* Enter notes in columns 60-74 on important Calculation Specifications.
* Maintain a "Date-Modified" comment line at the beginning of each
program. Also develop a scheme to keep track of program
modifications. For example, you can use the Sequence Number Field
(columns 1-5) to document changes. For lines added on 02/28, enter
A0228. For lines that are modified, enter C0228. "Comment out"
deleted lines and enter D0228 on them.
* Develop consistent standards and style.
Using Structured Programming Techniques
Structured programs are easier to develop, test and maintain. They are
also easier to understand.
* Replace repetitive code segments with subroutines (EXSR).
* Stick to sequential logic in the Calculation Specifications. Try to
avoid GOTO operations. Instead, use the combinations: IF-THEN-ELSE,
IF-THEN, DO-WHILE, DO-UNTIL.
Standardizing Field Names
Use field names that are:
* Five characters long
A 5-character name can be prefixed or suffixed. For example, if a
last name field is called LNAME, it can be prefixed by T when used in
an Output Specification for a Terminal file.
* Meaningful
Names that relate to the contents or purpose of a field are easier to
understand and make programs more readable. Also use similar names
for arrays and their associated counters. For example, the counter
for array AMT can be A.
* Used consistently in other programs