Flylib.com

Books Software

 
 
 

RPG COMPONENTS


RPG COMPONENTS

Every RPG program is made up of components. Each component is defined through one or more RPG specification. A description of some of the components follows .

  • Files. The names of files that will be accessed by the RPG program.

  • Input. The information read and processed by the program.

  • Fields, Arrays, Data Structures, and Named Constants. The names of the variables —referred to as "fields" in the RPG language—and constants, that are used to store, compare, and process information within the program.

  • Labels. The names assigned with BEGSR, ENDSR, KLIST, PLIST, EXCEPT, and TAG identifiers. They are used to label subroutines, access data files, declare parameter and key lists, control output, and act as the target of a GOTO , respectively.

  • Calculations. The computations (e.g., math, field manipulation, decisions, and array searching) performed on the information within the program.

  • Output. The results of the program. The processed data is written to a printer, written or rewritten (updated) to a data file, or presented to a user through a workstation device.

  • Procedures. The portions of code that are called to perform a specific task and often to return a value to the caller.



RPG LIMITATIONS

Like all high-level languages, RPG has a set of restrictions. RPG IV has fewer limitations than previous versions of RPG. The features listed in Table 1.4 document any significant RPG language restrictions, along with several previous limitations that have been removed in RPG IV. These are marked "No limit."

Table 1.4: RPG IV Limitations

Feature

Limit

AN/OR ( positions 7 to 8 of Calc spec)

No limit

Array elements

32,767 per array/table

Arrays and tables

No limit

Compile-time array or table length

100 positions

Data structure length

65,535 positions for named data structures 9,999,999 for unnamed data structures

Data structure occurrences

32,767 per data structure

Edit word length

Literal: 24 positions Named Const: 115 positions

Field length

Char: 65,535 positions; Numeric: (31, 30)

Field name

4,096 characters

Files ( open files per program)

No limit (actually 32767)

File key length

2,000 positions

Lines per page ( program-described )

Minimum of 2; maximum of 255

Lines per page (externally described)

Minimum of 1; maximum of 255

Matched fields (combined length)

256 positions

Named constants

Char: 1024 positions; Numeric: (31, 30)

Nested IF, DOxxx, SELECT, FOR groups

100 levels

Parameters

255 program to program; 399 to procedures

Primary files

1 per program

Printer files

No limit (8 standard overflow indicators available)

Program Status Data Structure

1 per program

Record address files (ADDROUT)

1 per program

Record format length

99,999 positions (system limit is)

Spacing and skipping printed output

0 to 255 lines

Subroutines

32,767 per program



NAMING CONVENTIONS

As with other computer languages, RPG has standard naming conventions. Table 1.5 lists the criteria for each named component of an RPG program. Unless otherwise noted, all names must be unique. For example, the name of a data structure cannot be the same as that of an array.

Table 1.5: Naming Conventions

Name

Naming Convention

All Names

The first character must be A to Z (or a to z), @, #, or $. Subsequent characters can be A to Z (or a to z), @, #, $, 0 to 9, or the underscore (_) character. Letter case is not significant. If @, #, or $ is used as the first character of a name, at least one other character must be specified. No embedded blanks or periods are allowed. Array names can be suffixed with an array index. All names are global to all areas of the RPG IV program unless modules or subprocedures are used. When modules or subprocedures are used, names can be declared local to a module.

File

A file name cannot be the same as a (record) format name.

Format

A (record) format name must be 1 to 10 characters in length. Format names cannot be the same as that of a file name.

Field

A field name must be 1 to 4096 characters in length. Field names may be the same as a data structure or data structure subfield name, but not both.

Structure

A structure name, referred to as a data structure in RPG, can be the same as that of an input file's field name. It can be manipulated the same as any other variable, and can be specified as a parameter of a CALLx operation.

Qualified Name

A qualified name is a data structure subfield name qualified to (i.e., attached to) its parent data structure name. Qualified names are created by specifying the data structure name followed by a period, followed by the data structure subfield name. For example: MyDS.CustName Qualified names are created when the QUALIFIED or LIKEDS keywords are used to declare a data structure.

Array Index

An array index name must represent a numeric field that contains zero decimal places or it can be an expression. The array index can be a field of type packed, signed, integer, or binary. Although binary and integer are the most efficient, packed decimal is most commonly used. Array indexes are identified using parentheses. For example, MyArray(x) indicates that array index x is used with the array name MyArray.

Label

A label is the target of a branch or GOTO operation. A label is defined with either the TAG or ENDSR operation.

Named Constant

A named constant is used to assign a name to a literal value. This name can be used repeatedly throughout the program.