Professional Documents
Culture Documents
Migration RPG Language Reference Manual
Migration RPG Language Reference Manual
LANGUAGE REFERENCE
MANUAL
jUNE 2011
——————————
The following are trademarks of Migration Specialties International, Inc:
MSI, Migration RPG, SFG, S/3X Conversion Tools, CVTFILE, CBL
All other trademarks and registered names used in this document are the
property of their respective owners.
ii
Contents
PREFACE xxxiii
iii
Contents
iv
Contents
v
Contents
vi
Contents
vii
Contents
viii
Contents
x
Contents
xi
Contents
xii
Contents
xiii
Contents
xiv
Contents
xv
Contents
xvi
Contents
xvii
Contents
xviii
Contents
xix
Contents
xx
Contents
xxi
Contents
xxii
Contents
INDEX
EXAMPLES
1–1 Example of first cycle output specifications 1–15
1–2 Program using total time features 1–17
1–3 Example of a program using detail time features 1–19
2–1 Example of column numbers 2–2
2–2 Line number usage 2–2
2–3 Comments in a program 2–3
4–1 File Sharing 4–26
5–1 compile time Table and Array Coding 5–3
9–1 *PLACE Special Word Usage 9–14
9–2 Output field end position in an output record 9–20
10–1 Defining character fields 10–3
10–2 Defining binary fields 10–5
10–3 Defining packed-decimal fields 10–6
11–1 ADD Operation Code Usage - 2 operands 11–10
11–2 ADD Operation Code Usage - 1 operand 11–10
11–3 ADD Operation Code Usage - Indicator controlled 11–10
11–4 ANDxx Operation Code Usage 11–12
11–5 BEGSR Operation Code Usage 11–13
11–6 BITOF Operation Code Usage 11–14
11–7 BITON Operation Code Usage 11–16
11–8 CABxx Operation Code Usage 11–18
11–9 CALL Operation Code Usage 11–20
11–10 CASxx Operation Code Usage 11–22
11–11 CASxx Operation Code Usage - Unconditional CASxx 11–23
11–12 CHAIN Operation Code Usage - Relative file 11–25
xxiii
Contents
xxiv
Contents
xxv
Contents
xxvi
Contents
xxvii
Contents
FIGURES
1–1 Flowchart of Basic RPG Logic Cycle 1–5
1–2 Detailed RPG Logic Cycle Flowchart 1–8
10–1 Format of a Character String 10–2
10–2 Address of a String 10–2
10–3 Word Data Type 10–4
10–4 Longword Data Type 10–4
10–5 Packed-decimal Data Type 10–6
10–6 Zoned-Decimal Data Type (123+) 10–8
10–7 Trailing Numeric Data Type (123-) 10–8
10–8 Zoned-Decimal Data Type (123-) 10–8
11–1 Fixed-Length Descriptor Format 11–99
13–1 Sequential File Organization 13–3
13–2 Relative File Organization 13–4
13–3 Indexed File Organization 13–4
13–4 Index Key Value 13–5
13–5 Sequential File Access Within Limits 13–9
13–6 Creating an Addrout File 13–17
13–7 Using Matching Fields For Multifile Processing 13–33
19–1 Fixed-Length Descriptor Format 19–8
TABLES
2–1 Column 6 (RPG Specification Identification Codes) 2–3
3–1 Column 7 (Comment or Compiler Directive) 3–2
3–2 Column 15 (DEBUG Option) 3–2
3–3 Column 18 (Currency Symbol) 3–3
3–4 Column 19 (Date Format Code) 3–3
3–5 Column 20 (Date Edit Code) 3–4
3–6 Column 21 (Inverted Print Code) 3–5
3–7 Column 26 (Alternate Collating Sequence) 3–5
3–8 Column 43 (File Translation Code) 3–6
3–9 Column 60 (Zoned-decimal output) 3–6
4–1 Column 7 (Comment or Compiler Directive) 4–2
4–2 Column 15 (File Type) 4–3
4–3 Device Types and File Types 4–4
4–4 Column 16 (File Designation) 4–4
4–5 Column 17 (End-of-File) 4–6
xxviii
Contents
xxix
Contents
xxx
Contents
xxxi
Contents
xxxii
Preface
This manual describes the features, uses, constructs, and syntax of the
Migration RPG programming language on OpenVMS systems.
Intended Audience
The Migration RPG User’s Guide is intended for programmers who are
familiar with computer concepts and the RPG II programming language.
Migration RPG was originally developed for users moving from IBM®
System/3X platforms to Digital Equipment Corporation VAX systems and
was modeled after IBM System/36™ RPG II. It has since been enhanced
beyond the scope of IBM System/36 RPG II to provide a more generic
and complete RPG environment under the OpenVMS operating system.
Migration RPG still maintains complete IBM System/36 compatibility.
This manual is designed to be used as a reference manual.
Convention Meaning
CTRL/X This sequence indicates that the user must hold down
the key labeled CTRL while pressing another key.
PF1 + X This sequence indicates that the user must first press
and release the key labeled PF1, then press and release
another key.
RETURN or <RETURN> A keyname is shown enclosed or within angle brackets
to indicate a key on the keyboard to be pressed by the
user.
A vertical ellipsis indicates the omission of items from
. a code example or command format. The items are
. omitted because they are not important to the topic being
. discussed.
() In format descriptions, parentheses indicate that, if more
than one option is chosen, the options must be enclosed
in parentheses.
[] In format descriptions, optional parameters in a
command are denoted by square brackets. If a
command delimiter, such as a comma or slash, is
included within the square brackets, it is also optional. If
the delimiter is outside the square brackets, it is required
in the command line. Never include the square brackets
in the command line.
BOLDFACED TEXT Commands entered by the user at the terminal are
printed in boldfaced type.
xxxiii
Preface
Associated Documents
Additional information concerning Migration RPG can be found in the
following manuals:
• Migration RPG User’s Guide
• Migration RPG Screen Format Reference Manual
xxxiv
1 Understanding the Migration RPG Logic Cycle
There are also three types of specifications which can be used to define
RPG workstation screens and Menu and Prompt Utility screens. These are
the Screen Specification (S), Help Specification (H), and Field Description
Specification (D). These specifications are covered in the Migration RPG
Screen Format Reference Manual.
1–1
Understanding the Migration RPG Logic Cycle
1–2
Understanding the Migration RPG Logic Cycle
1–3
Understanding the Migration RPG Logic Cycle
1–4
Understanding the Migration RPG Logic Cycle
START
(1)
(2)
(3)
Read a record.
(4) (5)
No
(6)
Yes
First cycle?
No
(7)
(8)
(9)
Is the Yes
last record End of job
indicator
on?
No
(10)
(11)
Detail calcs.
1–5
Understanding the Migration RPG Logic Cycle
Upon detecting the last-record indicator, the program enters the last cycle,
does one-time cleanup work, including total calculations and total output
operations, and ends.
1–6
Understanding the Migration RPG Logic Cycle
Each cycle begins when a new record is input and ends just before the
next record is input. The RPG coding specifications determine the range
and type of functions performed during each cycle. During the calculation
and output steps within each cycle, there are two distinct timing phases:
• Total time operations are performed on summary data accumulated
from a group of related records.
• Detail time operations are performed on individual records.
Sections 1.4.2.1 and 1.4.2.2 describe total time and detail time
characteristics and operations.
The first and last cycles of an RPG program are different from the rest of
the cycles in the program. They are responsible for program startup and
shutdown operations. These cycles are described in detail in the sections
1.4.1 and 1.4.3.
1–7
Understanding the Migration RPG Logic Cycle
START
(1) (8)
(9)
No
(3) Last No
record ind.
Initialize fields, data (LR) on?
structures, tables, and
arrays.
Load local data area. Yes
Open files. (10)
Turn on all
(4) control break
indicators
Perform header output. (L1 − L9).
Perform detail output.
Perform overflow output.
This step is the return
point for a normal RPG
cycle. Goto step 25
(5) (11)
*GETIN
Halt No
indicator(s) Return No
on? indicator (RT)
on?
Yes
(5a) Yes
(12)
Issue message
to user. Return
parameters
(5c)
Clear (13)
halt
ind. RETURN
(5b)
Cancel?
No (14)
1–8
Understanding the Migration RPG Logic Cycle
(15) (23)
Set on appropriate
control break indicators
(16) (L1 − L9).
Read Yes
being forced?
(25)
No No
LR on?
(17)
Matching No
fields (MR) Yes
present?
(26)
Have
Yes LR total Yes
(18) time operations
taken place
Match fields routine. ?
No
(27)
(19) (19a) *CANCL
End Total time calculations.
of job Yes Set on
conditions L1 − L9,
met? and LR (28)
(20) (29)
(33)
(21) Yes
Was (30) Close all files.
a record No
identified? Process halt indicators.
(34)
Control− No (32)
break indicators (35)
specified? Output local data area
and external indicators. Set return
Yes status and
exit program.
1–9
Understanding the Migration RPG Logic Cycle
(36)
Overflow No
indicators on?
Yes
(37)
(38)
(39)
(40)
Look−ahead No
fields
specified?
Yes
(41)
Look−ahead routine.
(42) *DETC
Process detail
calculations.
Goto step 4
1–10
Understanding the Migration RPG Logic Cycle
1–11
Understanding the Migration RPG Logic Cycle
If no halt indicators are set or if the user clears all set halt indicators
using the CONTINUE option, the program jumps to step 8. If a halt
indicator is set and the program is running in batch mode, or the user
selects the EXIT or KILL options at the halt prompt, the program
proceeds to step 6.
The step also serves as the return point for a *GETIN operation at the
end of a INFSR subroutine.
6 The program is being terminated due to a halt. Image termination
processing to handle the halt condition begins at this step.
7 The program jumps to step 33 to complete the halt-induced
termination.
8 Control break indicators (L1 - L9), first page indicator (1P), and all
record-identifying indicators are set off. Overflow indicators (OA
through OG, and OV) are also set off unless they were set on in the
previous cycle during detail calculations or detail output. All other
types of indicators that are on remain on.
9 The last record indicator (LR) is checked. If it is on, the program
proceeds to step 10 and begins last cycle processing. If it is not on, the
program jumps to step 11.
10 As the first step in last cycle processing, all control break indicators
(L1 - L9) are turned on. The program then jumps to step 25.
11 The return indicator (RT) is checked. If it is on, processing continues
with step 12, which will prepare for an immediate exit from the
program. If it is not on, the program jumps to step 14.
12 If the program contains a *ENTRY PLIST, contents of the fields
specified in factor 2 of the PARM statements are transferred to the
result field in preparation for passing the parameter information back
to the calling program.
13 The subprogram returns immediately to the calling program. Files,
fields, and indicators are left as they are currently set when a
subprogram exits in this fashion. If the subprogram is called again,
it will start up with all of these settings intact. The calling program
can initialize the subprogram before calling it again using the FREE
operation.
14 RPG determines whether a primary file was specified by the program.
If not, the program jumps to step 25.
15 On the first cycle, RPG reads a record from the primary input file and
each of the secondary files. On all other cycles, the program reads a
record from the last file processed, if required. If a record address file
is being used, the data retrieved from the record address file identifies
the record that is to be retrieved. If look-ahead fields are specified
in the last record processed, the record required may already be in
storage, meaning that no read will be necessary at this point.
16 If a FORCE instruction was processed during the previous cycle, the
program selects that file for processing. If a FORCE command is
processed, the program jumps to step 19, bypassing matching record
processing.
1–12
Understanding the Migration RPG Logic Cycle
1–13
Understanding the Migration RPG Logic Cycle
1–14
Understanding the Migration RPG Logic Cycle
Although all iterations of the logic cycle (other than the first) include a
total time phase, RPG bypasses all total time calculations and total time
steps during the first cycle unless the last-record (LR) indicator is on.
Example 1–1 shows an output record using the 1P indicator to specify that
the associated specifications should only output during the first cycle.
Example 1–1 Example of first cycle output specifications
1 2 3 4 5
1234567890123456789012345678901234567890123456789012345678
OREPORT H 1P
O 35 ’SALES REPORT’
O UDATE 80 ’ / / ’
1–15
Understanding the Migration RPG Logic Cycle
1–16
Understanding the Migration RPG Logic Cycle
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456789
*
FSALESFILIPE F8000 80 DISK
FREPORT O F 80 PRINTER
*
ISALESFILAA 01
I 01 04 REGIONL8
I 05 08 DIST L7
I 09 38 SALNAM
I 39 44 SALEIDL6
I P 45 492SALES
.
.
.
C SALES ADD SALTOT SALTOT 92
.
.
.
CL6 SALTOT ADD DISTOT DISTOT 92
CL7 DISTOT ADD REGTOT REGTOT 92
CL8 REGTOT ADD GRAND GRAND 102
.
.
.
OREPORT T L6
O 20 ’Total for Sales Person:’
O SALNAM 51
O SALEID 60
O SALTOT B 80 ’$ , , . ’
OREPORT T L7
O 20 ’District Total’
O DISTOT B 80 ’$ , , . ’
OREPORT T L8
O 20 ’Regional Total’
O REGTOT B 80 ’$ , , . ’
OREPORT T L9
O 15 ’Grand Total’
O GRAND B 80 ’$ , , . ’
In example 1–2, the following steps take place during total time
processing. In referring back to the detailed logic cycle (figure 1–2),
this description of total time processing will be starting at step 22.
• If, after the input of a new record, RPG determines that the
salesperson identification number in the current record differs from
the salesperson identification number in the previous record, a control
break occurs and the indicator L6 is turned on. When the L6 indicator
is turned on, all lower control break indicators are turned on as well.
Thus, the L6 control break turns on indicators L1 - L6. During total
time processing, the program will perform all L1 - L6 total time
calculations and output specifications. In the example, these are the
accumulated total sales for the salesperson whose number was found
in the previous record.
• During another cycle, the region identifier field changes. This will turn
on control break indicators L1 - L8. In this case, all L1 - L8 total time
calculations and output will be performed. In the example, the total
time processing for salesperson (L6), district (L7), and region (L8) will
all take place due to the L8 control break.
1–17
Understanding the Migration RPG Logic Cycle
• After the last input record in the file has been read, the last record
(LR) and all control break indicators are turned on. This is part of
last cycle total time processing. With indicators L1 - L9 on, all total
time calculations and output are performed. In the case of the sample
program, total time processing for the salesperson (L6), district (L7),
region (L8), and grand total (LR) will take place.
• During the normal RPG cycle, after control breaks have been processed
and total time processing takes place, detail time processing begins.
Detail time operations are for the record just read and are described in
the next section.
1–18
Understanding the Migration RPG Logic Cycle
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456789
FSALESFILIPE F8000 80 DISK
FREPORT O F 80 PRINTER
*
ISALESFILAA 01
I 01 04 REGIONL8
I 05 08 DIST L7
I 09 38 SALNAM
I 39 44 SALEIDL6
I P 45 492SALES
.
.
.
C SALES ADD SALTOT SALTOT 92
.
.
.
CL6 SALTOT ADD DISTOT DISTOT 92
CL7 DISTOT ADD REGTOT REGTOT 92
CL8 REGTOT ADD GRAND GRAND 102
.
.
.
OREPORT H 1P
O 35 ’SALES REPORT’
O UDATE 80 ’ / / ’
OREPORT H L8
O 07 ’Region:’
O REGION 12
OREPORT H L7
O 15 ’District:’
O DIST 20
OREPORT H L6
O 20 ’Sales Person:’
O SALNAM 50
OREPORT D 01
O SALES 50 ’$ , , . ’
OREPORT T L6
O 20 ’Total for Sales Person:’
O SALNAM 51
O SALEID 60
O SALTOT B 80 ’$ , , . ’
OREPORT T L7
O 20 ’District Total’
O DISTOT B 80 ’$ , , . ’
OREPORT T L8
O 20 ’Regional Total’
O REGTOT B 80 ’$ , , . ’
OREPORT T LR
O 15 ’Grand Total’
O GRAND B 80 ’$ , , . ’
1–19
Understanding the Migration RPG Logic Cycle
In example 1–3, the following steps take place during the last cycle. In
referring back to the detailed logic cycle (figure 1–2), this description of
the last cycle will be starting at step 19.
• The input file being read is at end-of-file, so the last record indicator
(LR) and all control break indicators (L1 - L9) are turned on.
• Total time calculations and output are performed for the last time.
In the example, all of the total time calculations will be performed to
finalize the accumulation of sales totals. This information will then be
output during total time output. The grand total for all sales will also
be output at this time, as its output specifications are qualified by the
LR indicator.
• The data and report files are closed and normal program shutdown
procedures take place, terminating the program.
1–20
2 Migration RPG Program Specifications
2–1
Migration RPG Program Specifications
1 2 3 4 5
1234567890123456789012345678901234567890123456789012345678
^
The arrow in the previous example points to column 43. The first line in
the column numbers contains the tens digits; the second line contains the
units digits.
1 2 3 4 5
1234567890123456789012345678901234567890123456789012345678
*
0056 IWORKSTN NS 99 1 C
0057 I OR 01 1 C1
0058 I 2 41 NAME
NEW I NS 04 1 C4
NEW I 2 2 ANSWER
0059 I NS 05 1 C5
.
.
.
2–2
Migration RPG Program Specifications
2.2.3 Comments
If an asterisk is placed in column 7 of a specification line, the entire line
can be used as a comment line. Comment lines do not require an entry in
column 6.
Columns 75 - 80 can be used to write comments in all RPG program
specifications. The RPG compiler ignores entries in columns 75 - 80.
Several of the RPG specifications allow comments to begin in columns
preceding column 75. See each specification section to determine where
comments can begin.
Example 2–3 Comments in a program
1 2 3 4 5 6 7
12345678901234567890123456789012345678901234567890123456789012345678901234
*
F* INDICATOR USAGE
F*
F* 01 SCREEN IDPT01 ACTIVE
F* 02 SCREEN IDPT02 ACTIVE
F* 10 HARDCOPY NOT COMPLETE
F* 15 ON-KEEP SCANNING FOR QUESTION / OFF-QUESTION
*
FWORKSTN CP F 79 WORKSTN
FDIFFHISTIC F 96 96R DISK
FREPORT O F 132 132 OF PRINTER
*
E TABA 8 8 2 A CORRECT ANS TABLE
E #ERR 1 2 41 ERROR MESSAGES
E TST 50 50 1 CORRECT ANSWERS
E ANS 50 1 USER ANSWERS
2–3
Migration RPG Program Specifications
2–4
3 Control Specification (H)
3–1
Control Specification (H)
3–2
Control Specification (H)
3–3
Control Specification (H)
If the UDATE field is being fed a date that is not in MM/DD/YYYY format
and the appropriate entry has not been made in column 19, the program
will work with the wrong date. For example, if the date 1999/02/15, which
is in YYYY/MM/DD format, is entered in the UDATE field via the REX
Utility, but the program accessing the date was not compiled with a Y
in column 19, the program will read the date in MM/DD/YYYY format,
placing 19 in the month columns, 99 in the day columns, and 0215 in the
year columns. This will no doubt confuse the end users.
The same problem can occur when using the TIME operation code to
obtain the system date. By default, this date is returned in MM/DD/YYYY
format. If the programmer is expecting to work with a date in a different
format, the appropriate date format code must be specified in column 19.
Note: The format of the reserved word $UDATE, which supplies the date
in a 6-digit non-Year 2000 compliant form, is also determined by
the entries in columns 19 and 20. See the Migration RPG Year 2000
Compliance Guide for more information concerning the $UDATE
field.
3–4
Control Specification (H)
See Appendix A, Character Sets, for a listing of the ASCII and EBCDIC
character sets.
3–5
Control Specification (H)
3–6
4 File Description Specification (F)
4–1
File Description Specification (F)
4–2
File Description Specification (F)
Table 4–3 shows the device types and file types which can be associated
together:
4–3
File Description Specification (F)
4–4
File Description Specification (F)
4–5
File Description Specification (F)
4–6
File Description Specification (F)
4–7
File Description Specification (F)
4–8
File Description Specification (F)
Random processing reads records from chained files in one of the following
two ways:
• For sequential or direct files, records are accessed by their relative
record number. A relative record number identifies the position of a
record relative to the beginning of the file.
• For indexed files, records are accessed by their index key values.
Addrout file processing uses the record address file generated by the
OpenVMS SORT Utility. The addrout file contains binary record numbers
that correspond to the addresses of records; therefore, the records to be
read are located by their addresses.
The entries listed in Table 4–10 are valid for sequential files that reside on
disk.
4–9
File Description Specification (F)
4–10
File Description Specification (F)
The entries listed in Table 4–11 are valid for relative files that reside on
disk.
4–11
File Description Specification (F)
The entries listed in Table 4–12 are valid for indexed files that reside on
disk.
4–12
File Description Specification (F)
The entries listed in Table 4–14 are valid for workstation files.
The entries listed in Table 4–15 are valid for record address files. Record
address files can be associated with sequential, relative, or indexed files
that reside on disk. Record address files containing key field limits can
only be associated with indexed files.
4–13
File Description Specification (F)
The entries listed in Table 4–16 are valid for KEYBORD files.
The entries listed in Table 4–17 are valid for SPECIAL device files.
4–14
File Description Specification (F)
The record length for an addrout file can be either 3 or 6. An addrout file
produced by the OpenVMS SORT Utility contains records 6 characters in
length. An entry of 3 for an addrout file is converted to 6 by the compiler.
This feature is used by Migration RPG to support RPG II programs
transferred to an OpenVMS system from an IBM System/3, System/34, or
System/36.
The entry must be numeric and right-justified. Leading zeros can be
omitted.
Packed-decimal key fields can have a maximum length of 8. When
specifying the length of a packed-decimal key, use the packed length of
the field.
4–15
File Description Specification (F)
4–16
File Description Specification (F)
4–17
File Description Specification (F)
4–18
File Description Specification (F)
possible. For this reason, Migration RPG supports a wide range of device
types.
The following table specifies the standard device types used in Migration
RPG. Given the ability to associate File Description specifications logically
to devices on an OpenVMS system, these device types are sufficient for
most RPG applications.
4–19
File Description Specification (F)
DECTAP Input device associated to a tape drive. Tape files can only be
TAPE processed as sequential input files.
PRINTR Output device used to define a report file.
READER Input device associated to a card reader. Card reader files can only
READ40 be processed as sequential input files.
TTY Input device associated to the logical SYS$INPUT. A TTY device can
be used to input records embedded in a command procedure.
4–20
File Description Specification (F)
4–21
File Description Specification (F)
4–22
File Description Specification (F)
4–23
File Description Specification (F)
4–24
File Description Specification (F)
4–25
File Description Specification (F)
In this example, the program MISTAKE assigns two file streams to the
data file GOODSTUFF.DAT. Under default conditions, this operation
would present no problems. However, if in the program the file GREEDY
has a share code of ‘N’, the program will be unable to connect a second
stream to the data file and will abort when it tries to connect the stream
for OUTCST.
4–26
File Description Specification (F)
4–27
5 Extension Specification (E)
Compile time tables and arrays require entries in columns 19 - 45; pre-
execution-time tables and arrays require entries in columns 11 - 45;
execution-time arrays require entries in columns 27 - 32 and columns
36 - 45. An alternate table or array must be defined on the same line in
columns 46 - 57.
A record-address file requires entries in columns 11 - 26. These entries
provide the following information:
• Name of the record-address file
• Name of the data file associated with the record-address file
5–1
Extension Specification (E)
5–2
Extension Specification (E)
The following example displays compile time table and array Extension
specifications and the associated data coded at the end of the program.
Example 5–1 compile time Table and Array Coding
1 2 3 4
1234567890123456789012345678901234567890123456
E*
E TABCST 3 9 4 2
E ARYDB 4 8 2
.
.
.
O*
** Data for TABCST compile time table.
134592830587
283758471047
574837263746
** Data for ARYDB compile time array.
SASBSCSD
THATBTCTD
5–3
Extension Specification (E)
5–4
Extension Specification (E)
The following rules apply to the from-file name (columns 11 - 18) and
number of entries in a record (columns 33 - 35) when an array name is
specified in columns 27 - 32.
• An execution-time array requires that columns 11 - 18 and 33 - 35 be
blank.
• A compile time array must have an entry specified in columns 33 - 35.
Columns 11 - 18 must be blank.
• A pre-execution-time array must have a file name specified in columns
11 - 18 and an entry in columns 33 - 35.
5–5
Extension Specification (E)
If a compile time array is not full, the RPG compiler will issue a warning
message when the program is compiled.
5–6
Extension Specification (E)
All numeric tables and arrays must have an entry specified in this column.
Specify a zero for numeric data with no decimal positions.
When alternating arrays or tables are specified, this entry applies to the
first entry that appears in the array or table data record.
5–7
Extension Specification (E)
When using tables or arrays in alternating format, this entry specifies the
sequence of the primary table or array.
When a sequence is specified for a compile time table or array, the
sequence is checked by the RPG compiler. If the table or array is not
sorted in the specified sequence, the compiler issues a fatal compile time
error.
If a pre-execution-time table or array is out of sequence, the program halts
and prompts the user to ignore the error and continue, or terminate the
program.
5–8
Extension Specification (E)
5–9
Extension Specification (E)
All numeric tables and arrays must have an entry specified in this column.
Specify a zero for numeric data with no decimal positions.
When alternating arrays or tables are specified, this entry applies to the
second entry that appears in the array or table data record.
5–10
Extension Specification (E)
5–11
6 Line Counter Specification (L)
6–1
Line Counter Specification (L)
6–2
Line Counter Specification (L)
This entry must be equal to or less than the form length. The entry must
be a right-justified, numeric value. Leading zeros can be omitted.
When the overflow line is reached, the following actions occur if fetch
overflow has not been specified.
1 If detail output has not been completed, detail output occurs.
2 Total-time output occurs.
3 Total lines conditioned by the overflow indicator are output.
Overflow printing occurs after the overflow line has been reached. Enough
space should be left between the overflow line and the end of the page to
allow for the overflow print lines.
If the overflow line is equal to the form length, overflow does not occur.
6–3
7 Input Specification (I)
The Input specification describes the records in input and update files.
The specifications can be divided into three categories:
• File and record descriptions. Columns 7 - 42 describe the file and its
records.
• Field descriptions. Columns 43 - 74 describe the fields in each record
and data structure.
• Data structure definitions. Columns 7 - 20 can be used to define a data
structure.
7–1
Input Specification (I)
If this entry is blank, the compiler will assume that the information
in this line describes a field or record from the last file named in an
Input specification. If the line follows a data structure definition, it can
be another data structure definition (DS in columns 19 - 20) or a data
structure subfield definition.
All records and fields associated with one file should be described in one
contiguous section of Input specifications.
The entry must be left-justified.
7–2
Input Specification (I)
Within one file, all records using alphabetic sequence codes must be
defined before those using numeric sequence codes.
Record sequencing can be used to insure that records from a file are
processed in the correct order. For example, in a customer order file
containing an order record followed by several detail records containing
order information, it would be important to ensure that the order record
was processed before the associated detail records. By assigning the order
record a sequence code of 01 and the detail record a sequence code of 02,
the program will ensure that the records are in the correct sequence before
it processes them.
If a record is processed out of sequence, the program halts and gives
the user the option of ignoring the sequence error and continuing or
terminating the program.
Sequence checking does not place records in order. It verifies that records
are in the correct order when they are input into the program. Sequence
checking has no relation to control levels and does not check data within a
record.
Input specifications with an AND or OR specified in columns 14 - 16
cannot have a sequence code.
7–3
Input Specification (I)
7–5
Input Specification (I)
7–6
Input Specification (I)
Entries Explanation
Blank Indicates that there is no record-identification condition. In this case, make
sure that all of the other record identification columns in this subset are
blank as well.
1-9999 Defines the position in the input record that is to be compared to the
character specified in columns 27, 34, and 41. For example, the number
10 specified in columns 28 - 31 would indicate that position 10 of the input
record should be compared to the character specified in column 34.
The position entry must be numeric and right-justified. Leading zeros can
be omitted.
7–7
Input Specification (I)
7–8
Input Specification (I)
7–9
Input Specification (I)
This entry must be greater than or equal to the start position entry in
columns 44 - 47. When specifying a one-character field, the start and end
position entries will be the same.
A value must be specified in this column for a numeric field even if the
field has no decimal points. In this case, specify a zero.
The number of decimal positions must be less than or equal to the number
of digits in the numeric field. If a number greater than the length of the
field is specified, the number of decimal positions is assumed to be equal
to the length of the field.
7–10
Input Specification (I)
If a 2 is specified in this column and the field contains the data 12345, the
field’s value is interpreted as 123.45. If a 4 is specified in this column and
the field contains the data 12345, the field’s value is interpreted as 1.2345.
7–11
Input Specification (I)
7–12
Input Specification (I)
Control break indicators can only be specified for primary and secondary
files.
Control break indicators can be assigned in any order.
Control break indicators are ranked from highest (L9) to lowest (L1).
When a control break causes RPG to set on a control break indicator,
all lower control break indicators are set on as well. All control break
indicators are set off after detail time output.
Control fields are initialized to hexadecimal zeros. This usually causes a
control break to occur on the first record with a control field. Because of
this, RPG bypasses total-time calculation and output operations on the
first cycle.
Fields with different control break indicators can overlap in a record.
The same number of control fields do not need to be specified for all record
types.
Control break indicators cannot be specified for look-ahead fields.
When the same control break indicator is assigned to more than one field,
the fields are referred to as split-control fields. In this case, the fields
must be either all numeric or all alphameric and described on adjacent
lines. The fields used within split-control fields do not need to be the same
length.
The maximum length of a control field or split-control field is 144
characters.
The total length of a split-control field must be the same length as other
fields using the same control break indicator.
The decimal positions and sign of numeric fields are ignored when
determining a control break. Thus, the fields 257.8 and 2578 would be
considered equal. The fields -3049 and 3049 would also be considered
equal.
Field names are ignored when processing control fields. This allows the
same control break indicator to be assigned to multiple fields with the
same name.
If any one control field is numeric, all fields assigned to that control break
indicator will be treated as numeric when being compared, meaning that
only the digit portion of each character will be compared.
7–13
Input Specification (I)
Matching fields can be used with one file to perform sequence checking or
with multiple files to control the order in which records are processed.
Matching fields can only be specified for records in primary and secondary
input and update files.
Up to nine different fields can be specified as match fields in a single
record.
If more than one matching field is specified for a record type, all the fields
are logically concatenated and treated as one continuous field. The fields
are combined according to descending sequence (M9 - M1) of matching
field values.
The match codes M1 - M9 are not indicators. If a record is matched, the
matching-record indicator, MR, will be turned on. The MR indicator can
be used in the Calculation and Output specifications.
The program performs sequence checking for all record types with
matching field specifications. An error in sequence will generate a halt.
The user will be given the option of ignoring the mismatched record and
continuing, or terminating the program.
The same number of matching fields and the same matching field values
(M1 - M9) must be defined for all records that contain matching fields.
The maximum length of all matching fields combined cannot exceed 144
characters.
Matching fields can be overlapped in a single record.
When more than one matching code is used, all matching fields must
match before the matching-record indicator (MR) is set on.
7–14
Input Specification (I)
Matching fields assigned the same matching code (M1 - M9) should be
either numeric with the same number of digits or alphameric with the
same length. If any single match field is numeric, all fields assigned that
match code will be treated as numeric fields when compared, meaning that
only the digit portion of the field will be compared.
Not all files or all record types within one program must have matching
fields defined. However, at least one record type from each of two files
must have matching fields defined if the files are to be matched.
If the matching field contains packed-decimal data, the unpacked length,
which is two times the packed length minus one, is considered the length
of the matching field for comparison purposes. It is valid to match a
packed field in one record against a zoned-decimal or trailing numeric field
in another if the unpacked lengths are equal. The length must always be
odd because the length of a unpacked, packed-decimal field is always odd.
The file sequence specified in column 18 of the File Description
specification must be the same for the files compared using matching
fields. All files must be in ascending or descending sequence.
The sequence of a single file can be checked using M1 - M9 codes to
designate the sequence check fields. If the file is out of sequence, a halt
occurs and the user has the option of ignoring the non-sequenced record or
terminating the program.
Look-ahead fields cannot be specified as matching fields.
If an alternate collating sequence is specified, it is used when comparing
the values in matching fields containing alphameric data.
Field names are ignored when carrying out match field compares, so fields
from different records can have the same name and match code.
When specifying an ascending sequence check, match fields are initialized
to hexadecimal zeros. When a descending sequence is specified, match
fields are initialized to hexadecimal FF’s. Numeric fields are initialized to
zero.
Numeric matching fields are compared based on their absolute values;
decimal positions and signs are ignored. Thus, the field 2.987 and 298.7
would be considered equal, as would the fields 2039 and -2039.
Matching fields cannot be split; the same matching field value (M1 - M9)
cannot be used more than once within one record.
Matching fields are independent from control break indicators.
7–15
Input Specification (I)
If a program has two records with eight fields each, and the first seven
fields are the same but the last field is different, a record-identifying
indicator can be used as the field-record-relation indicator to condition the
field that is different, rather than defining all eight fields for both records.
7–16
Input Specification (I)
7–17
Input Specification (I)
7–18
8 Calculation Specification (C)
8–1
Calculation Specification (C)
8–2
Calculation Specification (C)
8–3
Calculation Specification (C)
8–4
Calculation Specification (C)
8–5
Calculation Specification (C)
8–6
Calculation Specification (C)
8–7
Calculation Specification (C)
Any entry in this field must be numeric and right-justified. Leading zeros
can be omitted.
The maximum length for a numeric field is 15 digits.
The maximum length for an alphameric field is 256 characters.
If the field is described elsewhere in the program and an entry is made in
columns 49 - 51, both entries must specify the same length. If they do not,
the compiler will issue a warning message and use the first field definition
it encountered to define the field.
8–8
Calculation Specification (C)
If the field has been described previously in the program and an entry is
made in column 52, both entries for decimal positions must be the same.
If they are not, the compiler will issue a warning message and use the first
valid field definition for all occurrences of the field.
The number of decimal positions must be less than or equal to the length
of the field.
If the result field contains alphameric data, leave this column blank.
When the result is numeric, but has no decimal positions, a zero must be
specified in this column.
8–9
Calculation Specification (C)
Using a control break indicator (L1 - L9) as a resulting indicator does not
automatically set on lower-level, control break indicators.
Using an external indicator (U1 - U8) as a resulting indicator allows the
indicator to be set; it can then be tested after the program exits.
8–10
9 Output Specification (O)
9–1
Output Specification (O)
The file name must match a file name specified in the File Description
specifications. Valid output files are add, combine, output, or update files.
The entry must be left-justified.
If columns 7 - 14 are blank, the compiler assumes that the information in
this program line describes a field or record from the file last named.
All the records for a single file need not be described together.
9–2
Output Specification (O)
9–3
Output Specification (O)
9–4
Output Specification (O)
An entry in this column is valid only for printer output files with overflow
lines.
Do not specify an overflow indicator on the same line as fetch overflow.
If an overflow indicator is specified in columns 23 - 31 of the same
specification, the overflow routine will not be fetched for the specification.
If an OR relationship is specified between two lines, each output record
defined by the OR relationship that is to use fetch overflow must have an
F specified in column 16.
RPG fetches an overflow routine when overflow occurs and all conditions
specified by the indicators in columns 23 - 31 of the Output specification
are met. When fetch overflow is specified, only overflow output associated
with the file containing the executed fetch routine is output. The overflow
routine does not automatically advance to the next page.
9–5
Output Specification (O)
9–6
Output Specification (O)
Entries can be specified in all space and skip columns for a single program
line. If this is done, the entries are executed in the following order: skip
before, space before, print the output line, skip after, and space after.
Specifying a skip before entry past the overflow line causes RPG to set on
the overflow indicator.
If a skip before entry is specified on the same line number that the printer
is currently on, no skipping takes place.
If a skip before entry is specified to a line number less than the current
line number, the printer advances to that line number on the next page.
The skip entry cannot exceed the entry for forms length (columns 18 - 19
of the Line Counter specification). If there is no Line Counter specification,
the skip entry cannot exceed the default of 66 lines.
Columns 19 - 20 must be left blank for an AND line.
If columns 19 - 20 are left blank for an OR line, the entries made for the
previous record will be applied to the OR line.
9–7
Output Specification (O)
Entries can be specified in all space and skip columns for a single program
line. If this is done, the entries are executed in the following order: skip
before, space before, print the output line, skip after, and space after.
Specifying a skip after entry past the overflow line causes RPG to set on
the overflow indicator.
If a skip after entry is specified on the same line number that the printer
is currently on, no skipping takes place.
If a skip after entry is specified to a line number less than the current line
number, the printer advances to that line number on the next page.
The skip entry cannot exceed the entry for forms length (columns 18 - 19
of the Line Counter specification). If there is no Line Counter specification,
the skip entry cannot exceed the default of 66 lines.
Columns 21 - 22 must be left blank for an AND line.
If columns 21 - 22 are left blank for an OR line, the entries made for the
previous record will be applied to the OR line.
9–8
Output Specification (O)
9–9
Output Specification (O)
9–10
Output Specification (O)
When conditioning an entire record, enter the indicator on the line that
specifies the record type (column 15). When conditioning a field, enter the
indicator on the same line as the field name (columns 32 - 37).
If more than one indicator is specified on a line, the indicators form an
AND relationship.
Overflow indicators can be used on AND or OR lines; however, only one
overflow indicator can be associated with a group of output indicators. If
a line is to be considered an overflow line, the overflow indicator must
appear on the main specification line or on an OR line.
If an overflow indicator is used, it must be the same one assigned to the
file on the File Description specification.
Overflow indicators cannot be used to condition exception output lines, but
they can be used to condition fields in an exception record.
Note that RPG outputs those detail and heading lines conditioned by
the first-page (1P) indicator, no indicator, or all negative indicators (N in
columns 23, 26, or 29) before reading the first record from a file. Therefore,
use the 1P indicator to condition only heading and detail output lines that
do not depend on data from an input record. For a line with no indicators
or all negative indicators that requires data from an input record, use a
negative first-page indicator (N1P in columns 23 - 31) to prevent the line
from being output before reading the first record.
Because the 1P indicator is set off after the first detail time output, it
should only be used to condition heading and detail lines.
If a control break indicator is used with a total record and no overflow
indicator, the record is output when a control break occurs and after
the last record of a control group has been processed. If a control break
indicator is used with a detail record and no overflow indicator, the record
is output when a control break occurs and after the first record of a new
control group has been processed. If a control break indicator is used with
an overflow indicator, the record is output when a control break occurs and
the overflow line has been passed.
9–11
Output Specification (O)
9–12
Output Specification (O)
9–13
Output Specification (O)
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
*
OREPORT D
O HOTFT 10
O DNCSTP 15
O QCKFT 25
O HOTFT 35
O DNCSTP 40
O QCKFT 50
O BALLRM 75
In the second set of Output specifications, the fields HOTFT, DNCSTP, and
QCKFT are output twice by specifying the *PLACE special word to replace
the second set of output field definitions. Note that the end position of the
*PLACE field accounts for the total size of all three fields it is duplicating.
This code will produce the same results as the code in the first output
example.
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
*
OREPORT D
O HOTFT 10
O DNCSTP 15
O QCKFT 25
O *PLACE 50
O BALLRM 75
A *PLACE special word repeats all fields in a record which preceded it.
The end position specified for a *PLACE special word indicates where the
fields being repeated by the *PLACE operation will end. Be sure the end
position specified accounts for the length of all of the fields being repeated
to prevent field overlapping.
The *PLACE special word can be repeated to duplicate field definitions
more than once within a output record.
Additional fields and constants can be specified following a *PLACE
special word. These items will not be affected by the *PLACE operation.
9–14
Output Specification (O)
The format the process date is returned in depends upon the setting placed
in columns 19 - 21 of the Control specification. See sections 3.8, 3.9, and
3.10 in Chapter 3, Control Specification (H), for more information on how
to specify the format in which a process date is returned.
The UMONTH and $UMNTH fields specify the month portion of the
process date. These fields are defined as a 2-digit, zero-decimal, numeric
fields.
The UDAY and $UDAY fields specify the day portion of the process date.
These fields are defined as a 2-digit, zero-decimal, numeric fields.
The UYEAR and $UYEAR fields specify the year portion of the process
date. The UYEAR field is defined as a Year 2000 compliant 4-digit, zero-
decimal, numeric field. The $UYEAR field is defined as a non-Year 2000
compliant 2-digit, zero-decimal, numeric field.
9–15
Output Specification (O)
9–16
Output Specification (O)
9–17
Output Specification (O)
9–18
Output Specification (O)
9–19
Output Specification (O)
The end position is the location of the rightmost character in the output
field. For example, if a field contains 26 characters and 40 is specified as
the field end position, the field would be placed in the output record as
follows:
Example 9–2 Output field end position in an output record
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
Colorado Springs, Colorado
The numbers above this example are for reference only; they do not appear
in the output record.
9–20
Output Specification (O)
Leave this entry blank for the output field under the following conditions:
• The output file is a PRINT or PRINTER file.
• An alphameric field is being output.
• An edit code has been specified.
• An edit word has been specified.
• The special word *PLACE is being used.
9–21
Output Specification (O)
9–22
Output Specification (O)
9–23
Output Specification (O)
9–24
Output Specification (O)
* Indicates that the field is to be edited using asterisk fill. Place the
asterisk in the rightmost position where asterisk fill is to stop.
Each leading zero that appears in the data to the left of and
including the stop position is replaced with an asterisk. The first
asterisk encountered when scanning the edit word is the asterisk fill
character. Any asterisk appearing after the first asterisk is treated
like any other character.
Edit word using asterisk fill
Source Data Edit Word Result of Edit
00496.23 ’bbbb*.bb’ **496.23
00496.23 ’*bbbb.bb’ *0496.23
& Indicates that the position in the edited field is to be a blank space.
Edit word using the ampersand character
Source Data Edit Word Result of Edit
00496.23 ’bbbbb.bb&-&Sales’ bb496.23b-bSales
9–25
Output Specification (O)
Decimal point Indicates the exact position in the edited field where a decimal point
or comma or comma is to be printed. If a decimal point or comma appears
to the left of the most significant digit in the output field, it will be
replaced with a blank space or, if asterisk fill is specified, with an
asterisk.
Edit word using commas and a decimal point
Source Data Edit Word Result of Edit
00496.23 ’bb,bbb.bb’ bbb496.23
47496.23 ’bb,bbb.bb’ 47,496.23
Any other Prints the characters in the edited fields, if the position is to the right
character of the most significant digit in the edited field. Any character to the
left of the most significant digit in the edited field is replaced with a
blank space or an asterisk if asterisk fill is specified.
Edit word using the slash (/) character
Source Data Edit Word Result of Edit
030992 ’bb/bb/bb’ b3/09/92
030992 ’0bb/bb/bb’ 03/09/92
9–26
Output Specification (O)
The following table describes the characters which can be used in the sign
portion of an edit word.
Any Prints the specified character(s) in the edited field if the data is
character negative; otherwise, the character is replaced by a blank. If
an ampersand ( & ) is specified, it will be replaced by a blank
space. These characters must appear between the last replaceable
character in the edit word and the sign character(s). If they appear
to the right of the sign character(s), they are treated as extensions to
the field and will always be printed.
Edit words for a negative field using optional display characters
Source Data Edit Word Result of Edit
496.23 ’bbb.bb&30&day&CR’ 496.23bbbbbbb
496.23- ’bbb.bb&30&day&CR’ 496.23b30bdaybCR
496.23 ’bbb.bbCR&overdue’ 496.23bbboverdue
496.23- ’bbb.bbCR&overdue’ 496.23CRboverdue
9–27
Output Specification (O)
9–28
10 Migration RPG Language Elements
10–1
Migration RPG Language Elements
7 0
.
.
.
A+L−1
7 0
The address of a string specifies the first character of a string. The string
XYZ is shown in Figure 10–2. The address of the string would point at the
character X.
Figure 10–2 Address of a String
7 0
X A
Y A+1
Z A+2
10–2
Migration RPG Language Elements
The following code example depicts how character fields are defined within
an RPG program:
Example 10–1 Defining character fields
1 2 3 4 5
1234567890123456789012345678901234567890123456789012345678
*
00050ISALES AA 01 1 CJ
00060I 11 35 DESCR
00070I 36 40 CODE
.
.
.
00120C MOVE ’SNOJOB’ NODE 6
Lines 60 and 70 describe two input character fields. The first, DESCR,
is 25 characters long. The second, CODE, is 5 characters long. Line
120 depicts the creation and initialization of a character field within the
Calculation specifications. Here the character literal SNOJOB is being
moved into the 6-character field NODE.
10–3
Migration RPG Language Elements
15 0
31 0
10–4
Migration RPG Language Elements
The following code example depicts how binary fields are defined within an
RPG program:
Example 10–2 Defining binary fields
1 2 3 4 5
1234567890123456789012345678901234567890123456789012345678
*
00050IINVENTRYAA 01
00060I 01 060PARTNO
00070I B 07 080QTY
00080I B 09 122COST
10–5
Migration RPG Language Elements
7 4 3 0
31 32 A
33 0C A+1
1 2 3 4 5
1234567890123456789012345678901234567890123456789012345678
*
00050ILEDGER BB 10
00060I 01 10 CUSTID
00070I P 11 152INCOME
00080I P 16 222EXPENS
10–6
Migration RPG Language Elements
0 48 30 0 0 {[?
1 49 31 1 1 A
2 50 32 2 2 B
3 51 33 3 3 C
4 52 34 4 4 D
5 53 35 5 5 E
6 54 36 6 6 F
7 55 37 7 7 G
8 56 38 8 8 H
9 57 39 9 9 I
-0 125 7D } p ]:!
-1 74 4A J q
-2 75 4B K r
-3 76 4C L s
-4 77 4D M t
-5 78 4E N u
-6 79 4F O v
-7 80 50 P w
-8 81 51 Q x
-9 82 52 R y
The sign of a numeric field is stored with the least significant digit in an
overpunch format, meaning that the sign is combined with the last digit in
the field.
There are several variations of overpunch format. Alternate forms of
overpunch sign representation are accepted by RPG on input and the
standard trailing numeric sign representation is generated by default on
output. Output can also be defaulted to zoned-decimal representation
using the zone-decimal options in column 60 of the Control (Header)
Specifiation or column 44 of the Output Specifications.
10–7
Migration RPG Language Elements
7 0
1 A
2 A+1
3 A+2
7 0
1 A
2 A+1
L A+2
7 0
1 A
2 A+1
s A+2
10–8
Migration RPG Language Elements
Naming Convention
• The first character of a name must be one of the following:
— Uppercase letters A through Z
— An underscore ( _ )
— A dollar sign ( $ )
• The remaining characters of a name can be the uppercase letters A
through Z, the digits 0 through 9, an underscore ( _ ), or a dollar sign
( $ ).
• Names must be left-justified.
• Names cannot contain embedded blanks.
• RPG special words cannot be used as names.
• The maximum length of a name is six characters, except for a file
name, which can be up to eight characters long.
10–9
11 Operation Codes
11–1
Operation Codes
Chapter 15, Using Tables and Arrays, for information on using arrays
in arithmetic operations.
• No field in an arithmetic operation can be longer than 15 digits.
• RPG performs all arithmetic operations algebraically.
• The results of all arithmetic operations are signed. The sign of the
result of an arithmetic operation depends on the operation:
Addition:
— If factor 1 and factor 2 have like signs, the result field has the
same sign.
— If factor 1 and factor 2 have unlike signs, the result field uses the
sign of the factor with the largest absolute value.
Subtraction:
— Change the sign of factor 2 (positive to negative or negative to
positive) and use the same rules used for addition.
Multiplication:
— If factor 1 and factor 2 have like signs, the sign of the result field
is positive.
— If factor 1 and factor 2 have unlike signs, the sign of the result
field is negative.
Division:
— If factor 1 and factor 2 have like signs, the sign of the result field
is positive.
— If factor 1 and factor 2 have unlike signs, the sign of the result
field is negative.
— The sign of the remainder is the same as the sign of factor 1.
11–2
Operation Codes
11–3
Operation Codes
11–4
Operation Codes
11–5
Operation Codes
11–6
Operation Codes
11–7
Operation Codes
• The xx portion of the CASxx, IFxx, ANDxx, ORxx, DOUxx, and DOWxx
instructions identifies the type of comparison operation that is to take
place. The comparison operation can be:
— GT (Greater Than) - Comparison is true if factor 1 is greater than
factor 2.
— LT (Less Than) - Comparison is true if factor 1 is less than factor
2.
— GE (Greater Than or Equal) - Comparison is true if factor 1 is
greater than or equal to factor 2.
— LE (Less Than or Equal) - Comparison is true if factor 1 is less
than or equal to factor 2.
— EQ (Equal) - Comparison is true if factor 1 is equal to factor 2.
— NE (Not Equal) - Comparison is true if factor 1 is not equal to
factor 2.
— Blanks (Unconditional - CASxx operation only) - The CASxx
instruction allows for the unconditional execution of a CASxx
statement by leaving the comparison code blank. An unconditional
CASxx statement will always execute. Unconditional CASxx
statements are usually placed at the end of a case construct.
• A structured operation code, the statements following it, and its END
statement form a structured construct. Structured constructs have the
following characteristics:
— Structured constructs can be nested.
— When a structured construct completes execution or if a structured
construct is bypassed, execution of the program resumes at the
statement immediately following the structured construct’s END
statement.
— Structured constructs cannot be split between detail time
calculations, total time calculations, and subroutines. A structured
construct must begin and end within the same set of calculation
specifications.
— Branching into a structured construct may produce unpredictable
results.
— CASxx constructs can only contain CASxx statements.
11–8
Operation Codes
Description
The ADD operation allows two numeric fields to be added together.
Rules
All fields specified in an ADD operation must be numeric.
Conditional indicators (columns 7 - 17) are optional.
Factor 1 is optional. If present, factor 2 is added to factor 1 and the sum
is placed in the result field.
Factor 2 is required. If factor 1 is not present, factor 2 is added to the
result field and the sum is placed in the result field.
The contents of factor 1 and factor 2 are not affected by an ADD operation.
Resulting indicators (columns 54 - 59) are optional. They can be
used to indicate whether the contents of the result field are positive
(columns 54 - 55), negative (columns 56 - 57), or zero (columns 58 - 59)
after the ADD operation completes.
Operation
RPG aligns the operands according to their decimal points before
performing any arithmetic operation. Results of an arithmetic operation
are aligned on the decimal point in the result field, which can cause
truncation on both ends of a result. More information on arithmetic
operations is available earlier in this chapter in Section 11.1.
11–9
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C FLD1 ADD 1 FLD2
In this example, the constant 1 is added to FLD1 and the result is placed
in FLD2.
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C ADD 1 CNT
In this example, the constant 1 is added to the field CNT and the result is
placed in CNT.
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C N10 CASH ADD INTRST SUM
11–10
Operation Codes
Description
The ANDxx operation allows a more complex conditional operation to be
specified in DOUxx (Do Until), DOWxx (Do While), and IFxx operations.
Fields specified in the ANDxx operation are compared and return a true
or false condition to the program. The true/false condition is used by the
program to determine if the structured construct of which the ANDxx
operation is a part should be executed or bypassed.
Rules
The ANDxx operation can be used in conjunction with the DOUxx,
DOWxx, IFxx, and ORxx operations.
Control level entries (columns 7 - 8) for the ANDxx operation must be
consistent with the control level entry for the associated DOUxx, DOWxx,
or IFxx operation.
Conditional indicators (columns 9 - 17) are not permitted.
Factor 1 and factor 2 are both required. They can contain a literal,
field, array element, table element, or data structure element. The data
types of both fields must match, meaning that both fields must be either
alphameric or numeric.
The comparison carried out in an ANDxx operation follows standard RPG
comparison rules. These rules are discussed earlier in this chapter in
Section 11.4.
Resulting indicators (columns 54 - 59) are not allowed.
11–11
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C TRICK DOUEQ4
C STER ANDLTJOKE
.
.
.
C END
11–12
Operation Codes
Description
The BEGSR operation indicates the beginning of an internal subroutine.
Rules
The BEGSR operation must be the first specification in an internal
subroutine.
The entry of SR in columns 7 and 8 is optional. Conditional indicators are
not allowed.
Factor 1 contains the name of the subroutine. The name can be 1 to
6 characters long and must begin with an alphabetic character. Valid
characters in a subroutine name are A - Z, 0 - 9, $, and _ (underscore).
Each subroutine name within a program must be unique; it cannot
duplicate another subroutine name, a TAG label, a ENDSR label, a CALL
routine name, or a PLIST label.
Resulting indicators (columns 54 - 59) are not allowed.
See Section 11.6 earlier in this chapter for more information on coding and
executing internal subroutines.
Example 11–5 BEGSR Operation Code Usage
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
CSR SBGT BEGSR
.
.
.
CSR ENDSR
In this example, the BEGSR operation is used to define the internal RPG
subroutine SBGT. Note the use of the SR indicator in columns 7 - 8. Use
of this indicator is optional. Using it makes the subroutine section in an
RPG program easier to identify.
11–13
Operation Codes
Description
The BITOF operation sets the bits specified in the mask in factor 2 off (to
0) in the result field.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 must be blank.
Factor 2 can contain a literal bit mask or a single-character, alphameric
field which contains the bit mask used by the BITOF operation. A literal
bit mask identifies the bits as 0 through 7, with 0 as the leftmost bit. The
bit mask must be enclosed in single quotes. For example, to set bits 0, 4,
and 5 off, enter ’045’ in factor 2. A bit number cannot be specified more
than once in a mask.
If a field name is specified in factor 2, it must be a single-character,
alphameric field, table, or array element. The bits that are on in the field
name are set off in the result field. If a table or array element is specified,
each element must be a single-character, alphameric field. If factor 2 is
not a single character field or literal bit mask, a compilation error will
occur.
The result field should be a single-character, alphameric field, table,
or array element. Bit operations are only designed to work on single
character alphameric fields. The bits specified in factor 2 will be set off in
the result field. The remaining bits in the result field will be unaffected.
Resulting indicators (columns 54 - 59) are not allowed.
Example 11–6 BITOF Operation Code Usage
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C N66 BITOF’0125’ ESC 1
C N66 BITON’3467’ ESC
11–14
Operation Codes
This example demonstrates the use of the BITOF and BITON operations
to create the escape character (hex 1B). Note that these instructions will
only be executed if indicator 66 is off. The field ESC is being defined in the
Calculation specifications as a 1-character alphameric field (1 in column
51, blank in column 52).
11–15
Operation Codes
Description
The BITON operation sets the bits specified in the mask in factor 2 on (to
1) in the result field.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 must be blank.
Factor 2 can contain a literal bit mask or a single-character, alphameric
field which contains the bit mask used by the BITON operation. A literal
bit mask identifies the bits as 0 through 7, with 0 as the leftmost bit. The
bit mask must be enclosed in single quotes. For example, to set bits 2, 5,
and 6 on, enter ’265’ in factor 2. A bit number cannot be specified more
than once in a mask.
If a field name is specified in factor 2, it must be a single-character,
alphameric field, table, or array element. The bits that are on in the field
name are set on in the result field. If an array element is specified, each
element in the array must be a single-character field. If factor 2 is not a
single character field or literal bit mask, a compilation error will occur.
The result field should be a single-character, alphameric field, table,
or array element. Bit operations are only designed to work on single
character alphameric fields. The bits specified in factor 2 will be set on in
the result field. The remaining bits in the result field will be unaffected.
Resulting indicators (columns 54 - 59) are not allowed.
Example 11–7 BITON Operation Code Usage
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C BITON’3467’ ESC 1
C BITOF’0125’ ESC
This example demonstrates the use of the BITON and BITOF operations
to create the escape character (hex 1B).
11–16
Operation Codes
Description
The Compare and Branch operation allows a program to conditionally
branch to a TAG based on the results of the comparison of factor 1 and
factor 2.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 and factor 2 are both required. They can contain a literal,
figurative constant, field, array element, table element, or data structure
element. The data types of both fields must match, meaning that both
fields must be either alphameric or numeric.
The xx portion of the CABxx operation can be one of the following
instructions:
• GT (Greater Than) - Comparison is true if factor 1 is greater than
factor 2.
• LT (Less Than) - Comparison is true if factor 1 is less than factor 2.
• GE (Greater Than or Equal) - Comparison is true if factor 1 is greater
than or equal to factor 2.
• LE (Less Than or Equal) - Comparison is true if factor 1 is less than or
equal to factor 2.
• EQ (Equal) - Comparison is true if factor 1 is equal to factor 2.
• NE (Not Equal) - Comparison is true if factor 1 is not equal to factor 2.
• blank - If a TAG has been specified in the result field, a branch
operation is executed independent of the compare. If no entry is
present in the result field, the CAB operation functions like a compare.
Operation
The CABxx operation can be used to:
• Branch from any line to any line within the detail calculation section.
• Branch from detail calculations to total time calculations.
• Branch from any line to any line within total time calculations.
• Branch from a subroutine line to the detail calculations section.
• Branch from a subroutine line to the total time calculations section.
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C FLDA CABLEFLDB TGLE 040506
.
.
.
C TGLE TAG
The CABxx operation in this example will cause the program to branch
to the tag TGLE if FLDA is less than or equal to FLDB. Note the use of
optional resulting indicators. These indicators will be set based on the
results of the comparison carried out by the CABxx operation. In this
example, if FLDA contains 7 and FLDB contains 12, indicator 05 will be
turned on and the program will branch to the TGLE tag.
11–18
Operation Codes
Description
The CALL operation transfers control to the RPG subprogram or external
routine specified in factor 2. This operation code is used primarily to call
RPG subprograms.
Rules
Conditional indicators (columns 7 - 17) are optional.
The CALL operation transfers control to a subprogram much as the
BEGSR operation code transfers control to an internal subroutine. Factor
2 must contain an alphameric literal or a field defined by the EXTRN
operation code that names the subprogram. This can be a valid OpenVMS
program name. Factor 2 cannot be an array element or data field name.
The program specified in factor 2 can be written in any OpenVMS
programming language, including Migration RPG. When specifying a
program name which exceeds 8 characters, use the EXTRN operation code
to define a field which represents the program name.
The result field can contain the name of the parameter list associated
with a PLIST operation code. This enables the calling program to share
parameters with the subprogram. Individual parameters can also be
specified immediately following the CALL operation code using the PARM
operation code. Both the PLIST option and PARM statements can be used
together with the CALL operation code.
Factor 1, half adjust, and the resulting indicator in columns 54 and 55
must be blank. Any valid resulting indicator can be specified in columns
56 and 57 to be set on if the subprogram exits with an error status set.
Any valid resulting indicator can be specified in columns 58 and 59 to be
set on if the subprogram is a Migration RPG program and exits with the
LR indicator set.
Operation
While the CALL operation can call any type of subprogram or system
service, it is specifically designed to call Migration RPG subprograms and
is generally used for this purpose. It has been designed to make Migration
RPG compatible with advanced versions of RPG II.
11–19
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C CALL ’MAMMAL’ 23
C PARM FOX
C PARM BAT
C PARM WEASEL
C PARM WOLF
This example displays the use of the CALL and PARM operation codes.
The subprogram MAMMAL is called and passed the parameters FOX,
BAT, WEASEL and WOLF. MAMMAL can then manipulate these fields
and return their updated values to the calling program. After the
subprogram MAMMAL is processed, control returns to the next executable
statement following the last PARM statement. Indicator 23 will be set on
if MAMMAL should exit with an error status set.
11–20
Operation Codes
Description
The CASxx operation allows an internal subroutine to be conditionally
selected for execution.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 and factor 2 are both required in all CASxx operations except
when the xx portion of the CASxx operation code is blank. They can be
either field or literal data. Factor 1 and factor 2 must both contain either
alphameric or numeric data.
The result field is required. It must contain the name of a valid
subroutine. If the condition evaluated by the CASxx operation is true,
program control is passed to the subroutine. If the condition is false,
program execution continues with the next line.
The comparison carried out in a CASxx operation follows standard RPG
comparison rules. These rules are discussed earlier in this chapter in
Section 11.4.
The xx portion of the CASxx operation can be one of the following
instructions:
• GT (Greater Than) - Comparison is true if factor 1 is greater than
factor 2.
• LT (Less Than) - Comparison is true if factor 1 is less than factor 2.
• GE (Greater Than or Equal) - Comparison is true if factor 1 is greater
than or equal to factor 2.
• LE (Less Than or Equal) - Comparison is true if factor 1 is less than or
equal to factor 2.
11–21
Operation Codes
Operation
When a subroutine is called by a CASxx operation, control is returned to
the line following the END statement associated to the CASxx construct
when the subroutine completes execution.
Example 11–10 CASxx Operation Code Usage
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C HOME CASGTVISTOR WIN
C HOME CASLTVISTOR LOSS
C HOME CASEQVISTOR TIE
C END
11–22
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C SCORE CASLTAVERAG BAD
C SCORE CAS AVERAG UPDATE 04 05
C END
11–23
Operation Codes
Description
The CHAIN operation reads a record by key from a file during calculations
and makes the contents of the record available to the program. A CHAIN
operation can read records from a sequential, relative, or indexed file.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 is required. It contains the relative record number or key field to
be used to access the chained file. Data structure elements can be used to
specify non-contiguous keys.
Factor 2 is also required. It must contain the name of the file from which
the record is to be read. This file must be a chained or full-procedural file
(C or F in column 16 of the File Description specification) and must be
defined in the program’s File Description specifications.
The result field must be blank.
A resulting indicator in columns 58 - 59 is not allowed. A resulting
indicator in columns 54 - 55 is optional for chained files and required for
full-procedural files. This indicator serves as a record-not-found indicator
and will be turned on if the record requested is not found.
A resulting indicator in columns 56 - 57 is optional. If specified, it serves
as an error indicator, turning on if the record requested by the CHAIN
operation cannot be accessed. If this indicator is turned on, the record-not-
found indicator will also be turned on. The $STAT$ field will contain the
completion status of a CHAIN operation.
If a record-not-found or error indicator is not specified on a CHAIN
operation and the chain fails, the program will abort with an error.
Operation
If a chained file is conditioned by an external indicator (U1 - U8) in the
File Description specifications, all CHAIN operations associated to that file
should also be conditioned by the same indicator.
A record which is not found during a CHAIN operation cannot be updated.
However, it can be added.
11–24
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
H
00010FINP IP F 80 80 DISK
00020FOUT OC F 52 52R DISK
00030FRPT O F 80 80 PRINTER
00040IINP AA 02
00050I 1 50TAXNUM
00060I 1 52 RECORD
00070C*
00080C 02 TAXNUM CHAINOUT 99
00090C*
00100OOUT D 02 99
00110O RECORD 52
00120ORPT D 02
00130O RECORD 52
00140O 99 70 ’ADDED’
00150O N99 70 ’DUPLICATE’
This program scans a file for duplicate records. The CHAIN operation is
used to chain into the relative file OUT to determine if the record read
from the file INP is present in the OUT file. The field TAXNUM contains
the relative record number which is used to chain into the OUT file.
Note the use of indicator 99 as the record-not-found indicator in columns
54 - 55. If 99 is on after the CHAIN, the INP record is added to the OUT
file. If 99 is off after the CHAIN, the record already exists in the OUT file
and is reported as a duplicate in the RPT file.
11–25
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
F*
FIDXMST UC F 57 57R 5AI 1 DISK
.
.
.
C KEY CHAINIDXMST 9899
C 99 $STAT$ CASEQ’000181B0’LCKERR
C 99 CAS GENERR
C END
11–26
Operation Codes
Description
The COMP operation compares factor 1 and factor 2, setting resulting
indicators based upon the results of the comparison.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 and factor 2 are both required. They can contain a literal,
figurative constant, field, array element, table element, or data structure
element. The data types of both fields must match, meaning that both
fields must be either alphameric or numeric.
The result field must be blank.
At least one resulting indicator (columns 54 - 59) must be specified. These
indicators indicate the results of the comparison as follows:
• High - Columns 54 - 55
Factor 1 is greater than factor 2.
• Low - Columns 56 - 57
Factor 1 is less than factor 2.
• Equal - Columns 58 - 59
Factor 1 is equal to factor 2.
All resulting indicators specified in a COMP operation are set off before
the operation begins.
The comparison carried out in a COMP operation follows standard RPG
comparison rules. These rules are discussed earlier in this chapter in
Section 11.4.
If an alternate collating sequence has been specified, alphameric fields are
translated into the alternate collating sequence before being compared.
Alphameric and numeric fields cannot be compared against each other.
11–27
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C CODE COMP 24 11
In this example, the COMP operation is used to compare the field CODE
to the numeric literal 24. If CODE is equal to 24, indicator 11 will be
turned on.
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C CODE COMP 3 12 11
In this example, the COMP operation is used to compare the field CODE
to the numeric literal 3. If CODE is greater than 3, indicator 12 will be
turned on. If CODE is equal to 3, indicator 11 will be turned on.
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C CODE COMP KEY 1313
In this example, the COMP operation is used to compare the field CODE to
the field KEY. If CODE is less than or equal to the field KEY, the indicator
13 will be turned on.
Example 11–17 COMP Operation Code Usage - Greater than, Less than,
Equal
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C 01 CODE COMP CUP 203040
In this example, the COMP operation is used to compare the field CODE
to the field CUP. If CODE is greater than CUP, indicator 20 is turned on.
If CODE is less than CUP, indicator 30 is turned on. If CODE is equal to
CUP, indicator 40 is turned on. Note that indicator 01 must be on before
this command will be executed.
11–28
Operation Codes
Description
The DEBUG operation code is provided to assist the programmer in
debugging RPG programs. It is especially useful as Migration RPG does
not interface with the OpenVMS Symbolic Debugger.
Rules
Control Specification Entry
To turn the debugging option on in an RPG program, a 1 must be coded in
column 15 of the Control (H) specification. If column 15 is blank, all debug
files and debug operation codes are ignored by the compiler.
File Description Specification Entries
An output file to which the DEBUG operation will write must be defined
in the File Description specifications. A program can contain multiple
DEBUG files, although one is usually sufficient.
A debug file must be an output file. The device type can be PRINT,
PRINTER or DISK. A debug file cannot be a WORKSTN file.
Calculation Specification Entries
Conditional indicators (columns 7 - 17) are optional.
Factor 1 is optional. It can contain a literal, field name, array, array
element, table element, or data structure element. The contents of factor 1
are output to the debug file. Factor 1 is most commonly used to output a
literal which can serve as a tag to indicate the section of code the program
is processing or which serves as a label to identify the contents of the
result field.
Factor 2 is required. It must contain the name of the debug file as it
appears in columns 7 - 14 of the File Description specification. The file
must be an output file.
The result field is optional. It can contain a field name, array, array
element, table element, or data structure element. The contents of the
result field are output to the debug file.
Resulting indicators (columns 54 - 59) are not allowed.
11–29
Operation Codes
Operation
A DEBUG operation always outputs all indicators which are set at the
time the DEBUG operation code is executed.
DEBUG statements can be left in a program and turned on and off by
placing a 1 in column 15 of the Control specification. When turned off,
DEBUG files and statements are ignored by the compiler and are not
included in the executable image. To turn debug on, a 1 must be placed in
column 15 of the Control specification and the program must be recompiled
and relinked.
The DEBUG operation code is useful for checking the contents of fields
and tracking a program through its cycle.
After debugging a program with the DEBUG operation code, don’t forget
to turn debug off by blanking out column 15 in the Control specification
and recompiling and relinking the program. Otherwise, the program will
continue to produce DEBUG files each time it is run.
11–30
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
*
* The 1 in column 15 of the Control specification
* indicates that DEBUG is to be turned on in this
* program.
H 1
.
.
.
F* This File specification defines the DEBUG file.
F* In this case the file is defined as a PRINTER
F* file. A DEBUG file can also be defined as a
F* DISK file. DEBUG files are always defined as
F* output files.
F*
FERROR O 80 PRINTER
.
.
.
C* This DEBUG operation will print the literal
C* ’START’, the contents of the field NAME, and
C* all indicators currently set in the DEBUG file
C* ERROR.
C*
C ’Start’ DEBUGERROR NAME
.
.
.
C* The first DEBUG operation in this section will
C* output the literal ’ACCNT’ and the contents of
C* the field ACCNT and all indicators currently
C* set to the DEBUG file ERROR. The second DEBUG
C* operation will output the label ’END’ and all
C* of the indicators currently set to the DEBUG
C* file ERROR.
C*
C ’ACCNT’ DEBUGERROR ACCNT
C ’End’ DEBUGERROR
11–31
Operation Codes
Description
The Field Definition operation allows the programmer to define data fields
based on the attributes of other fields in the program.
Rules
Conditional indicators in columns 7 - 8 are optional.
Conditional indicators in columns 9 - 17 are not allowed.
Factor 1 is required. It must always contain the entry *LIKE.
Factor 2 is required. It must contain the name of the field that provides
the attributes for the field being defined. Factor 2 cannot be a literal or
data structure name. Factor 2 can be a field name, array, array element,
table, or data structure element.
The result field is required. It must contain the name of the field to be
defined. It cannot contain the name of an array, array element, table, or
data structure.
Entries in columns 49 - 51 (field length) are optional. They can be used
to make the field length of the entry in the result field longer or shorter
than the field length of the entry in factor 2. A plus (+) coded in column
49 indicates that the length of the new field will be increased. A minus
(-) coded in column 49 indicates that the length of the new field will be
decreased. Entries in columns 50 - 51 indicate how much to increase or
decrease the field length. If columns 49 - 51 are left blank, the field length
will be the same as that of the entry in factor 2.
Increasing a numeric field beyond 15 characters or an alphameric field
beyond 256 characters will generate a compile time error. Decreasing a
field to less than one or changing the number of decimal places defined for
it will also generate a compile time error.
The number of decimal positions in a numeric field defined by a DEFN
operation cannot be changed. The new field will have the same number of
decimal positions as the entry in factor 2.
Resulting indicators (columns 54 - 59) are not allowed.
11–32
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C *LIKE DEFN TONSIL THROAT
C *LIKE DEFN TEETH MOUTH +08
C *LIKE DEFN TOES FEET -02
In this example, the DEFN operation is being used to define three fields.
The first field, THROAT, will be defined with the same characteristics as
the field TONSIL. The second field, MOUTH, will have the same data type
as the field TEETH, but will be 8 characters longer in length. The third
field, FEET, will have the same data type as the field TOES, but will be 2
characters shorter in length.
11–33
Operation Codes
Description
The Divide operation allows two numeric fields to be divided, with the
quotient being placed in the result field.
Rules
All fields specified in an DIV operation must be numeric.
Conditional indicators (columns 7 - 17) are optional.
Factor 1 is optional. If it is 0, the result of the DIV operation will be 0.
The contents of factor 1 are not affected by the DIV operation.
Factor 2 is required. It cannot be 0. If factor 2 is 0, the program will abort
with a divide-by-zero error. If factor 1 is present, it is divided by factor
2 and the quotient is placed in the result field. If factor 1 is not present,
the contents of the result field are divided by factor 2 and replaced in the
result field. The contents of factor 2 are not affected by the DIV operation.
The result field is required. It will contain the quotient produced by the
DIV operation.
Resulting indicators (columns 54 - 59) are optional. They can be used to
indicate whether the contents of the result field after the DIV operation
are positive (columns 54 - 55), negative (columns 56 - 57), or zero (columns
58 - 59).
Operation
Any remainder resulting from the DIV operation will be lost unless a MVR
(Move Remainder) operation immediately follows the DIV operation. See
Section 11.12.38 for more information on the MVR operation.
Half adjust (column 53 of the Calculation specification) cannot be specified
for a DIV operation immediately followed by an MVR operation.
RPG aligns the operands according to their decimal points before
performing any arithmetic operation. Results of an arithmetic operation
are aligned on the decimal point in the result field, which can cause
truncation on both ends of a result. More information on arithmetic
operations is available earlier in this chapter in Section 11.1.
11–34
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C 03 DISCNT DIV STKPRC PERCNT 22H
In this example, the DIV operation divides the field STKPRC into DISCNT
and places the product in PERCNT. Note that PERCNT is being defined in
the Calculation specifications as a numeric field with two decimal places.
Half-adjust has been specified in column 53 to round the results of the
DIV operation. This operation will only be executed if indicator 03 is on.
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
CL1 DIV CARSTK CARPCT 22H
In this example, the field CARPCT will be divided by CARSTK and the
result placed in CARPCT. Note that this operation only takes place during
L1 control break processing.
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
CL3 RIP DIV OFF SCAM 52
CL3 MVR PORK 42
In this example, the field RIP will be divided by OFF, with the result being
placed in SCAM. Any remainder from this DIV operation will be placed in
the field PORK by the MVR operation. Note that this operation only takes
place during L3 control break processing.
11–35
Operation Codes
Description
The DO operation allows a set of operations to be performed a fixed
number of times. The DO operation code, the operation codes which follow
it, and the associated END operation code constitute a DO loop. The DO
operation code is considered a structured operation code.
Rules
Conditional indicators (columns 7 - 17) are optional. They can be specified
on both the DO statement and the associated END statement. Conditional
indicators on a DO operation are processed as follows:
• If the conditional indicators on the DO operation are not satisfied,
control passes to the next executable statement following the
associated END statement.
• If conditional indicators are satisfied on the DO operation, processing
of the DO loop begins. Conditional indicators on a DO operation are
checked once at the beginning of the DO loop, meaning that once
conditions have been satisfied to begin execution of the DO loop, they
are not checked again as the DO loop executes.
• When execution of the DO loop operations reaches the associated END
statement, conditional indicators on the END statement are checked.
If the conditional indicators are not satisfied, control passes out of
the DO loop to the next executable instruction. If the conditional
indicators are satisfied, and the index value is less than the limit
value, control passes back to the beginning of the DO loop.
11–36
Operation Codes
Operation
A DO loop is executed as follows:
1 Conditional indicators (columns 7 - 17) on the DO operation are
checked. If satisfied, the DO operation is performed. If not satisfied,
control is passed to the first executable statement following the
associated END statement.
2 The starting value in factor 1 is moved to the index value in the result
field.
3 If the index value is greater than the limit value in factor 2, control is
passed to the first executable statement following the associated END
statement, terminating the DO loop. Otherwise, execution of the DO
loop proceeds. The comparison carried out in a DO operation follows
standard RPG comparison rules. These rules are discussed earlier in
this chapter in Section 11.4.
4 Operations within the DO loop are executed.
5 When the associated END statement is reached, its conditional
indicators are checked. If the conditional indicators are not satisfied,
control passes to the next executable statement following the END
statement, terminating the DO loop.
6 If conditional indicators on the END statement are satisfied, the END
operation is performed. The increment value in factor 2 of the END
operation is added to the index value of the DO operation. Control
then passes back to step 3 in the DO loop. Note that steps 1 and 2 are
not performed again, meaning that conditional indicators on the DO
operation are not tested again.
11–37
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C 22 STRT4 DO LIM4
C MULT STRT4 SUBTOT 40
C SETON 04
C EXCPT
C SETOF 04
C 23 END 4
11–38
Operation Codes
Description
The Do Until operation performs a set of instructions until the condition
specified by the xx portion of the instruction is met. The DOUxx operation
code, the operation codes which follow it, and the associated END
operation code constitute a DOUxx loop. The DOUxx operation code is
considered a structured operation code.
Rules
Conditional indicators (columns 7 - 17) are optional. They can be specified
on both the DOUxx statement and the associated END statement.
Conditional indicators on a DOUxx operation are processed as follows:
• If the conditional indicators on the DOUxx operation are not satisfied,
control passes to the next executable statement following the
associated END statement. If conditional indicators are satisfied
on the DOUxx operation, processing of the DOUxx loop begins.
Conditional indicators on a DOUxx operation are checked once at
the beginning of the DOUxx loop, meaning that once conditions have
been satisfied to begin execution of the DOUxx loop, they are not
checked again as the DOUxx loop executes.
• When execution of the DOUxx loop operations reaches the associated
END statement, conditional indicators on the END statement are
checked. If the conditional indicators are not satisfied, control passes
out of the DOUxx loop to the next executable instruction. If the
conditional indicators are satisfied, the comparison test specified in
factor 1 and factor 2 of the DOUxx operation is carried out. If the
comparison is false, control passes back to the beginning of the DOUxx
loop. If the comparison is true, control passes out of the DOUxx loop
to the next executable instruction.
11–39
Operation Codes
Operation
A DOUxx loop is executed as follows:
1 Conditional indicators (columns 7 - 17) on the DOUxx operation
are checked. If satisfied, the DOUxx construct is performed. If not
satisfied, control is passed to the first executable statement following
the associated END statement.
2 Operations within the DOUxx loop are executed.
3 When the associated END statement is reached, its conditional
indicators are checked. If the conditional indicators are not satisfied,
control passes to the next executable statement following the END
statement, terminating the DOUxx loop. If conditional indicators
on the END statement are satisfied, the contents of the factor 1
and factor 2 fields specified in the DOUxx operation are compared.
(Note this comparison takes place at the end of the DOUxx loop. If
the conditions specified by the DOUxx operation and any associated
ANDxx and ORxx operations are true, the DOUxx loop is terminated
11–40
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C INCOME DOUGTTAXES
C ADD 1 WEEK
C INCOME ADD PAYCHK INCOME
C END
In this example, the DOUxx loop will be executed until the field INCOME
is greater than the field TAXES.
11–41
Operation Codes
Description
The Do While operation performs a set of instructions until the condition
specified by the xx portion of the instruction is no longer true. The DOWxx
operation code, the operation codes which follow it, and the associated
END operation code constitute a DOWxx loop. The DOWxx operation code
is considered a structured operation code.
Rules
Conditional indicators (columns 7 - 17) are optional. They can be specified
on both the DOWxx statement and the associated END statement.
Conditional indicators on a DOWxx operation are processed as follows:
• If the conditional indicators on the DOWxx operation are not satisfied,
control passes to the next executable statement following the
associated END statement. If conditional indicators are satisfied
on the DOWxx operation, processing of the DOWxx loop begins.
Conditional indicators on a DOWxx operation are checked once at
the beginning of the DOWxx loop, meaning that once conditions have
been satisfied to begin execution of the DOWxx loop, they are not
checked again as the DOWxx loop executes.
• The relation between factor 1 and factor 2 on the DOWxx operation
is checked. If the relation is true, execution of the DOWxx construct
proceeds. If the relation is false, the DOWxx loop is terminated
and control is passed to the next executable statement following the
associated END statement.
• When execution of the DOWxx loop operations reaches the associated
END statement, conditional indicators on the END statement are
checked. If the conditional indicators are not satisfied, control
passes out of the DOWxx loop to the next executable instruction.
11–42
Operation Codes
Operation
A DOWxx loop is executed as follows:
1 Conditional indicators (columns 7 - 17) on the DOWxx operation
are checked. If satisfied, the DOWxx operation is performed. If not
satisfied, control is passed to the first executable statement following
the associated END statement.
2 The contents of factor 1 and factor 2 are compared. As long as the
conditions specified by the DOWxx operation and any associated
ANDxx and ORxx operations are true, the DOWxx loop will be
executed. If the comparison operations are false, control is passed
to the next executable statement following the associated END
statement.
3 Operations within the DOWxx loop are executed.
11–43
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C N10 PRINC DOWLTLOAN
C ADD 1 MONTHS
C PAYMNT SUB INTRST PRINC
C END
In this example, the DOWxx loop will not execute if indicator 10 is on. If
indicator 10 is off, the DOWxx loop will execute as long as the value of
PRINC is less than the value of LOAN.
11–44
Operation Codes
Description
The ELSE operation can be paired with an IFxx operation. It allows the
program to execute a set of instructions if the IFxx operation conditions
are not met.
Rules
An ELSE operation must appear within the bounds of an IFxx/END
construct. Only one ELSE operation can be paired with an IFxx operation.
Conditional indicators in columns 7 - 8 are optional. If used, they must
match the conditional indicator appearing in the associated IFxx and END
operations.
Conditional indicators in columns 9 - 17 are not allowed.
Factor 1, factor 2, and the result field must be blank.
Resulting indicators (columns 54 - 59) are not allowed.
Operation
In an IFxx/ELSE/END construct, the operations bound by the ELSE
statement and the associated END statement will be performed if the IFxx
condition is not true. If the IFxx condition is true, the instructions bound
by the IFxx statement and the ELSE statement will be performed and
the statements bound by the ELSE statement and the associated END
statement will be skipped.
11–45
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C GUN IFEQ LOADED
C EXSR SHOOT
C ELSE
C EXSR LOAD
C END
11–46
Operation Codes
Description
The END operation is used to specify the end of a CASxx, DO, DOUxx,
DOWxx, or IFxx/ELSE construct. END statements are always associated
with one of these structured operation codes.
Rules
Conditional indicators in columns 7 - 8 are optional on all END operations.
If these indicators are specified, they must match the conditional indicator
specified on the structured operation code associated with the END
statement.
Conditional indicators in columns 9 - 17 are not permitted on END
statements associated with CASxx and IFxx/ELSE operations.
Conditional indicators in columns 9 - 17 are optional in END statements
which are associated to the DO, DOUxx, and DOWxx operations. Sections
11.12.14, 11.12.15, and 11.12.16 describe these operation codes and the use
of conditional indicators on their associated END statements.
Factor 1, factor 2, and the result field must all be blank on all END
operations with the exception of the END operation associated with a DO
operation. An END operation associated with a DO operation can have an
optional entry in factor 2. See Section 11.12.14 for more information on
the END operation associated with the DO operation.
11–47
Operation Codes
11–48
Operation Codes
Description
The End Subroutine operation defines the end of an internal RPG
subroutine.
Rules
The ENDSR statement must be the last statement in a subroutine.
The entry of SR in columns 7 and 8 is optional. Conditional indicators are
not allowed.
Conditional indicators in columns 9 - 17 are not allowed.
An entry in factor 1 is optional. Factor 1 can contain a unique label
which can be used by GOTO and CABxx operations within the subroutine.
Branching to a label or TAG within a subroutine from outside of the
subroutine is not permitted.
If the subroutine is an INFSR subroutine, an entry in factor 2 is optional.
Otherwise, factor 2 must be blank. See the Migration RPG Screen Format
Reference Manual for information on the coding and execution of an INFSR
subroutine.
Resulting indicators (columns 54 - 59) are not allowed.
Operation
The ENDSR operation signifies the end of an internal RPG subroutine.
When it is processed, program control is returned to the first executable
statement following the EXSR or CASxx operation which called the
subroutine. The only exception to this rule is when the subroutine in
question is an INFSR (exception) subroutine.
See Section 11.6 earlier in this chapter for more information on coding and
executing internal subroutines.
11–49
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
CSR COOLER BEGSR
.
.
.
CSR CHIPS CABEQ0 POP
.
.
.
CSR POP ENDSR
In this example, the ENDSR operation signifies the end of the internal
RPG subroutine COOLER. Note the use of the label POP on the ENDSR
statement. If the condition checked by the CABxx operation within the
subroutine COOLER is true, control will branch to the label POP on the
ENDSR statement.
11–50
Operation Codes
Description
The EXCPT operation allows records to be output during detail time or
total time calculations or a screen to be displayed to a WORKSTN device.
Rules
On the Calculation specification:
• Conditional indicators (columns 7 - 17) are optional.
• Factor 1 must be blank.
• Factor 2 is optional. It can be used to specify a unique 1 - 6 character
name which is associated to the exception records in the Output
specifications.
• The result field must be blank.
• Resulting indicators (columns 54 - 59) are not allowed.
Operation
If the exception name is blank in factor 2 of the EXCPT operation,
exception output records with a blank name in columns 32 - 37 that
satisfy the conditional indicators in columns 23 - 31 will be output.
If an exception name is declared in factor 2 of the EXCPT operation,
exception output records with a matching name in columns 32 - 37 that
satisfy the conditional indicators in columns 23 - 31 will be output.
11–51
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
FFIRDAT O 128 DISK
FREPORT O 80 PRINTER
.
.
.
C* The following EXCPT operation is unlabeled. All
C* exception output records which do not have a label
C* in columns 32 - 37 will be processed by this
C* operation.
C*
C EXCPT
C*
C* The following EXCPT operation will only be
C* executed if indicator 10 is on. It will process
C* all exception output records with the label REPORT
C* in columns 32 - 37.
C*
C 10 EXCPTREPORT
C*
C* The following EXCPT operation will only be
C* executed if indicators 10 and 20 are on and
C* indicator 30 is off. It will process all
C* exception output records with the label DATA
C* in columns 32 - 37.
C*
C 10 20N30 EXCPTDATA
.
.
.
O* The following record will be output when the
O* EXCPT operation labeled DATA is executed.
O*
OFIRDAT E DATA
O LOCTN 10
O DAMAGE 20
*
OLST H 1P
O 40 ’FIRE REPORT’
*
O* The following record will be output when
O* the unlabeled EXCPT operation is executed.
O*
O E
O LOCTN 20
O DAMAGE 60
*
O* The following record will be output when
O* the unlabeled EXCPT operation is executed
O* and indicator 22 is on.
O*
O E 22
O CALTIM 10
O RSPTIM 20
11–52
Operation Codes
This example demonstrates the use of the EXCPT operation to output data
to a disk file and a report during calculation processing.
11–53
Operation Codes
Description
The EXIT operation allows an RPG program to call an external subroutine.
In Migration RPG programs, the CALL operation code can be used to
accomplish the same function. The EXIT operation code is retained by
Migration RPG to maintain compatibility with other versions of RPG and
to support the MSI-supplied subroutines SUBR01, SUBR21, and SUBR23.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 must be blank.
Factor 2 is required. It must contain the name of the external subroutine
which is to be called by the EXIT operation. If the subroutine is not one
of the MSI-supplied subroutines (SUBR01, SUBR21, or SUBR23), then the
subroutine must be linked to the RPG program.
The result field must be blank.
Resulting indicators (columns 54 - 59) are not allowed.
Operation
RLABL statements can be associated to an EXIT operation. The RLABL
statements must immediately follow the EXIT operation.
An EXIT operation functions much like a CALL operation in that it passes
program control to an external subroutine or subprogram. When the
external routine has completed execution, it returns control to the first
executable statement following the EXIT/RLABL construct.
11–54
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C EXIT SUBR23
C RLABL MIC
C RLABL DATAST
C RLABL LEVEL
C RLABL RCODE 10
This example demonstrates the use of the EXIT operation code to call the
MSI-supplied message member subroutine SUBR23.
11–55
Operation Codes
Description
The Execute Subroutine operation causes program control to be passed
to an internal RPG subroutine. When the subroutine has completed
execution, control is returned to the first executable statement following
the EXSR statement.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 must be blank.
Factor 2 is required. It must contain the name of the subroutine which
is being called. The program must also contain a BEGSR operation code
which contains the subroutine name in factor 1.
The result field must be blank.
Resulting indicators (columns 54 - 59) are not allowed.
See Section 11.6 earlier in this chapter for more information on coding and
executing internal subroutines.
Example 11–31 EXSR operation code Usage
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C N10 EXSR MOUNTN
.
.
.
CSR MOUNTN BEGSR
.
.
.
CSR ENDSR
This example demonstrates the use of the EXSR operation code to call the
internal RPG subroutine MOUNTN. Note that the EXSR operation will
only be executed if indicator 10 is off.
11–56
Operation Codes
Description
The EXTRN operation is used to define program names exceeding eight (8)
characters in length for the CALL and FREE operation codes.
Rules
Factor 1 and factor 2 are required entries for this operation code.
Conditional indicator entries (columns 9 - 17) are not permitted.
Factor 1 is used to name the field Migration RPG initializes, using the
value specified in factor 2. Factor 1 of the EXTRN operation is defined as
an alphameric field. This field can only be used with the CALL and FREE
operation codes and cannot be defined elsewhere in the program.
Factor 2 is used to name the external constant. A maximum of 31
characters can be used to name the constant. The constant must be
enclosed in apostrophes. The constant can be a valid OpenVMS program
name.
Operation
The EXTRN operation initializes the value of an alphameric field to a
link-time constant. It is used to assign a program name exceeding eight
(8) characters in length to a field name which can be used with the CALL
and FREE operation codes.
11–57
Operation Codes
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890
C* This example depicts the use of the EXTRN operation
C* code to define the program BOEING_747_JUMBO. The
C* program FLY can then be referenced as a subprogram
C* using the CALL and FREE operation codes.
*
C FLY EXTRN’BOEING_747_JUMBO’
.
.
.
C CALL FLY
.
.
.
C FREE FLY
11–58
Operation Codes
Description
The FORCE operation allows selection of the next file from which a record
is read during multi-file processing.
Rules
Conditional indicators in columns 7 - 8 are not permitted.
Conditional indicators in columns 9 - 17 are optional.
Factor 1 must be blank.
Factor 2 must contain the name of the file against which the FORCE
operation is to be executed against. The file name must match a name
specified in columns 7 - 14 of the File Description specifications of an input
or update file.
The result field must be blank.
Resulting indicators (columns 54 - 59) are not allowed.
Operation
The FORCE operation can be used for primary or secondary input and
update files. The FORCE operation cannot be used to read records from
WORKSTN or KEYBORD files.
When a FORCE operation is executed, it identifies the file from which the
next record will be read. The read is performed at the beginning of the
next program cycle. If more than one FORCE operation is executed during
the same program cycle, all but the last are ignored.
Although FORCE operations override normal multi-file processing, they
cannot override the first record selected by the program. Input of the first
record occurs in the first cycle before the first pass through calculations.
If a FORCE operation is issued for a file that is at its end-of-file, the file is
not selected for processing. In this case, normal multi-file processing logic
selects the next record.
A FORCE operation bypasses matching record processing.
11–59
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
F*
FINNMST IP 20 DISK
FPARTS IS 20 DISK
.
.
.
C 01 FORCEPARTS
11–60
Operation Codes
Description
The FREE operation is used to remove an RPG subprogram from the
active list and ensure that subprogram initialization (first cycle processing)
takes place the next time the subprogram is called.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 must be blank.
Factor 2 is required. It must contain an alphameric literal or a field
defined by the EXTRN operation code that names the subprogram. This
can be a valid OpenVMS program name. Factor 2 cannot be an array
element or data field name. The program specified in factor 2 must be a
Migration RPG program. Submitting a non-Migration RPG program to the
FREE operation code will produce unpredictable results. When specifying
a program name which exceeds 8 characters, use the EXTRN operation
code to define a field which represents the program name.
The result field must be blank.
An error indicator can be specified in columns 56 and 57. The error
indicator will be turned on if the FREE operation is submitted to a
subprogram which has never been called or which was already freed
in a previous operation.
Resulting indicators in columns 54 - 55 and 58 - 59 are not allowed.
Operation
When a Migration RPG subprogram is called for the first time, normal
program initialization, such as file opens and field initialization, takes
place. After that, as long as the subprogram is not terminated normally
(LR indicator on) or abnormally (halt indicator on or error), each time the
program is called, it resumes operations where it left off at the previous
exit, very much like an internal subroutine. Thus, program initialization
is skipped during each additional call after the first one as long as the
subprogram has not been ended and the FREE operation code has not been
exercised against it. The FREE operation code provides the programmer
with another method to place a subprogram back into its initial starting
state.
11–61
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C* This example depicts the use of the FREE operation code
C* to reinitialize the program SKI.
*
C CALL SKI
.
.
.
C FREE SKI
11–62
Operation Codes
Description
The GOTO operation allows a program to pass control to a label defined by
a TAG or ENDSR operation, skipping all intervening instructions.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 must be blank.
Factor 2 is required. It must contain the label of the TAG or ENDSR
operation to which the program is to branch. A label can be 1 - 6
characters long and must begin with an alpha character.
The result field must be blank.
Resulting indicators (columns 54 - 59) are not allowed.
Operation
Branching using the GOTO operation must comply with the following
conditions:
• A GOTO operation can branch from any point in the detail calculations
section to any TAG in the detail calculations section.
• A GOTO operation can branch from any point in the total time
calculations section to any TAG in the total time calculations section
with the exception of last record calculations (LR in columns 7 - 8 of
the Calculation specification).
• A GOTO operation can branch to any TAG or ENDSR statement
within the confines of a subroutine.
• A GOTO operation cannot branch from the detail calculation section to
the total time calculation section, or vice versa.
• A GOTO operation cannot branch from outside a subroutine to a TAG
or ENDSR within a subroutine, or vice versa.
• A GOTO operation cannot branch from outside the last record
calculations section to within the last record calculations section,
or vice versa.
11–63
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C LOOP TAG
.
.
.
C 10N12 GOTO LOOP
11–64
Operation Codes
Description
The IFxx operation allows a set of instructions to be performed based on
whether the condition in the xx portion of the instruction is true. IFxx
operations can be combined with ANDxx and ORxx operations to make the
condition more complex. IFxx operations can also be paired with the ELSE
operation to allow an additional set of instructions to be executed should
the IFxx condition be false. The IFxx operation is always paired with an
END operation and is considered a structured operation code.
Rules
Conditional indicators in columns 7 - 8 are optional. If specified, the same
indicator must be used on the IFxx operation, optional ELSE operation,
and associated END operation.
Conditional indicators in columns 9 - 17 are optional on the IFxx
statement. They are not allowed on associated ELSE and END
statements. Conditional indicators on the IFxx operation control whether
the entire IFxx construct is executed or skipped. The complete operation
of an IFxx construct is detailed later in this section.
Factor 1 and factor 2 are both required. They can contain a literal,
field, array element, table element, or data structure element. The data
types of both fields must match, meaning that both fields must be either
alphameric or numeric. The comparison carried out in an IFxx operation
follows standard RPG comparison rules. These rules are discussed earlier
in this chapter in Section 11.4.
The result field must be blank.
Resulting indicators (columns 54 - 59) are not allowed.
11–65
Operation Codes
Operation
An IFxx operation is processed as follows:
• If present, the conditional indicators in columns 9 - 17 are checked. If
the conditions are met, processing continues with the IFxx operation.
If the conditions are not met, program control is passed to the first
executable instruction following the associated END statement.
• The comparison operation specified by the xx of the IFxx operation
and any associated ANDxx and ORxx operations are carried out. The
following actions will occur based on the results of the comparisons
and the structure of the IFxx construct:
— If the comparison operations are true, then the statements
following the IFxx operation will be executed. Execution
will continue until an associated ELSE or END statement is
encountered. If the statement encountered is an ELSE operation,
control will pass to the first executable instruction following the
associated END statement.
— If the comparison operations are false and there is no ELSE
operation associated with the IFxx operation, control will be
passed to the first executable statement following the associated
END statement.
— If the comparison operations are false and there is an ELSE
operation associated with the IFxx operation, control will be
passed to the first executable statement following the associated
ELSE statement.
11–66
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C AIR IFGT PLANE
C Z-ADD1 RCODE
C Z-ADDTEST MIC 40
C Z-ADD1 LEVEL 10
C END
C*
C TRAIN IFLE TRACK
C EXSR PF
C Z-ADD2 XX 141011
C ELSE
C EXCPTLAST
C EXCPTDETAIL
C END
11–67
Operation Codes
Description
The KEYnn operation pauses a program during calculations and allows
the user to enter data from their terminal.
Rules
To use the KEYnn operation, a KEYBORD device must be specified in the
File Description specifications.
KEYnn operations are always directed at the terminal which invoked the
program.
KEYnn operations should not be specified in programs that are run as
batch jobs.
Conditional indicators (columns 7 - 17) are optional.
Factor 1 is optional. It can contain a literal, field, table, array, or data
structure element. The contents of factor 1 will be displayed when the
KEYnn operation is executed. If factor 1 is not specified, a message
member code must be specified with the KEYnn operation code.
The nn portion of the KEYnn operation code can be blank or can specify
a message member number from the User Level 1 message member file
(RPGUSRLV1). If the message member corresponding to the message
number in the KEYnn operation code is found, the message is displayed.
If the message member file is not present or no entry exists which
corresponds to the message number specified, nothing is displayed. If
an entry is made in factor 1 of the KEYnn operation, the message number
is ignored. If no entry is made in factor 1, the message number is required.
See the Migration RPG User’s Guide for more information on creating and
referencing message member files.
Factor 2 must be blank.
The result field is required. It must contain the name of the field which is
to accept the data keyed in by the user. The result field can be a field or a
table, array, or data structure element.
Resulting indicators are optional. They can be used to evaluate the
contents of the result field after the user has entered data. The possible
results of the evaluation are:
11–68
Operation Codes
Operation
The KEYnn operation pauses the program and accepts input from the
user. The input is placed in the field specified in the result field of the
KEYnn statement. A KEYnn operation is terminated by pressing one of
the following keys:
• Return or Enter - For a numeric field, enters the field as a positive
number. For an alphameric field, simply enters the field.
• PF1 + Enter - For a numeric field, enters the field as a negative number.
Not valid for alphameric fields.
• PF4 - For a numeric field, enters the field as a positive number. For an
alphameric field, simply enters the field.
When a field is not completely filled by the user, numeric fields are right-
justified and zero-filled while alphameric fields are padded to the left with
blanks.
The user has the following options when responding to a KEYnn operation:
• Data can be entered. If it is, it replaces the contents of the result field.
• A field exit key can be pressed without entering any data. If it is, the
result field is initialized to blanks or zeros, depending upon whether it
is an alphameric or numeric field.
• The DUP key ( PF3 ) can be entered. If it is, the data currently
residing in the result field is not affected by the KEYnn operation.
11–69
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
*
FKEYIN IP F 70 70 KEYBORD
.
.
.
C ’Name’ KEY NAME 10
C 10 KEY12 SEX
C 10 AUTO KEY CAR
In this example, the KEYnn operation is used to prompt the user to enter
information from the terminal while the program is executing. Note the
File Description specification for a KEYBORD file. A KEYBORD file must
be defined in the File Description specifications in order to use the KEYnn
operation.
The program will pause and display the prompt ’Name’ when it executes
the first KEYnn operation in the example. Any input entered by the user
will be placed in the NAME field. Note the use of indicator 10 in columns
58 - 59. If an entry is made in the NAME field, indicator 10 will turn
on. If no entry is made, indicator 10 will be turned off. The following two
KEYnn operations will only execute if indicator 10 is on.
The second KEYnn operation will display message number 12 from the
User Level 1 message member file as a prompt. It will accept input into
the SEX field.
The third KEYnn operation will display the contents of the AUTO field as
a prompt. It will accept input into the CAR field.
11–70
Operation Codes
Array LOKUP
Table LOKUP
Description
The LOKUP operation searches for an entry in a table or array.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 is required. It must contain a literal, field, array element, data
structure element, or table name. Factor 1 serves as the search element in
a LOKUP operation. If a table name is specified in factor 1, it refers to the
last element selected by a LOKUP operation, not the entire table.
Factor 2 is required. It must contain the name of the table or array on
which the LOKUP operation is to be performed.
The result field must be blank in an array LOKUP operation. It is optional
in a table LOKUP operation. In a table LOKUP operation, the result field
can contain the name of a related table.
Resulting indicators are required in a LOKUP operation. At least one,
but no more than two, resulting indicators can be specified. Resulting
indicators specify the type of search to be made and indicate the results of
the search.
The resulting indicators function as follows:
• Greater than search
In this case, an indicator is only specified in columns 54 - 55 (high).
The LOKUP operation searches for the first element in the table or
array that is greater than the search element specified in factor 1. If
an entry fulfilling these requirements is found, the high indicator is
turned on.
11–71
Operation Codes
Operation
In the LOKUP operation, factor 1 contains the search argument and factor
2 contains the name of the table or array. The search element can be an
alphameric or numeric literal, a field name, an array element, or a table
name. Search arguments must be the same length and format as the
entries in the table or array being searched. For example, both the search
element and the array or table must be numeric with the same number of
digits, or both must be alphameric with the same number of characters.
Tables and arrays should be sequenced before greater than or less than
type searches are carried out against them. Remember, the LOKUP
operation stops processing as soon as it finds an element which fulfills the
search requirements. If the search is intended to find the highest or lowest
element in the table or array and the table or array is not sequenced, the
search may not return the desired element. Table and array sequencing
can be indicated by an entry in column 45 of the Extension specification.
Compile-time arrays and tables are checked for correct sequencing during
program compilation. If the sequencing is not valid, the compiler will
generate a fatal error.
11–72
Operation Codes
Pre-execution time arrays and tables will generate a halt if they are not
in a valid sequence when being loaded during program initialization.
The user is given the option of continuing or terminating the program in
response to the halt. If the program is continued, the array or table will
be stored in an invalid sequence and may not produce the desired results.
Run-time tables and arrays cannot be checked before a program is
compiled or begins execution. If they are not in sequence, the LOKUP
operation may not produce the desired results. It is advisable to perform
a SORTA operation on run-time arrays before using them in a LOKUP
operation.
Resulting indicators are set off when a LOKUP operation begins. If a
LOKUP operation is not successful, no resulting indicators are turned on.
If an index is used with an array in a LOKUP operation, the search
begins at the array element specified by the index. Elements in the array
preceding the index are not searched.
If the index used with an array in a LOKUP operation is a variable, it will
be set to the number of the array element meeting the search criteria if
such an element is found. If the LOKUP operation is unsuccessful, the
index variable will be set to 1.
When the LOKUP operation finds a table entry that satisfies the search,
it places a copy of the entry in a special storage area which can be
referenced in other RPG operations by specifying the table name. This
area is called the table reference field. When another LOKUP operation
completes successfully, the new entry replaces the previous entry in the
table reference field.
11–73
Operation Codes
Both tables should have the same number of entries. The related table
must have as many or more entries than the table to be searched.
11–74
Operation Codes
11–75
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
E* The elements assigned to these tables and array
E* appear at the end of the sample code.
E*
E LBS 1 6 2 A
E TABTUK 1 6 2 0D
E TABCRD 1 6 5 D
.
.
.
C PART LOKUPLBS 08 08
C*
C* In this example, a greater than or equal LOKUP
C* is being performed against the LBS array. If an
C* element in the array is greater than or equal to
C* the contents of PART, indicator 08 will be turned
C* on.
C*
C PART LOKUPLBS,X 11
C*
C* In this example, a greater than search is being
C* performed against the array LBS. If the search
C* is successful, indicator 11 will be turned on.
C* Here the LBS array is using an index variable (X).
C* The LOKUP operation will begin its search at the
C* element specified by X. If X were 3, the LOKUP
C* would begin with the element CC. If PART were
C* XX, this LOKUP would not find a match.
C* Indicator 11 would not be turned on and the
C* variable index X would be set to 1. If PART
C* were DD, this LOKUP would find that element 5,
C* EE, was greater than DD. Indicator 11 would be
C* turned on and the variable X would be set to 5.
C*
C CARD LOKUPTABTUK 66
C*
C* In this example, a less than LOKUP operation is
C* performed on the table TABTUK. If the number
C* specified in the CARD field is less than an element
C* in the table, indicator 66 will be turned on and
C* the element will be placed in the TABTUK storage
C* area. If CARD were equal to 4, the search would
C* be successful, indicator 66 would be turned on,
C* and the element 02 would be placed in the TABTUK
C* storage area.
C*
C CARD LOKUPTABTUK TABCRD 2123
C*
C* In this example, a less than or equal search is
C* performed against the table TABTUK. If the
C* search is successful, either indicator 21 or 23
C* will be turned on and the element in the TABTUK
C* table will be moved to the TABTUK storage area.
C* If the search is successful, the associated
C* element in the TABCRD table will also be moved to
C* the TABCRD storage area. If CARD were 11, the
C* search would be successful and indicator 23
C* (equal) would be turned on. The element 11 from
C* the TABTUK table would be moved to the TABTUK
C* storage area and the associated element JACK
C* would be moved to the TABCRD storage area.
11–76
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
O*
** LBS Array
AA
BB
CC
DD
EE
FF
** TABTUK Table
14
13
12
11
02
01
** TABCRD Table
ACE
KING
QUEEN
JACK
TRUMP
FOLD
These examples use the array LBS and the table TABTUK to demonstrate
the use of the LOKUP operation. The results of each operation are
described in the comments associated with each instruction.
The array LBS has the following characteristics:
• It is a compile-time array.
• It contains 1 element per record (columns 33 - 35).
• It has a total of 6 elements (columns 36 - 39).
• Each element has a length of 2 characters (columns 40 - 42).
• The array contains alphameric elements (column 44).
• The array is sorted in ascending order (column 45).
11–77
Operation Codes
11–78
Operation Codes
Description
The Move High Zone to High Zone operation moves the high zone of factor
2 to the high zone of the result field.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 must be blank.
Factor 2 is required. It must contain an alphameric entry.
The result field is required. It must contain an alphameric entry.
Resulting indicators (columns 54 - 59) are not allowed.
Operation
The MHHZO operation moves the zone from the leftmost position of the
entry in factor 2 to the leftmost position of the entry in the result field.
Example 11–39 MHHZO Operation Code Usage
1 2 3 4
1234567890123456789012345678901234567890123456789
C*
C MHHZOPIT PAT
In this example, the zone portion of the leftmost character in the PIT field
will be moved to the zone portion of the leftmost character in the PAT
field.
11–79
Operation Codes
Description
The Move High Zone to Low Zone operation moves the high zone in factor
2 to the low zone in the result field.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 must be blank.
Factor 2 is required. It must contain an alphameric entry.
The result field is required. It can be an alphameric or numeric entry.
Resulting indicators (columns 54 - 59) are not allowed.
Operation
The MHLZO operation moves the zone from the leftmost position of the
entry in factor 2 to the rightmost position of the entry in the result field.
Example 11–40 MHLZO Operation Code Usage
1 2 3 4
1234567890123456789012345678901234567890123456789
C*
C MHLZOSNAKE PIT
In this example, the zone portion of the leftmost character in the SNAKE
field will be moved to the zone portion of the rightmost character in the
PIT field.
11–80
Operation Codes
Description
The Move Low Zone to High Zone operation moves the low zone of factor 2
to the high zone of the result field.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 must be blank.
Factor 2 is required. It can be an alphameric or numeric entry.
The result field is required. It must contain an alphameric entry.
Resulting indicators (columns 54 - 59) are not allowed.
Operation
The MLHZO operation moves the zone from the rightmost position of the
entry in factor 2 to the leftmost position of the entry in the result field.
Example 11–41 MLHZO Operation Code Usage
1 2 3 4
1234567890123456789012345678901234567890123456789
C*
C MLHZOCAR WASH
In this example, the zone portion of the rightmost character in the CAR
field will be moved to the zone portion of the leftmost character in the
WASH field.
11–81
Operation Codes
Description
The Move Low Zone to Low Zone operation moves the low zone of factor 2
to the low zone of the result field.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 must be blank.
Factor 2 is required. It can contain an alphameric or numeric entry.
The result field is required. It can contain an alphameric or numeric entry.
Resulting indicators (columns 54 - 59) are not allowed.
Operation
The MLLZO operation moves the zone from the rightmost position of the
entry in factor 2 to the rightmost position of the entry in the result field.
Example 11–42 MLLZO Operation Code Usage
1 2 3 4
1234567890123456789012345678901234567890123456789
C*
C MLLZOLAWN MOWER
In this example, the zone portion of the rightmost character in the LAWN
field will be moved to the zone portion of the rightmost character in the
MOWER field.
11–82
Operation Codes
Description
The MOVE operation carries out a right-justified transfer of characters
from factor 2 to the result field.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 must be blank.
Factor 2 is required. It can contain a literal, figurative constant, field,
array element, table element, or data structure element.
The result field is required. It can contain a field, array element, table
element, or data structure element. It cannot contain a literal.
Resulting indicators (columns 54 - 59) are not allowed.
Operation
The MOVE operation transfers data from factor 2 to the result field. It
can carry out the following types of transfers:
• Alphameric element to alphameric element.
• Alphameric element to numeric element.
• Numeric element to alphameric element.
• Numeric element to numeric element.
11–83
Operation Codes
1 2 3 4
1234567890123456789012345678901234567890123456789
C*
C MOVE PORTER HOUSE
In this example, the contents of the field PORTER are moved to the field
HOUSE. The table following the code example depicts the results of the
MOVE operation for different field sizes.
Field Field
Size Contents Size Contents Result of MOVE
4 ROCK 4 ROCK
7 ROLLER 4 LLER
7 CONCERT 8 LICORICE LCONCERT
6 179945 4 6457 9945
4 3098 8 11111111 11113098
11–84
Operation Codes
Description
The Move Array operation carries out a left-justified transfer of alphameric
data from factor 2 to the result field. It is used to transfer data in and out
of arrays.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 must be blank.
Factor 2 is required. It can contain a literal, figurative constant, field,
array, array element, table element, or data structure element.
The result field is required. It can contain a field, array, array element,
table element, or data structure element. It cannot contain a literal.
Resulting indicators (columns 54 - 59) are not allowed.
Operation
The MOVEA operation is used to move several contiguous array elements
to a single field, move a single field to several contiguous array elements,
or move contiguous array elements from one array to another. Transfer of
data from factor 2 to the result field is carried out as follows:
• If a non-indexed array is specified in factor 2, transfer of data begins
with the leftmost character of the first element in the array.
• If an indexed array is specified in factor 2, transfer of data begins with
the leftmost character of the element specified by the index.
• If a data field is specified in factor 2, transfer begins with the leftmost
character of the field.
• If a non-indexed array is specified in the result field, placement of
transferred data begins with the leftmost character of the first element
in the array.
• If an indexed array is specified in the result field, placement of
transferred data begins with the leftmost character of the element
specified by the index.
• If a data field is specified in the result field, placement of the
transferred data begins with the leftmost character of the field.
11–85
Operation Codes
If the field length of factor 2 is greater than the field length of the result
field, the excess rightmost characters in factor 2 are not moved. If the field
length of the result field is greater than the field length of factor 2, the
rightmost characters in the result field remain unchanged.
Array element boundaries are ignored in a MOVEA operation. Therefore,
movement of data into the result field can end in the middle of an array
element.
All data transferred by a MOVEA operation is treated as alphameric data.
This means that numeric data is transferred without regard for the sign.
It is up to the programmer to ensure that the transfer of numeric data is
carried out properly.
If a figurative constant (*BLANK, *BLANKS, *ZERO, or *ZEROS) is
specified in factor 2 of a MOVEA operation and the result field contains an
array, the following actions are possible:
• If the array is non-indexed, the data transfer will begin with the
leftmost character of the first element of the array and the entire
array will be blank or zero-filled.
• If the array is indexed, the data transfer will begin with the leftmost
character of the array element specified by the index and the
remainder of the array will be blank or zero-filled. Array elements
to the left of the index will not be affected.
11–86
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
*
E ALPHA1 5 2
E ALPHA2 5 2
E NUM 5 3 0
.
.
.
C MOVE ’XXXX’ FLDA 4
C MOVE ’9999999’ FLDN 70
.
.
.
** ALPHA1 array elements
AABBCCDDEE
** ALPHA2 array elements
GGHHIIJJKK
** NUM array elements
111222333444555
The following examples depict the use and results of the MOVEA
operation. Example 11–44 shows the array and field definitions used
in the examples.
Example 11–45 MOVEA Operation Code Usage - Array to Array
(Alphameric)
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
*
C MOVEAALPHA1 ALPHA2
In this example, the contents of the array ALPHA1 are moved to the array
ALPHA2.
11–87
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
*
C MOVEAALPHA2 FLDA
In this example, the contents of the array ALPHA2 are moved to the field
FLDA.
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
*
C MOVEAFLDN NUM,3
In this example, the contents of FLDN are placed in the NUM array,
starting with the third element.
11–88
Operation Codes
Description
The Move Left operation transfers the contents of factor 2 to the result
field. The transfer begins with the leftmost character of factor 2 to the
leftmost character of the result field.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 must be blank.
Factor 2 is required. It can contain a literal, figurative constant, field,
array element, table element, or data structure element.
The result field is required. It can contain a field, array element, table
element, or data structure element. It cannot contain a literal.
Resulting indicators (columns 54 - 59) are not allowed.
Operation
A MOVEL operation is essentially the opposite of a MOVE operation.
A MOVEL operation transfers characters in a left-justified fashion, as
opposed to the right-justified transfer carried out by a MOVE operation.
There are three basic types of MOVEL operations, each of which is based
on the lengths of the elements in factor 2 and the result field. These
MOVEL operations are summarized in the following paragraphs.
In a MOVEL operation where the field length of factor 2 is equal to the
field length of the result field, the following rules apply:
• If factor 2 and the result field are both alphameric fields, all characters
are transferred.
• If factor 2 and the result field are both numeric, all digits are
transferred and the sign of factor 2 becomes the sign of the result
field.
• If factor 2 contains numeric data and the result field is alphameric, all
characters are transferred. The result field will contain only numeric
characters; the sign is not used.
11–89
Operation Codes
In a MOVEL operation where the field length of factor 2 is longer than the
field length of the result field, the following rules apply:
• If factor 2 and the result field are both alphameric, only the number of
characters needed to fill the result field are transferred.
• If factor 2 and the result field are both numeric, only the number of
digits needed to fill the result field are transferred. The sign of factor
2 becomes the sign of the result field.
• If factor 2 contains numeric data and the result field is alphameric,
only the number of characters needed to fill the result field are
transferred. The result field will contain only numeric characters;
the sign of factor 2 is not used.
• If factor 2 contains alphameric data and the result field is numeric,
the digit portion of the leftmost characters of factor 2 are moved to
the result field. The zone portion of the rightmost character in factor
2 is used to determine the sign of the result field. If the rightmost
character of factor 2 is a J through R or {, the result field will be
considered negative.
11–90
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C MOVE ’HOTSPOT’ SUN 7
.
.
.
C MOVEL’ICE’ SUN
C MOVE ’CUBE’ SUN
This example depicts the use of the MOVEL operation code. The field
SUN (a 7-character alphameric field) is defined and initialized in the
Calculation specifications by a MOVE operation. It is initialized with the
value ’HOTSPOT’. Later in the program, the value of the field SUN
is changed by a MOVEL and a MOVE operation. After the MOVEL
operation, the contents of the field SUN will be ’ICESPOT’. The MOVEL
operation replaces the leftmost three characters of the field SUN with
the literal ’ICE’. After the MOVE operation, the field SUN will contain
’ICECUBE’. The MOVE operation replaces the rightmost four characters
of the SUN field with the literal ’CUBE’.
11–91
Operation Codes
Description
The Multiply operation allows two numeric elements to be multiplied
together, with the product being placed in the result field.
Rules
All elements specified in a MULT operation must be numeric.
Conditional indicators (columns 7 - 17) are optional.
Factor 1 is optional. If present, factor 1 is multiplied by factor 2 and the
product is placed in the result field.
Factor 2 is required. If factor 1 is not present, the result field is multiplied
by factor 2 and the product is placed in the result field.
The contents of factor 1 and factor 2 are not affected by a MULT operation.
Resulting indicators (columns 54 - 59) are optional. They can be
used to indicate whether the contents of the result field are positive
(columns 54 - 55), negative (columns 56 - 57), or zero (columns 58 - 59)
after the MULT operation.
Operation
RPG aligns the operands according to their decimal points before
performing any arithmetic operation. Results of an arithmetic operation
are aligned on the decimal point in the result field, which can cause
truncation on both ends of a result. More information on arithmetic
operations is available earlier in this chapter in Section 11.1.
11–92
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C FLD1 MULT 2 FLD2
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C MULT 2 CNT
In this example, the field CNT is multiplied by the constant 2 and the
result is placed in CNT. If the contents of CNT are 5 at the beginning of
the operation, they will be 10 when the operation is completed.
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C 10 CASH MULT PERCNT INTRST
11–93
Operation Codes
Description
The Move Remainder operation moves the remainder from the Divide
operation (DIV) on the preceding line to the result field.
Rules
The MVR operation must immediately follow a DIV operation.
Conditional indicators (columns 7 - 17) are optional.
Factor 1 must be blank.
Factor 2 must be blank.
The result field is required. It must contain a numeric entry which will
accept the remainder from the previous DIV operation.
Resulting indicators (columns 54 - 59) are optional. They can be
used to indicate whether the contents of the result field are positive
(columns 54 - 55), negative (columns 56 - 57), or zero (columns 58 - 59)
after the MVR operation.
Operation
The MVR operation captures the remainder of the previous DIV operation.
The MVR operation must immediately follow a DIV operation.
The number of significant decimal positions of the remainder is the greater
of either of the following:
1 The number of decimal positions specified for factor 1 in the associated
DIV operation.
2 The sum of the number of decimal positions specified for factor 2 and
the result field of the associated DIV operation.
11–94
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C PRINC DIV MONTH PAYMNT 50
C MVR RESIDL 50
In this example, the field PRINC will be divided by MONTH, with the
result being placed in PAYMNT. Any remainder from this DIV operation
will be placed in the field RESIDL by the MVR operation. If PRINC
contains 511 and MONTH contains 12, the result of the DIV operation will
be 42, which will be placed in the field PAYMNT. The MVR operation will
move the remainder of 7 into the field RESIDL.
11–95
Operation Codes
Description
The ORxx operation allows a more complex conditional operation to be
specified in DOUxx (Do Until), DOWxx (Do While), and IFxx operations.
Fields specified in the ORxx operation are compared and return a true
or false condition to the program. The true/false condition is used by
the program to determine if the structured construct of which the ORxx
operation is a part should be executed or bypassed.
Rules
The ORxx operation can be used in conjunction with the DOUxx, DOWxx,
IFxx, and ANDxx operations.
Control level entries (columns 7 - 8) for the ORxx operation must be
consistent with the control level entry for the associated DOUxx, DOWxx,
or IFxx operation.
Conditional indicators (columns 9 - 17) are not permitted.
Factor 1 and factor 2 are both required. They can contain a literal,
field, array element, table element, or data structure element. The data
types of both fields must match, meaning that both fields must be either
alphameric or numeric.
The comparison carried out in an ORxx operation follows standard RPG
comparison rules. These rules are discussed earlier in this chapter in
Section 11.4.
Resulting indicators are not allowed.
11–96
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C JUGGLE DOWGT3
C BALLS OREQ PINS
.
.
.
C END
In this example, the Do While loop will continue to execute as long as the
field JUGGLE is greater than 3 or the field BALLS equals the field PINS.
11–97
Operation Codes
Description
The PARM operation is used to exchange parameters with an RPG
subprogram.
Rules
The PARM operation code is used to define parameters which will make
up a parameter list to be passed to an RPG subprogram. The PARM
operation code is used with the CALL and PLIST operation codes. PARM
statements can appear anywhere in the Calculation specifications as long
as they immediately follow a CALL or PLIST statement. Up to 99,999
PARM statements can follow a CALL or PLIST statement.
Conditional indicator entries (columns 9 - 17) and resulting indicator
entries (columns 54 - 59) are not permitted.
Factors 1 and 2 are optional in a PARM statement. If specified, they must
have the same data type, alpha or numeric, as the result field. A literal or
figurative constant cannot be specified in factor 1.
The result field must contain a field, data structure, array, or array
element name. *ENTRY PLIST parameters cannot specify array elements
using fields as subscripts. The result field cannot contain a literal or table
name. *IN, *INxx, and *IN,xx entries are legal PARM fields, but should
be specified with caution as their settings reflect indicator settings. The
length and decimal position columns (49 - 52) can be used to define the
result field.
The field specified in the result field of a PARM statement is passed by
descriptor to the RPG subprogram. The field can be manipulated and
updated by the subprogram. The subprogram then returns the updated
value to the calling program. If an RPG subprogram terminates with an
error, any changes made to the fields specified in the PARM statements
are still returned to the calling program. To preserve a field from changes
when using it as a parameter, specify the field name in factor 2 of the
PARM statement and declare a temporary field name in the result
field. The contents of factor 2 will be copied to the result field when
the subprogram is called and the contents of the field in factor 2 will
remain unaffected.
11–98
Operation Codes
31 23 15 0
1 DTYPE LENGTH
POINTER
11–99
Operation Codes
11–100
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C* The following example illustrates the use of the
C* PARM statement with the CALL operation code.
C*
C* The first parameter passes the contents of the
C* field TAP to the called program and returns any
C* modifications to the field TAP when the called
C* program exits.
C*
C* The second parameter copies the contents of the
C* field FOX to the field TROT before passing the
C* contents of TROT to the call program. Since TROT
C* is defined as a 10-byte, alpha field, it will be
C* moved using a MOVE operation. When the called
C* program exits, TROT will contain the updated data.
C*
C* The third parameter passes the contents of the
C* field CHARLE to the called program. When the
C* called program exits, the updated contents of
C* CHARLE will be copied to STON.
C*
C* The fourth parameter copies the contents of the
C* field ROCK to the field AND when a program is
C* called. Since AND is defined as a 7-byte, numeric
C* field, the copy is carried out using a Z-ADD
C* operation. When the called program exits, the
C* updated data in AND is Z-ADDed to the field ROLL.
C*
C CALL ’DANCE’
C PARM TAP
C PARM FOX TROT 10
C STON PARM CHARLE
C ROLL PARM ROCK AND 70
11–101
Operation Codes
Description
The PLIST operation defines a unique symbolic name for a list of
parameters that is used in a CALL operation.
Rules
A PLIST operation can be specified anywhere within the Calculation
specifications, including total time calculations and between subroutines.
A PLIST entry consists of a PLIST statement followed by one or more
PARM statements which define a list of parameters that is to be passed
to or received by a subprogram. A parameter listed is ended when an
operation other than a PARM is encountered.
Indicator entries in columns 7 - 8 are optional.
Indicator entries in columns 9 - 17 are not allowed.
Factor 1 is required. It must contain the name of the PLIST. A PLIST
name can be one to six characters in length and must be unique. If
the parameter list being defined is the entry parameter list for an RPG
subprogram, factor 1 must contain *ENTRY. Only one *ENTRY PLIST can
be defined in a program.
Factor 2 must be blank.
The result field must be blank.
Resulting indicators (columns 54 - 59) are not allowed.
Operation
The elements in a parameter list supplied by a calling program and the
elements in a parameter list defined by a *ENTRY PLIST in an RPG
subprogram should match in size and data type.
11–102
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C* The *ENTRY PLIST is set up to accept and return
C* three parameters from a calling program. The
C* PLIST labeled FARM has three parameters assigned
C* to it. A CALL statement in this program could
C* reference the PLIST FARM and pass the FARM
C* parameter list to another program.
C*
C *ENTRY PLIST
C PARM COWS
C PARM HOGS
C PARM CHICKN
C*
C FARM PLIST
C PARM TRACTR
C PARM COMBIN
C PARM PICKUP
11–103
Operation Codes
Description
The READ operation calls for a record to be read immediately from a
demand or full-procedural file. The READ operation differs from the
FORCE operation in that the FORCE operation specifies a read from a file
on the next cycle.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 must be blank.
Factor 2 is required. It must contain the name of the demand or full-
procedural file the READ operation is to access. The file name specified
in factor 2 must match a file name specified in columns 7 - 14 of the File
Description specifications.
The result field must be blank.
The resulting indicator in columns 54 - 55 (high) must be blank. The
resulting indicator in columns 56 - 57 (low) is optional and can be used
as an exception indicator on reads to WORKSTN devices and an error
indicator on reads to data files. The resulting indicator in columns 58 - 59
(equal) is optional and indicates an end-of-file condition.
Operation
A READ operation can only be specified for a demand or full-procedural
file. These files have a D or F specified in column 16 of the File Description
specification.
A READ operation can be carried out against the following types of input
and update files:
• Sequential files processed consecutively.
• Sequential files processed randomly and consecutively.
• Relative files processed consecutively.
• Relative files processed randomly and consecutively.
• Indexed files processed sequentially by key.
• Indexed files processed sequentially by limits.
• Indexed files processed randomly and consecutively.
11–104
Operation Codes
• WORKSTN files.
• SPECIAL device files.
11–105
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
*
FJAZZ ID F 80 80 DISK
.
.
.
C READ JAZZ 99
.
.
.
11–106
Operation Codes
Description
The Read Equal Key operation retrieves the next sequential record from
an indexed, full-procedural file if the key matches the entry in factor 1.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 is required. It can contain a literal, field, array or table element,
or data structure element. The entry must have the same field type and
length as the key field of the file being read.
Factor 2 is required. It must contain the name of the file being read. The
file must be a full-procedural, indexed file and the name must match a
name specified in columns 7 - 14 of the File Description specifications.
The result field must be blank.
A resulting indicator in columns 54 - 55 is not permitted. A resulting
indicator in columns 56 - 57 is optional and serves as an error indicator. A
resulting indicator in columns 58 - 59 (equal) is required and serves as a
record-not-found indicator.
Operation
The READE operation will read the next sequential record from an
indexed, full-procedural file if the key in the record matches the key
specified in factor 1. A full-procedural file is identified by an F in column
16 of the File Description specification. A CHAIN or SETLL operation
must occur before a READE operation to position the record pointer within
the file. If a READE operation fails, another SETLL or CHAIN operation
must be carried out to reposition the record pointer or all subsequent
READ, READE, and READP operations will fail.
A resulting indicator in columns 56 - 57 is optional. If specified, it serves
as an error indicator, turning on if the record requested by the READE
operation cannot be accessed. If this indicator is turned on, the record-not-
found indicator will also be turned on.
The $STAT$ field will contain the completion status of any CHAIN, READ,
READE, or READP operation.
11–107
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
*
FROCK IF F 120R 5AI 1 DISK
.
.
.
C KEY CHAINROCK 99
C LOOP TAG
C N99 KEY READEROCK 99
.
.
.
C N99 GOTO LOOP
.
.
.
In this example, the READE operation is used to read all records with a
key equal to the record located by the CHAIN operation. Note the use of
indicator 99 to indicate a record-not-found condition.
11–108
Operation Codes
Description
The Read Prior operation retrieves the previous sequential record from a
full-procedural file.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 must be blank.
Factor 2 is required. It must contain the name of the file being read. The
file must be a full-procedural file and the name must match the name
specified in columns 7 - 14 of the File Description specification.
The result field must be blank.
A resulting indicator in columns 54 - 55 is not permitted. A resulting
indicator in columns 56 - 57 (low) is optional and serves as an error
indicator. A resulting indicator in columns 58 - 59 (equal) is optional and
serves as a beginning-of-file indicator.
Operation
The READP operation will read the previous sequential record from a
full-procedural file. A full-procedural file is identified by an F in column
16 of the File Description specification. The READP operation can be used
against the following types of full-procedural files:
• A fixed-length sequential file.
• A relative file.
• An indexed file with both ascending and descending key definitions.
11–109
Operation Codes
The $STAT$ field will contain the completion status of any CHAIN, READ,
READE, or READP operation.
If a READP operation is successful, the record-identification indicators
associated with the record read remain on for the rest of the cycle. Other
record-identification indicators are not affected.
Indexed files require some special preparation before they can be accessed
with the READP operation. Key fields within an indexed file must be
defined as both ascending and descending keys for the READP operation
to function correctly. For example, the primary key (Key 0) of an indexed
file is defined as an ascending key starting in offset 0 with a length of 6.
To access this file using the primary key with a READP operation, the first
secondary key (Key 1) in the file would need to be defined as a descending
key starting in offset 0 with a length of 6.
The rule of thumb for defining keys in an indexed file which is accessed
using the READP operation is that each key defined in the File
Description specifications must have an associated key defined as the next
secondary key in the file. Thus, if key 2 is defined in the File Description
specification, key 3 will be the key accessed by the READP operation.
Creating indexed file definitions for files which are to be accessed using
the READP operation is covered in more detail in the Migration RPG
User’s Guide. Creating indexed file definitions is covered in the OpenVMS
File Definition Language Facility Manual.
Example 11–58 READP Operation Code Usage
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
*
FMINE UF F 120 DISK
.
.
.
C READ MINE 98
.
.
.
C READPMINE 99
.
.
.
This example depicts the use of the READ and READP operation codes
to extract records from the file MINE. The READ operation will read the
next sequential record in the file. If an end-of-file condition is returned by
the READ operation, indicator 98 will be turned on. The READP operation
will read the previous sequential record in the file. If a beginning-of-file
condition is returned, indicator 99 will be turned on.
11–110
Operation Codes
Description
The RETRN operation causes an RPG subprogram to return to the calling
program. The RETRN operation is associated with the CALL operation.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 must be blank.
Factor 2 must be blank.
The result field must be blank.
Resulting indicators (columns 54 - 59) are not allowed.
Operation
The RETRN operation is similar in function to the ENDSR (end
subroutine) statement. It tells an RPG subprogram to exit immediately
and return control to the calling program. When a RETRN statement is
processed, the follow steps occur:
1 The halt indicators (H1 - H9) are checked. If a halt indicator is on, the
program ends abnormally, closing all data files, and returning an error
status. If warning messages are enabled, a warning is issued to the
user’s terminal when the subprogram returns.
2 If no halt indicators are on, the LR (last record) indicator is checked.
If LR is on, the subprogram ends normally, shutting down file streams
and deactivating the subprogram.
3 If neither the halt or LR indicators are on, the subprogram returns
control to the calling program. Data and indicator settings in the
subprogram are preserved.
11–111
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C* This subprogram is called by another, passing the
C* parameters PHASER and PHOTON. After manipulation
C* of these fields, it returns to the calling program
C* without ending. Any values or indicator settings
C* established each time this subprogram is run are
C* retained as long as the calling program does not
C* run a FREE operation against it.
C*
C *ENTRY PLIST
C PARM PHASER
C PARM PHOTON
*
C PHASER ADD ENERGY PHASER
C PHOTON ADD ENERGY PHOTON
*
C RETRN
11–112
Operation Codes
Description
The RLABL allows parameters which are to be passed to an external
subroutine called by an EXIT operation to be defined. The RLABL
operation is maintained for compatibility with non-Digital versions of the
RPG programming language and to pass parameters to the MSI-supplied
subroutines SUBR01, SUBR21, and SUBR23. The CALL operation and
its associated instructions are recommended for calling external routines
using Migration RPG.
Rules
Conditional indicators (columns 7 - 17) are not permitted.
Factor 1 must be blank.
Factor 2 must be blank.
The result field is required. It must contain the name of the field, array,
table, or data structure element that is being passed to the external
subroutine.
Resulting indicators (columns 54 - 59) are not allowed.
11–113
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
*
IDS DS
I 7 56 DATAST
I 17 56 DATA
I 75 820MIC
*
C MOVE NUM MIC
C MOVE 1 LEVEL 10
*
C EXIT SUBR23
C RLABL MIC
C RLABL DATAST
C RLABL LEVEL
C RLABL RCODE 10
11–114
Operation Codes
Description
The SETnn operation allows information to be displayed on the user’s
screen and can enable command keys for user input. The SETnn operation
is often used in conjunction with the KEYnn operation.
Rules
The SETnn operation can only be used if a KEYBORD file has been
defined in the File Description specifications. KEYBORD must be defined
as the device type in columns 40 - 46 of the File Description specification.
Conditional indicators (columns 7 - 17) are optional.
Factor 1 is optional. It can be a literal or data field which will be displayed
on the user’s screen when the SETnn operation is processed.
The nn portion of the SETnn operation code can be blank or can specify
a message member number from the User Level 1 message member file
(RPGUSRLV1). If the message member corresponding to the message
number in the SETnn operation code is found, the message is displayed.
If the message member file is not present or no entry exists which
corresponds to the message number specified, nothing is displayed. If
an entry is made in factor 1 of the SETnn operation, the message number
is ignored. If no entry is made in factor 1, the message number is required.
See the Migration RPG User’s Guide for more information on creating and
referencing message member files.
Factor 2 must be blank.
The result field must be blank.
Resulting indicators (columns 54 - 59) are optional. If specified, they must
contain the command key indicators KA - KN and KP - KY.
11–115
Operation Codes
Operation
The SETnn operation can be used to display data and define command
keys. The following actions can occur when the SETnn operation is
executed:
• If factor 1 is present, its contents are displayed to the user’s screen.
• If factor 1 is not present, the message member defined by the nn
portion of the SETnn operation will be displayed from the User Level
1 message member file (RPGUSRLV1), if it is found.
• If no command key indicators are defined in a SETnn operation, the
program continues without stopping for user input. SETnn operations
which do not specify command key indicators can be used to create a
running display of data.
• If command key indicators (KA - KN, KP - KY) are defined in the
resulting indicator columns, the SETnn operation stops the program
and waits for user input. It will allow the user to enter the defined
command keys from the terminal. If a command key is entered, its
corresponding indicator is turned on. If the command key is entered
again during the same SETnn operation, its corresponding indicator is
turned off. Any command key indicators defined in a SETnn operation
are turned off when the SETnn operation begins execution.
• If a SETnn operation with command keys stops a program, entering a
command key does not restart the program. The user must press the
Return , Enter , or PF4 key to continue the program.
11–116
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
*
FUSERIN IP F 70 70 KEYBORD
E PRMPT 1 5 40
.
.
.
C ’WAKE UP!’SET
C PRMPT,1 SET
C SET23 KA
.
.
.
**
USER DATA ENTRY REQUIRED
11–117
Operation Codes
Description
The Set Lower Limit operation positions the record pointer within a file at
the record with a key that is greater than or equal to the key specified in
factor 1.
Rules
The SETLL operation can only be performed against full-procedural and
demand indexed files that are being processed sequentially within limits.
The File Description specification for the SETLL file must have an F or D
in column 16 and an L in column 28.
Conditional indicators (columns 7 - 17) are optional.
Factor 1 is required. It can contain a literal, field, array or table element,
or data structure element. The entry must have the same field type and
length as the key field of the file being read.
Factor 2 is required. It must contain the name of the file being read.
The file must be a full-procedural or demand indexed file being processed
within limits. The file name must match the name specified in columns
7 - 14 of the File Description specification.
The result field must be blank.
Resulting indicators (columns 54 - 59) are not allowed.
Operation
When a SETLL operation is performed, the file record pointer is set at the
record with the key that is greater than or equal to the key specified in
factor 1. Subsequent READ, READE, and READP operations will begin
from that point.
If the program issues a READ operation before issuing a SETLL operation,
processing begins with the first record in the file.
When end-of-file is reached on a limits file, another SETLL operation can
be used to reposition the record pointer in the file.
11–118
Operation Codes
A record-address file and the SETLL operation cannot be used with the
same data file.
Example 11–62 SETLL Operation Code Usage
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
0001 H
0002 FCUSTMSTRIF F 132L 5AI 1 DISK
0003 FINPUT CD F 32 WORKSTN
.
.
.
0009 ICUSTMSTRAA 01
0010 I 1 5 KEY
0011 I 6 20 LSTNAM
0012 I 21 35 FSTNAM
0013 *
0014 IINPUT BB 02
0015 I 1 5 KEY
.
.
.
0044 C READ INPUT 90
0045 C N90 KEY SETLLCUSTMSTR
0046 C N90 READ CUSTMSTR 90
11–119
Operation Codes
Description
The Set Indicators Off operation will set one to three indicators off.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 must be blank.
Factor 2 must be blank.
The result field must be blank.
At least one resulting indicator must be specified in columns 54 - 59.
Operation
The SETOF operation will set all of the indicators specified in the resulting
indicator columns off (to 0).
Example 11–63 SETOF Operation Code Usage
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C SETOF 101112
C SETOF 20
In this example, the SETOF instruction is used to turn off indicators 10,
11, 12, and 20.
11–120
Operation Codes
Description
The Set Indicators On operation will set one to three indicators on.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 must be blank.
Factor 2 must be blank.
The result field must be blank.
At least one resulting indicator must be specified in columns 54 - 59.
Operation
The SETON operation will set all of the indicators specified in the
resulting indicator columns on (to 1).
Example 11–64 SETON Operation Code Usage
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C SETON 304050
C SETON 6070
11–121
Operation Codes
Description
The Sort Array operation allows the elements in an array to be sequenced.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 must be blank.
Factor 2 is required. It must contain the name of an array.
The result field must be blank.
Resulting indicators (columns 54 - 59) are not allowed.
Operation
The SORTA operation sequences the elements in an array. It is commonly
used to ensure that the elements of an array are properly sequenced before
a LOKUP operation is performed.
If the array sequence has been defined in columns 45 or 57 of the
Extension specification, the array is sorted accordingly. If no sequence
has been defined, the array will be sorted in an ascending sequence. All
SORTA operations use a standard ASCII collating sequence. Alternating
collating sequences are ignored.
Only the array specified is sorted.
11–122
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
*
FINPUT IP F 80 80 DISK
*
E LUFF 10 10
*
IINPUT NS 01
I 1 100 LUFF
*
C SORTALUFF
In this example, the array LUFF is loaded from an input record and then
sorted into ascending order.
11–123
Operation Codes
Description
The Square Root operation calculates the square root of the value specified
in factor 2.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 must be blank.
Factor 2 is required. It must contain a numeric entry. It can contain the
name of a numeric array if the result field also contains a numeric array.
The result field is required. It must contain a numeric entry.
Resulting indicators (columns 54 - 59) are not allowed.
Operation
The SQRT operation calculates the square root of the entry in factor
2, placing the product in the result field. The SQRT operation always
produces a positive result. If the value specified in factor 2 is negative, its
sign is changed before the square root calculation takes place.
It is recommended that the result field have at least half as many decimal
places as factor 2. Results of a SQRT operation are always half-adjusted.
Example 11–66 SQRT Operation Code Usage
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C SQRT NUM CHUCK
In this example, the SQRT operation calculates the square root of the
contents of NUM and places the result in CHUCK.
11–124
Operation Codes
Description
The Subtract operation subtracts factor 2 from factor 1, placing the
difference in the result field.
Rules
All fields specified in an SUB operation must be numeric.
Conditional indicators (columns 7 - 17) are optional.
Factor 1 is optional. If present, factor 2 is subtracted from factor 1 and the
difference is placed in the result field.
Factor 2 is required. If factor 1 is not present, factor 2 is subtracted from
the result field and the product is placed in the result field.
The contents of factor 1 and factor 2 are not affected by a SUB operation.
Resulting indicators (columns 54 - 59) are optional. They can be
used to indicate whether the contents of the result field are positive
(columns 54 - 55), negative (columns 56 - 57), or zero (columns 58 - 59)
after the SUB operation.
Operation
RPG aligns the operands according to their decimal points before
performing any arithmetic operation. Results of an arithmetic operation
are aligned on the decimal point in the result field, which can cause
truncation on both ends of a result. More information on arithmetic
operations is available earlier in this chapter in Section 11.1.
11–125
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C FLD1 SUB 1 FLD2
In this example, the constant 1 is subtracted from FLD1 and the result is
placed in FLD2.
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C SUB 1 CNT
In this example, the constant 1 is subtracted from the field CNT and the
result is placed in CNT.
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C 10 PAY SUB TAXES PITANC
11–126
Operation Codes
Description
The TAG operation defines a label to which a GOTO or CABxx operation
can branch.
Rules
Conditional indicators in columns 7 - 8 are optional.
Conditional indicators in columns 9 - 17 are not permitted.
Factor 1 is required. It must contain the label which defines the branch
destination of a GOTO or CABxx operation. A label can be 1 - 6 characters
long and must begin with an alpha character. Each TAG label name must
be unique.
Factor 2 must be blank.
The result field must be blank.
Resulting indicators (columns 54 - 59) are not allowed.
Example 11–70 TAG Operation Code Usage
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C LOOPY TAG
This example depicts the use of the TAG operation to define the label
LOOPY.
11–127
Operation Codes
Description
The Test Bit operation compares the bits specified in factor 2 to the
corresponding bits in the result field.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 must be blank.
Factor 2 can contain a literal bit mask or a single-character field which
contains the bit mask used by the TESTB operation. A literal bit mask
identifies the bits as 0 through 7, with 0 as the leftmost bit. The bit mask
must be enclosed in single quotes. For example, to test bits 0, 5, and 6,
enter ’056’ in factor 2. A bit number cannot be specified more than once
in a mask.
If a field name is specified in factor 2, it must be a single-character,
alphameric field, table, or array element. The bits that are on in factor 2
are tested in the result field. If an array element is specified, each element
in the array must be a single-character field. If factor 2 is not a single
character field or literal bit mask, a compilation error will occur.
The result field should be a single-character, alphameric field, table,
or array element. Bit operations are only designed to work on single
character alphameric fields. The bits specified in factor 2 will be tested in
the result field.
At least one resulting indicator (columns 54 - 59) must be specified.
Operation
The TESTB operation tests the bits in the result field which are specified
as on in factor 2.
At least one resulting indicator must be specified. All three resulting
indicators can be used. The indicators are turned on by the TESTB
operation as follows:
• High - Columns 54 - 55
This indicator turns on if each bit specified in factor 2 is off in the
result field (off status).
• Low - Columns 56 - 57
11–128
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C TESTB’04’ WK01 333435
C TESTBLOTTO WINNER 444546
In this example, the first TESTB operation checks bits 0 and 4 in the field
WK01. If both bits are off (0), indicator 33 will be turned on. If the bits
are in a mixed state, one off and one on, indicator 34 will be turned on. If
both bits are on (1), indicator 35 will turn on.
In the second TESTB operation, the bits which are on in the field LOTTO
will be compared to the corresponding bits in the field WINNER. If all bits
which are on in LOTTO are off (0) in WINNER, indicator 44 will be turned
on. If the bits which are on in the LOTTO field are in a mixed state in the
WINNER field, some on and some off, indicator 45 will be turned on. If all
bits which are on in the LOTTO field are also on (1) in the WINNER field,
indicator 46 will be turn on.
11–129
Operation Codes
Description
The Test Zone operation tests the zone of the leftmost character in an
alphameric field.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 must be blank.
Factor 2 must be blank.
The result field is required. It must contain an alphameric field, table
element, array element, or data structure element.
At least one resulting indicator (columns 54 - 59) must be specified.
Operation
The TESTZ operation tests the zone portion of the leftmost character in
an alphameric entry. The resulting indicators are used to indicate the
results of the test. At least one resulting indicator must be specified. All
three resulting indicators can be used. The resulting indicators indicate
the following conditions:
• Plus - Columns 54 - 55
This indicator turns on if the zone of the leftmost character in the
result field is an &, A - I, or has the same zone as an A.
• Minus - Columns 56 - 57
This indicator turns on if the zone of the leftmost character in the
result field is a J - R or has the same zone as a J.
• Zero - Columns 58 - 59
This indicator turns on if the zone of the leftmost character in the
result field does not meet one of the first two conditions.
11–130
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C TESTZ ULP 102030
In this example, the TESTZ operation is used to test the zone portion of
the first character in the field ULP.
11–131
Operation Codes
Description
The TIME operation returns the system time and date.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 must be blank.
Factor 2 must be blank.
The result field is required. It must contain a 1 to 14-digit, zero-decimal,
numeric field. The time and date are returned by the TIME operation
in the format HHMMSSMMDDYYYY. This string is loaded from left
to right into the result field. If the result field contains a 6-digit field,
HHMMSS will be loaded into it. If the result field contains a 14-digit field,
HHMMSSMMDDYYYY will be loaded into it. If the result field contains a
4-digit field, HHMM will be loaded into it.
Resulting indicators (columns 54 - 59) are not allowed.
Operation
The TIME operation obtains the system date and time from the OpenVMS
$ASCTIM system service. The date obtained by the TIME operation may
not be the same as the date available from the UDATE or $UDATE field.
The user has the option of using the REX Utility to set a program date
which can differ from the system date. The program date is accessed via
the UDATE and $UDATE field. See the Migration RPG User’s Guide for
more information on the REX Utility.
The system date can be returned in MMDDYYYY, DDMMYYYY, or
YYYYMMDD format. The format used will depend upon the date format
code placed in column 19 of the Control specification.
11–132
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
IFULTIM DS
I 1 60TIME
I 7 140DATE
C*
C TIME CLOCK 60
C TIME FULTIM
In this example, the first TIME operation will move only the system time
to the field CLOCK, as CLOCK is defined as a 6-digit, numeric field. The
second TIME operation moves the system time and date into the data
structure FULTIM, which is defined as being 14 digits in length.
11–133
Operation Codes
Description
The $TIME operation returns the system time and a non-Year 2000
compliant date. The $TIME opcode is provides backward compatibility for
older applications which are not Year 2000 compliant.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 must be blank.
Factor 2 must be blank.
The result field is required. It must contain a 1 to 12-digit, zero-decimal,
numeric field. The time and date are returned by the $TIME operation
in the format HHMMSSMMDDYY. This string is loaded from left to
right into the result field. If the result field contains a 6-digit field,
HHMMSS will be loaded into it. If the result field contains a 12-digit field,
HHMMSSMMDDYY will be loaded into it. If the result field contains a
2-digit field, HH will be loaded into it.
Resulting indicators (columns 54 - 59) are not allowed.
Operation
The $TIME operation obtains the system date and time from the
OpenVMS $ASCTIM system service. The date obtained by the $TIME
operation may not be the same as the date available from the UDATE or
$UDATE field. The user has the option of using the REX Utility to set a
program date which can differ from the system date. The program date
is accessed via the UDATE and $UDATE field. See the Migration RPG
User’s Guide for more information on the REX Utility.
The system date can be returned in MMDDYY, DDMMYY, or YYMMDD
format. The format used will depend upon the date format code placed in
column 19 of the Control specification.
11–134
Operation Codes
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
ITIMDAT DS
I 1 60TIME
I 7 120DATE
*
C $TIME SAVTIM 40
C $TIME TIMDAT
In this example, the first $TIME operation will move only the HHSS
portion of the system time to the field SAVTIM, as SAVTIM is defined as a
4-digit, numeric field. The second $TIME operation moves the system time
and non-Year 2000 compliant date into the data structure FULTIM, which
is defined as being 12 digits in length.
11–135
Operation Codes
Description
The XFOOT operation sums the elements in a numeric array and places
the total in the result field.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 must be blank.
Factor 2 is required. It must contain the name of a non-indexed, numeric
array.
The result field is required. It must contain a numeric field entry which
will accept the product of the XFOOT operation.
Resulting indicators (columns 54 - 59) are optional. They can be
used to indicate whether the contents of the result field are positive
(columns 54 - 55), negative (columns 56 - 57), or zero (columns 58 - 59)
after the XFOOT operation.
Example 11–75 XFOOT Operation Code Usage
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
*
E AR$ 5 5 0
.
.
.
C XFOOTAR$ TOTAR$ 70
In this example, the XFOOT operation is used to total the elements in the
numeric array AR$. The result of the XFOOT operation is placed in the
field TOTAR$.
11–136
Operation Codes
Description
The Zero-Add operation initializes the result field with the contents of
factor 2.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 must be blank.
Factor 2 is required. It must contain a numeric entry.
The result field is required. It must contain a numeric entry.
Resulting indicators (columns 54 - 59) are optional. They can be
used to indicate whether the contents of the result field are positive
(columns 54 - 55), negative (columns 56 - 57), or zero (columns 58 - 59)
after the Z-ADD operation.
Operation
The Z-ADD operation adds the contents of factor 2 to zero and places the
product in the result field.
Example 11–76 Z-ADD Operation Code Usage
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C Z-ADD24 LOLLY 70
In this example, the Z-ADD operation is used to initialize the field LOLLY
to the value 24.
11–137
Operation Codes
Description
The Zero-Subtract operation initializes the result field with the contents of
factor 2.
Rules
Conditional indicators (columns 7 - 17) are optional.
Factor 1 must be blank.
Factor 2 is required. It must contain a numeric entry.
The result field is required. It must contain a numeric entry.
Resulting indicators (columns 54 - 59) are optional. They can be
used to indicate whether the contents of the result field are positive
(columns 54 - 55), negative (columns 56 - 57), or zero (columns 58 - 59)
after the Z-SUB operation.
Operation
The Z-SUB operation subtracts the contents of factor 2 from zero and
places the product in the result field.
Example 11–77 Z-SUB Operation Code Usage
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C Z-SUB100 POP 70
In this example, the Z-SUB operation is used to initialize the field POP to
the value -100.
11–138
12 Using Indicators
12–1
Using Indicators
12–2
Using Indicators
The remaining sections in this chapter describe each type of indicator and
its usage in a program.
12–3
Using Indicators
The record identifying indicator for a particular record type is set on when
RPG processes a record of that type. For a primary or secondary file,
the record identifying indicator is set on before total time calculations.
For a chained or demand file, the record identifying indicator is set on
immediately after the record is read. In either case, it is set off when the
program reaches the end of the current program cycle (after detail time
output).
Record identifying indicators can be set on or off within the Calculation
specifications.
If the CHAIN or READ operation is used to retrieve a record, the program
does not set the associated record identifying indicator off until the
beginning of the next program cycle. Be careful when performing more
than one CHAIN or READ operation for a file with multiple record types
12–4
Using Indicators
because more than one record identification indicator can be set on during
a single cycle.
Record identifying indicators can be used to condition both detail time
and total time calculation and output operations. The following example
shows how record identifying indicators can be used to condition program
operations:
Example 12–1 Record Identifying Indicators Usage
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456
*
00010FSALES IPE F 120 DISK
00020FREPORT O F 80 OF PRINTER
00030 *
00040ISALES AA 01 1 CJ
00050I 2 50ITEM
00060I 10 15 DESCR
00070I 20 242SALES
00080I 30 342COST
00090I 40 432PROFIT
00100I BB 99
00110 *
00120C 01 SALES SUB COST NET 52
00130C 01 TSALES ADD SALES TSALES 62
00140C 01 TCOST ADD COST TCOST 62
00150C 01 TPROFT ADD NET TPROFT 62
00160 *
00170OREPORT H 201 1P
00180O OR OF
00190O UDATE Y 10
00200O 42 ’JANUARY SALES REPORT’
00210O 64 ’PAGE’
00220O PAGE 68
00230O H 22 1P
00240O OR OF
00250O 4 ’ITEM’
00260O 23 ’DESCRIPTION’
00270O 35 ’SALES’
00280O 47 ’COST’
00290O 60 ’PROFIT’
00300O D 01
00310O ITEM 3 5
00320O DESCR 22
00330O SALES 1 35
00340O COST 1 48
00350O PROFIT1 60
00360O T 1 LR
00370O 6 ’TOTALS’
00380O TSALES1 35 ’$’
00390O TCOST 1 48 ’$’
00400O TPROFT1 60 ’$’
12–5
Using Indicators
• Line 10 indicates that the program will be reading records from the
file SALES. The identification code (columns 21 - 41) on line 40 groups
these records according to a code that represents the month. If the
code for the month is J, the record identifying indicator 01 is set on.
• Lines 120 - 150 use the record identifying indicator 01 to condition
detail time calculations. The calculation are performed each time a
record of the type described on line 40 is read.
• Line 300 uses the record identifying indicator 01 to condition detail
time output. The output operation is performed each time a record of
the type described on line 40 is read.
The output file produced by the program in Example 12–1 might appear
as follows:
Example 12–2 Output generated by Example 12–1
1 2 3 4 5 6
12345678901234567890123456789012345678901234567890123456789012345678
02/04/83 JANUARY SALES REPORT PAGE 1
ITEM DESCRIPTION SALES COST PROFIT
10005 AMMONIA 60.30 50.00 10.30
10982 MATCHES 295.00 205.00 90.00
22650 NUTMEG 209.00 170.00 39.00
TOTALS $564.30 $425.00 $139.30
12–6
Using Indicators
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456
*
00040ISALES AA 01 1 CJ 2 CU 3 CL
00041I AND 4 CY
00050I 1 9 MONTH
00060I 10 15 CODE
00061I AX 98
00070 *
00080ICUSTMST BB 02 1 CA 2 CA
00081I OR 1 CA 2 CB
00082I OR 03 1 CB 2 CB
00060I 1 5 CODE
In this example, the SALES record on lines 40 and 41 uses the AND
qualifier to construct a 4-character record identification condition. In this
case, the record identifying indicator 01 will be turned on if the first 4
positions in the SALES record are JULY.
On lines 80 - 82, the OR qualifier is used to describe three different sets of
record identification conditions which can be used to select the CUSTMST
record. If the first two characters in the CUSTMST record are AA, the
record identification conditions on line 80 are satisfied and indicator 02 is
turned on. If the first two characters in the CUSTMST record are AB, the
record identification conditions on line 81 are satisfied and indicator 02 is
turned on. Note that because no record identification indicator has been
specified on line 81, the program defaults back to the indicator specified
on line 80. If the first two characters in the CUSTMST record are BB, the
record identification conditions on line 82 are satisfied and indicator 03 is
turned on.
12–7
Using Indicators
Field indicators are used to test the value of a field in the following ways:
• To determine if a numeric field is positive, specify a field indicator in
columns 65 - 66 of the Input specification. The indicator will be turned
on if the field’s contents are positive.
• To determine if a numeric field is negative, specify a field indicator in
columns 67 - 68 of the Input specification. The indicator will be turned
on if the field’s contents are negative.
• To determine if a numeric field is zero, specify a field indicator in
columns 69 - 70 of the Input specification. The indicator will be turned
on if the field’s contents are zero.
• To determine if an alphameric field is all blanks, specify a field
indicator in columns 69 - 70. The indicator will be turned on if the
field’s contents are blank.
12–8
Using Indicators
The following example shows how field indicators can be used to condition
a Calculation specification:
Example 12–4 Field Indicator Usage
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890
*
00024IPARTLIS AA 01 1 CF
00025I 2 100INVCDE 112233
.
.
.
00041C 11 ITEM MULT FACT1 ORDER 62H
00042C 22 ITEM MULT FACT2 ORDER H
00043C 33 ITEM MULT FACT3 ORDER H
12–9
Using Indicators
How and when resulting indicators are specified and set is dependent upon
the calculation operation being performed. Not all operations require or
even allow resulting indicators. Chapter 11, Operation Codes, contains
descriptions of all of the RPG operation codes and their related resulting
indicator usage.
12–10
Using Indicators
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
*
00010C HOME COMP VISTOR 102030
00020C 10 ADD 1 WINS
00030C 20 ADD 1 LOSSES
00040C 30 ADD 1 TIES
12–11
Using Indicators
12–12
Using Indicators
12–13
Using Indicators
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456789
*
00010FSALESFILIPE F8000 80 DISK
00020FREPORT O F 80 PRINTER
*
00050ISALESFILAA 01
00060I 01 04 REGIONL8
00070I 05 08 DIST L7
00080I 09 38 SALNAM
00090I 39 44 SALEIDL6
00100I P 45 492SALES
.
.
.
00200C SALES ADD SALTOT SALTOT 92
.
.
.
00300CL6 SALTOT ADD DISTOT DISTOT 92
00310CL7 DISTOT ADD REGTOT REGTOT 92
00320CL8 REGTOT ADD GRAND GRAND 102
.
.
.
00400OREPORT T L6
00410O 20 ’Total for Sales Person:’
00420O SALNAM 51
00430O SALEID 60
00440O SALTOT B 80 ’$ , , . ’
00450OREPORT T L7
00460O 20 ’District Total’
00470O DISTOT B 80 ’$ , , . ’
00480OREPORT T L8
00490O 20 ’Regional Total’
00500O REGTOT B 80 ’$ , , . ’
00510OREPORT T L9
00520O 15 ’Grand Total’
00530O GRAND B 80 ’$ , , . ’
12–14
Using Indicators
12–15
Using Indicators
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890
*
00040ISALES AA 01 1 CJ
00050I 2 5 BRNCH L3
00060I 10 15 SLSPR L3
00070I 20 24 CUSTNOL3
00080I BB 02 1 CF
00090I 1 23 UNIT L3
In this example, the fields BRNCH, SLSPR, and CUSTNO combine to form
the control field. When the data in these fields is compared with the data
in storage obtained from a previous record, indicator L3 is set on if the
data has changed in any of the fields.
The field UNIT has also been assigned the control break indicator L3.
Note that the length of UNIT is equal to the combined length of BRNCH,
SLSPR, and CUSTNO. If the UNIT record is input, the contents of the
field UNIT will be compared to the L3 storage area.
12–16
Using Indicators
12–17
Using Indicators
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456
*
00020FREPORT O F 80 OF PRINTER
.
.
.
00170OREPORT H 201 1P
00180O OR OF
00190O UDATE Y 10
00200O 44 ’SALES REPORT’
00210O 68 ’PAGE’
00220O PAGE 72
00230O H 22 1P
00240O OR OF
00250O 5 ’ITEM’
00260O 23 ’DESCRIPTION’
00270O 41 ’SALES’
00280O 56 ’COST’
00290O 72 ’PROFIT’
00300O D 01
00310O ITEM 3 5
00320O DESC 25
00330O SALES 1 41
00340O COST 1 57
00350O PROFIT1 72
00360O D 1 OF
00370O 30 ’SUBTOTALS’
00380O TSALES1 41 ’$’
00390O TCOST 1 57 ’$’
00400O TPROFT1 72 ’$’
00410O T 1 LR
00420O 30 ’GRAND TOTAL’
00430O TSALES1 41 ’$’
00440O TCOST 1 57 ’$’
00450O TPROFT1 72 ’$’
See Chapter 14, Using Printer Output Files, for a full description of the
overflow routine and overflow indicators.
12–18
Using Indicators
12–20
Using Indicators
1 2 3 4 5
1234567890123456789012345678901234567890123456789012345678
*
IFILEIN AA 02 80 CS
I 01 10 FIELD1
I XX H1 80NCS
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456789
*
IFILEIN AA 01
I 01 50FIELD1 H2
*
C NH2 SQRT FIELD1 FLD2 95
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
*
C FIELD1 SUB 59 FIELD1 H4
C NH4 FIELD2 DIV FIELD1 FIELD1
12–21
Using Indicators
12–22
Using Indicators
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
*
C ASTEK COMP 999 RT
C RT ADD 1 COUNT
12–23
Using Indicators
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456
*
00170OREPORT H 201 1P
00180O OR OF
00190O UDATE Y 10
00200O 39 ’SALES REPORT’
00210O 64 ’PAGE’
00220O PAGE 68
00230O H 22 1P
00240O OR OF
00250O 4 ’ITEM’
00260O 23 ’DESCRIPTION’
00270O 35 ’SALES’
00280O 47 ’COST’
00290O 60 ’PROFIT’
In this example, the output records defined on lines 170 - 180 and
230 - 240 will be output during the first cycle, ensuring that the program
has appropriate headings on the first page. The overflow indicator (OF)
ensures that the headings are repeated on each new page.
12–24
Using Indicators
The following heading lines would be printed on the first page of the report
when the specifications in Example 12–13 are executed during the first
cycle.
Example 12–14 Output generated by Example 12–13
1 2 3 4 5 6
12345678901234567890123456789012345678901234567890123456789012345678
02/04/83 SALES REPORT PAGE 1
ITEM DESCRIPTION SALES COST PROFIT
12–25
Using Indicators
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456
*
00360O T 1 LR
00370O 6 ’TOTALS’
00380O TSALES1 35 ’$’
00390O TCOST 1 48 ’$’
00400O TPROFT1 60 ’$’
The following information will be output after processing the last record in
Example 12–15:
Example 12–16 Output generated by Example 12–15
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890
TOTALS $564.30 $425.00 $139.30
12–26
Using Indicators
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890
*
00050ISALES AA 01 1 CA
00060I 01 04 REGION
00070I 05 08 DIST
00080I 09 38 SALNAM
00090I 39 44 SALEID
00100I P 45 492SALES
00050I BB 02 1 CB
.
.
.
00320CL0 02 REGTOT ADD GRAND GRAND 102
.
.
.
00510OREPORT T L0 02
00520O 15 ’Grand Total’
00530O GRAND B 80 ’$ , , . ’
12–27
Using Indicators
12–28
Using Indicators
1 2 3 4 5 6
12345678901234567890123456789012345678901234567890123456789012
*
00003FMRGIA IP AF 40 40 DISK
00004FMRGIB IS AF 40 40 DISK
.
.
.
00006IMRGIA NS 01 01 CA
00007I 1 1 COD
00008I 2 40KEY M1
00012IMRGIB NS 03 01 CB
00013I 1 1 FUD
00014I 2 40CORE M1
.
.
.
00050C MR MOVE CORE DUP
00051C MR ADD 1 DUPCNT
.
.
.
01410O D 1 MR
01420O 30 ’DUPLICATE CODE: ’
01430O DUP 35
In this example, the fields KEY and CORE serve as match fields (M1)
for the files MRGIA and MRGIB. If the contents of KEY and CORE
match, a record is read from the secondary file (MRGIB) and the MR
indicator is turned on. Turning the MR indicator on will cause the
calculation operations on lines 50 and 51 and the output operations on
lines 1410 - 1430 to be executed.
If the contents of the KEY and CORE fields do not match, a record is read
from the primary file (MRGIA) and the MR indicator is turned off.
12–29
Using Indicators
1 2 3 4 5 6 7
123456789012345678901234567890123456789012345678901234567890123456789012
*
00003FHOOSER IPE F 80 DISK
00004FFROSTY USE F 140 DISK U1
.
.
.
00050C U1 MOVE SNOW MAN
.
.
.
01410OFROSTY D U1
01420O MAN 10
In this example, the file FROSTY will not be available for processing
unless the external indicator U1 is on. If U1 is on, the file will be opened
and the calculation and output operations on lines 50 and 1410 - 1420 will
be performed. If U1 is off, the file will not be opened and the operations
on these lines will be ignored.
12–30
Using Indicators
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
*
C *IN,20 COMP *IN,15 99
C MOVE ’1’ *IN,20
12–31
Using Indicators
12.6.2 *INxx
The special word *INxx is a predefined, single-character, alphameric field
where xx represents any valid RPG indicator. Like *IN array elements,
*INxx fields can contain only the characters 0 or 1.
*INxx fields can be used anywhere any other single-character, alphameric
field can be used.
In the following example, the value of the indicator 20 is checked in an IF
operation. If the indicator is on (value = 1), the IF construct is executed.
If the indicator is off (value = 0), the IF construct is bypassed.
Example 12–21 *IN Indicator Array And Element Usage
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
*
C MOVE ’1’ ON 1
C MOVE ’0’ OFF 1
.
.
.
C *IN,20 IFEQ ON
C READ TRIPLX 99
C END
12–32
13 Using DISK Files
The file designation used by an RPG program defines the method by which
the program processes the file. The file designations include:
• Primary (P)
• Secondary (S)
• Record-address (R)
• Chained (C)
• Pre-execution-time table (T)
• Demand (D)
• Full-procedural (F)
13–1
Using DISK Files
This chapter describes the use of DISK files within an RPG program. The
Migration RPG Screen Format Reference Manual describes the use of a
WORKSTN device.
13–2
Using DISK Files
1 2 3 4 5 6
Fourth record
13–3
Using DISK Files
1 2 3 4 5 6 Relative Record
Number
A B D C
| Record |
An index key value is a field within each record that is defined by its
relative location within the record and by its length. The index key value
is the primary means of locating records within the file. For example,
an employee’s badge number could be used as the index key value for
an employee record. The index key value in Figure 13–4 is the first six
characters in the record or 768979.
13–4
Using DISK Files
Key Data
| Record |
13–5
Using DISK Files
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456
*
FSHASTA IPE F 60 DISK
13–6
Using DISK Files
The following example shows how to specify a primary input file, ZONK
with fixed-length records 120 bytes long. The file organization is indexed
with its index key in packed-decimal data format.
Example 13–2 File Description specification for a primary sequential
file - Sequential access by key
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456
*
FZONK IPE F 120 3PI 1 DISK
Both methods permit the programmer to limit the records which the
program can access.
To access a file sequentially within limits, make the following entries in
the File Description specifications:
• Columns 7 - 14 (file name) - specify the name of the data file.
• Column 15 (file type) - specify I or U to indicate whether the file is to
be opened for input or for update.
• Column 16 (file designation) - specify P, S, D, or F to indicate whether
the input file is primary, secondary, demand, or full-procedural.
• Column 19 (record format) - specify F or V to describe the record
format (fixed-length or variable).
• Columns 24 - 27 (record length) - specify the length of fixed-length
records or the maximum length of variable-length records.
13–7
Using DISK Files
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456
*
FEMPMST IP F 180L 8AI 1 DISK
13–8
Using DISK Files
Figure 13–5 presents an example of how limits file processing works. The
first record in the record-limits file causes the program to retrieve those
records whose keys are greater than or equal to the low key (C) and less
than or equal to the high key (E). When the program reaches a record with
a key value greater than E or reaches end-of-file, it reads the next record
from the record-limits file to get a new low and high range. The second
record in the record-limits file causes the program to retrieve those records
whose keys are greater than or equal to the low key (A) and less than or
equal to the high key (D). The indexed file is processed until it reaches the
end of the record-limits file or the program terminates.
Figure 13–5 Sequential File Access Within Limits
C data
F data
| Record |
Rules
• In the record-limits file, only one set of limits can be specified per
record.
• The record length of the limits file must be at least twice the length of
the indexed file key field.
• The low key must begin in character position 1, and the high key must
immediately follow the low key.
• The length of the high and low keys must be the same and must be
equal to the length of the key field in the file to be processed.
• If the key fields being used are numeric, the format of the fields in the
data file and the limits file do not have to match. For example, the
limits file could use a zoned-decimal or trailing numeric format while
the indexed file used a packed-decimal format. If the key formats
differ, the key field format must be indicated by an entry in column 31
of the File Description specifications and the unpacked length of each
field must match.
• Numeric keys cannot contain blanks; use leading zeros if it is
necessary to fill a numeric key field.
• Alphanumeric keys can contain blanks.
13–9
Using DISK Files
When specifying a limits file, the following entries must be made in the
Extension specifications:
• Columns 11 - 18 (from file name) - specify the name of the record-limits
file.
• Columns 19 - 26 (to file name) - specify the name of the file to be
processed by the record-limits file.
The following example shows how to specify the File Description and
Extension specifications for processing a file sequentially within limits. In
the example, the limits file EMPLMT is associated to the indexed data file
EMPMST. The EMPMST file will be processed within the limits obtained
from the EMPLMT file.
13–10
Using DISK Files
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456
*
FEMPLMT IRE F 16 8 EDISK
FEMPMST IP F 180L 8AI 1 DISK
E EMPLMT EMPMST
13–11
Using DISK Files
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
H
FEMPMST IF F 132L 8AI 1 DISK
FREQUEST CD F 32 WORKSTN
.
.
.
IEMPMST AA 01
I 1 80BADGE
.
.
.
IREQUEST BB 02
I 1 80BADGE
.
.
.
C READ REQUEST 99
C N99 BADGE SETLLEMPMST
C N99 READ EMPMST 99
13–12
Using DISK Files
13–13
Using DISK Files
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
00001H
00010FCHKLST IPE F 10 DISK
00020FINVENTRYUC F 120R DISK
00030FREPORT O F 80 OF PRINTER
00040 *
00050ICHKLST AA 01
00060I 1 50ITMNUM
00070I 6 100QTY
00080IINVENTRYAB 02
00090I 1 50ITMNUM
00100I P 21 250QTYSLD
00110I P 26 300VALUE
00120 *
00130C ITMNUM CHAININVENTRY 50
00140C *IN50 IFNE ’1’
00150C ADD QTY QTYSLD
00160C VALUE MULT QTY SALE 70
00170C SETON 40
00180C EXCPT
00190C SETOF 40
00200C END
00210 *
00220OINVENTRYE 40
00230O ITMNUM 5
00240O QTYSLD 25P
00250OREPORT H 22 1P
00260O OR OF
00270O 22 ’STORE PURCHASES’
00280OREPORT H 1P
00290O OR OF
00300O 06 ’ITEM #’
00310O 22 ’QUANTITY SOLD’
00320O 30 ’PRICE’
00330O D 01N50
00340O ITMNUM 05
00350O QTYSLD 18
00360O SALE 1 31 ’$’
00370O D 01 50
00380O ITMNUM 05
00390O 20 ’ITEM NOT FOUND’
13–14
Using DISK Files
13–15
Using DISK Files
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
00010FSTORES IP F 130 DISK
00020FGROCER IC F 100R10AI 1 DISK
00030FREPORT O F 30 PRINTER
00040ISTORES AA 01
00050I 1 11 STORE
00060I 12 210ITEM
00070IGROCER AB 02
00080I 1 100REC
00090I 11 130COUNT
00100I 14 17 VALUE
00110C ITEM CHAINGROCER 50
00120C 50 SETON LR
00130OREPORT H 22 1P
00140O 22 ’STORE PURCHASES’
00150O D 01N50
00160O STORE 14
00170O COUNT 20
00180O VALUE 27
00190O D 01 50
00200O ITEM 10
00210O 25 ’ITEM NOT FOUND’
Figure 13–6 shows how an addrout file is created from a data file using
the SORT/PROCESS=ADDRESS command. The SORT/MERGE Utility is
discussed in detail in the OpenVMS SORT/MERGE Utility Manual.
13–16
Using DISK Files
SORT/PROCESS=ADDRESS/KEY=(POS:1,SIZ:1) −
FUZZ.DAT ADDROUT.DAT
D data 47382 Address of C
The following entries are required in the File Description specification for
the data file which is associated to the addrout file:
• Columns 7 - 14 (file name) - specify the name of the data file.
• Column 15 (file type) - specify I or U to indicate whether the file is to
be opened for input or update.
• Column 16 (file designation) - specify P or S to indicate that the file
named in columns 7 - 14 is primary or secondary.
• Column 19 (record format) - specify F or V to describe the record
format (fixed-length or variable).
• Columns 24 - 27 (record length) - specify the length of fixed-length
records or the maximum length of variable-length records.
• Column 28 (mode) - specify R to indicate random record access.
• Columns 29 - 30 (key length) - specify the length of the key field if an
indexed file is being accessed.
• Column 31 (record address type) - specify I to cause the program to
access the file according to the addrout file.
• Column 32 (file organization) - specify I if an indexed file is being
accessed.
• Columns 40 - 43 (device code) - specify DISK.
• Columns 71 - 72 (external indicators) - external indicators U1 - U8 can
be specified to indicate whether the file is to be accessed. An external
indicator based file is accessed if the external indicator is on.
The following example depicts the sort command used to create an addrout
file and a program which uses the addrout file. The sort command uses the
/PROCESS=ADDRESS qualifier to create an address output file ordered
by zip code. The program then uses the addrout file to read the data file
TOWNINFO and produce a listing of towns by zip code. Note that both
13–18
Using DISK Files
the addrout and data file are defined in the File Description specificiations
and that an Extension specification ties the two files together.
Example 13–8 Random access by addrout file
$ SORT/PROCESS=ADDRESS/KEY=(POS:26,SIZ:5) -
SYS_FILE:TOWNINFO.DAT SYS_SCRATCH:ADDROUT.DAT
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
H
FADDROUT IRE F 6 6IT EDISK
FTOWNINFOIP F 120R 6II 30 DISK
FREPORT O F 80 80 OF PRINTER
E ADDROUT TOWNINFO
ITOWNINFOAA 01
I 1 12 TOWN
I 13 14 STATE
I 15 25 COUNTY
I 26 30 ZIP
OREPORT H 202 1P
O OR OF
O 12 ’TOWN LIST’
O UDATE Y 70
O PAGE 80
OREPORT D 01
O TOWN 12
OREPORT D 01
O COUNTY 11
OREPORT D 3 01
O STATE 02
O ZIP 10
13–19
Using DISK Files
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
*
FFPFJ01 IF F 80L 5AI 2 DISK
*
IFPFJ01 XX 01
I 1 1 XSTAT
I 2 6 KEYFLD
I 7 11 FLD1
I 12 16 FLD2
*
.
.
.
*
C KEYFLD CHAINFPFJ01 50
C 50 GOTO END
*
C LOOP TAG
C READ FPFJ01 90
C 90 GOTO END
.
.
.
*
C END TAG
C SETON LR
*
.
.
.
13–20
Using DISK Files
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
H
*
FOUTI24 IP F 24 DISK
FOUT60A O F 24 DISK
*
IOUTI24 AA 01
I 1 3 PN
I 4 10 PNAME
I 11 12 WHOUSE
I 13 17 COLOR
I 18 200WEIGHT
I 21 240QTY
*
OOUT60A D 01
O PN 3
O PNAME 10
O WHOUSE 12
O COLOR 17
O WEIGHT 20
O QTY 24
13–21
Using DISK Files
Example Example 13–10 can also be used to create a relative file. Relative
files must always use a fixed-length record format. To add records to
specific locations within a relative file, the file must first be populated with
records.
13–22
Using DISK Files
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
H
*
FOUTI24 IP F 24 DISK
FOUT60I O F 24 3AI 1 DISK
*
IOUTI24 AA 01
I 1 3 PN
I 4 10 PNAME
I 11 12 WHOUSE
I 13 17 COLOR
I 18 200WEIGHT
I 21 240QTY
*
OOUT60I D 01
O PN 3
O PNAME 10
O WHOUSE 12
O COLOR 17
O WEIGHT 20
O QTY 24
This example demonstrates how to create a single key indexed file. During
program startup, the indexed output file OUT60I.DAT will be created. The
file will contain a single ascending key. The key will start in position 1
and have a length of 3 characters. The program reads data from the input
file OUTI24.DAT and writes it to the indexed file OUT60I.DAT.
By default Migration RPG creates indexed files with a primary key that
does not allow duplicates. If duplicate primary keys are desired, or if the
file needs to be defined with additional keys, create the file using the DCL
CREATE utility with the /FDL parameter. Data can then be added to
the file by defining is as an output add file (A in column 66 of the File
specification).
13–23
Using DISK Files
The following entries must alse be made in the file’s Output specification:
• Columns 7 through 14 (file name) - define the output file name.
• Columns 16 through 18 - specify ADD to identify the record to be
added.
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456
H
*
FINFO IP F 80 DISK
FLOG O F 80 DISK A
*
IINFO AA 01
I 1 80 DATA
*
OLOG DADD 01
O DATA 80
13–24
Using DISK Files
13–25
Using DISK Files
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456
H
*
FNEWDATA IP F 80 DISK
FMASTER UC F 80R 5AI 2 DISK A
*
INEWDATA AA 01
I 1 1 STATUS
I 2 6 KEY
I 7 80 DATA
*
IMASTER XX
*
C 01 KEY CHAINMASTER 99
*
OMASTER DADD 01N99
O STATUS 01
O KEY 06
O DATA 80
13–26
Using DISK Files
To update a record, retrieve the record to change, change the contents, and
then write the record back to the file. Only the fields to be changed need
to be specify in a record. The remainder of the record is rewritten using
the data that was read into the input buffer. A data structure can be used
to update a record instead of outputting individual fields.
Example 13–14 Updating records in an indexed file
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
H
*
FTRANSACTIP F 25 DISK
FMASTER UC F 80R21AI 1 DISK
*
ITRANSACTAA 01
I 1 20 NAME
I 21 25 NEW#
*
0010 IMASTER BB 10 1 CA
0020 I CC 20 1 CB
0030 I DD 99
*
C N01 GOTO END
*
* Update record type 10.
*
C MOVEL’A’ KEY 21
C MOVE NAME KEY
C KEY CHAINMASTER 99
C N99 EXCPT
*
* Update record type 20.
*
C MOVEL’B’ KEY
C MOVE NAME KEY
C KEY CHAINMASTER 99
C N99 EXCPT
*
C END TAG
*
OMASTER E 01 10
O NEW# 40
OMASTER E 01 20
O NEW# 60
13–27
Using DISK Files
Define both Input and Output specifications for the file to be updated.
Enter ADD in columns 16 through 18 of those Output specifications that
identify the records to be added. The output records without ADD in
columns 16 through 18 identify those records to be updated.
Records in an indexed file can be randomly updated by key, sequentially,
or both randomly and sequentially if the file is defined as a full-procedural
file. To specify an indexed full-procedural file to be processed in the
update mode, make the following entries for the file in its File Description
specification:
• Column 15 (file type) - specify U to indicate that the file is to be opened
for update.
• Column 16 (file designation) - specify F to indicate a full-procedural
file.
• Column 32 (file organization) - specify I to indicate an indexed file.
The last record retrieved from the file is the one that is deleted when
DEL is specified in columns 16 - 18 of the Output specification. There is
no need to describe any fields in the output record because the operation
deletes the entire record.
Example 13–15 Deleting records from an indexed file
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
H
*
FDELETE IP F 20 DISK
FMASTER UC F 80R20AI 2 DISK
*
IDELETE AA 01
I 1 20 NAME
*
IMASTER BB
*
C 01 NAME CHAINMASTER 99
C N99 EXCPTREMOVE
*
OMASTER EDEL REMOVE
13–28
Using DISK Files
13.11.2 Checking Record Sequence for More Than One Record Type
The fields in a record of one type can be in a different order than the
fields in other record types in the same file. For example, in a payroll file
consisting of two different record types, one type represents commission
payment and the other type represents salary. All employee records are
to be in ascending sequence according to district (DSTRCT). Records
in a district are to be in ascending sequence according to department
and employee number. Therefore, three fields (DSTRCT, DEPT, and
EMPNUM) must be checked in each record. The matching field value M3
is assigned to DSTRCT, the most important field; M2 is assigned to DEPT,
the next most important field; and M1 is assigned to EMPNUM, the least
important field. Refer to the following example:
13–29
Using DISK Files
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456
*
IPAYROLL AA 01 80 CC
I 1 3 DEPT M2
I 6 7 DSTRCT M3
I 14 152COMM
I 25 27 EMPNUM M1
I BB 02 80 CS
I 1 3 DEPT M2
I 8 9 DSTRCT M3
I 13 172SALARY
I 25 27 EMPNUM M1
First, the program determines the record type. Then, it looks at the
matching fields for the same record type.
In the preceding example, the same three matching fields (DSTRCT,
DEPT, and EMPNUM) appear in both record types and are the same
length.
The length of matching fields assigned to the same match code must be
the same length for each record type. Table 13–1 shows that this is true
for the previous example:
Matching fields need not be specified for all the record types in a file.
13–30
Using DISK Files
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456
*
IPAYROLL AA 01 80 CC
I OR 02 80 CS
Specify common fields only once because they apply to both record types.
The field-record-relation indicators specified in columns 63 and 64 of the
Input specification identify the fields unique to a particular record type.
Therefore, the COMM field in the following example is associated with
record type 01 and the SALARY field is associated with record type 02.
The DSTRCT, DEPT, and EMPNUM matching fields are used in checking
the sequence of the records in the PAYROLL file, and the matching-
field values M1, M2, and M3 are described only once in columns 61 and
62 without any field-record-relation indicators in columns 63 and 64.
Therefore, the matching fields and their values apply to both record types
(01 and 02) as shown in the following example:
Example 13–18 Matching record fields and field-record-relation
indicators
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456
*
IPAYROLL AA 01 80 CC
I OR 02 80 CS
I 1 3 DEPT M2
I 8 9 DSTRCT M3
I 25 27 EMPNUM M1
I 14 152COMM 01
I 13 172SALARY 02
If one of the matching fields is in a different record position for each record
type, matching field entries must be assign, as shown in the following
example:
Example 13–19 Matching record fields with field-record-relation
indicators
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456
*
IPAYROLL AA 01 80 CC
I OR 02 80 CS
I 1 3 EMPNUM M1
I 20 21 DSTRCT M3
I 6 72COMM 01
I 10 12 DEPT M201
I 5 7 DEPT M202
I 10 142SALARY 02
For a 01 record type, matching field DEPT is in field location 10 - 12. For
a 02 record type, matching field DEPT is in field location 5 - 7.
13–31
Using DISK Files
Records with and without matching fields can be combined in the same
file. Records without matching fields are processed before records with
matching fields. If two or more of the records being compared have no
matching fields, selection of those records is determined by the priority of
their files, as follows:
• The records in primary files are processed before the records in
secondary files.
• The records in secondary files are processed in order of appearance in
the File Description specifications.
Table 13–2 shows that the matching fields from a primary file are
compared with the matching fields from a secondary file to select records
in ascending sequence. The letters represent the data in the matching
fields.
Figure 13–7 shows the logic flow when a program uses matching fields to
do multifile processing. A keyed list follows the figure.
13–32
Using DISK Files
Compare (3)
match fields. Process A
Cycle n
(4) Record 2
C
Compare (5)
match fields. Process B
Cycle n + 1
(6) Record 2
D2
Compare (7)
match fields. Process C
Cycle n + 2
(8) Record 3
D1
Compare (9)
match fields. Process D1
Cycle n + 3
13–33
Using DISK Files
(10) Record 4
F
Compare (11)
match fields. Process D2
Cycle n + 4
(12) Record 3
X
Compare (13)
match fields. Process F
Cycle n + 5
13–34
Using DISK Files
10 The fourth record of the primary file is read and the matching field (F)
is located.
11 The contents of the matching field (D2) of the second record in the
secondary file are compared with the contents of the matching field (F)
of the fourth record in the primary file. D2 is selected.
12 The third record of the secondary file is read and the matching field
(X) is located.
13 The contents of the matching field (F) of the fourth record in the
primary file are compared with the contents of the matching field (X)
of the third record in the secondary file. F is selected. Because the
primary file is now at its end, the remaining records in the secondary
file (X and Z) are processed in order of appearance.
When the matching fields in a primary file match one or more of the
matching fields in the secondary files, RPG sets the matching-record (MR)
indicator on before detail-time calculations. The MR indicator can be used
to condition calculation and output operations for the record just selected.
The indicator remains on for one complete program cycle. It is set off if
the record selected for processing contains no matching fields. A record
selected using the FORCE operation code causes the MR indicator to
remain off for one program cycle while the forced record is processed.
RPG processes matching records for two or more files in the following
ways:
• When a record from the primary file matches a record from the
secondary file, the record from the primary file is processed before
the record from the secondary file is processed. The record-identifying
indicator that identifies the record type just selected is on at the time
the record is processed.
• When records from ascending files do not match, the program
processes the record with the lowest matching field content first.
• When records from descending files do not match, the program
processes the record with the highest matching field content first.
• A record type that has no matching field specification is processed
immediately after the previous record is processed. In this case, the
MR indicator is set off. If this record type is the first in the file, the
program processes this record first, even when it is not in the primary
file.
• The matching of records makes it possible to enter data from primary
records into their secondary records because the program processes
the record from the primary file before matching the record from the
secondary file. However, the transfer of data from the secondary record
to matching primary records can be done only when look-ahead fields
are specified.
13–35
Using DISK Files
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456
H
*
FRECI99A IP AF 80 DISK
FRECI99B IS F 80 DISK
FRECI99C IS F 80 DISK
FOUTPUT O F 80 DISK
*
IRECI99A 01 80 C1
I 1 80 TEXT
I 1 2 MATCH M1
I 02 80 C2
I 1 80 TEXT
*
IRECI99B 03 80 C3
I 1 80 TEXT
I 1 2 MATCH M1
I 04 80 C4
I 1 80 TEXT
*
IRECI99C 05 80 C5
I 1 80 TEXT
I 1 2 MATCH M1
I 06 80 C6
I 1 80 TEXT
*
OOUTPUT D N1P
O TEXT 80
Table 13–3 lists the contents of the matching fields for all three files:
primary, first secondary, and second secondary. Field values with A after
the value represent values from the primary file. Field values with B after
the value represent values from the first secondary file. Field values with
C after the value represent values from the second secondary file.
13–36
Using DISK Files
Table 13–4 lists the steps involved in processing the files in Table 13–3
and those indicators that must be set on for the operation to occur.
13–37
Using DISK Files
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456789
H
*
FIDXI01 IP F 24 4AI 21 DISK
FIDXJ01 IS F 24 3AI 1 DISK 01
FIDXK01 IS F 24 2AI 11 DISK 02
FIDX03A O F 24 DISK 01
*
IIDXI01 AA 01
I 1 3 PN
I 4 10 PNAME
I 11 12 WHOUSE
I 13 17 COLOR
I 18 200WEIGHT
I 21 240QTY
*
IIDXJ01 BB
I 1 3 PN
I 4 10 PNAME
I 11 12 WHOUSE
I 13 17 COLOR
I 18 200WEIGHT
I 21 240QTY
*
IIDXK01 CC
I 1 24 FIELDS
*
IFIELDS DS
I 1 3 PN
I 4 10 PNAME
I 11 12 WHOUSE
I 13 17 COLOR
I 18 200WEIGHT
I 21 240QTY
*
OIDX03A D N1P
O FIELDS 24
13–38
Using DISK Files
ends with an EXCPT operation on the same file. This results in a new
record being added to the file, for example the BAR record. Continuing
with the normal logic cycle, the program enters detail time and the record
selected for input has become the BAR record which was just written
instead of the expected FOO record. The same buffer is used for both
input and output. When the BAR record is written, the record buffer is
overwritten and its previous contents lost so that when it is time for field
extraction to occur, the wrong record is found.
There are a number of workarounds that can be used. The ADD records
could be written to a distinct output file and merged with the master files
outside of the application. Or, total-time processing can be used to save
the record to be written and set an indicator on. Then, during detail-time
processing, use the indicator to trigger the EXCPT operation. Because
the fields of the input record have been populated by this time, no conflict
occurs with a single record buffer.
The best alternative is to open two streams to the same file and have two
F specifications which essentially refer to the same file. Normal input
processing takes place using one stream and all ADD processing occurs on
the other stream. Because a record buffer is allocated for each file, two
buffers are created in this scheme, and no conflict occurs. Both files need
to use the file sharing option (S in column 68 of the F specifications) in
this case.
Only one update is allowed for each logic cycle for update files other than
demand and chained files.
13–39
14 Using Printer Output Files
Printer files give the programmer a quick and easy way to create
formatted reports. RPG provides the programmer with several features
which aid in report generation. Sections 14.2 and 14.3 describe these
features and explain how to use them.
Note: RPG printer files contain all the print control characteristics
required to properly format a report. The default DCL PRINT
command causes the insertion of a form-feed character when the
form nears the end of a page. In some cases, this may cause blank
pages to be inserted in the middle of a report. To suppress the
insertion of form-feed characters, use the /NOFEED qualifier on
the PRINT command when printing printer output files created by
RPG programs, or set the bottom margin of the form type being
used to 0 with the DCL command DEFINE/FORM.
$ PRINT/NOFEED PAYBACK.LIS
- or -
$ DEFINE/FORM/MARGIN=(BOTTOM=0) DEFAULT 0
14–1
Using Printer Output Files
14–2
Using Printer Output Files
14–3
Using Printer Output Files
For complete information on how to use these special words, see Chapter 9,
Output Specification (O).
14–4
Using Printer Output Files
To specify the number of lines to skip, make the following entries in the
Output specification:
• Columns 19 - 20 (skip before)—specifies the line number to skip to
before printing a line.
• Columns 21 - 22 (skip after)—specifies the line number to skip to after
printing a line.
If both spacing and skipping columns are made for the same line, RPG
formats the output in the following order:
1 Skip before
2 Space before
3 Print the output line
4 Skip after
5 Space after
When an OR line is specified for an output print record, the space and
skip entries of the preceding line are used. If space and skip requirements
differ from the preceding line, enter space and skip entries on the OR line.
The skip entry cannot exceed the entry for forms length (columns 18 - 19
of the Line Counter specification). If there is no Line Counter specification,
the skip entry cannot exceed the default of 66 lines.
Specifying a skip before entry past the overflow line causes RPG to set on
the overflow indicator.
If a skip before entry is specified on the same line number that the printer
is currently on, no skipping takes place.
If a skip before entry is specified to a line number less than the current
line number, the printer advances to that line number on the next page.
Note: If the line printer listing of a printer output file includes an
unexpected blank page at the end of the file, use the DCL
PRINT/NOFEED command to prevent the default OpenVMS
printer settings from overriding the forms control information
embedded in an RPG printer file. Another fix for this problem is
to set the bottom margin of the form type being used to 0 with the
DEFINE/FORM command. For example:
DEFINE/FORM/MARGIN=(BOTTOM=0) DEFAULT 0
14–5
Using Printer Output Files
Example 14–1 prints TOP on line 1, TEST LINE on line 7, PRINT TWICE
FOR BOLDING on line 13, and the fields beginning on line 16.
Example 14–1 Sample Report Program using Spacing and Skipping
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456789
*
OREPORT H 1P
O 41 ’TOP"
O H 320411 1P
O 44 ’TEST LINE’
O H 0 1P
O 30 ’PRINT TWICE FOR BOLDING’
O H 15 1P
O 30 ’PRINT TWICE FOR BOLDING’
O D 1 N1P
O DESCR 18
O STOCK# 26
O ONHANDZ 31
O PRICE K 39 ’$’
Sample output from Example 14–1 might look like the following:
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456789
1 TOP
2
3
4
5
6
7 TEST LINE
8
9
10
11
12
13 PRINT TWICE FOR BOLDING
14
15
16 1 LB CARROTS VEG1MQ 47 $.79
17 6 PACK SODA DRNK2A 40 $1.48
18 1 LB BUTTER DAR0BT 38 $1.59
19 STEAK MET0 22 $3.15
20 HEAD LETTUCE VEG1WQ 63 $.35
14.5.1 Printing Lines Before Reading the First Record: First-Page Indicator
Use the indicator 1P to condition those heading lines which should be
printed before RPG processes the first record. The indicator 1P can
be used to condition entire records or individual fields within a record.
Specify the indicator 1P just like any other indicator in columns 24 - 25,
27 - 28, or 30 - 31 of the Output specification.
14–6
Using Printer Output Files
For complete information on how to use the indicator 1P, see Chapter 12,
Using Indicators, and Chapter 9, Output Specification (O).
14–7
Using Printer Output Files
Rules
• Spacing past the overflow line sets the overflow indicator on.
• Skipping past the overflow line to any line on the same page sets the
overflow indicator on.
• Skipping past the overflow line to any line on the new page does
not set the overflow indicator on unless the skip is specified past the
overflow line on the new page.
• A skip to a new page specified on a line not conditioned by an overflow
indicator sets the overflow indicator off before the form advances to a
new page.
• An overflow indicator can appear on either line of an AND or an OR
relationship. In an AND relationship, the overflow indicator must
appear on the main specification line for that line to be considered
an overflow line. In an OR relationship, the overflow indicator can be
specified on either the main specification line or the OR line. However,
only one overflow indicator can be associated with one group of output
indicators.
• If an overflow indicator is used on an AND line, the line is not an
overflow line. In this case, the overflow indicator is treated like any
other output indicator.
• An overflow indicator cannot condition an exception line (E in column
15 of the Output specification), but can condition fields within the
exception record.
In Example 14–2, the length of a page is 15 lines. The overflow line is line
12. When the overflow line is reached, the overflow indicator is set on,
which conditions the heading line that prints the date, report title, and
page number at the top of each page.
14–8
Using Printer Output Files
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456789
H
FINPUT IP F 80 80 DISK
FREPORT O F 132 132 OF LPRINTER
L*
LREPORT 15FL 12OL
I*
IINPUT NS 01
I 1 5 ZIP
I 10 150CEN30
I 16 210CEN40
I 22 270CEN50
I 28 330CEN60
I 34 390CEN70
I 40 450CEN80
I 46 47 STATE
I 48 59 COUNTY
I 63 74 TOWN
O*
OREPORT H 202 1P
O OR OF
O UDATE Y 12
O 47 ’SOUTHERN NEW HAMPSHIRE’
O 53 ’TOWNS’
O PAGE 77
O*
O D 1 01
O TOWN 13
O COUNTY 26
O STATE 30
O CEN80 J 38
O CEN70 J 46
O CEN60 J 54
O CEN50 J 62
O CEN40 J 70
O CEN30 J 78
14–9
Using Printer Output Files
A sample of the output from Example 14–2 might look like the following:
Example 14–3 Sample Output from Report using an Overflow Indicator
1 2 3 4 5 6 7
12345678901234567890123456789012345678901234567890123456789012345678901234567
12/14/1991 SOUTHERN NEW HAMPSHIRE TOWNS 1
Hampstead Rockingham NH 3,785 2,401 1,261 823 823 775
Kingston Rockingham NH 4,111 2,882 1,672 1,002 1,002 1,017
Litchfield Hillsborough NH 4,150 1,420 721 341 341 286
Newmarket Rockingham NH 4,290 3,361 3,153 2,640 2,640 2,511
Atkinson Rockingham NH 4,397 2,291 1,017 434 434 407
Rye Rockingham NH 4,508 4,083 3,244 1,246 1,246 1,081
Hollis Hillsborough NH 4,679 2,616 1,720 996 996 879
Peterborough Hillsborough NH 4,895 3,807 2,963 2,470 2,470 2,521
Raymond Rockingham NH 5,453 3,003 1,867 1,340 1,340 1,165
14–10
Using Printer Output Files
Rules
• To fetch the overflow routine for each record in an OR relationship,
specify F (fetch overflow) in column 16 for each OR line.
• An overflow indicator cannot be specified in columns 23 - 31 on the
same line with F (fetch overflow) in column 16.
• The fetch overflow routine will not automatically cause the form to
advance to the top of the next page. The form will only be advanced if
a heading or detail line conditioned by the overflow indicator specifies
a skip to a line number which is less than the current print line.
To decide when to fetch the overflow routine, study all possible overflow
situations and count lines, spaces, and skips to determine what happens
when an overflow occurs.
14–11
Using Printer Output Files
In Example 14–4, all of the report detail is output at total time based on
the control break indicator L2. Since a large number of lines are output
at the same time, this could cause data to be printed past the end of the
form. To prevent this from occurring, the fetch overflow routine is called
every third or fourth line to check for the overflow condition.
Example 14–4 Sample Report Program using Fetch Overflow
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456789
*
H
FINPUT IP AF 234R I DISK
FADROUT IR AF 768 3 3IT EDISK
FUNITPRODIC F 256 256R 3AI 1 DISK
FPRINT O F 132 OF PRINTER
E ADROUT INPUT
E NUM 48 7 0
E NM1 12 7 0
E NM2 12 7 0
E NM3 12 7 0
E NM4 12 7 0
E CST 48 9 2
E CT1 12 9 2
E CT2 12 9 2
E CT3 12 9 2
E CT4 12 9 2
E YM 48 4 0
E YM1 12 4 0
E YM2 12 4 0
E YM3 12 4 0
E YM4 12 4 0
E COST 4 8 2
E USA 66 2
E INS 10 6 0
E MDL 10 3
E*
14–12
Using Printer Output Files
14–13
Using Printer Output Files
14–14
Using Printer Output Files
14–15
Using Printer Output Files
14–16
Using Printer Output Files
14–17
Using Printer Output Files
14–18
Using Printer Output Files
14–19
15 Using Tables and Arrays
RPG supports two types of tables which are used to locate a specific data
item quickly and easily.
• Single tables—consist of one group of similar entries. When searching
a single table, the result of the search is whether the item being
searched for is present in the table. If the searched-for item is found,
that entry becomes the current entry.
• Related tables—are two tables that contain associated data elements.
This means that the data element in the second table is somehow
related to the corresponding data element in the first table. For
example the first table could be a list of labor codes used in processing
warranties for a product. The corresponding data in the second table
could described the time allowed in hours for the repair operation.
When looking up information in related tables, the first table is
searched to see if the entry is present. If the entry is found, RPG
retrieves the corresponding entries from both tables and makes them
available as the current entries.
15–1
Using Tables and Arrays
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890123
H
FINPUT IPE F 50 DISK
FREPORT O F 132 OF PRINTER
E TABA 1 5 3
IINPUT NS 01
I 1 3 ITEM
C ITEM LOKUPTABA 10
OREPORT H 202 1P
O OR OF
O 24 ’Sample Table Program ’
O 72 ’Page: ’
O PAGE Z 77
O*
O D 01
O 4 ’Item’
O ITEM 8
O 10 31 ’was found in the table’
O N10 33 ’was not found in the tab’
O N10 35 ’le’
** TABA
AAA
BBB
CCC
DDD
EEE
15–2
Using Tables and Arrays
General Rules
• The first entry must begin in character position 1.
• All entries must be contiguous, with no space between entries, as
shown in Example 15–2.
• Entries cannot span record boundaries. Therefore, the length of an
entry is limited to the device’s maximum record length. If a related
table is defined using the alternating format, corresponding entries
cannot exceed the maximum record length.
• Each input record, except the last, must have the same number of
entries. The last record can be shorter to accommodate an uneven
number of entries.
15–3
Using Tables and Arrays
Compile-Time Rules
• The first record must be preceded by a delimier record containing
either double slashes ( // ) and a blank or double asterisks ( ** ) and a
blank in character positions 1 - 3. Because these strings are delimiters,
records in a compile-time table cannot contain either of these three
characters in positions 1 - 3.
Table delimiters must be consistent within a program. The compiler
will interpret the first delimiter found as the default delimiter for the
remainder of the program. I.E: if the first delimiter encountered is "**
", all remaining delimiters must also be "** ".
15–4
Using Tables and Arrays
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890123
E TABA 6 6 5
.
.
.
** TABA
637419231290343728441937510306
\ /\ /\ /\ /\ /\ /
1 2 3 4 5 6 <-- Element
The table in Example 15–2 consists of six entries in a record, and each
entry is five characters long.
When creating table input records for related pre-execution-time and
compile-time tables in alternating format, the entry for the first table
must be followed immediately by the corresponding entry for the second
table.
Example 15–3 defines the related tables TABA and TABB. The first record
contains the first five entries for both TABA and TABB. The second record
contains the last four entries for the tables. In this example, each entry
in TABA is alphameric with a length of three. Each entry for TABB is
numeric with a length of three and zero decimals. Both tables have a total
of nine entries per table. Example 15–4 shows how the same tables, TABA
and TABB can be defined by specifying only one entry per record.
Example 15–3 Related Tables - Multiple entries per record
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890123
E TABA 5 9 3 TABB 3 0
.
.
.
**
AAA000BBB111CCC222DDD333EEE444
FFF555GGG666HHH777III888
\ /\ /
^ ^
| |
| TABB element 6
TABA element 6
15–5
Using Tables and Arrays
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890123
E TABA 1 9 3 TABB 3 0
.
.
.
**
AAA000
BBB111
CCC222
DDD333
EEE444
FFF555
GGG666
HHH777
III888
15–6
Using Tables and Arrays
The main table’s values for entries per table (columns 36 - 39), from file
name (columns 11 - 18), and entries per record (columns 33 - 35) are also
used for the alternate table.
Rules
• If the compile-time table contains numeric data, it must be in trailing
numeric or zoned-decimal format. Therefore, leave column 43 (data
format) blank. Leave column 55 (data format) blank if defining related
tables in alternating format.
• The input records for compile-time tables must be in the same order in
which the tables are defined in the Extension specifications.
• In compile-time tables the maximum length of an alphameric array
element is 96 characters. This is the maximum record size for an RPG
source program.
• If the compile-time table contains more entries than are defined for
the table in the Extension specification, a warning will be generated
stating that the table is full.
• If the compile-time table contains less entries than are defined for
the table in the Extension specification, a warning will be generated
stating that the table is short.
In the following example, the table name is TABLE1. There are 10 entries
in the table, with one entry in each record. The length of each entry is
five digits, with two decimal positions. The data type of the entry in each
record is trailing numeric, by default.
Example 15–5 Extension Specification to define a compile-time table
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890123
E TABLE1 1 10 5 2
.
.
.
// TABLE1
63741
92312
90343
72844
19375
10306
23847
09374
59780
12361
The following example defines two related tables, TAB1 and TAB2. There
are four entries in each table, with two entries in each record. The length
of each entry is five digits, with zero decimal positions for TAB1 and TAB2.
Both tables are in ascending sort sequence.
15–8
Using Tables and Arrays
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890123
E TAB1 2 4 5 0ATAB2 5 0A
.
.
.
// TAB1 / TAB2
11111222223333344444
55555666667777788888
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890123
FINPDATA IT F 50 EDISK
.
.
.
E INPDATA TABLEA 10 50 5
Rules
• The input file cannot contain more entries than are defined for the
table. If it does, a run-time error occurs.
• If more than one pre-execution-time table is to be loaded from table
files, each pre-execution-time table must be loaded from a different
file. The exception is when two pre-execution-time tables are defined
as alternating tables, both tables are loaded from the same table file.
15–9
Using Tables and Arrays
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890123
E TAB1 1 5 5 0
.
.
.
C FLD1 LOKUPTAB1 10
C 10 TAB1 MULT 100 TAB1
15–10
Using Tables and Arrays
15–11
Using Tables and Arrays
into the special work area for that table. Next, the corresponding entry is
located in the table specified in the result field and placed into the special
work area for that table.
If a LOKUP operation against a table fails, the table reference field
contents in factor 2 and the optional result table reference field contents
do not change. When a program initializes, the first entry in a table is
placed in the table reference field.
See Chapter 11 for a complete description of the LOKUP operation code.
In Example 15–9, FLD1 is the search argument in the LOKUP operation.
If the program locates FLD1 in TAB1, that entry becomes the current
entry. Then the corresponding entry in TAB2 is located, and it then
becomes the current entry for TAB2.
Example 15–9 Related table LOKUP
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890123
C FLD1 LOKUPTAB1 TAB2 10
In Example 15–10, the program tries to match the search argument ITEM
with an entry in table TABA. If a matching entry is found, indicator 11 is
set on. If no matching entry is found, the halt indicator H1 is set on and
the program terminates. In the compile-time table TABA, there are 10
entries in a record and 50 entries in a table. Each entry is five characters
long.
Example 15–10 Program table LOKUP
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890123
H
FINPUT IPE F 30 DISK
FREPORT O F 40 DISK
E TABA 10 50 5
IINPUT NS 01
I 1 5 ITEM
I 6 102FLD1
I 15 30 FLD2
C ITEM LOKUPTABA 11
C N11 SETON H1
C 11 100 ADD FLD1 NEW 62 10
OREPORT D 01 11
O NEW B 20
//
10001100021000310004100051000610007100081000910010
20001200022000320004100052000620007200082000920010
30001300023000330004100053000630007300083000930010
40001400024000340004100054000640007400084000940010
50001500025000350004100055000650007500085000950010
15–12
Using Tables and Arrays
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890123
H
FINFILE IP F 80 80 DISK
FFILE1 IT F 80 80 EDISK
FFILE2 IT F 80 80 EDISK
E FILE1 TABLE1 1 6 3 2A
E FILE2 TABLE2 1 6 3 0
IINFILE NS 11
I 1 32COST
I 4 60LENGTH
I 7 100NUMBER
C LENGTH LOKUPTABLE2 20
C N20 GOTO NOPROC
C COST LOKUPTABLE1 26 26
C N26 EXSR PROCES
C NOPROC TAG
.
.
.
15–13
Using Tables and Arrays
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890123
H
.
.
.
E TABLE3 1 6 3 0
.
.
.
C 025 LOKUPTABLE3 20
C 20 MOVE 250 TABLE3
.
.
.
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890123
H
FINFILE IP F 80 80 DISK
FTABLE1 IT F 22 22 EDISK
FTABLE2 O F 22 22 DISK
E TABLE1 TABLE2 TABA 2 10 5 TABB 6 2
IINFILE NS 01
I 1 5 ITEM
C ITEM LOKUPTABA TABB 11
C N11 SETON H1
C 11 TABB MULT 1.05 TABB H
15–14
Using Tables and Arrays
When the program executes, it reads the first record from the primary
input file MASTER. If the search argument ITEM is matched, indicator
11 is set on and the corresponding entry from TABB is made available for
processing. If no match is found, the halt indicator H1 is set on and the
program terminates without creating the output file TABLE2.
When the program ends, the updated tables TABA and TABB are written
to file TABLE2 with the same number of entries per record as the table
input file TABLE1.
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890123
H
FINFILE IP F 80 80 DISK
FTABFILE IT F 80 80 EDISK
FTABFILE2O F 80 80 DISK
FOFILE O F 80 80 DISK
E TABFILE TABFILE2TABSH 10 80 4 0
IINFILE NS 01
I 1 40ENTRY
C 0000 LOKUPTABSH 11
C 11 Z-ADDENTRY TABSH H1
C 11 EXCPT
OOFILE E
O TABSH 10
15–15
Using Tables and Arrays
a single array or it can define two arrays which contain associated data
items, referred to as alternating format.
When an array is defined using the alternating format, the rules for
loading the data into the array are:
• The first entry from the first array is read.
• Next the first entry from the second array is read.
• This alternate reading continues until all entries from both arrays are
read.
15–16
Using Tables and Arrays
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890123
H
FPROCD IP F 80 DISK
FINLIST O F 132 OF PRINTER
E AR1 1 5 5 0ALT1 20
E AR2 4 4 5 0ALT2 4 2
IPROCD NS 01
I 1 50PRODNO
I 6 80QUAN
C Z-ADD1 I 20
C PRODNO LOKUPAR1,I 20
C Z-ADD1 T 20
C PRODNO LOKUPAR2,T 21
C 21 QUAN MULT ALT2,T AMT 72
OINLIST H 202 1P
O OR OF
O UDATE Y 18 ’ / / ’
O 47 ’INVENTORY PARTS LIST’
O PAGE 65
O H 1 1P
O OR OF
O 32 ’PRODUCT PRODUCT’
O 53 ’UNIT’
O H 2 1P
O OR OF
15–17
Using Tables and Arrays
Rules
• The first entry must begin in character position 1.
• All entries must be contiguous, with no space between entries, as
shown in Example 15–16.
The array in Example 15–16 consists of five entries,. Each entry is 10
characters long.
15–18
Using Tables and Arrays
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890123
E TABA 5 5 10
.
.
.
** TABA
aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeee
\ /\ /\ /\ /\ /
1 2 3 4 5 <--- Elements
Compile-Time Rules
• The first record must be preceded by a record containing either double
slashes ( // ) and a blank or double asterisks ( ** ) and a blank in
character positions 1 - 3. Because these strings are delimiters, records
in a compile-time array cannot contain either of these characters in
positions 1 - 3.
Table delimiters must be consistent within a program. The compiler
will interpret the first delimiter found as the default delimiter for the
remainder of the program. I.E: if the first delimiter encountered is "**
", all remaining delimiters must also be "** ".
15–19
Using Tables and Arrays
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890123
E ARY1 5 9 3 ARY2 3 0
.
.
.
**
AAA000BBB111CCC222DDD333EEE444
FFF555GGG666HHH777III888
\ /\ /
^ ^
| |
| ARY2 element 6
ARY1 element 6
15–20
Using Tables and Arrays
Example 15–18 Related arrays defined using a single entry per record
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890123
E ARY1 1 9 3 ARY2 3 0
.
.
.
**
AAA000
BBB111
CCC222
DDD333
EEE444
FFF555
GGG666
HHH777
III888
15–21
Using Tables and Arrays
The entries made in the following columns for the main array also apply
to the alternate array:
• Columns 11 - 18 (from file name)
• Columns 33 - 35 (entries per record)
• Columns 36 - 39 (entries in array)
Rules
• If the compile-time array contains numeric data, it must be in trailing
numeric or zoned-decimal format. Therefore, leave column 43 (data
format) blank. Leave column 55 (data format) blank if defining related
arrays in alternating format.
• The input records for compile-time arrays must be in the same order
in which the arrays are defined in the Extension specifications.
15–22
Using Tables and Arrays
Example 15–19 describes the compile-time array A1. The array has eight
entries with four entries in each record. Each entry is a character field
that is six bytes long. The array records are located at the end of the
program.
Example 15–19 Compile-time array
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890123
E A1 4 8 6
.
.
.
**
111111222222333333444444
555555666666777777888888
15–23
Using Tables and Arrays
Rules
• The input file cannot contain more entries than are defined for the
array. If it does, a run-time error occurs.
• The input file can contain fewer entries than are defined for the array,
but only if a sequence is not specified. When a sequence is not specified
and the array contains fewer entries than are defined, the remaining
entries are automatically filled using blanks for alphanumeric data
and zeros for numeric data.
15–24
Using Tables and Arrays
Example 15–20 shows how to use the Input specification to load an entire
execution-time array containing packed-decimal data as a single field.
Array ARR contains seven elements, and each element is four bytes long.
The execution-time array is loaded from the input file ARRIN as a single
field in packed-decimal format. Note that the array is specified as packed-
decimal in the Input specification but as trailing numeric in the Extension
specification.
Example 15–20 Execution-time array load from data file
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890123
.
.
.
E ARR 7 7 0
IARRIN NS 03
I P 1 28 ARR
.
.
.
Example 15–21 shows how to use the Input specifications to load an array
with elements scattered throughout the record. Array ARR1 contains 4
elements, each 5 bytes long, which are scattered among other fields in the
input record.
Example 15–21 Execution-time array load from data file
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890123
.
.
.
E ARR1 4 5
IARRFILE NS 03
I 1 5 ARR1,1
I 6 8 FLD1
I 9 13 ARR1,2
I 14 20 FLD2
I 21 25 ARR1,3
I 26 32 FLD3
I 33 37 ARR1,4
.
.
.
15–25
Using Tables and Arrays
Rules
• When specifying arrays with the same number of elements for factor 1,
factor 2, and the result field, RPG performs the operation on the first
element, then on the second element, and so on, until all the elements
in the array have been processed.
If the arrays do not have the same number of elements, RPG ends the
operation when the last element of the array with the fewest elements
is processed.
15–26
Using Tables and Arrays
• When one factor is a field or constant and the other factor or result
field is an entire array, RPG performs the operation once for every
element in the array.
• If the operation requires factor 2 only and the result field is an array,
RPG performs the operation once for every element in the array.
• An array must be specified for the result field.
• Resulting indicators are not allowed.
If an array is specified for the result field and an array element as one
of the factors in a calculation, RPG alters the value of the element as a
result of the calculation. When this occurs, RPG uses the new value in
all subsequent operations that reference that element. For example, two
numeric arrays contain the data shown in Table 15–1.
ARR2,1 2
ARR2,2 7
ARR2,3 5
ARR2,4 9
15–27
Using Tables and Arrays
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890123
H
FINPUT1 IPE F 60 DISK
FREPORT O F 60 DISK
E WEEK 8 6 2
E YEAR 8 8 2
IINPUT1 NS 01
I 1 48 WEEK
C XFOOTWEEK TOTAL 82
C ADD WEEK YEAR
CLR XFOOTYEAR GRAND 102
OREPORT D 01
O 20 ’WEEKLY TOTAL=’
O TOTAL 35 ’$ , . ’
O T LR
O 20 ’YEARLY TOTAL=’
O GRAND 35 ’$ , , . ’
Two execution-time arrays, WEEK and YEAR, are defined in the Extension
specifications. The Input specifications instruct the program to load the
array WEEK after reading each sales record from the file INPUT1.
The array elements are in contiguous positions in the input record.
Therefore, when the name of the array is specified as the field name,
the data is automatically loaded into the appropriate elements of the array
as the input record is read. In this case, only one Input specification is
necessary to load the execution-time array WEEK.
The XFOOT operation calculates the sum of all the elements in the array
WEEK and puts the sum in the result field TOTAL. The next calculation
adds one array to the other. Adding arrays involves adding each element
of one array to the corresponding element of the other array. Resulting
indicators cannot be specified to indicate the result of the operation.
These arrays have the same number of elements; therefore, any specified
operation is performed until all elements have been processed. In the
case of two arrays containing different numbers of elements, the specified
operation is performed only until the last element in the shorter array is
processed.
15–28
Using Tables and Arrays
15–29
Using Tables and Arrays
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890123
C QTY LOKUPARR 11
Unlike the search of a table, the program can control where the search of
an array is to begin. This is done by specifying in factor 2 of the LOKUP
operation the name of the array to be searched along with an index. The
value of the index specifies the array element where the search is to begin.
The index can be a literal or a field name. See Chapter 11, Operation
Codes, for a complete description of the LOKUP operation code.
In Example 15–24, the search begins with the seventh element of array
ARR:
Example 15–24 Array LOKUP with starting position
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890123
C QTY LOKUPARR,7 11
15–30
Using Tables and Arrays
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890123
H
FINPUT1 IT F 50 EDISK
FINPUT2 IPE F 10 DISK
FOUTPUT O F 60 DISK
E INPUT1 ARY1 10 10 5 0D
IINPUT2 NS 01
I 1 50SEARCH
C Z-ADD1 I 20
C LOOP TAG
C SEARCH LOKUPARY1,I 56
C 56 EXCPT
C 56 ADD 1 I
C 56 I COMP 11 54
C 56 54 GOTO LOOP
OOUTPUT E 56
O 7 ’INDEX=’
O I 9
O 18 ’VALUE=’
O ARY1,I 23
15–31
Using Tables and Arrays
If the array is not indexed, data movement starts with the first element of
an array or field. If the array is indexed, the move starts with the element
specified by the index. Data movement stops when one of the following
conditions is met:
• The last array element is moved or filled.
• The number of characters moved equals the length of the shorter field,
as specified either in columns 33 - 42 (factor 2) or in columns 43 - 48
(result field) of the Calculation specification.
See Chapter 11, Operation Codes, for more information on the MOVEA
operation code.
Example 15–26 shows a pre-execution-time array, ARR20, being loaded
from the file ARRFILE. A copy of ARR20 is moved into the execution-time
array ARR15 using the MOVEA operation code.
Example 15–26 Program using MOVEA on an array
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890123
FARRFILE IT F 80 EDISK
E ARRFILE ARR20 5 50 4
E ARR15 50 4
.
.
.
C MOVEAARR20 ARR15
15–32
Using Tables and Arrays
each entry being a six-digit, trailing numeric data type with two decimal
positions. The files ARRAYIN and ARRAYOUT must also be described in
the File Description specifications as an input table file (ARRAYIN) and an
output table file (ARRAYOUT).
Example 15–27 Updating a pre-execution-time array
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890123
.
.
.
FARRAYIN IT F 50 EDISK
FARRAYOUTOT F 50 EDISK
E ARRAYIN ARRAYOUTCOSTL 8 100 6 2
.
.
.
In Example 15–28, for each record read from FILEA, the execution-
time array DISCNT is written out to the file REPORT using Output
specifications:
15–33
Using Tables and Arrays
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890123
E COSTLIST PRICE 5 10 5 2
E DISCNT 10 5 2
IFILEA NS 01
I 1 22PERCNT
.
.
.
C 01 PRICE MULT PERCNT DISCNT H
.
.
.
OREPORT D 1 01
O DISCNT 120 ’ $0. ’
To output an individual array element, specify the array and the index of
the desired element (in the form ARR,n, where n is either a constant or a
field name) in columns 32 - 37 (field name).
Example 15–29 outputs only the first and second elements of array DSCT:
Example 15–29 Writing individual array elements
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890123
E COSTLIST PRICE 5 10 5 2
E DSCT 10 5 2
IFILEA NS 01
I 1 22PERCNT
.
.
.
C 01 PRICE MULT PERCNT DSCT H
.
.
.
OREPORT D 1 01
O 20 ’ITEM 1 COST: ’
O DSCT,1 32 ’ $0. ’
O 50 ’ITEM 2 COST: ’
O DSCT,2 62 ’ $0. ’
If the array or array elements being output to a report file are numeric,
edit codes or edit words can be used to add commas, dollar signs, or to
suppress leading zeros. Do not use edit codes or edit words to modify
array data if it is going to be used as input data to subsequent programs.
When specifying an edit code with an entire array (nonindexed), RPG
automatically inserts two spaces between elements of the array in the
output record.
15–34
16 Defining and Using Data Structures
Note that a data structure name can only be six characters long. Data
structure names follow field name conventions. They can be 1 - 6
characters long, must begin with an alpha character, and can be composed
of any valid alphanumeric characters.
The data structure name can appear on only one data structure
specification. It cannot be the same name specified for a look-ahead
field.
16–1
Defining and Using Data Structures
The field location’s start and end positions are relative to the beginning of
the data structure.
When coding a subfield definition in an Input specification, only columns
44 - 58 are used.
16–2
Defining and Using Data Structures
16–3
Defining and Using Data Structures
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
*
ICUSTMSTRAA 01
I 1 16 CUSTNO
I 17 46 NAME
.
.
.
ICUSTORDRBB 02
I 1 16 CUSTNO
I 17 25 PARTNO
.
.
.
ICUSTNO DS
I 01 02 STATE
I 03 05 CITY
I 06 100ZIP
I 11 160ID
In this example, the field CUSTNO is used in both the CUSTMSTR and
CUSTORDR files. It is redefined by a data structure and, within the data
structure, it is further broken down into the fields STATE, CITY, ZIP, and
ID. By using a data structure to redefine the CUSTNO field, only 16 bytes
of storage are used to store the field and its subfields. Furthermore, the
subfields used to redefine the CUSTNO field need only be defined once in
the data structure, rather than repeated within each input record.
16–4
Defining and Using Data Structures
16.3.2 Using a Data Structure Storage Area In More Than One Way
A data structure can be used to define a single area of storage for several
purposes. The following example depicts the use of a data structure to
define three input records.
Example 16–2 Using a data structure to define multiple input records
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
*
IINVENTRYAA 01 01 CM
I 1 50 ITMREC
I BB 02 01 CI
I 1 26 QTY
I CC 03 01 CO
I 1 34 ORDREC
.
.
.
I DS
I 01 50 ITMREC
I 01 01 RECCOD
I 02 100PARTNO
I 11 50 DESC
*
I 01 26 QTY
I 01 01 RECCOD
I 02 100PARTNO
I 11 160STOCK
I 17 200LOWLIM
I 21 26 LSTORD
*
I 01 34 ORDREC
I 01 01 RECCOD
I 02 100PARTNO
I 11 16 ORDDAT
I 17 220ORDQTY
I 23 280AVEORD
I 29 340BIGORD
16–5
Defining and Using Data Structures
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
*
ICUSTORDRBB 02
I 1 16 CUSTNO
I 17 25 PARTNO
I 26 310ORDDAT
I 32 370SHPDAT
.
.
.
IORDKEY DS
I 01 16 CUSTNO
I 17 220ORDDAT
In this example, the data structure ORDKEY is constructed from the fields
CUSTNO and ORDDAT. The fields CUSTNO and ORDDAT are obtained
from the CUSTORDR file and are reordered in the data structure to build
the ORDKEY.
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
*
I UDS
I 01 040RPTNO
I 17 48 USER
I 120 125 START
This example indicates how to code the local data area data structure.
16–6
Defining and Using Data Structures
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
*
C EXIT SUBR21
C RLABL I_O 1
C RLABL TERMID 2
C RLABL RETCOD 1
C RLABL LDA
16–7
Defining and Using Data Structures
1 2 3 4 5 6
12345678901234567890123456789012345678901234567890123456789012345
*
FTERMINALCD F 120 WORKSTN
F KINFDS EXCPTN
.
.
.
IEXCPTN DS
I *STATUS STATUS
I *OPCODE OPCODE
I *RECORD RECORD
I *SIZE SIZE
I *MODE MODE
I *INP INP
I *OUT OUT
I 23 26 RCODE
16–8
17 Specifying An Alternate Collating Sequence Or A
Translation File
17–1
Specifying An Alternate Collating Sequence Or A Translation File
17–2
Specifying An Alternate Collating Sequence Or A Translation File
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
H S
.
.
.
O*
** Alternate Sequence Table
ALTSEQ 2030 blank = 0
ALTSEQ 4131 A = 1
ALTSEQ 4232 B = 2
ALTSEQ 4A33 J = 3
ALTSEQ 4B34 K = 4
** End of Alternate Sequence Table
17–3
Specifying An Alternate Collating Sequence Or A Translation File
17–4
Specifying An Alternate Collating Sequence Or A Translation File
The first blank space in a file translation record terminates the translation
parameter entries for that record. The rest of the line can be used for
comments.
If a large number of characters are to be translated, additional translation
parameter records can be specified.
The last file translation parameter record must be followed by another
record containing two asterisks and a blank (** ) in columns 1 - 3.
17–5
Specifying An Alternate Collating Sequence Or A Translation File
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
H F
.
.
.
O*
** File Translation Parameter Records
*FILES 2A41 * = A
*FILES 2B42 + = B
*FILES 2C43 , = C
*FILES 2D44 - = D
** End of File Translation Parameter Records
17–6
18 Using a SPECIAL Device File
18.1 Overview
This chapter describes how Migration RPG provides support for SPECIAL
device files. SPECIAL device file support will allow the programmer to
access files, devices, and services which are not directly supported by RPG
or the OpenVMS Record Management Services (RMS). SPECIAL device
files coded in an RPG program can be treated like normal file definitions
with Input and Output specifications. However, the programmer is
responsible for providing an external subroutine which serves as the
I/O interface for SPECIAL device files. The external subroutine used
by the SPECIAL device file is declared in the SPECIAL device File
specification. These subroutines, which can be written in any native
OpenVMS programming language, are responsible for transferring data
back and forth between the RPG program and the special device. RPG
provides support for up to 99 SPECIAL device files in a single program.
Migration RPG provides support for reading input from SYS$COMMAND
and writing output to SYS$OUTPUT via the supplied subroutine SUBR01.
18–1
Using a SPECIAL Device File
18–2
Using a SPECIAL Device File
If a continuation line is coded for the SPECIAL device file, then an Array
Control Data Structure will be created and the address placed in bytes
18–3
Using a SPECIAL Device File
14-17 of the File Control Data Structure. The layout of the Array Control
Data Structure is described in Table 18–4.
• If the file type is Input, then only the Get (G) operation code is
generated by the RPG compiler for the SPECIAL device file subroutine.
• If the file type is Output, then only the Put (P) operation code is
generated by the RPG compiler for the SPECIAL device file subroutine.
• If the file type is Update, then the operation codes in Table 18–6
are generated by the RPG compiler for the SPECIAL device file
subroutine.
18–4
Using a SPECIAL Device File
• If the file type is Combined, then the operation codes in Table 18–7
are generated by the RPG compiler for the SPECIAL device file
subroutine.
18–5
Using a SPECIAL Device File
The program creates a report which shows the data read from each
file along with information on the status of program indicators (see
Example 18–7). The 5 subroutines which support the SPECIAL device
files are written in VAX C.
Example 18–1 Sample Migration RPG Program using SPECIAL Device
Files
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456789
*
H
FSBR100 UP F 45 45 SPECIAL TESTSBR100
F KARR1
FNORMAL IS F 50 50 DISK
FSBR200 IS F 45 45 SPECIAL TESTSBR200
FSBR300 CD F 50 50 SPECIAL TESTSBR300
FSBR400 UD F 55 55 SPECIAL TESTSBR400
F KARR2
FSBR500 O F 60 60 SPECIAL TESTSBR500
FREPORT O F 132 132 OF PRINTER
E*
E* Array used with SPECIAL device file SBR100
E*
E ARR1 2 5 0
E*
E* Array used with SPECIAL device file SBR400
E*
E ARR2 1 5 3
E*
E* Array contains the data supplied to SPECIAL device file SBR500
E*
E D500 1 3 60
ISBR100 NS 01
I 1 45 DATA1
INORMAL NS 02
I 1 50 DATA2
ISBR200 NS 03
I 1 45 DATA3
ISBR300 NS 04
I 1 50 DATA4
ISBR400 NS 05
I 1 55 DATA5
C*
C* Process the data from SPECIAL device file SBR100
C*
C 01 ADD 1 ARR1,1
C 01 ADD 2 ARR1,2
C 01 EXCPTOUT100
C*
C* Process the data from file NORMAL
C*
C 02 EXCPTOUTNML
C*
C* Process the data from SPECIAL device file SBR200
C*
C 03 EXCPTOUT200
C*
C* After all primary and secondary files have been processed,
C* process the demand files and output only files.
C*
CLR EXSR SUB300
CLR EXSR SUB400
CLR EXSR SUB500
18–6
Using a SPECIAL Device File
18–7
Using a SPECIAL Device File
18–8
Using a SPECIAL Device File
18–9
Using a SPECIAL Device File
18–10
Using a SPECIAL Device File
if ( File_DS->op_code == ’G’ )
{
if ( cnt == 1 )
{
memcpy( File_DS->buffer, input1, 45 );
cnt++;
return 1;
}
if ( cnt == 2)
{
memcpy( File_DS->buffer, input2, 45 );
cnt++;
return 1;
}
if ( cnt == 3 )
{
memcpy( File_DS->buffer, input3, 45 );
cnt++;
return 1;
}
return 3; /* EOF */
}
/* Is this a call for update data, op-code of U */
if ( File_DS->op_code == ’U’ )
{
memcpy( outbuf, File_DS->buffer, 45 );
outbuf[46] = 0;
printf( "Buffer Data SBR100: %s\n", outbuf );
memcpy( outary, File_DS->array->ary_buffer, 10 );
outary[11] = 0;
printf( "Array Data SBR100: %s\n", outary );
return 1;
}
return 2; /* Else return error */
}
18–11
Using a SPECIAL Device File
18–12
Using a SPECIAL Device File
if ( File_DS->op_code == ’G’ )
{
if ( cnt == 1 )
{
memcpy( File_DS->buffer, input1, 45 );
cnt++;
return 1;
}
if ( cnt == 2)
{
memcpy( File_DS->buffer, input2, 45 );
cnt++;
return 1;
}
if ( cnt == 3 )
{
memcpy( File_DS->buffer, input3, 45 );
cnt++;
return 1;
}
return 3; /* EOF */
}
return 2; /* Else Return error */
}
18–13
Using a SPECIAL Device File
18–14
Using a SPECIAL Device File
if ( File_DS->op_code == ’G’ )
{
if ( cnt == 1 )
{
memcpy( File_DS->buffer, input1, 50 );
cnt++;
return 1;
}
if ( cnt == 2)
{
memcpy( File_DS->buffer, input2, 50 );
cnt++;
return 1;
}
if ( cnt == 3 )
{
memcpy( File_DS->buffer, input3, 50 );
cnt++;
return 1;
}
return 2; /* Error */
}
/* Is this a call for output data, op-code of P */
if ( File_DS->op_code == ’P’ )
{
memcpy( outbuf, File_DS->buffer, 50 );
outbuf[51] = 0;
printf( "Buffer Data SBR300: %s\n", outbuf );
return 1;
}
return 2; /* Else return error */
}
18–15
Using a SPECIAL Device File
18–16
Using a SPECIAL Device File
if ( File_DS->op_code == ’G’ )
{
if ( cnt == 1 )
{
memcpy( File_DS->buffer, input1, 55 );
cnt++;
return 1;
}
if ( cnt == 2)
{
memcpy( File_DS->buffer, input2, 55 );
cnt++;
return 1;
}
if ( cnt == 3 )
{
memcpy( File_DS->buffer, input3, 55 );
cnt++;
return 1;
}
return 3; /* EOF */
}
/* Is this a call for update data, op-code of U */
if ( File_DS->op_code == ’U’ )
{
memcpy( outbuf, File_DS->buffer, 55 );
outbuf[56] = 0;
printf( "Buffer Data SBR400: %s\n", outbuf );
memcpy( outary, File_DS->array->ary_buffer, 15 );
outary[16] = 0;
printf( "Array Data SBR400: %s\n", outary );
return 1;
}
return 2; /* Else return error */
}
18–17
Using a SPECIAL Device File
18–18
Using a SPECIAL Device File
Example 18–7 Report Generated by the Sample Migration RPG Program SPCDEV
18–19
19 Coding Subprograms
19–1
Coding Subprograms
19–2
Coding Subprograms
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456789
*
* This example displays the use of the CALL and PARM opcodes.
* The subprogram MAMMAL is called and passed the parameters FOX,
* BAT, WEASEL and WOLF. MAMMAL can then manipulate these fields
* and return their updated values to the calling program. After
* the MAMMAL CALL is processed, control returns to the next
* statement following the last PARM statement. Indicator 23
* will be set on if MAMMAL exits with an error status set.
*
C CALL ’MAMMAL’ 23
C PARM FOX
C PARM BAT
C PARM WEASEL
C PARM WOLF
19–3
Coding Subprograms
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456789
*
* The following CALL statements are equivalent.
* Both call the subprogram PROG1. Note the use
* of the underscore when defining the program
* name in an EXTRN statement.
*
C PRGNM EXTRN’_PROG1’
C CALL PRGNM
C CALL ’PROG1’
19–4
Coding Subprograms
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456789
*
* This example depicts the use of the EXTRN opcode to define the
* subprogram BIG_AIRPLANE. BIG_AIRPLANE can then be referenced
* using the CALL and FREE opcodes.
*
C FLY EXTRN’_BIG_AIRPLANE’
.
.
.
C CALL FLY
.
.
.
C FREE FLY
19–5
Coding Subprograms
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456789
*
* This example depicts the use of the FREE opcode to reinitialize
* the program SKI.
*
C CALL SKI
.
.
.
C FREE SKI
19–6
Coding Subprograms
19–7
Coding Subprograms
31 23 15 0
1 DTYPE LENGTH
POINTER
19–8
Coding Subprograms
19–9
Coding Subprograms
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456789
*
* The following example illustrates the use of the PARM
* statement with the CALL opcode.
*
* The first parameter passes the contents of the field TAP
* to the subprogram and returns any modifications to
* the field TAP when the subprogram exits.
*
* The second parameter copies the contents of the field FOX
* to the field TROT before passing the contents of TROT to
* the subprogram. Since TROT is defined as a 10-byte,
* alpha field, the move will be left-justified and blank-
* filled. When the subprogram exits, TROT will contain
* the updated data.
*
* The third parameter passes the contents of the field CHARLE
* to the subprogram. When the subprogram exits, the
* updated contents of CHARLE will be copied to STON.
*
* The fourth parameter copies the contents of the field ROCK
* to the field AND when the subprogram is called. Since AND
* is defined as a 7-byte, numeric field, the copy is carried
* out using a Z-ADD operation. When the subprogram exits,
* the updated data in AND is Z-ADDed to the field ROLL.
*
C CALL ’DANCE’
C PARM TAP
C PARM FOX TROT 10
C STON PARM CHARLE
C ROLL PARM ROCK AND 70
19–10
Coding Subprograms
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456789
*
* The *ENTRY PLIST is set up to accept and return three parameters
* from a calling program. The PLIST labeled FARM has three
* parameters assigned to it. A CALL statement in this program
* could reference the PLIST FARM and pass the FARM parameter list
* to another subprogram.
*
C *ENTRY PLIST
C PARM COWS
C PARM HOGS
C PARM CHICKN
*
C FARM PLIST
C PARM TRACTR
C PARM COMBIN
C PARM PICKUP
19–11
Coding Subprograms
19–12
Coding Subprograms
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456789
*
* This subprogram is passed the parameters PHASER and
* PHOTON. After manipulation of these fields, it
* returns to the calling program without ending. Any
* values or indicator settings established each time
* this subprogram is run are retained as long as the
* calling program does not execute a FREE operation
* against it.
*
C *ENTRY PLIST
C PARM PHASER
C PARM PHOTON
*
C PHASER ADD ENERGY PHASER
C PHOTON ADD ENERGY PHOTON
*
C RETRN
19–13
Coding Subprograms
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456789
*
H
* CALL.RPG
*
* This program demonstrates passing data between
* a Migration RPG program and subprogram. The
* subprogram in this example is an external routine
* that left justifies an alphameric field.
*
FOUTPUT O F 80 DISK
*
* Create right justified alphameric fields.
*
C MOVE ’JACK’ FLD1 10
C MOVE ’RABBIT’ FLD2 15
*
* Output fields before they are left justified.
*
C EXCPTDATA
*
* Left justify alphanumeric fields.
*
C CALL ’LFTJST’
C FLD1 PARM FLD1 $FLD 256
C PARM 10 $SIZ 30
*
C CALL ’LFTJST’
C FLD2 PARM FLD2 $FLD
C PARM 15 $SIZ
*
* Output fields after they are left justified.
*
C EXCPTDATA
*
C SETON LR
*
OOUTPUT E DATA
O FLD1 10
O FLD2 30
19–14
Coding Subprograms
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456789
*
* SUBPROGRAM: LFTJST.RPG
*
* This routine left justifies an alphanumeric field.
*
* On Entry:
* FLD - Original alphanumeric field
* SIZE - Size of alphanumeric field
*
* On Return:
* FLD - Left justified field
*
E ORG 256 1
E LFT 256 1
*
I DS
I 1 256 FLD
I 1 256 ORG
*
* The *ENTRY PLIST defines the parameters that will be passed
* to the subprogram and that can be passed back to the
* calling program.
*
C *ENTRY PLIST
C PARM FLD
C PARM SIZE 30
*
* This block of code left justifies the input field.
*
IF C FLD IFNE *BLANKS
AND C ORG,1 ANDEQ*BLANK
*
C MOVEA*BLANKS LFT
C Z-ADD1 I 30
*
DOW C I DOWLESIZE
AND C ORG,I ANDEQ*BLANK
C ADD 1 I
END C END
*
C MOVEAORG,I LFT,1
C MOVEALFT ORG
*
END C END
*
* The RETRN opcode returns control to the calling
* program.
*
C RETRN
19–15
Coding Subprograms
The following commands can be used to build and run the CALL program.
Example 19–10 Commands Used to Build CALL Program
$ RPG CALL
$ RPG /NOEND LFTJST !Note the use of the /NOEND
$! !qualifier on the subprogram.
$ LINK CALL, LFTJST
$!
$ ASSIGN /USER CALL.DAT OUTPUT
$ RUN CALL.EXE
19–16
Coding Subprograms
1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123456789
*
H
* PASS1.RPG
*
* This program demonstrates passing three parameters to
* the COBOL subprogram PASS1C.COB via the Macro-32
* interface module PASS1M.MAR.
*
FOUTPUT O F8000 80 DISK
*
* The PLIST opcode is used to define a parameter list.
*
C PARAMS PLIST
C PARM ALPHA1 12
C PARM ALPHA2 16
C PARM NUM1 60
*
C MOVE ’FOXTROT ’ALPHA1
C MOVEL’SUPER ’ALPHA2
C MOVE ’WOMAN ’ALPHA2
C Z-ADD10 NUM1
C EXCPTOUT
*
* The CALL opcode is executed, calling the PASS1M
* interface module and passing it the PARAMS
* parameter list.
*
C CALL ’PASS1M’ PARAMS
*
C EXCPTOUT
C SETON LR
*
OOUTPUT E OUT
O ALPHA1 12
O ALPHA2 30
O NUM1 40
19–17
Coding Subprograms
.TITLE PASS1M
;This module converts the RPG parameters from a
;descriptor type to a reference type. Migration
;RPG passes external parameters by descriptor,
;but DEC COBOL only accepts external parameters
;by reference.
.PSECT $CODE,PIC,REL,CON,SHR,RD,NOWRT,EXE,NOVEC,LONG
.ENTRY _PASS1M,^M<>
MOVL AP, R10 ;Get stack pointer.
TSTL (R10)+ ;Skip count of number of
;elements on stack.
TSTL (R10)+ ;Skip FREE flag.
MOVAL @(R10), R0 ;Get address of first descriptor.
MOVAL @4(R0), R1 ;Get address of first parameter.
PUSHL R1 ;Push first parameter address
;onto stack.
TSTL (R10)+ ;Move to second parameter.
MOVAL @(R10), R0 ;Get address of second descriptor.
MOVAL @4(R0), R1 ;Get address of second parameter.
PUSHL R1 ;Push second parameter address
;onto stack.
TSTL (R10)+ ;Move to third parameter.
MOVAL @(R10), R0 ;Get address of third descriptor.
MOVAL @4(R0), R1 ;Get address of third parameter.
PUSHL R1 ;Push third parameter address
;onto stack.
CALLS #3, G^PASS1C ;Call COBOL subprogram.
RET
.END
19–18
Coding Subprograms
IDENTIFICATION DIVISION.
PROGRAM-ID. PASS1C.
AUTHOR. MSI
This program displays the data passed to it by
the Migration RPG program PASS1.
DATA DIVISION.
LINKAGE SECTION.
01 ALPHA1 PIC X(12).
01 ALPHA2 PIC X(16).
01 NUM1 PIC 9(6).
PROCEDURE DIVISION USING ALPHA1 ALPHA2 NUM1.
P0.
DISPLAY ALPHA1.
DISPLAY ALPHA2.
DISPLAY NUM1.
EXIT PROGRAM.
The following commands can be used to build and run the PASS1 program
on a VAX system.
Example 19–14 Commands Used to Build PASS1 Program on a VAX
System
$ RPG PASS1
$ COBOL PASS1C
$ MACRO PASS1M
$ LINK PASS1, PASS1M, PASS1C
$!
$ ASSIGN /USER PASS1.DAT OUTPUT
$ RUN PASS1.EXE
The following commands can be used to build and run the PASS1 program
on an Alpha or Integrity system.
$ RPG PASS1
$ COBOL PASS1C
$ MACRO /MIGRATE /UNALIGN /OBJECT=SYS$LOGIN:PASS1M -
SYS$LIBRARY:ARCH_DEFS.MAR + SYS$LOGIN:PASS1M.MAR
$ LINK PASS1, PASS1M, PASS1C
$!
$ ASSIGN /USER PASS1.DAT OUTPUT
$ RUN PASS1.EXE
19–19
20 Calling External Routines, EXIT and RLABL
20–1
Calling External Routines, EXIT and RLABL
0 1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890123
FCALLO O F 80 PRINTER
*
IDATAST DS
I 1 4 FLD1
I 6 9 FLD2
I 11 140NUM
*
C Z-ADD1 NUM
*
C EXIT EXTSBR
C RLABL NUM
C RLABL FLD1
C RLABL FLD2
*
C SETON LR
C EXCPT
*
OCALLO E LR
O NUM 10
O FLD1 20
O FLD2 30
20–2
Calling External Routines, EXIT and RLABL
20–3
21 Auto Report Features and Functions
The Auto Report Utility allows a programmer to build and compile RPG
programs from core modules and copybooks. The utility will consolidate
unordered copybooks, sort the RPG specifications into the correct order,
make programmer-specified modifications to the source code, and compile
the program. The following sections describe Auto Report features and
functions.
The Auto Report Utility is invoked with the AUTOC command. The
AUTOC command and its qualifiers are described in the Migration RPG
User’s Guide.
21–1
Auto Report Features and Functions
The remaining columns in the Compile Qualifier specification are not used
and should be left blank.
Example 21–1 depicts a Compile Qualifier specification used to establish
some program compilation parameters. The C in column 7 indicates that
the program source file assembled by the Auto Report Utility is to be
retained. The entry in columns 8 - 24 indicates that the assembled source
file is to be named VACATION and is to be placed in the PAYROLL area.
The program will be given a default extension of .AUT. The B in column 30
indicates that no listing file is to be produced by the Auto Report compile.
21–2
Auto Report Features and Functions
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
UCPAYROLL:VACATION B
21.2 Copybooks
Copybooks are files of RPG specifications that are copied into the
generated RPG program by Auto Report and organized correctly depending
upon specification type. Code copied in from a copybook has a C placed
in column 5 of the RPG specification line in the generated source file to
identify it as copybook code.
Copybooks are included in an Auto Report program using the /COPY
statement. The /COPY statement must begin in column 7 of an RPG
specification line. The /COPY statement can be formatted in either of two
ways, as shown in Example 21–2.
Example 21–2 /COPY statement layouts
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
C*
C/COPY logical,filename
C/COPY logical:filename
The first /COPY format is compatible with that used on an IBM System/36.
The second format is a standard OpenVMS file designation. Auto Report
will recognize and process either format.
The logical name in the /COPY statement is optional, but the file name
must be specified. If a logical name is not specified, Auto Report will
search for the copybook in the programmer’s current default directory.
Copybook files are assumed to have an extension of .RPG. If the extension
is different, it must be specified in the /COPY statement. Auto Report will
accept up to 84 characters in a logical:filename string.
After the /COPY statement is processed, it is included in the generated
source file as a comment.
If Auto Report cannot access the specified copybook, an error will be logged
to the terminal and as a comment in the generated source file.
Example 21–3 depicts the /COPY statements used to include the copybooks
INVENTORY.RPG and DATE_SUB.SUBROUTINE from the GENERIC
area into a program. The first example uses the standard OpenVMS
file format for the file names. The second example uses the System/36
compatible file format, where the System/36 library name would be
equated to a OpenVMS logical name. Note that the .RPG extension
does not need to be declared on the INVENTORY copybook because it is
the default extension. The .SUBROUTINE extension must be included on
the DATE_SUB copybook because it is a non-standard extension.
21–3
Auto Report Features and Functions
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
*
I/COPY GENERIC:INVENTORY
C*
C/COPY GENERIC:DATE_SUB.SUBROUTINE
- or -
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
*
I/COPY GENERIC,INVENTORY
C*
C/COPY GENERIC,DATE_SUB.SUBROUTINE
21–4
Auto Report Features and Functions
21–5
Auto Report Features and Functions
Example 21–5 depicts the modification of several fields which are included
from a copybook. These changes include:
• The ACCTNO field is changed from a numeric to an alphameric field.
• The BALANC field has the high and equal indicators blanked out and
the low indicator changed to 99.
• The ACTDAT field is changed from a trailing numeric field to a
packed-decimal field. The field end position is also changed.
(Copybook module)
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890
*
I 1 100ACCTNO
I P 11 150BALANC 101112
I 16 210ACTDAT 20
I 22 270LSTDEP
I 28 330LSTWTH
21–6
Auto Report Features and Functions
21–7
Auto Report Features and Functions
21.5 Limitations
The following limitations, in terms of the number of RPG source lines which can be processed,
apply to the Auto Report Utility:
21–8
Auto Report Features and Functions
All comments count towards the limit of the specification type under which
they are processed. Comment lines with a blank specified in column 6 are
assigned to the specification type last processed.
21–9
A Character Sets
This appendix contains the ASCII character set, the hexidecimal value of
each ASCII character, and the EBCDIC equivalent.
ASCII EBCDIC
Character Decimal Hexadecimal Decimal Hexadecimal
NUL 000 00 000 00
SOH 001 01 001 01
STX 002 02 002 02
ETX 003 03 003 03
EOT 004 04 055 37
ENQ 005 05 045 2D
ACK 006 06 046 2E
BEL 007 07 047 2F
BS 008 08 022 16
HT 009 09 005 05
LF 010 0A 037 25
VT 011 0B 011 0B
FF 012 0C 012 0C
CR 013 0D 013 0D
SO 014 0E 014 0E
SI 015 0F 015 0F
DLE 016 10 016 10
DC1 017 11 017 11
DC2 018 12 018 12
DC3 019 13 019 13
DC4 020 14 060 3C
NAK 021 15 061 3D
SYN 022 16 050 32
ETB 023 17 038 26
CAN 024 18 024 18
EM 025 19 025 19
SUB 026 1A 063 3F
ESC 027 1B 039 27
FS 028 1C 028 1C
GS 029 1D 029 1D
RS 030 1E 030 1E
A–1
Character Sets
ASCII EBCDIC
Character Decimal Hexadecimal Decimal Hexadecimal
US 031 1F 031 1F
space 032 20 064 40
! 033 21 079 4F
" 034 22 127 7F
# 035 23 123 7B
$ 036 24 091 5B
% 037 25 108 6C
& 038 26 080 50
’ 039 27 125 7D
( 040 28 077 4D
) 041 29 093 5D
* 042 2A 092 5C
+ 043 2B 078 4E
, 044 2C 107 6B
- 045 2D 096 60
. 046 2E 075 4D
/ 047 2F 097 61
0 048 30 240 F0
1 049 31 241 F1
2 050 32 242 F2
3 051 33 243 F3
4 052 34 244 F4
5 053 35 245 F5
6 054 36 246 F6
7 055 37 246 F7
8 056 38 248 F8
9 057 39 249 F9
: 058 3A 122 7A
; 059 3B 094 6E
< 060 3C 076 4C
= 061 3D 126 7E
> 062 3E 110 6E
? 063 3F 111 6F
@ 064 40 124 7C
A 065 41 193 C1
B 066 42 194 C2
C 067 43 195 C3
D 068 44 196 C4
A–2
Character Sets
ASCII EBCDIC
Character Decimal Hexadecimal Decimal Hexadecimal
E 069 45 197 C5
F 070 46 198 C6
G 071 47 199 C7
H 072 48 200 C8
I 073 49 201 C9
J 074 4A 209 D1
K 075 4B 210 D2
L 076 4C 211 D3
M 077 4D 212 D4
N 078 4E 213 D5
O 079 4F 214 D6
P 080 50 215 D7
Q 081 51 216 D8
R 082 52 217 D9
S 083 53 226 E2
T 084 54 227 E3
U 085 55 228 E4
V 086 56 229 E5
W 087 57 230 E6
X 088 58 231 E7
Y 089 59 232 E8
Z 090 5A 233 E9
[ 091 5B 074 4A
\ 092 5C 224 E0
] 093 5D 090 5A
^ 094 5E 095 5F
_ 095 5F 109 6D
` 096 60 121 79
a 097 61 129 81
b 098 62 130 82
c 099 63 131 83
d 100 64 132 84
e 101 65 133 85
f 102 66 134 86
g 103 67 135 87
h 104 68 136 88
i 105 69 137 89
j 106 6A 145 91
A–3
Character Sets
ASCII EBCDIC
Character Decimal Hexadecimal Decimal Hexadecimal
k 107 6B 146 92
l 108 6C 147 93
m 109 6D 148 94
n 110 6E 149 95
o 111 6F 150 96
p 112 70 151 97
q 113 71 152 98
r 114 72 153 99
s 115 73 162 A2
t 116 74 163 A3
u 117 75 164 A4
v 118 76 165 A5
w 119 77 166 A6
x 120 78 167 A7
y 121 79 168 A8
z 122 7A 169 A9
{ 123 7B 192 C0
| 124 7C 106 6A
} 125 7D 208 D0
~ 126 7E 161 A1
DEL 127 7F 007 07
A–4
B CONSOLE, KEYBORD, And CRT Device Usage
CONSOLE, KEYBORD, and CRT are device names that are similar in
function to the WORKSTN device name. All of these designations refer
to terminal and keyboard activity as interpreted by the RPG program.
However, all of these devices differ in the ways that they can interface
with the associated program and in the manner in which output may be
displayed on the terminal.
CONSOLE, KEYBORD, and CRT device designations are included to
ensure continuing compatibility with older RPG applications developed on
non-OpenVMS platforms. Because these three device designations have
display limitations (as explained under each subheading), they are not the
recommended method of providing an interactive interface between the
user and the executing program.
Using a WORKSTN device is the recommended method of providing
interactive capability between the user and the executing program. It
offers greater flexibility in programming applications. A WORKSTN device
can be defined for both input and output operations. The programmer can
specify which fields on the display are input fields, which are output fields,
and which are both input and output fields. (See the Migration RPG
Screen Format Reference Manual for information on the WORKSTN device
and how to program workstation screen specifications.)
B–1
CONSOLE, KEYBORD, And CRT Device Usage
16 P Primary File
B–2
CONSOLE, KEYBORD, And CRT Device Usage
Table B–1 (Cont.) Rules for Coding CONSOLE Device File Description
Specification
Column Allowable
Number Values Explanation
S Secondary File
D Demand File
R Record Address File
Blank
24-27 Record This value must be the same as the highest ending
length position defined for the CONSOLE file on the input
specifications.
31 Blank Used for record address files only. Required if the key
fields in the record address file are the same as the key
fields in the indexed file.
A Used for record address files only. Identifies indexed files
with zoned-decimal or trailing numeric key fields.
B–3
CONSOLE, KEYBORD, And CRT Device Usage
Table B–1 (Cont.) Rules for Coding CONSOLE Device File Description
Specification
Column Allowable
Number Values Explanation
40-46 CONSOLE This field must contain CONSOLE as the device name.
TTY Required entry if column 15 contains D. Program must
then be manually linked to runtime library.
Table B–2 Rules for Coding CONSOLE Device File Input Record
Specifications
Column Allowable
Number Values Explanation
7-14 File name Must contain the name of the CONSOLE device file.
This name must match the name in the associated File
Description specification.
B–4
CONSOLE, KEYBORD, And CRT Device Usage
Table B–2 (Cont.) Rules for Coding CONSOLE Device File Input Record
Specifications
Column Allowable
Number Values Explanation
B–5
CONSOLE, KEYBORD, And CRT Device Usage
Table B–3 Rules for Coding CONSOLE Device File Input Specifications
Column Allowable
Number Values Explanation
44-47 Numeric entry Must contain record location where field begins.
48-51 Numeric entry Must contain the record location where the field ends.
Subfields can redefine a larger field, but they cannot
overlap previously defined fields.
53-58 Field name Must contain a unique field name from one to six
alphameric characters. This name will display as the
prompt.
B–6
CONSOLE, KEYBORD, And CRT Device Usage
$ RPGCON ABC
- or -
$ RPGCON
CON>ABC
where "ABC" is the name of the file containing the RPG source code
statements. The following rules apply when using RPGCON:
• An extension of .RPG is assumed for the input file. If this is not the
file name extension, then the extension must be given explicitly.
• The output file will be given the same name as the input file, with
FM appended to the file name. The output file will have an extension
of .FRM to indicate screen format file. For example, if the RPG
source file being processed by RPGCON was labeled FOZZ.RPG, the
screen format file produced by the RPGCON Utility would be labeled
FOZZFM.FRM.
The output file generated by the RPGCON Utility contains screen format
source code (S & D specifications) and may be edited (or customized) as
much as necessary. This file must then be compiled using the screen
format generator (SFG).
Following the compilation of the screen format file, an executable image
is produced by linking the program object generated by the RPG compiler
and the screen object generated by the screen format generator.
The following example indicates how a CONSOLE program would be
compiled and linked to produce an executable image.
Example B–1 Compiling and linking a CONSOLE program
$ RPG FOZZ
$ RPGCON FOZZ
$ SFG FOZZFM
$ LINK FOZZ,FOZZFM
B–7
CONSOLE, KEYBORD, And CRT Device Usage
RPG does not support the use of multiple record formats with CONSOLE
devices. All screen formats generated by the utility RPGCON are given
the format name XX. This means that only the first format in the screen
format file will be displayed to the user for the purposes of inputting
data. If multiple record types have been defined for the CONSOLE device,
the following message will be displayed when the screen format file is
compiled:
** WARNING ** 100 - Duplicate screen name, XX in S specification
The following sections describe the fields which appear on the control line
and how to interact with a CONSOLE screen.
B–8
CONSOLE, KEYBORD, And CRT Device Usage
Alphameric fields will specify length. Numeric fields will specify length
and decimal positions, with a period separator between the two items.
B–9
CONSOLE, KEYBORD, And CRT Device Usage
B–10
CONSOLE, KEYBORD, And CRT Device Usage
24-27 Record Must contain the length of the largest record to be output.
length
40-46 CRT This field must contain CRT as the device name.
B–11
CONSOLE, KEYBORD, And CRT Device Usage
15 H Heading
D Detail
T Total
E Exception
B–12
CONSOLE, KEYBORD, And CRT Device Usage
B–13
CONSOLE, KEYBORD, And CRT Device Usage
B–14
CONSOLE, KEYBORD, And CRT Device Usage
Table B–8 (Cont.) Rules for Coding KEYBORD Device File Description
Specification
Column Allowable
Number Values Explanation
24-27 Record Must contain the length of the largest field to be entered.
length
40-46 KEYBORD This field must contain KEYBORD as the device name.
B–15
CONSOLE, KEYBORD, And CRT Device Usage
To use the KEYnn operation, the following rules apply for coding the
Calculation specification:
B–16
CONSOLE, KEYBORD, And CRT Device Usage
49-51 Field Length Required entry if not defined elsewhere in the RPG
program.
B–17
CONSOLE, KEYBORD, And CRT Device Usage
To use the SETnn operation properly, the following rules apply for coding
the Calculation specification:
B–18
CONSOLE, KEYBORD, And CRT Device Usage
B–19
Index
ALTSEQ • 17–2
A AND
input specifications • 7–2, 7–3, 7–4, 7–8, 12–6
output specifications • 9–2
Adding records • 13–24
record identification
Addition • 11–9
example • 12–7
ADD operation code
ANDxx operation code
example • 12–11
general information • 11–3, 11–7
general information • 11–1
rules • 11–11
rules • 11–9
Arithmetic operation codes • 11–1
ADD option
rules • 11–1
output specifications • 9–4
signs • 11–2
addrout files
Arithmetic operations • 11–136
File Description specification • 13–17
addition • 11–9
Addrout files
division • 11–34
creating • 13–16
remainder • 11–94
example • 13–16, 13–19
multiplication • 11–92
Extension specification • 13–18
square root • 11–124
file designation • 4–6
subtraction • 11–125
function • 13–16
zero add • 11–137
record length • 4–8
zero subtract • 11–138
rules for specifying • 13–17
Array elements
specifying
outputting • 15–34
key length • 4–15
searching • 15–30
Alphameric data
Array name
defining fields
alternate entry • 5–8
example • 10–3
primary entry • 5–4
Alphameric fields
Arrays • 15–15
comparing • 11–3
alternate format • 15–21
Alphameric literals
compile-time • 15–17
factor 1
compile-timed
calculation specifications • 8–4
delimiter • 15–17
factor 2
creating • 15–18
calculation specifications • 8–6
array input records • 15–18
Alternate collating sequence • 3–5
definition • 15–15
alternate sequence table
elements
coding • 17–1
loading
specifying • 17–1
input specifications • 7–11
Alternate format
execution-time • 15–18
arrays • 15–21
*IN,xx indicators • 12–31
compile-time • 15–21
in calculations • 15–26
pre-execution-time • 15–21
example • 15–27
related • 15–21
indexed
Alternate keys
LOKUP operation code • 11–74
specifying • 4–24
*IN indicators • 12–31
Alternate sequence table
input records
coding • 17–1
example • 15–18
Index–1
Index
Index–2
Index
Index–3
Index
Chained files
Compile-time arrays • 15–17
Record address type (cont’d)
advantages • 15–17
processing mode creating • 15–19, 15–22
valid combinations • 4–16 rules for specifying • 15–19
CHAIN operation delimiter • 15–19
example • 13–13 outputting • 15–33
CHAIN operation code updating • 15–32
general information • 11–6 writing • 15–33
rules • 11–24 Compile-time tables • 15–2
Character data advantage • 15–3
defining fields delimiter • 15–4
example • 10–3 input records
Character data type creating • 15–4
example • 10–2 rules for specifying • 15–4
Character sets outputting • 15–15
ASCII • A–1 rules for defining • 15–7
Decimal • A–1 COMP operation code
EBCDIC • A–1 example • 12–11
Hexadecimal • A–1 general information • 11–3
Collating sequences • 17–1 rules • 11–27
alternate • 3–5 Conditioning indicators
alternate sequence table relationship with control level indicators
coding • 17–1 calculation specifications • 8–4
ASCII • 3–5 CONSOLE • B–2 to B–9
EBCDIC • 3–5 automatic generation of display screen formats •
file translation parameters • 17–4 B–7
coding • 17–4 displaying CONSOLE device files • B–8
specifying • 17–1 control key usage • B–9
EBCDIC • 17–1 record identification code • B–8
file translation parameters • 17–1 record identification indicator • B–8
user defined • 17–1 file description specification • B–2
user-defined • 3–5 input specifications • B–4
Collating sequencess limitations of • B–2
alternate • 17–1 Constants
Column numbers • 2–1 output specifications • 9–22
Command key indicators • 12–19 Continuation entries • 4–21
Comments • 2–3, 8–10 Continuation lines • 4–20
control specification • 3–6 continuation entries • 4–21
extension specifications • 5–11 continuation options • 4–21
file description specification • 4–27 disk files • 4–21
input specifications • 7–18 INFDS data structure • 4–23
line counter specifications • 6–3 INFSR subroutine • 4–23
output specification • 9–28 SPECIAL device files
Compare operation codes entries • 4–21
COMP • 11–3 options • 4–21
Comparing data • 11–27 specifying a screen format file • 4–23
Compile Qualifier specification • 21–1 workstation device files
Compiler directives • 2–3 entries • 4–22
/COPY • 2–4 options • 4–22
/EJECT • 2–4 Continuation options • 4–21
/SPACE • 2–4
/TITLE • 2–4
Index–4
Index
CONTINUE
halt response • 1–11
Control break
D
example • 1–17
Data
indicator initialization • 1–12
comparing contents • 11–3
last record • 1–12
fields
Control break indicators • 12–12
initialization • 11–137, 11–138
calculation specifications • 8–2
moving • 11–5, 11–6, 11–83, 11–85, 11–89
conditioning data
arrays • 11–85
input specifications • 7–12
left-justified • 11–89
function • 12–12
right-justified • 11–83
input specifications • 7–12
tables • 11–85
setting • 11–6
moving from the left • 11–6
split-control fields • 12–16
transferring • 11–5, 11–6
usage • 1–13
Data files
Control breaks • 1–13
addrout access
processing • 1–13
File Description specification • 13–18
split-control fields • 12–16
file translation parameters
Control level indicators
coding • 17–4
relationship with conditioning indicators
translation parameters • 17–4
calculation specifications • 8–4
Data formats
Control specification • 3–1
binary
Alternate collating sequence • 3–5
tables and arrays
comments • 3–6
alternate entry • 5–9
currency symbol • 3–3
primary entry • 5–6
date edit code • 3–4
Extension specification
date format code • 3–3
alternate entry • 5–9
DEBUG option • 3–2
primary entry • 5–6
general description • 1–2
input specification • 7–9
inverted print • 3–4
numeric
mulitple • 3–1
tables and arrays
/COPY
alternate entry • 5–9
compiler directive • 2–4
primary entry • 5–6
Copybooks
output specification • 9–21
Auto Report • 21–3
packed-decimal
/COPY statement(XS)Auto Report utility
tables and arrays
example • 21–3
alternate entry • 5–9
Creating files
primary entry • 5–6
add entry • 4–24
Data Structures • 7–1
buffers • 13–38
defining • 16–1
CRT • B–10 to B–13
defining subfields • 7–11, 7–12
file description specification • B–10
initialization • 16–3
limitations of • B–10
input specifications
output specifications • B–12
name • 7–2
field • B–12
local data area • 16–6
record • B–12
name • 7–2
Currency symbol • 3–3
output • 9–12
floating
output specifications • 9–12
output specifications • 9–23
redefining input records • 16–5
rules for specifying • 3–3
reorganizing input fields • 16–6
subfields • 16–2, 16–4
Index–5
Index
Data Structures
Detail time records
subfields (cont’d)
output specifications • 9–3
binary • 16–3 Device codes • 4–18
numeric • 16–3 rules for specifying • 4–20
packed • 16–3 specifying
updating files • 13–26 card reader • 4–18
using • 16–3 disk • 4–18
using storage in more than one way • 16–5 printer • 4–18
Data transfer workstation • 4–18
move WORKSTN • 4–18
rules • 11–5 Device display limitations • B–1
Data types • 10–1 Disk device
binary • 10–4 specifying • 4–18
character • 10–2 Disk files
packed-decimal • 10–6 continuation lines • 4–21
specifying Division • 11–34
tables and arrays remainder • 11–94
alternate entry • 5–9 DIV operation code
primary entry • 5–6 general information • 11–1
zoned-decimal • 10–7 MVR operation code • 11–94
Date remainder • 11–94
edit code • 3–4 rules • 11–34
format • 3–3 Do loop • 11–7
Debugging Migration RPG programs • 11–29 DO operation code
DEBUG operation code general information • 11–3, 11–7
rules • 11–29 rules • 11–36
Decimal character set • A–1 Do until loop • 11–7
Decimal positions DOUxx operation code
calculation specification • 8–8 general information • 11–3, 11–7
extension specification rules • 11–39
alternate entry • 5–10 Do while loop • 11–7
primary entry • 5–7 DOWxx operation code
input specification • 7–10 general information • 11–3, 11–7
Deferred write • 4–26 rules • 11–42
DEFN operation code
rules • 11–32
Deleting records
example • 13–28
DEL option
E
output specifications • 9–4 EBCDIC character set • A–1
Demand file • 4–5 EBCDIC collating sequence
Demand files specifying • 17–1
processing mode Edit Code modifiers
record address type output specifications • 9–23
valid combinations • 4–16 Edit codes
Detail records example • 9–18, 12–5
output specifications • 9–3 Y edit code • 13–19
Detail time • 1–7 output specifications • 9–17
processing individual records • 1–18 specifying
Detail time processing notation • 3–4
setting LR • 11–6
Index–6
Index
Index–7
Index
Index–8
Index
Index–9
Index
Files (cont’d)
File designations • 4–4
array • 4–4 indexed
chained • 4–4 processing modes • 4–12
demand • 4–4 reading • 11–24
full-procedural • 4–4 sequential access via a key • 11–107
primary • 4–4 Setting an access point • 11–118
record-address • 4–4 specifying
secondary • 4–4 key length • 4–15
table • 4–4 input/output operation codes • 11–6
File format • 4–7 KEYBORD file
File names • 10–9 processing modes • 4–14
file Description specification • 4–2 limits
input specification • 7–2 specifying
Line Counter specification • 6–1 key length • 4–15
output specification • 9–2 look-ahead read • 1–12
rules for specifying • 13–2 matching record indicator • 12–28
File organizations • 4–16 multifile processing • 13–29
indexed • 13–4 organization • 13–3
relative • 13–3 output • 14–1
sequential • 13–3 controlling overflow • 4–17
Files using overflow indicators • 4–17
adding records • 13–24 primary • 4–4
addrout • 13–16 primary read • 1–12
specifying printer file
key length • 4–15 processing modes • 4–13
array printer output • 14–1
input controlling overflow • 4–17
specifying • 5–2 using overflow indicators • 4–17
output processing mode • 4–8
specifying • 5–3 processing using matching fields
chained • 4–5 input specifications • 7–14
characteristics • 13–1 random access • 13–12
conditioning with an external indicator • 4–25 random access by key • 13–19
creating • 13–21 record address
indexed • 13–22 processing modes • 4–13
output • 14–1 specifying • 5–2
printer output • 14–1 record-address • 4–5
record-limits • 13–7 record formats • 13–2
relative • 13–22 record-limits • 13–7
sequential • 13–21 relative
definition • 13–1 processing modes • 4–11
deleting records • 13–28 reading • 11–24
demand • 4–5 secondary • 4–4
external indicators • 12–30 secondary read • 1–12
file access methods • 13–5 sequence code • 4–7
file names • 13–2 sequential
file types • 13–2 processing modes • 4–9
first cycle sequential access • 13–5, 13–6, 13–19
openning • 1–10 sequential by key access • 13–6
full-procedural • 4–5, 13–19 sequential input • 11–104
example • 13–20 reversed • 11–109
Index–10
Index
Files (cont’d)
First-page indicator • 14–6
sequential input based on a key • 11–107 output specifications • 9–10
sequential within limits access • 13–7 First page indicators • 12–24
sharing • 4–25 conditioning output data • 12–24
SPECIAL file example • 12–24
processing modes • 4–14 function • 12–24
specifying FL
chained • 4–4 form length flag • 6–2
demand • 4–4 Floating currency symbol
display • 4–3 example • 12–5
full-procedural • 4–4 output specifications • 9–23
input • 4–3 FORCE • 1–12
output • 4–3 FORCE operation code
primary • 4–4 general information • 11–6
processing mode • 4–8 rules • 11–59
record-address • 4–4 Form length
secondary • 4–4 FL • 6–2
update • 4–3 line counter specification • 6–2
table Form length flag
input FL • 6–2
specifying • 5–2 line counter specification • 6–2
output FREE
specifying • 5–3 operation code • 19–6
updating records • 13–26 rules • 19–6
workstation address FREE operation code
processing modes • 4–13 rules • 11–61
*FILES • 17–5 From-file name
File sharing arrays • 5–2
column 73 access codes • 4–26 record-address files • 5–2
definition • 4–25 tables • 5–2
specifying • 4–25 Full-procedural file • 4–5
usage • 4–26 Full-procedural files
File specification processing mode
general description • 1–2 record address type
SUBR01 • 4–21 valid combinations • 4–16
File translation • 3–6 Record address type
File translation code • 3–6 processing mode
File translation parameters valid combinations • 4–16
coding • 17–4
specifying • 17–1, 17–4
File types • 4–3
display • 4–3
input • 4–3, 13–2
G
output • 4–3, 13–2 *GETIN
update • 4–3, 13–2 logic cycle • 1–11
First cycle • 1–15 GOTO
reading records • 1–12 TAG • 11–127
steps • 1–10 target • 11–127
First page GOTO operation code
indicator initialization • 1–12 general information • 11–3
rules • 11–63
Index–11
Index
Index–12
Index
Indicators Indicators
*IN,xx specifying (cont’d)
result field (cont’d) *INxx • 7–11, 7–12
calculation specifications • 8–7 types • 12–3
*INxx • 12–32 U1 - U8 • 12–1, 12–30
factor 1 usage • 12–10
calculation specifications • 8–5 usage • 12–3
factor 2 using as fields • 12–31
calculation specifications • 8–6 INFDS data structure • 16–8
result field continuation lines • 4–23
calculation specifications • 8–7 declaring • 4–23
KA - KN, KP - KY • 12–19 Information data structure • 16–8
usage • 12–10 INFSR subroutine
L0 • 12–1, 12–12, 12–27 *CANCL • 1–13
output specifications • 9–10 continuation lines • 4–23
L1 - L9 • 12–12 declaring • 4–23
usage • 12–4, 12–10 *GETIN • 1–11
last record *IN indicators • 12–31
end-of-job • 1–13 example • 12–31
Last Record • 12–26 function • 12–31
Level Zero • 12–27 specifying array elements • 12–31
LR • 12–1, 12–12 specifying arrays • 12–31
example • 12–5 Input
usage • 12–4, 12–10 forcing file selection
matching record • 12–28 FORCE • 11–59
MR • 12–1, 12–28 indexed
negating Setting a starting point • 11–118
calculation specifications • 8–2 KEYBORD device • 11–68, 11–115
OA - OG, OV • 12–17 reading by key • 11–24
usage • 12–10 sequential based on a key • 11–107
overflow • 4–17, 12–17, 14–7 sequential read • 11–104
1P • 12–1, 12–24, 14–6 reversed • 11–109
example • 12–5 Input/output operation codes • 11–6
printer output files • 14–6 Input specification modifiers
program defined • 12–1 Auto Report Utility • 21–5
record identification • 1–13 Input specifications • 7–1
record identifying AND • 7–2, 7–3, 7–4
01 - 99 • 12–4 record-identification conditions • 7–8
H1 - H9 • 12–4 comments • 7–18
L1 - L9 • 12–4 control break indicators • 7–12
LR • 12–4 data format • 7–9
record-identifying • 7–4 data structure • 7–1
resulting • 12–10 decimal positions • 7–10
calculation specifications • 8–10 field indicators • 7–17
return (RT) field name • 7–11
check • 1–12 field positions
RT • 12–23 end • 7–10
usage • 12–4, 12–8, 12–10 start • 7–10
setting off • 11–120 field-record-relation indicators • 7–15
setting on • 11–121 field start and end positions • 7–9
specifying file name • 7–2
*IN,xx • 7–11, 7–12
Index–13
Index
Index–14
Index
Index–15
Index
Index–16
Index
O subprogram
CALL • 11–19, 19–2
EXTRN • 11–57, 19–4
Index–17
Index
Index–18
Index
P RPG
list • 11–102
PARM
1P operation code • 19–7
example • 12–5 rules • 19–7
Packed-decimal data processing in first cycle • 1–10
defining fields PARM operation code
example • 10–6 general information • 11–4
determining length • 10–6 rules • 11–98
Packed-decimal data type 1P indicator • 12–24, 14–6
example • 10–6 conditioning output data • 12–24
specifying example • 12–24
tables and arrays function • 12–24
alternate entry • 5–9 *PLACE
primary entry • 5–6 special words
Packed-decimal fields output specifications • 9–14
key PLIST
length • 4–15 *ENTRY
PAGE usage • 1–10
example • 12–5, 13–19 operation code • 19–11
special words rules • 19–11
output specifications • 9–13 PLIST operation code
PAGE1 general information • 11–4
special words rules • 11–102
output specifications • 9–13 Porting RPG applications
PAGE2 device specifications • 4–18
special words disk files
output specifications • 9–13 continuation lines • 4–21
PAGE3 IBM RPG II compatibility
special words record address files
output specifications • 9–13 key length • 4–8, 4–15
PAGE4 SPECIAL device files
special words continuation lines
output specifications • 9–13 entries • 4–21
PAGE5 options • 4–21
special words SUBR01 support • 4–21
output specifications • 9–13 workstation device files
PAGE6 continuation lines
special words entries • 4–22
output specifications • 9–13 options • 4–22
PAGE7 Pre-execution-time arrays • 15–18
special words creating • 15–18, 15–23
output specifications • 9–13 rules for specifying • 15–18
outputting • 15–33
Index–19
Index
Index–20
Index
R Record-identification conditions
AND • 7–8
identifying record types • 7–6
Random by addrout file access • 13–16 OR • 7–8
example • 13–19 specifying
rules for specifying • 13–17 character • 7–7
Random by key file access • 13–14 comparison character • 7–8
example • 13–15 digit • 7–7
rules for specifying • 13–14 not • 7–7
Random file access • 13–12 position • 7–6
using zone • 7–7
an addrout file • 13–16 Record identifying indicators
keys • 13–14 example • 12–5
relative record numbers • 13–12 function • 12–4
example • 13–13 identifying record types • 12–4
rules for specifying • 13–13 Record-identifying indicators
READE operation code conditioning input data • 7–4
general information • 11–6 input specifications • 7–4
rules • 11–107 Record indentification • 1–13
READ operation code Record length • 4–8
general information • 11–6 Record-limits files
rules • 11–104 example • 13–7
READP operation code function • 13–9
general information • 11–6 rules for specifying • 13–9
rules • 11–109 Record locking
Record-address file • 4–5 trapping
Record address files example • 11–26
file designation • 4–6
Index–21
Index
Related tables
Records
creating (cont’d)
adding • 13–24
output specifications • 9–4 input records • 15–5
array input • 15–18 LOKUP operation code
basic processing cycle • 1–7 rules • 11–74
deleting • 13–28 Relative file organization • 13–3
example • 13–28 example • 13–3
output specifications • 9–4 Relative files
identifying types • 7–4 adding records • 13–25
processing totals • 1–16 rules for specifying • 13–25
record identifying indicators • 12–4 creating • 13–22
specifying rules for specifying • 13–22
detail processing modes • 4–11
output specifications • 9–3 updating records
exception rules for specifying • 13–27
output specifications • 9–3 Result field
format • 4–7 calculation specifications • 8–7
heading restrictions
output specifications • 9–3 calculation specifications • 8–8
length rounding data
fixed • 4–7 half-adjust • 8–9
variable • 4–7 specifying *IN,xx indicator array elements • 8–7
record-identification conditions • 7–6 specifying *INxx indicators • 8–7
total Resulting indicators • 12–10
output specifications • 9–3 calculation specifications • 8–10
types example • 12–11
defining the ordering sequence • 7–2 function • 12–10
output specifications • 9–3 RETRN
updating • 13–26 operation code • 19–12
example • 13–27 rules • 19–12
using record identifying indicators • 12–4 RETRN operation code
Record types rules • 11–111
defining the ordering sequence • 7–2 Return indicator
detail RT • 12–23
output specifications • 9–3 Return status
exception halt indicators • 1–14
output specifications • 9–3 RLABL operation code
heading general information • 11–4
output specifications • 9–3 rules • 11–113
identifying • 7–4 RPGCON • B–7
output specifications • 9–3 RPG II programs
specifying arrays • 15–15
record-identification conditions • 7–6 RPGLDA • 16–6
total RPG program
output specifications • 9–3 example • 1–19
using record identifying indicators • 12–4 RPG programs
Related arrays • 15–19 documenting • 2–3
alternate format • 15–21 RPG subprograms
creating • 15–19, 15–21 halt indicators
Related tables processing • 12–22
creating • 15–7 RT indicator • 12–23
initialization • 1–10
Index–22
Index
SETLL operation
S limits processing • 13–11
SETLL operation code
general information • 11–6
Screen format names
rules • 11–118
output specifications • 9–22
SETnn operation code
Screen formats
general information • 11–6
continuation lines • 4–23
rules • 11–115
Secondary file • 4–4
SETOF operation code
Secondary files
general information • 11–6
processing mode
rules • 11–120
record address type
SETON operation code
valid combinations • 4–16
general information • 11–6
Record address type
rules • 11–121
processing mode
Set operation codes • 11–6
valid combinations • 4–16
rules • 11–6
Sequence checking
Skip after
using matching fields • 7–14
output specifications • 9–8
Sequence code • 4–7
Skip before
Sequence codes • 7–2
output specifications • 9–7
assigning a numeric code • 7–3
SORTA operation code
extension specifications
rules • 11–122
alternate entry • 5–10
/SPACE
primary entry • 5–7
compiler directive • 2–4
sequence number • 7–3
Space after
specifying
output specification • 9–6
alphabetic • 7–2
Space before
numeric • 7–2, 7–3
output specification • 9–6
sequence option • 7–4
SPECIAL Device File
Sequence Number
Coding the SPECIAL File Subroutine • 18–4
input specification • 7–3
File Description Continuation Specifications • 18–2
Sequential by key file access
File Description Specifications • 18–1
example • 13–7
Introduction • 18–1
rules for specifying • 13–6
Migration RPG Program Logic • 18–3
Sequential file access • 13–5, 13–6
Programming Features Supported • 18–3
example • 13–6
Sample Program • 18–5
rules for specifying • 13–6
SUBR01 Support • 18–1
Sequential file organization • 13–3
SPECIAL device files
example • 13–3
continuation lines
Sequential files
entries • 4–21
adding records • 13–24
options • 4–21
example • 13–24
SPECIAL device routine
rules for specifying • 13–24
name • 4–20
creating • 13–21
SPECIAL device routines
rules for specifying • 13–21
SUBR01 • 4–21
processing modes • 4–9
SPECIAL files
Sequential input
processing modes • 4–14
example • 13–13
Special words • 14–4
Sequential within limits file access
factor 1
example • 13–8
calculation specifications • 8–4
record-limits file • 13–7
factor 2
Index–23
Index
Index–24
Index
Subroutines (cont’d)
Subprograms
calling • 19–2 operation codes • 11–4
RPG Subtraction • 11–125
CALL • 11–19 Symbolic device • 4–20
FREE • 11–61, 19–6 System services
parameter list • 19–11 calling • 19–2
PARM • 19–7 passing parameters • 19–7
passing parameters • 19–7
PLIST • 19–11
RETRN • 19–12
RPG
T
calling
Table
CALL • 11–19
elements
halt indicators
initialization • 11–73
processing • 12–22
LOKUP operation code • 11–73
parameter list • 11–102
sequencing • 11–72
PARM • 11–98
Table name
passing parameters • 11–98
alternate entry • 5–8
PLIST • 11–102
primary entry • 5–4
RETRN • 11–111
Tables • 15–1
startup • 1–10
compile-time • 15–2
SUBR01
rules for defining • 15–7
calling • 11–54
compile-timed
parameter passing • 11–113
delimiter • 15–3
file description specification • 4–21
creating
SPECIAL device option • 4–21
input records • 15–3
SUBR21
definition • 15–1
calling • 11–54
entries • 15–3
parameter passing • 11–113
input records • 15–3
example • 16–7
creating • 15–3
local data area subroutine • 16–7
rules for specifying • 15–3
SUBR23
loading time
calling • 11–54
selecting • 15–2
parameter passing • 11–113
LOKUP operation code • 11–73, 15–10
example • 11–55, 11–114
names • 10–9
Subroutines
operations
external
LOKUP • 11–71
calling
permanent update • 15–14
CALL • 11–19
pre-execution-time • 15–3
EXIT • 11–54
rules for defining • 15–9
RLABL • 11–113
referencing entries • 15–10
identification • 11–13
related • 15–1, 15–5, 15–16
internal
creating • 15–7
begin
searching • 11–73, 15–10
BEGSR • 11–13
rules for specifying • 15–10
calling
set up and usage example • 11–76
EXSR • 11–56
single • 15–1, 15–16
conditional calling • 11–21
creating • 15–6
termination
compile-time • 15–7
ENDSR • 11–49
pre-execution-time • 15–9
names • 10–9
specifying • 4–4
Index–25
Index
Index–26
Index
X
XFOOT operation code
arrays • 15–28
example • 15–28
general information • 11–1
Index–27