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
Files.
The
Input.
The information read and
Fields, Arrays, Data Structures, and Named Constants.
The names of the
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
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
Procedures. The portions of code that are called to perform a specific task and often to return a value to the caller.
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
|
Feature |
Limit |
|---|---|
|
AN/OR (
|
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
|
4,096
|
|
Files (
|
No limit (actually 32767) |
|
File key length |
2,000 positions |
|
Lines per page (
|
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 |
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
|
Name |
Naming Convention |
|---|---|
|
All Names |
The first character must be A to Z (or a to z), @, #, or $. Subsequent
|
|
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. |