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

5- 1
Chapter 5 Processing Data in an RPG Program
This chapter discusses ways to manipulate data once it is read into a
program. The RPG language features that make it easier to handle data in
a program are tables, arrays, and data structures. You can also use
subroutines to manipulate data in a program. Internal and external
subroutines are discussed in this chapter.
This chapter does not address all of the ways to work with data
internally in a program. For information on indicators, numeric editing,
changing the hexadecimal value of characters and other features, see the
HP RPG Reference Manual
.
Using Tables and Arrays
Tables and arrays are the most convenient and efficient way to organize
elements of related data so that you can reference them individually or
as a group. Each element in a table or array has the same length, the
same data type (numeric or alphanumeric) and, if numeric, the same number
of decimal positions. Tables and arrays are defined using the File
Extension Specification.
You commonly use tables to keep rates, constants or data of any kind that
remains the same during program execution. For instance, you can enter a
table for state tax rates.
Normally, you use arrays to save data accumulated during program
execution. However, arrays and tables can often be used interchangeably.
Differences Between Tables and Arrays
Tables are loaded either during program compilation or before a program
is executed. Tables can only be processed one element at a time; you
cannot perform operations on an entire table in one operation. Table
names start with TAB. When you use a table name, RPG selects the table
element found during the last lookup (LOKUP) operation.
Arrays are loaded either during compilation, or before or during program
execution. You can process arrays one element at a time. You can also
process all elements of an array in one operation by using the array
name.
Kinds of Tables and Arrays
There are three kinds of tables and arrays: compile-time,
preexecution-time and execution-time. They are grouped into these
categories according to when they are loaded or created by a program.
The kind of table or array that you use depends how you're using it in
your program:
This kind of Is used when:
table or array:
Compile-Time The table or array elements change infrequently, if at
all.
Preexecution-Time The table or array elements change frequently.
Execution-Time The array elements change frequently or they are created
by the program.
Compile-time, preexecution-time and execution-time tables and arrays are
discussed in the next three sections.