HP 3000 Manuals

Establishing and Using Standards [ HP RPG/XL Programmer's Guide ] MPE/iX 5.0 Documentation


HP RPG/XL Programmer's Guide

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

    You can use the $COPY/$INCLUDE statements to get field definitions
    from a source library (see "Using Source Libraries" in Chapter 6).
    For RPG programs running under MPE V, fields that are not used in a
    program increase the size of the data space at both compile-time and
    run-time.

Standardizing the Use of Indicators 

Use this indicator:   For: 

01-09                 Input Specification records

10                    Input Specification flush indicator

11-19                 Input Specification fields

20-59                 General-purpose Calculation Specification
                      operations

60-69                 CHAIN or READ resulting indicators

70-79                 External subroutines.

80-89                 Exception output

90-98                 Work (reusable) indicators

99                    First-time indicator

Standardizing File Names 

Use this prefix     For this type of file: 
(or suffix): 

B                   Batch

C                   Catalog

D                   Data

I                   Input

J                   Job

K                   KSAM key

N                   Notes

P                   Executable program

R                   RAF

S                   Source programs or sorted output

T                   Temporary

W                   Work

Standardizing MPE Group Names 

Use this Group name:  For: 

DATA                  MPE, KSAM, TurboIMAGE files; operator logon group

DOC                   User documentation

FORMS                 VPLUS and SIGEDITOR forms

JOB                   Job streams

PROGRAM               Executable programs

PUB                   UDCs, user notes, temporary and scratch files

SOURCE                Source programs, schemas and program documentation



MPE/iX 5.0 Documentation