GC21 7567 2_System_3_RPG_II_Additional_Topics_Programmers_Guide_Jul74 2 System 3 RPG II Additional Topics Programmers Guide Jul74

GC21-7567-2_System_3_RPG_II_Additional_Topics_Programmers_Guide_Jul74 GC21-7567-2_System_3_RPG_II_Additional_Topics_Programmers_Guide_Jul74

User Manual: GC21-7567-2_System_3_RPG_II_Additional_Topics_Programmers_Guide_Jul74

Open the PDF directly: View PDF PDF.
Page Count: 516

DownloadGC21-7567-2_System_3_RPG_II_Additional_Topics_Programmers_Guide_Jul74 GC21-7567-2 System 3 RPG II Additional Topics Programmers Guide Jul74
Open PDF In BrowserView PDF
IBM System/3
RPG II Additional Topics
Programmer's Guide

Program Numbers:
5702-RG1 (Model
5704-RG1 (Model
5704-RG2 (Model
5705-RG1 (Model

10)
15)
15)
12)

Page of GC21-7567-2
Issued 30 June 1978
By TNL: GN21-5616

Third Edition (July 1974)
This is a major revision of, and obsoletes, GC21-7567-1. Information concerning IBM
System/3 Model 15 has been added and numerous corrections have been made. Changes to
text and illustrations are indicated by a vertical line to the left of the change; new or
extensively revised illustrations are denoted by the symbol 0 at the left of the caption.
This edition applies to the following IBM System/3 RPG II program products:
Version

Modification

Program Number

System/3 Model

15
6
2
4

00
00
00
00

5702-RG1
5704-RG1
5704-RG2
5705-RG1

8 and 10 Disk
15A,B,C
15D
12

Changes are periodically made to the information herein; before using this publication
in connection with the operation of I BM systems, refer to the latest IBM Systeml3
Bibliography, GC20-8080, for the editions that are applicable and current.
This publication contains examples of data and reports used in daily business operations.
To illustrate them as completely as possible, the examples include the names of
individuals, companies, brands, and products. All of these names are fictitious and any
similarity to the names and addresses used by an actual business enterprise is entirely
coincidental.
Use this publication only for the purposes stated in the Preface.
Publications are not stocked at the address below. Requests for copies of IBM publications
and for technical information about the system should be made to your IBM representative
or to the IBM branch office serving your locality.
This publication could contain technical inaccuracies or typographical errors. Use the
Reader's Comment Form at the back of this publication to make comments about this
publication. If the form has been removed, address your comments to IBM Corporation,
Publications, Department 245, Rochester, Minnesota 55901. Comments become the
property of IBM.

© International

Business Machines Corporation 1971, 1974

------ --------- -----_.- ---

Technical Newsletter

This Newsletter No. GN21-5709
Date 21 December 1979
Base Publication No. GC21 - 7567 - 2
File No. S3-28
Previous Newsletters GN21-5616
GN21-5389'

IBM System/3
RPG II Additional Topics
Programmers Guide

©IBM Corp. 1971, 1974

This technical newsletter applies to current versions and modifications of the applicable System/3
programs listed in the edition notice, and provides replacement pages for the subject publication.
These replacement pages remain in effect for subsequent versions and modifications unless
specifically altered. Pages to be inserted and/or removed are:

v through viii (text rearranged)
3-7,3-8
3-17,3-18
5-65,5-66
5-75,5-76
6-33,6-34
6-37,6-38

6-47,6-48
7-7 through 7-10
7-19, 7-20
7-31, 7-32
9-49,9-50
10-41, 10-42

Changes to text and illustrations are indicated by a vertical line at the left of the change.
Summary of Amendments
Miscellaneous technical changes
Note: Please file this cover letter at the back of the manual to provide a record of changes.

IBM Corporation, Publications, Department" 245, Rochester, Minnesota 55901
1211 cl\n

(',..~...

1 Q'7Q

,-,--------

- - --,---,-_.-

Technical Newsletter

)

Th is Newsletter No.

G N21-5616

Date

30 June 1978

Base Publication No.

GC21-7567-2

File No.
Previous Newsletters

S3-28
G N21-5389

IBM System/3
RPG II Additional Topics
Programmer's Guide
©IBM Corp. 1971,1974

This technical newsletter applies to the current versions and modifications of the applicable
System/3 programs listed in the edition notice and provides replacement pages for the subject
publication. These replacement pages remain in effect for subsequent versions and modifications
unless specifically altered. Pages to be inserted and/or removed are:
Cover
Title Page, Edition Notice
v, vi
3-11 through 3-16
4-3,4-4
4-27,4-28
5-53 through 5-56
5-56.1 through 5-56.6 (added to accommodate new and moved text)
5-77,5-78

)

Changes to text and illustrations are indicated by a vertical line at the left of the change.

Summary of Amendments
•

Expanded description of the RPG II Linkage Editor, page 5-54

•

Included miscellaneous technical changes

Note: Please file this cover letter at the back of the manual to provide a record of changes.

IBM Corporation, Publications, Department 245, Rochester, Minnesota 55901
©IBM Corp. 1978

Printed in U.S.A.

TIm)!

Technical Newsletter

This Newsletter No.

~\

GN21-5389

Date

24 May 1976

Base Publication No.

GC21-7567-2

File No.

53-28

Previous Newsletters

None

J

IBM System/3
RPG II Additional Topics
Programmer's Guide
©IBM Corp. 1971,1974

This technical newsletter provides replacement pages for the subject publication. Pages to be
inserted and/or removed are:
i, ii

1-5, 1-6
3-21,3-22
3-27 through 3-32
3-39,3-40
4-3,4-4
4-7,4-8
5-5,5-6

)

5-9,5-10
5-49,5-50
5-67,5-68
5-77 through 5-80
6-9,6-10
7-9, 7-10
7-19 through 7-22
8-27,8-28

9-1,9-2
9-27,9-28
9-41 through 9-44
9-49,9-50
9-55,9-56
10-11 through 10-14
10-21 through 10-24

Changes to text and illustrations are indicated by a vertical line at the left of the change; new or
extensively revised illustrations are denoted by the symbol. at the left of the caption.

Summary of Amendments
•
•

References to Model 8 and Model 12 have been added.
Miscellaneous additions and corrections.

Note: Please file this cover letter at the back of the manual to provide a record of changes.

\

)

"'IBM Corporation, Publications, Department 245, Rochester, Minnesota 55901
© IBM Corp. 1976

Printed in U.S.A.

Page of GC21-7567-2
Issued 24 May 1976
By TNL: GN21-5389

Preface

This manual presents advanced RPG II programming topics
for application programmers and students, who must code
programs for IBM System/3:

I

•

Model6

•

Model8

•

Model 10 (Card System)

'. Model 10
•

ORGANIZATION OF THE MANUAL

This publication has eleven chapters. Chapters 1-6 cover
information that is basic to most data processing jobs:
RPG II program logic, detailed information about writing
input, output, and calculation specifications and the concepts and specifications involved in multifile processing.
Additional programming topics that youmay require for
your job are presented in Chapters 7-11: controlling input
and output during calculation time, tables, arrays, data
structure, and the DEBUG operation.

Model 12
RELATED PUBLICATIONS

•

Model 15

The System/3 Model 8 is supported by System/3 Model 10
control programming and program products. The facilities
described in this publication for the Model 10 are also applicable to the Model 8, although the Model 8 is not referred
to. Note that not all devices and features that are available
on the Model 10, are available on the Model 8. Therefore,
Model 8 users should be familiar with the contents of the
IBM System/3 ModelBlntroduction, GC21-5144.

)

PREREQUISITES I,

This manual assumes that you have coded and tested some
basic RPG II programs that include listing records on a
printer, simple calculations, group totals, and the use of
more than one record type. You may have gained this
experience through IBM education courses, programmed
instruction courses, or previous data processing experience.
Introduction to RPG /I, GC21-7514, contains some of
this basic information.

There are numerous IBM System/3 publications containing
further information on RPG II. The following are the related reference manuals:
•

I

IBM System/3 Card System RPG" Reference Manual,
SC21-7500

• IBM System/3 RPG " Reference Manual, SC21-7504
(Model 10, Model 12 and Model 15)
• IBM System/3 Model 6 RPG" Reference Manual,
SC21-7517

If you are programming on a disk system, it would be helpful if you would understand 'the disk concepts and disk file
processing information in the following books before reading this book:
• IBM System/3 Disk,'Concepts and Planning Guide,
GC21-7571
• IBM System/3 RPG /I Disk File Processing Programmer's
Guide, GC21-7566

)

ii

How To Use The Manual

This publication is a programmer's guide; it is not intended
to serve the same purpose as a reference manual of language
specifications and does not replace a reference manual.
RPG II programming topics are approached and organized
according to their normal use in a data processing job, using
examples whenever possible. Unlike a reference manual,
individual chapters are self-contained units of information,
intended to be read from beginning to end. However, if you
desire information about a specific topic, you may go
directly to that topic by using the index or the table of
contents. If an individual chapterhas a special prerequisite
topic, that topic is clearly identified on the title page of
the chapter.
Althoug~

the chapters are complete units, there is a logical
progression of topics through chapters 1-6. Therefore, you
may wish to read them consecutively. If you have read the
RPG /I Programming Fundamentals Programmed Instruction course, you do not need to read chapters 1-6 consecutively.

For ease of illustration, many of the examples in this book
use card-like figures to represent records. This does not
imply that a card device must be used for input or output
in these situations. Any of several input/output devices
might be used, depending on which System/3 model and
configuration you are using.

Review Questions
Review questions and answers are provided at the end of
each chapter. Where chapters contain several related topics,
these questions are grouped by subtopic. If you wish, you
may turn to the end of the chapter after you complete each
subtopic, to answer the review questions and reinforce what
. you have learned, before continuing the chapter.

)
iii

iv

Contents

)
HOW TO USE THE MANUAL

)

Editing
Methods of Editing
Editing and End Position
Using *PLACE To Print Duplicate Information.
Specifications For Using *PLACE
Formation Of Print Lines
Printing A Field Several Times On The Same Line
Using Two Printer Output Files in One Program
Model 10 Card and Disk Systems
Model 6
File Description Specifications
Output Format Specifications.
Example: End-of-the-Month Billing

3-12
3-12
3-19
3-19
3-22
3-22
3-26
3-27
3-28
3-28
3-28
3-29
3-31

REVIEW 3
Overflow and Fetch Overflow
Forms Alignment
Editing
*PLACE
Dual Printer Output Files

3-33
3-33
3-34
3-34
3-35
3-35

ANSWERS TO REVIEW 3.

3-36

CHAPTER 4. CARD OUTPUT OPERATIONS.
Introduction .
Punching And Printing On Cards
Punched Output.
Printing On Cards
Using One File For Both Input And Output.
Punching Into The Same Card That Is Read.
Punching Into A Blank Card In The File
When To Specify A Combined File
Stacker Selection
Input And Combined File Cards
Stacker Selecting Output File Cards
Merging Input And Output File Cards

4-1
4-2
4-2
4-2
4-2
4-8
4-8
4-11
4-14
4-14
4-15
4-17
4-19

REVIEW 4
Punching and Printing On Cards
Using One File For Both Input And Output.
Stacker Selection

4-21
4-21
4-21
4-23
4-25

CHAPTER 1. RPG II LOGIC •
Introduction.
Basic Data Processing Logic
Basic RPG II Logic
Specific Steps in Basic RPG II Logic
First Program Cycle.
Summary of Basic RPG II Logic
RPG II Logic Related To Indicators
1P (First Page) Indicators
Last Record Indicator (LR)
Record Identifying Indicators (01-99)
Field Indicators (01-99)
Resulting Indicators (01-99)
Halt Indicators (Hl-H9)
Overflow Indicator (OA-OG, OV).
Matching Records Indicator (MR)
Setting Indicators

1-1
1-2
1-2
1-4
1-6
1-7
1-7
1-7
1-13
1-16
1-19
1-25
1-31
1-35
1-41
1-42
1-43

REVIEW 1

1-45

ANSWERS TO REVIEW 1 .

1-46

CHAPTER 2. DESCRIBING AND USING INPUT.
Introduction .
Control Fields
Split Control Fields.
Checking the Sequence of Record Types.
Order of Record Types Within a Group
Checking the Order of Record Types in a Group
Incorrect Records Within a Group
Sequenced and Unsequenced Record Types in a Group
Unexpected or Unused Records Within a Group
Field Record Relation Indicators .
OR Relationship
OR Relationship With Field Record Relation Entries
Field Record Relation with Control Fields
Field Record Relation with Split Control Fields
Conditioning Use of Input Files (External Indicators)
Using One Program to do More Than One Job
Ending The Program Before Processing All Files
Completely.

2-1
2-2
2-2
2-5
2-6
2-6
2-12
2-12
2-14
2-14
2-15
2-15
2-16
2-18
2-18
2-19
2-19
2-22

ANSWERS TO REVIEW 4.

REVIEW2

2-25

CHAPTER 5. CONTROLLING OPERATIONS IN AN

ANSWERS TO REVIEW 2 .

2-28

CHAPTER 3. CONTROLLING PRINTER OUTPUT
Introduction .
Using Overflow and Fetch Overflow To Control Page
Formatting .
Overflow Indicators.
Specifications for Using Overflow Indicators
Preventing Records From Printing Over The

)

iii

Perforation .
Fetch Overflow
Aligning Forms

3-1
3-2
3-2
3-2
3-4
3-6
3-8
3-12

RPG II PROGRAM
Introduction.
Additional Uses of Indicators To Control Calculations
and Output.
Preventing Operations From Being Done When
An Error Occurs
Controlling Which Operations Are Done for a
Specific Program Run.
Controlling Calculations When Overflow Occurs
Performing Calculations On The Basis of the Results
Of Other Calculations.
Con troll ing Operati ons on the Basis of the Next Record
In A File

5-1
5-2
5-2
5-2
5-7
5-11
5-12
5-17

v

Page of GC21-7567-2
Issued 30 June 1978
ByTNL: GN21-5616
Processing Card or Disk Files
Checking For Duplicates
Doing Special Operations When There Is Only
One Record In A Group .
Doing Special Operations For The Last Record
In A Group.
Additional Points To Consider AboLit Look Ahead.
Moving Data .
Specifications For Moving Data
S"aving Information From A Field By Move
Operations .
Separating One Field Into Two Parts.
Changing Field Type (Alphameric or Numeric)
Branching In Calculations
Bypassing Calculations .
Branching Backward
Using Subroutines in Calculations.
Using Subroutines To Do The Same Calculations
Several Times In One Cycle
RPG " Linkage Editor .
Linkage Editor Map.
Simple Overlays .
Special Open.
Overlay Starting Addresses.
Fitting Available Storage
RPG " Logic and Function Shifting
Special Uses of Control Level Indicators.
Internal Control Level Indicator LO .
Using Control Level Indicators As Calculation
Conditioning Indicators
Group Printing .
Binary Field Operations (Controlling Switches) .
B ITON Operation Code
BITOF Operation Code
TESTB Operation Code
Example.
Increasing The Speed of Operations (Dual I/O Areas)
Dual Input Areas
Dual Output Areas

5-17
5-20
5-26
5-28
5-28
5-28
5-29
5-31
5-33
5-34
5-36
5-36
5-42
5-44

5-45
5-54
5-55
5-56
5-56.1
5-56.1
5-56.3
5-56.3
5-56.4
5-56.4
5-59
5-59
5-67
5-67
5-67
5-68
5-69
5-69
5-69
5-71

REVIEW 5
Additional Uses Of Indicators
Controlling Operations On The Basis of the Next
Record In A File .
Moving Data .
Branching In Calculations •
Using Subroutines In Calculations
Special Uses Of Control Level Indicators.
Binary Field Operations
Dual Input/Output Areas

5-73
5-73

ANSWERS TO REVIEW 5.

5-77

5-74
5-74
5-75
5-75
5-76
5-76
5-76

CHAPTER 6. MATCH FIELDS AND MULTIFILE
PROCESSING.
Introduction .
Checking Sequence Of Records Within A File
,
File Containing Only One Record Type . '.
File Containing More Than One Record Type
Using Match Fields With Field-Record Relation for
More Than One Record Type in a File .
Match Fields The Same For All Record Types .
Match Fields Differ Between Record Types .
Matching Records: One Record Type In Each File.
Processing Order: More Than One Matching Record
In A Secondary File
Processing Order: More Than One Matching Record
In The Primary File
• . . . . . . .
Matching Records: Records Which Have No Match
In The Other File .
Matching Records: More Than One Record Type'
In A File
Match Fields In Different Locations ~n The Same
File .
Processing Records Which Do Not Have Match
Fields
Matching Records: When All Records In One File
Have Been Processed •
Use of Match Fields and Control Fields in the Same
File.
Determining Whether Files Should Be Primary or
Secondary

6-1
6-2
6-2
6-2

6-6
6-8
6-8
6-9
6-12
6-12
6-20
6-20
6-26
6-26
6-29
6-30
6-34
6-38

REVIEW 6
Review Problem.

6-41

ANSWERS TO REVIEW 6.
Solution To The Review Problem.

6-46

CHAPTER 7. PROGRAMMED CONTROL OF INPUT AND
OUTPUT

6-44

6-49

7-1
7-2
7-2
7-2
7-4
7-7

Introduction.
Altering The Order of Processing Files (Force Operation)
Specifying The Next File To Process •
Alternating Processing Between Two Files
Forcing A Number of Records From a File
Look-Ahead To Determine Whether A File Is To
Be Forced .
Processing Demand Files (Read Operation) .
Considerations For Using READ and Demand Files
Repetitive Output (Except Operation)
Using EXCPT and *PLACE
Conditioning The Use of EXCPT Operation

7-15
7-22
7-26
7-26
7-26
7-29

REVIEW7
FORCE
READ
EXCPT

7-31
7-31
7-32
7-33

ANSWERS TO REVIEW 7 •

7-34

./

vi

Page of GC21-7567-2
Issued 21 December 1979
By TNL: GN21-5709

)

)

CHAPTER 7. PROGRAMMED CONTROL OF INPUT
AND OUTPUT . . . . . . . . . . . .
Introduction . . . . . . . . . . . . . .
Altering The Order of Processing Files (Force
Operation) . . . . . . . . . . . . . .
Specifying The Next File To Process . .
Alternating Processing Between Two Files .
Forcing A Number of Records From a File .
Look-Ahead To Determine Whether A File Is To
Be Forced . . . . . . . . . . . . . . .
Processing Demand Files (Read Operation) . . .
Considerations For Using READ and Demand
Files . . . . . . . . . . . . .
Repetitive Output (Except Operation)
Using EXCPT and *PLACE. . . .
Conditioning The Use of EXCPT Operation

7-1
7-2
7-2
7-2
7-4
7-7
7-15
7-22
7-26
7-26
7-26
7-29

REVIEW 7
FORCE
READ.
EXCPT

. 7-31

ANSWERS TO REVIEW 7

.7-34

CHAPTER 8. TABLES . . .
Introduction . . . . . . .
Searching a Single Table
Designing Table Input Records.
Describing Table Input Records With Extension
Specifications. . . . . . . . . . . . . .
Coding The Table Lookup Operation (LOKUP) .
Two Table Search. . . . . . . . . . . . . . .
Designing Table Input Records For Two Tables
Describing Two Tables With Extension
Specifications. . . . . . . . . . . . . .
Coding The Table Lookup Operation (LOKUP)
Using Table Data In Calculations and Output . .
Conditioning Operations On The Basis of a Table
Lookup . . . . . I • . . . • . • • • . . •
Referencing Data Foll6wing A Successful Search
Searching For Low, High, or Equal Conditions
Moving Data In A Table Entry . . .
Modifying The Contents Of A Table
Loading Tables . . . . . . .
Compile Time Tables . . . . . .
Pre-execution Time Tables. . . .
Loading Pre-execution Time Tables
Output of an Entire Table
REVIEW 8 . . . .
Review Problem

7-31
7-32
7-33

8-1
8-2
8-4
8-4
8-5
8-7
8-8
8-11
8-13
8-14
8-14
8-14
8-16
8-19
8-21
8-22
8-25
8-25
8-25
8-26
8-28

CHAPTER 9. ARRAYS . . . . . .
Introduction . . . . . . . . . . .
When To Use an Array Instead of a Table
Defining An Array. . . . . . . . .
Referencing All Elements In An Array . .
Array to Array Calculations . . . . .
Calculations Using Arrays and Single Fields (Or
Constants) .'. . . . . . . . . .
Adding All Elements Within An Array
Output of an ,,Entire Array . . . . .
Accumulating G"roups Of Totals
Referencing Individual Elements of an Array
Indexing An Array . . . . . . . . . .
Output of Individual Elements of An Array.
Referencing Only Part of a Field . . . . .
LOKUP Of An Array . . . . . . . . . . . .
Searching An Array For A Particular Element
Searching An Array For More Than One Element .
Output During An Array Search
Loading Arrays . . . . . . .
Compile Time Arrays . . . . .
Pre-execution Time Arrays. . .
Storing Input Data Into Execution Time Arrays
Array Data Consecutive On More Than One Record
(Model 6, Model 10 Disk System, and Model 15)

9-1
9-2
9-2
9-2
9-4
9-4
9-7
9-8
9-9
9-14
9-19
9-20
9-22
9-23
9-27
9-27
9-32
9':'34
9-35
9-35
9-36
9-38
9-44

REVIEW 9 . . . . . . .

.9-53

ANSWERS TO REVIEW 9

.9-55

CHAPTER 10. WORKING WITH DATA
STRUCTURE . . . . . . . . . . . .
. 10-1
Character Structure . . . . . . . . . .
10-2
Representation Of Characters On 96-Column Cards .
10-2
Representation Of Negative Numbers . . . . .
10-3
10-4
Representation of Characters In Storage
Difference Between Character Representation on
10-4
Cards and In Storage . . . . . . . . . .
Identifying Bit Combinations With Numerical
10-13
Values . . . . . . . . . . . . . . . . .
Assigning Numerical Values to Zone and Digit
Portions . . . . . . . . .
10-16
Saving Disk Storage Space .
10-19
Collating Sequence of Characters
10-21
Collating By Zone or Digit . .
10-25
10-28
Altering the Collating Sequence.
Specifying Changes In Collating Sequence.
10-28
10-33
Coding Characters To Be Equal
Recording Specifications For The Altered
Sequence . . . . . . . . . . . . .
10-38

. 8-29
8-30

)
vii

Altering The Structure of Characters .
How Move Zone Operations Work
Coding a Move Zone Operation
Differences In The Move Zone Operations
Field Format and Move Zone Operations
Example of a Move Zone Operation
Choosing the Model Character For Factor 2
Translating Characters . . . .
Need For File Translation . . . . . . . .
Specifying File Translation . .'. . . . . .
Recording Specifications For The Translation
Table
REVIEW 10
Character Structure
Collating Sequence of Characters .
Altering The Collating Sequence .
Altering The Structure of Characters
Translating Characters
ANSWERS TO REVIEW 10

viii

10-39
10-39
10-39
10-40
10-41
10-41
10-42
10-44
10-44
10-44

CHAPTER 11. DEBUG . .
Introduction . . . . . . .
Using The DEBUG Function
Specifications For DEBUG
Format of Records Created By DEBUG
Getting Results From DEBUG . . . .
Placement of DEBUG . . . . . . . .
Making Your Program Work For All Cases.

· 11-1

REVIEW 11

· 11-7

10-48

ANSWERS TO REVIEW 11

· 11-8

1049

INDEX . . . . . . . . . .

· X-1

10-49
10-49
10-50
10-50
.10-50

10-51

11-2
11-2
.11-2
11-4
11-5
11-5
11-5

Chapter 1. RPG II Logic

CHAPTER 1 DESCRIBES:
Basic R PG II logic.

RPG II logic related to indicators.

AFTER READING THIS CHAPTER YOU SHOULD BE ABLE TO DESCRIBE:
Basic three-step logic of a data processing job.
Detail time and total time.
Specific steps in a basic RPG II job that includes detail and total operations.
RPG II logic related to the following indicators: 1P, LR, record identifying
indicators, field indicators, resulting indicators, halt indicators (H 1-H9), overflow
indicators (OA-OG, OV), matching records indicator (MR).

Note: You can use the review questions contained in Review 1 at the end of this
chapter to test your comprehension of the chapter. Answers follow the review
questions.

-- ........

RPG II Logic

1-1

RPG II logic is built around these indicators. Their status
(on or off) affects the sequence of the program's operations.
The logic is set up to test the status of various indicators at
specific times. By testing indicators, the program knows
what to do next.

INTRODUCTION
What procedures do you follow if you are preparing bills to
send to customers? Before you can do anything you need
some information. You have to know three things: (1)
the customer's balance at the beginning of the month; (2)
his purchases; and (3) his payments. Once you have
gathered this information, you can perform the necessary
calculations to find the amount due. Finally you record
this amount on the bill. You go through these same procedures for each customer.

RPG II program logic is d~signed to take care of all types of
jobs. You must understand this logic to write specifications
which make correct use of it.
Because the logic is a rather complex topic, it is described
segment by segment. However, when you have finished
reading this section, you will have a picture of how the
complete RPG II program logic works.

This is a type of job you can easily have your computer do
for you. To do the job, however,the computer must know
the same things you know. You must, therefore, tell it
exactly what information to expect, what to do with the
information, and what to give you as a result. This you do
through specifications you write: File Description; Extension; Line Counter; Input; Calculation; and Output-Format.
To do this billing job, you do things in a logical order. You
read information first. You do calculations second. Finally,
as a result of the calculations, ,you record the amount owed.
Then you begin to do the same things in the same order for
the next customer.
The computer must also do things in a logical order. The
information you supply through specifications doesn't give
the computer the logic it needs to do your job; the RPG II
Compiler supplies this. RPG II logic supplied by the compiler is the framework for your jC?b. When your source program is compiled, your source statements are fitted into the
framework of RPG II program logic to make a complete
program. The generated program then has all the information it needs to do your job in a logical manner.
What happens if, in doing your billing job, you find that a
customer,paid more than he owed? You know immediately
that he has a credit balance and indicate so on the invoice.
How does the RPG II program recognize this situation?
And how does it know what to do when such a situation
occurs?
The RPG II program uses signals which tell it when a particular situation occurs and what to do when that situation
does occur. These signals are known as indicators. There
are many different kinds of indicators which signal many
different situations. You, as a programmer, must know how
to specify the indicators so that they signal to the computer
what you want them to.

1-2

BASIC DATA PROCESSING LOGIC

• I

Usually, all records in a file of input records are not read at
once. Your computer probably is not large enough to store
and work with information from all records at the same
time. Therefore, records are read one at a time. Three
steps, as shown in Figure 1-1, are done for each record read.
The phrase program cycle refers to all the operations performed from the time one record is read until the next record is read.' One program cycle is therefore one revolution
around the circle used to illustrate the program logic. Since
one program cycle (one'revolution) is needed for each record read, many program cycles are required for every job.
Consider how the three step logic shown in Figure 1-1 works
for a job which requires a detailed listing of purchases made
by each customer. The input file is in ascending order by
customer number. Each record contains customer name
(NAME), number (NUM), and charge (CHRG). Information
from the record is merely transferred to the printed page.
One line is printed for each record read. Each record read
is known as a detail record and each line printed is a detail
line.
The job begins: the first record is read. No calculations are
performed. A record is then printed. This ends the first program cycle. The second begins with the reading of another
record. Figure 1-2 shows the input and output of the detail
printing job.
Suppose, however, instead of merely listing the charges
made by each customer you also wish to find the total
charges for each customer, as shown in Figure 1-3.

•

..

•

•

•
•

Write or punch
results

Read a record

•
•

•

•
•

•

•
•

• Perform ~Icula~

Figure 1-1. Basic Logic of a Data Processing Job

1645
1645

Input file

1645
1645

1762
1796

I

JOE AARON
JOE AARON
BILL BELL
JOHN BART

JOE AARON
JOE AARON

7.42
6.43
13.85*

1762

BILL BELL

131.42
131.42*

7.42
6.43
131.42
24.93

1796
1796

JOHN BART
JOHN BART

24.93
2.98

Printed report

)

Figure 1-2. Detail Printing Job

Figure 1-3. Calculating and Printing Totals
RPG II Logic

1-3

BASIC RPG II LOGIC

To do this, you mUlit do calculations to accumulate a total
in addition to printing out individual (detail) records. But
when do you print out the total you have calculated? The
total for a customer, of course, should be printed after all
detail records for that customer have been printed (Figure
1-3). However, in the three-step logic discussed so far, there
is no provisi,on for printing a total record. Neither is there
a way to distinguish between individual input records in
order to determine when all records for a customer have
been read.

i

RPG II logic, therefore, is an extended version of this 3-ste p.
logic. It calls for calculations and output operations to be
done at two different times in one program cycle (see Figure 1-4). The names detail and total have been given to the
times at which calculation and output operations are performed. Total time, as the name suggests, is the time in
which total operations are done on data accumulated from
a group of related records. T,~e printing of total charges for
Joe Aaron (Figure 1-3) is an example of a total time operation. Detail time is the time in which operations are performed for individual records. An example of a detail time
operation is the printing of an individual charge for Joe
Aaron. Remember, detail operations are done for every
record read, but total operations are done only after a certain group of records are read (see Figure 1-5).

If the RPG II program used only the three-step logic, it
would not be able to do this job and many others like it.
It could adequately work with information from only one
record at a time, as in the detail printing job. It could not
correctly do operations to accumulate data from several
records.

•

•

•

•

• Perform detail

Read a record

output operations

•

Detail
time
Perform detail
calculations

•

•
•
•

•
•

Perform total
output operations

Perform total
calculations

•

•
Figure 1-4. Basic RPG II Logic
1-4

•

Page of GC21-7567-2
Issued 24 May 1976
By TNL: GN21-5389

Detail

operatiO)rn:s.~,_ - - - - - - - - - - - - - - - ; - ;

)

1713 LEE ARMSTRONG 379

1713 LEE ARMSTRONG 571

1713 LEE ARMSTRONG 475

1713 LEE ARMSTRONG 298

1645 JOE AARON

1645 JOE AARON

643

742

Total Operations:
Done only after
all records in
one group have
been processed.

~__________________________ ~GROUPl

)

Figure 1-5. Detail Versus Total Operations

Because this basic RPG II logic is only a framework for your
job, you have to supply additional information so that your
job will be complete. Only then will your program work
correctly. For example, the RPG II compiler supplies your
program with the logic framework which enables it to do
detail and total operations. But you must tell it when total
operations should be done and which calculation and output
operations are to be done at detail time and which are to be
done at total time.
Remember that the only way you can tell the program
whatto do in certain situations is to use indicators. Control level indicators are used to tell the program:
1.

When to do total operations.

2.

What operations are total operations.

If you were finding total m9nthly charges for each customer, how would you know when to record totals for
each customer? When you encounter a record with a dif-

ferent customer number in the NUM field, you know that
you have gathered all the information for one customer.
(You could use the NAME field to tell you this, but there
is a chance that two customers may have the same name.)
You would then record that total before gathering information for the next customer.
Any field used to control and direct processing is known
as a control field. You indicate to the compiler program
which field is a control field by assigning one of the control
level indicators (L 1-L9) to the field in columns 59-60 of
the Input sheet. You also use this same control level indicator to tell the program which calculations are total calculations by entering the indicator in columns 7-8 of the
Calculation sheet. Those calculations that are not conditio,)ed by a control level indicator (in columns 7-8) .are
detail calculations. Control level indicators are not used
in the Output-F<:>rmat sheet to indicate detail and total
records. Rather a T is used in column 15 to indicate a
total output oper~tion; and H or 0 is used to indicate
an operation done at detail time.
RPG II Logic

1-5

Specific Steps in Basic RPG II Logic

, According to RPG II logic, after a record is read the program
checks to see if information in the control field of the record
just selected is different from the control field information
in the previous record. (The program always saves the control field information so that it can make a comparison.) If
there is a change, the proper control level indicator (the one
you assigned) is turned on. This means that all records
from one group have been read. All total operations can
then be performed. Control level indicators are always
turned off before the next record is read.

Figure 1-4 shows very generally the sequence of events in an
RPG II program cycle. The RPG II logic actually consists
of definite steps taken during the cycle. When you do a job
you mentally ask yourself questions such as, "Do I do this
now? Do I have all my information? What shou Id I do
next?" RPG II logic also asks questions. It uses your program to find the answer and thus determines what to do
next. The questions, and specific steps taken based on the
answers to the questions, are shown in Figure 1-6.

•
•

•

"

•

•

Read a record

•
'" "'\.

Detail
time /

//

/
/

/

/

/
Perform detail
calculations (those
with blanks in
columns 7-8)
/

/

-/

/

/

/

I

Move data from
record read at
beginning of cycle
• / into processing
area

•

Perform total output
operations (those
identified by a T)

Figure 1-6. Steps in RPG II Total and Detail-Time Logic

4I

,

•

,

Total"
time
,

' "-

,

•

•

Change in control field?
If yes, turn on control
level indicatiors

"
'

/

•

1-6

•

Turn off control
level indicators
L1-L9 •

Perform detail
output operations
(those identified
by 0 or H)

•

•

•

",

Perform total
calculations (those
conditioned by LO-L9
or LR in columns 7-8
of Calculation sheet)

\.

,

Notice the step between total and detail time. Here data
from the record read at the beginning of the cycle is moved
into a processing area and becomes available to use in calculations and output. Data from this record is not available
at total time. Total operations are performed only on data
accumulated from previous records. Detail operations on
the record which caused the control level indicator to be
turned on are done only after total operations for previous
records.
Why are total operations done before detail operations?
Think of what would happen if the record which caused
the control level indicators to be turned on were processed.
Information on this record would be added to information
from records in the previous group. As a result, the totals
printed would be in error since they contained information
from one record in the next group (the record just read).
To prevent data from the first record in a new control gropp
from being accumulated in the totals for the previous
group, total operations are done before detail operations.

First Program Cycle
When control fields are specified for a record, the first program cycle may be slightly different from the others.
Control level indicators are turned on by the first record
containing control fields. This happens because contents
of the control fields on this record are different from the
blank control field areas that were in main storage before
the record was read. To prevent printing of blank totals on
the first cycle, RPG Illogic causes total operations to be
bypassed on the first cycle.

Note: If the initial input records do not contain a controf
field, total calculations and total output operations are
bypassed on each program cycle through and including the
first cycle in which a record with control fields is read.

Summary of Basic RPG II Logic
Figure 1-7 shows specifications for the group printing job
previously discussed and the logic for the first four program cycles. Follow the logic involved in each program
cycle step by step. Remember, the cycle repeats itself from
the time the program is started until the last record is
processed.
Be sure you understand this basic logic before proceeding
further.

RPG II LOGIC RELATED TO INDICATORS
It was previously stated that RPG II logic is built around
indicators. This section discusses how logic related to indicators fits into the basic RPG II detail and total time
logic shown in Figure 1-4.
In your specifications, you use indicators to tell the program what to do and when to do it. Although you use indicators, you do not set them. Naturally the indicators
don't turn on and off by themselves. The compiler supplies
logic which is needed to control the setting of indicators.
Indicators are set to signal various conditions that occur
during the execution of a program. In addition to setting
indicators, RPG II logicalso causes tests to be made for
yarious indicators at certain times in the program cycle.
Specific operations are performed as a result of these tests.
It is very easy to think that an indicator is on when it really
is off or vice versa. It is extremely important that you know
when indicators are on and when they are off in the program cycle. Many programs fail just because the programmer did not understand RPG II logic concerning indicators.
The following paragraphs will discuss the time in the program cycle at which indicators are set and the time at
which they are tested.

)
RPG II Logic

1-7

RPG

IBM

GX21-9094 U/M 050"
Printed in U.S.A.

INPUT SPECIFICATIONS

International Business Machine Corporation

1

2

75 76 77 78 79 80

Page [ ] ] O f _

Date

Record Identification Codes

~;~:~f:ation I

IIIIII

Field
Indicators

Field Location
-3

Filename

Field Name
Position

Position

Iii

From

Position

~~~

Zero

To

Plus Minus or

Blank

~uti

9 1011 1213 14 15 16 17 18 19 20 21 22 23 24 25 2627 28 29 303132333435 3637383940414243 44'45464748 49 50 51 5253 54 5556575859606162636465666768 697071 72 73 74

o
o
o
o

2

I

12

3

I

III
121b

4

I

5

I

IBM

International

BUSine~s

Machine

RPG

Corpor8t~on

l5 tJUIM
125 . 'NIAIMr:
1322~IHIG .

1

Form GX21-9093
Printed in U.S.A.

CALCULATION SPECIFICATIONS
1 2

Program
Programmer

C
-

g~

~3~
....E occ
!l en

4

6

~

8 5~

6

7

I

C

01 2 1
- 1- I

c
-

011

8

At

. Jd

Operation

Factor 1

:i =-

Factor 2
Name

~

5

Length

Plus IMinusl Zero

~~

'u - Lookup(Factor 2)is

5

z
Z
C:I: High Low Equal
9 10 1112 1314 15 16 17 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 48 47 48 49 50 61 5253 54 55 56 67 5859 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

I I I I I I ~In[)j I rbtrlAlLI I I I I irlolrlA.ILI I 1B12
II II II II II II II
II II II II II II II II II II II II JI 11111J111
I I I I I I I I I

I ell
II

I I I
II II II

r.lH(;1

OUTPUT

GX21 -9090 U/M 050"
Printed In U.S.A.

1 2

~

~~
e -

...E~

5

6

2

0
0

4

0

0 5

0

o
o

6

0

7

0

o
o

8

0

9

0

1 0

0

~

~

"ADD
R

Jd
~

i

!<

0

0

z

z

--'"

Field Name

1

7

8

0

z

'AUTO

mil

~

."w
'C

End
Positon
in
Output
Record

9 10 II 12 13 14 15 16 17 18 1920 21 22 2324 25 26 27 28 29 30 31 32 33 34 35 36 37 38 ~ 40 41 42 43

ID 1

IT

2~

~11

1

11

...

l!ls

II\,

A

11M

Ib~

Zero Balances
to Print

Ves
Ves
No
No

Ves
No
Ves
No

No Sign

CR

-

1
2
3
4

A
8
C
0

J
K

L
M

X •

IIIII

Remove

Plus Sign
V· Date
Field Edit
Z ~ Zero
Suppress

Constant or Edit Word

ii;

a::

«~~048~~~~~54~WAWW~~~~~~68~~W~

Iblt
Ihl

Commas

~;~:~f:ation 1 I.

0::

:::;

IJ~
ILlI~

tJlUM
NIA ME.
rlHG

Figure 1-7 (Part 1 of 5), Illustration of Detail and Total Time

1-8

ItI!
i

'A~D

olp IRlr INT

3

O~tput Indicators

Skip

Space

... ell

o

.f
o
o
o

;. ~
~~

75 76 77 78 79 80

Page [ ] ] O f _

- .. ~~

Filename

Line

4

11111111111111
I I I I I I I I I I I I I I

SPECIFICATIONS

Date

0

3

11111111111111

International Business Machine Corporation

Programmer

0 1

Comments

Compare
ce S 1>211<211-2

Program

-

IIIIII

Resulting
Indicators

Result Field

RPG

_IBM

~;~:~f:ation I

Arithmetic

=:0

Line

3

Indicators

~

75 76 77 78 79 80

Page [ ] ] O f _

Date

\*'

71 72 73 74

//

"'--------------,
JOE AARON
I
1645

742

I

I
I
I

I

I
I

I

1645

JOE AARON

II

7.42

I

I

I

•

•
•

•

•

Turn off
control level
indicator L 1

I

I

•

I

I

L _ _ _ ~~~ _ _ _ _ _ _ _ _ _

JI

•

1645 JOE AARON 742

•

Perform detail output:
Print the record

•

)

•
Perform detail calculation:
Add CHG to TOTAL

•

Change in control field?
Yes, turn on control
level indicator L1

00000
742

00742

•

Move data from record
selected into
processing area

•

Bypass total
operations because
this is the first record
with a control field •

•

•

J

Recall that there is
always a control break
on the first cycle,
although total operations
are bypassed.

Figure 1-7 (Part 2 of 5). Illustration of Detail and Total Time

)
RPG II Logic

1-9

/r-----------i
(

1645
1645

JOE AARON
JOE AARON

7.42
6.43

1645 JOE AARON

643

:

I

I

I

I

I

I

I

•

•

•

•

•

I

I

• L_

I
I

I
_ __ J

1645 JOE AARON 643

•
•

•
Perform
detail calculation:
Add CHG to TOTAL

•

••
Change in control field? No

00742
643
01385

•

•
Move data from record
selected into
processing area

•
•
Figure 1-7 (Part 3 of 5). Illustration of Detail and Total Time

1-10

•

~-----------,

1645
1645

JOE AARON
JOE AARON

(//

7.42
6.43

BILL BELL

~

1342

1

I

I

BILL BELL

I

13.42

•

•
•
•

I
I

1

13.85*
1762

1762

I

•

.1

I

:

I

• L___________ _

Turn off
Control level
indicator L 1

•
)

•
Perform detail calculations:
Add CHG to TOTAL

00000
1342
01342

•
•

•
Move data from record
selected into
processing area

•

Perform total output:
Print TOTAL,
reset field to
zero

•
1645
1645

•

Change in control field?
Yes, turn on control level
indicator L 1

JOE AARON
JOE AARON

•

Figure 1-7 (Part 4 of 5). Illustration of Detail and Total Time
RPG II Logic

1-11

1645
1645

1762

JOE AARON
JOE AARON

7.42
6.43

BILL BELL

,------------,
, / 1796

JOHN BART

I
I

I

I

I

I

13.42

I

I

I

I

I
I

I

I

24.93

•

2493

(

13.42*
1796

JOHN BART

13.85*

•

•

•

I

.f;;:!f!I#/!(!!f!f!"~ - - - __ I

------------~~~

1796 JOHN BART 2493

Turn off
control level
indicator L 1

record

•
•

Perform detail output:
Print the record

•
Perform detail calculation:
Add CHG to TOTAL
00000
2493

•
Change in control field?
Yes, tu rn on control
level indicator L 1

02493

•

•

Move data from record
selected into
processing area

Perform total output:
Print TOTAL,
reset field to
zero

•
•
1645
1645

JOE AARON
JOE AARON

•

7.42
6.43
13.85*

1762

BILL BELL

13.42
13.42*

tf:':"

Figure 1-7 (Part 5 of 5). Illustration of Detail and Total Time
1-12

•

The 1 P indicator is turned on only for the beginning of the
first cycle. It is turned off before a record is read and is
never used again during the program (see Figure 1-8).

1P (First Page) Indicators
It was stated before that the first program cycle is slightly
different from the others because total operations are bypassed on the first cycle. Another difference in the first
cycle is that the first page indicator (1 P) is on during the
beginning of the cycle. Any records conditioned by the 1 P
indicator are printed before the first record is read.

Notice in Figur~ 1-8 that the program performs 1 P output
and other heading and detail output first when it is started.
This is a/ways true. In any program, 1P output and any
other heading or detail output for which specified conditions have been met is performed before the first record is
read. On succeeding cycles, however, it is usually easier to
think of reading a record as the first step in the cycle.

This indicator is used to condition records which are to be
printed on the first page of a report. These records are
usually headings used to identify information found on the
page, but may also be detail lines.

•
•

•

•

•

•

Turn off control
level indicators L 1-L9
and 1P

•
Perform heading and detail
output for which conditions
have been met, including 1P
output (first cycle only)

)

•
START

•

. (1P is on)

•
•

Change in control field?
If yes, turn on control •
level indicators

Perform detail
calculations

•

Move data into
processing area

•
•

Bypass total
operations

•

)

Figure 1-8. Logic for the First Page (1P) Indicator
RPG II Logic

1-13

Assume that a heading is desired on the report created by
the previous example (Figure 1-7). The heading should be
printed on the first page before any records are printed.
Thus the heading line is conditioned by 1P (see Figure 1-9).
Figure 1-10 shows what happens in the first cycle according
to RPG Illogic.

RPG

GX2t·9090

SPECIFICATIONS

OUTPUT

1 2

Program
Programmer

-

Page

Date

o

u:: Space

Skip

Filename

Line

I .I

i i~ ~ ~
c

I-

eli

f;"oo

And

~

o
Z

~~r.:AND
5

o 1
o 2
o 3

o

4

o

5

o

6

o 7

o

8

o

9

1 0
11
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
2 0

6

7

8

9

t>

Output Indicators

~ ~~-+----'-----r------r--------~----~

Field Name

And

a:

0

Z

·AUTO

!~ ~~

Commas

Zero Balances
to Print

Ves
Ves
No
No

Ves
No
Ves
No

Positon

~utPut ~
Record

UIM 050·

Printed in U.S.A.

75 76 77 78 79 80

[[]Of_ ~~:;~f:ation I

No Sign

CR
A
B
C

J
K

0

M

L

I. 1 1 1 1 1

X· Remove
Plus Sign
V • Date
Field Edit
Z

. Zero

Suppress

Constant or Edit Word

~

10 11 12 13 14 1S 16 17 18 19 20 21 22 23 24 25 26 27 78 2'9 30 31 32 33 34 35 36 37 38 39 40 4' 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 ,'7 68 69 70 71 72 73 74

alp IRlr NT
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a

H

32

11P
10
.~0
6~

In

11

\ AI JIM P.F IQ'
\/J AIM E'
... ,. I,.
\
J
('"

II

,

It I

.

tL IL OL 69 89 L9 99 59 t9 £9 t9 19 09 65 85 L5 95 95 tS ~~ tS 15 os 6~ 8. L~ 9t 5~ n

NIUIM
NIA 1M 1=
rl~IG

10
41)
A(/}

£. tt It O. 6£ 8£ Lt 9£ St t£ ££ tt 1£ OC 6t 8t it 9t St

~t

ct tt It Ot 61 81 LI 91 SI U £1 tl II 01 6

8

L

9 5

~

C t

I

Figure 1-9. Heading Line Conditioned by the First Page Indicator

/'

1-14

/r----------:- I
(

NUMBER

1645

NAME

CHARGES

"::;\\\\~~:~E AARON

I

742

•

•

.

\\\\\\

•

•

1645 JOE AARON 742

I

I

I

I
I

I

I

I

I

I

I

I
I

I

I

. _ _ _ _ _ _ _ _ JI

I

•

\~;h : :~lr~u~:~:~ ~: ~ ~1
.:.:::~~ conditions have been met,
including 1P output (first
cycle only)

•

)
START

•

(1Pison)

•
•

Change in control field?
Yes, turn on control
level indicators

Perform detail .
calculations

•

•

Move data into
processing area

•
•

Bypass total operations

•

Figure 1·10. Program Cycle Illustrating the 1P Indicator

)
RPG II Logic

1-15

You use LR to condition all operations done at the end of
the job. These usually include the calculating of totals for
all records and/or writing or punching summary information. Suppose the previous example (Figure 1-7), which
found total charges for each customer, required the statement List Complete as of
(date job was run).
Since this is to print out after all records have been
processed, it is conditioned by LR (see Figure 1-12).
Figure 1-13 shows what happens during the last program
cycle according to RPG II logic.

Last Record Indicator (LR)

The last program cycle is also a little different from the
othe:rs. When the record with a /* in positions 1 and 2 is
read, the LR (last record) indicator is turned on. Since the
/* record has no data on it, detail operations need not be
performed. Thus RPG II logic is set up so that detail
operations are not done when LR is on (see Note). Total
operations are done. The program then ends.
When the last record indicator is turned on, all control level
indicators are also turned on. Thus all total operations conditioned by L1-L9 and LR are performed. See Figure 1-11
for specific steps in the end of job logic.

during calculations, rather than by reading a /* record.
However, when LR is turned on in calculations, the other
control level indicators are not turned on .

•

•

•

Note: Detail operations are done if LR has been turned on

•

•

•

Read a
record

•
Was the record
just read an end
of file ( / * ) record?

•
•
lfso turn
on all control
level indicators
and LR
•

•

•

HALT

•

Perform
total

•

Perform total
output operations

•

•
/

Figure 1-11. Logic for the Last Record (LR) IrftJicator
1-16

RPG

IBM

GX21·909(I U/M 050'
Printed in U.S.A.

SPECIFICATIONS

OUTPUT

Intern.tlon.1 Business MKhine Corpor.tion

1 2

Program

-

0

Ii: Space

Skip

I

c It.

Filename

!
E

3

4

5

6

;ii ::(

And

7

8

I
.I

Field Name

And

~

o
Z

8

0

Z

'AUTO

L..
0

o
o

8

0

9

0

1 0

0

1 1

0

2

0

1

~

en
~

~

End
Positon
in
Output
Record

Commas

Zero Balances
to Print

Ves
Ves

II

No
No

No Sign

X • Remove
Plus Sign
V' Date
Field Edit
Z = Zero
Suppress

CR

Ves

A

No

Ves

B
C

No

0

I. 1 1 1 1 1

J
K
L
M

a:

Constant or Edit Word

..J

en
0:

-

9 10 II 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 3031 3233 34 35 3637 38 39 40 4' 42 43 44 45 46 47 48 49 5051 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

0

0 7

ffr

a:

~

f-;\ro"o ~
';~ro

.f
0 1

~ ~ ~ ~

~ ~
I- US

:>

Output Indicators

~~~-+--~--+---~----~--~

Line

75 76 77 78 79 80

~;:;~,:.tion I

Page [ D o , _

Date

Programmer

,l

iT

I~

1£

IL R

""\

1\:

InlA11E y

I I II II
'"
, ---&;3
b'l

'*,

I I
! :

I
I

11[51

;

' , i

!

\ 1.

;

i

I: ;

~!-

I

r-r-t-7 :

-~-l---l.--L ..

rlr-

Mlp Il 1= ITiE ~ OFl'
I
I ,
I
I
I

H+,-t--LL ~
I

'

I

;

,

:

Figure 1-12, Total Lines Conditioned by LR

)

RPG II Logic

1-17

/

/--------,

I

1*

(

I

I

I

:

I

I

I

I

•

•

•

I

I
'-__

_

_ _ ....JI

•

•
record

•
Was the record
just read an
end offile
( / * ) record?

•

•
lfso tum
on all control
level indicators
andLR

•

•
HALT

•

Perform
total

•

Perform total
output operations

•
7940

f.

2.97
13.56*

LIST COMPLETE AS OF 10/20/71

Figure 1-13. Program Cycle Illustrating the LR Indicator

1-18

•

After the program has selected the next record to process,
it turns on the record identifying indicator which you assigned to that record type. This indicator is turned off only
at the end of each prog~am cycle; thus it is on during both
detail and total operations. Detail and total operations conditioned by the record identifying indicator, currently on,
will then be performed.

Record Identifying Indicators (01-99)
You assign a record identifying indicator to each type of
record in the input file. If certain 'operations are to be performed for one record type only, you',may c~ndition those
operations by the appropriate record identifying indicator. '
By this method you can tell the RPG II program what operations to perform when it: processes a specific re~ord type.

Figure 1-14 shows specific steps in the RPG Illogic related
to record identifying indicators .

•

•

•

•

•

•

Turn off
control level indicators

•

and record identifying'
indicators

Turn on record
identifying indicator •
identifying the
record selected
for processing

)

•
•
Change in control field?
If yes, turn on control
level indicators
•

Perform detail
calculations

•

Move data
into processing
area

•

Perform total
calculations
•.

Perform total
output

•
"\

•

Figure 1-14. Logic for Record Identifying Indicators

)
RPG II Logic

1-19

. Consider the use of record identifying indicators in a billing
job. A monthly file is kept which contains records of purchases and payments made by each customer. In addition,
the file contains a balance forward record for each customer. Figure 1-15 shows the three input record types used
and output records required.

NUM

The three record types are defined on the input sheet. Each
type is given a different record identifying indicator. The
record identifying indicators are then used to indicate which
operations are to be performed for each record type. Figure 1-16 shows the input, calculation, and output-format
specifications for the job. Use these"specifications to help
you follow, step by step, the operations performed in the
program cycles shown in Figure 1-17.

Payment
Record

PAYMNT

(Number)

(Name)

(Balance)

PURCHS ~t---- Purchase
Record

Control
Field
NUM

.(Purchases)

BALFOR .....+-+--- Balance
S
Forward
Record

NAME

"

.(Payments)

A
(Balance)·

Figure 1-15. Input and Output for Billing Job

RPG

IBM

GX21-9094 U/M 050'
Printed in U.S.A.

INPUT SPECIFICATIONS

Internation,l Busines. Machine Corporation

1 2

Program
Progr8mmer

]

j ~

8.

~

.8

~
4

5

6

,..--,..-§

o

R

f;'N f[)
7

8

2

1

z

r~

.~

1l
Position

]a:

t

g.e~

~

S6

Position

t

~~ ~
~uO

Position

~e

~~

·5

t;;i a:

~~~

o~

From

Iqlh

It

o
o

3

I

I~

1311

4

I

o
o

5

I

6

I

II

o

7

I

I~ I

o

B

I

o

I

.

~

.~ biN

Ojl:t,
I
~

1rl1,1c1

Alii'" 12.!'Jl

IGlh
~b

h NlllM
I~I" INi.Q 1M I,:
J"~ ILII"I

IJ.I~

Ii

FhJc

~IA

11

~ILJIM

':10 ~I'l

R

H

,..~

1

1'7 NUM

I~l

~~ 2P Alv

-

Figure 1-16 (Part 1 of 2). Billing Job Specifications Using,Record Identifying Indicators

1-20

3

rl~

I

11

D

~

:§-8

u:~

r~

..,g

1·1 11I I

Field , '
Indicators

~
a:

j

~~ :i...

Zero
Plus Minus or
.. Blank

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 38 37 38 3940 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 66 59 60 61 62 6J64 6566 6768 6970 71 72 73 74

It IL IL II INC; ~111 II rt.l

2

I

~
i8

0

o

I

~
'2

~

IS

9

Field Name

~

To

0 1

1 0

:~;:;:.tionl

Field Location
3

2'.

8

Ii

Filename

line

3

Record Identification Codes

2B

I

t--

75 76 77 78 79 80

Plge[TIOf_

Date

MNT

.

IBM

)

RPG

.

Form GX21-9093

CALCULATION SPECIFICATIONS

Printed in U.S.A.

International Business Machine Corporation

1 2

Program
Programmer

.C
line

~~
=0
~~~
I- '0 cr.E

3

Indicators

",-

~

5

4

~ ~

7 8

C
C

o

3

C

o

4

ft

"

;
Length ~
c;:.a'
E

8 5 z15

2

Arithmetic

:€ g

Factor 2
Name

6

0 1

Operation

Factor 1

At

15

.~

15

«

";

Plus IMinus\ Zero
Compare
1>211 <211-2
lookup(Factor 2)is

z
z
OJ: High low Equal
9 10 1112 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 Ja 39 40 41 42 43 44 45 46 47 4B 49 5051 52 53 54 55 56 57 5859 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

B~ L FIOIR'
BIA LF lolR

120
BI~

PI IDlr ~Ic:.
IpA IVIM NIT

ADD
S1A

~A

Il F "R

~A II

11= "'Q

.

C

RPG

GX21-9090 U/M 050'

SPECIFICATIONS

OUTPUT

Printed in U.S.A.

International Business Machine Corporation

1 2

Program
Programmer

~ Space

Filename

line
[

.......
~ ;

.f
6

OR t-P I(

2

0
0

4

0

o

5

0

o
o

6

0

7

0

o

8

0

o

9

0

1 0

0

1 1

0

1

2

0

1 3

0

1 4

0

1 5

0

1 6

0

1 7

0

1 8

0

1 9

0

~

At

~

~

z°

0

z

Field Name

1

II

0

z

'AUTO

...

I(i.\

~

."0.,

End
Positon
in
Output
Record

w

7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

1

3

Vi

l!!

~~

f-;\f[)f[;
o R
A ~f[)

E

5

....

~ ~

I-

~

2 0

Output Indicators

Skip

~~
0

o
o
o
o

Page

Date

0

3 4

Comments

-

IBM

-

75 76 77 78 79 80

[DOf_ ~~;~f~atiDnl I I I I I I

Resulting
Indicators

Resu It Fie Id
~

At

&

o

Page

Dale

IRT

I~rh'h

I"

Zero Balances
to Print

Yes
Yes
No
No

Yes
No
Yes
No

[DOf_ ~~~;~f~ation I I I I I I I

No Sign

CR

-

1

A

J

2
3
4

B
C

K
L
M

0

X

Remove
Plus Sign
Date
Field Edit
Z • Zero
Suppress
c:

Y •

0::

g

Constant or Edit Word

.

Ii:

«%~g4B~~~~~54~~~~~W~~~M~~~6868ro

71 72 73 74

lL~

11

121~

D lL

1310

h" lLl2.

It 1

In

Commas

75 76 77 78 79 80

,

ItJlM
I~A MIE

l.1J;

iRA , Il= nlR~

Ib~

'p \ ~Ir

ll~ 1

12.~

t"'A J II", r"I-LL

1410J

.- f - - i -

~1<1i

....

'RA llF hlRlA

16~

16lL

. \

~'

0
0
0
0
0
0

ZL IL OL 69 B9 L9 99 99 ~ C9 ~9 19 09 69 as L9 99 99 ~ C9 ~g 19 09 6~ 8~ L~ 8~ 9~ I>t C~ ~~ I~ O~ 6C 8C LC 9C 9C Ii: CC ~C IC OC 6Z 81: L~ 9~ 9~ ~~ C~ U

1~ O~

61 81 LI 91 91

~I

Cl

~I ,"-_O~

6

8

L

9 9 V C

~

I

Figure 1-16 (Part 2 of 2)~ Billing Job Specifications Using Record Identifying Indicators

RPG II Logic

1-21

167,0 HENRY ABLE

495
25~~

1645

643

1645
742

1645

----------....,
/1645 JOE AARON
1645

JOE AARON

47.68

I

I

I

II

':I

I

!A

I

•

•

•

•

4768 I

I

I

I

B

s
A

B I

------~
Record
Identification Code

1645 JOE AARON 4768

•

Turn off control
level indicator L 1
and record identifying
indicator 10.

record

B

•

Turn on record
identifying indicator 10

Perform detail
output

•
•
Change in control field?
Yes, turn on control
, level indicator L 1

Perform detail
calculations'

•

•

Move data
into processing
area

•
•

.'

Bypass total
operations

•

Figure 1·17 (Part 1 of 3). Program Cycle Illustrating Use of Record Identifying Indicators

1·22

/

167,£) HENRY ABLE 495

)

/

1645
1645

643

r - - - - - - --------,
(/

1645

JOE AARON

47.68

7.42

•

•

•

1645

742 :

I

I

I

I

I
I

I
I

I

I

I

I

I
I

I

I
AI

•

B

S

A

•

Turn off record
identifying indicator

•

)

20

Turn on
record identi- 0
fying indicator
20

output

•
Perform detai I
calcu lations:

4768 (BALFOR)
742 (PURCHS)
5510 (BALFOR)

Change in
control field? No

0

•

•

Move data
into processing
area

•

•

•

Figure 1-17 (Part 2 of 3). Program Cycle Illustrating Use of Record Identifying Indicators

)
RPG II Logic

1-23

167~

HENRY ABLE 495
250~

1645

r--------~-l

(/

1645

643

I

I

1645

JOE AARON

I

I

I

I

I

I

I

47.68

I

I

I

7.42
6.43

•

•

•

•

I

IL___

,B

S

_ _ _ _ _ _ _A JI

•

•

Turn off record
identifying indicator
20

record

A

Turn on
•
record identifying indicator
20

Perform detail

•
Perform detail
calculations:
5510 (BALFOR)
~ (PURCHS)

•
Change in
control field? No

6153 (BALFOR)

•

•
•

Move data
into processing
area

•

•

•

Figure 1-17 (Part 3 of 3). Program Cycle lIIustra~ing Use of Record Identifying Indicators

1-24

For each program cycle, field indicators are set to reflect
the result of the test on a field. If the condition tested for
is satisfied, they are turned on; if the condition is not satisfied, they are turned o~f. A field indicator that is set as
the result of a test retains its setting until another test is
made using the same indicator.

Field Indicators (01·99)
, Field indicators are used to test a field on an input record
for a plus, minus, zero or blank value. Any operations
that are to be performed only when a numeric field is plus,
minus, or zero or when an alphameric field is blank may
be conditioned by the appropriate field indicator.

When the indicator is on, any detail and total operations
conditioned by the field indicator may be performed. before
testing of a field again resets the indicator. Remember that
at total time, however, the field indicator will have the setting established in the previous cycle.

Note: A numeric field that is all blanks will turn on an
indicator specified for all zeros. However, if an alphameric
field is all zeros, the field will not turn on an indicator
specified for all blanks.
Field indicators are turned on or off after data from the
record to be processed has been moved into the processing
area. Figure 1-18 shows the RPG 1/ logic related to field
indicators.

•

•

•

•

•

•

•

Turn off
control level
and record identifying
indicators

)

Turn on record.
identifying
indicator

Perform detail
output

•
•
Change in
control field?
If yes, turn on
control level
indicators

Perform detail
calculations

•
•

Move data
into processing
area. Turn'

field indicators
on or off
•

Perform total
calclliations

Perform total
output

•
- .....
J

\1

•

•

Figure 1-18. Logic for Field Indicators
R PG II Logic

1-25

Each time a record with a B in position 96 is read>O ISCRT
must be tested. Only when it contains a positive value
should discount be calculated. Figure 1-19 shows the input,
calculation, and output-format specifications for this job.

Consider the use of field indicators in the billing job previously described. The same record types are used as in the
previous job. The only difference is the additional field, ,
discount (OISCRT), in columns 39-40 on the balance forward record.

Use these specifications to help you follow, step by step,
the logic for each program cycle shown in Figure 1~20.

All employees receive a discount on everything they buy:
The rate of discount they receive is recorded in the OISCRT
field. All accounts other than employee accounts have a
zero in the discount field since they receive no discount~

RPG

IBM

GX21-9094 U/M 050'
Pri,ntedin U.S.A.

INPUT SPECIFICATIONS

International Business Machine Corporation

1

Program

Page

Date

Programmer

I
I---

~
Filename

Line
0-

4

5

I
g

co.

~§

Vl

~

,-+-- ~

6

7

8

E co

~~'D

~

0

-"-;;;

irl

0

Position
"0

z

0

~

E~j
z u u

1~

Position

z0 ~

-: N ~

~u6

Position

~~
~

u

~~~

From

~~~

N(;

~I~

11 ~

I

I

0 3

I

Is

9b "18

I~IQ

1"11(£ ILll Ills IrlRIr

I

I

I

I~
IA I

17 1~1'Jlf'V
131t INIA IrvlF
1~lg 1?lo lie r14-l~

I
I

o

6

I

o

7

o

8

o

9

I

1 0

I

~I) 11\1,.., I:>rt

..c..1:t 1,,1- '~~

191fl Ir lA

i9l1:l

~5

.g
0

:!2~
u.i.i:

.2:!Qi

I I I I- - I 1

Field
Indicators

~

"0

f:r !
~6 u:
"0

-;;

Zero

Plus Minus or
Blank

I

11

1 2

I

1 3

I

Is
1=-1,

1 4

I
~

Figure 1-19 (Part 1 of 2). Billing Job Specifications Using Field Indicators

11

Iqlq

'-.

11

1-26

'7 NUIM

I~;'

4

]

~

13~ NA MIE
l:l ') tr'" It:OIR

5

~Z~;~f:ation I

9 10 11 12 13 14 15 16 17 18 19 20 21 2223 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 6364 6566 67 68 69 70 71 72 73 74

2

o

~
e

0

0

c

g

.~

11=\ ITII LIT

,

Field Name

~

To

0 1

o

75 76 77 78 79 _80
of _

Field Location
3

2

1

~.,-

Z

>

l-

3

Record Identification Codes

N

2

CD

17 IN ulf.1
tJlA 1M 1= .
13 IS lIP IAlv MINT
1

13~

RPG

IBM

Intern.lional BUlin'" Machine

CALCULATION SPECIFICATIONS

Form GX21-9093
Printed in U.S.A.

c~rPOr.tion
1

Program

)

Date

Programmer

-

C

Indicators

~

::gj
~~~
'0

~

E

AL

4

1

5 6

~

en

o
o

7

8

(;

Length ~ ~

g~

u ~
a ::c

z°

z

75 76 77 78 79 80
of_

~~;~;~f:ation I

I I I I 1I

Arithmetic
Plus IMinusl Zero

Comments

Compare

1 >211 <211 ~ 2
Lookup(Factor 2)is
High Low Equal

9 10 1112 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 3a 39 40 41 42 43 44 45 46 47 48 49 5051 5253 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

c
c

191'7 2~
i9i9 20.\

3

C

')~

4

c

3t2l

5

C

2

,~ ;;

Factor 2
Name

~85~
3

Operation

Factor 1

At

o:~

2

[I]

Resulting
Indicators

Resu It Fie Id

0_

Line

o
o
o

Page

Ip ,IRIr I-I~

Mlu IL T IOlr s'r IRIr
51ulB !nlI sir
Ipil R',. 1"1e;
~IDln
lSlUIB 'nl.
"""

Ip I IRr I-I~
ISA IL F "A
1Q.4 I) r: I"IR

IDr fJlr
1o

14'1-1

J Qlr I", c.

~A IIJ:' hR
IR~ J Ie hD

;

RPG

IBM
I
IProgrammer

OUTPUT

International Busine$l Machine Corporation

I
I

Program

-

Date

0

S Space
Filename

- .. Q)«
~!

~

~~

A~D

I-

~

"\
)

5

6

~~D
7

8

1L

;. :u

~i5

~

~

l

Graphic

~

z°

0

z

z°

:m
;9

1

0

o

2

0

tJlu~

o

3

0

NIA MJ:'

o

4

0

~IA

5

0
0

7

0

o
o

8

0

9

0

1 0

0

1 1

0

1 2

0

1 3

0

1 4

0

1 5

0

1 6

0

1 7

0

1 8

0

1 9

0

2 0

Positon
in
Output
Record

2

75 76 77 78 79 80

~~~;:;;:ation [

Zero Balances
to Print

Ves
Ves
No
No

Ves
No
Ves
No

No Sign

CR

1
2

A

B

3
4

C
D

J
K
L
M

I. 1 1

III

X = Remove

Plus Sign
Y = Date
Field Edit
Z = Zero
Suppress

a:

g

Constant or Edit Word

0:

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 3809 40 41 42 43 44 45 46 47 4a 49 50 51 52 53 54 55 56 57 58 59 50 61 62 63 64 65 66 67 68 69 70 71 72 73 74

4

6

5

~~

"AUTO

Commas
v

a:
ill 0;

1

pagernO f _

I I

!ttl

UIM 050"

Printed in U.s.A.

Card Electro Number

....

3

0

I I

Field Name

0

o
o

I I

I I

I

Punch

Output Indicators

Skip

e~
a-

Line

Punching
Instruction

GX21-9090

SPECIFICATIONS

I,..

,1'\

3~~

n

l~

10

1

21(Jj

In

1

3£1

rr

Il2

'11

I

11.'5
I"'1Ii,M

1';,5
~b ~

plU IRr IHC;i 1

2125

p~ IVM INTl

LJt7J

BIA IL FhRA

h0

.. -'-

0
0
0
0
0
0

U

IL OL 69 S9 L9 99 S9 1'9 C9 Z9 19 09 6S

as

LS 99 S9 1>9 CS Z9 IS 09

6~

8V Lv 9. 9. 11> C. ZV Iv OV 6C 8C LC 9C SC I'C C& ZC 1& OC 6Z 8Z LZ 9Z SZ tZ

cz

ZZ IZ OZ 61 81 LI 91 51 vI CI ZI II 01

6

8

L

9

S

~

C Z

I

!Figure 1-19 (Part 2 of 2). Billing Job Specifications Using Field Indicators

RPG II Logic

1·27

276
2~1

H BOLE

1~

593

JIM ARNO

1693

1693 rj

JIM ARNO
193 BI LL AMES 743

-----------,

193 BI LL AMES

193

BILL AMES

4768 J16 1
I
I
1

47.68

B

I

S

I

I

B

IA

•

•

•

I

BI

·. "dt~~;~- - -

--~"
Record .Identification
Code

193 BILL AMES 4768 ~6

•

•

Turn off control
level indicator L 1 and I
record identifying
indicator 10

record

Turn on record
identifying
•
indicator 10
output

•
Change in
control field?
Yes, turn on control
level indicator L 1

Perform detail
calculations

•

•
•

Move data into
processing area. ,
Turn field indicator
99 on (DISCRT is plus)

•
•

Bypass total operations

•

Figure 1·20 (Part 1 of 3). Program Cycles Illustrating Use of Field Indicators

1·28

•

H BOLE
JIM ARNO

)

JIM ARNO

BILL AMES

47.68

I

J

I
I
I
I

I
I

•

•

I

•

$1

I

I

6.99

I
L-__

I

_

10

1693

1693

;----------1
(/ 193 BI LL AMES 743

BILL AMES
193

593

AI

B

S
B

__ - - J

•

•

)

Turn off record
identifying indicator
20

Turn on record
identifying
•
indicator 20

Perform detail
output

•
•

Perform detail calculations:

-----•
7.43
x.06

7.43
-.45

47.68
6.98

.45

6.98

54.66

•

Move data into
processing area

Change in control field? No

•

•
•

•

Figure 1-20 (Part 2 of 3). Program Cycles Illustrating Use of Field Indicator.

RPG II Logic

1-29

276
201

H BOLE

JIM ARNO

593

1f/J

1693

,/"-----------,
(

201

JIM ARNO

1693 9)

193

47.68

BILL AMES

I

I

I

I

I

I

I
6.99

•

•

I
IL__

2~1 JIM ARNO 1693

<)

o

:
I S

I

•

I

I

I

l

_ ____B....J

95

Turn off control,
level indicator L 1
and record identifying
indicator 10

Turn on record •
identifying
indicator 10

Perform detail
output

•
•
Change in
control field?
Yes, turn on •
control level
indicator L 1

Perform detail
'0 calculations

o

Move data into
processing area.
Turn field indicator
99 off (DISCRT is 0).

• Perform total

Perform total

193

BILL AMES

6.99

•

Figure 1·20 (Part 3 of 3). Program Cycles Illustrating Use of Field Indicators

1·30

B

Resulting Indicators (01-99)

A resulting indicator may change status in the same cycle.
This happens when one indicator is assigned to signal the
result of both a totaf and detail calculation. The total calculation could turn it off and the detail calculation could
turn it on, or vice versa. The indicator will not, however,
be reset to show that a field is blank or zero after being
blanked out by the Blank After function (B in column 39
of the Output-Format sheet).

Resulting indicators are assigned to signal something about
the result of a calculation operation. Any operation which
is dependent upon the result of the calculation can then be
conditioned by a resulting indicator.
Resulting indicators may be turned on or off at either detailor total calculation time. An indicator which is set as a
result of the calculation operation retains this setting until
the next time a calculation is done for which the same indicator is a resulting indicator and the condition is not
satisfied. Figure 1-21 sho~s the RPG Illogic related to resulting indicators.

•

•

•

The use of resulting indicators is demonstrated by an inventory job which determines whether an item needs to be reordered. After inventory has been taken, the quantity on
hand is recorded for each item. If the quantity on hand is
100 or less, reorder should be immediate. If the quantity

•

•

•

•

Turn off
control level
and record identifying
indicators

)
Turn on record
identifying
•
indicator

Perform detail
output
operations

•
Perform detail
calculations.

Change in
control field?
If yes, turn on
control level

Turn Calculation
resulting indicators
on oro!!

•
•

indicators
Move data
into processing
area. Turn
field indicators
on or off
•

•

•

Perform total
calculations.

Turn Calculation

Perform total
output

•

•

Figure 1-21. Logic for Resulting Indicators
RPG II Logic

1-31

is over 100,the ite~ need not be reordered at this time. A
list of all items is printed. All items to be reordered are indicated with a'double asterisk. Figure 1-22 shows the
specifications for the job. Use these specifications to help
you follow the program cycles shown in Figure 1-23.

RPG

IBM

GX21·9094 U/M 050·
Printed in U.S.A.

INPUT SPECIFICATIONS

International Business Machine Corporation

1

2

75 76 77 78 79 80

Program
pageDJof_
Date

Record Identification Codes

~~~;:f:ation I

Field
Indicators

Field Location

Field Name

Filename
Position

z

i

0

~

Position

§~

z0
-=

~

From

Position

I I I 1 I 1

Zero
Plus Minus or
81ank

To

N ;

~o6

9 1011'121314151617 IS 19202122232425262729 29 30 31323334 35363738394041424344454647 4B 49 50 51525354 55565758596061626364656667 6B 697071727374

o
o
o
o

~l

lAB

I
I

3

I

lLl

4

I

1312.

5

I '.

1

o

r !t..Ilv E IN

2

11

RPG

IBM

IllCi'J 'I irlE M
l.jl~

UJ QI J IV

Form GX21·9093
Printed in U.S.A.

CALCULATION SPECIFICATIONS

Intarnational BUlinaa MeChinl Corpotlt!on

1 2

75' 76 77 78 79 80

Program
Date

PrOlIrammer

C
'----'-

At

~.§~

Operation

Factor 1

Jd

5

. ..,

~

z0

z0

.f

85

~

6

7

9 10 11 12 1314 15 18 17 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 33 34 35 36 37 3B 39 40 41 42 43 44 45

0/1/

C

01 2 1

C

8

I

'""""

I

RPG

IBM

46

47 4B 49 5051 52 53 54 55 6667 5859 60 61 62 63 54 65 66 67 6B 69 70 71 72 73 74

hlTlvI I I I I I I tbM)pl l~~ 111111 II " I
I \ I I """"I
" " I

/

1

Comments

cf ;

Name

""

I

I :~Io I II I I III I I , , " ,
I I I 1\ I I I I I I I I I I I I
GX21·9090 U/M 050"
Printed in U.S.A.

SPECIFICATIONS

OUTPUT

Intern.tional BUliness Machine Corporation

1 2

75 76 77 78 79 80

Program

Programmer

0

~ Space

~~
olt
....
..,
=. t

Filename

Line

~1

8.

I-

~

~
3

4

1

0

pageDJof_
Date

r---

o
o
o
o

6

6

0

2

0

3

0

4

0

6

0

o

211<211-2
~i Lookup( Factor 2)is
u ~
o :r: High Low Equal

Factor 2

I- ~:;i

~~~;:f:ation I

Resulting
Indicators

Result Field

9~

::0

E

4

Indicators

~

Line

3

pageDJof_

14
25
~fl

Commas

Zero Balances
to Print

Ves
Ves
No
No

Ves
No
Ves
No

No Sign

CR

1
2

A

3
4

C
0

B

J
K
L
M

~~;:f:ation I
X •

I. 1I I I I

Remove

Plus Sign
V· Date
Field Edit
Z • Zero
Suppress

II:

~ii::

Constant or Edit Word

44~~Q~~W~~~54~~~~~W~~~54~~~m69ro

'~ I~

I

71

n

73 74

(desc)

\

1~2

.,----------1

)

(/
**743J1

743J1

I

89

(desc)

I

I

I

I
I

I

WH SOCKS, SZ 6 H

I

I

I

•

•

•

I

I

I

•

I
L ___ _

•

•

Turn off record
identifying indicator

record

01

Turn on
record identifying •
indicator 01
output

)

•
•
•

Change in
control field?
No, there is no
control field
•

Perform detail calculations
(Compare 89 to 100).
Turn resulting indicator
36 on

•

Move data
into processing
area

•

•

•
,

I

Figure 1·23 (Part 1 of 2). Program Cycles Illustrating Use of Resulting Indicators

.-/1
RPG II Logic

1·33

,-----------,
(/

864M2

(desc)

102

. I

I

I

I
I

I

**743J1

WH SOCKS,

864M2

I
I

SZ6

BLUE SOCKS,

SZ6

I

I
I

I

I

I
I

•

•
•

Turn off
record identifying
indicator 01

I

I

. _ oJ
__

•
864M2 (desc) 102·

Turn on record
identifying
•.
indicator· 01

Perform detail
output

•
•
Perform detail calculations
(Compare 102 to 100).
Turn resulting indicator
36 off

Change in
control field?
No, there is no
control field •

•

•

Move data
into processing
area

•
•

•

Figure '·23 (Part 2 of 2). Program Cycles Illustrating Use of Resulting Indicators

1·34

Halt Indicators (H1-H9)

A halt indicator may be turned on at one of four different
times (see Figure 1-24). Its use, of course, will determine
when it is turned on. The program does not halt immedi- ately when a halt indicator is turned on. All total and detail
operations remaining in the cycle are performed first; then
the program halts. This means that processing wi II sti II be _
completed on information from the record that caused the
error condition.

Halt indicators are used to stop the program when a specified condition is satisfied.' Halt indicators may be used as
record identifying, field, or resulting iodicators. When halt
indicators are used as record identifying indicators, a halt
will be caused by a specific type of record; when used as
field indicators, a halt will be caused by erroneous input
data; when used as resulting indicators, a halt will be caused
by erroneous results from calculations.

)

•

•

•

•

•

•

HALT'

•

)'

Turn on halt
indicators when
used as record
identifying indicators

•

Perform detail
output

•
•

Perform detail
calculation.

Change in
control field?
No, there is no
control field
•

Turn halt indicators'
used as resulting
indicators on or off

•

Move data from record
selected into
processing area.

•

I f total calcu Iations were
done, halt indicators

Turn halt indicators
used as field
indicators on or off

used as resulting
indicators would be
turned on or off

•

•

•

Figure 1-24. Logic for Halt Indicators

RPG "Logic

1-35

NUM field is sometimes inadvertently omitted from the
record. Any record with a blank NUM field should be
corrected. Therefore, you must have some way of telling
the compLiter to halt if the NUM field is blank. The indicatorH1 'in columns 69-70 (see Figure 1-25) will do this.

After a halt you may continue processing by pressing
START on the processing unit. Halt indicators are always
turned off before another program cycle begins.
Suppose a halt indicator were used in the billing job previously described in the discussion of field indicators. The
halt indicator is used as a field indicator to check for an
erro ;n the input record. When recording information for
a customer who makes many purchases and payments, the

RPG

IBM

GX21·9094 U/M 050'
Printed in U.S.A.

INPUT SPECIFICATIONS

International Business Machine Corporation

12

Program

Programmer

Page

Date

I

-

>

~
4

5

6

Position

-~-~
j
o

I-

z

R

Position

~ §j

ge

i

Position

~§

~Et6

z u u

~o

AN 0
7

8

:~

'g

~
"

~ ~ ::

From

1

3

I

B~

4

I

~J

o
o

5

I

1~lq

6

I

o

7

I

11

o

8

I

Is

o

9

I

1 0

I

I
I

~

T

1

~)ll

IT N:C;

10

-

Itt 2

"JC/

Iql~

ILl

IN

q6

H.L

lull

7 INllltJ

INIA1t'!E
I~Q 121p Ill~ IrlHS

~ls

It

I']

~
l~ I

1_~'cZ

IJ.lI,

NIL M

NIA MI~
VM If\lJ

CALCULATION SPECIFICATIONS

Form GX21·9093
Printed in U.S.A.

pageDJOf_

Date

Indicators

~

~oc

';i.e

At

~3~

Result Field

Factor 1

Jd

Operation

5 6

~

en

7

8

:J:

Factor 2
Name

~oti

~

85 ~

z'0

•

Length

Resulting
Indicators
Arithmetic
Plus (Minus( Zero

~
Compare
~ 1>2(1<2(1-2

75 76 77 78 79 80

~;~;~;:ation I

IIIIII

Comments

~ Lookup(Factor 2)is

0

:l!

z

9 10 1112 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51

0 1

C

Z~

RA

FI"\R

ADD

PI la r ut:.

o
o

2

C

,~cl

RA

FAR

~UR

dl:T

3

C

....

~

Figure 1-25 (Part 1 of 2). Billing Job Specificatiorls Using Halt Indicators

1-36

~

Zero
Plus Minus or
Blank

~6 u:

1 2

E

"

a:

International Business Machine Corporation

C
r-4

I:~

~

i

13~

Program

3

ii:~

1
7 NJM
.30.1 ~A ME
:ai"l "'0 1\1 Fr"IR
HCL; ,Wll 111~ IrlRT

I~II

u.

Programmer

Line

0

:9~

Field
Indicators

Ir~

RPG

IBM

6

IIIIII

q,b rA

o
o

1 3

~~~~;~f:ation I

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 2526 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 6364 6566 6768 6970 71 72 73 74

I

1 4

)

il

2

I

3

0

o

I

-.;

]

~~~

IR ITII

1 2

~

Field Name

~

To

0 1

11

757677787980

of _

Field Location
3

~·5

j ~

0-

2

1

c.

!l
ii

Filename

Line

3

Record Identification Codes

~

]

OJ

~A I,
AA It

f: 1'111)

F O~

High

Low Equal

53 54 55 5667 5859 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

RPG

IBM

I

l Programmer

Date

0

~ Space

e~
e -

-".

Filename

Line

~

f-

E

.f

)

I
I

Program

-

3

4

0

1

OUTPUT

5

6

:; 4i

~

Instruction

Punch

~

8. ti
~J5

At

~ z

0

..:

z

Field Name

L

~

;3

0

z

"AUTO

8

l~r'lib

In

0

IN

3

0

~A M!r:

4

0

0

5

0
0

7

0

o

8

0

0 9

0

1 0

0

1 1

0

1 2

0

1 3

0

1 4

0

1 5

0

1 6

0

1 7

0

1 8

0

1 9

0

Positon

5

in
Output
Record

en

~~

'0

II

12~

D

!1

l3ltll

T

11

~

1

2

75 76 77 78 79 80

Page [ ] ] O f _

Commas

Zero Balances
to Print

Ves
Ves
. No
No

Ves
No
Ves
No

~~~;~f:ation 1 1.1

No Sign

CR

-

1
2

A

J

B

K

Plus Sign
V = Date
Field Edit

3

C
0

L

Z •

M

4

X -

IIII

Remove

Zero

Suppress

Constant or Edit Word

it

«~~~~~50~~~~~W~~W50~~~~~~~~wro

71 72 73 74

11~

0 2

0

a:

9 10 II 12 13 14 IS 1617 18 19 20 2122 2324 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

OiR Eip lolRrI"

0 6

...

1("

II

AiN~
7

I I Card Electro Number
I I

I
I

Output Indicators

Skip

~~
i-;:;: 'D'D ~
~
o R

I I
I I

Graphic

Punching

o
o

2 0

GX21·9090 U/M 050"
Printed in U.S.A.

SPECI FICATIONS

International Business Machine Corporation

lLls
als

M

P.A IFD ~lA

It..~

p~ Rlr

H51

12~

'" 11
II
I'

r

N""ll

'q.l.

~A I

IF: I"'1IRlA

!b'Q!
'61.

It J
\ ~I

0
..

0
0
0
0
0
ZL lL OL 69 89 L9 99 59 1>9 C9 Z9 19 09 69 99 L9 99 59 1>9 C9 Z9 IS 09 6t 8t Lt 9t 9t

»

Ct Zt It Ot 6C 8C LC 8C SC tC CC ZC IC OC 6Z 81: LZ 9Z 9Z tZ CZ ZZ IZ OZ 61 81 LL 91 51 tl CI ZI LL 01

6

8

L

9

5

t

C Z

I

Figure 1-25 (Part 2 of 2). Billing Job Specifications Using Halt Indicators

RPG II Logic

1-37

Figure 1~26 shows the three program cycles. In the first
cycle there is no error. In the second, a halt occurs because
of a blank number field. The third begins with another
record being read.

1645

JOE AARON
JOE AARON

643
742

/1645 -JOEAARON- 4768 1I
,
(

I

I

I

I

I

I

I

I

IA
I

I

•

•

•
•

•

Turn off
control level indicator L 1
and record identifying
indicator 10

I

L___

•

A

BI
_-::- _ _ _ _ _ J

1645 JOE AARON 4768

Turn on record
identifying
•
indicator 10

Perform detail
output

•
•
Change in
control field?
Yes, turn on •
control level
indicator L 1

Perform detail
calculations

•

•

Move data into
processing area

•
•

Bypass total operations

•

Figure 1-26 (Part 1 of 3). Program Cycles Illustrating Use of Halt Indicators
1-38

since detail operations are performed before the halt occurs.
In order to prevent processing data which could be in error,
you must write specifications which will bypass operations
when an error occurs. This will be discussed later in the
chapter titled Controlling Operations in an RPG /I Program.

The second cycle shows that operations are performed on
the record that contains the blank NUM field. The record
containing an amount of 742 has a blank account number
field. Thus it is not known whether this record really belongs to Joe Aaron. But Joe is charged 742, regardless,

1645

643

JOE AARON

r-- --.-- - - - I
/

1645

47.68

JOE AARON

7.42

.

742

JOE AARON

I

I

I

I

I

I
I

I

I

A I

I

I

•

RESTART
turn off H1

Turn off record
identifying
indicator 20

I

(

I

A

-----~

record

~

HALT
'\

)
Turn on record
identifying
indicator 20

output

•
/
I

•
•

Perform detail
calculations:

4768
742

•

Change in control field?
No

•

5510

•

Move data into
processing area .
Turn H1 on
(Blanks in NUM)

•
•

)

•

Figure 1-26 (Part 2 of 3). Program Cycles Illustrating Use of Halt Indicators
RPG II Logic

1-39

1645

1645

JOE AARON

643

47.68

JOE AARON

7.42
6.43

•

•

•
•

•

Turn off record
identifying
indicator 20

Turn on
record identi- •
fying indicator
20

Perform detail
output

•
/

•

Perform detail
calculations:
5510 (BALFOR)
643 (PURCHS)

Change in control field?
No

•

6153 (BALFOR)

•
•

Move data into
processing area

•
•

•

Figure '-26 (Part 3 of 3). Program Cycles Illustrating Use of Halt Indicators

1-40

Figure 1·27 shows RPG II logic related to overflow indica·
tors. A more detailed discussion of the purpose and use of
overflow indicators can be found in the chapter titled Controlling Printer Output.

Overflow Indicator (OA·OG, OV)

)

Overflow indicators are used to signal when the end of a
printed page has been reached. They are assigned to the
printer file' and turn on when the overflow line is printed.
This could be either at detail or total output time. Those
lines which you wish to print at the end of one page or at
the beginning of another are conditioned by the overflow
indicator.

•

•
•

•

•

Turn off control
level, record
identifying, and
halt indicators

•

•

Halt if
halt indicator
is on

Set off overflow
indicators if
performed during
this cycle
Turn on record
identifying
•
indicator

)

occurs, turn on
overflow indicator

•

Perform detail
calcu lations.
Turn calculation
resulting indicators
on or off

•

Move data into
processing area.
Turn field
indicators
• on or off

Change in control field?
I f yes, turn on appropriate control level
indicators
•

Is overflow indicator
on? If so, perform
output operations
• conditioned by
overflow indicator

•

•

Perform total
output.· If

Perform total
calculations

overflow occurs
turn on the
overflow indicator

•

Figure 1-27. logic for Overflow Indicators

)
RPG II Logic

1-41

Matching Records Indicator (MR)

The matching record indicator (MR) is used only when you
are processing more than one input file. It indicates when fields on records from different files match. MR is set only
after total operations are performed. Thus, at detail time,
MR always signals the matching status of the record just
selected for processing; at total time, it reflects the matching
.
status ·of the previous record.

Thus far, you have been concerned with only one input file.
According to RPG II logic discussed so far, a record is read
from the input file, then processed. Another is read and
processed and so on. Suppose you have more than one in·
put file; from which file is a record read?
RPG II logic has been designed so that your program can
select the next record for processing. Figure '·28 shows
general steps in the logic (multifile logic) required when
more than one input file is used.

•

•

•
•

Specific steps in the multi·file logic are described in the
chapter titled Match Fields and Multifile Processing. At
this time, it is sufficient to know at what point in the pro·
gram cycle records are selected for processing and at what
point MR is turned on .

Turn off
• control level,
. recordJdentifying, and halt
indicators

•

•

Multi·file logic: logic
used to select the
record to process
when more than one
input file is used.

Read a
record

Are end·offile
conditions met?

Halt if
halt
indicator
is on

Are multiple input
files being used?
If so, determine
the next record
to process
Turn on
•
recording identifying
indicators

Perform detail

•

•

Perform detail
calcu lations.
Turn calculation
resulting indicators
on or off

•

Change in control field?
If yes, turn on control
level indicators
•

Move data into
processing area. Turn
field indicators on or off

•

TurnMR
on or off
•

Perform total
output

•

Fipure 1·28. Simplified Matching Record Logic

1-42

Perform total
calculations. Turn

•

Setting Indicators
You have just seen the normal setting of indicators according to'RPG II logic. You, in your program, can alter this
setting by turning any indicator (except 1P) on or off
through use of the operation codes SETON andSETOF
(see Figure 1-29). An indicator may be set during either
detail or total time. It will be set at the time the SETON
or SETOF code is executed and will retain the setting you
, give it until it is reset according to the program logic.
(Refer to the logic for the,various indicators, earlier in this
section, to determine when they are set on and off in the
logic cycle.)

RPG

IBM

Indicators of various types may be used anywhere in the
program. For example, you can use LR as a record identifying indicator, L1-L9 as resulting indicators, or L1-L9 as
record identifying indicators. If you need to set indicators
yourself, you should be thoroughly familiar with RPG II
program logic so that you will use the indicators correctly
in your program.

CALCULATION SPECIFICATIONS

Form GX21·9093
Printed in U.s.A.

Internatlonll Business Mach."e Corporation

1 2

Program

Dale

Programmer

C

Indicators

~

9[2
i.e

~

E

)

4

Factor 1

Operation

5 6

~ (I)

a 1

C

a 2

C

7

a 3

c~

a 4

C

o

5

C

~

Ie

8

~

Factor 2
Name

t£

& 8 5~
3

Arithmetic

>..Jc(

t- (5

~

0

z

Length

:l!

IS~ Irb~

1-- r-I--

~
:!:

'0

z

9 10 1112 13 l' 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 46 49 50 51

1

75 78 77 78 79 80

[I] of_ ::;~f~calion I I I I I I I

Resulling
Indicalors

Result Field

At At

& :; z
Line

Page

51~

rr"F

Plus IMinusl Zero
Compare
1>211<211-2
Lookup(Faclor 21is
High Low Equal

53 54 55 58 57 58 59

Comments

eo

61 62 63 64 65 66 67 68 6Q 70 71 72 73 74

Il~ 1112

ITU lRlhl II rzjIJ It 12.

~'9

fJ EN 9~q ~FIE

~IN

I

Figure 1-29. Setting Indicators

~\

.-/'
RPG II Logic

1-43

1·44

Review"

)

1.

Arrange the following steps in the order they occur in the RPG II· logic cycle starting with Read a record.
a. Read a record
b. Total output
c. Move data from input area to processing area
d. Detail calculations
e. Detail output
f. Total calculations

2.

In the RPG II cycle, total calculations and total output are for data ·from:
a. the record just read
b. records read in previous RPG II cycles

3.

When is the 1 P indicator on? When is it turned off?

4.

Which steps are bypassed during the first program cycle?

5.

When the LR indicator comes on, the last program cycle ends after _ _ __
therefore
operations are not performed when LR is on (/* record read).

6.

When are record identifying indicators turned on? When are they turned off?

7.

When are field indicators (the indicators which test the contents of an input field)
turned on or off?

8.

Halt indicators may be turned on at various times depending on how they are used.
If a halt indicator is turned on, when does the computer stop?

9.

Calculation resulting indicators are turned on during total or detail calculations.
When are they turned off?

J
Review 1

1-45

Answers To Review 1

.1.

a, f, b, c, d, e

2.

b

3.

1 P is on at the beginning of the first program cycle only. It is turned off before
the first record is read.

4.

total calculations and total output

5.

total output, detail

6.

Record identifying indicators are turned on right after a record has been read and
identified. They are turned off at the end of each RPG " cycle.

7.

Field indicators are set just after data is moved from the input area to the processing area.

8.

The computer halts after detai I output.

9.

Resulting indicators remain on until reset by another calculation.

(

/

1-46

..

Chapter 2. Describing and Using Input

)
CHAPTER 2 DESCRIBES:
Specifying and using control fields and split control fields.
Checking the sequence of record types.
Describing input record types using the OR relationship.

OR records with field record relation.
Field record relation with control fields.
Conditioning use of input fiI~s.

BEFORE READING THIS CHAPTER YOU SHOULD BE ABLE TO DESCRIBE:
Function and coding of input fields on the Input sheet.
Function of RPG II indicators.
RPG II object program cycle (Chapter 1).

)

AFTER READING THIS CHAPTER YOU SHOULD BE ABLE TO DESCRIBE:
Function and RPG II coding for control fields and split control fields.
How to handle typical record type sequence checking situations.
Function and RPG II coding for field record relation.
Uses for conditioning input files.
Setting external indicators.

Note: You can use the review questions contained in Review 2 at the end of this chapter
to test your comprehension of the topics in the chapter. Answers follow the review
questions.

)
Describing And Using Input

2-1

INTRODUCTION

For every RPG II program, you must describe the input
information you are processing. This includes describing
input files, record types within each file, and fields within
each record type. Input files are described on the File
Description sheet; record types and fields within each input
.
file are describ~d on the Input sheet.

A control field is any field used to indicate when a certain
type of processing should be done. Since the CLASS field
(Figure 2-3) controls processing, it must be specified as
the control field. Each time a record is read, this control
field is checked for a change in contents (control break).
When a control break occurs, a different type of processing
or additional processing is to occur. In this case, a change
in the CLASS field indicates:

i
)

From previous :instruction, reading, and experience, you
should already know how to describe and use input files,
record types, and fields. You should also know how to use
RPG II indicators to condition operations. This chapter
describes additional ways to use input with control level
indicators, field record relation indicators, and external
indicators.

1.

Skip to the bottom of the page.

2.

Print the date.

3.

Skip to a new page.

4.

Print heading.

CONTROL FIELDS

A basic type of report in any data processing installation is
a detail list that consists of one line of printing for each
record read, such as a transaction listing. Figure 2-1 shows
what a detail report would look like.
Because product classes are repeated for each line, the
report is cluttered and hard to read. The same report (Figure 2-2) grouped by class is much easier to read. Here, all
items from one class are listed together with headings used
on each page to identify the information. Since all items
on one page apply to the same class, the class is printed
only once. Such a report is sometimes referred to as a
group-indicated report. Group-indication is the printing of
control information on one line per group. The date is
printed at the bottom.

CLASS

ITEM NO

DESCRIPTION

00124
00124
00124

7657352
63241B1
43151CK

SWEATER, V-NK, SZ 32
SWEATER, V-NK, S2 34
CARDIGAN, SZ 36

00124
00125
00125
00125
00125

76738K2
54321K4
56422K4
57381J4
58324B1

T-SHIRT, WH, SZ 40
T-SHIRT, WH, SZ 42

00125
00126

57421C2
67341B3

T-SH I RT, BK, SZ 46
WOOL SOCKS, BL 10

CARDIGAN, SZ 40

T-S~'HRT, WH, SZ 30
T-SHIRT~WH, SZ 32

ON HAND
10

16
17

8
11

14
15
8

12
11

IN STOCK AS OF 10/30/70

Figure 2-1. Printed Report of all Items in Stock

,/

2-2

CLASS

ITEM NO

DESCRIPTION

ON HAND

00124

46732J1

SWEATER, V-NK, SZ 32

10

6324181

SWEATER, V-NK, SZ 34

16

43151CK

CARDIGAN, SZ 36

17

IN STOCK AS OF 10/30/70

CLASS

ITEM NO

00125

ON HAND

DESCRIPTION

54321K4

T.:sHIRT, WH, SZ 30

11

56422K4

T-SHIRT, WH, SZ 32

14

57381J4

T-SHIRT, WH, SZ 40

15

5832481

T-SHIRT, WH, SZ 42

8

IN STOCK AS OF 10/30/70

)

ON HAND

CLASS

ITEM NO

DESCRIPTION

00126

6734183

WOOL SOCKS, 8L 10

11

6743283

WOOL SOCKS, GR 10

9

IN STOCK AS OF 10/30/70

Figure 2-2. Report Group - Indicated by Product Class

CLASS

ITEMNO

DESC

~
I
I

DATE

ONHAND

)

5 6

12 13

32 33

38 39

44

Figure 2-3. Item Record

Describing And Using Input

2-3

Coding Control Fields

indicator is used on the Output· Format Sheet (Figure 2-4,
insert B) to condition those operations which should be
performed only when a control break occurs. Note that the
L1 indicator is used in line 08 to condition the CLASS field
in the detail output line. This causes the CLASS field to be
printed only for the first record of a new control group.
That is, the CLASS field is printed only when it changes.

The RPG II specifications for the program are shown in
Figure 2-4. The entry L1 on line 02 of the Input Sheet
(Figure 2-4, insert A) establishes the CLASS field as a con·
trol field. When the information in the control field
changes (a control break occurs) L1 is turned on. The L 1

RPG

IBM

GX21·9094

INPUT SPECIFICATIONS

UIM 050·

Printed ",U.S.A.

International Business MachIne CorporatIon

I

Program

Page

Programmer

Date

I

Record Identification Codes

E

Il

iii

Filename

~·o

~

i

~

~

'2

5

~

z

0 R

~

0

~

Position

t

~

Position

§~
Cl

0

0

6

z

~

z

t

Cl

~

75 76 17 78 79 80

Field
Indicators

Field Location

]

Line

2

[[]Of_ ~~~~;~f:ation I I \ \ I I I

Position

~

§ <5

0

z

;;;

t

e ~

i

~ <5

Field Name

From

a:

To

..J

:¥
g'g>

] ......

]

g

~

III

0:

·8

0

:2-0

r?

.~

8

Cl

.~

~:~
.. .c;

: 02 types in a row. But what if a customer actually made two payments during the month? Or what if
he bought.more than one i~em during the month? You
wouldn't want the program to halt whenever it read more
'than one payment of purchase record per customer.

, To prevent halting in this situation, you must make another
entry, this time in column 18. Place the letter 0 in column
18 to indicate that the record type is optional (it mayor
may not be present). If you leave column 18 blank, the
computer assumes, that the record type must always be
i
present.

You must make another entry to indicate whether the program can expect to read one or more records of the same

Of the three record types, which must always be there?
The balance forward record should be present. Leave column 18 blank for it. The other two record types are optional. Enter the letter 0 for each (see Figure 2-13):.
/

RPG

IBM

GX21,9094 U/M 050·
Printed in U.S.A.

INPUT SPECIFICATIONS

International Business Machine Corporation

12

Program
Programmer

Page

Date

Record Identification Codes

B

I

-

c.

B

Filename

Line

8.

~

~
ell

~

Z

.£~-

....

~§ ~
Z

0

i

:~

il

'';; 0

--- j.!

~

3

2

1

Position

geg
()

a::

Z

~

Position

2

u u

Ii;

~.e ~
~f)6

~

0;

Position

~~
~u

Ii; '"
t; t

a::
....

From

To

Field Name

~

~~~

4

5

6

7

8

~It

~I

IR

o

2

I

o
o
o
o

3

I

I, ,

1411

4

I
I

6

I

o

7

I

o

8

I

o

III

l'il~

12~ INlA IMIJ:
l'1iZ lain !OIR
\4 7 ~IQlA IDll'IF
lslh "'It' Islr IN~

II
12.1

12.P5 INIA MIl:
12.'7 QIA ,T I'INII

'1

Itl2
~I.~

l1.2

II.~

q6
q!1l

~I:>

I
I

11

11

I

"I"
131b

I

1 3

I

-

Figure 2-11. Description of Sequenced Record Types

2-10

1

Irl3

9

1 0

1 2

~

5
:E~

u:~

3 !.[

~
~

IIIIII

Field
Indicators

'0

~

Zero
Plus Minus or
Blank

u:

9 10 11 12 13 1415 16 17 18 1920 21 22 23 24 2526 27 28 29 30 31 3233 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 5960 61 62 6364 65 66 6768 69 70 71 72 73 74

rr II II rr INlr.. ill

0 1

5

~;~~;~f:ation I
g

1 ~a

'~

0

AND

3

'757677787980

of _

Field Location

B

~

OJ

122J NIA MII=
1~5 rlr EI~
~2.

riD SiT

RPG

IBM

)

GX21·9094

INPUT SPECIFICATIONS'
1

Program
Programmer

~'Q'f'

Filename

I!
11

3

4

10

1

10

2

10

3

5 16

7

fO
IA

8

IS II
'I

9 10 11 12 13114

II

I

IT

Position

d,~~

fl§ IJ

I

10 6

I

7

I

10 6

I

10 9

I

1 0

I

11

I

fl§

Codes

II

Field Location

Ifl§ IJII Ii

Position

2

OJ

I I I I 1I

Field
Indicators

,.

Field Name
From

75 76 77 78 79 60

~~~;~f:ation I

of _

~

;!'.~

To

1 Plus Minus

!~:ro
I

~

Blank

21 22 23 24 251 26 127 28 29 30 31 32 133 134135 36 37 38 139 140 141142 143 44 45 46 47 4B 49 50 51 152 53 54 55 56 57 58 15960 161 62 16364 165 66 67 68 .69 70 71 72 73 74

Balance

(/J 1

INt=.

FlllCord pElr gro l Ip.

I
I

I

10 5

I

Position

I

10 4

10

Record

Ij

Line

Page

I

Oat. ;

I

-

U/M 050·

Printed in U.S.A.

International Business Machine Corporation

1"1.

,

II
II

icates one or more
)ayment Record per grou

"

I IIIIIj Ir I
I
II

eJ

,.

one or mOrl I I
Purchase Records per group

II I I I I I II I I I I I I

I

Figure 2-12. Number of Each Record Type Per Group

"~I

IBM

International

RPG

BU5ines~ Machine Corporation

GX21·9094

INPUT SPECIFICATIONS
1

Program
Programmer

Page

Oat.

Record

I

Codes
2

I--Line

5

6

7

8

9 10 11 12

10

1

I~ ITIL

10

2

I

10

3

I

i

~I§

[§"

4

to

Lit INt;

Fir-lill :]

IA N~h;t;J

I)

fl§

,~!§IJ

Position

Position

I§

Ifl§ IIIj1i

21 22 23 24 25 126 127 28 29 30 31 132 133 134135 36 37

~J..

A

indicates that
Record must

IIII
III

10 6

I

Payment Record is optional.

7

I

10 6

I

I III III I I I I II I
II I I
III

9

II
II

11

II

-

I-

~:ro
Blank

o indicates that the

~

~-~

:n

: Plus IMinus

prese~

I

1 0

!)

Field Name

I I I I II
III

I

0

To

I I I I I' I

Field
Indicators

Ij
From

~~;~f:ation I

45 46 47 4B 49 50 51 152 53 54 55 55 57 68 159 60 ,61 62 16364 165 66 167 68 69 70 171 72 73 74

10 5

I.....
IV.

75 76 77 7B 79 80

of_

Field Location

:=5
Position

2

OJ

3

10 4

!o

I
--/

,!
I!

3

!

----\

Filename

U/M 050·

Printed in U.S.A.

',.,

M
I I I I

D

"
that the
ase Record is nn-tlnn<>1

J IIIILIIIIIL I'
I I I I I

I I I I I I I I I

I

Figure 2-13. Optional Record Types in a Group

Describing And Using Input

2-11

Checking the Order of Record Types in a Group

II,

summary, three entries must be made to ensure proper
checking of the sequence of records in a group.

1.

Columns 15~16 must contain a numeral from 01
through 99 that indicates the order in which records
must be read.

2.

Column 17 must contain an entry that indicates
whether or not more than one record of a type can
be expected. A 1 indicates that ,only one record of
type will be accepted. An N indicates that more
than one record of a type wi II be accepted.

a

3.

For the end-of-month billing example, the NAME field is
used as a control field. A change in the NAME field indicates the end of one group and the start of another. Since
the balance record is always the first one in a new group, ,
the balance record type should be the only one that causes
a control break. If the records are mixed up, as shown in
Figure 2-15, a control break wi II occur before all records
of one group have been read. For ~xample, when the
Arnold James' payment record is read after a John Hill
balance record, a control break occurs because information
in the NAME field changes. There should be no control
break at this time. If there is a control break here, the
results of the report will be inaccurate.

Column 18 must contain an entry which indicates
whether or not the record type is optional. The letter. 0 indicates that the record type is optional. A
blank indicates that the record type must be present.

Incorrect Records Within a Group
The entries for checking the sequence of record types within a group will determine that the records in groups A and
B shown in Figure 2-14 are in order. Suppose, however,
that the payment records for John Hill and A. James were
mixed up (Figure 2-15). The program using the sequence
specifications just described would not find this error. The
record types are still in proper order, but the records themselves are in the wrong groups. To ensure that records are
in the right group other specifications have to be made.

JAMES, A

®
JAMES, A

JAMES, A

j_payment
t------Balance

HILL, JOHN

Purchase

Payment

Balance

Figure 2·14. Correct Data Records in a Group

2-12

)

To prevent this, certain calculation specifications must be
made. Line 01 of the Calculation sheet shown in Figure
2-16 shows that indicator H 1 is set on. H 1 is a halt indicator. When it is on, processing halts after calculations and
output operations have been performed for the'record just
read.

JAMES. A

®

I-payment
I
I

L_-.LJ______J-I-----Balance
I

HILL, JOHN

)

......- - Purchase

10+----

Payment

....- - - Balance

Figure 2-15. Incorrect Data Records in a Group

RPG

IBM

Form GX21-9093

CALCULATION SPECIFICATIONS

Printed In U.S.A.

International Busint.. Machine Corporation

Page
Programmer

-

C

Date

Indicators

~

At

~j~

Name

&85 ~

01 1 c I
2

1

'0

z

'0

Z

9 10 11 12 13 14 15 16 17 18 t9 20 2t 22 23 24 25 26 27 2829 30 3t 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 4B 49 50 5t

01 1 c .~ NrlllL
1

-

Length

(I)

3 4 5 6 7 8

)

Factor 2

Operation

Factor 1

At

... '0 a:
E ::.

_1_1

Result Field

gee

~Q

Line

75 76 77 78 79 80

1 2

Program

IsII=IT~N I J.111 I I I I II I I I I I
II
II I I I I I I I I I I I I II I I III I I I I Ilill
I
I I
I I

I I 11 Jill J
I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

[OOf---..:. ~~~~f:ation I I I I I I I

Resulting
Indicators
Arithmetic
Plus 1Minusl Zero
Comments
Compare
1>211<211=2
LookuplFactor 2)is
High Low Equal
54 55 5657 5859 60 6t 62 63 64 65 66 67 68 69 70 7t 72 73 74

1~ll

I I II I I 11 I I I I I II I
II I II 11111111111111
II I I I II
I I I I I
I

I

I

Figure 2-16. Haltinu When Incorrect Record if Found in a Group

Describing And Using Input

2-13

Look at the indicators which condition the SETON operation, L1 and N01. A control break (L 1 turns on) caused by
record type 01 (balance record) is correct. But a control
break (L 1) caused when any other record type (02 or 03)
is read indicates that a record is in the wrong group. This
is an error condition. Thus when L1 is on (a control break
has occurred) with any record identifying indicator other
than 01 (N01), the halt indicator H 1 is set on to stop processing.

Sequenced and Unsequenced Record Types in a Group
So far we have talked about having records in a group which
must be in a special sequence. However, you may also have
records in the group which need not be in any sequence. In
this case, all records which do not need to be in sequence
are specified on the Input sheet before those that do. Remember that unsequenced records must have alphabetic
entries in columns 15-16, and blanks in columns 17-18.

Halting on an error is one way of handling error conditions.
This method allows you to stop, correct the record in error,
and start processing over again. This often wastes time since
you must restart the computer each time an error is found.
Programming to bypass the error is more often done. This
will be discussed at a later time.

IBM

I
I

RPG

Unexpected or Unused Records Within a Group
If the computer reads any record types which are not specified, it will halt. Often you may have several record types
within a file, but the job being done requires the use of only
a few of the record types. Do you still have to specify
each type? No, you don't. But remember each time an undescribed type is found, the program halts. This could result
in wasted time. Therefore, to prevent halting and to eliminate a description of each record type, you specify a catchall indicator in addition to specifying all record types needed
(see Figure 2-17).

INPUT SPECI FI

These record types are not
described for they are not
needed. The catch-all
sequence entry causes all
to be considered as type 99.

International Business Machine Corporation

J

Program

I

Date

Programmer

Graphic

Instruction

Punch

I

I

I

I

Record Identification Codes

9

I

Punching

Identification Code

n* (blank)

l:l

~

'--

1

3

2

c.

i )~
&~
:8
5 ]
'::;'-

Filename

Line

~
I-

~
5

6

r--!-r--

o

3

4

o

1

7

8

o

2

IIR I,:r
I

o

3

I

o
o

4

I

5

I

o

6

I

o

7

I

o

8

I

o

9

I

1 0

I

11

I

1 2

I

1 3

I

1 4

I

R

'A N"'D

1
Position

9 10 11 12 13 14 15 16 1718 19 20 21 22

hlR ID.S Nls
~ll1

2~

;.;.

for5'~

Position

~~

~

Position

~'

~Q
~h1 f!
l~ j~ ~ ~ <5

I

C

B

E

27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

,ql~

~[~ 1~lcA

tZlll

~[~

F?J... ~[r R

(

~H.. 1~1('!r

'rJl.

A

0
i

~12 J la oJl,

~[b

if' ~

0'

,.,(1-..

1..... ,.[1 ...

.- Figure 2-17. Catch-All Sequence Entry

2-14

ge
~ ~

z

~

'ql/,

~I"

I

These record types are
individually described
because they are used
for the job.

)

According to the specifications in Figure 2-17, any record
read which does not have one of the identification codes
specified, is considered to be record type 99. If no operations are conditioned by record identifying indicator 99,·
none will be done for all records which are considered type

99.
You may also use a catch-all indicator specification to prevent halting when unexpected records (record in wrong
file, blank record, etc.) are read. Unwanted card records
are normally stacker selected into a special stacker so that
they can be removed from the deck at the end of the job.
Figure 2-18 shows specifications that describe three unsequenced record types used in the program and a catch-all
indicator which will be assigned to unwanted record types
found in the file. When records are not in a special order,
(alphabetic entries in columns 15-16), the catch-all indicator
is described last with no Record Identification Codes. The
catch-all indicator turns on if a card is read which can not
be identified by any of the preceding Record Identification
Codes.

RPG

IBM

INPUT:

Dal.

Programmer

)

I

-

Filename

Line

!
~

4

5

6

'Ar;'o
7

If'

o

2

I

o

3

I

o
o
o

4

I

5

I

6

I

o

7

I

o

8

I

o

9

I

1 0

I

11

I

1 2

1~1l

c-r-c-g
o R z

0 1

..

Record Identification Codes

~

]
1:

3

You may have some programs which process several different record types. Two or more record types might contain identical fields. To eliminate coding these identical
fields for every record type you may use the OR relationship which indicates that certain fields are found on all
record types. Not all fields are identical in different record
types, however. You must have some way of specifying
those fields found on only specific record types in the OR
relationship. Field record relation indicators indicate those
fields found on only specific record types.
Field record relation indicators will relate:
•

A field to a specific record type in the OR relationship.

•

Control fields and split control fields to a specific record
type in an OR relationship.

•

Match fields for more. than one record type (see Match
Fields and Multifile Processing).

OR Relationship

International BUSiness Mach"lne Corporation

Program

'\

FIELD RECORD RELATION INDICATORS

8

1

2

c.

~·o

~

Position

"E

~

m

~~~

~

u <5

Position

i;;

~
~

e
N

~..

Positio

~u<5

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 2526 27 28 29 30 31 32 33 34 35 36 37

lAIR In~

You can eliminate duplicate coding by using an OR relationship to describe identical record types. This method also
reduces the size of the program.

lAA

ttlll

'Rb

r~

Iss

rlJ2.

'qb

~12

Irl'

rl513

·qb

~l3

Ino

~~

I

When using the OR relationship, you need to write the
names of identical fields from more than one type of record only once on the Input Sheet. OR relationship specifications indicate that the fields mimed may be found on
all of the record types. The following input specifications
are necessary to set up the OR relationship:

1.

Record identifying indicators (01-99) for each record
type.

2.

The letters OR in columns 14-15 for all record types
other than the first.

3.

Entries describing the record identification code of
each record type (columns 21-41).

T

Figure 2-18. Unsequenced Record Types with Catch-All Sequence
Entry

)
Describing And Using Input

2-15

When columns 63-64 are blank, the fields listed are assumed
to be found in the positions specified on all records in the
OR relationship. When an entry is specified in columns
63-64, the field is found only on the record type having that
record identifying indicator.

The record identifying codes must be described for all types
of records in the file before any fields are described (Figure

2-19).
The letters OR are placed before the description of each
record type except the first. OR indicates that the fields
listed may be found on all record types. In this example,
the fields listed may be found on records identified by an
N, D, or 0 in column 96. Identical fields are described
after the entries which establish the OR relationship.

To use the OR relationship with field record relation entries
you must:

1.

Code the specifications describing record types in the
ORrelationship (Figure 2-21, lines 02,03, and 04).

OR Relationship With Field Record Relation Entries

2.

Describe all fields which are identical on all record
types (Figure 2-21, lines 06, 07, and 08). In this
example, the identical fields are CLASS, ITEMNO,
and DATE.

3.

Specify all fields that are found only on the first record type in the OR relationship, then the second record type, then the third, and so on (Figure 2-21, lines
10,'11,12, and 13).

In the example of printing a report by product class, all
record types had identical fields (Figure 2-3). Suppose that
the information on each record type is organized differently; the records have some fields which are identical and
some which are not (Figure 2-20). Now you want to print
only a description of new items. The record identified by
an N is the only one with the DESCfield. All record types
still have CLASS, ITEMNO, DATE, and ONHAND fields.

In this example, the only fields for the first record type
which have not been described are DESCand ONHAND.
For each field, the entry 01 must be made in columns
63-64. This entry means that DESC and ONHAND are
found on only the record type 01 identified by an N in
column 96.

The OR relationship can be used when all fields are not
identical. In this case, additional entries must be made in
the field record relation columns (63-64) on the Input
,sheet. The entry consists of any of the record identifying
indicators (01-99) assigned to a record type specified in the
OR relationship. The record identifying indicator entered
in columns 63-64 relates a field to a particular record by
identifying the record type in which the field is found.

/

GX21-9094 U/M 050'
Printed In U.S.A.

RPG' INPUT SPECIFICATIONS

IBM

International Business Machine Corporation

1

Program

Page

Programmer

Dale

Record Identification Codes

I

0

Filename
Position

3

4, 5

6

7

8

9

8i

~ E'
0
z
6

Position

~~
~u

l;
t;

l!!

<5

Position

~
0
z

0
N

u

l;
t;

g

-;;;
-in

Ji

~

!
6 ~
~

a:

From

To

..J

OJ

0:

Field Name

~
]

c

.3

Field
Indicators

0

0

;E-t;

~

u..i.L

J

.~ Qj

g .sE'
-£ :s

~
Ii
0

'C

'C
0;

Zero
Plus Minus or

Blank

~6 u:

10 11 12 13 14 15 16 t7 18 19 20 21 22 23 24 25 26 2~ 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

KJAA

~I,

qh

~IN

OR

~12

~b

~In

01

II

02

I

o
o

4

I

5

I

o

6

I

JI~

132 InIES'"

o

7

I

33

I... "

o

8

I

Figure 2·19. Using the OR Relationship to Describe Identical Record Types

2-16

75 76 77 7B 79 BO

Field Location

I--Line

2

[]JOf_ ~~~;~f:alion I I I I I i I

12 IIITEM!N'"
AND

CLASS

)

DESC

ITEMNO

5 6

12 13

!

ONHANO

m
II

Z

90

40

3233

'8o

DATE

9596

New Item Record

~

CLASS

ITEMNO

(")

o

~

ON HAND

o
m

DATE

~

II

o

~
12 13

5 6

90

20

9596

Regular Item Record

~

CLASS

ITEMNO

(")

o

~

ONHAND

o

DATE

~

m
II

o

~
5 6

12 13

20

90

9596

Discontinued Item Record

Figure 2·20. Record Types with Some Identical Fields

)
RPG

IBM

International Business Machine

GX21,9094 U/M 050'
Printed in U.S.A.

INPUT SPECIFICATIONS

CorpOr~tion
1

Program
Programmer

Page

Date

I

Record Identification Codes

ii

]

I---

i

Filename

line

~
....

tll

~

r-I-r-

~~~

1

~

c.

~

~§ ~
~.g ~
:>

z

c.

0

0

0
Position

irl

a:

:0

~~~

~

uG

Position

_
~

S

e

o~

~

';:;
';;;

&l

Position

~

~§
z u

jji

Field Name

0

0;

zuu

75 76 77 78 79 80

Field Location
3

2

';'.

Z

2

[00'_ ~~::~':ation I I I I I I I

From

]

C>.

To

~
'g

~

c

.§

0

:2-tl

.~~

u.u.

~
1:

f:~ w~
~2

:Ou

Field
Indicators

'0

Zero
Plus Minus or

Blank

u:

AND

3

4

o 1
o 2
o

3

o

4

7

8

9 10 11 12 13 14 15 16 17 18 19 20 21 2223 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 5960 61 62 6364 65 66 67 68 69 70 71 72 73 74

1* Inll= ~~ IRIT ip,11=
Itt INIV II~IN
I

I

6

o

7

I

o

8

I

o

9

1* Irlu IJ:~IJ:

o

I-

It<

~llL IRIH{ t<11 h"ly IpIE~
~~I
19~ j,.IN
~I;)
'"'IQ
~Ib Irl'"
I"

lIN ITIHIE

~R

f.-IR
Iqlb It- II"
~13
Il:lr 11= II Itllc:. IAIRII= Irlr IEIN rrlr IrlAll

IllN IAIL

HII-

I~

Il=lr 11= IL InLc; l4.IRIE'

II=~

IIINln """IN

~INIE

Ip~ IRh" Illr

III
19c2
IAQ
11.3

11

I

1313

1 2

I

1113

..

I

lIB

I

~

ITY IIJI~IS

1.5 Irll

II

I

T

~

IRIE IL ~ rrlI "'IN I~II-I T!D ~IT IRish"

i.

IH~

1 0

1 3

\

6

I~ ITIH IE:I~II=
I

o 5

../e

5

IAIc;I~

IL I, IIlr IFIMIN
IQI.<" ~In IMrlJ:
IRI~

1~lr

I~I;>

~IY Ipl~

11:11: 1~1r

I" I,.,
In
bbl l/tlro- .I", u 11\11 I",
I"'fIUJIll
1.1

'U

IliA

1"1,,

~
~Il
~ll

lal2
~13

Figure 2·21. Field Record Relation
Describing And Using Input

2·17

Field Record Relation with Control Fields

The DESC field is related to the record identified by an N
because this is the only record type having a DESC field.
ONHAND, however, is found on all record types. ONHAND must be related to the record having an N in column
96 because it is in a different location on this record type.
The field location of ONHAND must be specified and related to the corresponding record type by the record identifying indicators (Figure 2-21, line 11).

Control fields can also be related to a specific record type
in an OR relationship by field record relation entries. In
Figure 2-22 the CLASS field is a control field (L 1 in columns 59-60). It is also found on all record types; blanks
in the columns 63-64 indicate this. However, if a control
field is found on only one record type, the control field
must be 'related ·to the record type in which it is found by
an entry in columns 63-64 (Figure 2-22, line 07).

Rememberthat when fields are not identical on all record
types, the field must be described and related to all record
types on which it is found.

The number of control fields need not be the same for
every record in the OR relationship. Regardless of the number of control fields per record type, all control fields and
all other fields related to the same record type should be
entereu as a group (Figure 2-22, lines 07 and 08).

All fields relating to only one record type should be entered
as a group and must be given the same record identifying indicators in column 63-64.
If most fields are common, describing the record type with
field record relation usually reduces the number of specifications you must write and the amount of storage necessary
to hold the instructions.

RPG

IBM

Field Record Relation with Split Control Fields
The rules applying to field record relation with control
fields also apply to field record relation with split control
fields. In addition, wnen split control fields are found on
record types described in an OR relationship used with field
record relation entries, all portions of the split control field
must be assigned the same control level indicator and the
same field record relation entry. This is necessary because
all parts of a split control field are on the same record rather
than on two different records.

GX21 ·9094

INPUT SPECIFICATIONS
1 2

75 76 77 78 79 80

Program

]
Filename

Line

...~

~
5

Record Identification Codes

~

I

r---

4

pageDJOf_

Dale

PrO!1ammer

3

6

~

I
r-r-r-

o R
f;:r;;~

7

8

1

c.

~
1i

5

Z

~·o

~

."
0

'il

Position

]

Z

C

~

Position

~ §a

~~ g
~~6

Position

~c

~§

~~~

.;;;

From

Field Name

~

~~~

~

c

c

IIIIII

Field
Indicators

."
0

0

:2'4:;
.~

"ii

-£

:~

~

3 .sg' ]
u.U::

~

.~

~6

."

-.;

Zero
Plus Minus or
Blank

LL

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 3233 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 5960 61 62 63 64 6566 67 68 69 70 71727374

tJV lEN TR YAA

OH

~Ib ~N

It
I

""R

12J?

0 3

I

O'R

(23

o

4

I

1

o
o

5

I

191b
IqlA

~n
~f'

6

I

h
q(lj

0 7

I

I

o

8

I

~J

o

~

.r; roll

A.c;~

Ll

12 Trr t:.M.N
9.r; 1(1] J 110\ IE

301"(,..1'\11= sr
... 1'\

.:1""1{.

9

I

I

~

I..
IL

1 0

I

L~

t!!:..

11

I

-

~

To

0 2

.

~~~;~f:ation I

Field Location
·3

2

0 1

1 2

U/M 050'

Printed in U.S.A.

International Business Machine Corporation

L2

~II

, n It..Il"I

ell

JI\ IfI.IJ"\

(J,

11\

'

.. ,("\

el_~

I

1"'"

Figure 2·22. Field Record Relation with Control Fields
2·18

(

CONDITIONING USE OF INPUT FILES (EXTERNAL
INDICATORS)
Thus far, in this chapter, you have read about jobs that
require the complete processing of all input files specified.
The following topics will illustrate how you can use RPGII
to do jobs for which:

1.

It is not necessary to process one or more of the files.

2.

It is not necessary to process an entire file.

Using One Program to do More Than O'ne Job
Have you ever thought how useful it would be 'if, when
doing similar jobs, you could use one program to perform
more than one function?
Consider, for example, the following jobs. Two types of
reports are required each week. One is a sales analysis reo
port showing what items sold during the week. The second
is an inventory report showing balance on hand for each
item in stock. Notice the similarity in the format of the
reports (Figure 2·23L

BALANCE FORWARD

SALES ANALYSIS
ITEM NUMBER

46732

AMOUNT SOLD

DATE

ITEM NUMBER

46732

AMOUNT SOLD

DATE

7

09/15/70

09/16/70

8

09/16/70

09/17/70

2

09/17/70

"!

09/15/70

8
2

BALANCE

09/19/70

09/19/70

150*
46739

12

09/15/70

20

09/16/70

25

09/17/70

8

09/18170

3

09/19170

46733

)

32*
46739

12

09/15/70

20

09/16/70

Figure 2·23. Two Similar Reports from Two Different Jobs

Describing And Using Input

2·19

Two files are available: the MASTER file which contains
balance forward records for all items in the store; and a
transaction file (TRANS) which contains all the weekly
sales for edch item (Figure 2-24). Both files are in ascending order by item number.
The sales analysis report merely requires a listing of records
found in the transaction file.
The inventory report requires that records from two files
be matched. (If you are not familiar with multifile processing using two input files, see the chapter Match Fields

and Multifile Processing. ) When records from both files

match, the number sold is subtracted from the balance on
hand. The new balance is then printed on the report
following the list of transactions:
One report requires two files; the other only one. How
could you write one program to produce reports which
have such different file requirements? If you had some
wayof telling the program when to expect the use of one
file and when to expect two files, it could be done.
This you can do with external indicators.

Item Number

Item Number

~
45671

Note; On disk systems,
MASTER & TRANS
could be disk or
console files.

00123

/

MASTER
FILE

/

/

/

TRANSACTION
FILE

/

/

/

/

/

\

/

/

I

\

/
123

..

5

6 7 8 9 1 0 \I

I

1213141516'17 18 1920212223242526272829303132

/----------------------------'~

3334353637383940"'424)4445464748495051525354 55565758596061626364

B

979899100101 '0210310410510610','08109110111 11211311411511611711811912012112212)124125126127128

1

A
8
4

!

4

J.

~

97 98 99 100 101 102 103104 105 106 107f8 109 110 111 112 113 114 115

117 118 119 120 121 122 123 124 125 " . 127 128 ~

7

8

9

10

III"

DATE
13 14 15 I.

8
4

17 18 19 20 21 22 23 24 25 2. 27 28 29 30 31 32

!

~ ITEM QUANTITY

~

B
A

I

2

3

4

J.

7

8

9

10

"I"

~

DATE
13 14 15 I.

1718192021 22 23 24 25 2. 27 28 29 30 31 32

~

B
A

A

A

8
4
2

8
4
2
1
B

8
4
2

A

A

A

A

8
4

8
4

8
4
2

8
4
2
1

1
B

333435363738394041424344454647484950 51525354555657585960 61626364

2
~~"~~M~nnH~nnnnW~~~~~~~~M~V~~"~~

IBM3700

2
1

1

B

8
4
2
33 34 35 36 37 3839 40 .. 4243 44 45 46 47 48 49

so

51

52 53 54 55 56 57 58 59 6061 62 63 64

16566676869707172 737475167778798081 82838485868788899091 9293949596

IBM3700

Figure 2-24. Format of Records Used to Produce Sales Analysis and Balance Forward Reports
2-20

II.

A

ITEM BALANCE
FORWARD
3

B

1

B

Setting External Indicators
You are already familiar with several types of indicators
used in theRPG II language. These indicators are used to:
1.

Once an indicator is set, it is not changed during the entire
program. The only way the setting may be changed for the
next program is by another Indicator Control Card entered
in the System Initialization Prog~am.

Signal the occurrence of a specific condition, such as
matching records, control break, or last reco~d ..

2.

1

Control when certain operations should be performed; such as only when a control break occurs,
or when a specific record type is ,read.

in the Card System, enter an Indicator Control Card in the'
System Initialization Program. The control card myst have
the following format:

Columns

Entry

0

0

0

0

- I ndicators set
- Punches'

1

0

/

\

/

\

/

\

Most indicators are set by the program on the basis of the '
conditions which occur during the execution of the program. External indicators, however, are set by you prior
to the execution of the program. You do this in one of the
following ways, depending on which System/3 model you
have:

Model 10 Card System: In order to set external indicators

ua

U1 U2 U3 U4 U5 U6 U7

/

\

/

65 66 67 68 6970 71 72 73 74 7S 76 77 78 79 80 8\ 82 83 84 85 86 87 8889 90 91 92 93 94 95 96

B
A

~~~a~~m~m~mm~oom~ruMM_mM"BrnUmm~mrn~

8
4
2

~

8
4
2
1

2

3

4

5

6

7

•

9

1011

12 13 14 15 16

,7,.,92,021 22 23 24 25 26 27 2. 29 30 31 32

A

1-2

)

/ / (two slashes)

3

blank.

4-6

INO

7

blank

8-15

One-position entries indicating the setting
of U1 through US. Indicator U1 is set in
column 8, U2 in column 9, and so on, as
follqws:
1
Indicator is ~urned on
Indicator is turned off
o
~ (blank)
Indicator remains as it
wasset in, the last job

16-96

~
A

8

8

4
2.
1
B

4
2
1
B

33 343536373839404'424344 45 46 47 484950 51525354 S5 565758596061626364

A
8

"\

B
A

A

8
4

4

2

2

1

~~n~~~nnnu~~nH~~~~~M~%n~~~~~~~e%1
181013700

Fig~re 2-25: Indicator Control Card (Model 10 Card System)

Model 10 Disk System and Model 1-5: Although most
indicators are set by the program, you set external indicators
prior'to the execution of the program. This is done by
including a SWITCH statement in your Operational Control
Language. The format of the SWITCH statement is:

1/ SWITCH indicator settings

blank'

Figure 2-25 shows an Indicator Control Card which causes
external indicators U1 and U8 to be set on, indicators U2
through U6 to be set off, and indicator 'U7 to remain as it
was in the 'previous program'.

The indicator settings are:
indicator is turned on.

o

indicator is turned off.

X

indicator is unaffected.

J
Describing And Using Input

2-21

Figure 2-26 shows a SWITCH statement which sets external
indicators Ul and U8 on and indicators U2 through U6 off.
Indicator U7 is unaffected.

used. This then is how you can tell a program when to expect one file and when to expect two. Consider again the
two' jobs discussed previously: sales analysis and inventory.

Once an indicator is set, it is not changed until you provide
another SWITCH statement or perform IPL. You cannot
use the SETON or SETOF operation codes with external
indicators.

The TRANS file is needed for both jobs, the MASTER file
is only needed for the inventory job. Thus, the MASTER
file is assigned the Ul indicator. You set the indicator on
for the inventory job (MASTER is used here) and off for
the sales analysis job (MASTER is not used here).

On the Model 15, when operating in job mode, SWITCH
settings are reset to 0 at end of job.
Model6: The operator sets external indicators prior to
execution of the program by responding to the SWITCH
keyword displayed by the system. An eight-position response is possible, corresponding to the eight external indicators. Possible entries for each position are:

indicator is turned on.

o

indicator is turned off.

x

indicator remains unchanged.

For example, if the operator keys XXXX10XX in response
to the SWITCH keyword:
•

Indicator U5 is turned on.

•

Indicator U6 is turned off.

•

Indicators Ul, U2, U3, U4, U7, andU8 remain unchanged.

While displaying the SWITCH keyword, the system displays
the previous external indicator setting. If all indicators are
to remain unchanged, the operator responds to SWI TCH by
pressing PROG START.
Indicators set by the SWITCH keyword retain their settings
until another SWITCH statement changes them or the next
IPL occurs.
1

Itt

4

8

VI 5M 111" rlH

12

1rl

20

16
'I: ~/j '11:1

24

28

xl

Figure 2-26. SWITCH Control Statement

Using an External Indicator to Condition a File

You can assign an external indicator to a file. When the indicator is on, the file is used; when it is off, the file is not
2-22

The Ul indicator is assigned to a file on the File Description
sheet in columns 71-72. Any of the eight external indicators
(Ul-U8) could be used. Ul was arbitrarily chosen for this
example (Figure 2-27).
Naturally, the calculations performed and the type of report written out will depend upon which job is being done.
Different calculation and output-format specifications are
needed for each. In order to determine which specifications to use for a particular run of the program, calculation
and output-format'speCifications must also be conditioned
by the external indicator. This topic will be further
discussed under Controlling Operations in an RPG 11 Program.
When writing a program which can do two jobs, be certain
that the two jobs are very similar. Where the jobs require
many different calculations and output operations, it would
be easier to write two different programs than to use external indicators.

Ending the Program Before Processing All Files Completely
When should end-of-job operations take place? The program would normally end after all records have been processed. When you are reading one file, you usually want to
process all records in that file. Normally, you wouldn't
want to process a few records and then end the program
unless, of course, you found an error condition. The computer also operates under the assumption that all records
in the file should be processed before the program ends.
The LR (last record) indicator which conditions end-of-job
operations is not turned on until the last record has been
processed.
Suppose, however, that you are using two files in your program. The computer assumes that all records in both files
must be processed before the program ends. If you want,
the program to end before all records in both files are processed (for example, when the secondary file runs out of
records), you can specify this. This is done by placing an E
in column 17 of the File Description sheet for the file which
will terminate the program.

File Description Specification
File Type

F
-

)

~:~ge~o~! ~~~;'~:I~i:;d
Record Address Type
Type of File

~Q1JOnce

Filename

File Format

I

" Additional Area
Nioverfl~

Line

I!
I~

3

4

o

2

5 1 6 7 8 9 1011121314

01 3
01 4
01 5
01 6
017

III .wl~11

IFM ~~ trlEIR

rip

T IRIA INl"
IF P IRlr NIT

fils

IF

1""\

ca,

Mode of Pr"",,!sing

File Designation
End of File

Block
Length

Record
Length

I~:S

g

;)

Key Field
Starting
Location

I~

Device

~

Symbolic
Device

Ii

Extent Exit
for DAM

",umoer OT raCKS
i

, Name of
Label Exit

..

I""

~~n~

I~

IK

21 2, 2, 124 25 26 27 28129 30 13132'3334135363738 139 140414,43444546 4' 48 49 50 61 52 153 54 65 56 57 58 59 60 61 62 63 54 65 166167

~!~
lAl~
1=

96
9Jb

MIFV"

U2

'MII=Ir

JJ

lCJjf:

pair

1

~

~~~ncl
~

Core Index

1",

11

u. ..<" ..

u"'~.

wil

NTE:IR

IF
IF

I,

IF

o Is

IF

019
110

IF
F
F
F

ZL IL OL 69 89 L9 99 59 t9 t9 Z9 19 09 6589 LS 95 55 K,tS ZS IS OS

6~

Bt Lt 9t St tt tt Zt It Ot 6t at Lt 9t st tt tt Zt It. Ot 6Z az LZ 9Z SZ tZ tz zz IZ OZ 61 BI LI 91.51 tl tl ZI II 01

6BL95ttZI

Figure 2-27. Assignment of an External Indicator

)

Figure 2-28 shows the File Description sheet used in a
billing program that is to end when the last record of the
secondary file has been processed. This is indicated by an
E in column 17.

File Description Specification
File Type

F
-

Mode of Processing

\

Extent Exit
for DAM

R..

Sequence

Filename

~",

;; ~·~cord Add;e~:'~~;d
,rl Arlrl,.<, Type
Type of File

'ile Designation
End of File

~

Device

File Format
Ig

I!
I~

3

1012
1013
014
01 5
01 6
01 7

Symbolic
Device

16

7

8

9

II 12 13 14

IFM~~ rrl;IR
FIBl4llln ulE
,F

IIII wltl

~I

Block
Length

Record
Length

•.

Number of Extents
!::nd

~

IN :Overfl~

I;)

1~li

Key Field
Starting
Location

~~n~

C'.nnHn".Hnn ' ;n.'

!

Cib

Ml=lrlllll

q~

MI=Irlul2

I~

~

IK

120 21 2, 23 2j 25 26 27 128129 30 131132 33 34 135 36 37 38 39 4C 4' 42 43 44 45 46 147 48 49 60 61 62

•• c~.

U'

Core Index

" Additional Area

Line

;:~"'u

Name of
Label Exit

154 55 66 67 58 69 16061 62 63 54 65 66167 58 69 170171 72 7374

!F
IF
iF

o Is

F

019
11 0

F
F
F
IF

ZL IL OL 69 89 L9 99 59 t9 t9 Z9 19 09 69 89 LS 99 55 K t9 ZS IS OS 6t Bt Lt 9t St tt

~\

)

t~

zt It Ot 6tat Lt 9t st tt tt zt It OE 6ZazLZ 9Z sz tZ tz zz IZ OZ 61 BI LI 91 51 tl tl ZI II 01

6

8

L

9

5

t

t

Z

I

Figure 2-28. End-of-Job Specification

Describing And Using Input

2-23

To indicate that the program will end only after all records
from all files have been processed, you have the option of
leaving column 17 blank for all input, update, or combined
files or of placing an E in column 17 for all of these files.
Figure 2-29 shows both ways of specifying that all files
must be completely processed before end-of-job. For more
information concerning end-of-job for programs using more
than one file, see Match Fields and Multi-file Processing.

File Description Specification
File Type

-F

~e

End of File

R.

Filename

~a.

of Processing

~:~~t~n~! Kl:~~~~~io;;rl

File Designation

Sequence

A,

Iype 01

,Type
~oIe

File Format

M1-'. ,.,.

Line

II~

~

12 13 14 11~1

516 7 8 9

~

1012
10 13
10 14
10 Is
10 16
10 17
10 Is
10 19
11 0
1

~

Ira

i

I:)

11lL19 21 22 23 24.25 26 27 128

IFMIAS tr If IR
II
IFlr IRlA NS lA r IT II II II
IF
lin:\a~:';~
J
IFI-IF
IFM ~ls rrlEIR
.. 1..
'F" 1IK~
N!I IAI'
T1i
'F
iF
F
F
'".

~

"Arlrli,i';n.1 A,

'29

I':"~

I~
i~

Key Field
Starting
Location

Device

I~

i

Symbolic
Device

~

Extent Exit
for DAM

Number of Extents
Tape

Core Index

~~n;:

[~

~

K

30 31 132 33 34 35 36 37 38 13914041'4243444546 !47 48 49 50 51 52 53154 55 56 57 58 59 160 61 62 63 54 65 66167 68 69 170171 72 73 74

9b

IMIF~IUll

q~

IMII=' ~Iu~

-

f1l
~

...

--

qf.,

MF Irlull

1=;'\

91,

M~ 'rill:'

~:.I

,/-

,

I'

Note: On disk systems, the files shown here might be on different devices, such as disk or console.

2-24

~

Continuation Lines

IJ

tA I, 01 6! S! LI 91 9! 111 £! t9 19 09 69 99 L9 99 99 vs t9 t9 19 09 6v 8v Lv 9v 9v vv tv tv Iv OV 6t lit Lt 9t 9t vt tt tt It ot at at a 9t 9t vt tt t! It Ot 61 81 LI 91 91 VI tl tl II 01

Figure 2-29. Two Ways of Specifying that

~~~~;n~:;r~~~IOW

Name of
Label Exit

All Records in All Files Must be Processed Before the Program Can End

6 8

L' 9

S v

ttl

Review 2

)
1.

A sales analysis report is to be group-indicated by salesman number as shown on
the print chart below (GX20-1776) ...
The fields on input file records are arranged as follows:

Positions
1-2

Salesman number (last two digits of the three possible)
Amount of sale
Customer name
Salesman number (first digit of the three possible)
1 identifies the record type

3-8
9-23

30
96

Fill in the input specifications forthis program choosing your own file and field
names.

i
~

II

PAGE _ _ _ __

:

: - Fold back 01 dolled lino.

DATE _ _ _ __

I

Fold in 01 dOlled lino.

I
NOTE: Dimension!

Exact measurement

)

with a ruler rather t

111 11 111 111 111 111 111 11 1111 1 I

! 2 2 22 23 3 333 333 33 44 44 44 44 445 555 55 55 556 66 66 66 66 67 777 77 77 7 7 I I I II 18 181 119 989 99 99 990 00 00 000 001 111 111 111 22 22 2 2 2 ;
156 7 I 801 234 517 19 01 23 45 67 190 1 23 45 67 890 1 2 34 56 78 90 1 23 45 67 89 01 23 45 678 90 1 23 45 67 890 1 2 34 5 I; 7 890 1 23 456 789 01 2345

6,

I

~L IEl~ IA\'j~ ILlY

IC;A LIESM N

IS
lU

IX~)(X

'/.. IX

11417

I}(,IX IX~ .~D(

I

i
I

1)1,1)( X~ • lXl)(

~

(t fit II

X D( ,IX XIx. Ix 0<

~

("" ItJIf ( ~b"

01- ~I.,::; I~ Isllo 'r,

1..-'fIO !a)

--....,

j

Review 2

2-25

2.

A large warehouse requires a weekly report showing the quantity of each item in
stock. Three types of records are found in the file for every item in stock:
a. In Stock, which records the quantity in stock at the beginning of the week. This
record must be present, and there can be only one per item. It is identified by a
a in column 96.
b. Receipt, which records the quantity brought into the warehouse. This record is
optional. There may be several per item. It is identified by an I in column 96.
c. Issue, which records the quantity shipped out of the warehouse. This record is
optional. There may be several per item. It is identified by an 0 in column 96.

ITEMNO I DATE I INSTOK I
I
I
I
1 2 3 4 5 6 7 8'9 10 11 12 13 14 115 Iii 17 18 19 20 21 ~2 23 24 25 26 27 282930 3i
INSTOCK Record

ITEMNO

I DATE I

SHIPIN

I

1 7 3 4 5 6 7 C19 10 Ii I~ 13 14115 IS 17 IS 19 20 211.2 23 24 25 La 27 28293031

RECEIPT Record

ITEMNO
.1 2 3 4 5 G 7

I DATE
I
81 ~

lOUT
I

I

I

1J 11 11 Il 11115 16 17 18 i9 20 211222324252627282930 31

ISSUE Record
/

The records are grouped according to item number. All records of one item number must
be in the order listed previously. Using the information given, write the Input specifica-.
tions which are necessary to:
a .. Check the sequence of the records in each group.
b. Prevent halting if unwanted or unused record types are read.

2-26

3.

)

Rewrite the Input specifications shown below using field record relation entries. _

RPG

IBM

GX21 "9094

INPUT SPECIFICATIONS
1

Program

I

Record Identification Codes

-!]

~

£" ~

~

.8

I-

]

r-f-r-§
o R z

f;;:~'o

7

8

1'5

4

1

lip lAir IF IT I, 11=

2

I~

~

Position

~~~

!

~

-

Position

;;

Position

~~
~u

~uO

!i ~

From

Field Name

g

~

'~

Ociio::

.3

0

IN IS

11~

I

I,

hid

I

~

1,,1(1 I~I~ Iptr

5

I

~
11~
I~~

I

7

I

a

8

If*

~IT 1",lrlk

IAlllln 1~lo IN In Inl~ In :J IrlT Irlr 1,,15
IN I;
I~~
11 ~I"

a

9

I

1

a

I

17

11

I

lLJ

1 2

I

Il.

1 3

I

133

1 4

I

1

...

"

IBM

If I~

1 ..

1-

0

~~
u.u.
.~.~

"§ .~

"'.s=
::;;u

-'"

.!l!

a:
"0'>

c: c:

.3

IIIIII

£

! ~~ !
g ~ :~
~.!

::;;u

"

ii:

0

~

:9-0 ~

~

iI

]
e

0
0

.~ ~
LLLL

~u

]

Zero
Plus Minus or

Blank

"0

0;

u::

12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 5, 52 53 54 55 56 57 58 59 60 6, 62 63 64 65 66 67 68 69 70 ;, 72 73 74 '

.0 1

11

0

~

0

"0

Field
Indicators

Field Location

:?-.~

~

75 76 17 78 79 80

[]JOf_ ~~~;~f:ation I I I I I I I

c.

~

Filename

Line

2

UIM 050'

~1

9b rl1
BI~
1

13
19

Is N t"'l11 I I
2(1. 5 1 Is ~I"II' 1 ,

I~~ t1l C\ /
1

92 AMlr
123 rlJ Ie l

'AIM

/

I
I
I
I
I
I

lL 'L OL 69 89 L9 99 59 l>9 C9 19 .g 09 65 85 L5 9S SS tS CS lS IS OS 6t 8t Lt 9t St tt Ct It It Ot 6C BC LC 9C SC tc CC lC IC OC 6l 8l Ll 9l Sl tl El II Il Ol 61 81 LL 91 SL tl CI II II 01

The two fields which make up the salesman number should be assigned the same
control level indicator to indicate that both fields are to be considered as one.
The split control fields must be specified on two adjacent lines. Since the first
digit of the salesman number is in position 30, this single digit field should be
specified before the field containing the last two digits of the number. The
program determines the order in which the digits areto be arranged by the order
in which the fields are specified.

2-28

6

8

L

9

S

t

C l

I

2.

RPG

IBM

GX2' -9094 U/M 050'
Printed In U.S.A.

INPUT SPECIFICATIONS

Internallonal BUSiness Machine Corporation

1

Program

Date

Programmer

Record Identification Codes

s

I

i
~

Filename

Line
0-

>

I-

~
5

r--r-

o

R

1

3

2

~

c.

~
2l

§

Z

1'0

0
-;;;

ki

Position
"0

j

~ @j

Z

U

U

t-;;:~ro

Position

- e

=
e ~
~~6

-~

0

0;

Position

~

0

o U~

Z

Ii;

From

Field Name

Q.

To

~

~

1

If{ IEIr hlR IDS

a

2

I

o
a

3

I

4

I

o
o

lL

5

I

6

I

~
lL~

a

7

I

o

8

I

11.

S III/ Il:MIN

o

9

I

19

1 0

I

11 L/ IO!A irE.
12 I Oilc; lUll PiT N

11

I

9 '0 "

qlq

Nis

~I-. INrir

QI~ !/lI'"

,..

r/'.I, AI~ ml?

qh

q~

rlf"'

IV

CLL-4

1 4

I

1 5

I

I
I

2 0

I

u:

{3

IT II It. '/ iN

-

IDlA. IrF
12.1 (2jlriN lST hK

I

qb rlr\
~
~l5

1 8

-.;

Zero
Plus Minus or
Blank

lLj

11~
r/~~

l1.

1 9

~.2

:;u

"0

'"'II

I

I

:£

Iqb IF[ lEt D5

11
a5LL 1 tnll.

I

I

-5

"0

Iqlh f..jrf"l

1 2

1 6

!

:!i

'2 '3 14 15 '6'7 '8 '9 20 2'222324 2526 27 28 29 30 3' 32 33 34 35 36 37 38 39 40 4142 4344454647 48 49 50 5' 52 53 54 55 56 57 58 59 60 6' 62 63 64 65 66 67 68 69 70 71 72 73 74

1 3

1 7

~

.3

0

0

.5 .£ g'
~

4

8

0

.~

IIIIII

Field
Indicators

c

u.u.

0

7

75 76 77 78 79 80

~~~;~f:"ion I

of _

!JJ8

-.;

3

6

2

CD

Field Location

~

~

f---

)

Page

8 IrlT iEM if\J "
114 lOlA IrF
11 I O!~i,

IT

I
I
I
I
I

j

ZL IL OL 69 89 L9 99 59 >9 e9 Z9 19 09 65 as L5 95 S5 .S es zs IS OS 6. a. L. 9' S••• e. z. I. O. 6e 8C Le ge se

.c

ee ze Ie oe 6Z al

a

9l Sl . l el II Il Ol 61 al LI 91 SI ., el II "01

6

a

L

9

S

•

ell

Any alphabetic sequence entry must be entered first to catch all record types not
being used for the program. This prevents halting when an unused or unidentified
record is fo.und in the input file. The three record types being sequence checked
must be assigned sequence numbers in ascending order with the INSTOK record
first, the RECEIPT record second, and the ISSUE record third. Since there is only
one INSTOK record per group, a 1 must be entered in column 17. This record
must be present so column 18 is left blank. Both of the remaining record types
require an N in column 17 and an 0 in column 18. They are optional, and there
may be more than one per group. Any record identifying indicators (01-99) you
choose are correct.

Answers To Review 2

2-29

3.

RPG

IBM

GX21 ·9094 , U/M 050'

INPUT SPECIFICATIONS

Printed in U.S.A.

Intern~t,onal Business Machine Corporation
1 2

Program

Page
Date

Programmer

I

i
&

Filename

Line
0.

>

~
4

0

1

5

6

~

r-r-r-~
o R z

f-

3

Record Identification Codes

~

~

I----

'7

f-;:'Nfo
8

2

1

~

Field
Indicators

Field Location
3
c:

~·o

0

~

Position

~~l
z u

"E

~

U

Position

~

~ 12 ~

~~c5

ii
0;
Position

~Q

~§

Field Name

.;);

0

~~ ~

To,

From

~
'2

~~~

Q

lIP AIY IFI IE INls
h'R

11 Cl
12.(l

1

Ir C

0 3

I

~IR

l~(l

.1

~rr

o

4

I

2

1.1111 ~IE ,: II< IN""

o
o

5

I

Lj

1!l11L Ii

6

I

b

i"'lll.l~

o

7

I

o

8

I
I

"

2.i4 ",\A MiE

~~

"1,7

l~

11"1IL

I

1.0'1

2. ILl

1 2

I

3fl

1 3

I

1 4

I

1 5

I
I

7

I·

I

8

I

1 9

I

2 0

I

"'IN

.~I~ 12. PIA

I

I

fJlT

l~

1 0

6

~

.":J. fl

11

I

°

:2~

~

]

u.u:::

~

~

-£ :~

"C

.~

"ii

.s~

~

Zero
Plus Minus or
81ank

~6 ~

J Ir'R

I

9

E°

9 10 II 12 13 14 IS 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 6364 65 66 67 68 69 70 71 72 73 74

0 2

o

75 76 77 78 79 80

[TIOf;...... ~~~;:f:.tion I I I I I I ·1

I-

Y IR~rr

NA Mlf
l:.

1fo\f"1~

NA ME

~1.3 IU-I R~ l\.IJuln

IL Il
lL 1.1

11 tl
I~
I:J ft

I~H~
I~~

I~(lj

I
I
I
I
I
II 1£ O£ 69 89 £9 99 99 ~ £9 19 19 09 69 89 £9 99 99 ~9 £9 19 19 09 6~ 8~ £~ 9~ 9 ••• £~ l~ II> O~ 6£ 8£ ££ 9£ 9£ >£ ££ l£ 1£ O£ 6l 8l

a

9l 9l ~l £l II Il Ol 61 81 £1 91 91 ~I £1 1I II 01

6

B £

9

9

~

£

l

I

Because these record types contain common fields, the OR relationship may be used
to describe them. However, since not all fields are common to all record types,
field record relation entries must also be used. All common fields-WEEKNO,
EMPNO, and DEPT-are described first. The NAME field, although found on all
record types, is in different locations. Thus, it must be related to all record types
by specifying it and its end position three times and using the record identifying .
indicator in columns 63-64 to indicate the record type with which it is associated.
PAYRAT is found in only record type 10. Thus 10 is placed in the Field Record
Relation columns (63-64). DEDAMT and HRSWKD are related to the record type
on which they are found in the same way. Remember that all fields related to one
record type must be grouped together.
4.

An external indicator (U1-U8); 71-72; File Description.

/'

2-30

5.

File Description Specification

-

File Type

F

Mode of Processing
Length of Key Field 01'
of Record Addre .. Field

File Designation
End of File

Record Address Type
Type of File
Organization
or Additional Area
Overflow Indicotor

Sequence

Filename

File Format
Line

8-

~

g

3

4

5 6

e~
~e

e

g~

c~
wc
W

K

Option

l!:.
~
a:

~

Entry

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 28 27 28 29 30 31 32 3334 35 36 37 36 39 4041 42 4344 4& 48 47 48 49 50 61 52 53 54 65 56 57 68 59 60 81 62 83 54 65 56 67 68 69 7071 72 73 74

o

5

~

Block
Length

File Addition/Unordered
Extent Exit
for DAM

SF

F

~b

J:

qlc

rtF Ie Jl
r-\J:.'~ 12

,

F
F
~L

)

IL OL 69 89 L9 99 99 \>9 £9

~9

19 09 69 99 L9 99 99 \>9 £9

~9

19 09

6~ 8~ L~ 9~ S~

»

£~ ~~ I~ O~

6£ BE L£ BE !it K tt

~t

1£ at

u u

L~ 9~ !I~

~z £z ~z I~ O~

61 81 LI 91 91

~I

£1

~I

II 01

6

8

L

9

9

~

£

~

I

In the example above, TRANSACT is specified as a combined MFCU file because it
isto be both read and punched. An E is entered in column 17 for this same file to
indicate that the program should end when all TRANSACT records have been
processed.
If you have a disk system, however, TRANSACT could be a disk update file (U in
column 15). NAMADD would probably also be a disk file. An E would still be
entered in column 17 for the TRANSACT file.

)
Answers To Review 2

2-31

/'

2·32

Chapter 3. Controlling Printer Output

)
CHAPTER 3 DESCRIBES:
RPG II overflow and fetch overflow to control page formatting.
RPG II fetch overflow object program cycle.
Aligning printer forms.
Editing with edit words.
"Using the special RPG"II word, *PLACE, to print duplicate information.
Dual printer files.

BEFORE READING THIS CHAPTER YOU SHOULD BE ABLE TO DESCRIBE:
The RPG II object program cycle for overflow.
Function of RPG II indicators.
Using edit codes to punctuate numeric data.

)
AFTER READING THIS CHAPTER YOU SHOULD BE ABLE TO DESCRIBE:
RPG II overflow and fetch overflow.
Effects of fetch overflow on the RPG II object program cycle.
Aligning printer forms.
Using edit words.

Coding for the Dual Feed Carriage Feature on the IBM 5203 Printer and coding for
Dual Feed Tractors on the IBM 2222 Printer.

Note: You can use the review questions contained in Review 3 at the end of this
chapter to test your comprehension of each topic in the ch~pter. Questions are
grouped according to the topic to wh ich they apply. Answers follow the review
questions.

)
Controlling Printer Output

3-1

INTRODUCTION
The most important part of any RPG II program is the
result-the output. This chapter describes the RPG II coding necessary to format and punctuate printed output to
make it easier to read and understand. Methods are also
described for duplicating information on the output record
and using dual printer files to print two rep,orts in the same
program.
Using the printer, you can create a report consisting of individual lines (records) recorded consecutively on stock
paper. You may also use it to record information on your
own preprinted forms, such as on bills, invoices, and checks.
Regardless of the paper or form you are printing on, you
are always interested in obtaining a report that is neat and
readable. This means that the format of the report and
data on the report must be considered when planning the.
program.
RPG II coding for the different printers available on ,
System/3 is nearly identicaL Differences in coding are
noted. The available printers are:
•

IBM 5203 Printer (Model 10)

•

IBM 1403 Printer (Model 10 Disk System and Model 15)

•

IBM 5213 Printer (Model 6)

•

IBM 2222 Printer (Model 6)

USING OVERFLOW AND FETCH OVERFLOW TO ,
CONTROL PAGE FORMATTING
RPG II performs automatic page formatting. With standard
66 line forms, it leaves five blank lines at the top of a page
and six at the bottom. (Six lines are printed per inch; eight
lines per inch are also possible.) However, automatic page
formatting may not always meet your needs. If you want
control over page formatting, you can ,use an overflow
indicator (OA-OG, OV). For instance, assume that at the
end of every month you prepare an inventory report which
consists of a list of the quantity of all ite~s in stock by
product class. Items are listed by product class, and each
product class should start 011 a new page (Figure 3-1).

3-2

Suppose the heading were to start on line 11 of each page.
To have an equal margin (ten spaces) on top and bottom,
line 56 should be the last printed line on the page (assuming 66 lines per page). For this report, you must use an
overflow indicator to control page format.

,/

Overflow Indicators
Overflow indicators, like other indicators, are used to do
two things:
• Signal a certain condition.
•

Control when specific operations (including those whicr.
control page format) are performed.

For example, in the monthly inventory report, items in
stock are listed by product class. 'The report consists of 46
lines per page (starting line is 11 and ending line 56). Some
product classes are going to have more than 46 different
items in stock. ' 'Forthese classes, additional pages (overflow
pages) are required to list the items.
Normally, the overflow line is the last line you want to
print on the page. For this report, the overflow line would
be line 56. When this line is printed, the overflow indicator
(if one is assigned) is turned on to signal that the last line
you wished printed on the page has been reached.
'When the overflow indicator is on, you know that the overflow line has ~een reached. At the end of the page, operations, such as 'advancing to a new page (the overflow page)
and printing headings on the new page, can be performed.
By assigning and using overflow indicators, you can print
special lines at the bottom of the 'page and at the top of the
new page. Because you do these operations only when the
overflow indicator is on, you will have to condition these
operations by the overflow indicator.

./

)

CLASS
,00124

ITEM NO

DESCRIPTION

46732J1
63241B1
43151CK

SWEATER, V·NK, SZ 32
SWEATER, V·NK, SZ 34
CARDIGAN, SZ 36

ON HAND

Line 11

10
16
17

IN STOCK AS OF 10/30/71

-

-

-- --

-

Line 56

-

-

-

CLASS

ITEM NO

DESCRIPTION

00125

54321K4
56422K4
57381J4
58324B1

T·SHIRT,
T·SHI RT,
T·SHI RT,
T·SHI RT,

WH,
WH,
WH,
WH,

SZ
SZ
SZ
SZ

-

-

---

-

ON HAND
30
32
40
42

Line 11

11
14
15
8

Line 56

IN STOCK AS OF 10/30/71

)

CLASS

ITEM NO

DESCRIPTION

00126

67341B3
67432B3

WOOL SOCKS, BL 10
WOOL SOCKS, GR 10

IN STOCK ASOF 10/30/71

Line 11

ON HAND
11

-

9

-- Line 56

Figure 3·1. End·of·Month Inventory Report

Controlling Printer Output

3·3

name can be used here. Columns 15-22 contain the entries
for report formatting:

Specifications for Using Overflow Indicators
You must specify to the RPG II compiler how reports
should be printed. To tell it what to do, you make ·Iine
counter, file description, and output-format specifications.

•

Columns 15-17: Place in these columns the number of
available lines per page. Your page can contain a maximum of 112 lines . .The inventory report uses standard
" 11 'inch paper, providing 66 lines per page.

Line Counter Specifications
• Columns 18-19: Put the letters FL in these columns to
show that the previous. speCifications gave form length.

Line counter specifications, found on the bottom half of
the Extension and Line Counter sheet (Figure 3-2), are used
exclusively for defining the number of lines you want'
printed on each page.

•

Every time you use an overflow indicator to control foro'
matting, you should prepare line counter specifications.
Otherwise, a page length of 66 lines will be assumed with
line 60 as overflow line.

• Columns 23-24: Enter the letters OL in these columns
to show that the previous specification was the overflow
line.

Figure 3-3 is a sample Line Counter sheet for the inventory
report. Columns 7-14 are for filename. Only a printer, file

RPG

IBM

Columns 20-22: Enter in these columns the number of
. the overflow line, when you want the overflow indicator
to be turned on. In the exaiTlple given, it was 56. You
can use any number from 1-112.

Notice that columns 25-80 are 'not used.

Form X21·9091
Printed in U.S.A.

EXTENSION AND LINE COUNTER SPECIFICATIONS

International Business Machine Corporation

1. 2

Program
Programmer

75 76 77 78 79 80

Page [ [ ] of _

Date

.

~~;~;~f:ation I

IIIIII

Extension Specifications

E
-

Number
of

Number of the Chaining Field

Table or
Array Name

To Filename

Line

Entries
Per
Record

From File~ame

3

4

0

1

o
o

3

5

,/

Record Sequence of the Chaining File

6

7

8

Number
of'

Entries
Per Table

Length
'of
Entry

Table or
Array Name

j~

:§ ~ ~

~~i

or Array

Length
of
Entry

(Alternating
Format).

.§ 3

~~

Comments

1:

~~

~

~~&

9 10 It t2 t3 t4 t5 t6 t7 t8 t9 20 2t 22 23 2425 26 27 2B 29 3031 32 33 34 35 36 37 38 39 4041 42434445 46 47484950 5t 52 53 54 55 56 57 58 59 60 61 62 6364 6566 67 68 69 70 71 72 73 74

2

0

4

o
o

5
6

o

7

o

8

Line Counter Specifications

-

L
Line

Filename

0.

]

I-

~
3

1

4

10

4 ,

5 6

., E

.~

:l

...JZ

7

8

]

5

z

~1

.c

5

z

1:

~!

:J~

UZ

., E

]

~~

., E
'2UZg
2 ~ .=...JZ
::J

1:

., E

:J~

]

:::I

~.8

]

., E

.5 :::I
...JZ

9 10 11 12 13 14 15 16 t7 18 19 2021 22 23 24 25 26 27 2B 29 30 31 32 3334 35 36 37 3839 40 41 42 4344 454647

1

1 2

L

Figure 3-2. RPG II Extension and Line Counter Specification Sheet

3-4

~!

., E
2UZ§ .=...JZ
2§
UZ

~i:
~ §

uz

4a

]
.~

5

...JZ

~.8
~ §

UZ

.8
" E
.S:
::J
...JZ

~~
<: E

6~

"

11

~

~!;

E

6~

:J~

<: E

12

~ !! ., 1:E !.8
" E
2§
5 :5:i uz
:Ji 2
UZ

49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 7071 72 73 74

Line Counter Specifications

L

)

10

~

Li~"

3

•

1

7

8

12

~

Filename

6 6

.. E

1l

a 1l

:J:i

... z

1l

.. E
.S :J
..JZ

~ 5

1l ", 1lE ~1lE
5
z :3£ 6~
C

.0

.. E
.S ::::J
..JZ

II
.. E
5 :3:i

~jJ

~

UZ

~1l
~ §

UZ

1l

~~

2§

.. E

~:E

UZ

]
.. E
.£ :::J
..JZ

~~
C E
.2 ~
UZ

1l

.. E
.E ::I
..JZ

~~
~ §
uz

,5

f

..JZ

1l

]}j

E

C

6~

.. E
.S :::J
..JZ

~1l
C E

6~

1l

.. E
.S :::J
..JZ

~.8
Ii E
ti~

1l
.. E
:3i

~~
~ §

UZ

9 10 11 12 13 ,. 15 16 17 18 19 2021 2223 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 4546 47 4849 50 61 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

L~IR~INIT

1

11

Ib61~IL

1~lb~IL

1 2

Figure 3·3. Line Counter Specifications

File Description Specifications

You must assign an overflow indicator to the printer file
when you want to control the format of printed reports.
This is done by an entry in columns 33·34 of the File Description sheet (Figure 3-4). You may 'choose to enter any
of the following overflow indicators: OA, DB, DC, 00, DE,
OF, OG, or av. The one you choose, however, must be
used throughout the program: L mustalso be' entered in
column 39 to indicate that li,ne counter specifications are
used.
These two entries indicate to the RPG II compiler that it
"") should not provi,de automa, tic page formatti~g, ~ut should
format according to your specifications. If you do not
make an entry in columns 33-34 of the File Description '
sheet for a printer file, an automatic skip to line 1 occurs
on overflow.
'
. File Description Specification

-

File Type

F

Mode of Processi ng

~; '~'~cord Address Field
,Type
",

I

End of File
Sequence

Filename

Type of File

File Format

' Additional Area
IN IOverflow Indicator

Line

I!

Ij
!3

4

1012
1013
1014
10 Is
1016
1017
1018
1019
11 10

5 1617

8

9

' 0 " '2 '3

li'~II Iwl~11

IFi.- lAIR Infi

II

IFlp IRII INh"
IF

Iri

Symbolic
Device

Device

I;;)

Block
Length

Record
Length

I:)

1~li~ i~ j"I'

Ii
I~

File
Number of Tracks

Extent Exit
for DAM
Name of
Label Exit

Tape
Core Index

r~n'in""i~n I

~

'n,

Starting

I";:::

Location

2' 2: 2: 124 25 26 27 128129 30 13,

IMIF!r

I., .,

.2.3

so

;~

I~

IK
434.4546 147 4S 40 60 61 52 1,,1 .. 66 66 67 68 60

3637 313 139140

~~~;:

65 166 67 168 69 170171 72173 74

lJl1

11 Ipll1 [It-J rrlE.l~

IF
IF
IF
IF

Different device names could be used here,
depending on your system configuration
and model. The device name for the Model 6
printer would be TRACTR1.

IF
IF
IF
IF

ZJ ,

0' 69 89 L9 99 59 l>9 £9 Z9 '9 09 69 89 L9 9S 59

os

£9 ZS 'S 09

6~ 8~ L~ 9~ 5~ ~ £~ Z~ ,~ O~

6£ 8£ L£ 9£ 5£

~

££ Z£ ,£ O£ 6Z 9Z

a

9Z 5Z

~Z

£Z ZZ 'Z OZ 6, 8, Ll 9, 5,

~,

£, Zl " 0 ,

6

BL95~£Z'

Figure 3-4. Assigning an Overflow Indicator to the Printer

~
Controlling Printer Output

3-5

Preventing Records From Printing Over the Perforation

Output-Format Specifications

\

\

Suppose yourpr'ogram prints severai detail and/or total
'records per program cycle as shown in Figure 3-6. In this
case, the overflow indicator could be turned on:

When RPG II handles overflow, pages are advanced automatically. When you handle overflow, you must specify
that forms should advance. This is done by specifying a '
skip to the first printing line on the page. For the end-ofmonth inventory report (Figure 3-1), this would be a heading on line 11. Figure 3-5 shows the correct specification
for forms advancement. Remember to make a skip specification on a line conditioned by the overflow indicator
, (Figure 3-5). If you forget, a continuous listing will be the
result.

1.

When the detail record is printed.

2.

When anyone of the total records is printed.

If overflow occurs when the detail record is printed, all
total lines will also be printed before forms advance, provided a level 3 control break has occurred (L 1-L3 are on).
Remember the specification to skip to the next page is on
the heading line conditioned by. the overflow indicator.
This heading line is reached only after total records are
printed.

When the printer reaches the end of a printed page, RPG II
also allows you to ignore that the end of the page has been
reached and continue printing. You do this by assigning an
overflow indicator and never using it to condition output'
files. Lines will be printed, from the top line to the bottom
line of each page, even over the·perf~ratiori. If you do not
want this to happen, remember to use an overflow indicator
to condition the output operations which are to be done
when the end of the page is reached.

Assume that line 58 was specified as the overflow line for
this program. Assume also that the detail record printed on
the overflow line and that a level 3 control break occurred
when the next card was read. One page of the report would
look like that shown.in Figure 3-7. Because all total records are printed before overflow is sensed, the last total
record is printed on the fourth line of the next page. One
total record was even printed over the perforation.
What can you do to eliminate this situation? You could
specify the overflow line high enough on the page so that
all total records would be printed on the page after the
overflow line has been reached. For the report shown in
Figure 3-7, the printing of total records requires 14 lines (including spacing lines). Thus for the case where a detail record is printed on the overflow line, you would have to
specify line 44 as the overflow line to prevent printing
past line 58.

RPG

IBM

OUTPUT

GX21-9090

SPECIFICATIONS
I

0

S Space

~~
e -

~ ;

~

5

6

:1 L

~

Oi

t-

o

~

!!

~g

"Acto

t-

E

R

~

A~fo
7

8

Output Indicators

Skip

-. ~ ~

' Filename

Line

4

Page

Date

Programmer

3

~

0

0

z

z

Field Name

a:

Xl 0;

;3
'AUTO

5

~ ~

Positon
in
Output
Record

9 10 11 12 13 14 15 1617 18 1920 21 22 23 24 25 26 27 2B 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

olp Hit NT

o
o
o

2

0

3

0

12.l5

4

0

~~

0 5

0

511

0 6

0

71A

0 7

0

H
aiR

8J1

Zero Balances

Yes
Yes
No
No

Yes
No
Yes
No

to Print

:)

No Sign
I,
2

3
4

2

[I]
CR
A
B
C
0

75 76 77 78 79 80

of_

J
K

L
M

~~~;~f~cation I
X -

IIIIII

Remove

Plus Sign
Y = Date
Field Edit
Z = Zero
Suppress

Constant or Edit Word

;;:;
Q:

«%~~~~~~~~~~~D~~~~~~M~~DM~ro

71 72 73 74

IP

,.,v

~

Figure 3-5. Specifications for Forms Advancement

3-6

Commas

Ell

0

z

...'"

1(:;1

0 I

~

U/M 050'

Printed in U.S.A.

International Business Machine Corporation

Program

-

/

,,. I.

AI" c; I
, II T E.IM NO'
....
~' I",
K
1'" 1 "IN'

,:"

\~N

IHA !NO'
/

"

GX21·9090 U/M 050·
Printed in U.S.A.

SPECIFICATIONS

OUTPUT

RPG

IBM

International Business Machine CorPOrlltion

1
\

)

Program

0

~ Space

Output Indicators

Skip

@~
e -

~

-.. ~ ~
~]

Filename

Line

~ ~
to- 9 £9 Z9 19 09 69 ag L9 99 99 1>'9 £Y Z9 19 09 6~ 8~ L~ 9~ 9~

»

II

1"\1 IvlT "'IT Jg
£~ Z~ 1~ O~ 6£

8£ L£ 91: 9£

Ibl.z:;

~ ££ Z£ 1£ 0. 6Z 8Z LZ 9Z 9l ~Z £Z ZZ lZ OZ 61 81 L1 91 91 ~1 .1 ZI 11 01

6

8

L

9

9

•

•

Z

1

Figure 3-6. Several Total Records Per Cycle.

54 __________________________~______~J~O~E~B~R=O~W~N~__________4~09~.1~0~______________________~
55

~~ -------------------,--------------------1..:.:.:::::.:..:::.:::::...------------;;;:if;~~~:::~t~!
60 ________________________________________________________________________________

~

61

,

~

7~m

63----------------------------------------------------------~~~------------------~

~
I
65---------------------------------------------------------------------------------~1

66'
01
02

_______

_

______

_

~.eU2__

-

03--------------------------------~--------------------------------------------~

04

13,421.67

05---------------------------------------------------------~~~-------------------4\

06

---------------------------------------------------------------------------------~I

~--- -------------------------------------------------------------------~--------------------------------------~--~
Figure 3-7. Printing Over the Perforation
Controlling Printer Output

3-7

Page of GC21-7567-2
Issued 21 December 1979
By TNL: GN21-5709

for the usual time. Figure 3-9 shows the two additional
times when operations conditioned by the overflow indicator may be performed. (Remember that forms advance
at this time.)

This is not the best solution, however. Suppose overflow
was caused by the second total record instead of the detail
record. Only one more total line would be printed before
. forms advanced. Much of the page is not used in this case
since the last line is printed on line 50 (see Figure 3-8). As
you see, this is a very uneconomical solution since much
paper can be wasted.

During the regular program cycle, the RPG II program tests
only once to see if the overflow indicator is on; this occurs
imm~diately after total output. By using the fetch overflow specification, you can tell the computer to check if the
overflow indicator is on before it prints total or detail records. You do this by simply entering an F in column 16 of
the Output-Format sheet for any detail or total record.
When an F is encountered, a test is made before that line is
printed.

Fetch Overflow
RPG II provides you with a better solution for preventing
printing over the perforation than the one previously discussed. This solution uses the RPG II routine known as
fetch overflow. Fetch overflow specifications allow you to
alter the basic RPG II overflow logic (see Overflow Indicator, Chapter 1). You can cause forms to advance at the
time total or detail records are printed, instead of waiting

~

If the overflow indicator is on when the test is made, all
operations conditioned by the overflow indicator are
immediately performed. These operations usually include
forms advancement and the printing of headings. In order
for the line to be printed, all other indicator conditions
tested for on the same line as the overflow indicator must
also be satisfied.

~

~

-

-

}

78.45

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

I

168.17

I
755.67

\

4,989.72

~(

13,421.67

J

I

I

I
--

------------ - - - - - - - - - - -- -- ---

-

-

Figure 3-8. Specifying the Overflow Line High on the Page

3-8

~

-

-

-(
J

)

•

•

/)i\1f overflow indicator \{

i!!!i~!:ison, perform output\\\\\

•

:fit (total, heading, detai/}).
';:':;' conditioned by the
.' '.: overflow indicator

·'i ......··.·.C

\
.'.

Turn off control
level and record
identifying
indicators
Set off overflow indicator
if performed this cycle;
leave on if fetched during

•

·~·••·.·.···.perlorm d:,:::::::~::tions or
. _ " " Turn on overflow indicator if overflow line
is printed

Turn on
resulting
indicator

•

•
Perform detail
calculations
Change in
control field?
Yes, turn on
control level
indicator

Move data into
processing area

)

•

Is overflow indicator on?
If so perform all operations
coriditioned by the overflow
indicator and turn overflow
indicator off

•

Perform total output:
Turn on overflow indio
cator if overflow line

•

•

Perform total
calculations

l.. •

is pri;.ed••••••••••

\/:~

turn off the overflow.:::;.
':{\:Jndicator "::/::::::::::::;::}}irri!::/i?
···:::':::.;.;-;.;::::::::::)))H}i::::::::

Figure 3·9. Logic for Fetch Overflow

Controlling Printer Output

3·9

Figure 3-10 shows two fetch overflow specifications (lines
07 and 09). Consider how these operations are performed.
When it is time for the specification in line 07 to be done,
a test is made to see if the overflow indicator is on. If it is
on, the overflow routine is fetched; this causes the following operations to be performed.

1.

All total lines conditioned by the overflow indicator
are printed.

2.

Forms are advanced' (provided a skip to a new page
has been specified in a line conditioned by the overflow indicator).

3.

Heading lines conditioned by the overflow indicator
are printed.

4.

The overflow indicator is turned off.

5.

The record specified in line 07 is printed.

Another test is made to see if the overflow indicator is on
because of the specification (F) in line 09. If line 07 causes
forms to advance, the overflow indicator would not be on
at this time. The total record specified in specification line
09 would be printed normally.

RPG

IBM

OUTPUT

International BUSiness Machine Corporation

Program

Programmer

Oal.

o

~ I~ Space
Filename

Line

3

4

5

!
~
6

Field Name

n!~

ADD

7

8

9 10 11 12 13

Output lI,dicators

Skip

~*D

I~

'AUTO
32 33 34 35 36 J7

20121

Lip

~Il

Figure 3-10. Fetch Overflow Specifications

However, if the record specified in line 07 were printed on
the overflow line, the overflow indicator would be on and
the specification in line 09 would cause the overflow routine
to be performed.
Consider again the example as shown'in Figure 3-6. When the
detail line was printed on the overflow line, all total lines
were also printed before forms advanced. As a result, printing occurred over the perforation onto the next page
(Figure 3-7).
What records should most logically be printed on an overflow page? Your answer is probably all those records that
printed on or over the perforation. It would indeed be nice
if all total records could be printed on the next page when
a detail record was printed on the overflow line (see Figure
3-11 ).
If the program knew before it printed the first total record
that the overflow line had been reached, forms could be advanced before the total records were printed. By specifying
an F in column 16 of the first total specification, you can
tell the program to check to see if the overflow indicator is
on. If it is on at this time, forms will advance before total
records are printed. Specifying an F in column 16 of the
first total specifications will cause all total records to be
printed on an overflow page.
Would an F for the first total line take care of all situations?
S,uppose that overflow did not occur until the first total record was printed. The remaining total lines, having no fetch
overflow specification in column 16, would not cause the
program to check to see if the overflow indicator was on.
Thus, they would be printed on the same page (Figure 3-12).
Counting the spaces, this would mean the last print line
would be eight lines beyond 58 (the overflow line) or on
line 66.
If this is feasible for your report, you could allow printing
on line 66. If not, you could have the overflow indicator
checked at the second total line. In this case, if the first
total line caused the overflow indicator to turn on, the secondtotal line would fetch the overflow routine. Thus, the
last total records would be printed on the overflow page.
How can you determine on which line to place the F, that
will fetch the overflow routine (provided the overflow indicator is on)? You should study all possible overflow
situations. By counting spaces and lines, you can calculate
what would happen if overflow occurred on each detail and
total line. This is essentially the method used in the previous
discussion.
,/

3-10

-

)

---

---

~

_'\

'"

l

JOE BROWN

54
55
56
57

409.10

j

78.40

"';';';';::::::::::-:"

iiOVerfIO:,
'::{:::line

168.17

58

59
60
61
62
63
64
65
_66_ _ _ _ _ _ _

\

\

- - ------------ - - - - -

Page 2

~

-I

755.67

I

4,989.72

)

~

-- - -----

Figure 3-11. Printing Total Records on the Overflow Page

./

---

/

13,421.67

~.

-/ '

168.17

____________________________________________________________________
61
62

~7~~§1

_______

~

4,989.72

63---------------------------------------------------------~-----------~

64

65--------------------------------------------------------------------------~

66

)

Figure 3-12. Printing on the Last Line on the Page

Controlling Printer Output

3-11

Page of GC21-7567-2
Issued 30 June 1978
By TNL: GN21-5616

ALIGNING FORMS
Regardless of the type of printing forms you are using, it is
always necessary to have the forms aligned so that printing
is done on the correct line. If printing occurs above or below the line, your report looks messy and is hard to read.

When fields are printed out according to basic specifications
they appear exactly as they are inside the computer. This is
shown by the following examples: "
Type of Field Field Before Printing
Alphameric

How can you be sure the first line will be printed in the
correct position? You can align the forms in the position
you feel is correct. But you can never be sure until you try.
To try the alignment, the program must be executed; a
record must be printed. Suppose the forms are incorrectly
aligned, and as a result, the first printing line is incorrectly
positioned. In this case, you can stop the computer and
realign the forms so that, hopefully, the second line will be
correct. This can go on for several tries, however. I n the
meantime, the first few records printed on the report will
have been incorrectly aligned.
RPG II has the facility to print the first line repeatedly until
forms are aligned properly. This eliminates printing the
first several lines of a report before correct forms alignment
is attained. The use of this facility requires two specifications:

1.

An output line conditioned by the 1 P indicator.

2.

The entry of 1 in column 41 of the control card.

Field After Printing

JOHN T SMITH

JOHN T SMITH

004765K

004765K

Numeric

The alphameric field, when printed, is easy to read and
understand, but the numeric field is confusing. How should
it be read? What does the K mean? K is actually a combination of a digit and the sign of the field. But in this
form, the reader would have to guess what it says (see
Character Structure in Working With Data Structure for
more information).
Editing is the means by which data is made more readable
and understandable. Editing a field m"eans punctuating it
by removing the sign of the field from the rightmost digit
and placing it at the end of the field, adding commas, decimal points, minus signs, dollar signs, or any other constant
information.
Only numeric fields need to be edited before they are
printed. Notice the difference between the following
edited and unedited data taken from the same numeric
amount field:

When these specifications are made, the first line conditioned by the 1 P indicator is printed. All processing then
stops. The operator has time to reposition the forms if
necessary. When this is done, the operator has the option
of having the 1 P line printed again or of continuing processing. This he indicates by specific settings of the console

The edited amount field is certainly much more precise
and understandable than the unedited field.

switches on the processing unit. (See halt 1 P in the IBM
System/3 Models 8 and 10 Halt Guide, GC21-7540 for a
complete description of the alignment process.)

Methods of Editing

All space and skip entries specified for the 1 P line are performed when forms are being aligned. This should be considered in planning for forms alignment.
If spooling printed output on the Model 15, the 1 P forms
alignment option will be ignored and the user can request
alignment by means of the OCl PRINTER statement.

EDITING
Formatting a printed report is one way of making the report easy to read and understand. Formatting, however,
concerns only the spacing and arrangement of data on the
printed page. It does not concern the data itself. Data
must also be readable before the rep?rt can be understood.
Editing makes a field readable.
3-12

004765K
$476.52CR

unedited data
edited data

A field can be edited by two methods: (1) edit codes anu
(2) edit words. Several different codes are available. Each
code edits in a slightly different way according to a predefined pattern. All, however, remove the sign of the field
so that the rightmost digit will always print as a number.
(See Character Structure in Working With Data Structure
for more information.) The Y edit code is used for date
fields only.
Figure 3-13 shows the edit pattern for all codes. Choose
the code which will edit a field the way you want it to
appear and enter this code in column 38 of the OutputFormat sheet.

)

Sign For Negative Balance

Print Out On Zero Balance *
Domestic and
World Trade J
World Trade I
United Kingdom

Zero
Suppress

Commas

Decimal
Point

No Sign

1

Yes

Yes

No Sign

.00 or 0

,00 or 0

0,00 or 0

Yes

2

Yes

Yes

No Sign

Blanks

Blanks

Blanks

Yes

3

Yes

No Sign

.00 or 0

,00 or 0

0,00 or 0

Yes

4

Yes

No Sign

Blanks

Blanks

Blanks

Yes

Edit
Code

CR

- (Minus)

A

Yes

Yes

CR

.00 or 0

,00 or 0

0,00 or 0

Yes

B

Yes

Yes

CR

Blanks

Blanks

Blanks

Yes

C

Yes

CR

.00 or 0

,00 or 0

0,00 or 0

Yes

D

Yes

CR

Blanks

Blanks

Blanks

Yes

J

Yes

Yes

-

.00 or 0

,00 or 0

0,00 or 0

Yes

K

Yes

Yes

-

Blanks

Blanks

Blanks

Yes

L

Yes

-

.00 or 0

,00 or.O

0,00 or 0

Yes

M

Yes

-

Blanks

Blanks

Blanks

Yes

X **

)

Y ***

Yes

Z

Yes

*

**
***

Zero balances for the World Trade format are written in two ways, depending on the entry made in column 21 of the control card
specifications.
The X code performs no editing.
The Y code is used for date fields. It suppresses the leftmost zero only. The Y code edits a three to six digit field according
to the following pattern:

nnln
nnlnn

nnlnnln
nnlnnlnn
If a data field of six digits is packed on disk and the Y edit code is used with the data field, an error will occur. To solve this
problem, move the data field to another field.

Figure 3-13. Edit Codes

)
Controlling Printer Output

3-13

Page of GC21-7567-2
Issued 30 June 1978
By TNL: GN21-5616

For example, if you wish a field called AMOUNT which
has two decimal positions to be zero suppressed and punctuated with decimal points and commas (when needed) but
with no sign, you choose the code that will do this. The
chart in Figure 3-13 shows that two codes will accomplish
this-1 and 2. If you wish a zero balance to print, you
would choose the code 1. If you wanted blanks to print
when the field is zero, you would use the 2 code.

Depending upon its contents, the AMOUNT field, when
printed out, could look like any of the following (where
N is any number):

Using edit codes is a convenient way of editing. However,
the codes by themselves can't do everything you might
want to do.

The blanks between the first digit and the dollar sign are
the result of zero suppression. The dollar sign remains in
position 69; this is known as a fixed dollar sign.

$NNN.NN
$ NN.NN
$
N.NN
$
.NN

Often, it is desirable, as in writing checks, to eliminate these
empty spaces. There are two ways of doing this: (1) moving the dollar sign so that it is always next to the first digit;
and (2) filling the spaces with asterisks.

Punctuating With a Dollar Sign
Suppose you wanted a dollar sign to be printed on the report for the AMOUNT field. An edit code won't put the
dollar sign there. You will have to specify this in addition
to the edit code you are using.

Instead of having blanks between the dollar sign and the
first digit, you can cause the dollar sign to print next to
the first digit. In this case, the amount field would look
like one of the following:

According to the printer spacing chart (Figur~ 3-14), the
AMOUNT field is six characters long. It begins in column
70 and ends in column 75. However, the minus sign
would extend the amount field to column 76, as shown
in Figure 3-15 and Figure 3-16. The dollar sign, if printed,
should be in column 69. Line 11 in Figure 3-15 shows the
specification for editing the AMOUNT field by the edit
code J. This code is used so that negative values will print
with a minus sign (-) following the field. The dollar sign can
be specified as a constant ending in column 69 and must be
specified in line 12, the line following the edit code.

____________________________ PAGE ____- - - - DATE _______

TERS PER INCH, 6 LINES PER VERTICAL INCH)

1 23 45 67

.,

, 1 , 1

o,

(

$NNN.NN
$NN.NN
$N.NN
$.NN
A dollar sign that changes positions is known as a floating
dollar sign. It is specified by placing the entry '$' in columns 45-47 on the same specification line as the edit code
(see Figure 3-16). Remember that the fixed dollar sign was
specified by placing $ in columns 45-47 of the line following the edit code (Figure 3-15).

i

I

:-+- fold bock

I

I

01

:--

doH.d lin•.

I

I

,,

, , ,,

, 1 2 2 22 22 22 22 3 3 33 3 3 3 3 33 44 44 44 44 44 5 5 55 55 55 551 66 66 & 6 6& 67 7 7 7 7 77 7 7 71111 II 8 1111 1111 1111
9' '99
23 45 , 7 II 9 01 23 45 , 7 1111 0' 23 45 67 1111 0 ' 23 45 & 7 119 o , 2 3 45 & 7 1190 1 2 34 5 ' 7 II 90 , 2 34 56 7 II 90' 23 45 , 7 1111 01 23 456

1

2

,

3

Wl: E~ L'r'

,

I

4

5 tRIPP. I~IT

C;J!lL

5

i

II.I:E 1fT

6
7

I~'A

,

It: 5M AN
I

!

,•

,

X~ ~X
C l;.p T)

XX IXX

X.x )(X):

lXX ~. ~X(ff ~O 'tJfI 1,)

(it; 1(, J'jill

.!J}..

X

XD(

·XX

IT.ll

I

11
12

I

I

,

13
I

14

I

I

Figure 3-14. Printer Spacing CharvCEditing)

3-14

orr

!

10

15

:

. I

: I

I

I

,I : I

I

I
I

I

,

I

./

Page of GC21·7567·2
Issued 30 Ju ne 1978
By TNL: GN21·5616

)

RPG

IBM

SPECI FICATIONS

OUTPUT

Printed in U.S.A.

I

Program

I Programmer

I Oat.
:§

Space

~~ ~~
i~

Filename

~~ ~.::
E L
r;;:OO

!

E

*~"o
Op Rl NT E.R. III

~
3

4

o

I

o
o
o

2

0

3

0

4

0

o

5

0

o
o

6

0

7

0

o

8

0

. .0 9

0

I

0

0

I

I

0

2

0

"

n

I

I

Punch

I

I

I

I

I

I

I

I

Output Indicators

Skip

~~

Line

.

page[DOf

J

I

2

;

75 76 77 78 79 80

i

1 1 1 1 1

II

~~:;~f~ation 1

-

.!!o

0

-

I

GX21·909Q.·, UM/050'

internltional BUlineu Machines CorJ)orIdon

5

6

7

8

9

1

AL
~

~

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 2728 29 30 31 32 33 34 35 36 37 3839 4041 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

4

6

0

z

r;:'No

3

0

~

rr
.g

0

OJ

R

0

0

~ ~«

OJ

"Aro"D

t-

E

t

Ji

Field Name

I. I 1 1 1 I

1

--- -- ---

.

75 'A Mh

_.- .. t--_.

-S !:L

-

-~ .1.

-

- r- f - . - - - f--r-

- - - I-f-- .

- -...-

I.e, IAIL EL; MIA AJ'

--

AM IOU ~I J_

Ir

1/"1 IT A!L'

1ILJ I \ $/~
1

I··'

r- .

I'N T'

t-

The floating dollar sign is specified
by placing '$' in columns 45·47
of the same line as the edit code,

Figure 3·16. Floating Dollar Sign

Controlling Printer Output

3·15

Page of GC21-7567-2
Issued 30 June 1978
By TNL: GN21-5616

Punctuating With Asterisks

The telephone number and social security number are
entered in the record as one continuous number with no
dashes. Remember that fields will print out exactly as they
are recorded. Thus the telephone number will appear as
2820804. This.is rather hard to read. 282-0804 is much
better. How will you get the dash to appear?

To indicate that asterisks should fill the spaces caused by
suppression of leading zeros, place the entry ,*, in columns
45-47 of the same specification line as the edit code. If a
dollar si~n is to appear before the asteris~, it must be specified on the next line. With the specifications shown in Figure 3-17, the AMOUNT field, depending upon its contents,
could look like any of the following:
$NNN.NN
$*NN.NN
$**N.NN
$* * * .NN

A dash is a type of punctuation. So some type of editing
must be done. Can you find a code that will edit this way?
No, there is none available.
For this case, you will have to set up your own editing pattern. An edit word gives a pattern for punctuation. For the
phone number you need three digits, a dash, and then four
digits. You specify the edit word in columns 45-70 of the
Output-Format sheet. The word, like any constant, must
be enclosed in quotes. Figure 3-18, line 04, shows how the
telephone number field is edited: three blanks, a dash, and
four blanks.

Refer to the IBM System/3 RPG /I Reference Manual,
SC21-7504 for a more detailed explanation and further
considerations.

Punctuating With Dashes

Unless the social security field is also edited, it will print
out in one long string of numbers, such as 472446357.
Form the edit word to make the social security number
read: 472-44-6357. It should look like the edit word
shown in Figure 3-19, line 05 . .Notice that a leading 0
(zero) is included in the edit word in addition to the number of places required for the data. This prevents zero suppression when the SOCSEC field is edited.

What code would you use for the following job? A report
listing all employee names, addresses, telephone numbers,
and social security numbers, is desired. A file is kept on all
employees. Each record includes one employee name, address, telephone number, and social security number among
other things.

RPG

IBM

OUTPUT

GX21-9090

SPECIFICATIONS
1

Program

0

~

~!

f--Filename

Line

~~
Ii -6

~ ~

j
1

5

6

7

IN

It-IR

11-1

2

0

3

0

o

4

0

I",

0

5

0

~I~

0

6

0

0 7

0

0 8

0

0 9

0

1 0

0

1 1

0

1 2

0
0

;;:

0

Z

Z

121(ij~

r.IV
IIlp

12

hlv
Illp

a:

~ ~

0

z

~I

'AUTO

8 ~

~ ~

S>
End
Positon
in
Output
Record

Zero Balances

Commas

to Print

I

No Sign

CR

1

A

2

B

3

C
D

Yes
No
Yes
No

Yes
Yes
No
No

a:
-'

4

II

,-I- 1-1---

J
K
L
M

X =

Remove
Plus Sign

Y

=

Date
Field Edit

Z

=

I--- - f - - - f -

IAI~ au INIr ,I

1_ 1

1

1

1

Zero
Suppress

Constant or Edit Word

to

Ci:

'1\.1" IE l:

\
f-- f--

IK Iv lc;lQ I.

DE Ip IT

I~lc;

1011: loh IclT I

I

1511 \ IslA It 11=15 IMIA IN'
171; \ IA 1M", INIT' -I--- 1---1---!B~ \ iT It"IlT IAIL
1\1< II To fill empty spaces caused by zero
1715 \* 'I> suppression with asterisks, place ,*,
169 ll' "Ii in columns 45-47 of the same line
I

In

75 76 77 78 79 80

~Z~;~f:a1ion 1

of _

1--,- - 1--

3f3

~~-

2

IT]

40 41 42 43 4 4 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70

IblB

Figure 3-17. Punctuating with Asterisks

3-16

L

0

to

I"'I~

0

0

Jd

to

Field Name

8 9 10 11 12 13 1415 1617 18 19 20 21 22 23 24 2526 2728 29 30 31 32 33 34 35 36 37 38 39

o

1 4

Output Indicators

Skip

~~«

~~fAND

O~If(

1 3

Space

f;:ro'o

f-

3 4

Page

Date

Programmer

0

U/M 050'

Pnnted in U.S.A.

International BUSiness Machine Corporation

+-1--

as the edit code.

71 72 73 74

I

"

)

RPG

IBM

GX21·9090

SPECI FICATIONS

OUTPUT

I

Program

0

~ Space

t::0 ~
~~

Filename

~ ~

!

... cl5

0

I

5

3

o

4

0

5

n

"

1L

~

~

::t

o
A~'o
7

8

0

0

z

z

Field Name

z

v

Ifi

I~

0

"AUTO

~
~

Positon
in
Output
Record

Commas

Zero Balances
to Print

Ves
Ves
No
No

Ves
No
Ves
No

2

CD

75 76 77 78 79 80

of_

-

No Sign

CR

I

A

2
3
4

B

J
K

C
0

L
M

~;~;~f:.tion 1 I.

III

I I

X

:0:
Remove
Plus Sign
V = Date
Field Edit
Z = Zero

Suppress

0::

g

Constant or Edit Word

c:

9 10 11 12 13 14 15 16 17 18 19 20 2122 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

Op RI INrr 1= IR In

~l

11

a
a
a
a

0 2
0

6

~

~~

"A'D'D ~
R

~

4

Output Indicators

Skip

@B

Line

3

Page

Date

Programmer

-

U/M 050-

Pt-intedin U.S.A.

InternatIonal Business Machine Corporation

NA 'MIE

31!Zl

lAD nlR

.l\~

h-E IllE

Iblll

,

-

I

n

Figure 3-18. Edit Word for Telephone Number

)
RPG

IBM

GX21-9090

SPECIFICATIONS

OUTPUT

12

Program

Page

Date

Programmer

-

0

u: Space

Output Indicators

Skip

@~
t~

0-

~~

Filename

Line

1t

j

6

o

7

4

I

Op RI iN IT" IEIR

0

2

0

0

3

0

4
5

a
a

"

a

roo

At

"A '0 '0

R

0

CD

L

0

z

z

iil

;3

0

z

'AUTO

8

~

Positon
in
Output
Record

Commas
Ves
Ves
No
No

ru

:u

~

.....

@i

Zero Balances

to Print
Ves
No
Ves
No

CD

No Sign

I

2
3
4

757677787980

~;~;~f:ation 1 I.

of _

CR

-

A
B
C
0

J
K
L
M

IIIII

X = Remove
Plus Sign
V = Date
Field Edit
Z = Zero
Suppress

0::

g

Constant or Edit Word

c:

9 10 11 12 13 14 15 1617 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

3

o

~~«

CD

Field Name

A~ro

0

0

~

~Ji

!
5

U/M 050-

Printed in U.S.A.

International Business Machine Corporat,on

In

II

(211

NA 'MI~

131~
Lr;llt

lI\o nlR
irE IliE

Ibll7

I

I"nIr.le; .J:~

171'\

'bl

-

J

-

-

I

Figure 3-19. Edit Word for Social Security Number

Controlling Printer Output

3-17

Page of GC21-7567-2
Issued 21 December 1979
By TNL: GN21-5709

Punctuating by Leaving Blanks

RPG

SPECIFICATIONS

OUTPUT

1 2

A company has rather long account numbers. To make
them easier to read and handle, blanks are left after every
third digit when the number is printed.

nching
truction

Page

.

"-

ndicators

Is there a code that will insert blanks? No, again you have
to specify your own edit word. In an edit word, blanks indicate where the digits go and ampersands indicate where
blanks will go. The account field consists of ten digits.
The edit word shown in Figure 3-20, insert A, will put
blanks after every three digits.

1

Field Name

Ifi
1m
Positon
~

;9

0

z

'AUTO

~

in

Output
Record

[0

Commas

Zero Balances
to Print

No Sign

CR

Ves
Ves

Ves

1

No

Ves

2
3

A
B

No
No

No

4

~

of_

J

C

K
L

D

r"

Constant or Edit Word

il:

'7 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 I

A

-~I

~~
_C
~~

Punctuating by Adding Constant Information

For shipping purposes, the catalog department of a department store must know the weight of every item it sells.
The weight in pounds and ounces is recorded in a 6-digit
field. The last two digits are ounces, the first four digits
are pounds. When printed out on a report, the constants
LBS and OZ must be inserted. Otherwise, the data would
not be understandable. Again to do this, an edit word is
needed because no edit code will insert LBS and OZ.

IAr IrnINT

5~

wl~ IIG ~T

1::J7

wlE II r.. HiT

67

,
,
,

IF:

I(

I

~

f! Il IBis ~I~

If!h ~'

(]j £11 lAS E!I~

I~h ~'

I 'I

I I I

Figure 3-20. Edit Words

The printed field is shown on the printer spacing chart in
Figure 3-21. One space is needed between the digit and
LBS and between the digit and OZ. Two spaces separate
pounds from ounces. Remember in the edit word, blanks
are specified for digits, ampersands are specified for blanks;
and constant information is inserted where desired. The
edit word should be as long as the field shown on the printer
spacing chart. Figure 3-20, insert B, shows the correct edit
pattern for this field.

II

10, _ _ _ _ _ _ _ _ _ _ _ _ _ _ PAGE _ _ _ __
~ACTERS

OATE _ _ _ __

PER INCH, 6 LINES PER VERTICAL INCH)

I

I

: - fold back at dotted line.

:I

I

1
11 111 111 1 1 2 22 2 2 222 223 33 33 3 3 3 334 44 44 44 44 455 55 55 55 55 666 66 66 66 677 777 777 7 7 888 888 88 889 999 99 99 99 (
1 23 45 67 890 1 23 456 789 o I 234 567 89 01 234 567 89 o 1 234 56 7 II 901 23 45 67 89 01 2 34 56 78 90 1 23 456 7 8 90 1 23 45 67 890 I 23 45 67 89 (

1
2
3

i

4

5
6
7

I

XX XXIXX
i (

I
9
10
11
12
13
14

AI

i)(X ~X XI)(X

I!

~)(

I
I

i

!

)CIX

alS

XIX
~.

I~~,

I

Figure 3-21. Print Chart (Weight Field)

3-18

XX XX

)

Edit words can do all kinds of editing for you. They can
even be set up to do the same thing as the edit codes. All
you have to do is show where the commas, decimal points,
credit signs, etc. should appear. A zero is used to indicate
where zero suppression stops. For example in Figure 3-20,
insert C, the 0 shows where zero suppression is to end in
the WEIGHT field.
Edit codes are a faster and more convenient way of editing
than edit words. Therefore, edit words are normally used
only when edit codes alone cannot accomplish the job.

Editing and End Position
When specifying end positions for fields which are to be
edited, either by edit words or edit codes, be sure to allow
enough room for the edited field. If the field to be edited
is six characters long on the input record, do not allow only
six positions for it on the printed report. By the time the
field is edited, it may contain many more characters than
six. For example, the WEIGHT field which is to be punctuated with the constants LBS and 02 is only a 6-character
field on th,e input card. But when printed out after editing
it requires 15 spaces. Always specify an end position on
the Output-Format sheet (columns 40-43) that takes into
account the length of the edited field.

USING *PLACE TO PRINT DUPLICATE INFORMATION
Using *PLACE, you can tell the RPG II compiler to print
duplicate information. When you specify *PLACE on the
Output-Format sheet, the fields listed above it will be
printed in a different position on the same line. This eliminates much duplicate coding.
For example, assume that your distribution firm prepares
invoices on their data processing system. The invoice (Figure 3-22) sent to each customer consists of two parts: one
part the customer keeps, the other he tears off and sends
along with his payment. Many fields are common to both
parts of the invoice. For example, NAME and CUSTNO
(customer number) are printed on the first line of each part.
All fields in the fourth line of the report, except for the
description (DESC) fields, and all fields in the total line are
found in both parts of the invoice. The second part is almost a duplicate of the first.

)
NAME

CUSTNO

NAME

CUSTNO

AOOR
CITY

ITEM
NO·

QTY

PRICE

TOTAL

_J

AMT

TOT

ITEM
NO

OESC

QTY

PRICE

AMT

TOTAL TOT

Figur.3-22. Invoice Form

Controlling Printer Output

3-19

Figure 3-23 shows the printer spacing chart for the invoice.
What output-format specifications would you write to print
fields twice on the same line? You could define the field
and give the end position for it each time you wanted to
print the field. Figure 3-24 shows the coding necessary
using this method. There is an easier way to do this, however. This is through the use of *PLACE.

I

I

: - fold bock

DATE _ _ _ __

CTERS PER INCH. 6 LINES PER VERTICAL INCH)

i

I

J. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ PAGE _ _- - -

01

~

doH.d Ii ....

I

I

I I I I I 1 I 1 I I 2 2 2 2 22 222 2333333 33 3 :5 4 44 444 44445 55 5 5 55 55 51.11 I I 11111 7 7 7 7 7 777 7 7 I II I 11111 I II I 1 9 '
'9 " ' 9
I 23" 5 1 7 " 0 1 2 :5 4 51 7 II , 0 I 2 :5 4 5 1 7 II '012345 1 7 1 ' 0 I 2 345 17 II'
I 23 45 17 II' 01 2 :5 4 5171'0 I 2 :5 4 5 17 I ' 01 2345 .71
I 23 45.7:

°

I

1
2
3
4
S

,°

\

I

,
•

I

i

I

If WAI\j[E:

SITI"l IJ

(

I

9
10
'11
12
13
14
15
16
17
11
19
20
21
22
23
24
2S
26
27
2.
29
30
31
32
33
34

1511V'1 )

I(

7

I
I

I

I

i

I

:

I
)(X~il(

/JiT~

II

If

I

I

( L+ITIY

·1)

:'1
I

I

I

I

X.)(
PI

I

I

i

I

~

I

I

)

1)11)1 IXlX! I

I

)

I}I~

I~I)

~ITIY

J

,/,

•

if. 1M I

I~

I~

• III

~)

I

I

I
:

, i

,

i
I

1

i

I

i

I

I

I

I

I

i

1

!

I

I

I

i

I

I

I

!

I

I

:

17

11~

~I}O)tI~~

rr

• X~

01 IT

17~ll

~~I)(IX ~

.\XI)(

( 17 rlf)

I

I

3S

36
37
3.
39
40
41
42

!

I

I

I

43

....

4S
46
47

I

:

4.
4'
SC

I

!
/'

Figure 3-23. Printer Spacing Chart for Invoice

3-20

Page of GC21-7567-2
Issued 24 May 1976
By TNL: GN21-5389

IBM

RPG

OUTPUT

GX21-9090 U/M05O"
Printed In U.S.A.

SPECIFICATIONS

Intern.tional Busines. Machine Corporation

1 2
Program

J

Programmer

Date

0

-

Page

~ Space

e~
e-

-

...
~ Gi

Filename

Line

~~

~
E

7

8

4

1

o
o
o

2

01 IVV
0

3

0

4

0
0

o

~

2l

~

0

1
z

z

1:1

'~

',..,

12~1c;

"

l2

MR

tljJ

0

o
o

8

0

1'\

I~

MR

(2jl

MR

all.

0

Ves
No
Ves
No

No Sign

CR

-

1
2

A

3

C

4

0

J
K
l
M

8

X • Remove
Plus Sign
V - Date
Field Edit
Z - Zero
Suppress

II:

::;

Constant or Edit Word

iil

li:

lL

'"

75
~b

~ID IDR

7~

Irlf Iry

,5

fT lEI", ru"

IflJ

1 1

0

1 2

0

"ITIY

1 3

0

PIR II

1 4

0

AM hJ Nr:~

1 5

0

r - ~1'1 N:""

!J:i12l

1 6

0

DE 51"TV

1712

23
,. E

0

1 8

0

PR llrlF'

1 9

0

A~

2 0

0

"1,

3~
":\B

,~

B:~

1 7

)

to Print

Ves
Ves
No
No

Positon
in
Output
Record

Zero Balances

Commas

IIIIII

'2.'i
3~

is, NI"I

Irl

0

0

~~

~iA !ME.
Irl LeiT INr
INA IM~

6

9

~~

'AUTO

Ii'

End

Il>

:~~'f~cation I

~~

MR

0 7

1 0

f

II:

0

0

z

Field Name

75 76 77 78 79 80
of_

9 10 11 12 13 14 15 1617 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 3!139 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71727374

3

0

0 5

At

Afore ~
r;~'o

~
6

~

~~

It tl

I-

5

~

Output Indicators

Skip

[0

l~

917

Nrrl3

Iqli

0
0
0
0
0
lL 1£ O£ 69 89 £9 99 S9 1'9 £9 Z9 19 09 6S

IBM

as

£S 99 SS 1'9 £S lS IS

os

6~ 8~ £~ 9~ S. ~ £. It I. O. 6£ 8£ ££ 9£ 5£ >£ t£ l£ It .0£ 6l 8l

RPG

OUTPUT

a

9l Sl ~l £l U

Il Ol 61 81 LI 91 SI .1 £1 II II 01

u:

Page

~J

Space

Output Indicators

Skip

e-

Filename

Line

~
I-

)

6

0 1

0

o
o
o

2

0

3

0

4

0

0 5

0

o

6

0

0 7

0

o

0

8

~~

~~
~~ m<

I-

U5

1-;\ 010

j
5

9

S

•

£

l

I

GX21·9090 U/M OSC'
Printed in U.S.A.

Date

0

4

£

SPECI FICATIONS
1 2

Programmer

3

8

International Business Machine Corporation

Program

-

6

o R
A~ro
7

8

At
~

~

1

t

:!i

0

z

li

b

0

z

z

'AUTO

Positon
in
Output
Record

~

.~

'0

w

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

II"

...

Field Name Ifl

3~

MR

9 40 41 42 43

Illl

Commas

Zero Balances

to Print

No Sign

CR

Ves
Ves
No
No

Ves
No
Ves
No

1
2
3
4

A
B
C

13

0

75 76 77 78 79 80
of_

J
K
l
M

::~af:ation I

IIIIII

X ... Remove
V -

Plus Sign
Date
Field Edit

Z ... Zero

Suppress

II:

~li:

Constant or Edit Word

44~46~48~ro~~~54~~~~~~~~~~~66~68~ro

128 'T I_IT ~IL
'(loa-

[0

71 72 73 7.

I

13'8

'$ ,
185 'T lair !All
:qi5
~B'B '$ I
81
1

TIOIr

138

I

Figure 3-24, Output-Format Specifications for Invoice (Coding Each Field Twice)
Controlling Printer Output

3-21

Specifications for Using *PLACE

A *PLACE specification must not be conditioned by indicators in columns 23·31. *PLACE is automatically conditioned by the same indicators that condition the field or
fields to be repeated.

*PLACE is a special RPG II function which can be used to
accomplish duplicate printing with less coding. To the RPG
II com'piler the specification *PLACE means: Duplicate
that part of the line which has been specified and place the
duplicated information in a different position on the same
line. *PLACE means a special function is to be performed.
You should not use this specification as a field name, since
the RPG II compiler will assume you want the preceding
field duplicated. When using *PLACE you first define, for
each record, all the fields which are to be duplicated. Give
the end position for each field as you normally do. Then
enter the word *PLACE on the line below the fields which
are to be duplicated. Figure 3-25 shows the entries for the
first detail line of the invoice.

Formation of Print Lines
When System/3 performs printer output, a whole line is
printed at once, regardless of how many fields are in that
line. Before printing, the whole nne is moved to an area of
storage exactly as it is to be printed. Data is placed in this
storage area one field at a time.
The sequence in which data enters the storage area depends
on the sequence that field names are specified on the RPG II
Output-Format sheet. The first field recorded on the OutputFormat sheet 'is entered first, then the second, etc. Each
field is inserted into the storage area according to its endposition entry on the Output-Format sheet. If you have
made conflicting entries in your specifications (for example,
one field overlapping another) the last field mentioned is
the one that will print in its entirety.

The compiler does not know where to print unless you
specify an end position on the *PLACE entry. In Figure
3-25, the end position given for the *PLACE entry was 86.
The *PLACE specification duplicates not only letters but
also blank spaces. It will duplicate all the characters (including blanks) from position 1 to the end position specified for a field. Thes~ duplicated characters are then placed
so that they end in the end position specified for the
*PLACE entry.

*PLACE operates in the same way as normal field names.
The operations associated with *PLACE are performed in
the sequence *PLACE is specified on the Output-Format
sheet in relation to other output entries.
/'

When specifying an end position for the *PLACE entry,
you must know exactly where you wish the fields to print.
You must also consider tbe amount of space needed for
the printing-oralr characters to be duplicated. Always
specify an end position which "allows room for the printing
of duplicated fields.

RPG

IBM

OUTPU,.

GX21·9090 UIM 050'
Printed in U.S.A.

SPECIFICATIONS

Internationa' Business Machine Corporation

1

Program
Programmer

Page

Date

0

f

Output Indicators

Skip

Space

~~

I---

-;.

0-

Filename

Line

~
I-

]
3

4

5

6

...
;

~~AND
7

0 1

011

o
o
o

8

~

~

~~
I- cl5
-;;:CoO
~~

Jd
~

~

~

0

z

1

0

z

Field Name

I
~

;3

0

z

.';lJ"

'AUTO

...

~]
End
Positon
in
Output
Record

9 10 II 12 13 14 15 1617 18 19 20 21 22 23 24 25 26 27 2B 29 30 31 32 33 34 35 36 37 38139 40 41 42 43

!Nlv "!J rE

1"\

21ct~

Commas

Zero Balances
to Print

Ves
Ves
No
No

Ves
No
Ves
No

NA 1rv1~
W"lJ 1ST

2

0
0

4

0

*pIt AI,. f

0 5

0

Coo

N"

CR

-

1

A

J

2
3
4

B

K

C
0

M

L

:~;~f~ation 1

I. 1 1 1 I I

X = Remove

Plus Sign
V = Date
Field Edit
Z a Zero
Suppress

a:

g

Constant or Edit Word

ii;
«%~Q~~~~~~~~~n~w~~~~~~~n~wro

2~
~Ib

alb

Figure 3-25. Output-Format Specifications for First Line of Invoice (Using *PLACE to Print Fields Twice)

3-22

75 76 77 78 79 80

of_

No Sign

MIR rll

3

2

[I]

71 72 73 74

i'

10

20

30

40

50

60

70

80

90

I

I

I

I

I

I

I

I

I

I

JOHN FITZGERALD

A.

4758321

I

IL_JOHN

_FITZGERALD
___________
__ 1
4758321
~

B.

Result of
field description

Result of ·PLACE
entry

~ntries

Fi{Jure 3-26. Line Formation (First Line of Invoice)

)

Follow the formation of the first line to be printed on the
invoice. According to the specifications in Figure 3-25,
the NAME field ends in position 25 and CUSTNO in 36.
The first part of the line is completed with these specifications (Figure 3-26, insert A). Because of the way lines are
formed, the end position for the *PLACE entry must be at
least two times the higher end position specified for a field
that is to be duplicated. This ensures that the last field
mentioned will not overlap the field preceding. In this case
the same fields are to be printed again on the second part
of the same line. Since the end position was 36, the second part of the same line must end at least in position 72
(two times higher than the end position for the field to be
duplicated). It is decided they are to end in position 86.
The second part of the line is formed by the *PLACE entry
(Figure 3-26, insert B).

IBM

RPG

Using Different Spacing for Duplicated Fields

The second and third lines of the invoice do not have fields
to be duplicated. However, the fourth line of the invoice
requires that all fields be duplicated. Notice that different
spacing is required for the duplicated fields because a field
called DESC must be inserted between ITEMNO and QTY.
Figure 3-27 shows correction specifications. You want to
start with ITEMNO since it is the first field. ITEM NO is
specified as usual; the end position is given. Then *PLACE
is specified with the correct end position, 50 in this case.
These specifications cause the line to look like that in Figure 3-28, insert A.

GX21-9090

SPECIFICATIONS

OUTPUT

1

2

75 76 77 78 79 80

Program

Programmer

0

u: Space

~~
e !t

~~

Filename

Line

~ ~
~

.

.

.f

~~fAND

~

E

3

4

1

o

2

o
o

3
4

0

5

o

6

o

7

o

8

o

9

1 0

1 1

Page [ D o , _

Date

.1---

o

5

U/M 050'

Printed in U.S.A.

International BUSiness Machine Corporation

6

7

8

1L

~~

en

<{

'00 ~

"

Output Indicators

Skip

Field Name

Positon

~,:::

~

~

0

0

0

z

z

...

II;
1m

z

'AUTO

"0

in
Output
Record

w

9 10 11 12 13 14 15 1617 18 19 20 21 22 23 24 2526 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

alI INIV
a
a
a
a
a
a
a
a
a
a

IT

I..

12 Vi le;

11"1

I~

~

IMR

~IJ

loz

MIR

011

I'

Zero Balances
to Print

Yes
Yes
No
No

Yes
No
Yes
No

No Sign

CR

-

X = Remove

1
2

A
B
C
0

J
K
L
M

Y :

3
4

Z :

IIIII

Plus Sign
Date
Field Edit
Zero
Suppress

a:

~0:

Constant or Edit Word

«~.~~~50~~~~~WDW~50~~~~~~n~~ro

71 72 73 74

I~

11 ,

I~IIY.

N"'"'

I,*'p iliA 'rl~
~T['r'

..,

Commas

~~:;~f:ation 1 I.

IplA :I~'E l3

INlTl3
IA IrlJ:

~~ la'J

~Ip I,
In,lE

6 lr
~

11~
15~

121_1
1311ll
I:::\IA

Iql;
1712

I(

~'I

Figure 3-27. Specifications for Fourth Line of Invoice

.-/.

Controlling Printer Output

3-23

o

100

47535
47535

38

1.10

47535

38

1.10

41.80

:

47535

~

_ 47535

47535

38

1.10

41.80

47535

WOOL SOCKS, GR, SZ 9

38

1.10

41.80

41'80~
..

,

~A' ·PLACE
Line after first
I
I

TOTAL _ _ __

I
I
I

B. Line after second
·PLACE
C. Line after speci·
fication of the
DESC field

TOTAL _ _ __

Figure 3·28. Fourth Printed Line

Now, the remaining three fields are specified and an end
position is given for each. *PLACE is entered after them
to signify that the above three fields should be duplicated.
Remember that when fields are duplicated, all information
from position 1 to the highest end position specified for a
field is used. In this case, positions 1 through 38 are ~upli·
cated and placed so that they end in position 95.
QTY, PR ICE, and AMOUNT are in positions 1 through 38,
but ITEMNO is also there since it ends in position 10. Thus,
all four fields are duplicated and placed so that they end in
96. Figure 3·28, insert B shows resulting formation of the
line. ITEMNO now appears three times, once in the DESC
field area where it should not be.

I n this example, we can specify the field DESC to end in
position 75. It will overlay the unwanted ITEMNO field
and thus get rid of it. Figure 3·28, insert C shows the line
as it will be printed.

/'

For each job you do using *PLACE, you will have to cal·
culate exactly what happens when lines are formed.

Duplicating Constants

*PLACE can duplicate constants as well as fields. The same
specifications are used for both. Figure 3·29 shows the
specifications for the last line of the invoice. In this case
*PLACE duplicates a field and two constants. As you can
see, using *PLACE eliminates duplicate coding.

/'

3·24

RPG

IBM

GX21·9C!90 U/M 050'
Printed in U.S.A.

SPECI FICATI ONS

OUTPUT

International Business Machine Corporation

1

2

75 76 77 78 79 80

Program

-

Page [ T I o , _

Dale

Programmer

0

u::

Space

Filename

Line

i- ""~ ~ <~
~~

~

E

2.~r-

~
3

4

a

1

0

2

5

6

At

m

r-;o"D

I-

0

en

~

0

z

1

0

Z

z0

Field Name

8

9

~

-IE D

12lD~

0 7

0

a

8

0

0 9

0

1 0

0

1 1

0

h''''jf

1

2

a

i*,P lA r IF=

1 3

0

4

5

Ci

5

~~

End
Positon
in
Oulpul
Record

II

Zero Balances
to Print

Yes
Yes
No
No

Yes
No
Yes
No

No Sign

CR

1
2

A
B
C
0

3
4

J
K

L
M

X • Remove
Plus Sign
Dale
Field Edil
Z = Zero
Suppress
V •

a:

Constant or Edit Word

..J

m
0:

MIR ([1

0 6

0

0

a:

Commas

IIIII

1011 1213 1415 1617 18 19 20 2122 23 24 2526 27 2B 29 30 31 32 33 34 35 36 37 38 39 4041 4243 44 45 46 47 4B 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 6B 69 70 71 72 73 74

N,V '_lr

OIT
a
a
a
a
a

0 3

rr
;3

'AUTO

AND

7

:>

Output Indicators

Skip

~~

o !t

::;~':.'ion 1 I.

:<
i

i

IT

312

MIR Ll

~

~

c
Ie

I:U
AlB

'tr hI li:\ll

1$

I

1318
IQl5

I

I

1

Figure 3-29, Using *PLACE to Duplicate Constants (Last Line of Invoice)

)

\

Controlling Printer Output

3-25

Printing a Field Several Times on the Same Line

Since the label has to be only a few inches wide, the manager found he could print three labels side by side on his
120-print position printer (Figure 3-30).

*PLACE can be used to print the same field several times in
the line. All you have to do is enter *PLACE along with an
end position for each time you want the fields duplicated.
If you want the field duplicated twice, you need two
*PLACE entries.

You can see that each field needs to be printed three times
on each line. In the examples discussed so far, *PLACE was
used to duplicate fields only once.

Assume that periodically a store prepares mailing labels for
each customer who has an account with them. They use
the labels when they send out special advertisements. The
mailing label has only name, address, and zip code on it.

0,

I

10

20

30

40

I

I

I

I

Figure 3-31 shows the specifications for the first line.
NAME needs to be entered three times per line. The original field specification prints it one time: the two *PLACE
entries cause it to be printed two more times.

50

60

70

I

I

I

80

110

100

90

120

I

I

I

I

I

I

NAME

J

I

NAME

I

I

NAME

I

I

ADDR

I

I

ADDR

I

I

AD DR

I

I

CITY

I ISTATE I
I ZIP I

I

CITY

lSTATEI

I

CITY

I
I

I

ZIP

I I STATE I
I ZIP I

Figure 3-30. Mailing Labels

RPG

IBM

GX21-9090 U/M 050'
Printed in U.S.A.

SPECIFICATIONS

OUTPUT

International Business Machine Corporation

I

Program
Date

Programmer

0

~ Space

~~
o-

IFilename

Line

!

I

4

5

5

... !!
t

~~

I- cl)

~

~~D
7

8

Output Indicators

Skip

~~

ADD

~

3

-=

At
!!

~

~

z°

z°

Field Name

1
l5
z

'AUTO

n 32

r25:1

0 2

0

NA 'itE.

0 3

0

*p

o

0

*",

Figure 3-31. Using *PLACE for Producing Mailing Labels

3-26

~

."w

'0

9 10 II 12 13 14 15 1517 18 19 20 21 22 2324 25 26 27 28 29 30 31 32 33 34 35 36 37 38

0

4

vi

"

m

0 I

ASE'

2

75 76 77 78 79 80

~~:;~f:ation 1 I.

pagernO f _

End
Positon
in
Output
Record

9 40 41 42 43

'Arl~

,35
.ill

[Ar 1,:-

J.'l5

Commas

Zero Balances

Ves
Ves
No
No

Ves
No
Ves
No

to Print

No Sign

CR

-

I
2
3
4

A
B
C
0

L
M

J
K

IIIII

X = Remove
Plus Sign
V = Date
Field Edit
Z -

Zero

Suppress

a:

g

Constant or Edit Word

ii:
«%~~~~W~~~M~~n~~OO~~~M~~"M~M

71 72 73 74

USING TWO PRINTER OUTPUT FILES IN ONE
PROGRAM

)

Two System/3 printers, the IBM 5203 Printer on the Model
10 Card and Disk systems and the IBM 2222 Printer on the
Model 6 allow you to produce two separate printer output
files on the same printer in a program (Figures 3·32 and
3·33). The forms can be narrower than standard forms and
are often special forms such as checks or invoices.
A minimum of 17 print positions, between
the left carriage tractor and the right
carriage tractor, are not available for printing.

)
Figure 3·32. 5203 Printer with the Dual Feed. Carriage Feature

I 53958A

Primary tractor

Secondary tractor

Figure 3·33. 2222 Printer with Dual Feed Tractors

I 54019A

Controlling Printer Output

3·27

Page of GC21-7567-2
Issued 24 May 1976
By TN L: GN21-5389

Model 10 Card System, Model 10 Disk System, and
Model 12

To print two output files for one program, each of the two
printer files is considered a separate output file and must·
be described as such. These output files require special
descriptions on the File Description and Output-Format
sheets.

The feature of the 5203 printer that allows you to produce
two separate printer output files is known as the Dual Feed
Carriage Feature. The feature is available on 96, 120, and
132 position printers. One form is controlled by the left
carriage of the printer and the other form is controlled by
the right carriage. There is space between the right and left
carriage tractors that cC?~tains no form. When you are printing on two forms you lose at least 17 print positions
because no forms can be placed in this space (see OutputFormat Specifications, later in this section).

File Description Specifications
Model 10 Card System, Model 10 Disk System, and Model

I

.12: Figure 3-34 is a sample File Description sheet for the
Dual Feed Carriage Feature. The two output files to be
printed must be assigned to the device names PRINTER and
PRINTR2 on the File Description sheet (columns 40-46).
PRINTER is the device name for the left carriage of the
printer. The right carriage is assigned the device name.
PRI NTR2. Record Length entries (columns 24-27) for the
two printer files should be the same. Entries under Block
Length (columns 20-23) must be the same as Record Length
entries. You are responsible for ensuring that output to the
PRINTER device is confined to the left-hand form and output to the PRI NTR2 device is confined to the right-hand
form. You can easily layout your two reports using the
Printer Spacing Chart.

Model 6
The 2222 printer on the Model 6 has dual tractor feeding,
a primary tractor and a secondary tractor. All 220 positions of the printer are available for printing, that is, there
need be no positions lost between the primary tractor and
the secondary tractor.
The tractors that control the right-hand and left-hand forms
on the printer are adjustable. That is, the width of the
forms and the starting and ending print positions for each
form are variable.

. File Description Specification
File Type

F

-

File Addition/Unordered

Mode of Processi n9
Length of Key Field or
of Record Address Field

File Designation
End of File

Record Address Type
Sequence

Filename

Type of File
Organization
or Additional Area

File Format

line

~
~

~
~

~w~~
3

4

5

7

8

9

o
o
o

3
4

F~

5

F

o
o
o
o

6

F

1

FIT

7

F

8

F

9

F

0

~~

Record
Length

~

Symbolic
Device

Device

1!

.:l

~

Key ~ield

Number of Extents
Tape
Rewind

Core Index

~
Condition

U

.~

Ul·~

Continuation Lines

~::~~~:n:n

g

~umber of Tracks
for Cylinder Overflow

Name of
Label Exit

-5

::: I-

:)

.J

Extent Exit
for DAM

K

Option

Z

~

=>

~

Entry

10 11 12 13 14 15 16 17 18 19 2021 2223 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 4041 4243444546 4748495051 52 53 54 55 56 57 58 59 6061 626364 65 66 67 sa 69 70 71 72 73 74

rip
NP LJT
rFh IT P Tl

02

Block
Length

Overflow Indicator

w

~
Z
en

TP

T2

,...

IF

loJct lrLlltt

1~llslK

Ip RI11NIT J= IR

IF 1312 1 L~~
11= 1. 3 12 ll~12

P RII 1M rr R12

F
F
F

ZL IL OL 69 89 L9 99 S9 \>9 t9

~9

19 09 6S lIS LS 9S SS \>9 t9

~5

15 05 6v 8v Lv 9v SV vv tv

~v

Iv OV 6£ 8£ Lt 9t St vt tt

~t

It Ot

~ ~

a

9~ S~

v~ t~ ~l I~ O~

6' 8' LL 91 5' vI tl

~I

II 01

6

8

L

9

Figure 3·34. File Descriptions for Two Printer Files on Model 10 Card System, Model 10 Disk System and Model 12 (5203 Printer)

3·28

5

v

t

~

I

Page of GC21-7567-2
Issued 24 May 1976
By TNL: GN21-5389

I Model 10 Card System, Model 10 Disk System and Model 12:

Model6: Figure 3-35 shows the File Description sheet
entries for the dual tractors on the 2222 printer. Th~ two
printer files are assigned device names TRACTR1 and
TRACTR2 on the File Description sheet (columns 40-46).
TRACTR 1 is the primary tractor (left-hand print unit) and
TRACTR2 is the secondary tractor (right-hand print unit).
Under Block Length (columns 20-23) for each file enter the
beginning print position for that file. Under Record Length
(columns 24-27) enter the ending print position for that
file. Print positions for TRACTR 1 and TRACT~2 cannot
overlap.

Remember, there are 17 print positions you cannot use,
because there is a space between the left and right carriage
tractors which cannot contain a form. This is important
when you are planning where to position your printing on
each form. The first character to be printed on the form in
the right carriage (PR INTR2) must be at least 17 positions
away from the last character on the form in the left carriage
(PRINTER). Suppose you decide to use print positions
1 through .80. Because the first character in the right carriage must be at least 17 positions away from the last character in the left carriage, print position 98 is the first available position:

Output-Format Specifications
80
+17

Spacing and skipping on the two forms are completely independent. You can specify different spacing and skipping
for each output file. Spacing and skipping are entered in
columns 17-22 of the Output-Format sheet.

(End position of the form in the left carriage)
(Number of print positions you cannot use)

97
Therefore, 98 is the first available position. If the length of
your print line is 35 characters, the last position for the
second form is 132.

File Description Specification
File Type

F
f--

"\)

Mode of Processi ng

File Addition/Unordered
Extent Exit

Length of Key Field or
of Record Address Field

File Designation
End of File

Record Address Type

./

Sequence

Filename

File Format
Line

c

~
c~

ei2

~~

N

Block
Length

Record
Length

g~ w~ ...

3

4

o

2

o3
o4
o5
o6
o 7
o8
o9
1 0

5

7

Fir

8

9

~

0..

(;

C

~::,

Ui
~

...J

Device

Overfl~g
Key Field
Starting
Location

o~

~

Tracks

K

Option

Entry

~

"'II:

to tl 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 3334 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 7071 72 73 74

J: lL~~ ll.(Z~

IN:P I,r
flp
J irll n
II IJ-I tJlT 2

F~ tiT ip

~

F

r: lLe13

'"

F

~

~t:

Type of File
Organization
or Additional Area

N,,~I

In this example, TRACTR1 has 132 print (OverflOw
of Extents
positions; the form on the secondary
r--ape
ewind
tractor has 88 print positions. All 220
~
print positions are used in this case, no
Condition
Ul'~
positions are lost between tractors.

"'I 5K

r'R IAr i~Rl

1 lL 32

rRI~

i2.2fl

',HI..!

"-

OF
F
F

\

F

F

°

F
F
lL It OL 69 B9 L9 99 S9 t9 £9 19 19 09 6S

as

LS 9S SS t!i £9 lS IS

os

6. 8p L. 9. SP

»

CP ZP Ip OP 6C 8C LC 9C SC PC CC ZC IC OC 6Z 8Z LZ 9Z SZ pZ Cl II Il Ol 61 81 LI 91 SI pi CI ZI II 01

6

8

L

9

S

p

C l

I

I

Figure 3-35. File Descriptions for Two Printer Files on Model 6 (2222 Printer)

)
/

Controlling Printer Output

3-29

Page of GC21-7567-2
Issued 24 May 1976
By TNL: GN21-5389

REYNOLDS INDUSTRIES, INC.
111 W. SECOND ST.
SAN JOSE, CALI F. 95113

TELEPHONE
408-286-9100

CUST. NO.

430975

SOLD TO

S. W. KINGS
498 RIVER STREET
SAN JOSE, CALIF. 94067

SHIPTO

IMPERIAL DESIG~ HOMES
DIVISION OF S. W. KINGS
8343 BRANCH STREET
SUNNYVALE, CALIF. 95117

ORDER DATE

ORDER NO.

SALESMAN

SHIP DATE

7/10/70

13826

G. JONES

7/15/70

QTY.

96
40
350
200
175

ITEM
NUMBER

DESCRIPTION

391468
411116
411132
411732
511117

UNIT PRICE

.23
.60
.32
1.20
.42

OCTAGON BOX 4 INCH
TWINLITE SOCKET B
SOCKET ADAPTER BRN
SILET SWTCH IVORY
PULL CORD GOLD

EXTENDED
AMOUNT

$ 22.08
24.00
112.00
240.00
73.50
/

TOTAL
INVOICE REGISTER
7/15/71
INVOICE CUST.
NO.
NO.

EXTENDED
AMOUNT

DISC.
AMOUNT

13826
13827
13828
13829

$

$

430975
431030
432450
434960

FINAL TOTALS

471.58
238.96
57.70
208.62

$12,263.97

Figure 3-36. Sample Invoice and Invoice Register
3-30

INVOICE
AMOUNT
$

4.17

471.58
234.18
57.70
204.45

$145.29

$11,118.68

4.78

$471.58

Since INVOICE has a nonstandard form length, it must be
defined on the Line Counter sheet. You will use line 43 as
the overflow line. Figure 3-37 shows a sample Line Counter
sheet. (Note that since I NVREG has a standard form length~
it does not have to be defined on the Line Counter sheet.)

Example: End-of-the-Month Billing
Assume that your company invoices its customers using
your data processing system. It is your responsibility to
prepare and print the invoices to be sent to the customers.
You are also going to keep an invoice register; a record of
every invoice that is sent out. Since you have a dual feed
printer, you will print both the invoice and the invoice
register at the same time. You might name your two output files INVOICE and INVREG.
The format of your output must be determined. In this
case, INVREG will have the standard length of 66 lines,
while INVO ICE will have a nonstandard form length of 50.
Heading information is printed on the top of each report.
INVOICE uses a preprinted form for much of its heading
information. INVOICE has a 63 print position line and
INVREG has a 50 print position line. Figure 3-36, insert
A is a sample invoice and Figure 3-36, insert B is a sample
invoice register.

Line Counter Specifications

)

-

10

L

Line

!

Filename

~
3

4

5 6

" E
.!:
~
...JZ

7

8

1

~

1i

~1i
~

§

LLZ

1i ti~~~

" ::JE

.~

...J2

...J ~
02

1i
" E
.=...J2
::J

~.8

~

5

UZ

1i
.s"

E
:J

...JZ

~~

1i

UZ

" E
.S
::J
...JZ

2~

~~

1i

UZ

:J~

2§

"

E

~.!
~ §

U2

lJ

!.8

" E
.5
::J
...JZ

UZ

~ §

.c
" ::JE
.S
...JZ

~.!

iij E

tii

.c
" ::JE
.S
...JZ

~.8

2UZ§

11

12

1i

~1i

1i

~.8

" E
.5
::J
...JZ

6i

" E
.S
::J
...JZ

UZ

iij E

2§

1i

" E

:J~

~]

2§

UZ

9 10 11 12 13 14 15 16 17 18 19 2021 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 4344 45 46 47 48 49 50 51 52 5354 5556 57 58 59 6061 62 63 64 65 66 67 6869 7071 72 73 74

Figure 3-37. Line Counter Specifications for INVOICE

Controlling Printer Output

3-31

Page of GC21-7567-2
Issued 24 May 1976
By TNL: GN21-5389

You also want to have headings printed on the top of ev~ry
page. Because you do these operations only when an overflow indicator is on, you have to condition these operations
by the overflow indicator. Figure 3-38 shows the File Description sheets for Model 10 (Insert A) and Model. 6 (I nsert
B). Figure 3-39 shows the Output-Format sheet to print
headings at the top of ev~ry page. (Remember that skipping
and spacing on the two carriages are independent.)

OUTPUT

RPG

IBM

Internationa' BUlinea Machine Corporation

Program

Programmer

Date

0

~ Space

Filename

Line

~

- .. ~~
~ t

4

6

5

7

8

oliN

o
o
o

2

0

3

0

At

clS

~

~~ro

0 1

4

~

"ADIo

E

~
3

~

~ ~

I-

I-

Note for Mode/10 and Mode/12 Users: Recall that the
right form (in this case INVREG) must be at least 17
. positions away from the form in the left carriage. Because
INVOICE will have a 63 print position line, you assign positions 1-63 to it. INVREG is a 50 print position line and you
assign it to positions 81 through 130.

Output Indicators

Skip

e~
o!!:

I---

~

t

~

1

b

0

z

Field Name

0

z

z

·AUTO

9 10 II 12 13 14 15 16 17 18 1920 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 31

"'~I~

1-1

12 ~ll

lip
~r:

"'IR

0

0 5

0'"

~ 6

0

o

0

7

1. . . . . .

-

H

~~~

llP

hV

'"'R

Figure 3-39. Heading Specifications for INVOICE and INVREG

File Description Specification
File Type

F
-

File Addition/Unordered

Mode of Processi ng

Extent Exit
for DAM

Length of Key Field or
of Record Address Field

File Designation
End of File

Record Address Type
Sequence

Filename

Type of File

Organization

File Format

or Additional Area

Line

.J

Device

w

Number of Tracks
for Cyli nder Overflow

Name of
Label Exit

Symbolic
Device

Number of Extents
Tape

~

Core Index

~

Condition

Overflow Indicator U

8-

Block
Length

~
E

~ ~
D::

<"

.f
3

4

o

2

5 6

7

8

-5

N

Record
Length

Key Field
Starting
Location

a

~

.~

~

Continuation Lines

~
Option

W

Ul-'!!!.-

~

Entry

10 II 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 60 51 52 53 54 65 66 57 68 69 60 61 62 63 54 65 66 67 68 69 70 71 72 73 74

9

,...
~f
Fir NV
o3
Fir NV Hf:.[., ,...
o 4
FIT NP IT
!I [p I!::
Fr- JI'C to1l\lc
o5
.,Ir
o 6
F
o 7
F
@F
F

his:-

Is:- 132 1 BI2
1= L~2. 1131,

..... 7"

qb

F

IPR TIN [TE'R
IPR IrlN rrQ2

r~v

MF ~Iull

[9112

Is:- 117 i l l l KIl,;

~l

Inr lc;IK

~~ ~2

1M.

~

File Description Specification
File Type

F

-

File AdditionlUnordered

Mode of Processing

Extent Exit
for DAM

Length of Key Field or
of Record Address Field

File Designation
End of File

Record Address Type
Sequence

Filename

Type of File
Organization
or Additional Area

File Format

line

~

8-

~

g

§

.f
3

4

o

2

o

3

o

4

o

5

5 6

ii:w
7

8

9

~
~

'"
~~

Record
Length

Tape

~

Core Index

~o
~::::

~

Key Field
Starting
Location

Condition
Ul-'!!!.-

Continuation Lines

~

~

::J

K

Option

Entry

~

,

10 II 121314 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 3334 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 68 59 60 61 62 63 64 65 66 67 6869 7071 72 7374

,...
J:'.
FT NV
16 13
hlJ:
I~
I
Ur IRA Ir rr [Rll
roo
FI ' " V Krf-oiw
b,4 1 11~
1=
It<
IIolL
Fr ~p ~T
r[pJ:" !F
qb
IDll Sk
~~
AI!!.
Fr
Jlr
r:l;tt: ~h ID[r ~'j.(
~ 1.1; III 17R ~17 AT
ro. .. ,.

~

~\A

r®F
l
F
Figure 3-38. File Description Sheet for End-of-Month Billing
·.3-32

Number of Extents

Overflow Indicator U

::::1-

:l

Symbolic
Device

~

-5
.~

~

Device

w

(;

N

Block
Length

.J

Number of Tracks
for Cylinder Overflow

Name of
Label Exit

CiJl
alii

Review 3

Overflow and Fetch Overflow
1.

When you are not using overflow indicators or line counter specifications, but are
allowing RPG 1\ to handle overflow automatically, ~ow many lines are assumed per
page? What is the first line printed? What is the overflow line?

2.

Code the line counter specifications which are necessary to define a form of 50 lines
with the overflow line 8 lines from the bottom. What entries must also be made on
the File Description sheet?

3.

When is the overflow indicator turned on and when is it tested?

4.

Describe a situation where printing can occur below the overflow line.

5.

How does the fetch overflow specification alter the normal program cycle?

6.

Given the following information, supply the Fetch specifications, for the output
shown in Figure 3-40, which will prevent printing records on or over the perforation.
•

Number or printing lines per page is 66. The overflow line is 58.

• There are seven total lines in all. Since all are conditioned by the same control
level indicator, they will all print when a level 1 control break occurs.
• Overflow should be forced if the overflow line is printed prior to beginning total
output .

)

• Total lines 1, 2, and 3, must print on the same page. Total lines 4 through 7
must print on the same page.
RPG

IBM

GX21-9090 U!M 050'
Printed in U.S.A.

SPECIFICATIONS

OUTPUT

International Business Machine Corporation

1

2

75 76. 77 78 79 80

Program
~rogrammer

0

~ Space

C

Filename

Line

!

)
•

4

1

5

6

-

~~
~~

... cil

~

.£.'!!'fAND
7

8

2

0
0

4

0

o

5

0

o
o

6

0

7

0

o
o

8

0

9

0

1 0

0

1 1

0

1

2

0

1 3

0

1 4

0

0

~

~

0

0

z

z

Field Name

"

IJ

End

a:

0

z

~,~

'AUTO

~~
~~

Positon
in
Output
Record

9 10 11 12 13 14 15 16 17 18 1920 21 22 23 24 25 26 27 2B 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

O,p RIT I~T E'IR r 13

3

11

~

~~

~Dro

~

3

Output Indicators

Skip

e~

~

o
o
o
o

pageDJOf_

Date

Commas

Zero Balances
to Print

Ves
Ves
No
No

Ves
No
Ves
No

-

No Sign

CR

1
2

A

J

8

3
4

C

K
L
M

0

~~~~f:ation ,.

/.,

I" I

X c; Remove
Plus Sign
Y • Date
Field Edit
Z

:::0.

Zero

Suppress

a:

g

Constant or Edit Word

0:
«~~~~~50~~~~~~~~~50~~~~~~m~~H

71 72 73 74

IL ,

'T

12

I, ,

if'

1112.

It 1

'T

1112

it t

T.

~

t l

T'

2.

Ll

T

11

Ll

T" TIA !l11

Rbl

-

2. ,

R~

ry-'" Tl4 1_~1

Rlqj

T''"' riA 141

A~

T""" ,Tll I c\ I

~~

T'"' TA ,

t.,l

R~

rrn TA ,

71

R~

tll-l

Figure 3-40. Total Specifications (Question 6)
Review 3

3-33

Forms Alignment
7.

Why is accurate forms alignmentt important?

8.

What entries must be made in the RPG II specification sheets to repeat printing the
first heading line of a report until the forms have been correctly aligned?

Editing
9.

Choose the correct edit codes for the following punctuation.
a. 1,342,650.00CR (for zero balance, print .00)
b. 1,246,900- (for zero balance, leave the field blank)
c. 1694824.25- (for zero balance, leave the field blank)
d. 12/13/71

10.

Construct an edit word for a 12-digit account number so that it will print out with
the format XXX XXX XXX XX-X.

11.

On the Output-Format sheet, specify the edit code and any other entries necessary
to print out a dollar amount with the format $**1,234.56CR. The field must end in
position 50. If the tield is zero, print 00.

/

3-34

*PLACE
12.

What is the function of *PLACE?

13.

I n the example shown, is *PLACE used correctly? If not, why not?

RPG

IBM

OUTPUT

GX21·9090

SPECI FICATIONS
1

Program

Programmer

o

~ Space

e~
c -

Filename

Line

~~

Ii. ~
~5S
0 R

~

Skip

~

~~

"Aofo" ~

A~ro
4

5

6

7

8

9

,0 "

Output Indicators

-En-d-~ &>
II
I
r-r-r-1--T-r--t-r--,-+-----i.,.
~ 5 ~utPut ~
z°
z°
< z°
~ ~
~
And

1

F;,1d Nom'

,

~

·AUTO

'2 13 14 15 16 17 18 '920 21 22 23 24 25 26 27 28 29 3031 32 33 34 35 3637 38

Positon

Commas

Zero Balances
to Print

Ves
Ves
No
No

Ves
No
Ves
No

No Sign

IIIIII

X = Remove

CR

Plus Sign

J

A
B

K

C
-0

L
M

V = Date
Field Edit
Z = Zero
Suppress

Constant or Edit Word

9 4041 42 43 44 45 46 47 48 49 5051 52 53 54 55 56 57 5859 60 61 62 63 64 656667 68 69 70 71 72 73 74

o
o
o

2

0

2b.

3

0

37

4

0

)

75 76 77 78 79 80

~~~;~f:ation I

Record

O~IRJIN~

14.

11~13

.....
'

01

In

2

page'[Dof_

Date

~

3

U/M 050·

Printed in U.S.A.

International Business Meehlne CorporatiOn

~~

Write the output specifications to print two mailing labels in a row using *PLACE.
The first label ends in print position 25, the second in60. Each mailing label will
have three lines and look like this:
NAME
ADDRl
ADDR2

(25 characters)
(25)(18)
ZIPCODE

(5)

Dual Printer ,Output, Files
15.

What does the use of the dual feed printer allow you to do?

16.

What limitations exist when designing forms for use with the Dual Feed Carriage
Feature on the 5203 printer?

17.

How do you distinguish between the two feeds on the RPG II specification sheets?

Review 3

3-35

Answers To Review 3
1.

Sixty-six lines are assumed per page. First line printed is 06 and the overflow line
is 60.

2.

File Description Specification
File Type

F
-

File Addition/Unordered

Mode of Processing
Length of Key Field or
of Record Address Field

File Designation
End of File

~

!:!!
Z

Record Address Type

Sequence

Filename

Type of File
Organization
or Additional Area

File Formal
Line

Extent Exit
for DAM

..J _

Symbolic
Device

Device

w
~

Ci!

~

Number of Tracks
for Cylinder Overflow

Name of
Label Exit

Number of Extents
Tape

~
File _

Core Index

Noverfl~g
Block
Length

3

4

5 6

7

8

9

Record
Length

~ ~

Key

~g

~=:~~:n:B

Condition

~ield .~

2

I I I I FJI~ I

r"I

rJ~

~

~

:l

K

r 11 I/IPlOITlM1TI';IR

I II I I

<

Entry

Option

1011 1213 14 15 16 17 18 19 2021 222324252627 28 29 30 31 323334 35 36 37 38 394041 4243444546 4748495051 52 5354 55 56 5758 59

01 1 F,YIKCLii\i -,-i I I

U1-~

Continuation Lines .

6061 626364 65 66 67 68 697071 72 7374

I I 1I I I I I I I

1 I I

Line Counter Specifications
10

L

-

line

0.

1

Filename

~

1l ~~

]
3

4

1

1

5 6

" :::JE
.S

..JZ
7

8

~ §

u..Z

1

1l 6o~t

" :::JE
.5:

..JZ

..J

~

OZ

~
" E

.S ::J
..Jz

~~

~~

~

" E

~i

~~

t

J:l

~~

1 5 .=" E
uz ..JZ 3~
j

~
.E" E
j

-'Z

]f
uz

~
.S" :IE

..Jz

~!

2uZ§

~

.5..JZ§

]I
uz

~
" ::::IE
.5

..Jz

0;

t

J:l

.c

6i

.S-,Z§

C

fi E

11

1!~

~ §
uz

~
" E

.S :::I
-,z

12

1!~

~~

~
" ::IE
.S

-'z

~11
~ §
uz

9 1011 1213 14 15 1617 181920212223242526272829 3031323334353637383940 414243444546474849505152535455565758596061·62636465 666768697071 72 73 74

LlpRlrlNlr

~I~~~

~Iwb~

1 2
L
_~~~~-~4-~~~+-~-+4--~~~+-~-+~~-+~+-~~4-+4-+4-+-~~+-~-+4-~-+4-~~~4-~-+4-+-~~4-~-+~~~~
L

Form length is 50 lines and overflow line is 42. Any overflow indicator OA-OG or
OV must be entered in columns 33-34 of the File Description sheet. L must be
entered in column 39 to indicate that Line Counter specifications are used~

3-36

3.

If the printer has printed on the overflow line either during'totalor detail output,
the overflow indicator specified in the File Description sheet is turned on. The overflow indicator is tested and overflow output performed only after total output.

4.

a. When more than one detail or total line is printed during one cycle and a line
other than the last total line is printed on the overflow line.
b. When the last detail line for a control group prints on the overflow line, the total
lines for that group will print below.the overflow line.

~.

The overflow indicator is tested prior to printing each line specified with fetch overflow rather than waiting until all total output has occurred. If the indicator is on
when tested, overflow output is performed immediately and then the line specified
is printed.

/

6.

F in column 16 of lines 1 and 7 of Figure 3-40. F in column 16 of line 1 causes
forms to advance if the overflow indicator is on, assuring that total 1 will not print
below the overflow line and total 3 will not fall over the perforation. Since totals 4
through 7 must all print on the same page and will not all fit below the overflow line,
enter F in the specifications for total 4 to cause a skip to the next page if the overflow indicator is on. Since totals 5-7 must print on the same page as total 4, no fetch
specification should be entered for them.

7.

Forms must be aligned accurately so that printing is correctly positioned on each
page and so that printing occurs exactly where you want it, not above or below.

8.

There must be -at least one line on the output sheets conditioned by the 1 P indicator.
A '1' must be ~ntered in column 41 of the control card.

)

9. _ a. A
b~ K

c. M
d. Y

10.

Blank spaces show where digits are to be placed and &'s show where blanks go. The
word must be enclosed in quotes.

entir~

IBM

RPG

GX21-110110 UIM ow
Printed In U.S.A.

SPECIFICATIONS

OUTPUT

Internl.ion" 8ulinftl MechiM Corpor••ion

1 2

Pr01lrlm
Progrlmmar

Dltt

0

)

@i
a!!:

Space

.

...~

~ :(

o

R

r---

...~
E

~
3

4

1

0

2

0

3

0

4

0

o

5

0

o
o

6

0

7

0

o
o

8

0

9

0

1 0

5

6

0

1 1

0

1 2

0

1 3

0

1 4

0

1 5

0

1 6

0

1 7

0

1 8

0

1 9

0

2 0

~ ~

Filename

Line

o
o
o
o

Page

j -; ~=

~Dro

~~~
7

8

At

5

~

...

..

Output Indicators

Skip

l;

.::

«

0

z

~

1
~

Field Name

(;}j

I
·AUTO

~~

~~

End
Positon
In
Output
Record

9 10" 12 13 14 15 16 17 18 1920 21 22 2324 2S 26 27 28 29 30 31 32 33 34 35 36 31 38139 40 41 42 43

Air IrT IN'"

11[~

[D

75 76 77 78 79 80

of_

Commas

Zero Balanc..
to Print

No Sign

CR

-

Ve.
Ve.
No
No

Ve.
No
Ve.
No

1
2
3
4

A
B
C
0

J
K
L
M

a:
::J

:~;~:Cltion I
X •

IIIIII

Remove

Plus Sign
V • Date
Field Edit
Z • Zero
Suppress

Constant or Edit Word

0;

~
«%~g~~~~~~~~~~~~ro~~~~~~~MMro

,

&

i&

&

-

11121374

l

0
0
0
0

)

0

0

Answers To Review 3

3-37

The A edit code will zero suppress and insert commas, decimal points, and the:credit
sign CR. The asterisk entered in columns 45-47 will cause all places zero suppressed to
be filled with asterisks. The dollar sign must be specified on the line following the
edit code. When printed in position 38, it will come right before the asterisks.

11.

RPG

IBM

GX21·9090 UiM 050·
Printed in U.S.A.

SPECIFICATIONS

OUTPUT

International BusineSI Machin. Corporation

1 2

Program

Page
Programmer

Date

0

E Space

~~
e -

I---

-""
;; t

Filename

line

Ii
>

!

o

4

5

6

0

0 3

0

o

.

4

7

8

~

Ell

« z°

0

z

0

z

End

a:

a;
"0 .:.
8 U
!l

t

:::

ttl

·AUTO

~~

Positon
in
Output
Record

~

Commas

Zero Balances

Ves
Ves
No
No

Ves
No
Ves
No

to Print

No Sign

CR

-

1

A
8
C

J

2
3
4

0

K

L
M

X - Remove
Plus Sign
V - Date
Field Edit
Z ~ Zero
Suppress

Constant or Edit Word

i>:

9 1011 12 13 14 15 1617 18 1920 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 63 54 55 56 57 58 59 60 61 62 63 64 65 66 67 6B 69 70 71 72 73 74

AIMh NTA

5~

39

1*'

11$'

0
n

12.

3-38

~

Field Name

0

0 2

n

R

r;:;:N"o

1L

~!«

co

ADD

E

3

lI:

I- '"

~
0 1

0<

...

Output Indicators

Skip

75 76 77 78 79 80

[D0f_ ~~::~;:ation I I I I I I I

The function of *PLACE is to easily code the printing of duplicate information on
the same output line. *PLACE places information from print position 1, through
the highest end position previously defined for a field into the print positions indicated by the end position in the *PLACE entry.

13.

It is not correct. The end positon in the *PLACE specification is not high enough.
The duplicated information will overlay the field called ACCTNO. The end position
on the *PLACE line should be at least twice the highest end positi~n previously;
specified for'that record.

14.

Two labels must be printed. Therefore, for each line you must specify the original
field and a *PLACE entry, which will cause the contents of the original field to be
duplicated.

/

Page of GC21-7567-2
Issued 24 May 1976
By TNL: GN21-5389

RPG

IBM

-Il
I

I\-p_ro_gr_am_ _ _ _ _ _ _ _-.-_ _ _ _ _ _

IProgrammer

-

Date

o

S Space
t::
0

Filename

Line

Instruction

I

....

~ t

~!

~ ~ '" «

r;:;-fof-o

~~fo

And
~

~

I

T

Punch

I

I I

p

<1

0

0

z

z

1

Posi.ton
in
Output

0

z

'AUTO

Record

4

1

4

o

5

a
a
a
a

o
o

6

0

7

0

o

8

0

JJ.

o

9

0

~r

p" 1"'11')

z;

1 0

0

itlD Iii r t

b0

1 1

0

1 2

0

1 3

0

2

6

1 4

0

1 5

0

1 6

0

1 7

0

1 8

0

1 9

0

2 0

0

7

8

1

Page

Commas

Zero Balances
to Print

Ves
Ves
No
No

Ves
No
Ves
No

Field Name

3

3

U/U 050'
Printed in U.S.A.

I I Card Electro Number
I I

I

o
o
o
o

5

GX21,9090

SPECIFICATIONS

Output Indicators

Skip

~

I- ci)

)

Graphic

Punching

@"§

.......

-...,\

OUTPUT

International Busine" Machin. Corpor.tion

2

[0

No Sign

CR
A
B

e
0

75 76 77 78 79 80

of_

J
K
L
M

~~;~f~cation 1

I, 1 I I I I

X· Remove

Plus Sign
V = Date
Field Edit
Z a Zero
Suppress

a:

:::J

Constant or Edit Word

C:l
ii:

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 3D 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

'MA. M~

'n

II

b(2l

At". rH~I'
fA ',. 1=

2g
bClJ

rlt;

*p
1"1

11

2.~

*p LA I,.. r:

oj;UI.:;1

is

0
0
0
0
0
U 1£ O£ 69 Il9 L9 99 59 1'9-&9 19 19 09 65 85 £5 95 55 t5 t9 l5 15 05 61' 81' £1' 91' 51' "" &1' ll' II' 01' 6& 8& L& 9& 5& 1'& && l& 1& 0& 6l 8l

a

9l 5' 1"

&l U

Il Ol 61 81 LI 91 51 1'1- &1 II II 01

6

15.

The dual feed carriage allows the printing of two independent reports simultaneously.

16,

A minimum of seventeen print positions must be left blank between the two output
forms.

:117,

8

L

9

5

t

& l

I

Model 10 Card System, Model 10 Disk System, and Model 12: The only difference
is that the device name on the File Description sheet for the left carriage is PR INTER
and for the dght carriage is PRINTR2,

Model6: The only difference is that the device name on the, File Description sheet
for the left tractor is TRACTR 1 and, for the right tractor is TRACTR2.

Answers To Review 3

3-39

3-40

Chapter 4. Card Output Operations

)
CHAPTER 4 DESCRIBES:
Puncned output.
Printing on cards.
Using one file for both input and output.
Selecting the stacker for output cards.
Merging input and output file cards.

BEFORE READING THIS CHAPTER YOU SHOULD BE ABLE TO DESCRIBE:
Using the printer to produce a simple listing.
Using control fields.

RPG II object program cycle for detail and total operations.

AFTER READING THIS CHAPTER YOU SHOULD BE ABLE TO DESCRIBE:
Coding for punching a combined or output card file; summary punching.
Formatted printing and unformatted printing (*PR INT) on cards.
Uses and coding for combined files.
Stacker selecting input, combined, and output card files.
Coding for merging input and output card files.

Note: You can use the review questions contained in Review 4 at the end of this
chapter to test your comprehension of each topic in the chapter. Questions are
grouped according to the topic to which they apply. Answers follow the review
questions.

)
Card Output Operations

4-1

INTRODUCTION
Thus far, in this manual, the program output usually has
been a printed form or report. Punched cards generally
have been used as a source of input data. However, cards
can be used for output as well as input. This chapter describes RPG II coding for output operations using the IBM
5424 MFCU, available on the System/3 Models 10 and 15,
and the IBM 2560 MFCM, available on the System/3 Model
150nly.

On the Output-Format sheet, you can specify heading, detail, and total output, just as you can with a printer file. In
some cases, you may want to punch only total records by
summing the data on several input records and punching a.
separate card for the total. This is known as summary
punching. Do not specify an edit code for punched output
unless you want to have punctuation punched -into the output cards.

Printing On Cards
You might want to have card output for many reasons.
Perhaps you want to generate a new file or change an input
file in some way, such as by reformatting the records, adding data, deleting data, adding new records, or deleting unwanted records. The output you choose might be data
punched on the cards, printed on the cards, or both. Information can be printed on cards for identification, interpretation of the punched data, or any other purpose you
desire. You can punch and print data on blank cards or on
cards that already contain data. You can also direct cards
to a specific stacker or more output file cards with cards
from an input file.

PUNCHING AND PRINTING ON CARDS
Punching and printing on individual output cards are controlled separately. Punched cards need not be printed; .
printed cards need not be punched.

It is advantageous to print the same information on the
card as was punched on the card. This way you can easily
interpret what information is recorded on the card. Also,
printing information on the card makes it easier to recreate
a card that is damaged to the extent that it cannot be read
by the MFCU or MFCM, or duplicated by the data recorder.
Although you may print the same information on the card
. that is punched on the card, it is not always'necessary to
do so. You may print entirely different fields from those
that are punched.
The 96-column card has space at the top for four lines of
printing (Figure 4-1). Each line can contain 32 printed
characters, for a total of 128 print positions.
The 80-column card can be printed only on the MFCM
Model A 1 with the optional print feature. Up to six print
lines can be used. Each line can contain up to 64 printed
characters, for a total of 384 print positions.

Punched Output
Punched output can be used to:
•

Create a file of cards that is different from the input card
file

•

Add new records to a· card file

•

Add fields to input records

•

Punch a s~mmary card from a group of input cards

RPG II coding for punched output is similar to coding for
printer output. Ei~her the primary hopper (device name
MFCU1 or MFCM1) or the secondary hopper (device name
MFCU2 or MF·CM~) can be used as the output device; the
other hopper is used as the input device. In some cases,
punching can be done on the input cards themselves (see
Using One File for Both Input and Output, in this chapter).
Remember, however, if only one MFCU hopper is used, it
must be M FCU 1 (Model 10 Card System only).

4-2

The MFCM print heads can be set to 'print in 25 different
print line positions, from above the 12-punch position to
below the 9-punch positions (Figure 4-2). The print heads,
numbered 1 through 6, must remain in sequence from top
to bottom, with print head 1 at the top. Therefore, with
six print heads installed, print head 1 cannot be set below
line 20 and print head 6 cannot be set above line 6. Intermediate line positions are located on and between each row
of punch positions. Print-position 5 (between the 11-row
and O-row) should be avoided, if possible, because the feed
wheel may cause some smudging of characters printed in
that position. In punched fields, printing in even-numbered
line positions should be avoided because punching may
obliterate some characters.

/

Formatted Printing (MFCU)

)

Using formatted printing, you may print a field or constant
in any of the 128 print positions available on a 96-column
card. The first three lines are the lines usually printed. The
fourth is printed only if necessary because printing on the
fourth line increases considerably the amount of time needed
to print, and thus increases the time needed to do the job.

Printing lines

I

2

3

•

5

Ii

7

..

9

10 11

12 13 .. 15 16 17 18 11 20 21 Z2 23 24 25 2& 27 28 2t 30 31 32

»~»~n~»~~~o"~~~uu~~~»Y"~~~~~~uuul
U~~""ro~nnNnnnnn~~H"U""~""~~~~"""

B
A

V.H~~mm~m~m~~Mm~~~~~mMM~~~m~~~m~

B
A

8

8

4
2

.4
2

~I

23.

567.'~"~UU~~~R~ro~nnu~HV~H~~U~

A

A

8

8

4

4

2

2

~»~»~n~»~~~o"~~~U~~~~»~"~~""~~UU"~
A

A

8
4
2

8
4
2

1

U""""ro~nnNnnnnn~~Huu""~""~fl~~~""l
11M 3700

)

Figure

~-1.

Printing Lines on a 96-Column Punch Card

,;b, ,.,.,.".""".,,",,.,,"

>u" . . "

"u,"".»»""'iuu~

....

,~

*u.".. ... '; ..

""."~.",.,,,,,,,,,,,,,,,,,,,,,, """ "''''1

1

2
3
4
5
6

00000000000000000000000000000000000000000000000000000000000000000000000000000000

123456789WnUn"~ffinm~ro~nn~~~v~~~~~n~~$~~~~~~~"~UUq"~~~~M~~~~~~~u~~~~~~~ronnnM~mnnn~

7

111 111111 11 111111111 111 1111111111111111111111111111111111111 111 1111111 1111111111
22222222222222222222222222222222222222222222222222222222222222222222222222222222
12345678910nUn"~ffinm~ro~nn~~~v~~~~~n~~$~~~~~~~"~UUq"~~~~M~~~~~~~u~~~~~~~ronnnM~mnnn~~

33333333333333333333333333333333333333333333333333333333333333333333333333333333
~

13

44444444444444444444444444444444444444444444444444444444444444444444444444444444

123~56 78910nUn"~ffinm~ro~nn~~~vn~~~~n~~$~~~~~~~"~UUq"~~~~M~~~~~~~~~~~~~~HronnnM~m~nn~

1415

55555555555555555555555555555555555555555555555555555555555555555555555555555555

16
17

66666666666666666666666666666666666666666666666666666666666666666666666666666666
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 2D 21 2223242526 21 2.29 3a 31 32 33 34 3536 37383940 41 42434445464748495051 525354 55 5~ 57 ~8 S960 61 6263 6465 6& 6H0E9 70 71 12 73 71 757& 77 7879 eo

7 7 7 7 7 7 7 7 7 7 7 7 7 7 77 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 77 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7
8888888888888888888888888888888888888888888888888888 8 8 8 8 8 8 8 8 8 8 8 8 8 8 88 888888888888
I 2 3 4 5 6 1 8 9 10 1112 13 14 15 16 17 18 19 20 21 2223 24 25 26 27 28 29 3D 31 32 33 3435 36 37 38 3940 41 42 43444546 474849 50 51 52 53 54 55 56 57 58 59 ED 61 62 636465 66 6768 69 70 11 12 73 74 75 76 77 18 79 80

9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 99 9 9 9 9 9

"-

8
9
10
11
12

18
19

20
21

22
23
24

25

liM

• Figure 4-2. Printing Lines on an aO-Column Punch Card

Card Output Operations

4-3

Page of GC21-7567-2
Issued 24 May 1976
By TNL: GN21-5389

For each field or constant you wish printed by the MFCU,
you must make the following specifications on the
Output-Format sheet:

JAN IC'E T SWENSON
•

2

3

.~!5

,

7

8

,

10 11

12 13 lot 15 •• 17 '8 19 20 21

z.z

U 2. Z5 21 27 2' 2t 30 31 32

CHARLESVILLE.IDAHO·

74632448'

n~"H~»»~~U~"~"~UU~M~n~"~n~"~~u~U

p'17458
If a field is to be printed, enter the field name in columns 32-37.

1.

""~""ro~nn~~n"nn~~n~«"HV""~~n"«""

~M"~~mm~m~m~~MmmU~~~mM"~m~m~~~m~

12 .•. . ••
8
4

Enter * in column 40 to indicate that the field is to
be printed not punched.

2.

•
••

4

•

•

••

•
-·-8
•••
4

.~"~Uu~.~~~ro~nn~~~vHH~~nB
••
•
•

•••

8 •

Enter any end position from 001 to 128 in columns
41-43.

• ···········1
•• ...2

•••••

B~~~~~~7~
.....

A •

3.

OK
......
.
...
.•• .... ..AB

B......
A··
... · .......
·

•

A

• •

•

•••

2.-.

••

•• • •

1".

.••

8

•••

4

•

2

••

•

1

~nu"»~»»~~u~«~unuu~M~n~""~~"~~"~~B

A

4.

If a constant is to be printed, enter the constant in
columns 45-70.

A

8

8

4
2

•
4
•• 2

1 """""ro~nn~~nnnn~~n"u""v""~~n"u""1
IBM 3700

For example, to print the fields on the card stmwn in Figure 4-3, the specifications in Figure 4-4 lines 06-10 are
necessary. You indicate punchiRg of these fields by specifying an end position witPaut the asterisk (see Figure 4-4,
lines 02-05). If yo.u-1ntend to punch fields and print fields,
you need two specifications per field. If you have seven
fiel,(;k'fo be both punched and printed, you need 14 specifications.

Figure 4-3. Formatted Printing on a 96-Column Card

a field without printing it. If you punch and print the same
field, you may put each in different positions. In other
words, you may format the punched fields in a different
way than you format the printed fields.

Because printing and punching are two separate functions,
it is possible to print a field without punching it and punch

RPG

IBM

GX21·909().2 U1M 050'

SPECIFICATIONS

OUTPUT

Printed in U.S.A•.

International Business Machine Corporation

1 2

Program
Programmer

Page [ [ J o , _

Date

0

~Space

Output Indicators

Skip

~~

I---

I

0-

:; :u e

-",

Filename

Line

!
~

3

4

o
o
o
o

1

5

6

2

0

3

0

4

0

o

5

0

o
o

6

0

7

0

o
o

8

0

9

0

7

8

0

1 1

0

1 2

0

1 3

0

1 4

0

And

!

0

z

0

z

1

..h

Field Name

Xl

;3

0

z

v

Ifii
IUJ

'AUTO

9 10 11 12 13 14 15 16 17 18 1920 21 22 2324 2526 27 28 29 30 31 32 33 34 35 36 37

oC AR leo ulT Ie

1 0

~

~~
~Ji
rp;7ito e
~
~i5

~~ro

~

38139

Positon
in
Output
Record
40 41 42 43

~A ME
AD DR

~D DR

l4C crr H~
B!AL

~Ir All' ~~

Zero Balances
to Print

No Sign

CR

-

Yes
Yes
No
No

Yes
No
Yes
No

1
2
3
4

A

J
K
l

M

I. 1 1 1 1 1

X • Remove
Plus Sign
Y • Date
Field Edit
Z = Zero
Suppress

Constant or Edit Word

0:
«%%~~~~~~~~~~~~~ro~~~M~~~~Wro

2~

48

Sll-

~"

B
C
D

~~;~'~cation 1

a::

g

lI-CZ

AC CiT NO
SAL

NA ME

Commas

2QJ

~10 IISS
~~ ~11f
1K1(lJl i l
~l 1218

Figure 4-4. Specifications for Punching and Printing on a Card (Formatted Printing - MFCU)

4-4

75 76 77 7B 79 SO

71 72 73 74

Formatted Printing - MFCM

)

, Using formatted printing, you can print a field or constant
on any six of the 25 print lines available on an SO-column
card. For each field or constant you wish printed by the
MFCM, you must make the following specifications on the
Output-Format sheet:

1.

When printing a fiE~ld, enter the field name in columns
32-37.

2.

Specify a print' head number' (1-6) in column 41.

3.

Specify a print end~position(01-64) in columns 42
and 43. (The leading zero is required when specifying
print positions 01-09.)

4.

For example, to print the fields shown in Figure 4-5, the
specifications shown in Figure 4-6 are necessary. Coding
lines 02 through 05 cause the fields to be punched. Coding
lines 06 through 10 cause the fields and a constant,
BALANCE, to be printed. As you can see, two specifications
are required for each field that is to be both punched and
printed. In order to obtain the desired printing results, the
MFCM print heads must be aligned mechanically prior to
running the program.
Note: The fourth line of printing also could have been
printed using print head 4, with print heads 5 and 6 set to
line positions lower on the card.
Because printing and punching are two separate functions,
it is possible to print a field wit~out punching it and to
punch a field without printing it.

When printing a constant, enter the constant in
columns 45-70.

)

•

Figure 4-5. Formatted Printing on,an

~O-Column

Card

)
Card Output Operations

4-5

RPG

IBM
I
I

/

I

Program

0

~ Spac.

e~
e -

Filename

Line

!
4

5

6

~~fAND
7

0 1

Ot,..

0 2

0

0 3

0

o

4

0

0

5

0

0 6

0

0

7

0

0 8

0

0 9

0

1 0

0

1-1-11 1

~

~

~ ~

f;:7ifo

~

3

~ t

8

At
~

~

Graphic
Punch

I I
I I

Output Indicators

Skip

-. ~ ~
.... ci5

Punching
Instruction

I

Oat.

Programmer

-

U/MOSO·
Printed in U.S.A.

GX21-9090

SPECIFICATIONS

OUTPUT

Internltlonal BUltnlSS Machine Corporation

!l

<

1

,Field Name

I
I

f;
a:
II 0;

."
0

0

z

z

~

..:.

8 U
·AUTO

~ ~

I
I

I

Positon

in
Output
Record

75 76 77 7B 79 BO

pageDJOf_

D;>
End

1 2

Card Electro Number

Commas

Zero Balances
to Print

Ves
Ves
No
No

Ves
No
Ves
No

No Sign

CR,

1

A
B
C
0

2
3
4

J
K

l
M

~~;~f:ltion I

IIIIII

X .' Remove
Plus Sign
Date
Field Edit

V -

Z • Zero
Suppress

a:

~

Constant or Edit Word

it

9 10 11 12 13 1415 16 "7 18 19 20 2122 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 4041 42 43 «~~O~~~~~~~~~D~~~~~~M$~~~~ro 71 72 73 74

~ll

lAIR Inlr. hIlT Ir

12~
l/.jlo

NIAIM'f
lAin In'R
~~ Ir rr IN~
IBIAll
-

ILjIA
1514
il121(lj
i2121e

I~IA I~F:

lAin ID~R
Air ICiT N~

IRIAI!

IA

:~~ISl
5~17
l51~ltj

'11= Illil

lillN ""'IF

I

0

1--1-- I-- -

•

Figure 4-6. Specifications for Punching and Printing on a Card '(Formatted Printing - MFCM)

Unformatted Printing (*PRINT) - MFCU'and MFCM
Using formatted printing, recall that if you wish to both
punch and print a field, you must have two entries per field
on the Output-Format sheet: a punch entry and a print
entry. If you want several fields to be both punched and
printed, there is a great deal of coding involved.
RPG II has a special reserved word, *PR INT, which allows
you to punch and print fields and constants with less coding.
When *PR INT is specified, it causes all previous fields
described for the record to be printed. Use of *PRINT is
known as unformatted printing.
Figure 4-7 shows the use of the *PR INT specification.
NAME, ADDR, ACCTNO, and BAL are to be punched.
Following these field names in columns 32-37 is the entry
*PR INT. This entry causes the previous four fields to also
be printed on the card (see Figures 4·8 and 4-9).

Using *PRINT with the MFCU causes fields and constants
. to be printed in positions corresponding to the punch posi·
tions. For example, ACCTNO is punched in positions 41·48
and also is printed in positions 41-48.

/

On the MFCM, there is not space to print 80 characters on
one line. Therefore, data punched 'in columns 1-64 is
printed in print positions 1·64 by print head 1; data punched
.in columns 65·80 is printed in positions 49-64 by print
head 2 (Figure 4·9).
The word *PR INT can be used only once for a record and
must be entered after the description of all fields that are
to be both punched and printed. Suppose, instead of print·
ing all four fields (NAME, ADDR, ACCTNO, and BAL),
you want to print only NAME and ACCTNO. In this case,
the entry *PRINT must follow NAME and ACCTNO.
ADDR and BAL must be described after the *PR INT entry
(Figure 4·10).
Columns 7·22 and 39·74 must always be left blank on the
*PR INT specification line.

/

4-6

Page of GC21-7567-2
Issued 24 May 1976
By TNL: GN21-5389
RPG

JANICE T SWENSON
CHARLESVILLE.
IDAHO
74632448,017458

SPECIFICATIONS

OUTPUT

1

2

3

•

5

•

7

•

•

10 11

12 13 ... 15 II 17 18 It 20 21 Z2 U U ZS 21 27 21 21 30 31 32

»~~~n~U~~U~44~"~«u~~"nU"H"H"~~"U44

Output Indicators

ip

Field Name

11
~

0
« z

0

z

II
II

;3

z0

'AUTO

End

a:

Positon

5

in

en

~~

i

il1>

Commas

Zero Balances

Ves
Ves
No
No

to Print

Ves
No

Ves
No

a:

Output
Record

~
~

Cons1

21 22 23 24 2526 27 28 29 30 31 32 33 34 35 36 37 38 139 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55

N~ HI}:
~In Inlo
IA

II IN

BIAlt

IL~
~~
'~IR
1514

~Ip Il

Program

8

Ul'~

Continuation Lines

MIF"r Jil

IE

RPG

4

~
Condition

:Key
- -~ield
-5
.~

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59

AR

Tape
Rewind

'Core Index

F

IBM

3

Number of Extents

~

"8

Number of Tracks
for Cylinder Overflow

Overflow Indicator U

a

Ci:'

·f

Fis JiM

®

>l5
::::: t-

Record
Length

Z

Symbolic
Device

Device

~

or Additional Area

Line

Extent Exit
for DAM

,

nlJ:i

.=lls I~F' nib

....

RPG

)

IBM

Form GX21·9093
Printed in U.S.A.

CALCULATION SPECIFICATIONS

International Busines. Machine Corporation

1

Program

Date

Programmer

C

Indicators

~

11

-'0::
=0

~3~
.... aa:

Line

AL

o

1

o
o

2

o
o

7

8

0
z

4

5

.©

=

g~

High

Low Equal

9 10 1112 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 5253 54 55 5657 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

~1~ln

IJ:" IL InlL
I~I' Inl2
IFlt I"I~
IFII !I'll"
IJ:'I, In~
I~IL l"lb

C

lAlnlo

II J I 'MIL
rr~ trlAIL

II lJ JIM

h"~ ITIAl!

... 1,.

lAlnD
lADID
IA In In

rrlo ITIAIL

IAIDlo

II JII IAll

II

Iorol,.. I....

Il~

IA

!...IA

h"1A. LIlA

II MIL

IT

IIIR IL

fp;'"

''''IA

I

n

GX21·9090 UiM 050·
Printed in U.S.A.

SPECI FICATIONS

OUTPUT

Intern.tionll Business Machine Corporation

0

Page

~ Space

Filename

Line

!E
6

0-.,.

:; t

~

~

~ M~~
~~

~~

,*~'o

.e

7

~@

0
n

At
~

~

~

0

0

z

z

1

~

Commas

I~

End
Positon
in
Output
Record

Xl

;3

0

z

"

Field Name 1M

·AUTO

."
"C

w

~

Ves
Ves
No
No

Zero Balances

to Print

No Sign

1
2
3
4

Ves
No
Ves
No

2

OJ
CR

75 76 77 78 79 80
of_

-

A

J

B

K
L
M

C

0

~~~;~f~cation I

I. 1 I 1 I 1
;(

X = Remove
Plus Sign
V = Date
'field Edit
Z IS Zero
Suppress

Constant or Edit Word

Ii:

B 9 10 11 12 13 14 15 1617 18 19 20 2122 2324 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 4041 4243 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

01 1 1 o ~I'IIM~ IAIRln !n

)

Output Indicators

Skip

~~

I--

5

Comments

Compare

1>211<211-2
Lookup( Factor 2) is

1

4

IIIIII

Arithmetic

Date

3

., 75 76 77 78 79 80

~~~;~f:ation I

of _

Plus TMinuSf Zero

~ ~
u a :I:

RPG

IBM

Length

~

c
c
c
c
c

3

:E

Factor 2
Name

E E~ ~
.E 85 .g
5 6

Operation

Factor 1

Jd

2

OJ

Resulting
Indicators

Result Field

0_

i---

3 ·4

Page

I

I

II I

II III I

rlJl1

I

I I I I I I

II I I I

.1..1_I,I..l

llUIII"\IL

II I II

8

III

I I

II III II

I

III

III II IIII I

I

J 1415 I I I I I I II I I

Figure 4-14 (Part 2 of 2). Specifications for Reading and Punching Each Card

Punching into a Blank Card in the File
You have just learned how to use a combined file when you
wish to read and punch the same card. What if you wish to
read several cards and then punch another card in the same
file?· Remember any time you want to read and punch cards
fr~m the same fih~, that
must be defined as a combined
file: .

file

Assume that a company which keeps a weekly record of
items sold, uses these records at the end of the month to
determine the quantity of items on hand. For each item,
four different types of cards are read (Figure 4-15).

1.

Onhand, which contains the number in stock at the
beginning of the month.

2.

Issues, which contains the number sold during the
month. There is one of these cards for each week.

3.

Receipts, which contains the number added to stock'
through reorder.

4.

New On hand, which is blank. After calculations have
been performed to determine the number on hand, ,
this number and the date anda code are punched into
the card. This card, when punched, will be used as
next month's Onhand card, and will be in the same
format as the current Onhand card.

Card Output Operations

4-11

Each of these card types is identified by a code in column
96 (see Figure 4·15). (This code would be column 80 if
the MFCM were used.)

B
A

p."~~wm~m"ma"~maQMM~mMM~mum~m~m~

8
4

ITEMNO

DATE

INSTOK

2

B
A

B
A

8
4

!

2

2
1

~I 13.1171'~"UUu~.n~u~~U"""HVHH~~H~
A
A
8

8

4
2

4
2

0

1 IS II 17 ..

I. 70 71 7Z 73 ,.- 71 71 77 71 71 10 .. II U" II .. 17 .. "

to " .,

n ••

tI~'

A

8
4
2

"M»HUHH~~UO«U"U".IO~q"~"H~U"to~Qfl"B1
,
0:'
I
A

8

W

4
2

0 2

,

4
2

1
B

0 4

,

RECPT

UUUd.nW~~~U""H~VHH~~H~

B
A
8
4

A

A

W8

8
4

2

DATE

ITEMNO

1

B
A

'8

2

~"~.HUHH~~UO«U"U".~~U"~"H~H"~~Q""~
A

p."~~wm~m"maa~maQMM~mM"~mUm~m~~~

1 II II 17 ..

.... 3700

8,

0 4
.
0 2

I. 70 71 71 73 ,. 71 71 77 71 71 10 "

II II .. II .. 17 .. " to " '1 .3 ..

"~

1

.... 3700

Onhand Card

Receipt Card

/

B
A

:

p."~~wm~m"m"~~maUMM~mMM~mum~m~m~

ITEMNO

DATE

B
A

!

ISSUES

2

2

~I 13.117"~"UUu~.n~u~~U"""HVHH~~H~
8
4

A
8
4

2

2

A

~"M.HUHH~~UO«U"U".~~U"~"H~H"~~Q""~

'7

A
8

A
W 8

4

0

4

2

0

2

1 IS .. 17 ..

I. 70 71 71 73 7. 71 71 77 ,. 71 10 .. II .3 .. II II 17 .. I t to "

.... 3700

Issues Card

Figura 4·15. Four Card Types

4·12

t2 n

•••

~,

1

B

p."~~wm~mamaa~maQMM~mM"~mUm~m~~.

.

'B

A

A

e

8

4
2

~I
A

4
2
13.117 ••

~nUUUd.nW~~~U""HH"H"IO~H~
A

8

8

4
2

4
2

1

B 33 M » HUH

3t ~ .,

'

"

U 0 •• U " U • • 10 II II n ... " H P U It 10 .. Q

A

'~

1

B

, A

we

8
4
2 ,
111 .. 17 . . . .

70~7Z73,.7I7I777171IO

.... 3700

New Onhand Card

..

IIU~ . . . . ~ . . . to ..

Q4
02

t2n ..

"~1

Again, you will ne~d four types of specification sheets to
write your program: File Description, Input, Calculation,
and Output-Format. On the File Description sheet, you
must enter the filename, file type, and device (see Figure
4-16, insert A). Since this file is both read and punched,
the file. type ~ust be C to denote a combined file.

)

These cards must be read in a certain order. The onhand
card must come first, the new on hand (blank) card must
come last. The issues and receipts cards may be in either
order, but must always be in the same order for any program. For this program, assume that receipts cards follow
issues. Remember to indicate that cards are to be in a certain sequence by using numeric sequence entries for all card
types. These entries will direct the program to check for
sequence. Figure 4-16, insert B, shows input specifications
for this program.

On the Input sheet, you must describe all four card types
and assign record identifying indicators. These indicators
will be used later to condition those operations which are
to occur only when a specific card type has been read.

On the Calculation sheet, you define the calculations
(Figure 4-16, insert C) which must be performed to determine amount on hand. The record identifying indicators
assigned on the Input sheet are used to condition calculations. For example, only when an issues card is read (02 is
on) will number sold (ISSUES) be subtracted from INSTOK.

File Description Specification

-

File Type

F

Length 01 Key Field or
01 Record Address Field

End 01 File
Sequence

Type 01 File

c

C

~
0:

g
itw
3

4

5

7

8

9

Internatio

I Program

I

Programmer

~p

F

g

11

]

Line
l-

Z

ro :-;;-- i ·l

~
6

1
\

8

t-;" 'Nrc

20

I II

I

III

L ...L

Condition

~

MI~IL

1l!1 I I I I

ling

Graphic

Iction

Punch

I
I

I
I

"E

~

~

~

e

i!!

S<5

~f5
~u

~

g

Position

~c

~§

~~

Field Name

From

]

E

"0

..

To

ill
it

~

~

'in

~ ~ :::;0:

UIM 050'

75 76 77 78 79 80

2

Page [ 0 0 1 _

c

."

~~~~;~I:ation I
.g

0

:E-o
.!!"ii
u..U:

~~

~ i~

.~

c

IIIIII

Field
Indicators

~
"0

J
"0

-.;

Zero

Plus Minus or
Blank

u::

9 10 1 I 12 13 14 15 16 17 18 1920 2122124 2526 27 2B 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45'46 47 4B 49 50 51 52 53 54 55 56 57 58 59 60 61 62 6364 65 66 67 68 69 70 71 72 73 74

I

o

2

I

1

o
o
o
o

3

I

4

I

q
1;

5

I

6

I

1

Is

7

I

111.1

o

8

I

q
15

o

9

I

1 0

I

11

I

@

1

I Card Electro Number
I I

~

';:: 0

69 7071 72 73 74

GX21 ·9094

Field Location

~

sa

Printed in U.S.A.

1

I

60 61 62 63 64 65 66 67

I

3

2

Position

~

~

I

IIIIII I II

4

I

UH~

~

:::l

Entry

Option

K

Record Identification Codes

~

~

INPUT SPECIFICATIONS

RPG

1

Tape
Rewind

Core Index

Continuation Lines

3

1 2

7

Numberol Extents

.::

-1l0

0

o

5

Location

I

I I ~ I II~

Jl

>

~g

I R~ I Iql6

i ::§ ~ ... pO~ion

Filename
0.

(;

::::1-

;)

For the MFCM, change 96 to
80 in these positions and
change the device name.

I

-

!o<:

w

:il

, 0 11 12 13 14 15 16 17 18 19 20 21 22 23 2425 26 27 28 29 30 31 32 3334 35 36 37 38 39 40 4 I 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59

±I FI"IUlNld-,IRlpl
~F
IIII
IBM

~
~~

Record
Length

ill

Number 01 Tracks
lor Cylinder Overllow

Name of
Label Exit

Overflow Indicator ~
..---- 0
Key Field .~
Starting

N

Block
Length

Z

Symbolic
Device

Device

..J

Organization
or Additional Area

File Format
Line

Extent EXit.
for DAM

~

Record Address Type
Filename

)

File Addi.tion/Unordered

Mode 01 Processing

File Designation

1\1

1"IRlp fzllLl

~12N

,..,.
V ..

~11

tll2

1."1 I\! .t"~

F?lh

~~

~,..,

~I

Fill, rR

1

q

!15

rl141

~"I

Alb

IS r I'" 1\1I11~ "A :Tlt;
213 ~1 NS rrl"'liK

r I t:.11'

212 ~r

8

N

I"'I,A IT IE

5S IIJ E. ~
'I- 1'1 NII"\

llLi .I:'A ,TIE

'I:> li~ /=Ir IPT

~

T

)
-,

Figure 4-16 (Part 1 of 2). Specifications for Reading and Punching Combined File Cards

Card Output Operations

4-13

RPG

IBM

CALCULATION SPECIFICATIONS

Form GX21-9093
Printed In U.S.A.

/

International Business Machine Corporation

12

Program
Page

Date

Programmer

c

Indicators

Operation

[00'_ :~:~'~~tion 1

1 1 1 1 1 I

Resulting
Indicators

Result Field

Factor 1

75 76 77 78 79 80

Factor 2

Comments
Name

Line

Printed In U.S.A.

1 2

0

LL

~I
c -

r--

~
l-

4

5

6

8. 1\
~bl

I

]
3

-

;. ...
Q)

Filename

Line

R

Output Indicators

Skip

j!

At
~

~

Ii;

~

l5
z

0

z

L

Field Name

~

7

8

a:
0;

85

0

z

...

1(1

II
~~

'AUTO

f;:"N'D

End
Positon
in
Output
Record

-

Commas

Zero Balances
to Print

No Sign

CR

Yes
Yes
No
No

Yes
No
Yes
No

I

A

2
3
4

B

J
K

C
0

M

L

:~:~':.tion 1

1- 1 1 1 1 I

X ., Remove

Plus Sign
Y • Date
Field Edit
Z = Zero
Suppress

a:

~n:

Constant or Edit Word

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 46 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

0 I

°rJ "1 IN TH iRP

o
o
o

2

0

3

0

4

0

@

Space

ADD

o

75 76 71 78 79 80

pagerno,_

Date

"B

f?jl~
1 J ~"'J N

iA

nA rrl~
IN ~rr "IK

0

-

Is
lLlLI
~13
~Ib

'I(l

~

""'I~ ..... -

I

For the MFCM, change 96 to 80.

:--

Figure 4·16 (Part 2 of 2). Specifications for Reading and Punching Combined File Cards

On the Output-Format sheet (Figure 4·16, insert D) you
must show the fields which are to be punched. Since only
the blank card is punched, punching occurs only when 04
is on. Because the card punched will be used as next month's
Onhand card, ITEMNO, DATE, INSTOCK and a code must
be punched.

When To Specify a Combined File
How do you know whether to describe a card file that must
be read into the computer as an input or asa combined file?
If you remember these basic rules you will have no trouble
deciding.
1.

If the file contains cards that are to be both read and
punched, it must be a combined file.

2.

If cards in the file are to be stacker selected on some
basis other than card type, the file must be described
as a combined file (see Stacker Selection, Selecting on
a Basis Other Than Card Type).

4-14

STACKER SELECTION
Stacker selection is the means by which you can separate
certain cards from all others in the file. If stacker selection
entries are not made, all cards automatically fall into specific, predefined stackers:
MFCU1: Stacker 1
MFCU2: Stacker 4
MFCM1: Stacker 1
MFCM2: Stacker 4 (Model A2) or Stacker 5 (Model
A1)

Note: Unless stated otherwise, this discussion applies to
both the MFCU and the MFCM.

/-

)

Input and Combined File Cards

Selecting on a Basis Other Than Card Type

Input file cards are stacker selected by input specifications.
Combined file cards can be stacker selected by either input
or output specifications.

Suppose you wish to stacker select input file cards on some
basis other than card type, such as the result of calculations,
the results of matching records, or the conten'ts of an input
field. FC?r example, assume that the cards which contain
information concerning new, discontinued, and available
items in the store also contain the amount on hand at the
end of the month. In addition to listing all items, records
of items which need to be reordered are selected to a
separate stacker. The critical reorder point occurs when
there are 25 items or less left on hand. (This, of course,
does not apply to discontinued items.) Thus, in the calculations, ONHAND is always compared to 25. If the
amount is equal or less than 25, the item needs to be reordered. All cards describing items to be reordered are to
be separated from the others in the file by stacking them
in a special stacker.

Selecting on the Basis of Card Type

Stacker selection by input specifications must be on the
basis of card type. This means you may separate all cards
of one type from the input file by specifying a special
stacker into which they should be stacked.
Suppose you want to create a monthly list of all items in a
retail store. Three card types are used: one for new items,
one for discontinued items, and one for all other items.
The manager wants to take all cards describing discontinued
items out of his file. He can do this by specifying the stacker
into which the card type is to be selected. The specification
in Figure 4-17, insert A, line 02, will separate the discontinued item cards (card identified with a D in the last column)
from the other cards by putting them in stacker 2.

)

'~

Notice that the OR relationship was used in describing the
three card types. When stacker selection is done with the
OR relationship one rule must be kept in mind: each card
type will fall into the stacker indicated for it. For example,
Figure 4-17, insert A, shows the stacker selection entry 2
for the second card type. The other card types have no
stacker selecton entry. They are, therefore, stacked in
stacker 1 if they were entered in the primary hopper or in
stacker 4 or 5 if entered in the secondary hopper. According
to Figure 4-17, insert B, card type 02 falls into stacker 2,
card type 03 falls into stacker 3. Where does card type 01
fall? It will fall into either stacker 1,4, or 5 depending
upon the device used and the hopper in which the file was
entered.

Where would you specify the stacker select entry that
would do this? There are only two possibilities - Input
sheet or Output-Format sheet. Remember that input cards
can be stacker selected on the I nput sheet on the basis of
card type only. In our example, not all cards of anyone
type will describe items that need to be reordered. There~
fore, the selection is not on the basis of card type and cannot be specified for an input card on the Input sheet. This
leaves only the Output-Format sheet on which to specify
this stacker selection. But since our file is not an output
file, how could it be specified on the Output-Format sheet?
Remember that a combined file serves for both input and
output. Therefore, a file from which cards are to be
stacker selected must be defined as a combined file.

Card Output Operations

4-15

RPG

IBM

GX21-9094 U/M 050'
Printed in U.S.A.

INPUT SPECIFICATIONS

International Business Machine Corporation

1

.Program

Date

Programmer

2

75 76 77 78 79 80

[I] of _

Page

~~~~;~f:ation I

IIIIII

I

il

I

r--~

Line

I~ §

Filename

Ii
3

4

10

1

5

6

"'0
7

9 10 11 12 13

I I 1i\lIV It"-N

10

2

I

10

3

II

o
o
o

4

I

5

I

6

I

o

7

I

Codes
2

15
Position

!A- I! i

'iA,4 IN" "0

II§

.j

Position

lilR r~A

rll

91b

~2

qlb
qlb

~3

II§IJ

~N
Ir-'n

Ib

L

I ...

112 1

Il: ,., N

A-

I"'IE :f;~

~13
!313

312

i3iq

141 iDA iflE

~Is:t 1'1.,.. Nrl lA Min

GX21-9094

INPUT SPECIFICATIONS

Printed in

,

j
~I§ '1"

Filename

Ii
5 16

I
I

\

Date

Line

iii ]
ro "RrNio
IA

Punching

Instruction

Graphic
Punch

I
I

I
I

I
I

,.. "

~N

IH:IY

"I ..

}ol~

1

Card Electro Number
Page

~\ Il§IJ

Position

II§ J

Position

j§ i iii

t21LL

~!b
~ib
~h

From

To

I Plus Minus

j

kR

(lJ12

II

'rtR

~!-~

:014

II

1

5

10 15

II

I..

112

IItr

EM INn

10 16

II

1~

l~ 2.

IDII=

S,..

II

33

BB ~I'"

~

) II
_

Figure 4-17. Statker Selecting Cards in an OR Relationship

4-16

;q

IIIIII

~l

:~~ro
Blank

0 13

2

I

Field Name

44 45 46 41 4B 49 50 51 '52 53 54 55 56 57 58 159 60 61~

~n

Identification

,

j

roN
("'/"'1

Program

Field
Indicators

II

...J

75 76 77 78 79 80

Field Location

O 12

I~B

2

[I] of_

1

7 8 9 1 0 " ' 2 ' 3 1 '4 1'5 1'6 17 1'8 19 20 21 22 23 24125 126 27 28 29 30 31 13233 134 35 36 37 38

IItr

:017

U/M 050'

u.s A.

I

I

1

72 73 74

-----'--

For the MFCM, change 96 to 80.

~

i

171

--

Programmer

4

III

Plus IMinus ~:ro
Blank

Is DE IplT

lL

I

Program

1011

I~_~

Field Name

Ij

To

44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 5960 161 62 63 64 16566 167 68 69 70

~;!~i-.· -•.

Ir-Io-'i

RPG

I

III§ IJlh

From

I

IBM

3

Position

I

_

Field
Indicators

Field Location
3

20 121 22 23 ~. 25 126 127 2B 29 30 31 32 133 34135 36 37

r"'IlR
OIR

t:@Ir,'"

-I

8

Record

ID~ PT

111\

ID~ TF

n

~4 165 66 6758 169 70 71 727374

card types by input specifications and others by outputformat specifications. However, one card type should not
have both types of stacker selection specifications. If it
does, the input entry is ignored. Furthermore, if you are
punching or printing on combined file cards that are also
to be stacker selected, the stacker selection entry must be
on the Output-Format sheet.

Figure 4-18 shows the entries which are necessary to stacker
select all cards (except discontinued) cards) which contain
25 or less in the ONHAND field. The file would be described as a combined file by placing a C in column 15 of
the File Description sheet.

)

Figure 4-18, insert A, shows that the ONHAND field is
compared with 25. If the compare is equal or less, indicator 10 turns on to indicate that the item should be
ordered. Indicator lOis then used on the Output-Format
sheet to condition the stacker selection entry (Figure 4-18,
insert B, line 01). When 10 is on (there are 25 or less of
the item left) and the card is not a discontinued item (indicator 02 is not on), the card is selected into stacker 2.
All other cards go into stacker 1.

Stacker Selecting Output File Cards
Output file cards are stacker selected by' output specifications. For example, stacker selection by output specifications can be made on the basis of results of calculations,
matching records, content of fields, and error conditions.
Output stacker selection can be based on card type, but
card type selection is usually done with input specifications.

Rules for Stacker Selecting Cards from a Combined File

Consider an end-of-the-month inventory program that: (1)
finds the balance on hand for each item,(2) determines if
and when an item should be reordered; and (3) finds any
items that are overstocked.

Combined file cards can be stacker selected by both input
and output-format specifications. Input stacker selection
is based on card type alone; output stacker selection can
be on any other basis. In fact, you can stacker select some

RPG

IBM

Form GX21·9093
Printed in U.S.A.

CALCULATION SPECIFICATIONS

I.,ternattonal BUSiness MAchine Corpor,tion

12

Program

'\

..

Page

Date

Programmer

)

C

Indicators

~

=0

Line

4

o

'_d

Operation

Factor 1

At

.g :t

Factor 2

5

II)

Plus IMinusl Zero

~~

~

8 5-

~

7

9 10 1112 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 5051 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

8

0

z

0

z

I lbj Il~ 11111111111111
I I I lIilllllllllll

~NI~lAINIDI

I I I r1jMPI 2151 I II I I I I II II I I I
I 1'1 I r II T I I II I I ITT TTIf T I I 1'1 I I I

I
I

C

RPG

GX21-9090

SPECIFICATIONS

OUTPUT

1

Page

Date

Programmer

0

~ Space

Output Indicators

Skip

~~

I---

I

0-

Filename

line

~~

~

~ «~

~ -jj III

~~

"A Co 0

1-

j

~.!!-

And

Field Name

L

~ ~

0

OJ

:t

0

z

0

z

4

5

6

8 U

0

z

~~

'AUTO

05IEIL~UrI

@a
,I

,

111111
I

f;;>
End
Positon
in
Output
Record

Zero Balances

Commas

to Print

Yes
Yes
No
No

II

2

OJ

No Sign

CR

1
2
3
4

A
B
C
D

Yes
No
Yes
No

75 76 77 78 79 80

~~~;~f:ation 1 I,

of_

1I I I I

X = Remove
Plus Sign

Y = Date
Field Edit
Z = Zero
Suppress

J
K

L
M

0::

g

Constant or Edit Word

Q:

9 10 11 12 13 14 15 1617 18 1920 21 22 2324 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

8

7

f

0::

AND

3

U/M 050-

Interl"lational BUSiness Machine Corporatton

Program

1'1.1

Comments

Compare

g

~ 1>211<211=2
'u - Lookup(Factor 2)is
o ::t: High Low Equal

6

@c

IBM

Length

Name

a:.~

E ::.

3

AL

IIIIII

Arithmetic

c

-'0::

~~~
..... 0

757677787980

~~~;~f:ation I

of _

Resulting
Indicators

Result Field

0_

~

OJ

I

I

I

J)2

I I
I I
I

I

11t?S tJ~,

I II II
IIIII
I

I

I

I

I

III
I II
I

I

I

II I III I I I 111111 I I I II I I I I I
I I I I III I I I I I I I-I 1111111 I I I
I

I

I

I

I

I

I

I

I

I

I

I

1

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

Figure 4-18. Stacker Selection on the Basis of Calculations

Card Output Operations

4-17

Two files are used: an input file and an output file. The
input file contains three types of cards (Figure 4-19):

1.

2.

Inventory Balance cards, which contain the number
in stock ,at the beginning of the month, and the maximum and minimum quantities which should be kept
in stock.
Issue summary cards, which contain the total number
issued during each week. Since this is an end of the
month job, there may be several of these.

I

B

2

3

..

5

6

7

8

9

10 11

12 13 '4 15 16 17 19 19 2021 U

23 z.t 25 26 27 28 29 3031 32

97 ..ge-!9'"1OO 101 ta2 103 104 105 106 107 108 log 110 111 112 tl3 114 1T5 H6 117 118 119 120 121 122 123 124 125 126 127 129

B

A
8

A
8

ITEMNO

4
2

,

DATE
8

B

9

10 11

INSTOK

1213 "

15 t6

MAX

4
2

,

B

1718 19202122232' 25 26 27 28 29 30 31 32

A

A

:

!

MIN

,

,

2

2

Bn~~~"~»~~~~«~~a~U~~~~~MM~~»~~~~HB

3.

Receipt cards, which contain the number added to
stock through reorder.

8

W8

4

04

2

Each item must have a balance card. The other two cards
are optional. The output file contains blank cards.

02

~"~""ronnnu~nnn»~~~~ue"~~"~~nn""~'

,

181013700

Inventory Balance Card

For each item, the total number in stock will be calculated
from information on the input cards and then punched into
a blank o~tput file card along with all other fields found on
the balance card. The format of the output card must be
the same as the input balance card, since this output card
is used as the balance card for next month's inventory.
Before the balance on hand is punched into the blank cards,
the amount is compared to the maximum and minimum
quantities in stock established for each item to determine
reorder procedure. As a result of the comparison, four conditions could occur:

~A

A

1

2

3

..

5

6

7

•

9

10 11

12 13 '" 15 16 17 18 19 20 21 Z2 23 U

25 26 27 28 29 30 31 32

A

A

8
4
2

ITEMNO

~I

23.

'67

DATE
••

8
4
2

ISSUES

~"~U~U~~~uro~unN~nnHn~~n~

A

A

8
4

8
4
2

,

.,

2

B~~~~"~»~~~~«~~a~u~~~~~MM~~"~~~~HB

1.

If the amount in stock is zero or back-ordered, the
item should be reordered immediately.

A

W8

04
02

,

2.

If the amount is greater than zero but equal to or
. below the minimum, normal reordering procedures
should be followed.

3.

If the amount is between maximum and minimum,
the item does not need to be reordered.

4.

If the quantity is greater than the maximum, the
manager should be notified of the overstocked item.

Instead of putting all newly punched balance cards into
one stacker, it would be more convenient, when preparing
to reorder, if they were stacked into different stackers:
one stacker for items requiring immediate attention (reorder immediately or greatly overstocked), one for items
to be reordered normally, and one for items which need
not be reordered. To separate them, you specify different
stackers they could go into on the basis of the amount in
the INSTOK field.

A

8
4
2

~"67""

70

n n n

7.

~

76

n n

79.0., .2.3 U

0••• 07 ••••• 0., .2

.5Yo '

Issue Summary Card

I

B
A

2

3

..

!Ii

6

7

8

9

10 11

12 13 '''' 15 16 17 18 19 2021 Z2 Z3 2. 25 26 2728 29 30 31 32

~M"~~~m~m~m~~Mm~ru~~~mMM~m~mm~mmm

8
4

ITEMNO

DATE

B
A
8
4

RECPT

2

2

~I

23.

'.7

••

~"~U~U~~~u~~unN~nnHn~~n~

A

A

8

8

4

.4

2

2

~n~~~"~»~~u~«~~a~U~~~~~MM~~"~~~~H~

q:. A

A

8
4
2
1

W

0

0

65 66 67 68

n

70 71 7Z 73 74 75 7$ 77 7111 79 80 8T 82 83 U

85 86 87 88 89 90 91 92 93 , .

181013700

Receipt Card
Figure 4-19. Cards Used for Inventory Job
4-18

n"

111013700

g~,

8
4
2
1

From which file do cards come that are to be stacker
selected? They come from the output file since they are
the. newly created balance cards. Therefore stacker selection entries must be made on the Output-Format sheet.
Stacker selection entries are on the basis of the compare
operation. Thus these compare operations must set indicators whi,ch will be used on the Output-Format sheet to
indicate into which stacker cards must fall. Figure 4-20
shows the program specifications.
Figure 4-20, insert A, lines 01, 02, shows operations used
for finding the number in stock. When a control break
occurs (a card for a new item is read) the number in stock
is compared as many as three times (lines 04-06) to determine into which stacker the cards should fall for reordering
purposes. Resulting indicators are set off (line 03), since
improper selection could otherwise occur due to multiple
indicators set for a single condition.
INSTOK is first compared to zero. If it is equal or below,
indicator 10 is turned on. If INSTOK is greater than zero,
it is compared to the minimum quantity. When INSTOK
is equal to or less than minimum, indicator 20 is turned on.
If INSTOK is greater than minimum, it is then compared
to maximum. Indicator 10 is turned on if INSTOK is
greater than maximum; indicator 30 is turned on if it is
equal or less.
)

Any of these indicators can be set: 10, 20, 30. Since they
indicate the amount in the field INSTOK, they also indicate
into which stacker cards should fall. (See Figure 4-20, insert B.) If lOis on (I NSTO K is zero or less or greater than
maximum) cards go into stacker 4. If 20 is on (I NSTOK is
greater than zero, but equal to or less than the minimum),
cards go into stacker 2. If 30 is on (I NSTOK is greater
than MI N but less than or equal to MAX) cards go i!1to .
stacker 3. In all cases, five fields and aconstant are punched
punched on each blank card before it is stacked.

Merging Input and Output File Cards
Putting cards from two different files into the same stacker
is known as merging cards. Any two files can be merged.
To do so, you merely specify the same stacker for each file.
When input and output file cards are merged, the output
file card for each program cycle is stacked in front of the
input file card read at the beginning of the cycle. Why are
output cards stacked before input file cards? According to
the way the MFCU and MFCM operate:
1.

An input card is not stacked until the next input card
is read.

2.

Any output card that is punched is stacked immediately.

These statements are the key to the order of merging. Consider what this means during a regular program cycle. When
an output file card is punched, it is stacked. This could be
either at total time or detail time. However/the input card
read at the beginning of the cycle is not stacked until the
next card is read. This results in the output card being
stacked in front of the input card. Most often, however,
you would want the merged cards ordered so that input
cards precede output cards.
Reversal of the normal stacking order can be accomplished
by specifying look ahead fields or dual input areas for the
input file. When either of these is specified, input cards are
stacked before output cards.
Stacker selection cannot be specified for input files with
dual input areas. Therefore, if you wish to merge cards
from the input and output file, you must merge the cards
into the default stacker for the input file (defined previously - see Stacker Selection).

Rules for Stacker Selecting Cards From An Output File

If no stacker selection entry is made for the output file,
cards automatically fall into predefined stackers - stacker 1
if the file is in the primary hopper; stacker 4 if the file is in
the secondary hopper. You maYi however, cause cards to
be stacked in any of the four (or five) available stackers
merely by entering 1, 2, 3, 4 or 5 (5 for M FCM Model A 1) in
column 16 of the Output-Format sheet.

All cards from the same file will fall into the specified

---., ·'1

stacker unless indicators are used in columns 23-31. If,
as in this example, you want cards to fall into different
stackers, you must use indicators set by calculation operations to condition the stacker selection specifications.

J
Card Output Operations

4-19

RPG

IBM

Form GX21·9093
Printed In U.S.A.

CALCULATION SPECIFICATIONS

International Business Machine Corporation

1 2

75 78 77 78 79 80

Program

Programmer

D.le

Indicators

C ~=0

~

..Ja:

a:
E E~
.f 85

1

Operation

Factor 1

.~

Factor 2

4

5 6

o
o
o

1

C

2

C

3

C

4

C

5

C

7

Arithmetic

X

Plus IMinu.1 Zero

~i

9 10 1112 13 14 15 16 17 18 19 20 21

n

23 24 25 26 27 2829 30 31 32 33 J4 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 5051 5253 54 55 56 57 5859 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

II N ST ""K
IRE r pJ"

lL
11
111M Il~
IllN llW1 INI212

tTlc; 1_~I'j ~~

lIN Sh'" IlH<

tIN str ~~

lIN ~rr r..K

Sil
5~

il

TOF

,.,..., MP Itll

It ,\I s- '.... !I\
1,'4~

~

An"

ll.~ i~
12.~ 2~

r,..., M'P IMIIN

n

LIN ~T JIK

rrt 'MP

IMAI)(

RPG

OUTPUT

II
aX21·9090 U/M 050·
Printed in U.S.A.

SPECIFICATIONS

International Business Machine Corporation

1 2

Program

Programmer

Page

Date

0

S Space

Output Indicators

Skip

@"§
t: .f

.....
;.
-

1L

0'"

; ~

Filename

Line

~ ~
I- US

~
I-

4

5

6

~~

f-;"o'o

E

o

of
3

R

"Ar;:;ro
7

8

j

E

<

0

0

Field Name

z

frl
a:

l:

q;

;3 5

0

z

z

·AUTO

~ ~

8>
End
Positon
in
Oulpul
Record

olp LJ'N ~IH

tr~

1112

o
o
o

2

0

f'I'RI2

12.~

,....I~~

I~tt

'r

1.

0
0

It IT

rM IN"'"

IR

0 5

0

0

6

0

~ID lA,Tlc
t~N 1ST ~K

o

7

0

lll"l
12B
312

o
o

8

0

9

0
0

-

Figure 4-20. End-ot-Month Inventory Job

4-20

Zero Balances
to Print
Yes
No
Yes
No

No Sign
1

--

X ..

CR
A

J

2

B

K

3

C
0

M

4

I. 1 1 1 1 1

l

Remove

Plu.Sign
Y - D.,e
Field Edil
Z •

Zero
Suppress

a:

g

Constant or Edit Word

it

1
1

3

I

Yes
Yes
No
No

I

4

®

Commas

75 78 77 78 79 80

[00'_ ~~;~':"ion I

9 10 11 12 13 14 15 1617 18 1920 21 22 23 24 2526 27 28 29 30 31 32 33 34 35 36 37 38 39 4041 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

0 1

.

Comments

Compare

1>211<211-2
~i Lookup(Factor 2);.
OJ: High Low Equal

C

IBM

-

I I I 1 1 1

2 "',;

~

z0

0

z

~~
r2jl3

C

®

8

Length

Name

~~~;~':alion I

R.sulting
Indicators

Result Field

,.... "0

3

o
o

At

~.5~

Line

P.ge[Oo,_

MIA Ix

MIL IN

i

411
qlb

...

I
I

~

,

'lA'

For MFCM, change 96 to)O.
1 1 i-~I

I I I I tiTl

~

--f--f-

·1 I 1 1 I 1

Review 4

)
Punching and Printing on Cards
1.

Why is it important to print on a card the same information punched in a card?

2.

Using the following information, write the output-format specifications to punch
and print the following fields on output cards:

Field

End Position

CUSTNO

5

NAME

26

AMT

32

INVNO

38

DATE

44

2 (constant)

96 (use 64 for MFCM)

The information should be printed in the same relative positions as it was punched.
Do not use *PRINT for this. For the MFCM (Model 15 only), use print head 1 for
all fields.
3.

Do problem 2 using *PR INT.

)
Using One File For Both Input and Output
4.

When should a file be specified as combined?

5.

If all master cards in a file are to be separated from item cards in the same file, the
file type should be specified as _ __

6.

True or False? Both printer files and card files can be combined files.

7.

An electric company wishes to find the amount each customer owes for the electricity
he used during the past month. The input file consists of three types of records for
each customer:
•

READ1 which contains the meter reading at the beginning of the month.

•

R EAD2 which contains the meter reading at the end of the month. This card
will be used as next month's R EAD1 card. It now contains a blank in the last
column, and must therefore be punched with a 1 in the last column.

•

AMOUNT DUE which contains a blank field (AMTDUE) which will be punched
with the amount each customer owes.

For each account these three cards must be present and in the order indicated.

)
Review 4

4-21

1

B
A

2

3

4

5

6

7

8

9

10 T1

12 13 14 15 16 17 18 19 2021 22 23 24 25 26 27 28 29 3031

~~~a~am~~~m~~MmmQMMmmMMwm~mm~mm~

:

NAME

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 2 0 2 1 2223242526272829303132

32

B
A

B
A

ADDR:

:

2

2

2

1

,1

B

~

A

A

B

1213 14 15 16

17181920212223242526272629303132

A

a

2
1

1
1
B 333435363738394041424344454647484950 5152535455565758596061626364 B

1

2
17 18 19202122232425 26 27 2. 293031 32

~
A

a

READ2
33 34 3536 37 38 39 40 41 42 4344 45 46 47 48 49

so

51 52 53 54 55 56 57 58 59 60 61 62 6364

4
2
1

B

~A

A

A

Wa

a

a

4

4
2

4
2

1

~~D~~MnnH~~.nn~~~~~MM%DMM~~~~~~%1

0

4

2

B

B
A

ADDR:
1213 14 15 16

4

4
2

A
a

NAME

a

a

READ1

4
2

~M~a~am~~~m~~MmmQMMmmMMwm~mm~mm~

82

~~D~~MnnH~~.nn~~~~~MM%DMM~~~~~~%1

IBM 3700

IBM 3700

READ1 Card

READ2 Card

1

B
A

a

4

2

3

4

5

6

7

8

9

10 11

12 13 14 15 16 17 18 19 202' 22 23 24 25 26 27 28 29 30 3'

32

~M~a~am~~~m~~MmmQMMmmMMwm~mm~mrnrn

NAME

a

ADDR

4

2

2

1

1213141516171819202122232425262726293031 32

B
A

a
4
2
1

B

B
A

~
A

a

AMTDUE

4

33 3435363738394041424344 4546474849

so

51525354555657565960616263;;'

A
a

2
1

B

A
Wa

0

4
2

4

02
U 1

1

~~D~~MnnH~~.nn~~~~~MM%DMM~~~~~~%

IBM 3700

Amount Due Card

The program 'must:
• Find the number of kilowatt hours (KWH) of electricity used during the month. The
reading has two decimal places.
• Multiply the number of kilowatt hours used by rate per kilowatt hour to find amount
due. (AMTDUE has 2 decimal places.). Rate is $.05 per KWH for the first 50 KWH,
then $.02 per KWH for all over the first 50 KWH.
• Punch the amount due on the appropriate card.
• Separate all three card types into different stackers.
Make the necessary entries on the File Description, Input, Calculation, and Output-Format
sheets.

4-22

/

Stacker Selection

)

8.

If stacker selection is specified on the Output-Format sheet during detail output
for card 3, which card will be selected? Which card will be selected if stacker selection is specified during total time output after control group A?

B

- 4

-

-

-

)

9.

3

2

1

At each stop they make, drivers working for a fuel oil company record beginning
and ending meter readings and the number of gallons of oil delivered to the customer.
Later the account number, meter readings, and gallons delivered are punched into
cards.
All regular customers are charged 15r,t per gallon. However hospital and government
agencies receive a 2% discount. The code to show which customers receive a discount is in the account field. If the last digit is 0, no discount is given; but if the
last digit is 5, the discount is given.
Write the calculation and output-format specifications to:
a. Check the driver's calculations in determining gallons delivered to each account
by subtracting beginning meter reading from ending meter reading.
b. Calculate the amount charged to each account (AMOUNT).
c. Find total number of gallons sold for the day (TOTALG) and total amount
charged (TOTALA).
d. Print a report listing daily transactions and totals. If there is an error in driver's
calculations, print the account number, code, and a message,'CALCULATION
ERROR'.
e. Stacker select cards for customers receiving discounts into stacker 2. All others
go into stacker 3.

Review 4

4-23

Answers to Review 4

)
1.

Printing the same information that is punched on a card:
a. Enables you to easily see what is on the card. You don't have to analyze each
punch combination.
b. Makes it easier to recreate a card that is damaged to the extent that it cannot be
processed.

2.

RPG

IBM

GX21·9090 U/M 050'
Printed in U.S.A.

SPECIFICATIONS

OUTPUT

Intern.tional BUlin,u Machine Corporation

1

2

75 76 77 7a 79 ao

Program
Programmer

-

Date

0

S Space

~~
c!t
Filename

Line

Ii

~

8

oro

Jd

!!

~

~ 0
« z

0

z

1

I
~

;5

0

z

'AUTO

v

'(ij

.";E

End

Positon
in
Output
Record

9 10 11 12 13 1415 1617 18 1920 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

4

1

Op RI Nh"

2

0

3

0

4

0

o

6

0

nlVN

I~B

o
o

6

0

lnA TIE

ILj~

7

0

o
o

8

0

,.

9

0

I 0

0

I I

0

2

0

I 3

0

D

I-

S Space

Filename

~ ~
....

E

~

12t..

t\MT

!~2

7

8

~*"o

~b

AMT

InA ,TI~

~12l .~A
~OJ :L,~

~

~

Jd

j

~ zs
«

0

z

Field Name

L

CR

1

A
a
C
0

2
3
4

J
K
L
M

X
Remove
Plus Sign
V - Date
Field Edit
Z = Zero·
Suppress
g

Constant or Edit Word

' 2..'

\2

71 72 73 74

~

;3

0

z

'AUTO

~

End
Positon
in
Output
Record

9 10 11 12 13 14 15 16 17 18 1920 2122 23 24 25 26 27 29 29 30 31 32 33 34 35 36 37 38 b9 40 41 42 43

I

2

0

~J SrrN

3

0

4

0

o

5

0

o
o

6

0

INA 'M~
IAMT
lIN VINO
bA rr If:

7

0

a

0

r155

SiT .Nh

1L121"
11132

lIN V~'O
IhA TI~

I

3

0

I 4

0

J
K
L
M

X • Remove
Plus Sign
V - Date
Field Edit
Z = Zero
Suppress

cr:

~

Constant or Edit Word

«%%U~G50~~~~~~~~~50~~~M~~~~~ro

"2

I

lL Irl5

~MT

0

A
a
C
0

71 72 73 74

~.LI

INA 'MIl:

0

CR

I
2
3
4

I~e

0

I

No Sign

Ves
No
Ves
No

I~~

0

2

Zero aalanc..
to Print

Ves
Ves
No
No

5

9

I

Commas

~'b

I 0

I

f--

0::

Ib4
if'

ISolution for MFCU I--

I

...

f:jJ

I

4

o
o

No Sign

«%%U~G50~~~~~~~~~50~~~M~~~~~ro

~Qj III 5

f*0 12b
r.¥OJ 32.

3

n

Ves
No
Ves
No

5

SiT N~

o
o
o
o

Op Rlr INT

Ves
Ves
No
No

IIIII

cr:

Output Indicators

Skip

~~

'"
r;;-oro

....~

6

~t

Zero Balances
to Print

~0::

f*a1 Qb
e~
c!t

5

sir 1\11"
NA ME"

IT N V~"

0

Commas

~~~:~f:ation 1 I.

(lj:5

INA MI~

Line

J

~

~~

"
Field Name

3

-

7

..

Output Indicators

Skip

o
o
o
o

I

6

Ii t
~~

o R
A~7i

~
5

~~

iA

E

)

pageDJof_

I

-~f-

Solution for MFCM

1=-

-f-f-f-f-

1l.1~g

lllL4 4 I
111~ L/

\ 2.

I

Answers To Review 4

4-25

3.
RPG

IBM

GX21-9090 U/M 050·
Printed in U.S.A.

SPECIFICATIONS

OUTPUT

Intern.tionel Business Machine Corpor.tion

1 2

Program

Page

Dale

Programmer

0

iL Space
-'1:

c ,-

. . iP>

Output Indi~ators

8.

~

I-

G.I

:;'A~ '-0 -=0 ~

~

E

~

7

8

o
Z

Field Name

,I

And

Positon
in

Z

·AUTO

Zero Balances
to Print

Ves
Ves
No
No

Ves
No
Ves
No

No Sign

X

CR
A
B
C
0

V

J
K
L
M

.
.

Remove

Plus Sign
Date
Field Edit

Z = Zero

Suppress

cc

Constant or Edit Word

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 323334 35 36 37 38 39 4041 4243 44 45 46 47 48 49 5051 52 53 54 55 56 57 58596061 626364 6566 67 68 69 70 71 72 73 74

3

4

1

o
o
o

2

o

r

3

o

~AIME

2h

4

o

AIMlr

32

o

5

o

INIVN

~B

06

0

~~ITf

~4

0

Commas

::J
iii
ii:

Output
Record

0

o

o

6

I

~I
And

~~~~

-

Filename

Line

5

Skip

e~r,-+--'---r----r----r---~

r---

75 76 77 78 79 80

[DOf_ :~;~f:ation I I I I I-II

PIRiI NT
15TN~

5

8

I I I I I I I I I I I I I I I I 11.1

4.

A file should be specified as combined if it is both read and punched or if cards
from the file are stacker selected on a basis other than card type.

5.

Input (stacker selection is on basis of record type here.)

6.

False, only card files can be designated as combined files.

/-

7.

File Description Specification
..

File Type

F

Mode of Processi ng
Length of Key Field or
of Record Address Field

File Designation

r---

End of File

Record Address Type
Type of File

Sequence

Filename

Organization

File Format

or Additioni" Area

Line

c

e~
go:

E
.f

::::-0: w~u.

8.

3

4

5 6

a~

7

8

9

2

3

4-26

-

I I

~

c~

N

Block
Length

Record
Length

~

0:

0:

-

Overflow Indicator

Symbolic
. Device

w

a

Starting

Location

Number of Extents
Tape
Rewind

Core Index

~'

~
Condition

"
Key Field .~

~

;:.

~ ::::

::J

Device

...J

Number of Tracks
for Cylinder Overflow

Name of
Label Exit

UH~

Continuation Lines

~

K

Option

Entry

~

:::>
~

~

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 3334 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 6G 67 68 69 7071 72 73 74

.. I.... I..... I_I I I It"lp
...
01 1 FI_IJ'LIWIIJI
01 1 F I I I I I I I
- I .1

e

~

File Addition/Unordered
Extent Exit
for DAM

I

I I

I I

If:

I IQI~ II
I I I

~I~

I I

II

For MFCM, change 96 to
80 and change the device
name.

I III

I III
I

I I I

IMII= t.lu lL I I

" "I I III
1111"
I I I I I I
I" I II

" I II 1/111
I1/
I
J
I I I I I
II II
I I I" I

I

~I

I

I

I

I

I

I I

Page of GC21-7567-2
Issued 30 June 1978
8yTNL: GN21-5616

RPG

IBM

GX21-9094 U/M 050·
Printed in U.S.A.

INPUT SPECIFICATIONS

International BUSiness Machine Corporation

1

Program

Page

Date

Programmer

I

Record Identification Codes

B

j'0
:;:§

0-

Jl

1-

"Qr-;- il

~

Z

A'NO
3

4

a

1

5

Ilr

6

7

0

2

I

0

3

I

8

9

0

Position

I

~~j

Z

U

w
Position

-

~
~

e.
N

2i

~

Position

~

~u6

u

~o
o~
Z

u

-"

Field Name

-~

From

Jii

8

eHll bJl

~~ lel

I
I

0

6

I

II

0

7

I

135 lAin DR

a

8

I

lLlb
3{'"

o

9

I

1 0

I

1 1

I

II
l-'b

115 IN;A IN J:
!3~ lAin In R

131b
~211

rz'~ll

(t)2

191b

IQ~

~I~

IA

For MFCM, change 96 to

-5 :s

"0

~6 u:

Zero
Plus Minus or
Blank

0;

'~!A IME

lL~

I" f)i2
~L V:K !t-~
...,,1 ...

80.1 r

Form GX21·9093
Printed in U.S.';.

CALCULATION SPECIFICATIONS

International Business Machine Corporation

Eer
C

1

I

Indicators

~

0_

AL

.Jo::

~j~

~ '0

~

85 ~

~

6

7

8

-75 76 77 78 79 80

of _

~~~~;~f:ation

UJJIIJ

Arithmetic

I

Factor 1

And

0

2

OJ

Resulting
Indicators

Result Field

Operation

.g

Factor 2
Name

cr."
en

E

Page

Date

~e

Length

J:

~ ~

~~
u -

0

Plus IMinusl Zero
Compare

Comments

1>211<211-2
LookuplFactor 2)is

Z
Z
OJ: High Low Equal
9 10 1112 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 5859 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

o

1

C

02

o

2

c

(l12

o

3

C

-

£''11 1'17

rz2 A.5i

o

4

C

o

5

c

a

6

C

~2

o

7

c

Q;2 ~q

o

8

C

f-

"0

~l4

I

5

;l!

u...u: a
.S ~ ~

n l,

~~-m-_~~~~____________. -_____________~

4

a

31-0
.~ "ii

Ir-

RPG

3

Field
Indicators
a

lL~ INIA IME
13 _~ lAiD IDR

1
Illb

4

Line

IIIIj I

lL

5

-

~;~~;~f:ation I

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 2526 27 28 29 30 31 3233 34 35 36 37 38 39 40 4142 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 6566 67 68 69 70 71 72 73 74

IAR IDS

-

)

.3
g

~

0

IBM

0;

0':
~

To

0

1 2

~

0

~

Filename

Line

3

2

1

75 76 77 78 79 80

of _

Field Location

:J

]

'---

2

OJ

rl.2 Iqq

Iqq

iRI~ lAlnl2
!-lIn iRIt;
~h II 1~1c;

15~
IJ.lh

IRS

iR11= Alnll

5 JIB

~h

I Rlc;

1712

qq

"'n iMlp ;~
,J't1 I II
~5

lAlM TO It ~

1712111

1"111 llir

.~5

!AIM TD liE.

IH

Sit

sieJ

~h

rr

iB

IJJln 1111~c;

Mll Idr

It\lr'n

ADlo

~2

AIM Tin liE

IRl5

l4IMT
IAIM Tn rUlE

712~

Answers To Review 4

4-27

Page of GC21-7567-2
Issued 30 June 1978
By TNL: GN21-5616
RPG

IBM

GX2' -9090

SPECIFICATIONS

OUTPUT

12

CD

Program
Programmer

Page

Date

0

~ Space

Output Indicators

Skip

~!

,--

I

0-

~i
~~
~J5
~

Filename

Line

~
5 6

"

And

ADD

l-

3 4

U!M

050·

PTintedin U.S.A.

International Business Machine Corporation

~~AND
7 8

a

1

O~

a

2

0

a

3

0

a

4

0

a

5

0

9 '0 "

CD

:t

0

L

z

IT

End
Positon
in

a:

~ ~

8 U

0

0

z

[?>
Field Name

z

Output

~ ~

·AUTO

Record

II

757677767960

~Z~;~f:ation 1

of _

Commas

Zero Balances
to Print

No Sign

CR

-

Ves
Yp.s
No
No

Ves
No
Ves
No

1
2
3
4

A
6
C
0

J
K
L
M

I_ 1

I

I

I

I

X = Remove
Plus Sign
= Date
Field Edit

V

Z = Zero
Suppress

a:

Constant or Edit Word

-'
CD

ii:

'2 '3 1415 '6'7 '8 '9 20 2t 22 2324 2526 2728 29 30 3' 32 33 34 35 3637 3839 4041 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 7, 72 73 74

lAIR nc:;

riJ2

n2

I

-f--

1'116

I

I

I

I

I

I

I

I

I

1

I

I

I

I

I

1

I

I

I

f-r.-I-

.-f- ~ For MFCM, change 96 to 80.

.1 '

f-I-I-

~3

D3

~12

AIM riD ~IF

1--'-1-

I II I 11111 II I II I I 111
IIII IIIIII IIIIIII
III

I

1

1

1

1

I

1

1

II!

1

III

1

I

Since cards in this file are to be both read and punched the file must be defined as
a combined file (C in column 15 of the File Description sheet). The card type
identified by a 1 requires no punching, and therefore can be stacker selected on the
Input sheet. A 1 was entered in column 42 of the Input sheet to indicate the stacker.
Leaving this column blank would also indicate that the card type goes into stacker 1
because cards entered in primary hopper of the M FCU are automatically stacked in
stacker 1. Output operations are performed on card types 02 and 03. Stacker selection is, therefore, specified for each on the Output Specifications Sheet in column 16.

8.

a. Card 3 - the card that is being processed.
b. Card 3 - the card which caused the control break.
\.

9.

RPG

IBM

CALCULATION SPECIFICATIONS

Form GX21·9093
PTinted In U.S.A.

International Business Machir-e Corporation

--~~~------r----'--'---'---'LHEEJ

1

Card Electro Numberl
Page

-

C
line

Indicators

j

3 4

zex:

At

~
a:
8

0

9 '0 "

a

1

C

I

~lL

a

2

~l

a

3

c
c
c
c
c I
c

a

4

a
a

5
6

a

7

:~c
a

9

I

a

c
c

11

C

1

2

c

1 3

C

4-28

I

I

I

I

I

Resulting
Indicators

Result Field

At

Factor 1

Operation

.g I

Factor 2
Length

Name

-' z

5 6

75 76 77 78 79 80

~~~~;~f:a!iOn 1

of _

Arithmetic

a:0

!

2

CD

~ ~

I

Plus Minusl Zero
Compare

Comments

1>211<2 1-2
~ ~ Lookup(Factor 21is
U ~
0
c
z
z
a I High Low Equal
'2 '3 '4 15 16 17 18 '9 20 2' 22 23 24 25 26 27 2829 303' 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 505' 52 53 5455 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

--

- - I-C~~
1:\ JR
J:
17 INIr..
1-- -

rblRIR IElr
rll
l~ ~11
G'A Ll hlN
if]) ~12 ~lL
pU!Nir
10 rll~ ~l h'U
lll5 ~lL
AIM OJ INiT
r-,IA thiN
l~ ~lL

~~ Nrr

r'""N!p

rOMP
M

JT

\ L'1' I I I
AIFIGlr IIJI t==-_ r

G~~~
~
-to'
+- ,
.' 12--li I
[;~~ I I

If
~f1AD~

r!drlAlLIG

-,=H=

-L'1
ryt

IblT'~iLk

1_J±!
f-I-I=

1

,

1

I II I

I

I

I

1zj2 IGlr IV~ [)Ir 5'1' ~il NIT?
~IH 1r;"'K

bil

11"(1-\' t-

J9 t9 Z9 19 09 65 as L5 9S 55 I'S

ts

~5

15 OS 6t lit Lt 9. 5t .. tt

~t

It Ot 6t at Lt 9t 5t rt tt

~t

It Ot & &

L~ 9~ 5~ t~ t~ U

Il Ol 61 81 LI 91 51 VI tl II II 01

6

8

L

9

5

•

ell

You must be certain to check to. see if the code is 5 or 0, The resulting indicator showing the
result of the compare is then used on the Output-Format sheet to show into which stacker
cards should fall. Stacker selection must be specified as a detail operation so that the correct
card will be selected, Any report formatting you choose is acceptable,

)
Answers To Review 4

4-29

/'

,/

./

4·30

Chapter 5. Controlling Operations I n An RPG II Program

)
CHAPTER 5 DESCRIBES:

Additional uses of indicators to control calculations and output.
Controlling operations on the basis of the next record in a file.
Manipulating data by moving it from one field to another.
Saving storage space and coding in calculations by using branching and subroutines.
Special uses of control level indicators.
Binary field operations.
Increasing the speed of RPG \I operations.
BEFORE READING THIS CHAPTER YOU SHOULD BE ABLE TO DESCRIBE:

General usage of the following indicators: 01-99, MR, L1-L9, LR, 1P, OA-OG, OV.
The concept of matching records.
Coding of arithmetic operations in calculations.
RPG \I object program cycle.
AFTER READING THIS CHAPTER YOU SHOULD BE ABLE TO:

Control calculations and output using H1-H9, U1-U8, and Resulting Indicators.
Condition calculations using OA-OG and OV indicators.
Use the RPG \I look ahead feature. '
1

Code specifications to move data fro'm one field to another.
, Branch in calculations using GOTO and TAG.
Employ subroutines in calculations using BEGSR, ENDSR, and EXSR.
Cause an artificial control break and total operations using LO.
Use control level indicators to perform group printing.
Control calculations using binary switches.
State advantages of dual input/output areas and correctly code for them.

Note: You can use the,review questions contained in Review 5 at the end of this
chapter to test your comprehension of each topic in the chapter. Questions are
grouped according to the topic to which they apply. Answers follow the review
questions.

Controlling Operations In An RPG II Program

5-1

INTRODUCTION

There are many ways that you can control the performance
of RPG "operations. You have already learned the basic
elements of controlling calculations and output, especially
the concept of the RPG II object program cycle and the use
of indicators to condition specifications. This chapter supplements those basic concepts by presenting topics that will
help you improve the performance of your RPG II programs
and do more complex jobs.

You are probably somewhat familiar with the use of these
indicators from previous education, reading, or other topics
in this book. However, there are other kinds and uses of
indicators with which you may not be so familiar. This
section discusses:
1.

Halt indicators used to tell what operations should
be done on an error condition.

2.

External indicators used to tell what operations should
be done for a specific program run.

ADDITIONAL USES OF INDICATORS TO CONTROL
CALCULATIONS AND OUTPUT

3.

Overflow indicators used to tell what calculations
should be done when overflow occurs.

On the Calculation and Output-Format sheets, you describe
all the calculations and output to be done in your program.
Sometimes, all the calculation and output operations must
be performed on every program cycle. More often, however,
you want operations done only under certain conditions.
For example, you may want to perform a calculation or do
some output only when a control break occurs, do an operation only when a certain record type is read, or do certain
operations only on certain program runs.

In addition to these new uses of indicators, this section also
describes conditioning of operations based on the results of
certain calculations.

In columns 7-17 (I ndicators) of the Calculations sheet and
columns 23-31 (Output Indicators) on the Output-Format
sheet, you can specify when certain calculation and output
operations are to be done. Some of the indicators that can
be used, and the conditions they signal, are:

Indicator

Condition

01-99

Operation is done only when a specific
record type has been read, or when the
result of a calculation or the contents
of a field are as desired.

Preventing Operations From Being Done When an Error
Occurs
Halt indicators are used to test for an error condition in
your data. According to RPG II program logic, a halt does
not occur as soon as the error condition is found (as soon as
the halt indicator is turned on). Instead, the program
cycle is completed before the halt occurs. This means that
additional operations may be performed in error unless you
specify otherwise.

Preventing Calculations When an Error Occurs

MR

Operation is done only when records
match.

L1-L9

Operation is done only when a control
break occurs.

LR

Operation is done after all records have
been read and processed.

1P

Output record prints only on the first
page.

OA-OG;OV'

Output r~cord prints only when overflow occurs.

Specifications shown in Figure 5-1 illustrate the use of H1
to prevent calculations. Tests are made to determine if the
INSTOK, TOTAL, or ORDER fields on record types 01,02,
or 03, respectively, are negative. A negative value in any of
these fields is an error condition. When an error is found,
H1 turns on. Since calculations [normally] are done when
02 and 03 record types are read, conditioning these calculations by NH 1 prevents them from being done when data is
erroneous.
Halt indicators can also be specified on the Calculation
sheet to test for an error. For example, in Figure 5-2, H1
is set on if the result of operation in line 01 is negative. If
quantity in stock (lNSTOK) is negative after quantity
shipped (QTYSH) has been subtracted, an error has occurred. H1 turns on and the system will halt after the current
cycle.

/'

5-2

/'

RPG

IBM

GX21·9094

INPUT SPECIFICATIONS
,

Program

Programmer

Page

Date

~

I

i
&

Filename

line

!
5

6

o

R

f-;~~
1

8

Record Identification Codes

~

Position

j

~o e ~

-~ e

Position

~
~

~e
t:!
z u

(5 ~ ~

~ ~

(5

z u u

z u u

1ji

From

To

1

II

0 3

1

R

hN trlH IRlp

~!111 ~11

Iq~

1

IA

1

5

1

6

1

17

0

7

1

131q

o

8

1

0

9

1

, 0

1

~I~IN l(ll~

I....

UI~IJ\J

1-

I~

Iql~

All:

IT

~~

:211<211=2
'u - Lookup(Factor 2lis

z
z
o :I: High Low Equal
9 10 1112 13 14 15 16 11 18 19 20 21 22 23 24 25 26 21 2829 30 31 32 33 34 35 36 31 38 39 40 41 42 43 44 45 46 41 48 49 5051 5253 54 55 56 51 5859 60 61 62 63 64 65 66 61 68 69 10 11 12 73 14
T I"~I IUI"- 1 1 1 ~ltJRI 1 ~~T ~LIII
I ITlNI~rrICJlK 1 1
IrlAllSlrblkl 1 1 1 Aldnll )IHII t-IHl 1 1 1 trIMlsr-~k 1 1

~12 INUll
bll~ IMUlr

I

I I I I I I I I I

I I I I

I I

I! I I

I

I II I I

I I

1 1

1
1

T T
I

I

I

Figure 5-1. Conditioning Calculations by a Halt Indicator

RPG

Form GX21·9093

CALCULATION SPECIFICATIONS

Printed in U.S.A.

,
Page
Date

Factor 1

2

[0

75 76 77 78 79 80
of_

~~~;~f:ation I

IIIIII

Comments

Figure 5-2. Testing Result Field for Error Conditions

)
Controlling Operations In An RPG "Program

5-3

Preventing an Entire Record From Being Written

Figure 5-4 shows the specifications which will bypass the
writing of all fields except DEPT and ITEM NO when an
error occurs.

Figure 5-3, line 07, shows an output operation conditioned
so that the record specified will be written only when the
halt indicator is not on (NH 1). When the halt indicator is
on (H1), it will be bypassed.

Doing Output Only When an Error Occurs

It is also possible to condition records or fields so that they
are written only when an error condition occurs. Figure
5-5 shows the specifications which do this.

Preventing Fields From Being Written

Suppose, however, that you do not want to bypass the
writing of the entire record; but want some fields written
even when a halt condition occurs. For this case you
should use the halt indicator to condition certain fields
within the record instead of conditioning the entire record.
This way, when an error occurs, some fields will be written
and some will not.

RPG

IBM

Using the halt indicator will cause the computer to stop
after all operations are completed for the record causing the
error. You may restart processing immediately, however, by
pressing the start button on the processing unit.

GX21·9090 U/M 050Printed in U.S.A.

SPECIFICATIONS

OUTPUT

International Business Machine Corporation

1 2

Program
Programmer

Page

Date

0

Ijj

iSpace

Output Indicators

Skip

I~

I-

If
3

4

5 Is

7

8

9 '0 11 12

0,1

lOr. h"lp J,r

10 12

10

:0 3

10

o

4

0

o

5

0

o

6

0

,0 ,7
10 :8
~
11

r-

INto

12~l!

~lq

II

10
~

When H1 is on, this
record is not written out.
0

:1 3

0

1 4

0

1 5

0

rr

132 33 34 3S 36 37

~Ii

12

End

Positon
in
Output
Record

3" b. 14041

Commas

Zero Balances
to Print

No Sign

CR

Ves
Ves
No
No

Ves
No
Ves
No

1
2
3
4

A

Ii

8

.'

K
L

II ,
,,~

."

rr.c

1111'\

IIIII

=

Remove
Plus Sign
V = Date
Field Edit

Z • Zero
Suppress

4243 14414s~4748'95051S253~~~~58596061626364656667~6970 171 72 73 74

J 1/\ ~,

1'\'

12l;
ILlbJ
1714

Inl~ lsr
Iro..

X

J

M

IT

IN"

~Z~:~f:ation 1 I.

Constant or Edit Word

IR~ IIh I~,

In!1=' IPT

.

0

121; II In lJ:p h"'
~~ I' IT rrJ:'IM Nf'\I'
111~ I' In II=~ 1rR. P irlI I"'IN'

Irl-Is:

75 76 77 78 79 80

of _

C

It 11

Figure 5-3. Preventing a Record from Printing

54

·AUTO

--V

Ii
L

I~

::.::·.c.::~

{(

~Iv INILII

1
11 !2

I~

118 '19 20 21

II-!

0
0

I~

f£ IR

IA

Field Name

1L

jl~
I~ iofo

Filename

Line

...

:c:.:..

f--

CD

;r

~~

y

Rt1!

7Ll

Ilr~1

l~'" :,..,. "It\

Als

,..,11= '

/'

Page of GC21·7567·2
Issued 24 May 1976
By TNL: GN21·5389

)

GX21-9090 UIM 050'
Printed in U.S.A.

SPECIFICATIONS

OUTPUT

RPG

IBM

International Business Machine Corporation

Page
Date

Programmer

-

0

I~I~

!f
3

4

5 '6

Spoce

I!Ll !I~

8

9 to 11 12 13

~~Io

I~

I~

v

It'l
:~

U

in
Output
Record

'A~TO

Commas

Zero Balances
to Print

Yes
Yes
No
No

Positon

I~

No Sign

CR

1
2
3
4

A

Yes
No
Yes
No

!!;

01 2
013

,0

12.15

II '0 IfP IT'

01 4

1

0

H~

11.1 rT"EM

015

10

171~

I'n IES ~IR IP h"II f'lIN

01 6
o 7

10

QrJj

1'1"\111.

1

1m

tr

10

1 3

10

1 4

!o

Remove
Plus Sign
Date
Field Edit
Z • Zero
Suppress

B.

K

l
M

0

1

When H 1 is on, these
r--~
fields are not written out.

M

11

2

X -

Y -

J

C

78 79 80

",,,I
.r.

!I\

I

I

""'1

o 8

1

-

77

IIIIII

III

hvlN

D

10

:~~~f:ation I

of_

Constant or Edit Word

~

01"'1 JT ,l-'lU I
:0

10
~~ r-~
1 0
-- r--~

[I]

32 33 34 35 36 37 138139 140 41 42 43 «~~~~~50~~~~~~~~~50~~~~~W~~~ro 171 72 73 74

202.1

2f2J~

H
"':R

Field Name

L

At

iA of[)

7

; Output Indicators

Skip

I~I~

Filename

Line

011

75 76

1 2

Program

2.

I

I

I

I

I

!"lIE lelT

12l"

1115

"I~ 5~

....

,

~I/'l

III .... II~II"
IA

DI~

B~

nlA Til;

1'1'

IR1t2

17~

1',lIN

'K

1"-"11

A[4;

rliFl1

I

Figure 5-4. Preventing Fields from Being Written

)

RPG

IBM

International Business Machine

OUTPUT

GX21-9090-2 UIM 050'
Printed in U.S.A.

SPECIFICATIONS

Corpo~ation

-

ISpace

4

5

6

~

11

:j ~
DO

:f
3

~

Filt.:1ame

10
7

8

9 10 t 1 12 13

O~ [lJ Tlr U

,

I~

I~

fl

~~D

~

20 21

t!
OR

Z:t1J

.,.

Output Indicators

Skip

~

Line

Commas

"ti

Field Name

,I

!f~
:~~

'AUTO
32 33 34 35

_~

37

138 39

End
Positon
in
Output
Record

!f'lIVJJ

.0

(lJ

01 5

0

~

01 6

0

8~

17

0

111

~

[1

0
0

114

0

1 15

0

1 16

0

CR

1
2
3
4

A

B

J
K

C

l

0

M

X ... Remove
Plus Sign
Y = Date
Field Edit
Z = Zero
Suppress

58

59 60 61 62 63 ~ 65 66 67 6B 69 70 171 72 73 74

I

when an error condition
occurs.

1 12
11 13

No Sign

80

Constant or Edit Word

5 'ID EP IT
",,,
'll r I: 11'11'1

~~ This constant prints only

r-;-io

I;

Yes
No
Yes
No

78 79

L

.0
.0

i-r-

to Print

'40 41 42 43 1« 45 46 47 ~ 49 50 51 52 53 ~5~ 56. 57

01 2

10 19

Zero Balances

Yes
Yes
No
No

77

I 1I I I I

[L[l

01 3
01 4

(j

:~~~f~cation I·

Page [ D O f _

Date

0

011

75 76

1 2

Program

Programmer

rr

[2

'iD ES Ito II< ,ll'" ,11.1~
t..: LJ IAI ... D'
i""

,

'1('\

:({J[l

:Lll

~.

~
[(ll

[E[PT
II It: rtllNv

IElse

[~

nlM Iu 1\ Ilin

~
~

1111

~rrE

IY

,

174 'lIIN
8rll

IM
I~

I

v~·K

IA

n

lAS 0

I

In

;1= I

IE,LiD'

\

,)

Figure 5·5. Doing Output When an Error Occurs
Controlling Operations In An RPG " Program

5-5

Page of GC21-7567-2
Issued 24 May 1976
By TNL: GN21-5389

Using Indicators Other Than H1-H9 to Bypass Error
Conditions

data on the Input sheet and are then later used to condition
calculations and output operations (see Figure 5-6). They
do not cause a nalt.

If you are not interested in halting when an error condition
occurs but still wish to bypass the processing of erroneous
data, you may use indicators 01-99 instead. They, like halt
indicators, may be assigned to check for error conditions in

RPG

IBM

When you do not wish to halt the program for an error
condition, you may select cards into a special stacker so that
they will not be mixed with valid data cards. Stacker selection may be done based on the use of the indicator for an
error condition.
GX21·9094

INPUT SPECIFICATIONS

U/M 050'

Printed in U.S.A.

International Business Machine Corporation

I

Program
Date

Programmer

2

75 76 77 78 79 80

Page [ o o ! _

~~:~~!:ation I

I 1 1 1 1 1

I

I

Field

GX21-9090 UiM OSC'
Printed in U.S.A.

I
Date

0

S Space
Filename

Line
~

E

~
4

5

6

~~
~~

I-

~

3

Output Indicators

Skip

e~
e!!::

r---

en

f!

~~

~"olo

8

Field Name

1L

~

r;~~
7

f!

~

~

0

z°

I

~

8

z°

z

'AUTO

9 10 11 12 13 14 15 16 17 18 1920 21 22 2324 25 26 27 28 29 30 31 32 33 34 35 36 37

-'"
v

l.i

."w
38~

End

Positon
in
Output
Record
40 41 42 43

Commas

Zero 8alances
to Print

Ves
Ves
No
No

Ves
No
Ves
No

~

No Sign

CR

I

A
B
C
0

2
3

4

2

0

o

3

0

121.'i

o 4

0

o 5

0

o

0

' I irlEM Nh'
1111l " 01(: l';r IRI IPT Irf"l :N
IS'(l '''''' lulL All.!

6

III
""VIN

hR

1 I

0
0

1 3

0

1 4

0

•~~~n

~

n

I I I I I I

7

0

8

0

o 9

0

I 0

0

1

1

ll.

In

rr

l2

",

~.L

I

Figure 5-6. Using Indicators 01-99 to Prevent Output

5-6

'n 1~lp iT"

,~f2l

1 2

o
o

I"IE IpT

121s

I"\I~ ~r

1714

rrr J:I"1N

""'

nl4 TI~

•

~{zJ.

!A ... !n~

Iv

X ... Remove
V

= Date

K
L
M

Z

= Zero

Plus Sign
Field Edit

Suppress

«%~~~~ro~~~~~w~w~ro~~~~~~~~~ro

o

12 "-llL

J

I. 1 1 1 1 1

Constant or Edit Word

o~

H

75 76 77 78 79 80

~~:~~:cation 1

0:

o I

:, h" PJlr

2

Page [ o 0 ! _

p,~

1114 'IIIN
ISle

~rr rlrlk

A5 """IE'

71 72 73 74

)

Controlling Which.Operations are Done For a Specific
Program Run

The chapter entitled Describing and Using Input describes
how to condition the use of an input file with an external
indicator so that a program can use different input files in
different program runs. That chapter also describes how to
assign external indicators U1-U8 on the File Description
sheet and how to set the indicators.
This section-describes how external indicators are used on
the Calculation and Output-Format sheets to condition
which operations should be done for a specific program run.

Conditioning Input Files and Related Calculations
Consider for example, calculations done for a sales analysis
program. For each item in stock, monthly total sold (SOLD)
is calculated and then added to last month's year-to-date
total (BALFOR) to find the current year-to-date total
(BALNCE). In the first month of a new year, monthly totals
should not be added to prior year-to-date totals because
totals are not carried over from year to year. This last
statement, the year-to-date addition statement, therefore,
is not done for all program runs. By conditioning the
statement with an external indicator, you can control when
the statement is done. In Figure 5-7, the monthly total. is
added to prior year-to-date only when U1 is on.
When one program is written to do two similar, yet unique,
applications, some calculations may be used for both applications, some for only one. Again you may use external
indicators to control which calculation specifications are
used for each application.

RPG

IBM

Form GX21·9Q93

CALCULATION SPECIFICATIONS

Printeclin U.S.A.

Int.rnltional Busin," MlChin. Corporltion

1

Program
Page

Programmer

)

Date

2

[0

75 76 77 78 79 80
of_

~~~;~f:ation I

IIIIII

c
Comments

Figure 5-7. Conditioning a Calculation by an External Indicator

)
Controlling Operations In An RPG II Program

5-7

Conditioning Input Files and Related Output Operations

Two files are available: a MASTER file which shows the

Consider again the example discussed in the section of Chap-

which contains daily records of the number of items sold;
The sales analysis job requires one file since it just creates
a list of transactions. The inventory job requires two files
since, for each item, it subtracts the number sold from the

balance forward for each item, and a TRANSACTION file
ter 2 entitled C~nditioning Use of Input Fi/es. Two reports
were required: sales analysis and inventory (Figure 5-8).
Since the results are so similar (one report merely includes
more information than the other), the jobs are coded in one program.

balance forward to find the new balance forward. An external indicator was assigned on the File Description sheet (see
Figure 5-9). Its setting indicates to the program which files
are to be used.

BALANCE FORWARD

SALES ANALYSIS

ITEM NUMBER

AMOUNT SOLD

46732

ITEM NUMBER

DATE

AMOUNT SOLD

DATE

BALANCE

7

09/15/70

09/16/70

8

09/16/70

09/17/70

2

09/17/70

7

09/15/70

8

2

46732

09/19/70

09/19/70

150*
46739

~

12

09/15/70

20

09/16/70

25

09/17/70

8

09/18/70

3

09/19/70

46733
32*
/

46739

~

12

09/15/70

20

09/16/70

~

---

..........

""-

Figure 5-8. Two Similar Reports

File Description Specification
File Type

F

..,uuo u,

""-

'U"O",,'.

End of File

Ro, ""I Add ....

Sequence

Filename

Type

Type of File

File Format
Line

o

III! I~II

I!

I,

Ij
4

1012
1013
1014
1015
1016

6

Is I 7

1""1";: IW"I"-

8

9

IFlp I~II INIT

IF
IF

Additional Are.

",Ioverfl~

Block
Length

Record
Length

I~

Ii o~

Ig

Key Field

~::~~~:n

Device

I~

Irip IA
L-is ~

"'"

Numb~~-om.cks .

for

Name of
Label Exit

Symbolic
Device

Number of Extents
Tape

Core Index

Ii

~Lines
IK

21 2. 2: 124 25 26 27 128129 30 131 b213~ 341353637 3S 13914c 41 4

10' 11 12 13 14

IFM AS rrlErR
IF tr !RIA II\JI~

Extent Exit
for DAM

~:~::~! ~~~:~:I~i:d

I

f..---

I~

43 44 45 46 147 48 49 60 61 62 1.,1 ... ". 6R .7 ...,. 59 IRn Rl 62 63 64 65 166167

It'iFIr JI2
IMIFlr III
1Q1~ITIf\ lTI~IH

I.S;

The devices used depend on which
System/3 model and configuration you have.

1-11-1-

/

Figure 5-9. Assigning an External Indicator to the Master File

5-8

)

Because the results differ slightly for each job, different
output operations are required. When two jobs are coded
together, you indicate which operations are to be done for
each through the use of an external indicator by setting the
indicator to signal which files are to be used. You can speci'fy which output operations should be done in the same
way-by conditioning them by the same external indicator.

The file description specifications (Figure 5-9) show that
when U1 is on, the MASTER file is used. This means that
the inventory job is being done. Thus when U1 is on, only
the output specifications to print records for the balance
inventory are needed. Condition those output records on
U1 (Figure 5-10, lines 01, 05,10,12,15,22). Condition
those for the sales analysis job on NU1 (when U1 is not on
the MASTE R file is not used).

The Output-Format sheet shown in Figure 5-10 shows specifications for both jobs. Appropriate heading and detail lines
are given for each. The total record is only for the balance
forward job. Unless told otherwise, the computer will try
to perform all specifications (provided conditions set by
indicators in columns 23-31 are satisfied) in each cycle. You,
therefore, have to tell the computer which operations to do
for each job.

RPG

IBM

Conditioning Output Files and Related Output Operations
The program just discussed involves the use of a variable
number of input files. One program may also require the
use of a variable number of output files. In that case, the
output file must be assigned an external indicator. When
the indicator is on, the file is used. When it is off, the file
is not used.
GX21·9090 U1M 050Printed in U.S.A.

SPECIFICATIONS

OUTPUT

Internationa_ Business Machine Corporation

,1

Program
Programmer

0

~ Space

-""
=. G; e ~
Ii tl i~

Filename

Line

~a

~

~roro

I-

E

o

.f
3

4

1

5

Output Indicators

Skip

e~
0-

I--

o

Page

Date

6

o

2

0

3

0

o

4

0

o

5

0

o

6

0

o

7

0

o

8

0

o

9

0

1 0

0

j

~

~

L

0

z

8

::l

'AUTO

9 10 11 12 13 14 15 16 17 18 1920 21 22 2324 25 26 27 28 2930 31 32 33 34 35 36 37

--

I-

Nil

'/.1

13

IP

1

H

I~

I PiN

f

~

12

lip

D

~

MR

ejl

L11

Q

2..

MR

(/'.2

Jli

1 3

0

lc:;1"1

1 4

0

In~ tr~

1 5

0
0

1 8

0

1 9

0

2 0

0

2.L

0

.2.2

0

123

0

Il~

3800

NM,R rll.

1"'\

2

"

.2

~,

IM!I ItJ II ,

~I~

01';)

IUl Nilll

"'R

11

T

.3

1

"

40 41 42 43

Commas

Zero Balances
to Print

No Sign

CR

-

Yes
Yes
No
No

Yes
No
Yes
No

1
2
3
4

A
B
C
'0

J
K
L
M

X = Remove

Plus Sign
Y = Date
Field Edit
Z = Zero
Suppress

a:

g

Constant or Edit Word

Ii:
«%~~~~ro~~~~~~~~WOO~~~M~~~Mroro

IS!b

'A All

51-.

I.~

12.1Q

, T TIE'M 1I!1

F"I""IO 'Lilo

A 'A] Ir 11=

AIL E.S

lAl1\l A 1\0'5

4/

' n AIT

bl3

.p, A'· AN ~:I=

71 72 73 74

'" '

IS'

MA J:IQ 1
~I"\ Lin'

E'
I

I~;

y

l~(lj

JJ

Irtr IEM

12.~

It IT I,;M
~h IL 0
'Dl4 IT~

12l;

l,5
y

1li'0j

1

IRld

",r c~

0

Z£ 1£ O£ 69 89 £999 59 til E9 19 19 09 69 as £5 9S 55 t>S E9 Z5 15 os 6. 8. a

Ie, ~
It.. 1

0

J

End
Positon
in
Output
Record

75 76 77 78 79 80

121~

lIT J;::IM

0
0

0

~

1

11

1 6

8

v

11 'm 'A M!n Nh"

1 2

1 7

t;

I

0

z

A"'N'o
7

0 ....
y I'(

o

R

AL

Field Name

2

[[]Of_ ~~:~f~cation I I I I I I I

' *'

9. 5. . . t. Z. I. 0.51: at £t at 5t tl:U zt .t O£ 61: 81: LZ 9Z 5Z tZ tZ U

IZ OZ 61 81 LI 91 51 tl tl ZI II 01

6

8

£

9

5

•

t

Z

I

Figure 5-10, Conditioning Output Operations by an t;xt'ernallndicator
Controlling Operations InAn RPG "Program

5-9

Page of GC21-7567-2
Issued 24 May 1976
By TNL: GN21-5389

For example, consider a sales analysis job which does the
following:
~ach

1.

Calculates and records the quantity of
during the month.

2.

Updates the year-to-date total of the number of each
item sold.

3.

Creates a new year-to-date record.

the· current-year-to-date total is punched. Notice that the
new year-to-date summary card is stacker-selected into
stacker 1, the default stacker for the primary MFCU hopper
(Figure 5-11, line 11 of the Output sheet). Assu me that
the old summary card is selected into a different stacker by
means of an entry in column 42 of the input specifications.
Thus, the new summary card is automatically placed into
the item file in preparation for the next run of the program,
while the old summary card can be easily discarded.

item sold

At the end of the year, new year-to-date summary cards
should not be punched because the year-to-date total is
not carried over into the next year. In this case, the punch"
ing operations should not be done. You can tell the program whether or not to punch by conditioning the output
operations and the output file by the same external indicator. Figure 5-11 shows some of the specifications for the
job.

The input file, organized in ascending order by item number, consists of two record types: (1) item cards, and (2)
summary YTD cards. Each item card represents an item
transaction. During the job, item cards are counted; and,
when a control break occurs, amount sold is added to the
year-to-date total found on the summary card. The number sold and current year-to-date totals are recorded on the
sales analysis report, and a new summary card containing

File Description Specification
File Type

F

Mode of Processing

File Addition/Unordered

Extent.Exit
for DAM

length of Key Field or
of Record Address Field

File Designation
End of File

Record Address Type
Sequence

Filename

File Format

e

§'3 ~U

8-

~

g~

E

If

9

4

o

2

o

3

o

4

o

5

.J

W

Symbolic
Device

Device

Number of Extents

Storage Index

or Additional Area

Line

3

Type of File

Organization

~

w

i2!
~~

Block
Length

~~

Record
Length

Overflow Indicator

::::: t-

§

~

g

Key Field'
.

~:'~:~:n

The devices used depend on
which System/3 model and
configuration you have.

Continuation lines
Option

~

Entry

10 II 12 13 14 15 16 17 IS 19 20 21 22 23 24 25 26 27 28 29 30 31 32 3334 353637 38 39 4041 4243444546 4748495051 52 53 54 55 56 57 58 59 6061 626354 65 66 67 68 69 70 71 72 7374

F

RPG

IBM

GX21·9090 U/M
Printed in U.S.A.

SPECI FICATIONS

OUTPUT

1

2

75 76 77 78 79 80

Program

Page [ ] J o , _

Date

0

S Space

Output Indicators

Skip

~~
e-

f---

-".

;. ~
~~

Filename

line

~

f-

f-

j
5

OE~·

International Business Machine Corporation

Programmer

6

o

R



o

R

co

0

0

z

z

:::c

L

8

fr

Ir

End

cc

Positon

<3 U

in
Output
Record

'AUTO

~~

9 10 11 12 13 14 15 1617 18 t9 20 21 22 23 24 25 26 2128 2930 31 32 33 34 35 36 31 38

Op IRII INT

&>

1J ~

0

z

A"r-;:;'o
1

Field Name

I-

115
1315

o

4

0

I", f: s.r

I'\l"

0

5

0

IPR rrlf:

11,15

°

6

0

7

0

IT'" TA

Ibl5

IL to 1-'11 N

1I1;

0

0 B

o*,
olp [Rlf INT

~(B) 0
1 1

0

1 2

0

1 3

0

1 4

0

1 5

0

1 6

0

7

0

1

1 B

0

1 9

0

2 0

0

:0

No Sign

CR

1
2

A
B
C
0

3
4

-

X "" Remove

J
K

Y

~

L

Z

l1li

M

Plus Sign
Date
Field Edit
Zero
Suppress

CC

g

Constant or Edit Word

ii:

III

-

It 1 ~1

2

IrT £IM

.-

T 1

Yes
No
Yes
No

I. 1 1 1 I I

9 40 41 42 43 44 45 46 41 48 49 50 51 52 53 54 55 56 51 58 59 60 61 62 63 64 65 66 61 68 69 10 11 12 13 14

III f=M

E'" IT IN I--

J.

I

Zero Balances
taPrint

Yes
Yes
No
No

75 76 77 76 79 80

~:;~f~cation 1

~1

12

o@o
lAo

T

1

Commas

2

[DO!_

l~15

br:: sr

l'i15

IpQ T r 1=

Ih~

IT'"' T~

bli

III

0
0
0
0

)

0
LZ

Figure 5-12. Using U1 to Condition Output Operations
Controlling Operations In An RPG II Program

5-11

Assume, for example, that you are preparing an accounts
receivable report as shown in Figure 5-13. On each page of
the report, you wish to have a total showing the amount of
all accounts receivable on that page. You also wish to find
the total amount of all accounts receivable on all pages.
Thus at the beginning of each page, you must start accumulating totals for that page. When overflow occurs you want
to add the amount of the accounts received (page total) to
final total, print the page total and then reset the page total
to zero so that you can start accumulating totals for the
next page. Only the calculations which are to be done when
overflow occurs are conditioned by the overflow indicator.
See Figure 5-14 for the calculation specifications.

Performing Calculations on the Basis of the Results of
Other Calculations
(
I.

The value of the contents of a field rather than the occurrence of a certain condition can be used to determine
whether or not an operation will be performed. You have
worked with such situations already. For example, you
have used a field on an input record to determine if
processing should be done. If the field was positive, you
wanted to do all calculations; if it was negative, you did no
calculations. (See Preventing Calculations When an Error

\.

Occurs.)

For the situation just stated the contents of an input field
determined what calculations (if any) were done. In this
section, however, emphasis will be placed upon how results
obtained in a calculation operation can be used to determine whether or not other calculations are performed.

ACCOUNTS RECEIVABLE REGISTER

DATE 06/30/0

PAGE 1

CUST NO

ACCOUNT NAME

INV DATE
MO/DY/YR

11886

AABY, SHELLEY

4/18/0

86.40

12093

ACKER, ALVIN

4/18/0

403.10

12128

ADAMS, CINDY

4/1,8/0

345.05

12206

ADSON, MARION

4/18/0

700.60

12720

ANTON, MONICA

4/18/0

1,253.40

12803·

AXFORD, JOE

4/18/0

48.52

12815

BAILEY, MARLYS

4/18/0

107.05

12900

BALZUM,GERALD

4/18/0

345.10

13260

BATTEY, ADA

4/18/0

165.35

13265

BEABOUT, ART

4/18/0

316.05

12390

BERGERSON, M.

4/18/0

43.60

14619

BI LSTAD, DON

4/18/0

1,129.02

ACCOUNTS RECEIVABLE

4,943.24

/

PAGE TOTAL

I

Figure 5-13. Report with Page Totals

5-12

RPG

IBM

Form GX21·9093

CALCULATION SPECIFICATIONS

Printed in U.S.A.

International Business Machine Corporation

1 2

)

Program

Date

Programmer

C

line

Indicators

~

0_
..Ja:
::'0

I---

Page

AL

~3~
'0 a:
E ~ '"
~ 8 5~

Operation

Factor 1

.g

Factor 2
Length

Name

~

III

22

23 24 25 26 27 2829 3031 32 33 34 35 36 37

II -

rrbrr

~!

e

IIIIII

Arithmetic

0
~
z0
z
3 4 5 6 7 8 9 10 111 2 13 1415 1617 18 19 20 21
a 1
e
1~[o,11
a 2
e
Ir-IV
Ip~

a 3

75 76 77 78 79 80

~~:;~f:ati~n I

Resulting
Indicators

Result Field

1

CD of _

It\lnlo

A'" v-Ir

~IDID

11-11 INII

I_I ..

1-

38 39

40 41 42

43 44 45 46 47 48

I"bl

Plu. IMinu.1 Zero

Comments

Compare

1> 2 1 <: :ill- 2
~ ~ Lookup(Factor 2)i.
~ -;
OJ: High Low Equal
49 50 51 5253 64 55 5657 5859 60 6t 62 63 64 65 66 67

68

69 70 71

72

73 74

RI2

II

1=1I INT ,. . iT

Ir

J:

~~

~12

Figure 5-14. Conditioning a Calculation by an Overflow Indicator

Using the Results of Arithmetic Operations

How can you cause a test to be made on the data? Remember in Figure 5-1 how you tested for a minus quantity. By
entering an indicator (01-99, H1-H9)in columns 54-59, you
can test for plus, minus, or zero depending upon where you
place the indicator.

Consider how the result of a calculation can be used to determine the need for further calculations in a billing program. For each account, it is necessary to first determine
the amount owed by adding charges and payments (payments are recorded as negative numbers) to the balance due
at the beginning of the month. For any customer owing
money at the end of the month, a service charge of1-1/2
percent is added to the amount due. If he has credit coming,
he must be sent a credit memo instead of a bill. Thus a test
must be made on the amount due field to determine if it is
plus or minus. If it is plus, the customer owes money and
the service charge must be figured before the bill is printed.
If it is minus, he has a credit and must be sent a credit memo.
The card for the customer with a minus balance is stacked
into a special hopper. It is later used in a credit memo run.

)

RPG

IBM

For this program~ indicator 99 is placed in columns 54-55
to test for a plus condition (see Figure 5-15). When a control
break occurs (all transactions for one account are processed)
and when 99 is on, the 1-1/2 percent service charge is found
and added to amount due (AMTDUE) to find total amount
due.
If indicator 99 is off (no amount due) when the control
break occurs, these last two operations are not performed.

CALCULATION SPECIFICATIONS

Form GX21·9093

Printed in U.S.A.

International Business Machine Corporation

1

Program

Page

Date

Programmer

C

'-J~
I~I~~

13

A"

At

,"'00' 1

LI~e J~ 11 ~!' i 1-1~" 'l -r-ol l-l ~" " '-+-~""""'-I
1

F~o.'

Op',,211<211=2

511~ I-~ ~ I~
Ii

16061 62 6364 65 66 676869 7071 72 73 74

~10~13~le~~~~~I~~++++.¥~WIM~~~ID~I'~JIE~~~I~~~ILWT~~~~~~~~~~~~IA~I~~~~lr~~~~I~ ~1++++++++444444~~~

)

•

II

IAln~lr

Figure 5-15. Conditioning Calculations by an Indicator Set as a Result of an Arithmetic Operation

Controlling Operations In An RPG II Program

5-13

Using the Results of the Test Zone (TES7Z) Operation

The result of any arithmetic operation (ADD, SUB, MUL T,
DIV, Z-ADD, Z-SUB, MVR) can be tested by specifying resUlting indicators in columns 54-59. The resulting indicators which are set as a result of the test can condition th'ose
operations which are to be performed on the basis of the. result of that test.

Another operation code, TESTZ, is available to test data
during calculations so that you can determine which calculation todo next., TESTZtests only the zone portion of
the leftmost charact~r of'an'alph~meric field. TESTZ ~o~'s
not test specifically for plus, minus, or zero; high, low, Qr
equal. Rather, it tells you into which group of zones the
zone tested falls:

Using the Results of Compare Operations

• The zones of the character & (ampersand), A-I c~use
the Plus indicator entered in columns 54-55 to be turned
on.

In a compare operation (COMP), fields or literals of the
same type (alphameric or numeric) are compared to each
other to determine their relationship to each other. Indicators entered in coll!mns 54-59 are used to indicate whether
the field or literal in Factor 1 is higher than, lower than, or
equal to the field o-r literal in Factor 2.

• The zones of the characters } (bracket), - (minus), and
J-R cause the Minus indicator entered in columns 56-57
to be turned on.

The results of a compare can also control which calculations
should be done next. For example, when doing an inventory
and reorder application, the compare operation (COMP)
is used to determine if any item needs to be reordered. In
the example shown in Figure 5-16, the field called MIN
(minimum) contains the critical reorder point. The field
ONHAND is compared to MIN. If the amount on hand is
less than or equal to MIN, indicator 99 is on. The reorder.
quantity is calculated by subtracting amount on hand from
the number in the field called MAX which contains the
maximum number which should be in stock. If amount on
hand is greater than MIN, no reordering need be done and
this calculation is not done.

RPG

IBM

International Business Machine

• The zones of all other characters cause the indicator
entered in columns 58-59 to be turned on.
The test zone operation equid prove very useful in a large .
billing application. Consider the case of a company which
has so many accounts that billing must be divided. Customers
, whose last names are in the first part of the alphabet are
billed on the 15th of the month; all others are billed at the
last of the month. The master file used in billing is organized
in ascending order according to account number.

Form GX21-9093

CALCULATION SPECIFICATIONS

Printed In U.S.A.

l' 2

75 76 77 78 79 80

Program

C

. i>age[Oof

,

Date

Indicators

Result Field

'"

'--- ~~
=0
~~~
Line
I-

Jd

Jd

Factor 1

Operation

Factor 2

~

'"

af

85 ~

6

7

8

E
4

5

0 1

C

o

C

2

o

3

C

o

4

C

Length

Name

(50:."

3

'0

z

'0

z

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 28 27 28 29 30 31 32 33 34 35 38 37 38 39 40 41 42 43 44 45

~.I

lq~

IMAX

1\

.I,t"\

,.,.., MP
t;

R

Mr'N
I-

I ..

/

The records in this file could be sorted by name so that you
could divide the file for billing. However, this.fileis used,
so often for other purposes that it is a waste of time to .
repeatedly sort it according to name and then sort it aga'in
according to account number.

COr'pOrI~on

Programmer

/

-

cis

47 48 49 50 51

Resulting
Indicators
Arithmetic
Plus !Minus! Zero
Compare
1>211<2!1-2
Lookup(Factor 2)1,
High Low Equal

-

::~af~atio~ I

1 1 1 I· I I

Comments

54 55 58 57 58 59 60 61 62 63 64 65 66 67 66 69 70 71 72 73 74

~~ qq
lot

.. lot

Figure 5-16. Conditioning Calculations by an Indicator Set as a Result of a Compare Operation
/'

",

)

A better way to do the billing is to test the name field in
each record to see in which part of the alphabet the name falls.
During the first of the month, if the last name begins with
letters A-I, you wish to find amount due. TE5TZ will test
the first letter in the field and tell you in what part of the
alphabet it is. Figure 5-17 shows the calculation specifications necessary to bill customers whose last names fill into
category A-I.

RPG

Naturally at the end of the month you will want to bill the
rest of the customers. But you don't want to write another
program for end of the month bill ing. 50 you write one
program to do both jobs and use external indicators to condition the specifications for each job (see Figure 5-18).

Form GX21.-3

CALCULATION SPECIFICATIONS

PrlnlOd In U.s.A.

1 2
Progrlmmtr

C

~

Linl

Dotl

Indicators

~

Result Field

9l 1
11
!

Operation

Factor 1

I

Factor 2

4 I

o
o
o

1

8

2

c
c

3

C

7 8

j

\za 211

MR i?Jl

30 31 32 33 34 31 :IS 37 38 38 40 41 42 43 44 41 48 47 48 49 60 61 52

I!.~

lL~

A.4 " .4 1\1"

~
.§
~

j

II 10 11 12 1314 II II 17 II 111 20 21 22 23 24 21 21 27

MR

Length

Name

g~

! 85' j

3

75 78 77 78 7e 80

Plge[OO'_ ~:~"tltlonl I I I I I I

A:DD

KIolN

Comments

54 56 58 57 5858 80 81 82 83 54 86 88 67 88 89 70 71 72 73 74

b2 q9

I~

J.l(YI

Compare
1>211<211-2
Lookup(Factor 2)1s
High Low EquII

l~

N4 MI=

~

Resulting
Indicators
Arithmetic
Plus IMinusl Zero

Figure 5-17. Conditioning a Calculation by an Indicator Set as a Result of the TESTZ Operation

)
RPG

FonnGX21.-3

CALCULATION SPECIFICATIONS

PrlnlOdIn U.sA

1 2

Progrlnvnor

C

o
o
o
o

Indicators

jl l 1

9-

I

!8~

Factor 1

Operation

8

7

a

:€~e.

Factor 2

S ~
Length '" !!

Name

~~

~~

j

j

j

Resulting
Indicators
Arithmetic
Plus IMinusl Zero

Compare

Comments

1>211<211-2
Lookup(Factor 2)1s
High Low EqUlI

II 1011 12 13 14 11 1117 11 111 20 21 22 23 24 21 28 27 i211211303132 33 34 :IS :IS 37 :IS 38 40 41 42 43 44 46 48 47 48 49 60 11 52 53 54 55 58 67 58 59 80 61 82 83 84 65 68 87 68 89 70 71 72 73 74

c
c

MR

2

3

C

J

4

C

1

Result Field

!
I- g ci

Linl

3 4

DIU

~

f---

76 78 77 78 79 80

Plge[Oo,_ ~:~":"tlon I I I I I I I

Progrlm

~,

MR lLr2J
lLl

III"~

_

I~

'OLl IliA A,~

~If)![)

H~ IV~

la tJr

~nln

TR ANc\

MI"l AA jl

NlA ~r:...
lAM
'J:

1-t2

AM Tn

b2

J~

I~ f II 11

r

Figure 5-18. Using TESTZ and External Indicators

Controlling Operations In An RPG II Program

5-15

You can use TESTZ to test for any special code you set up
by using the zone of a character. This is most often done
when you have no space on your records for any other kind
of identifying information. For example, when establishing
a code for the percentage of commission received by each
salesman, you could use the & to indicate 6 percent and
the minus (-) sign to indicate 15 percent. You would, of
course, have to punch this code in the leftmost position of
a numeric field because this is the position tested by the

TESTZ operation~ Figure .5-19 shows how the code is
placed in the field containing salesman number. However,
you'must define the field as alphameric since the TESTZ
operation can only be performed on an alphameric field.
Figure 5-20 shows the TESTZ used on the SALSNO (salesman number) field, which contains the commission code,
in order to find rate of commission. The results of the'test
determines what other calculations will be done.

SALESMAN I

Whose number is 17657778
Who e1rns 15% commission
Has 17657778 punched
in SALSNO field

~M"m~mm~m~maa~mmM~M~mMM~m~m~~~~~

B •

B

A

A'

8 .
••••••
4
2

••

1 ••

B

1

2

8
4

•••

2

••••
3

..

5

•

7

•

•

10 11 12 13 '4 15 •

17

I'

It 2~ 21 22 23 24 25 2S 27 ~ •.. 2t 30 31 32

1

B

A

A

8
4
2

8
4
2

~»~UHnH»~~uu«u"u"a~~~"~"H~9"~~U""~
A

A

8

8

4

4

2

2

1

eMvM"~nnnun~"Hn~~u"Ne"v"n~~"""""l

/

11M 3700

Figure 5-19. Punching a Code

RPG

IBM

Intern.tion.1 BUlin.u Machin. Corpo...

~on .

Form GX21·9093
Printed in U.S.A.

CALCULATION SPECIFICATIONS
1 2

Program
Page

Date

Programmer

C

Indicators

~

0_

~

Line

-'IX:

IX:

5

Jd

=0

~~~
I- "0

Result Field

I!

Factor 1

Jd

~~

Factor 2

..

.g

6

9 10 11 12 13 14 15 18 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

3

4

1

c

2

C

3

c

-. -

7

8

Length

Name

~ ~ ~
~ 85

o
o
o

~

~

~~

MI~
lr.~

MI~

I.00I1...

1111.

MI~

r1[' 1c.IA Il I,: ICi

...1.. Is: Ie;

Figure 5-20. Tasting a Field to Determine a Code

5-16

Operation

lloli ~Il

Mll~ I.

rr

Mill lilT

46

8

~

if

~i

If1lb
lIlt:;

Ir-r- MIM

Irlc IMIM

Resulting
Indicators
Arithmetic
Plu.TMinusl Zero
Compare
1>211<211-2
Lookup(Factor 2)1.
High Low Equal

, Comments

47 48 49 50 51 52 53 54 55 56 57 56 59 60 61 82 63 64 65 68 67 68 69 70 71 72 73 74

II fj III

~IL ~Nh

~

75 76 77 78 79 80

[]JOf_ ~~~~:~tion I I I I I II

'i21~
~I'lu

Ts
Irl~

IrlF

!~h N~

I~

-

ulslJ:
'JlSIE

Ie nlR
Ih~
115~

-1

)

CONTROLLING OPERATIONS ON THE BASIS OF THE
NEXT RECORD IN A FILE
Sometimes, calculations to be performed may depend upon
information in the next record or on the type of the next
record to be processed. For example, in a certain kind of
program, you might want to bypass calculations for the current record if you know the next record in the file is identical.
The RPG II language has a special feature called look ahead,
which extends the basic RPG II logic. It will allow the computer to look at information in the next record to be
processed while it is processing the current record. This
means that information in record B can be used while record
A is being processed. By using this feature, you can
write a program that uses information from the next record
available for processing.

Processing Card or Disk Files
MFCU Files:. (Refer to the representation of the MFCU
card path in Figure 5-21 during'this discussion.) As Card
A is read, data recorded on.it is transferred ,tothe input
area. The card then moves on to the wait station. According to the RPG II program cycle, information is transferred
from the input area to the processing area right before detail time. At detail time, then, calculat!ons can be done on
data from the card path which is in the wait station (Card A).
However, when look ahead is specified, another card (Card
B) is read before detail time operations are performed in
the current cycle. Card A is stacked and information from
Card A is moved to the processing area. Then information
on Card B just read is transferred to the input area and is
available for use while processing Card A, now in the
stacker.

Look ahead can be used with card, tape, or disk input files.
This section discussesiook ahead with card (MFCU) and
disk files. For MFCM, tape, and other files, the concept
is similar.

)
Print

Secondary
- - - Hopper

--=H"';:::"~++----

Card A is stacked and data from card A
is moved to the processing area.

Before card A is processed, data from
card B is read into the input area,
where it is available while processing
card A.
'

--.....\
) . Figure 5-21. The Look Ahead Function with a Card File

Controlling Operations In An RPG II Program

5-17

Disk Files: Figure 5-22 shows processing of three of the

Record Processed

records from two disk input files, one primary and one
secondary. The records available for look ahead during the
processing of these records are:

Records Available

P1

P2 and S1

P2

P3 and S1

S1

P3 and S2
SECONDARY FI LE

PRIMARY FILE

!I r~II Ma~:I~;e!d --r :111

from secondary file (S1).
Area into which records
are read (read area).

I

1------------~------J
I
I

I
I

I

I
I

I
IL

I

I

Area into which records
are selected for
processing (process area).

I
_________________ J

®

0Read second
record from
primary file.

,' ....

r-----····
------------.,I
/\\\:"..

I

i r

wi

(P211

I

II-----~.

!I

I

------------JI

·'·';;:i\\h.

w

!

L _ _ _ _ _ _ _ _ _ _ _ _ ;.....- _ _ _. _ JI

0Select first record
from primary file
for processing.

Figure 5·22 (Part 1 of 2). Records Available for Look Ahead: Two Input Files
5-18

Read Area

Process Area

)

In general, when the record being processed is from an input file, the next record in the input file is available as are
the records which were read but not processed from the
other files.

©
0Read third
record from
primary file.

r--

A\\\\\>

h::~--------n--:

:L____
~

W:J

Read Area

-.:::::iiiii:!::b, __________

I

.,,""

I

:I
~
I
L________ 'f'-______ J
~

8select second record
from primary file for
processing.

I

Process Area

r:-':"-,

~1
: Processed Re~ords
L_!!,.!~J

@

)

r----------------,,:"'-l
i 12 (P311
~ iI
I

0Read second record
from secondary file.
Read Area

.:::

~------- ____,,,,.-4.iil!!f!"
-----J
...
I

I
I

l-______ I"lill _______
r:---,

,1

I

I

I

I

(P2)1

L. ____ J

r,----l

I
Process Area

J
8select first record from
secondary file for processing.

Processed Records

I

LJ~!~

)

Figure 5-22 (Part 2 of 2). Records Available for Look Ahead: Two Input Files

Controlling Operations In An RPG "Program

5-19

Checki Iig for' Dupli cates '

,.'

Duplicate 'records or records with duplicate fields are sometimes considered erroneous. Only one of the duplicates'
should be used for the job;,'
Consider, for example, the case of a company which has a
large turnover in inventory items. Quite frequently new
items are added and others deleted from the inventory. A
number for a deleted part is to be assigned to a new part.
Some mistakes have occurred, however, and one part number has been assigned to two different items. As a result of
this error, inventory balances for these items have not been
updated correctly, and errors have been made on customer
invoices. If this situation is possible, a regular check should
be made for duplicate part numbers.
Each month, a report is created showing the complete inventory. All part numbers are listed on the report. You
could look through th~ report to che~k fo:r duplicate part
'numbers, but it would be easier and more accurate if you
could add a few specifications that would check for duplicates and indicate on the report which item numbers are
duplicate.

By using the look ahead feature you have access toinfor-mation that is coming up. You can then use this information
t6 determine what operations to do. If you a're processing
a record with part number 64322, and you 'know that'the '
next record also has part number 64322, you can'print'a''''''
message indicating duplicate 'part numbers, then halt.' But,
if you are processing the record with part number 64322
and you do not know that the next record also has part
number 64322, you can do nothing special because you are
not aware that you are processing a record which contains
a duplicate entry.

Writing Specifications for Look Ahead

Any field which you want to look at in the next record to
be processed must be defined asa look ahead field. If that
field is also used in normal processing (other than as a look
ahead field), it must be defined in the normal way also.
Thus, most look ahead fields will be specified twice.
Figure 5-23, lines 01-05, shows specifications needed to
describe the input file used in preparing an inventory listing.
When checking for duplicates, PARTNO is the field you
want to use when looking ahead,at the next record; therefore, PARTNO must be defined as a look ahead field. The
specifications in Figure 5-23, lines 06-07, do this.
/

RPG

IB1«

INPUT SPECIFICATIONS

GX21·9094 UIM 050'
Printed in U.S.A.

International Business Machine Corporation

12

Program

Page

Date

Programmer

Record Identification Codes

I
Position

z

0

~

From

Position

Position

o
:~
~

To

4

01

o

2

o

3

o
o
o

5
6

o

7

4

5

6

7

8

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2!s 29 30 31 32 33

Ir'Nlp T
I
I
I
I
I
I

A~

~[

:nr

l2lb
1312

]

~

-0

15 IPA Rf IN"
DE ~~

2lt;

.~11 12.lp RI ~IE
~II; Itllr,~

Inl~1"\

,*N

Figure 5-23. Look Ahead Specifications

~~;~I:ation I

IIIIII

Field
Indicators
0

3i-t;

~~

6 1--..---.---1

~a::
"E

!~o.u:( ~~

Zero
Plus Minus or

Blank

35 36 37 38 39 40 41 12 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

lL
,

'1)-20

Field Name

c

~,

II
Ib
lAIR

-~_~-,'

~
'il

~ §~

3

757677787980

01_,

Field Location

Filename

Line

CD

Is

N~J{

1/\1

)

All look ahead fields must be defined as being in a record
type different from the others defined. This is done by
using a unique alphabetic sequence entry in columns 15-16.
No record identifying indicator (01-99) can be used. A
double asterisk (**) is placed in columns 19-20 to specify
that the fields described in the following lines are look
ahead fields. Field location is also specified for look ahead
fields.

Every look ahead field must be named, but the name given
must be different than whim it was described as a normal
input field. The same field is given two names so that you
can distinguish betweenthe field on the record being·
processed and that same field (the look ahead field) on the
record that is to be processed next (Figure 5-24).

12644
(NEXTNO)
NEXTNO refers to
positions 1-5 in the·
record to be processed next.

INPUT AREA

)

1
j1264iJ
(PARTNO)
PARTNO refers to positons
1·5 .in the record currently
processed.

Figure 5-24. Look Ahead Fie!d: A Field with Two Names

)
- - Controlling Operations In An RPG II Program

5·21

they are e'qual, indicator 07 is turned on. Notice on the
OutPut-Format~heet that when 07 is on, the word duplicate is printed.

Using Look Ahead Information

Now that Y9uhave specified the look ahead field, you can
use it as you would any other field. The only exceptions
are that you cannot use it as a result field in calculations,
nor can it be blanked after for output.

The SETON and SETOF operations in lines 02-04 of the,
Calculation sheet are used so that the computer will in- "
dicate a duplicate yvhen the second record having the dupI,icate part number is processed.

I n the listing program, you have to make a comparison
between part numbers from two records. If PARTNO on
the record being processing is the same as NEXTNO on the
next record to be processed, you wish to print a message
indicating duplicate entries. If the PARTNO and NEXTNO
fields do not match, there are no duplicates for that part
number, and the item is merely listed.

Consider, for example, records A 1, A2, and B. The first
two records are duplicates;the third is not. When A 1 is
processed, the program looks ahead to A2 and, by comparing, knows that A2 is the same as A 1. When A2 is
processed, the program looks ahead to B. The compare will
say that A2 is not a duplicate si(lce it does not match B1.
But A2 really is a duplicate because it is the same as A 1.
Thus, when processing A 1"you have to set an indicator
which will be on when A2 is processed and which will indicate that A2 is a duplicate since it matches the previous
record.

Figure 5-25 shows specifications for the program. The operation in line 01 of the Calculation sheet compares the part
number on the record being processed (PA~TNO) to the
part number on the record coming next (NEXTNO). If

RPG

IBM

CALCULATION SPECIFICATIONS

Form GX21-9093
Printed in U.S.A.

I",emltional Busineu Machine CorporatiOn

Program
~--

1

I

Page

Date

C

Indicators

~

9~
=0

1---

At

~!~
I- '0 rl

line

E ~ '"

~85~
5

a

1

C

0 2

c
c

rtJi7

C

!ilL

0 3

IBM

8

:---~

-:

--

r"" Mlp

r-E IA. RTINh

slL N(ll17
1£12.

Sf IThJ:'

I

~-

l'ilL 52
GX21-9090 U/M 050·
Prmted in U.S.A.

SPECIFICATIONS

___

~ Sp"lce

Filename

Line

~

-""~
;.
~~
I-

cl5

l!!

j

~~fAND
7

8

And

~

~

~

z°

8 U

z°

~~

"AUTO

0 1

olp 'Rlr INT

0 2

0

0 3

0

I~,Q 'HTN
II"\~ sir

o

0

~

@~

End

a:

~ ~

z°

9 10 11 12 13 1415 16 17 18 1920 21 22 232' 25 26 27 28 29 30 31 32 33 34 35 36. 37

In

....

Iti.l

II

And

38~

Page

__

-'"

Field Name

Il~

~

~~

~ro'o

I-

__

Output Indicators

Skip

~~
o-

6

1

~I~D-._t-e--~=~_-~~'-~~~~~~~;-r_~_~~!~n~~~G_p~_:_ic~I ~I~I ~1-L1~1~1 1L-~_rd_EI_ect_rO_N_um_~_r~

0

4

./; 2. rzl7

I

OUTPUT

RPG

r--

5

~11

International Busmess Machine Corporation

____________

.

~Il

IN It-. IYII ,N"

Sf ThN
Sf T~N

~:_r:_:_:m_er

3

Comments

Compare

g~ 1>211<2!1-2
Lookup(Factor 2)i.
~
o :x: High. Low Equal

za

z°

4

7

Plu. 1Minu.! Zero

J:

~ ;

Length

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 5051 5253 54 55 5657 5859 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

3

@.

6

·2

Factor 2
Name

I 1 1 1 1 1

Arithmetic

1'!

Operation

Factor 1

75 76 77 78 79 80

~~;~;~:ation I

of _

Resulting
Indicators

Result Field

1

2

CD

Positon

in
Output
Record

Commas

Zero Balances
to Print

No Sign
.,

Yes
-Yes

Yes

' No
No

Yes

1
2
3

No

4

No

2

CD

75 76 71 78 79 80

of_

CR

-

A
B

J
K

C
0

M

L

~~~;~f:ation I
X

I. 1 I 1 I I

=

Y

Remove
Plus Sign
= Date

Z

~

Field Edit
Zero
Suppress

a:

g

Constant or Edit Word

i>:

40 4' 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

~l
-.

~7

11\

2~

b~
11'11.

7~

qti'j

'In Ip

I~

Art" IF

I

Figure 5-25. Using Information from the Look Ahead Field to Check for Duplicates
I~

5-22

)

Indicator 52 is set on in line 03 to indicate that the last
duplicate record is being processed. Indicator 52 then conditions line 04 so that indicator 51 will be set off and not
indicate:duplicates in the following cycle. Fig'ure 5-26
shows the program logic for this job.

When PARTNO equals NEXTNO, 07 turns on. This, in
turn, causes indicator 51, which is used to indicate that a
duplicate record is processed, to turn' on. During the next
program cycle, the compare does not indicate duplicates;
therefore 07 is not on. But 51 is on, meaning that the record being processed is a duplicate since the part number on
it matched the part number on the previ9us record. Therefore, 07 is set on. Remember 07 conditions those output
operations which'are to be done for duplicates.

12457

12455 DOOR KNOB

48

DUPLICATE

12455

o

•

"

•

I,

/:

/~

•

I
I
I

12455

Turn on
record identifying
indicator 01

I

• ..I

Perform detail
output

)

\

,:

/;'/ Note: This record is read only if
~f.
the Look Ahead feature is used.
,N:P'
It is read after data from the
'~'f::'
,_ - ____ hr ... ,
first record is moved into
the processing area.
( 12455
I
I
Read a
Record

Turn off
record identifying
indicator 01

\
\

•

•

•
•

Perform detail calculations:
Compare PARTNO fields:
12455 to 12455
They are equal so turn 07 on.
07 is on so SETON 51 .

Move data from record
selected into processing
area. If Lo'ok Ahe'ad is
. used, read another. record.
If cards, the first is stacked.

•
•
•

)

•

•

•

Figure 5-26 (Part 1 of 3). Logic for Look Ahead

Controlling Operations In An RPG II Program

5-23

/12457
12455 DOOR KNOB

48 DUPLICATE

12455 HINGE,6"

90 DUPLICATE

./

/12456

I-

•
•

•

•

•

•

I

•

I

/
I
I
/
/

/

Turn off
record identifying
indicator 01

,

I

~

- .- -

12456

12455

I

I

I I

~/

,-

/1
I

I
/

/

/

/

- - - - -,
I

I
I

Turn on
record identifying •
indicator 01
output

•

Perform detail cal cui ati ons:
Compare PARTNO fields:
12455 to 12456
Not equal so turn 07 off
SETON 07 and 52 using 51 from
previous cycle. SETOF 51 and 52

•

•
•

Move data from record selected
into processing area. If Look
Ahead is used, read another
record. If cards, the first card
is stacked .

•
•
•

•

Figure 5-26 (Part 2 of 3). Logic for Look Ahead

(

5-24

)

12455 DOOR KNOB

48 DUPLICATE

12455 HINGE,6"

90 DUPLICATE

12456 HINGE~ 8"

75

•
•

•

•

Turn off
record identifying
indicator 01

Turn on'< . "
record: identifyin9

Perform detail
output operations

indicat~r

en,

•

•

)
•

Perform detail calculations:
Compare PARTNO fields:
12456 to 12457
Unequal so turn 07 off.

•

•
•

•

Move data from record sele,cted
into processing area. If Look
Ahead is specified, read another
record. If cards, the first card
is stacked .

•

Figure 5-26 (Part 3 of 3). Logic for Look Ahead

)
Controlling Operations In An RPG II Program

5-25

Doing Special Operations When There is Only One Record
in a Group

MONTHLY CHARGES

It is often important to know if and when you are processingthe only record in a group. The program described in the
following paragraphs is such a case.
A report is prepared showing charges made by customers
during the month (Figure 5-27). The input file is organized in ascending order by customer number. During the
month some customers will have made one charge; others
several.
When only one charge is made per customer, the total line
is nearly a duplicate of the only detail line. In this case,
you do not need to print both the detail and total line because the total line will do.

RPG

NAME

CHARGE

47653

JILL ARNDT

4.97 }
Detaillines
5.99
23.87

47653

JILL ARNDT

34.83· Total

49832

NANCY BENNET

87.93· Total

59821

JOAN BOND

7.42

Whenever a r'ecord is read, the current ACCTNO field is
compared to the one coming up. If the fields are equal, you
know you are processing a record that is not the only one
in a group. Therefore, a detail line should be printed.' If
the ACCTNO fields are not equal and this is the first time
the present account number has been encountered, the current record is the only one in the group, arid the detail line
should not print. Figure 5-28 shows the specifications for
the program.

GX21·9094 U/M 050'
Printed In U.S.A.

INPUT SPECIFICATIONS

International Business Machine Corporation

1 2

Program
Page
Date

Programmer

~

I

Record Identification Codes

Field Location

U

Filename

8.

~

~

rei ~r- ~!

E

5

6

~ - ~.!;
j ~~:;;~
...

f-;;~~

7

8

~.~
Position

!;

Position

!;

! ; , . _-z"'NiU
p ~
~Ni6

z_

fl

~ u0

~U6

Position

t ;;i a:
tj t -

Z Q
~N~~g
z

From

lolA

Ilr IJII\ lolf: 1~1c;
I

11

o

3

I

Ib

o

4

I

l312

nlRI

e.3...

~~
0

~ '"
:c
.f

~
"tI

J

8 ~]"
~u ~

~!l

1

I

-;;

Field
Indicators
1---.---.--1

Plus Minus

!:ro

Blank

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

2

7

Field Name

.~

U 0 cii ii:

o

o

~

~E

To

o

~~

.g

m

gt.

4

75 76 77 78 79 80

[]]Of_ :~;~f~cation I I I I I I I

~

Line

3

Detail

Figure 5-27. Format of Monthly Charges Report

But how will you know during anyone program cycle
whether the current record is the only one in a group?
You can find out by looking at information on the next
record. Remember, any time information from the next
record is necessary to determine how to process the current record, you must use the look ahead feature. Account
number is established as a look ahead field in this program.
Any look ahead field specified applies to all record types. Thus
each record read contains information that will be looked at
before the 'record itself is processed. By looking ahead into
this field you will know whether or not the next record
to be processed is part of a new group.

IBM

ACCTNO

IAR

'**

11

,., r/,

I.~fl
BHIL..

,~I ...

I"H"NIr 1111

~A

ME

H}O(~

I., ". NI-Il'

~\I

-

T

Figure 5-28 (Part 1 of 2). Using Look Ahead to Determine When There is Only One Record in a Group
/

5-26

RPG

IBM

)

Form GX21-9093

CALCULATION SPECIFICATIONS

Printtdin U.S.A.

Inlern'tion.1 BUlin,ss Machine Corpor.tion

Page
Olte

Programmer

C

0_
.Ja:
::'0

Jd

~3~
I- "0 a:

line

E :; '"

~

85-

5 6

1 8

o
o

1

C

2

C

o

3

c

o

4

C

At

Operation

Factor 1

:1 ~

Factor 2

Length ~

Name

~ i
-2 :;;

0
z

0
z

0
z

;

[0

of_

:~:~f~ltion I

IIIIII

R..ulting
IndlCltors
Arithmetic

Result Field

Indicators

~

-3 •

75 76 77 78 79 80

1 2

Program

Plus jMinuslzero
Compare

Comments

1>211<211-2
Lookup(Factor 2lis

e

:I: High Low Equal
9 10 1112 13 1. 1S 16 11 18 19 20 21 22 23 2. 25 26 21 28 29 30 31 32 33 34 35 36 31 36 39 40 41 42 43" 45 46 47 48 49 6051 5253 64 55 56 51 5859 50 61 62 63 64 65 66 67 66 69 70 71 72 73 74

~r

~~ ~rr ~h

~L

qq

---

~l

iMlp

~~

iqq

Nf:.. IX IN

1.Jt.

N

ADin Tn Tr UG
~!J;: rrbf

~IJ.I ~~

~l

...

1

~12

t1:G

II

l.Ifl

-@~
RPG

IBM

GX21-9090 UiM 050·

SPECIFICATIONS

OUTPUT

. Printed in U.s.A.

Inrern,llOn" Business M.chlne Corporation

1 2

Program
Page

Programmer

0

~Space

Filename

Line

.... eli

)

5

6

4

0

o

5

0

o
o

6

0

7

0

o
o

8

0

9

0

1 0

0

11

0

~

i~

'AlOe
~r;e

~
3 4

8. .,.

> 1II

....~

o
o
o
o

-=..~ e

AL

! !

..

Output Indicators

Skip

e~
e !!::

I---

0

1

0

z

Field Name

~

8

0

z

z

·AUTO

~

7 8 9 1011 12 13 1415 16 17 18 1920 21 22 23 24 2526 27 28 2930 31 32 33 34 35 36 37

1

OK 1::. ... 1-('11

2

0

3

0

3

Tip

J.I 1.3

Ilip

H

38139

...
End
Positon
in
Output
Record

Commas

Zero Balances
to Print

No Sign

CR

Yes
Yes
No
No

Yes
No
Yes
No

1
2
3
4

A
B
C

a:
.J

75 76 77 78 79 80
of_

0

J
K
L
M

::~a;'Cltion I

I. 1 1 1 1 -I

X •

Remove
Plus Sign
Date
Field Edit
Z = Zero
Suppress

Y

a

Constant or Edit Word

CD

0;:

40 41 42 43 .. 45 46 47 48 49 50 51 52 53 64 55 56 57 58 59 50 6t 62 63 64 65 66 67 66 69 70 71 72 73 74

155

I I".

IN

H

Iy

,..

,. ...

-po

.. I

12.'\ \ A rlr T INt'll
lCi5 \ N AM ~I
175 I r 111\ ("Jr 1,-1
r'\

12

4 It.

lllJ.
ILll

IA

II,!;

r-~ lAG

T

lLl3

III

12_'\

IW' 211 < 211 • 2
Lookup(Factor 21 is
High Low Equal
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

'-I"'\Mle Ar if' T

Figure 5-34. Sequence Checking (Incomplete Specifications)

Controlling Operations In An RPG II Program

5~31

®

L:J
ACCT

L:J-.L:J
ACCT

©

ACCT

5-32

SAVE

/

@

U
Figure 5-35. Moving Data to Save It

move

~\

j

Therefore, each time a record is read, you must save the information from the ACCT field so that it is not destroyed
when another record is read. This you can do by moving
ACCT into another field. (Figure 5-35 illustrates this con-·
cept.)

want to multiply the whole part number field times quantity just because the part of the field contains unit price.
Somehow, you must separate price from the rest of the
field.
To do this you again use a move operation. You cannot
move the whole field into another field as was done in the
previous example. This merely creates a second field identical to the first. You want only the last five characters.
Therefore, you must move the field into a 5-position field.
This will limit the move to five characters (see Figure 5-37).

Figure 5-36 shows the specifications needed to do the job.
Assume that you move ACCT into a field called SAVE.
The first step is to compare ACCT with SAVE (which contains the previous ACCT data). The second step is to move
ACCT into SAVE. In the first program cycle, SAVE will
contain all zeros since all numeric fields are set up with
zeros before the first record is read. I n the next cycle,
and all cycles thereafter, SAVE will contain the ACCT field
from the previous record.

RPG

CALCULATION SPECIFICATIONS

Maybe you are wondering why you would ever want to sequence check by calculations instead of using the RPG II
automatic sequence checking function which is done merely
by specifying a match field. The answer is that, with RPG
II automatic sequence checking, any out-of-sequence card
will cause a halt. If you do not wish to halt, but merely
wish to indicate out-of-sequence or duplicate cards, then
you must do your own sequence checking. You could also
use the look ahead feature, since both look ahead and the
use of moves in calculations give essentially the same results.
PART NO

)

Separating One Field Into Two Parts
A company has designed its part numbers to contain two
different kinds of information. The basic part number is
contained in the first three characters. The remaining five
characters contain the price. For example, in the part number 65J00498, the basic part number is 65J and the price is
$4.98. When preparing invoices, it is necessary to multiply
unit price times quantity to find the total price. You don't

RPG

IBM

Figure 5-37., Separating the Price from the Part Number
(Using MOVE)

Form GX21·9093
Printed in U.S.A.

CALCULATION SPECIFICATIONS

International Business Machine Corporation

1 2

Program

Date

Programmer

C

Indicators

~

gee-

~

=0

~ ~
~ ~ c£
E~~ ~
~ 85 ~
[

line

3

4

0

5 6

1

C

0 2

c

o

C

n

3

7

Page

8

At At

1£

Operation

.g £

Factor 2
Name

Length

~ ~

Arithmetic
Plus IMinusl Zero
Compare

Comments

1>211<211-2
g:¥ Lookup(Factor
2)is

.~ ';
(5
(5
z
z
OJ: High Low Equal
9 10 1112 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 5253 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

~V- I,. h'

Ir-Ir- l/\l!p

R~ IqR

lsl4 1'111=

1MIn IV~ lQ"" ir"1r

lC;IA IVIE

11;10

I

~

Figure 5-36.

Resulting
Indicators

Result Field

Factor 1

75 76 77 7B 79 BO

[I] 0'_ ~;:;~f:ation I I I I I I I

S~quence

C!;;;cldng (Correct Specifications)

Controlling Operations In An RPG II Program

5-33

In this case, the MOVE operation was used. Why wouldn't
the MOVEL operation work as well? Couldn't you move
left into a 3-character field to separate the price from the
rest of the part number? Remember that a move leaves the
original field as it was before the move. MOVEL does not
remove the first three characters from the original PARTNO
field. It merely copies them. You still would not have the
unit cost by itself. But you would have the part number by
itself (see Figure 5-38).

RPG

Changing Field Type (Alphameric or Numeric)
The part number field contains both numeric and alphabetic characters (see Figure 5-38). If you want the program to work with th~ zone portion of a character (as it
must to get the letter J), you have to define the field as
alphameric (blank in column 52 of the input sheet). However, you cannot use an alphameric field in arithmetic calculations. To find total cost, you must multiply unit price
by quantity. This is an arithmetic operation; thus the field
must be numeric.

CALCULATION SPECIFICATIONS

What do you do if you need one field to be defined as both
alphameric and numeric? You could define the field twiceonce as numeric and once as alpharne~ic. Of course, you
would have to use two names for the same field since every
field defined for one type of record must have a unique
name.
You may also use a move operation to change a numeric
field into an alphameric field or vice versa. You can change
fields by:.
1.

Moving an alphameric field named in Factor 2 into a
numeric Result Field.

2.

Moving a numeric field named in Factor 2 into an
alphameric Result Field.

PART NO

/

PART

Figure 5-38. Separating the Part from the Part Number (Using MOVEL)

5-34

Figures 5-39 and 5-40 give the rules for and examples of
the various types of moves you can make to change a field
type. Figure 5-39 illustrates the MOVE operation and Figure 5-40 the MOVEL operation. If you do not understand
results obtained in the low order positions, see the chapter
entitled Working With Data Structures.

Factor 2 same length as Result Field

Factor 2 same length as Result Field]

Factor 2
When moving an alphameric
field into a numeric field,
the digit portion of all characters
is moved. The zone portion of
the rightmost character is also
moved and used as the sign.

Factor 2
When moving an alphameric
field into a numeric. field, the
digit portion of all characters is
moved. The zone portion of the
rightmost character is also moved
and used as the sign.

Result Field
Factor 2
When moving a numeric field
into an alphameric field, all
digits are transferred. The sign
(zone portion) of the rightmost
character is also moved.

When moving a numeric field into
an alphameric field, all digits are
moved. The zone portion of the
rightmost character is also moved.

Result Field

-----------Factor 2 longer than Result Field

---------Factor 2 longer than Result Field

Factor 2

Result Field

When moving an alphameric
field into a numeric field, the
digit portions of only the number
of characters needed to fill the
Result Field are moved. The zone
portion of the rightmost character
is also moved and used as the sign.

Factor 2

)

When moving a numeric field
into an alphameric field, only the
number of digits needed to fill
the Result Field is moved. The
sign of the rightmost character
is also moved.
Result Field

Factor 2 shorter than Result Field

Factor 2
When moving an alphameric field
into a numeric field, the digit
portions of only the number of
characters needed to fill the Result
.....
r-M~--r-J8,' (zone of 0
Field are moved. The zone portion
becomes sign
of the rightmost character is also
of Result Field) moved and used as the sign.
Result Field
Factor 2
When moving a numeric field
into an alphameric field, only the
number of digits needed to fill
the Result Field is moved. The
sign of the rightmost character
becomes sign
is also moved.
of Result Field)

-..

---------------Factor 2 shorter than Result Field

Factor 2

Result Field
Factor 2

Result Field

J

J

When moving an alphameric
field into a numeric field, the
digit portion of all characters
is moved. The zone portion of
the rightmost character is also
moved and used as the sign.
All characters in the Result Fielg
to the left of those just moved
in remain the same as they were
before the move.
When moving a numeric field into
an alphameric field, all digits are
moved. The sign (zone) of the
rightmost character is also moved.
All characters in the Result Field
to the left of those moved in
remain the same as before the move.

Figure 5.39. MOVE Operations Involving Fields of Various
Lengths and Types

Factor 2

When moving an alphameric
field into a numeric field, the
digit portion of all characters
is moved. All characters in
the Result Field to the right
of those just moved in remain
the same as they were before
the move. Thus the sign of
field does not change.
When moving a numeric field
into an alphameric field, all digits
are moved. All characters in
the Result Field to the right of
those just moved in remain as they
were before the move.

Figure 5-40. MOVEL Operations Involving Fields of Various
Lengths and Types
Controlling Operations In An RPG II Program

5-35

I

In order for the letter in the part number ever to be read,
compared, or printed, the field .. lust be defined as alphameric. When it is time to multiply price times quantity, the
price portion of the field must be numeric. Therefore, when
using the MOVE operation to separate the unit cost from
the rest of the part number, you should, at the same time,
change the alphameric unit price into a numeric unit price
by moving it into a numeric field. To define a numeric
field, you must specify decimal position along with field
length (see Figure 5-41).

When using move operations to change an alphameric to a
numeric field, keep in mind the kind of sign (plus or minus)
each character will give you: a - (minus sign), or J through
R gives a minus sign; the rest give a positive sign. If you are.
aware of this, you will not get unexpected results. Since no
sign is involved in an alphameric field, you don't need to
worry about the sign when changing a numeric to an alphameric field.

BRANCHING IN CALCULATIONS
If the 5-character unit cost had preceded the part number
(for example, 0049865J), you would then use the MOVE L
operation to get the unit cost alone. Remember, however,
that th~ zone of the rightmost character is used for the sign
of the field (see Figure 5-40). The zone of the character J
is a minus sign. The price will appear as negative. This you
would not want.

TIONS
1

Page

The part number field
is defined as alphameric
since no entry has been·
made in column 52.

2

[I] (

Field Location

."

g

0

.v;

.,.
0

From

To

Field Name

~.~
0

1

The price section
of the part number
---'---'---"--"-'--'---'---'-~-=Ca-rd-::E-:-lec-trO-:-N-um--!b& field is changed to
:~~~n
I a numeric field by
_ - - - "_ _--'---'---L---'---'---'---'---'-_ _ _- - ; moving it into a
CALCULATION SPECIFICATIONS

Result Field

There are many times, however, when it is necessary that
operations not be performed sequentially. For example, in
one cycle you may wish to skip some calculations or to do
others several times. In this section you will learn to alter
the sequential processing of calculations using the most
efficient coding.

]

44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

~PG

The detail and total operations written on the Calculation
sheet are normally executed in the same order as they are
written. For each record selected for processing, the detail
operations are performed sequentially from beginning to
end. If the record selected for processing causes a control
break, the total operations are performed, in the order
specified, before detail operations.

numeric field. Two
decimal places were
specified to show
~ the cents portion
.~ of the field.
o

Bypassing Calculations
So far you have been bypassing operations by the use of
indicators. For each calculation conditioned by indicators,
a check is made to see if the condition set by the indicators
is satisifed. (When several sequential operations are conditioned by the same indicator(s), the test is only made on the
first operation.) If the condition is satisfied, the operation
is performed. Calculations are bypassed or omitted when
conditions are not satisfied. When bypassing calculations
in this way, the program has to check the conditions set for
the operations to determine whether or not to do them.
This requires time and storage space inside the computer.

w

Operation

:!

Factor 2
Name

Length

Figure 5-41. Changing a Field by the MOVE Operation

5-36

Another way to bypass calculations is to branch .around
them. With the latter method, the indicator setting for
each operation is not checked. When the branch is taken
around operations, the operations are just skipped (see
Figure 5-42, insert A).
Two operation codes are used for branching: GOTO and
TAG. GOTO is the code which causes a branch to another
spot in the calculations. The TAG operation gives the name
and location of the spot to which the GOTO operation
branches. GOTO causes a branch; the TAG code does
nothing but act as a nametag.

NEXT is found. NEXT is the name of the TAG statement.
Any operations between the GOTO statement and the TAG
statement (those specified in lines 03-05) are skipped. TAG
does nothing, so the next operation performed is the SUB
instruction in line 07.

Figure 5-42, insert B, shows how GOTO and TAG are specified. GOTO signals a branch to the spot named in Factor 2.
') This name must also appear in the TAG statement, where
it is entered in Factor 1. The rules for forming a name for
GOTO and TAG are the same as those for forming any field
name.

If branching were not done, the three operations skipped
by the branch would have to be conditioned by NO 1 so
that they would not be done when 01 turned on. And, of
course, a check would have to be made in each program
cycle to determine if the operations should be done or not.

A GOTO statement can be conditioned by an indicator, but
a TAG cannot. When a GOTO is not conditioned, a branch
occurs in every program cycle.
In the example shown in Figure 5-42, the GOTO operation
is done only when 01 is on. If the condition is satisfied, a
branch is taken to that point in the program where the same

There are many situations in which branching will help you
write more efficient and effective programs. The following
sections will explain more fully the use of GOTO and TAG.

Skip these
operations if
_ _ _ _ _ _ _ _ _ _ } 01 is on.

0(1 _ _

)
RPG

IBM

Form GX21·9093
Printed in U.S.A.

CALCULATION SPECIFICATIONS

International Business Machine Corporat!on

1

Program
Page

Programmer

c

13 4

!
I;

75 76 77 78 79 80

~~~~!:~s

~

Line

Date

2

[DO!_ :~~~f:ation I I I I I I I

If!

~ IJ: ,~

10 1
10 12
101 3
a 14
a 16
a 16
:a 17

C

(B\

C

,

A ~d

10 11

!,~

J
1920 21' 22 232425 26 27

RAil ~r 1=
rlll

C

C
C

c

Operation

Ijl~

Factor 2
Length

Name

c

C

Factor 1

AId

~".",

I~'~.~.~""

lAlnln

143 44 45 46 47 4S 49 50 51

lc;

ig,llll'

-,

RI~

1\1 r 11=

r,1"rr
...... ~ h'==t::
-- ~-'
,"

N~.x

RA It IN r,:

I~I~

I!I!

A Hhmetic
Plus Minusl Zero
:ompare

Comments

1>2 1 <211-2
,I~,
'2);s

~i9:5 5~o:" :i~~ 160 61
i

62 63 64 65 66 67 68 69 70 71 72 73 74

I~ rJJ

,--- f -

iT lAIC;
~II I~

...

,~r.

,~

r~

"

Figure 5-42. Bypassing Calculations by Branching Around Them

Controlling Operations 11;'1 An RPG II Program

5-37

Consider the use of such a bran~hing structure in a sales
analysis program. Each day the manager of a retail store
wishes to know total cash sales, total charge sales, and total
refunds. The input file, arranged in ascending order by account number, contains four different record types:

Branching When Different Record Types Require Different
Operations

When doing different operations for different recordWpes,
you use the record identifying indicators to show what operations should be done for each record type read (see Figure
5-43). When you have several record types and each type
requires several operations, you can see that many conditioning indicators are necessary.
For situations like this, you can branch directly to the set
of calculations which should be done for the record type
just read. When those calculations are done, you can then
branch to the end of all calculations. This eliminates checking operations to see if a set of calculations should be done
for the record'type being processed. In fact, record identifying indicators do not need to be specified for the individual
operations. Figure 5-44 shows the recommended branching
structure used for different record types which require different operations. Using this structure not only makes your
programs more efficient but also makes them easier to understand and document.

RPG

IBM

International Business Machine

rProgram

I

1

o
o

2

~
I; 6

b

4.

Cash sales records record total cash sales and cash refunds (if any) for a particular account.

CALCULATION SPECIFICATIONS

Form GX21·9093
Printed In U.S.A.

Graphic

Punching

Instruction

.1 Punch

I I
I I

I
I

Card Electro Number

I
I

Factor 1

Operation

5
6

o

7

c

o
o

8

C

O'~

9,

c
c

~IL

.~

Factor 2

Length

Name

'8

~

E

':rl

z

c

~II

~12
~12

iRIl; ~i~IV
'RIF= Ir 1,:lv
~ID ,J~ IrlD
lAin .1 IrIln
AID .HJ lsrr
14ln .I J Ish"
lAin .1 J lc;h"
1, .

(I,';)

~l

(l'~

~11.

~2

~12

I~

Il-ltot

~n'n

~nlD

,..,.. 'Mlp
.,.,.. Il\1lp
A,C:f:'
~lnlD

'A I,.., In

(JLl

!TI~ Ie; II~

~rllf:l

Ir~~

IRIJ:' IfooU [IR
IR.I~ '-IAIJl
I_I_
IIN 1M
r,..,11l I,IJI I~ Irl
1-1 ..
IJIII. ,'"

~Inlr:
lAlnlrl

11

C

rli5

1 2

C

~:h

1 3

C

t7~

1 4

c

I?lb

1 5

C

rzll,

lAIM)
lAin''''
~lDID
~Inln

IHIr-

J:T NIR I~'"

'rfJ 12'

!AID J~ lL\N
F[ NLA I.e J
IT II 1M

IH": JI~ :t\N
Ftr II\JIA n I

II
II

1M

II ~~
1r=lr INII l.sls
II IIIK It:~
II IIIK II:. [.,
II II I~IL
It=lr Nlo IPI~
1\111= I~H laiN

I~

2

75 76 77 78 79 80'

~~~;~f:ation I

H

rJ'd.

rrl c;lc:

I.

54 55 5657 5859 6o 61 62 63 64 65 66 67 68 69 70 71 72 73 74

These operations are
done on record type 01.

Iql, 1\
Iql,

1-,111
I,,~

~~

I-'~

I)

,

I I I I I I I
I I I I I I I

5~38

1
I

I I I I
I I I I

These operations are
done on record type 02.
This operation is done
on record type 03.
These operations are
done on record type 04.
This operation is
done on record type 05.

~~

These operations are
done on record type 06.

~ro

·11 I I I 1 I I I I I I I
I

Figure 5-43. Operations Performed for Different Record Types

IIIIII

Comments

~~

~

11=11 INcr- Ic;~
II If( lrol"l
II I :H 1"'.I"l
II II IJoe
IFlr N~ Ipl~

Resulting
Indicators
Arithmetic
Plus!Minu$f Zero
Compare
1>211<211-2
Lookup(Factor 2)is
High Low Equal

~I(}

'lZ lL'

A!nln

~14

I~

1_1-

II 11t'(1~
It: I INIR II; ,.

1

pageDJOf_

9 10 II 12 1314 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 4B 49 50 51 52

o

1 0

Refund records record any refunds made for an accou'nt. No cash and charge sales were made by this
customer.

b

b

z

z

o
o

4

3.

~

C
C
C
C
C
C

3

Payment records record any payments received. They
are included in the file, but are not needed in this job.

Result Field

At At

8-

E

o

2.

Indicators

C
4

I

Date

Programmer

3

Charge records record total charges and refunds (if
any) for a particular account.

Corpor8t~on

I

line

1.

II I I I I I I I I I I

/

RPG

)

IBM

CALCULATION SPECIFICATIONS

Form GX21·9093
Printed in U.S.A.

Internltional BUsines' Machine Corporlt!on

Programmer

C
I---

Indicators

~

~a:
GiQ

5

At

Result Field
Factor 1

Jd

Operation

Factor 2
Name

e ::. '"
~ 85 ~
6

Page [ D o , _

Oate

!3~
I- 00:

Line

15

z

15

z

4

o
o
o

1

c

~lL

Gin IT~

2

C

~~.

~I'" Irln

IRI,., JlrlL
I~II"I II rrl2.

:"$

c

l1.B

r:~ tr~

o

RID l

4

C

o

6

C

o

6

C

o
o
o

7

9

c
c
c

1 0

C

1 1

C

1 2

C

1 3

C

1 4

c

1 5

C

1 6

C

1 7

C

1 8

C

1 9

c

2 0

C

c
c
c
c
c

)
U

7

8

Length

Resulting
Indicators
Arithmetic
I!!
Plus IMinusl Zero
:~~ ~
~
Compare
1>211<211-2
Lookup(Factor
2)is
'u C J: High Low Equal

:~;~:.tion I

IIIIII

Comments

~i

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 33 34 35 35 37 3B 39 40 41 42 43 44 45 46 47 48 49 50 51 5253 54 55 56 57 5859 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

3

8

75 76 77 78 79 80

1 2

Program

Gb ~(,o,

~~

(;1/"1 IT 11"1
I~'~

JITil

rrl3

~I'" Il'rl4
If:NI~

rrlA~

1('

IJ

II
1-

IK

l..l

GI/"I IT I" lENin
rrld;
Ie
I~

r.;1I'l Irv,

lRolulri3

If~ID

triAIl;

It:

I~

IRb JrrlLl

r,'" IT I,...
Tl4It;

I~II\ID

TIAIG

I~N·I"I

~

IL OL 69 89 L9 89 SII til t9 III 19 09 69 89 L9 99 99 til t9 ~9 15 09 6~ ~ L~ 9. 5~

n

t:~ ~~ I~ ~

6t: 9t: Lt: 9t: 9t:

~

t:t:

~t:

IE at: ~ 8Z L~ 8Z ~ .~ t:~ U

I~ O~

61 81 LI 91 51 ~I EI ~I II 01

6

8

L

9

5

~

t:

~

I

Figure 5-44. Recommended Branching Structure

Controlling Operations In An RPG 1/ Program

5-39

RPG

IBM

GX21-9094 U/M 050'
Printed in U.S.A.

INPUT SPECIFICATIONS

Intern.tion.1 BUliness Machine Corporation

1 2

Program

-

Page

Dal.

Programmer

Record Identification Codes

~

I

]

5

~
f-

~

-f--~
o R z

r~

~

1i

7

8

3

4

1

o

2

IIDlA
I

o
o
o
o

3

I

o

Position

j

t

~ 2E
~ U

Position

_
~

!l

e

e

Position

~~6

<5

0

~~

~ U

~~~

Field Name

-

From

~

To

~

~~~

·2

]
g

'8

0

Field
Indicators

LLLL

II

-"
~
"C

.J
"C

-;;
iL

Zero
Plus Minus or
Blank

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 4142 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 6364 6566 6768 69 70 71 72 73 74

Q;

~11

c

II

q'b ~II-I

... ~

11

:

Is

A

-IT 'IV
AI .... !,-,..-

lLril

Illb ILl"

2.IQJ

lib 12'" He; !RIE:~

4

I

5

I

6

I

lL

7

I

ll~

lib12.P AY Mr-Jr

o

8

I

o

9

I

1 0

I

lL
llrl

,I~

bR s=r: liNn

11

I

18

Ar rlr IN'r,

lAr

rJj~

F1!b

~Ih

rtJ3

A""

rip

"R

I

~4

At"

AlS

Irr

Q

A

1 2

I

lL

I

lLrl

• =--..

I
I

l~

II'N.'I"'

.s Ar rrr IN'"

q'h "'A

1 3

(A)

E ~i
0

..

ii

f;f-;;"ii

o

6

co

0

go.

i
l

Filename

line

Field Location
3

2

1

75 76 77 78 79 80

[JJ0f_ ~~~;~f:tion I I I I I I. I

II~ 2'" Ac;11-J
~It.. -:>,.. Ac; HRI1=

12~

IlL

"1 I _

RPG

IBM

Intern.tional BUlin'" Machine

Form GX21-9093
Printed in U.S.A.

CALCULATION SPECIFICATIONS

Corpof'l~on

75 76 77 78 79 80

Program
Programmer

-c

Indicators

Result Field
Factor 1

Operation

i;

.f
8

2

C

3

C

o
o

4

C

5

C

o

6

C

o
o
o

7

C

8

C

9

C

1 0

c

Length

Name

~

E

;

~

Z
9 10 11 12 13 14 15 18 17 18 19 20 21 22 23 24 25 28 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 48 47 48 49 50 51 52

Resulting
Indicators
Arithmetic
Plus IMinusl Zero

5 lJlB
"IHl:IKII:.It-

AOID

1t'{1'" II'"

Aloin

lIe

Comments

Compare

1>211 <211-2
Lookup(Factor 2)1.
High Low Equal
54 55 56 57 58 59 50 81 82 83 84 85 88 87 68 89 70 71 72 73 74

,..
I

".

Il\n,.:1'"

rr

-,

II KIl!'"

J:~IR
15

C

~A5H

~Ioln

~U
KI~I"

Figure 5-45. Sales Analysis Job

5-40

IIIIII

Rf'lJTlzl

Ole

o
o

!

Factor 2

&
E

4

DII8

~

Line

3

~~~:;ation I

rlYp~

rzlLj

\

1

Figure 5-45, insert A, shows the input specifications for all
record types. Notice the record identifying indicators assigned to each record type.

RPG

CALCULATIO

International Business Machine Corporation

Date

In the calculations, all charges, cash sales, and refunds are
totaled. If a refund is given along with the cash or charge
sales for an account, the amount of the refund is subtracted
from the amount of the cash or charge before the cash or
charge is added to the total. Figure 5-45, insert B, shows
the calculation specifications for the job. As you see, the
recommended branching structure was used. If a charge
record (type 01) is read, a branch is taken to ROUT01. Calculations specified in lines 06-98 are performed. Then a
branch is taken to END, for there are no more operations to
do for that record. Branching for record types 03 and 04 is
handled in the same way as for record 01. However, when a
payment record is read (02 turns on) no calculations are performed because this job is not concerned with payments.
Therefore, a branch is taken to END. In this way all calculations are bypassed. They are not even checked to see if conditions established by indicators are satisfied.

Indicators

At

~

1

Factor 1

Operation

Factor

l-

E

'0

'0

z0

~

z

6

9 10 1112 13 14 15 16 17 18 19 20 21 22 23 24 25 26 21 2829 30 31 32 33 34 35 36 31 3B

C

Z

GI"I Tn I,:: Nln

INlfI'lR

c
c
c
c
c
c
c
c
c
c

-~

TIAIt;

IfND

,.

Figure 5-47. Branching in a Matching Records Job

Branching in a Matching Records Job

)

Suppose that you are doing a matching record job which requires that all calculations be done when records match.
All specifications can be conditioned by MR (see Figure
5-46), or GOTO and TAG can be used to branch around all
calculations when records do not match (see Figure 5-47).
In this example, GOTO is conditioned by NMR. When records do not match, all calculations are skipped and a branch
to END occurs.
RPG

Branching When An Error Condition Occurs

Branching is an easy way to bypass all calculations which
should not be performed when an error occurs. Figure 5-48
shows an example of this.

CALCULATION

nternational Business Machine Corporation

RPG

Date

Date

Indicators

Indicators

At Jd

8.

Factor 1

Operation

~

Factor 1

Operation

Factor

l-

]

~

6

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 21 2829 30 31 32 33 34 35 36 31 3B 39

C

At At

Factor 2

~

c
c
c
c
c
c
c
c

CALCULATIO

International Business Machine Corpor.tion

'0

z

E

'0

&

Z

MR

C

MR

c
c
c
c
c
c
c

f'itR

MR
f\1R

MR
MR
MR

ft

6

'0

'0

'0

Z
z
9 10 1112 13 14 15 16 17 18 19 20 21 22 23 24 25 26 21 2829 30 31 32 33 34 35 36 31 38

z

(;1"1 T~

J-fll

~IN"

FNID

TAG

I

Figure 5-48. Branching When an Error Occurs

J

Figure 5-46. Conditioning all Specifications by MR

Controlling Operations In An RPG II Program

6-41

Branching at Different Points in the Program

Within one program you may use any number of GOTO
and TAG operation codes. One or more GOTO statements
may have the same name (Figure 5-45, insert B, lines 02, 09,
and 12). However, each TAG must have a different name.
If two TAGs had the same name, your program would not
know where to branch.

Branching at Detail and Total Time

You may branch from one detail calculJltion to another detail calculation or from one total calculation to another
total calculation. However, you cannot branch from a detail to a total calculation or vice versa.

Branching Backward
So far, you have learned only about branching forward in
order to skip statements that you do not wish to perform.
The GOTO statement can also branch backward. In this
way you can go back to statements that were already done
in order to do them again.
Doing the same statements over and over again in one program cycle is called looping. The statements done several
times in one cycle, plus the branching statement, make up
the loop. Figure 5-49 shows the basic structure of a loop.
When would you want to branch backward? Suppose you
want to print out several mailing labels for each customer
by using the EXCPT operation code (see Repetitive Output
(EXCPT Operation) in the chapter, Programmed Control of
Input and Output for an explanation of the EXCPT operation). EXCPT is used to write several output records in one
program cycle. If you want to put out 25 mailing labels for
Joe Aaron, you would have to write the EXCPT operation
25 times - one time for each record. However, instead of
writing EXCPT 25 times, you could use a loop. One EXCPT
code is specified. It is performed and then a backward
branch is taken so that EXCPT will be done again.

Look at Figure 5-50. The loop just described is coded here.
But look at what will happen: An EXCPT record will be
printed; a backward branch will cause the EXCPT to be done
again; then another branch, and another EXCPT. When
would execution of the statements in the loop end? As
coded here, execution of these statements would go on indefinitely.
You want to stop printing mailing labels for Joe Aaron after
25 have been made. Therefore, you have to keep track of
the number printed. This is done through the use of a special count field which is constantly updated to reflect the
number of times looping has occurred. Figure 5-51 'shows
the way this is done. At the beginning of each cycle,
COUNT, the field used to keep track of the number of records printed, must be zero. Each time a record is put out,
1 is added to COUNT. COUNT is then compared to 25, the
number of mailing labels desired. When COUNT equals 25,
calculations will be complete for that program cycle, ~nd
looping will stop. When COUNT is less than 25 (indicator
10 is on), a branch is taken back to the beginning of the calculations so that they can be done again.
In this example, 25 mailing labels are created each cycle (for
each re'.:ord read). If a different number of records are requirec to be printed or punched for each cycle, you have to
comrJare the COUNT field to another fieldwhich contains
the number of records to be put out in that cycle (see Figure
5-52).

RPG
1855

Date

Indicators
f---

Jd At

Factor 1

Operation

Figure 5-49. Structure of a Loop

5-42

Factor 2
~

15

z

15

Z

)11 12 13 14 15 1617 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 36 39 40 41 42 43 44 4

~Ib 'AITI~

trl4~
t-~

r,~

01---------------------\:) LOOP

CALCULATION SPECI Fie

Machine Corporation

Figure 5-50. An Uncontrolled Loop

...._1... 11

rrn

~G AI

N

RPG

IBM

')
/

Form GX21-!1093

CALCULATION SPECIFICATIONS

Printed In U.S.A.

Intern.tlonal BUlln.u Machine Corporltlon

1 2

Program
Programmer

-

C

Page

Data

Indicators

~

0_

Jd Jd

~~

!.§~

Factor 1

Operation

:~ =

Factor 2
Name

~~; ~

5

I;

I;

z

z

4

o
o

1

C

Ito,...

2

C

ll\r; It\1r tJ

o

3

c

o
o

4

C

[

5

C

Ir:O IllNiT

o

6

C

o

7

C

7 8

Comments

i!

9 10 11 12 1314 16 18 17 18 19 20 21 22 23 24 26 28 27 28 28 30 31 32 33 34 35 38 37 38 39 40 41 42 43 44 45 48 47 48 49 50 51 52 53 54 55 5857 5859 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

3

6

R.sulting
Indicators
Arithmetic
Plu.!MinuSf Zero
l'l ~
Compare
Length
1>211<211-2
Lookup(Factor 21is
II ..
c::t: High Low Equal

Result Field

~ '0 a:."

Line

75 76 77 78 79 80

[DO!_ :~:~!:atlon I I I I I I I

,INT

~ Jlp,
h"~IG

ifo~

NIT

rh IN iT

~OID

ril'l

IN IT

~lt"'I

"'' ' trn

121.;

110111

IEIY

l~

I~ rl

1M'"

ICtIr-

JNrr
II~

IAI(:, ~lrN

Figure 5-51. A Controlled Loop

RPG

IBM

)

I"remldon"

Form GX21·9093

CALCULATION SPECIFICATIONS

Printed in U.S.A.

BUII~ Machine Corpora~on

1 2

Program
Page
Programmer

c

~

Indicators

9-

~
Line

Date

i

I

I

And

p),d

!

Factor 1

~ ~~ ~

~

5 8

o
o
o

1

c

~~llINT

2

IAGlc\lrN

o
o

4

o

6

o

7

C

6

8

~

4

c
c
c
c
c

7

~~

Factor 2
Name

3

3

Operation

~.!l.

.f85~

~~i:!:'

Result Field

I

9 10 11 12 13 14 16 18 17 18 19 20 21 22 23 24 25 28 27 28 28 30 31 32 33 34 38 38 37 38 39 40 41 42 43 44 46

11

Ic;lll~

NIT

IAloln

~ ~ L INIT

V''''IIIN,T

48

75 76 77 78 79 80

[DO!_ :~:~;:ation I I I I I I I

Length

Arithmetic
Plu.

J::~ Zero

~ ~

1 >2Tl <211-2

:!:

Lookup(Factor 2)1s

.~

Comments

~:EHighLowEqual

47 48 49 50 51 52 63 54 65 68 57 68 59 50 61 62 63 64 65 68 67 68 69 70 71 72 73 74

ifoh 11\ T

12~

il~

Flri=llln IMIAV

Figure 5-52. Printing a Various Number of Records in Each Cycle

Controlling Operations In An RPG II Program

5-43

cycle). A subroutine is a routine that is part of another
routine. That is, a subroutine is a group of operations that
can be used by the main routine several times in the same
program cycle. A subroutine can also be a sequence of
operations that is coded once and included in several different programs.

You can have as many loops in your program as you need.
You can even have one loop within another loop (see Figure 5-53, insert A).
Keep in mind, however, that an uncontrolled loop is an endless loop. Each loop you create must be controlled so that
it will be performed onlya limited number of times. Always
set up a condition which when satisfied will cause looping
to stop (see Figure 5-53, insert B).

Subroutines can be used to:

e Eliminate duplicate coding by performing the same calculations several times in the same program cycle or in
several different programs.

USING SUBROUTINES IN CALCULATIONS

A routine is something done over and over again. The calculations in your program can be called a routine because
the operations are done again and again (on each program

Ci)

Reduce the storage requirements of RPG II programs
(see Controlling Overlay by Using Subroutines in this:
chapter).

1

------------------1

------11
------·11
------It
- - - - 1l
_________________

/'

""-_r.:::;;-

®
RPG

IBM

International

CALCULATION SPE

B~sine$1 Machine Corporation

Program

Dote

Programmer

-C

Indicators

I;

9 10 1112 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 3031 32 33 34 35 36 37 38 39 40 41 4

1

C

2

C

o

3

c

o
o

4

C

5

c

o

6

C

o

7

C

o
o

8

c
c
c
c

@r
Figure 5-53. A Loop Within a Loop

5-44

Factor 2

z15

o
o

11

Operation

6

4

9

factor 1

]
3

1 0

At . Jd

~

~

line

5

z

15

Z

p~

TAr,

on plE

TAt;

'rtf"',

1~

C;"" T'f"I IL

I" ~IPR

lL 1

GI"I Tb II

h hiD A

The backward branches
will be done only when
conditions are satisfied.

Using Subroutines to do the Same Calculations Several
Times in One Cycle

)

The area in which all salesmen work is divided into three
districts: A, S, and C. Some salesmen work in only one
district. Others may work in parts of two or more districts.

In many 9f your programs, the same operation(s) may be
required several times in one cycle: When coding the job,
you can specify the operations as many times as needed.
This often involves large amounts of coding, however. If
the same operations are to be done several times in succession, you can often use looping to reduce the amount of
coding. This was explained in the previous section.

For each salesman, the input file contains a record formatted as shown in Figure 5-55. The amounts in the district
fields show total weekly sales made by that salesman in
each district. If the salesman did not work a district or
made no sales in that district, the field contains a zero.
The report must contain the commission earned in each district by each salesman. In addition, total commission must
be accumulated for each salesman and for each district. The
percentage of commission is:

What if the same operations are not done several times in
succession, but are performed, instead, at many different
points in your program? Creating a loop couldn't work in
this case. As an example, consider the job which creates a
weekly sales commission report. The report desired (Figure 5-54) shows two things:

1.

Total commission earned by each salesman.

2.

Total commissions paid in each district.

•

3 percent of the gross sales .01 to 1000.00 dollars.

•

Plus 2 percent of the gross sales 1000.01 to 5000.00
dollars.

•

Plus 1 percent of the gross over 5000.00 dollars.

COMMISSION REPORT

)

Salesman

DistA

Joe Arness

41.93

Dist B

Bob Brown
Charles Butler

r

26.98

Dist C

Total

23.16

9.43

113.16

24.93

138.09

449.16

109.38

585.52

74.52-0)

\..

986.43 *

1,998.02 *

1,043.97 *

-0

1

Figure 5-54. Sales Commission Report

SALESMAN
1 2 3 4 5 6 7

a

.

DIST
A

DIST
B

DIST
C

9 10 11 12 13 '4 1515 17 Ie 19 2021 22 n 2425 26272829:W 31 32 3334 3536373839 40 41 42 4344 45 46 " .,,'" " 52

~~ J
" " 51 5a 59

Figure 5-55. Input Record for Sales Commission Report

Controlling Operations In An RPG II Program

5-45

Figure 5-56 shows ~he calculations needed to find the information required for the report. You first compare the contents of each district field to zero to find out if the salesman sold anything in that district. If it is not zero, you calculate the commission (COMM) earned. You then add commission earned to total commission for the salesman
(MANTOT) and to total commission paid in each district
(TOTALA, TOTALB, or TOTALC).

Using the branching you have learned about so far, the
branching that uses GOTO and TAG, you could easily
branch to the calculations needed to find commission. But
/
I
since you could branch to them from three different places,
it would be difficult to determine to which point in the
calculations you should return. You could return to the
point where totals are accumulated for district A, the point
they are accumulated for district B, or the point they are
accumulated for district C. Imagine the number of indicators and SETON and SETOF operations necessary to do
this. Wouldn't it be nice if the program would automatically
go back to the point from which it branched?·

The calculations needed to find commission earned are the
same for each district (Figure 5-56, inserts A, B, C, lines
3-16). Why code these calculations three times? Why not
code them once and branch to them each time they are
needed? (See Figure 5-57.)

RPG

IBM
I Program
IProgrammer

Jnternationa' BUliness Machine

C
I---

o
o
o

1

~

5

.f

8

6

7

C

3

c
c
c
c
c
c
c
c
c
c
c

1 4

C

1 5

c

1 6
I 7

o

6

o
o
o

7

5

8
9

1 0
11
1 2
1

Jd

Graphic

Instruction

Punch

I I
I I

I
I

0

0

Form GX21·9093
Printed in U.S.A.

1 2

Card Electro Number
Page

I

75 76 77 78 79 BO

[DOf_ ~~;~;':Ition I I I I I I I

Resulting
Indicators
Arithmetic
g Plus IMinusl Zero
Compare
Length ce ; 1>211<211-2
~~ Lookup(Factor 2)is
'u ::
High Low Equal

Result Field

At

Factor 1

Operation

:§

Factor 2

0

Comments

(

ox

Z
Z
9 10 11 12 1314 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 3031 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 56 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

Z

... ..,

qlq

~

-

~

I ..

I~

I-h IMQ

t;h tr""
~I,..,
IMP I/~ (lr/l
!MIll T
~'3

U2J

nrr C:;iflA

1fll

11

-nlr

LJ

""'1 v:t:IR

Mil IT

11

I~~

~ID""
~Ic Tn

115 II~

~rrl.Ll

.. ~~

...

11

Gh TO
~~ fYjp

~I' A

~2

~h MIMIA

1,.21-1

~v FIR

/'2

\

I/~ I I 1/11
~,..

IYI

~

"
LR

~Iv !~IR

Is 8
M tT

I,,~ ~~

12
12

llllt2l fZC2

~D~

I,.

J II~ L~
l-t"'I M~A

trAG
ADlJ

C

;,..

AlJD

C

I~

IY IIYI

I

~IA

'- IJ.~ II~

-.

11~ ~~

rlt

'P'A IA
s-Ia ~(/] lila
!,-~ flJ't1J t?J~

12

II

1

:qlq

~
'R

i(ll}'

)

Calculations
required to find
commission earned.·

Ir.V :EIR
I....

A

"
J..I

1'"1

J

A

..

H

If M

1"'1 A N'"

II"R.IN

P-

U

1Y11I"'11Io\

~~
MIl'll

MIMIA

IA

"""A

-IA

1,12

7;'

T~!G

@.c

Figure 5-56 (Part 1 of 2). Calculations for Sales Commission Program

. ·5-46

I

Name

C

2

4

Punching

~o

3

o
o

I
I

Indicators

~

E :>

4

CALCULATION SPECIFICATIONS

Corpol'I~on
OIl.

K3

line

3

RPG " can do this through the use of a subroutine. Your
entire program is the main routine. The operations to be
performed several times in the program cycle make up a
subroutine. In this case, the main program uses the subroutine to find commission earned.

I

',,-.

RPG

)

.IBM

---ll

I-p_rog.:.,.r_am_ _ _ _ _ _ _-r-_ _ _ _ _

Programmer

I

Oate

C

I

Graphic

Punching
Instruction

Indicators

15
6

9 10 "

o

1

C

o
o

2

C

3

C

4

C

Ilia

6

C

LL:

o 6

C

o
o

Arithmetic
.g ::t: PluslMinu$f Zero
'g ~
Compare
Length ~ ~ 1 >211 <211-2

Operation

Factor 2

Dllsrrls
~

1t}1C)

I. rJj rzJ~

Il"'Ilr lc;lTlR
~iL

Inll ~triR

Ia

o

8

C

o

9

C

1111

Ir-Iv iJ:'IR
I~i~ rzi~

1 0

C

1 1

C

1111
,12

Ir,rr lc;1T1~

1 2

C

1 3

C

1 4

C

1 5

- C

1 6

C

111
Illl

I

6 Is

lIlT

I~

1112
1112

Ir-Iv II=I~

It IJ Qj rlltl :
1-1-

!-rIA
'IYI 'fY

I~'

~llltlr
IA I,.. ID

1M

IrlAIG

I)

IAAIA IN'" I..... I-r

1Ml4 ~Ir IrIT
rrl", trL4 ILIA

IA lr In

k..I

u~

~1t-1 ,I~I~IR

IfTlr211<211-2

Name
15
z

2

[I]

ReSUlting
Indicators

Result Field

8-

1

Card Electro Number

I-p-unch--+-+--t-I-+-+I~+I-ll

Indicators

E

- . . -.
j

hlv IEIR

Intlmational Business Machine Corporation

Factor 1

1 7

5" ~rl k'lkl
lit11

~

5

Calculations
required to find
commission earned.

j,..

C

4

II

II-Ifol ~~IA

I"', I" 11'

Irh 1~1~IA

C

Lin.

)

k.4

tJ"1r- IT~ Itl~

Program

3

II I, IIII 1.1,
IroIV 1,:11;1
Irlr- IMlrvl~

~~

rtl2

Ip,lnln

1
I------------.-Programmer
o-ot-.------ll

-

l~ lel€

1\

~171'"

1"11",11"1

rr~ trIA It If.:!
1l\'1t7l ~~ ~~

I""lr lslrlE
InlI Is IT Is

_C

II~ IL~

l2lrl

l2B

IllT

RPG

)

·a - Lookup(Factor 2)is

15

7

IBM

Comments

Z
Z
c ::t: High Low Equal
12 13 14 15 18 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 31 38 39 40 41 42 43 44 45 46 41 46 49 50 51 52 53 54 65 66 57 56 59 50 61 62 63 64 65 68 67 68 69 10 11 72 13 14

o

1 7

IIIIII

II!

Name

I;

:~~~~f:atlon I

Resulting
Indicators

Result Field

Factor 1

4

75 76 77 78 79 80

Page [ D O f _

I

- Punch

1 2

Card Electro Number

I--

3

Form GX21-9093
PrlnttdlnU.S.A•

CALCULATION SPECIFICATIONS

Internltional BUlinl" M.chine Corporlt!on

sit IR
IMlllllr
IAlelD

II jqlt

Calculations
required to find
commission earned.

Ie.
I"~U If~

rtll

~

I"

~1f"I IM~~

Ir~IG

IAlrln
IA 11'1 In

I

II1J lAIN II

11

IT IrlT ~ It I,.

~IA r-.Jlr IclT
II

tI~

II-

1,,/2
170

IT IA Il;

Figure 5-56 (Part 2 of 2). Calculations for Sales CommissicH; p,.,gram

Controlling Operations In An RPG II Program

5-47

RPG

IBM

Not this:
District A

Program

Punching

Programmer

Instruction

~ calcul~te.
\ commission

10ate

C

~

line

~3~
I- '00:

-

Accumulate totals

~ calculate
S commission
Accumulate totals
District C
calculate
commission

1

4

o
o

1

2

o

3

o
o

5

o

6

o
o
o

8

4

7

9

1 0

Accumulate totals

1 1

But this:

AL At

-'a:
=0

3

I;

/

1 Graphic 1
.1 Punch
1

(
'-

Indicators

0_

E l:l

District B

CALCULA-

International Businesl Machine Corporation

C/I

~

8 5~ z0

6

7

8

0

Z

CI~IR

1 3

C

Operation

Fa

~

9 10 1112 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 26 29 30 31 32 33 34 35 36 .:

C
C
C
C
C
C
CISIR
CIc;IR
CISIR
C1S1~
CISIA

1 2

Factor 1

C;IUI~

Ir-Ileo I'"-~Io

1~11\o InlsR

District A

~

Figure 5-58. Structure of a Subroutine

Accumulat~

District B

~ Calculate

_

_-~.-J7

Commission

Calling the Subroutine
District C
Accumulate totals

Figure 5-57. Branching to Similar Calculations

Specifications for Coding a Subroutine

Subroutines are specified on the Calculation sheet after all
detail and total operations. Every statement in the subroutine must be identified as part of the subroutine by the
letters SR in columns 7-8. (See Figure 5-58.) In addition,
two operation codes, BEGSR and ENDSR, are needed to
establish the beginning and end of the subroutine.

When using GOTO and TAG, you use a GOTO operation
code to branch to the next operation to be performed.
When you do the operations in a subroutine, you do not
branch to the subroutine; you call it.

(

When you call a subroutine, you use the execute subroutine
(EXSR) operation code. This operation code can be placed
anywhere in the calculation operations. Whenever the
EXSR operation code is encountered, all operations in the
subroutine will be performed. After the subroutine has
been executed, RPG II branches back to the main program
and continues execution with the next statement after the
EXSR statement (Figure 5-59).
Factor 2 must contain the name of the subroutine to be
executed. This same name must appear on a BEGSR
instruction.

Every subroutine used in the program must have a unique
name. The rules for forming a subroutine name are the
same as those for forming a field name. The name must
appear in Factor 1 on the same line as the BEGSR operation code.

(
\.,
5-48

Page of GC21-7567-2
Issued 24 May 1976
By TNL: GN21-5389
Main Program

,

EXSA

Fields Used in a Subroutine

Subroutine

~.----------

The same fields can be used by both the subroutine and the
main routine. You may define the field in either routine.
However, the name and characteristics of the field must be_
the same in both routines .

_____
•

....-

.,#

//

The fields you define in a subroutine should be ge.neral so
that they apply to all situations for which a subroutine is
used. For example, if 0 1STA is used as the field name in a
subroutine to calculate district sales, you a/ways take information from the DISTA field when calculating commission. However, you want the routine also to handle information from the fields DISTB and DISTC. Using specific
fields limits the correct use of a subroutine to one situation.

:s><~

Figure 5-59. EXSR (Order in Which Calculations are Performed)

Instead, if you use a general field name such as SALES, this
one subroutine can be used to calculate commission in all
three districts (Figure 5-60, insert C). However, because
there is no input field called SALES, you should use the
Z-ADD operation code to place information in this field
(Figure 5-60, insert B). The information in the appropriate district field (DISTA, DISTB, or DISTC) is moved into
the field called SALES before the subroutine is executed.
When finding commission earned in district A, DISTA is
moved into SALES; when finding commission earned for
district B, DISTB is moved into SALES, etc. In this way,
you ensure that the subroutine uses the correct information
each time it is called.

)
RPG

IBM

GX21·9094 UiM 050'
Printed in U.S.A.

INPUT SPECIFICATIONS

International Business Machine Corporation

1

Program

Page

Date

PrOQl'ammer

Record Identification Codes

I
i---0.

>

Position

~
5

6

g
0

z
1

8

.,

.0

.;;;

~

I-

:;;

.e!::!
0

1::

~

0

Position

~
~

~§ 0
ZO

Position

15 16 77 18 19 80
of_

:~;~f~cation I

g
~

:;; ~ a:

0

1::

§ a3l

::;

From

Iii
0:

To

,f

Field Name

~
'il

0

3

4

o

1

lie; lAl, ~~

o

2

I

o

3

I

o

4

I

I~~

®~

1,LJld

~
]

g

IIIIII

Field
Indicators

Field location

Filename

Line

2

OJ

0

~
:B-o
.!!'i)
0

~u:

.s~

8 *~
:':0

"E

~

"0

Zero
Plus Minus or
Brank

0;

u:

9 10 11 12 13 14 15 16 11 18 19 20 21 22 23 24 25 26 27 28 29 3031 32 33 34 35 36 31 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 64 55 56 51 68 59 60 61 62 63 64 65 66 67 68 69 70 71 72 13 14

~'A

~!t

II
121b

121" IJJIA 'MI~

',n

qq
qg

l:lb
IT~ rrlA
13A 12 In II Lc; rrl~

. . . Ih [:)1.... f..lc. rr'"

~7
~

Figure 5-60 (Part 1 of 4), Sales Commission Program (Using a Subroutine)

)
Controlling Operationsln An RPG /I Program

5-49

RPG

IBM

CALCULATION SPECIFICATIONS

Form GX21-9093
P,inted In U.S.A.

International Business Machin. Corpot1ltlon

1 2

Program
Page
Programmer

Date

c

Indicators

Result Field

~

" Factor 1

Operation

Factor 2

3.

~
E

line

3

4

6

Name

15

15

Length

.!'s
~

E

"2

15

.2

z

6

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 3S 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

z

ole

o

2

C

o

3

C

o
o

4

C

5

C

o

6

C

o

7

C

o
o

8

C

9

C

1 0

C

Iqlq

z

C

75 76 77 78 79 80

[[]Of_ ~:~·;;'cation I I I I I I I

Resulting
Indicators
Arithmetic
Plus IMinusl Zero
Compare

Comments

1 >211 <211-2
Lookup(Factor 2lis
High Low Equal
54 65 56 57

sa

69 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

InlT l"wlA

lIe
1 2

C

1 3

C

1 4

C

1 5

C

1 6

C

1 7

C

1 8

C

1 9

C

Figure 5-60 (Part 2 of 4). Sales Commission Program (Using a Subroutine)

Using Subroutines in the Sales Commission Report Example

3.

The subroutine is called by the EXSR operation code.

Now that you have learned how subroutines are used, defined, and executed, see how they are used in the sales commission report program. All specifications are shown in Figure

4.

The commission is calculated by
in the subroutine.

5-60.

5.

The subroutine is finished when ENDSR statement is
executed. The instruction following EXSR is executed. The commission found by the subroutine is
added to the total commission earned by the sales- "
man (MANTOT) and to the total commission paid in
the district (TOTAlA).

6.

Now D ISTB is compared to zero to see "if: commission
earned should be calculated. If so, information from
the field DISTB is moved to SALES, and:the" subroutine is called. The next steps are basically the same
as those already described. Follow the rest of the program.

First a record is read. Now commission earned in each district must be calculated ..
1.

2.

5-50

DISTA is compared to zero to see if the salesman sold
anything in that district. If the field is greater than
zero, commission must be calculated. If the field is
zero, a branch is taken to B, where another comparison is made.
Before the subroutine can be called, it must be suppHed with the correct amount of sales. Thus, the contents of DISTA are moved into SALES.

oper~tions specified

RPG

IBM

CALCULATION SPECIFICATIONS

Form GX21·9093
Printed in U.S.A.

International Busine" Machine Corporation

1 2

Program

Page

Programmer

Date

C
I----

Indicators

~

0_

~~~
.... "5 a::

Line

Operation

S
z

S
z

1

C

rh MJY1

C

rh fYiM

o

3

C

o

4

C

~INn

7

8

ALO

''',1,(.1 :NII

Af"ID

tl"

~-A

5

C~E

c.11l

c.1111~

6

CSR

E5

,..,.. ~p

o
o
o

7

C~R
c~g

5~ I
S~ I

'Els

M

Comments

J OJ

CSR
CSR 11

"- I-I

tr.IR Nil

~

SIA LFlS

c,.IA 'F='lc;
"IV J=R

r.,r

I" rfI Ol~ czj(t

sis

II (J': ~~ t1l~

MJ .ttl"

C~R

.L1

CSR

3~ a.l~

Ann

1 3

cS~

11
.11

1 4

cSR 12
cSR t2
cSR 12

5~ I~ls

""IV .E.IR
ILL ~I.

l5'ft Ifl~ ~~
St 113
M:tl lLlT • Ojll
~n IM[C!1
AII'lII"'l

C

.ell INlr lsH

SIr<

r

112
~12

rze

ltlZ '1(2
Irr ~~

~12~

if"-v fiR

bl2

il=I Nlr ~~

,-,.. ITh
Mil'

11

,© CC

1M

I. OJ rf:rJ: ~rl

L:r .C2l3

1 2

1 7

Compare

r~c;

o

lrll

T~
''1~1'j

o

1 6

Plus IMinusl Zero

1>211<211a2
~~ Lookup(Factor 2)is
'0 OJ:
" '" High Low Equal

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 5051 5253 54 55 56 57 59 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

2

1 5

=

~

o
o

1 0

Length

~ ~

E E~

4

8

:E

Factor 2

Arithmetic

6

3

9

Indicators

!!
Factor 1

Name

.E 85 ..g
£;

Resulting

Result Field

AL At

-'a:
=0

75 76 77 78 79 80

[DOf_ :~;~f:ation I I I I I I I

rzll2
ir"D M~

12 111L ~l
ir"r 1\11~
~I""I

J.i

MIJII

G'" T'" iF TiNlr ~I-I
hV :EIR
lr-i""I MIM

H

Ir-", ~Ni~

FIN I... ~",

1 II

2 0

C
C

)

C

C
C

C
U

LL OL 69 89 L9 99 59 t9 E9 Z9 L9 09 65

as

L5 9S 55 1'9 ES ~s L9 05 6. 8. Lt 9. S.

»

E. ~t L. Ot 6£ st LE 9E 5E VE E£ ~E LE DE 61: 8Z L~ 9~ S~ t~ £~ ~~ L~ O~ 6L 8L LL 9L SL .L EL ~L LL OL

6

8

L

9

9

t

E

t

L

Figure 5-60 (Part 3 of 4). Sales Commission Program (Using a Subroutine)

Controlling Operations In An RPG II Program

5-51

RPG

IBM

GX21-9090 U/M 050'
Printed in U.S.A.

SPECIFICATIONS

OUTPUT

International Business Machine Corporation

I

Program

Programmer

-

Page

Date

0

~ Space

Output Indicators

Skip

e~

-= ~!
0-

...

Filename

Line

:u

~~

~

E

o

.f
3

4

5

o 2
o 3
o 4
o 5
o 6
o 7
o 8
o 9
I 0
I I
I 2
I 3
I 4
I 5
I 6
I 7
I 8
I 9
2 0

@

6

At

<{

I- ~

~ fo'o

I-

o I

ID

R

Ip:fr:ifo
7

8

~

'"

Field Name

1

!m

0

z

z

Xl

~

Illl~

Lila

~

1~ll~_

lLlp

""'I~

I~

en
.:.

8 U

z

~~

'AUTO

9 10 11 12 13 14 15 16 17 18 1920 21 22 23 24 25 26 27 28 2930 31 32 33 34 35 36 37

aiR I~IP ~IRrr
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a

End
Positon
in
Output
Record

a:

"0

::(

...

I(;;!

38pg

2

,

757677787980

[I) 0'_ ~~~::':tion I

Commas

Zero Balances
to Print

No Sign

CR

-

Yes
Yes
No
No

Yes
No
Yes
No

I
2
3
4

A
B
C

J
K
L

0

M

I. 11I I I

X • Remove
Plus Sign
Y = Date
Field Edit
Z = Zero
Suppress

a:

g

Constant or Edit Word

ii:

40 41 42 43 «~~O~~~~~~~~~~~WW~~~~~M~M~ro 71 72 73 74

~19

I

~l5"

' Ie; IAII

Lsis

1

-II" Nlr lSL~ lr',..IN

1~1~ILl

ILOIIT I

ir-,V

~

lLll~

'rr ~tr~

~~!A

lLlB
lllA

1bL'i

10-"" f.1 1M Ir lLlB

171~

~YIMIM

.,..,.\1
I ...

•

Wl5

INI~ 1f"1t;;

IT

'n lr~rr
' In

,

~,

Ip 1
tr5tr "'"

Ibl5
1715
~ll
~!r,

1.... 1,.. 1",.1.1\ II..

i,... [~rr

lSI5

Ia l1lL~

I~

IL IQ
II

-

-,

I~

~II

L~I'i

-In

I~IJ

bls

..... -I,Q

~!~

1~

51b
??
ic"

,*'
1 if I

I~I

Figure 5-60 (Part 4 of 4). Sales Commission Program (Using a Subroutine)

Using Valid Subroutine Operations
Any operation code that can be used in calculations can be
used in a subroutine except BEGSR and ENDSR. This
means that you can use all arithmetic, compare and testing,
move look-up, EXSR, and branching operations.
There are limitations on some of the operations:

1.

You may only branch to another statement in the subroutine when using the GOTO statement (Figure 5-61,
insert A).

2.

5-52

You may branch to the ENDSR statement if you put
a name in Factor 1 of the ENDSR statement.

3.

You may not branch to a statement outside of the
subroutine (Figure 5-61, insert B).

4.

You cannot branch to a TAG within the subroutine
from a GOTO outside of the subroutine (Figure 5-61,
insert C).

5.

You cannot have a subroutine coded within another
subroutine. However, one subroutine can call another
subroutine. This means that within one subroutine
you may have an EXSR statement (Figure 5-62). A
subroutine, however, cannot call itself and cannot call
the subroutine which called it.

/

C

Indicators

~

j

At AL

11

~
3

4

~

DO THIS: Use a GOTO statement
to branch to another
statement within the
subroutine.

f-

0
'-

o

5

o

6

C

o

7

C

o a

c

o

C

9

1 0
11
1 2

C

C
ClslR
C5iR

1 3

C~IR

1 4

CSR

1 5

CC;R

5

A£ IGlsi~

EA

Gh T'"'

I2llL

®,

A CSR
-

C

At AL

r--Factor

1

Operation

Fac1

§ ~

~
5 6

8

~

7

9 10 11 12 13 14 15 1617 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 33 34 35 36 37

0

z

b

Z

C

NOT THIS: Use a GOTO statement

c
C

Ie

to branch to another
statement outside the
subroutine. INA ~IE.

3

4

C

o

C

1 0

7

9

1 0
1 1
1 2

CSR
CSR

CsR
CSR
1 5
CSR
1 6
CSR
,®,~ C
1 3

0

Operation

Fact

0

z

7

9 10 11 12113 14 151617 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

ITIAG

o

o

0

1

8

z

Z

outside the subroutine
to branch to a TAG
statement within the
subroutine.

o a

5
6

5

Factor

NOT THIS: Use a GOTO statement

C
C
C
C

o
o

At AL

g

Line

4

Indicators

3

~

]

>..J
(5

f-

3

EINn

I~N J'1,<;1~

IENlD

I

Indicators

3

1l. ]
Line

Z

Z

0

~

Facl

Operation

9 10 11 12 13 14 15 1617 18 19 20 21 22 73 24 25 26 27 28 29 30 31 32 33 34 35 36 37

'-

C

1

0

0

0

Z

5 6

0

>-----

Factor

~

line

-

o

6

a

7

o a

IP,I~ -;C;R

,

9

11
1 2

r:,!1"l T{) NIA ft1IE

1 4

1 3
1 4
1 5

11=

P"'cS

1 6

©

C
C
C
C
C
C51A
C5lR
ClslR
ClslR
ClSIR
ClslQ.
C

G'" Tr,

NA ~E

JJ.J: r.. [c:;,R

NIA ,ME

T~IG

FIr\/ InlslR
I

Figure 5-61. Branching Within a Subroutine

)

Controlling Operations In An RPG II Program

5-53

Page of GC21-7567-2
Issued 30 June 1978
By TNL: GN21-5616

RPG

IBM

CALCULAl

Program

Date

Programmer

C

E

0

Operation

Factor 1

Fac

i- -0

.f
~

AL At

~]~a:

Line

•

Indicators

- 0_
~
-'a:
=0

f---

3

8 5-

!:;

U)

~

7

8

9 1011 12 13 I. 15 1617 18 19 20 21 22 23 24 25 25 27 28 29 30 31 32 333435363

5 6

b

z

o "
o 4
5

o

6

o

7

o

8

o

9

C
C
C
CI~IR
c!=.l~

Lc; J IplA

11l.1c= 1r..Ic.lc

CI~I~

11

c 1c;1~
Clc;IR

1 2

CI~IQ

1 3

C~I~
CIc;I~

1 4

ic;IU Iplp

1&:1)( 1c;IR
~IN 1r'\~I~
15;IIJ Iplp

lo.l~ I,.. It"

1 7

Clsl~
C1c:;111

1 8

C

1 6

RPG II LINKAGE EDITOR
I ..

The output of the RPG II compiler becomes input to the
linkage editor, which builds the load (object) module for
later execution. The module can be cataloged into the
library, punched into cards, or written to diskette.
RPG

IBM
Program

Date

Programmer

C

Line

Indicators

~

0_

.... ori
E ~ '"

&853

0

4
1 ,

AL At

-'a:
=0

~~~

5 6

I,..

7

8

I

~

b

0

o

4

o 5
o

6

I I

7

C~IR

o

8

clc:.IR

o

9

11

C~IR

1 3

ClslR
clt:;IR
c

1 5

Ie; J IQIIl

1c1J: ~1c:.11:I

lc; JIplA

Inll"

The linkage editor combines the translated RPG II source
code with the system library modules necessary to complete
the program. The map of the linkage editor's output is
printed following the compiler diagnostic messages (if
present). The map also indicates the amount of internal
storage used by portions of a program.
The RPG II compiler used on Models 4, 6,8, 10, or 12
includes its own linkage editor, called the RPG II Linkage
Editor. On Model 15, the RPG II compiler uses the overlay
linkage editor that is part of the SCPo The following refers
to the RPG II Linkage Editor, although conceptually, it is
identical to the overlay linkage editor.

C~IR

ClslR
Cic;IR

1 2

1 4

I
I I
I
I I
Code a subroutine with- I
in another. subroutine
I

C
C
C

o

1 0

b

Fac

z
Z
9 10 11 12 13 14 15 1611 18 19 2C 21 22 23 24 25 26 27 2829 30 31 32 33 34 35 36 3"

~ NOT THIS:
f-

Operation

Factor 1

/"
\,

CALCULAT

International Business Machine Corporation

f---

Control level indicators cannot be used to condition statements within a subroutine since SR must appear in columns
7-8. The indicators used on the EXSR statement determine
whether the entire subroutine is performed at detail time
or at total time (Figure 5-63, insert B).

Irl

ClslR

1 5

\ ..

The EXSR statement can also be conditioned by indicators.
In this case, the entire subroutine will be performed only
when conditions for the EXSR statement are met. For example, in Figure 5-63, insert A, the subroutine will be performed only if MR is on.

u

1 0

(

b

call another subroutine

I-

Any indicator which is valid in columns 9-17 can be used
to condition an operation within the subroutine. That
operation will then be performed only when the conditions
established by the indicators are satisfied. The BEGSR and
ENDSR operation code, however, cannot be conditioned
by any indicators.

Z

DOTHIS: Use one subroutine to

o

Conditioning Subroutine Statements

International Business Machine Corporation

,..~In

iJ:IN In~1R
1...

1'1 11

~IM

-

Figure 5-62. Using EXSR Within a Subroutine

5-54

(

Page of GC21-7567-2
Issued 30 June 1978
By TNL: GN21-5616

)

RPG

IBM

Form GX21·9093
Printed in U.S.A.

CALCULATION SPECIFICATIONS

International Businesl Machine Corporation

1

Program

C

Indicators

ci

~-

I--

Name

t- '00:-

E E~

.f <35 zb
3

4

5

6

o

1

C

o

2

o

3

o

4

c
c
c

o 5

C

o

6

C

o

7

c

7

8

:€

Factor 2

Operation

zb

~I
1

75 76 77 78 79 80
of_

~~~~;~f:.tion I

IIIIII

Indicators

Arithmetic

l'!

Factor 1

2

[I]

Resulting

Result Field

At At

.Ja:

::0

~~~

line

Page

Date

Programmer

Length ~

I

;

Plus IMinusl Zero

Comments

Compare

1>211<211g2
~i Lookup(Factor 2lis
.~ ':;
C:I: Hi 9hJLOw 1!EQ ual

Z

9 10 11 12 13 14 15 1617 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 5051 52 53 54 55 56 577 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

MR

®,

IFly l~R lc;lu AlA

IT

I

1

®

~~ lsR

slu BS

IT

1111 I I

IIIII I

IIII II
I III I I

IIIII I
IIIII I

SUBA will be executed at detail I
time if MR is on.

I

SUBA will be executed at total time.

IIII II

I

IIIII I

Figure 5-63. Conditioning Calculations Within a Subroutine

Linkage Editor Map
Figure 5-63.1 illustrates the information available on the
RPG II Linkage Editor map.

)

The Start Addr column gives the physical location in .
storage of each module. Figure 5-63.1 shows the modules
in ascending sequence by address (which may not always be
the case). The root section indicates the beginning of the
program just after the system supervisor (OEOO, in this
case). The root section is 1,000 hexadecimal bytes long
(see Code Length column); therefore, the next available
location is 1 EOO. Note that the next higher address in the
example is 1 EOO for the input mainline section.
Start
Addr
OEOO
1 EOO
1 FOO
2000
2050
2060
2080
2100
2150
2250
2450

Name if
Overlay

Code
Length

Name

Title

1000
0100
0100
0050
0010
0020
0080
0050
0100
0200
OBOO

RGROOT
RGMAIN
RGSUBS
RGSUBS
RGSUBS
$$CSIP
RGMAIN
RGMAIN
$$PGLC
RGMAIN
RGSUBS

Root
Input Mainline
Record 10
Input ctrl rtn
Subseg
5444 consec input
Input fields
Detail calcs
Lokup routine
Detail output
Constants

The Code Length column gives the storage requirements
in hexadecimal. The Name column gives the name of
system (and user) modules and designates the compilercreated segments (which begin with RG). The functions
of modules are described, where practical, in the title
column.
The root section contains I/O buffers, constants, and
v,ariables required to run RPG II programs. Subseg is a
section that has functions that are not easily describable
by the compiler. For example, a calculation subroutine
is called a subseg.
The RGMAI N sections are the basic RPG " functions,
such as input, detail calculations, total output, and so on.
RGSUBS designates functions within the RGMAIN
functions. The modules are listed in functional sequence;
the subsections follow the main function. In Figure 5-63.1,
the lokup routine follows the detail calcs section because
a table look-up was performed in detail calculations.
Similarly, the constants section, because it fol!tJws the
detail output section, was defined on the output
specifications for detail (or heading) lines.

Figure 5-63.1. linkage Editor Map

)

Controlling Operations I n An RPG II Program

5-55

Page of GC21-7567-2
Issued 30 June 1978
By TNL: GN21-5616

Simple Overlays

Start
Addr

An overlay structure begins if the load (object) module
built by the linkage editor is larger than the available main
storage in a machine (the size is specified on the H-card or
is assumed to be that of the machine used for compilation).
The linkage editor begins with low-usage modules such as
execution time table dump and load routines, file open
and close, LR calculations and output, and so on. It
allocates an overlay fetch area large enough to hold the
largest of the selected routines (or groups of routines) and
calls for an overlay fetch routine, which will load into that
overlay area the selected routines as they are needed. The
overlay fetch routine checks to see if a requested overlay is
already in the overlay area before going to the disk library
to load it. This action saves time by avoiding unnecessary
loads from disk.
With overlays, the root section occupies the lowest position
in storage as before. It is followed by the overlay fetch
routine. The overlay fetch area comes next, followed by
the secondary root routine, or root 2. Root 2 is made up
of those routines that do not have to be overlaid.,

Name if
Overlay

Code
Length

Name

Title

OEOO
1 EOO

1000
0100

RGROOT
RGSUBS

1FOO

0700

RGSUBS

2600
2700
1FOO
2100
1FOO
2500
2520

0100
0100
0200
OOAO
0600
0020
0010

RGMAIN
RGMAIN
RGMAIN
RGSUBS
RGMAIN
RGSUBS
RGSUBS

Root
Overlay fetch
routine
Overlay fetch
area
Input mainline
I nput fields
Detail cales
Constants
Total cales
Constants
Exception.

~
\ ....

$##001
$##001
$##002
$##002
$##002

Figure 5-63.2. Storage Map

Overlay
Name

Relative
Start CITIS

$##001
$##002
$##003
$##004

00
00
00
00

00
01
01
01

16
02
OA
11

#rext
Sectors

Start
Address

03
07
06
04

lFOO
1FOO
lFOO
lFOO

Figure 5-63.3. Library Map
I

All the overlaid routines are given names in the Name If
Overlay column. The names are $##nnn! where nnn is
a three-digit overlay number.
Figure 5-63.2 shows a storage map of a program and
Figure 5-63.3 shows a library map of the same program.
Figure 5-63.4 is a diagram that illustrates the maps shown
in Figures 5-63.1 and 5-63.2. The library map indicates the
overlay size in the # Text Sectors column. You can see in
Figure 5-63.3 that overlay #2 ($##002) is the largest,
occupying seven sectors; this is equivalent to 0700 bytes in
hexadecimal (all storage requirements will be stated in four
hexadecimal digits). The storage map shows the overlay
fetch area of 0700 bytes. It also indicates that overlay
#2 contains the total calculations and is actually only
0630 bytes long (0600 for total cales, 0020 for constants,
and 0010 for exception output). Therefore, overlay #2
occupies seven sectors: six are flJII and the seventh has only
0030 bytes of code in it. If the user wants to reduce the
size of the program's overlay area, he would first try to
reduce the size of total calculations.

(

5-56

Page of GC21-7567-2
Issued 30 June 1978
By TNL: GN21-5616

Root

Overlay Fetch Routine

$##001

$##002

$##003

)

$##004

Overlay
Fetch
Area

Root 2
Figure 5-63.4. Diagram of Linkage Editor Map and Storage Map

The Relative Start G!T/S column gives relative library
locations in cylinder, track, and sector for the overlays.
This information does not pertain to this discussion.

Special Open
Sometimes a storage map will not list an overlay #1 but will
have other overlays starting with $##002. This indicates
that the special open has been implemented. The user
cannot directly cause this to happen. The linkage editor
provides this feature when it reduces a program's storage
requirements. Special open does not affect throughput.
When the open/close overlay is the largest one, special
open is implemented, rather than having that code increase
the storage required for the rest of the program. Special
open causes some of the unoverlaid code in root 2 to
overlay the open routine after the files have been opened;
it overlays some of root 2 with close at end-of-job.

Overlay Starting Addresses
As the maps in Figure 5-63.5 show, there are two starting
addresses for overlays. The main starting address for the
illustration is 1 FOO. The starting address for the suboverlay
is always higher; in this case, it is 2300.
Storage Map
Start
Addr

Name if
Overlay

Code
Length

Name

Title

1FOO
2100
2200
2300

$##D02
$##D02
$##D02
$##D03

0200
0100
0002
0100

RGMAIN
RGSUBS
RGSUBS
$$PGRI

2400
2300

$##D03
$##D04

0100
0300

RGSUBS
RGSUBS

Detail cales
Transfer vector
Contants
Reset Resulting
indr
Subseg
Exception

Library Map
Overlay
Name

Relative
Start CITIS

$##D01
$##D02
$##D03
$##D04
$##D05
$##D06
$#/IfJ07

)

#rext
Sectors

Start
Address

07
04
02
03
03 .

1FOO
1FOO
2300
2300
1FOO
2300
2300

04
02

. Figure 5-63.5. Storage and Library Maps

Controlling Operations In An RPG II Program

5-56.1

Page of GC21-7567-2
Issued 30 June 1978
ByTNL: GN21-5616

$##002 is a main overlay with suboverlays. There are two
indications of this: first, it includes a module RGSUBS
(which is titled transfer vector), and second, it is followed
on the maps by overlays with higher starting addresses.
The ,size of the overlay fetch area is the larger of (1) the
largest overlay with suboverlays plus the largest suboverlay,
or (2) the largest overlay without suboverlays. In Figure
5-63.5, the size of the overlay fetch area is equal to the sum
of the sizes of $##002 and $##006. This is not obvious
from the maps, but the block diagram (Figure 5-63.6)
drawn from the maps makes this clear. Overlay 2 is the
largest main overlay with suboverlays, so it determines the
starting address for all suboverlays. Overlay 6 is the largest
suboverlay . Together, overlays 2 and 6 require 8 sectors or
0800 bytes, which is greater than the 7 sectors (or 0700
bytes) for overlay 1.
If a user wants to reduce the size of the overlay fetch area,
he could reduce the size of either $##002 or $##006.
One sector, however, is all the user can expect to save
because $##001 is just one sector smaller than the overlay
fetch area.

Root

Overlay Fetch Routine

$##001

$##002

$##005

Overlay
Fetch
Area
$##003

$##004

$##006

$##007

Root 2
Figure 5-63.6. Diagram of Storage and Library Maps

(
5-56.2

Page of GC21-7567-2
Issued 30 Ju ne 1978
By TNL: GN21-5616

)

Fitting Available Storage

RPG II Logic and Function Shifting

The linkage editor removes modules from root 2, placing
them into the overlay structure until the program fits into
available storage (or until there are no more modules to
overlay, which means the program is too large to fit).
After a fit is obtained, there may be unused space in
storage. If there is, an attempt is made to find small
modules that can be removed from the overlay structure
and placed back into that free space.

The basic functional areas of RPG II logic are summarized
in the following sequence:

This process of moving overlaid modules back into main
storage might give you a missing overlay, that is, a
suboverlay without a main overlay. In the storage map,
you can sometimes notice unoverlaid modules among
the overlays. This is a result of moving modules from main
storage to an overlay and back again.
The linkage editor moves code rather than allowing
available storage go unused. Having code moved back to
main storage can improve speed of execution, but is not
under the control of the user. The linkage editor moves the
code when it can.

)

1.

Detail Output-Detail and heading output (except for
overflow lines) are performed.

2.

Physical Input-Records are read from primary and
secondary files, as necessary, and the ID indicator
is set.

3.

Total Calculations-All calculations with L and a
number in columns 7 and 8 are performed. This
includes all exception output specifications if EXCPT
is performed, or all required input specifications
for READs or CHAINs performed, or any user
subroutines called with EXSR.

4.

Total Output-Total output (except for overflow
lines) is performed. You should note that total
calculations and output are attempted on every
cycle.

5.

Overflow Output-All output lines with overflow
indicators conditioning them are performed.

6.

Logical Input-Data read in Step 2 is moved to the
fields named on the input sheet, and the
corresponding field indicators are set.

7.

Detail Calculations-All calculations without Land
a number in columns 7 and 8 are performed. See
Step 3 for more information.

These functional areas can be identified by the titles of
routines in the storage map. A user can reduce the size
of any of these areas by one of three methods:
•

Removing function from the program

•

Using more efficient coding

•

Shifting function from one general area to another

The removal of function from a program often results in
a second program being written to perform those functions.
Some system designs include luxuries that are not essenti\'ll
to the job. These functions may be removed from the
program.

)

Functions that cannot be removed can often be moved to
another area. Some total calculations can be moved easily
to detail calculations.

Controlling Operations In An RPG II Program

5-56.3

Page of GC21·7567·2
Issued 30 June 1978
By TNL: GN21-5616

The following multiply statement could be moved to detail
calculations by conditioning it with the 01 indicator, just
like the add, and deleting the L1 indicator on the MUL T
statement. The results will be identical. Similarly, some
calculations can be moved from detail to total; however,
a new record ID indicator will be on so the user may have
to use an extra indicator.
C

CL1

01

AMT
TOTAL

ADD
MULT

TOTAL
RATE

TOTAL
DISCNT

Primary and secondary input are done at input time.
READ and CHAIN are performed during calculations. If
calculations are too big, a file processed with the CHAI N
operation code might be first sorted and then matched as
a secondary file against the primary. If input is too big, a
secondary file could be made a demand file and processed
with the READ operation code during calculations.
Output, like calculations, can be shifted between detail and
total calculations. Even overflow output can be moved
to the following detail or total calculations by using a
numeric indicator, which is SETON conditioned by the
overflow indicator. EXCPT is output performed during
calculations. Some output functions may be moved from
output to calculations (either detail or total).

SPECIAL USES OF CONTROL LEVEL INDICATORS
At this time, you should be familiar with the normal use of
control level indicators, L 1·L9. You know that by assign·
ing them on the Input sheet and using them on the Calcula·
tion and Output Specifications sheets you can do total
operations.
In this section, you will learn to work with a special internal
control level indicator LO. You will also learn to use L 1·L9
indicators to condition calculations and to perform group
printing.

Internal Control Level Indicator LO
LO is a unique control level indicator which is always on.
You cannot assign it to a field, as you do L 1·L9, by entering it in columns 59·60 of the Input sheet. But, you can
use it to condition a calculation or output operation. The
operation so conditioned will be done at total time for
every program cycle, since LO is always on.
The main purpose of the LO indicator is to allow you to
specify total operations when indicators L 1·L9 are not
available or when they cannot accomplish the job.

Any calculation overlay or suboverlay that does an EXCPT
will contain all E output specifications. If a suboverlay has
EXCPT in it and is too large, that operation can usually be
moved to another subroutine. If the subroutines are large,
they can usually be divided into seve'ral smaller subroutines.
Calculation sections cannot be divided by the linkage editor
to be separate overlays; subroutines can. They will become
suboverlays to the main detail or total calculations overlay.
If one subroutine calls another subroutine, both will appear
in the same suboverlay. To divide them up, the first
subroutine must return to regular calculations from which
the second subroutine can be called.
Using shared I/O for disk files can save a great deal of space
in some programs. With the resulting smaller overlay
structure, performance may be improved. Alternatively,
larger disk file buffers and double buffering could be
specified. These two techniques use extra storage
(resulting in more overlays) but may still perform faster
because of the speed improvement in disk operations they
provide. Selection between larger disk I/O buffers or shared
buffers must be made by trial for each program.
Information about the overlay linkage editor can be found
in the IBM System/3 Overlay Linkage Editor Reference
Manual, GC21·7561.

5·56.4

(

\
/

J

Suppose you want to print the report shown in Figure 5-64.
The report is a listing of items a company has sold in each
of its two districts. The report includes total sales for each
district (DISTOT) and a grand total of sales in both districts
(GDTOT). The input records are grouped by district with
District 1 records preceding District 2. Each record contains an item number field (ITEM), an item description
'(DESCR), and an item cost field (COST), as shown in Figure
5-65.

1 uses either a 1 or an M as an identifier and District 2 uses
either a 2 or an N. Since the contents of the record identification field can change without actually having a change in
district, this field cannot be used as a control field. Neither,
of course, can the ITEM, DESCR, or COST fields be used as
control fields.

Artificial Control Breaks

A record identification code in position 1 indicates in which
district the item was sold. Normally, the fi~ld containing
the record identification code could be used as a control
field in the printing of district totals. However, each district has more than one record identification code. District

When it is necessary to do total operations but no control
fields are available to cause a control break, you can use LO
to cause an artificial control break. Figure 5-66, insert 8,
shows the use of LO to permit total calculation operations.

623.21
1,459.95
260.00

PORTABLE COMPRESSOR
PORTABLE GENERATOR, 30KW
HYDRAULIC JACK

34J261
46F419
21P006

1

DISTRICT TOTAL

87,347.16*
623.21
930.00
3,016.50

PORTABLE COMPRESSOR
PORTABLE SPRAYER
PORTABLE GENERATOR, 50KW

34J261
16A300
800610

)

Additional
items

1

DISTRICT TOTAL

131,219.04*

GRAND TOTAL

218,566.20**

Additional
items

Figure 5-64. Format of District Sales Listing

Record
1.0. Code

t
ITEM

:

DESCR

I

:
1

COST

I

112 3 4 5 6 718 9 1011 121314 1516 17 18 19 20 21 22 232420262128 2q 30\3; 3233 34 3~ .1637\383940

)

Figure 5-65. Format of Sales Record

Controlling Operations In An RPG II Program

5-56.5

This page is intentionally left blank.

(

(
5-56.6

RPG

Form GX:21,9093
Printed In U.S.A.

CALCULATION SPECIFICATIONS
1 2

Program

/

Programmer

C

Line

Olta

Indicators

~

I-I!I.

(:

!~

3

4

o
o
o
o
o
o

6

o

7

5 6

1

C

2

e
c
e
e

3
4

5

7

8

Factor 1

Operation

Factor 2
Name

gffi

~ 85

Resulting
Indicators
Arithmetic
Plus TMinusr Zero
Campara
1>211<211-2
Lookup(Factor 2)1.

Result Field

Jd Jd

SiC
=0

75 76 77 78 79 80

Page [OOf_

Length

:1

I~
ii
'2 ';

~~~~;~f:atiOn I ! ! ! !

II

Comments

Highs!!

Z
Z
c:c
b
LOw 1,E Quai
9 10 11 12 13 14 15 18 17 18 19 20 21 22 23 24 25 26 27 282!1 30 31 32 33 34 35 36 37 3B 39 40 41 42 43 44 45 46 47 4B 49 50 51 52 53 54 65 68 677 58 59 60 61 62 63 64 65 66 67 66 69 70 71 72 73 74

Z
b

IM~

ell ~.
e

I I I I 11

1

~

II=' 1)( Ic;IR lslJ IB~

11

~I)( [c;IR

~C;IU 1918

1111 1

I

I I I I 11
I II I I I

I

(~)
II f

of

SUBA wil.1 be executed at detain
time if MR is on.

111 I I I

II I I I I

SUBA will be executed at total time.

1111 r I

I

II II I I

Figure 5-63. Conditioning Calculations Within a Subroutine

You must give priority to subroutines to determine which
subroutines, rather than object cycle routines, should be
stored on disk. Those subroutines used infrequently should
be the first routines stored in the object library. Priority is
established through the order in which the subroutines appear at compilation time. The last subroutine in your source
program will be the first subroutine stored in the object
library. Consequently, you should place an infrequently
used subroutine as the last subroutine in your source
program:

SPECIAL USES OF CONTROL LEVEL INDICATORS
At this time, you should be familiar with the normal use of
control level indicators, Ll-L9. You know that by assigning them on the Input sheet and using them on the Calculation and Output-Format sheets you can do total operations.
In this section, you will learn to work with a special internal
control level indicator LO. You will also learn to use Ll-L9
indicators to condition calculations and to perform group
printing.

Internal Control Level Indicator LO
Subroutine
1

LO is a unique control level indicator which is always on.
You cannot assign it to a field, as you do Ll-L9, by entering it in columns 59-60 of the Input sheet. But, you can
use it to condition a calculation or output operation. The
operation so conditioned will be done at total time for
every program cycle, since LO is always on.

Subroutine
2

Subroutine
3

The main purpose of the LO indicator is to allow you to
specify total operations when indicators Ll-L9 are not
available or when they cannot accomplish the job.
The last subroutine in your
. .- - - source program is the first
subroutine stored on disk.

COIIUl1l1i~g

Operations In An RPG II Program

5-55

Suppose you want to print the report shown in Figure 5-64.
The report is a listing of items a company has sold in each
of its two districts. The report includes total sales for each
district (DISTOT) and a grand total of sales in both districts
(GDTOT). The input records are grouped by district with
District 1 records preceding District 2. Each record contains an item number field (ITEM), an item description
(DESCR), and an item cost field (COST), as shown in Figure
5-65.

1 uses either a 1 or an M as an identifier and District 2 uses
either a 2 or an N. Since the contents of the record identification field can change without actually having a change in
district, this field cannot be used as a control field. Neither,
of course, can the ITEM, DESCR, or COST fields be used as
control fields.

Artificial Control Breaks

A record identification code in position 1 indicates in which
district the item was sold. Normally, the field containing
the record identification code could be used as a control
field in the printing of district totals. However, each district has more than one record identification code. District

34J261
46F419
21P006

When it is necessary to do total operations but no control
fields are available to cause a control break, you can use LO
to cause an artificial control break. Figure 5-66, insert 8,
shows the use of LOto permit total calculationoper(ltions.

623.21
1,459.95
260.00

PORTABLE COMPRESSOR
PORTABLE GENERATOR, 30KW
HYDRAULIC JACK

DISTRICT TOTAL

GRAND TOTAL

218,566.20**

t
DESCR

:

COST

I
I
I
1 '2 3 4 5 6 7 18 9 10 11 12 13 14 1~ 16 J7 18 19 20 21 22 ,~ i4 2~ 25 2l 2~ 29 3013; 323)3.1 35 :i6 nl38 39 4D
I

Figure 5-65. Format of Sales Record

5-56

1

131,219.04*

Record
1.0. Code

:

87,347.16*

DISTRICT TOTAL

Figure 5-64. Format of District Sales Listing

ITEM

Additional
, , items

623.21
930.00
3,016.50

PORTABLE COMPRESSOR
PORTABLE SPRAYER
PORTABLE GENERATOR, 50KW

34J261
16A300
800610

1

Additional
items

RPG

IBM

GX21-9094 U/M 050'
Printed in U.S.A.

INPUT SPECIFICATIONS

International Business Machine Corporation

1--_ _ _ _ _ _ _ _ _--._ _ _ _ _ _---11
1
Date

I
I

Graphic

Punching
Instruction

Punch

I
I

Card Electro Number

I

1

Page

2

75 76 77 78 79 80

[00'_ ::~~'~cation I I I I I I I

Record Identification Codes
Field Location

~

0

0,.

Filename

0

Position

Position

From

Position

Field Name

]
g

D-

To

~
'2

.3

Cl

0

:B~

.!!Gi

u..u:::

.S ~

·8

Field
Indicators

~
"E

!

~~
:
End
Positon
in
Output
Record

1 6

0

...

Zero Balances
to Print

Yes
Yes
No
No

Yes
No
Yes
No

II

No Sign

CR

-

1
2

A
B
C

J

3'
4

0

K
L
M

1 1 1 1 1 I

/~

(

X • Rem""e
Plus Sign
Y = Date
Field Edit
Z a Zero
Suppress

a:

g

Constant or Edit Word

ii:

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

I/~
~I~

110<

5T

.L

I~I~

(2i.2. 12lL

~12

I~

I"I!R

, 1.IA

IJ.~'

IT 12

'LIR
CO!

I

T

L

~!~

I

IblL

I

~I(l

I

Ib~

11.

If

~

I...

1e,lfl
~12

J IK1

J

h"o irA II

I

I

I ...

r'" !TIAL

I

1fJt. ~I

Figure 5-66 (Part 2 of 2). Calculations Using an Artificial Control Break (LO Indicator)

Assume that the following five records are read:

/*
Identifying

5·58

Commas

~~:~'~cation I·

0

J. 1.1

Code

75 76 77 78 79 80

'Page [ 0 o , _

~l

,..,~

IT

!

~~

'AUTO

9 10 II 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

IUlr PIT

a:

8 U

0

z

0 1

11151

GX2HI090 U/M OSC'
Printed in U.S.A.

SPECIFICATIONS

OUTPUT

Intern.llonal Business Machine Corpar••ion

~ _ ......- - - - - -...

c

The operations performed on these five records are as follows:

)

Record

(1 )

(2)

Indicators On Operations Performed

LO

LO,21

)
(3)

(4)

(5)

,

)

LO,21

LO

LR

01 turns on.
No total operations are performed because conditions
in lines 5-6 (Calculations
sheet) are not met.
(Remember that operations
conditioned by control level
indicators in columns 7-8 are
performed first, but are bypassed on th e fi rst RPG II
cycle.)
COST is added to DISTOT.
21 is set on.
ITEM, DESCR, and COST
are printed out.
01 is turned off.
21 remains on.
01 is turned on.
No total operations are performed.
COST is added to D ISTOT.
ITEM, DESCR, and COST
are printed out.
01 is turned off.
21 remains on.
02 turns on.
DISTOT is added to GDTOT.
(Conditions for the total
operation in line 5 have been
met.)
D ISTOT is printed out.
COST is added to D ISTOT.
21 is set off.
ITEM, DESCR, and COST
are printed out.
02 is turned off.
02 is turned on.
No total operations are performed.
COST added to DISTOT.
ITEM, DESCR, and COST
are printed out.
02 is turned off.
DISTOT added to GDTOT
(LR indicator is on).
DISTOT and GDTOT printed
out.

Using Control Level Indicators as Calculation Conditioning
Indicators
Control level indicators are normally entered in columns 7-8
of the Calculation sheet where they specify which calcula~
tions are to be done at total time. They may, however, be
used in columns 9-17 also where they indicate which detail
operations are to be done on the first record of a control
group.
Control level indicators are turned on near the beginning ~f
the program cycle if the contents of the control field on the
record just read are different from the contents of the previous control field. Since the indicator is not turned off until the end of the cycle, it is on during total and detail time.
Thus, it is available to use as a conditioning indicatbr during
detail time as well as total time.
When an operation is not conditioned by control leve,l indicators specified in columns 7-8 of the Calculation sheet,_ the
operation is done at detail time. If the operation is conditioned by a control level indicator specified in columns 9-17,·
and not in 7-8 the operation is still done at detail time, but
only when the control level indicator is on. And when is
the control ,level indicator on? Only during the processing
of the first record in a control group as only the first record
in a new group causes a control break.

Group Printing
In group printing, data from groups of input records is
summarized and printed as totals on a report. Sometimes,
a field on each record in an input file is accumulated and
only the final total is printed. At other times, subtotals are
created by adding the contents of a field from a certain
group of records and printing the result.

Printing Only the Final Totals

It is possible to add the contents of a field from all data
records, and print only the total accumulated. You may
want to do this when you are not interested in any of the
detail information, but you do need a summation of that
information.
Figure 5-67 shows the coding for a program that finds the
totals for two fields of information and prints, only those
totals. Notice, when printing only totals, the Input sheet
need only contain those fields that will be used in the calculations or in the printing. The Output-Format sheet shows
only a total line (T in column 15). That line is not printed
until the last record has been processed (LR in columns
24-25). Then, one line is printed, containing the total
quantity, total cost, and a constant (see insert on OutputFormat sheet).
Controlling Operations I n An RPG II Program

5-59

File Description Specification
File Type

F

Mode of Processi ng

File Addition/Unordered

Extent Exit
for DAM

Length of Key Field or
of Record Address Field

File Designation
End of File

Record Address Type
Sequence

Filename

Type of File
Organization
or Additional Area

File Format

Line
Block
Length

Record
Length

~ ~

c:

0

< ::
\

Tape

g
.~

Starting

~

Location

W

Rewind

Core Index

~

Key Field

/

Number of Extents

W

Overflow Indicator

N

Symbolic
Device

Device

..J

Number of Tracks
for Cylinder Overflow

Name of
Label Exit

File
Condition

Ul·U8

Continuation Lines
Option

Entry

\

RPG

IBM

GX21·9Q94

INPUT SPECIFICATIONS
1

Program

Programmer

Record Identification Codes

5

6

o

2

I

o

3

I

Position

~
0

Z

7

8

I;
t;

Position

~

~ :!

l)

6

0

Z

I;

~

t;

a;

Position

~ 0
a N ~
z u 6

l) 65

3i

~

..J
III

~

~

Ci:

I~rl

j

Zero
Plus Minus or

Blank

0;

u::

IllY

CALCULATION SPECIFICATIONS

Form GX21·9093
Printed in U.S.A.

~-------__il

Punching

I

Dill

t--:_:_:ic---i-_t--I-t--t-_II--+--+I-il Card Electro Number

Instruction

~

Line

! ~8
-;
Name
Length ~ i

Indicators

~ ~_ §
~

,I

And

I

Alnd

Factor 1

Operation

~
I; 8

3

4

o
o

1

2

c
c

o

3

C

~

CI)

7

8

8 5·

0

~

1

2

75 76 77 78 79 80

P.~~Of_ ~~~:~f:llion

IIIIIII

R.. ulting

Result Field

Indicators

I

\,

.~- ~ PIU~~~:'~~ero

Factor 2

.~

0

Comments

Compar.
1>211<211-2

... '0 a:
E

'; Loo. kup(Factor 2)is

Z
Z
0 J: High Low Equal
9 10 11 12 13 14 15 18 17 18 19 20 21 22 73 24 25 26 27 28 29 30 31 32 33 34 35 36 37 3B 39 40 41 42 43 44 45 48 47 48 49 SO 51 52 53 54 55 56 57 56 59 60 61 62 63 ~ 65 66 67 6B 69 10 71 72 13 14

IIII,

IY

IAlDln
RPG

IT

rrit-.Tlrlr-Is

IJ

OUTPlJ

Program

I

Programmer

178.35

: 1363

Date

TOTALS FOR QTY AND COST

oI

0

ISpace

I~

~

Filename

Line

5 16 17

8

9 10 11 12 13

loi- I-ITI~

10
10
10
lois 10

IiI!

I~

Output Indicators

Skip

Field Name

Ijl~
iArcto

If

~~Io

IT I, it

AL

A~

l~

:~

l~
20 121

1·~1f.Ig;

·AUTO

POllton

I~II
I~

132 33 34 35 36 37 138

b9

in
Output
Record

140

414~

No

I~

I

No

I 4 I 0 I MI

Suppress

I

Constant or Edit Word

."148 4. 50 51 52 53 54 55 56 57 58 59 60 61 62 63

~

65 66 67 6B 69 70171 72 73 74

11.1~
ITlllT I/IYI~
rr~ trlr ~sl~

Figure 5-67. Group Printing - Printing Only the Final Tota's

5-60

~
'tJ

l,bblrif-,Ic::IT

c

4

a
:!2~
"ii
LLi.L
.~

Intern.tion,1 BusinelS Machin. Corporltion

Programmer

1011
1012
1013
10 14

Field
Indicators
0

~ .5 gt
g
~~
.3 :';;u

Q.

To

I~

I-p_ro_g_r._m_ _ _ _ _ _ _ _

•

From

a:

~

Field Name

IIIII I

9 10 tl 12 13 14 15 16 17 18 1920 21 22 23 24 25 26 27 28 29 30 31 3233 34 35 36 37 38 39 40 41 42 43 44 45 46 41 48 49 50 51 52 53 54 55 56 51 58 596061 62 6364 65 66 61 6B 69 70 71 72 73 14

RPG

IBM

13

0
.;;;
0

Filename

...~
~
4

75 76 77 78 79 80

,Field Location

~

Line

2

page~Of_ :~:~f:ation I

Date

I

3

U/M OSO·

Printed In U.S.A

Intern.tiona! Business Machine Corporation

lt~

1213
~Iq

I'IT l("'iT !All lei IFI"'IR If.-ITlv lA~ln

1,-1,..

j~rrl'

(

Group Printing of Subtotals
\
I

,/

Figure 5-68 shows group printing of subtotals. The input
records for the program contain item, quantity, and cost
fields; they were previously sorted by like items.
Figure 5-69 shows the codingto produce the report. Since
a subtotal is to be calculated for each different type of item,
the field ITEM is designated as a control field on Input
specifications. The calculations show that, as each input
record is read, the values in the OTY and COST are
accumulated into subtotal fields. At each control break,
the subtotal fields, SUBOTY and SUBCOS, are accumulated
into final total fields.
The Output-Format sheet in Figure 5-69 shows coding for
three different types of printed lines:
•

A detail line, which is printed for each input record read.
Note the use of a control level indicator on the ITEM
field., This causes the field to be printed only for the
first record of each control group (see Figure 5-68),
making the report less cluttered and easier to read. This
is known as group indication (see index entry) .

• 'A total line, conditioned by L1, which is printed only
after each complete group of like items was read, that
is, after each control break.

'\
)

•

A final total line, conditioned by LR, which is printed
only once, after all records werE~ processed.

If you want the subtotals to be the sums of only the
quantities and cost in one section (for instance, only those
quantities and costs under item ABCD), it is necessary to
set those fields back to zero after they have been printed
and added into the final totals. This process is indicated
in column 39. The B entries indicate that the totals, SUB
QTY and SUBCOS, are to be blanked out, or zeroed out,
after they are printed, when the control field (ITEM) changes. They are set back to zero so that they can correctly
accumulate the quantities and costs for the next item.

Controlling Operations In An RPG II Program

5-61

ABeD

25
60
65

25.00
60.00
65.00

:L50

:L50.00

:LO
2000
50
:L80

.20
40.00
:L.OO
3.60

2240

44.80

40
49

80.00
98.00

I
I

89

:L78.00

SUBTOTALS

I

2479

372.80

FINAL TOTALS

0
0

MNOP

0
0
0

I
I XYZZ

01

/

SUBTOTALS

SUBTOTALS

01

•

Figure 5·68. Group Printing - Report Showing Subtotals

File Description Specification
File Type

F

Record Address Type

Sequence
File Format

line
N

8.

Block
Length

~

E
J!

Extent Exit
for DAM

Length of Key Field or
of Record Address Field

End of File

Filename

File Addition/Unordered

Mode of Processing

File Designation

~

Record
Length

~~;:n~:a~i~~

~

or Additional Are.

~

Name of
Label Exit

Symbolic
Device

Device

Number of Extents
Tape
Rewind
File
Condition
Ul·U8

Core Index

Overflow Indicator c
Key Field
Starting
Location

l;

a:~ ~::-

.~
~

Continuation lines
Option

LU

Entry

4

3

o

2

o
o

3

4

RPG

IBM

GX21·9094 U/M 050·
Printed in U.S.A.

INPUT SPECIFICATIONS

International Busin," Machine Corporation

12

Program
Page

Date

Programmer

l;

I

Record Identification Codes

5 ~--------~----------~--------~

r&l

Filename

Line

Field Name
Position

3

o
o
o
o

4

5

5

2

I

3

I

4

I

5

I

7

8

z

0 ~

i

§~

Position

t

~~ ~

Position

From

of _

.

~~~;~f~cation I

757617787980

1 1 1 ·1 1 1

Field
Indicators

Field Location

]

•

Number of Track.
for Cylinder Overflow

Zero

To

Plus Minus or

Blank

~u6

9 10 11 12 13 14 15 15 17 18 19 20 21 22 23 24 25 25 27 28 29 30 31 32 33 34 35 35 37 38 39 40 41 42 43 44 45 45 47 48 49 50 51 52 53 54 55 55 57 58 59 50 51 52 53 54 55 66 67 68 59 70 71 72 73 74

~

5

~flJ

IrITIJ=~

IL 1

IllY

q

Figure 5·69 (Part 1 of 2). Group Printing - Printing Subtotals
/

5·62

RPG

IBM

)

In.rn"lonll BUllnt.. Mechint

Form GX21-11013

CALCULATION SPECIFICATIONS

Printed in U.s.A.

Corpor.~on

page~Of_

Cill

./

C
r-Lin.

Indicators

~

o
o
o
o
o
o

Result Field

98.

ji

Jd

Operation

Factor 1

Jd

~l~
0
&~5j
e 8 7 8 I 10 1112 13 14
Z

3 4

Factor 2
Length

Name

Resulting
Indicato"
Arithmetic
l!!
~g Plus JMinuslzero
l'l ~
Compare
Q.
~
1>211<211-2
~i Lookup{Factor 21i.
High Low Equal

::~"f~tlon I

Comments

~~

j

1

C

rll

hrlv

~IDID

l~

..,.'1"1
IllY

i';IL 111

C

rl.:!

11-",

SrT

~'DID

~ J p.'r hl~

~IIII':I

3

C

L

5

1""1 .... -

~I[JID

J:[ NI"'I ITlv

~Ir

4

CI

.1

[c:., Ip,~

IAlnl£l

'J:~

I:lr I\Ir 1""115

6

C

6

C

,...~

Nr hlc;

OUTPUT

RPG

~I~

IY

~12

N~

Q~
Q~

ITly

GX21-9090

U/M 050'
Prin«td In U.s.A.

SPECI FICATIONS

Intemltion.. Business MKhine CotpOt'ltion

l' 2

0

E;Space

r--

t::.::
e ....

Filename

......
~ ~ j
&-"

...> en~

!

:;
d;<

A 'Do
o R
~ND

~

•

Output Indicators

Skip

iEi

Line

AL

! !

1

b

z0

Field Name

I

ill

0

z

z

'AUTO

...

In
8
-~

]

End
Positon
in
Output
Record

4 6

6

1

0""

o

2

0

o
o

3

0

"'Tlv

I~

L.~

4

0

~,..

I~

23

o

6

0

o
o
o
o

6

0

lc; A I-

7

0

~

8

0

9

0

1 0

0

I,: .. N I- Tyl3

1 1

0

J:r ~I~ ""c.l~

1 2

0
0

1 4

0

Commas

Zero Balances
to Print

No Sign

CR

-

Yes
Yes
No
No

Yes
No
Yes
No

1
2
3
4

A
B
C
0

J
K
L
M

::~f~cation I

I. I I I I I

X • Remove
PlulSign
Y • Oat.
Field Edit
Z • Zero
Suppress

0:

g

Constant or Edit Word

ii:

9 10 II 12 13 14 16 16 17 18 1920 21 22 2324 25 26 27 28 2930 31 32 33 34 35 36 37 3839 40 41 42 43 44 45 48 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 84 65 66 67 88 89 70 71 72 73 74

3

o

1 3

7 8

75 78 77 78 79 80

pageWOf_

Oat.

PrOWIRuner

)

IIIIII

15 18 17 18 II 20 21 22 23 24 26 28 27 28 29 30 31 32 33 34 36 36 37 38 39 40 41 42 43 44 45 48 47 48 49 50 51 52 53 54 55 5657 58 59 50 81 62 63 84 65 88 87 88 89 70 71 72 73 74

2

DM

76 78 77 78 79 80

1 2

Program

TP J IT

"

1'"

IT 21

0111
IL LL

IT IEI~
~h"

4

LL
r:l~

"'Ir I_:u~
/"'Ie. 12. R

l~

2'.1
3~

h" 12~

liS IUtn

l~

S'

R
113
21;
~I~

'F-

",p,

I'rl'l rlt\ IL IS

I

Figure 5-69 (Part 2 of 2). Group Printing - Printing Subtotals

-..."

)
Controlling Operations In An RPG II Program

5-63

Group Printing wit!] Two Control Level Indicators
Certain programs require two or more control levels. Nine
levels (L 1-L9) are possible. This program uses two of these,
L1 and L2, to produce the report shown in Figure 5-70.
Each record in the input file contains the part number of
an item, the quantity of items sold, and a number to identify the salesman who sold those items. The file has been
previously arranged by salesman number. That is, all records
for salesman number 12 are together, all records for salesman number 13 are together, and so forth. Records are
also grouped by item number within each salesman group.
On the printed report, the salesman number is to be printed
once; part numbers are in the next column with the sums
of quantities for each part number in the rightmost column.
Subtotals are printed for each salesman and a final total
is printed at the end of the report.
Figure 5-71 shows the coding to produce the report. Since
the PARTNO field changes most frequently (there are
several part numbers for each salesman) that field is the
lowest level control field and is assigned indicator L 1 on the

Input sheet. The next higher level control field, which does
not change as frequently, is SLSNUM; therefore, SLSNUM,
is assigned indicator L2. The calculation on the first line
(01 indicator specified) occurs for every record that is read.
OTY is added to a total, OTYSUM. Line 2 occurs only ,
when the control field, PARTNO, changes, because L1
(columns 7 and 8) controls this calculation. So, when L1
is on, OTYSUM is added to another total, SUBTOT. T~e
third line describes the calculation of a finaltotal, FINOT.
This calculation occurs when L2 is on (when the control'
field, SLSNUM, changes).
When the higher level control level indicator (L2) is on, the
lower level indicator (L 1) is also on. As shown on the Output-Format sheet, when L 1 is on, PARTNO and OTYSUM
are printed (lines 03 and04). However, the field SLSNUM
is conditioned by L2, so itis printed only for the first record
of each L2 control group. When L2 is on, SU BTOT an~
the constant SUBTOTAL are printed (lines 05-07). When
LR is on, FINTOT and the constant FINAL are printed.
The two subtotals, OTYSUM andSUBTOT, are zeroed
after printing by entering a B in column 39 (lines 04 and
06). Detail lines need never be blanked after, nor does a
final total (regulated by the LR indicator).

/
I
\ ... ,.

5-64

Page of GC21-7567-2
Issued 21 December 1979
By TNL: GN21-5709
SALESMAN NUMBER

\

)
12
12
12

0

A235
B124
C140

375
100
200
675

0
A235
C140

13
13

0

SUBTOTAL

50
400
450

0

SUBTOTAL

,-

0

B124
C140
D896
E091

14
14
14
14

0

600
325
110
370
1405

SUBTOTAL

2530

FINAL

0

Figure 5-70. Group Printing - Report Produced Using Two Control Level Indicators

File Description Specification

)

File Type

F

Mode of Processing

File Addition/Unordered

Extent Exit
!orDAM

Length of Key Field or
of Record Address Field

File Designation
End of File

Record Address Type
Sequence

Filename
Une

N

~
~

Record
length

RPG

w

Tape
Rewind
File
Condition
Ul-U8

Core Index

~

a

.~
~

Key Field
Starting
Location

Continuation Lines

K

W

Option

Entry

GX21-9094 U/M 050'
Printed in U.S.A.

INPUT SPECIFICATIONS

International Business Machine Corporation

1 2

Program

Page

Date

Programmer

Record Identification Codes

I

~

Position

~
0

z
3

4

o
o

1

I

6

2

I

o

3

I

o

4

I

o

5

I

~

~
~

u6

Position

:;;

t>
~

~~
zu 6

Position

75 76 77 78 79 80
of_

~~:;~f:ation I

~
0

z

tl

§~

~ c::

....

To

~

~

CD

(I)

ii:

0

~

Field Name

LLLL

~

Field
Indicators

0

] ~~

'in
0

From

~

c

IIIIII

-;;

0-

0

Filename

Line

EiI2J

Field Location

f----

5

Number of Extents

Overflow Indicator ~

0

< ::::

IBM

Symbolic
Device

Device

....

Type of File
Organization
or Additional Area

File Format

Number of Tracks
for Cylinder Overflow

Nameo!
Label Exit

ff

:EU

~

'0

J
'0

a;

Zero

Plus Minus or
Blank

u:

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 3031 32 33 34 35 3637 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 5960 61 62 6364 65 66 67 68 69 70 71 72 73 74

r II t-.

I

,

IAA

1211
1

LI IplAIRr'Nh 1
"' ....
~IL
IY

q

,r1.0c:,.'J IC:;Nr ~I"

Figure 5-71 (Part 1 of 2). Group Printing with Two Control Level Indicators
Controlling Operations In An RPG II Program

5-65

Page of GC21-7567-2
Issued 21 December 1979
By TNL: GN21-5709
RPG

IBM

CALCULATION SPECIFICATIONS

Form GX21·9093
Printed in U.S.A.

1 2

Program

Programmer

C

Indicators

~~

I---

~3~

Une

E ::;

•

.g

Factor 2

5 6

7

Length

Name

..... ,ori
U)

,LS5"
3

Operation

Factor 1

At

8

~

0
z

0

Z

C

""'T Ivs 1M

2

C

1

~IT YS I'JIM

Af"I.D
An~D

r'lT VC; IU~

o

S

;

I...

o

3

C

2

Sil g .... I"'h"

ADln

,:-lr NT Il"li

l-

11\1

o

4

C

RPG

OUTPUT

IBM

~i

f'I~y

JoI

II

I~

Plu •. IMinu.1 Zero
Compare

High

~!c2l
~rJJ

,
GX21·9090 U/M OSC'
Printed in U.S.A.

SPECIFICATIONS

International..Business Machine Corporation

1

0

~ Space

Output Indicators

Skip

e~

-

11

0-

Filename

Line

!
6

7

8

3

4

o
o
o
o

1

Ole. II

2

0

3

0

4

0

0 5

0

o
o

6

0

7

0

o
o

8

0

9

0

1 0

0

1 1

0

1 2

0

~~
I- v;

~

~~

ADD

E

~
5

!. ...CLi e

**0

~

~ z0
<

0

'(il

Field Name

IT]

~

0

z

z

~

·AUTO

Positon
in
Output
Record

9 10 11 12 13 1415 16 17 18 1920 2122 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

1-"' toO- IJR '11

2

75 76 17 78 79 80

page~Of_

Date

Programmer

l~

T 12lL

c::; c;IN ' 1M
IPA RrT- NIt;

ll~

Zero Balances
to Print

Ves
Ves
No
No

Ves
No
Ves
No

a:

g

)

No Sign

CR

-

X

II:

1
2
3

A
B
C

V

~

Z

.~

4

0

J
K
l
M

I. 1 1 1 1 I

Remove

Plus Sign
Date
Field Edit
Zero
Suppress

Constant or Edit Word

ii:
«~~~~49~~~~54~~"~~~~~~~~M"M~ro

71 72 73 74

..... T ,ylc:. "

lil7

2.

M '!:lID

/

L 12

I,

5J MI
T I~IIZ

Commas

~~~;~f:ation 1

'.1

I

.,jl~

Lt.17
1211 'S I1B .... "

\,

"-A

IR

IF!! INT '.... T3

lil1
12.14 ' IF IT NIA

Figure 5-71 (Part 2 of 2). Group Printing with Two Control level Indicators

5-66

low Equal

:~ll

.......

Program

-

Comments

1>211<2(1-2
'u - lookup(Factor 2)i,

49 49 5051 52 53 54 55 5657 5859 50 61 62 63 64 65 66 67 68 69 70 71 72 73 74

0 1

!lIl

1 1 1 1 1 I

Arithmetic
J:

O:I:

9 10 1112 13 I. 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

~~~;~f:ation 1

Resulting
Indicators

Result Field
2

.AL

75 76 17 78 79 80

page~Of_

Date

~

,.
i

Intern.tion.1 Busine" Machine Corporetion

,

,

Page of GC21-7567-2
Issued 24 May 1976
By TNL: GN21-5389

BINARY FIELD OPERATIONS (CONTROLLING
SWITCHES)

BITON Operation Code

Note: This topic is intended for IBM System/3 Model 6,
Model 10, Model 12, and Model 15 programmers.

RPG II provides certain operation codes which set and test
individual bits in storage. These individual bits can be set
and tested to allow you further control over processing.
When this is done, the bits are called switches and their
functions are similar to that of RPG " indicators. The
operation codes which set and test the bits are known as
binary field operations. A binary field isa one-byte field
containing 8 bits identified left to right by the digits 0-7.
The bits can be set on, set off, and tested. Since each bit
can be utilized, there are eight indicators in every byte.

Figure 5-72 shows a Calculation sheet containing the BITON
operation code. This operation code causes specified bits in
Factor 2 to turn on (set to 1) in the field named in the Result Field. The field named in the Result Field must be a
one~position alphameric field. Since it is one position in
length, a 1 must be entered in column 51 of Field Length.
One or more of the eight bits can be turned on. To turn on
the first bit in a field, enter 0 in Factor 2. These bit numbers must be enclosed by apostrophes.
You can condition the operation with indicators in columns
7-17. You may also turn on a bit in an array element, but
that array element must b~ one position in length.
In Figure 5-72, bits 0, 1, and 7 are set to 1 in the binary
field labeled CODE.

When using binary field operations, remember how data
fields are initialized by the system:
• Alphameric fields are initialized to Hexadecimal '40'.

BITOF Operation Code

•

Figure 5-73 is a sample Calculation sheet containing the
BITOF operation code. This operation code causes specified bits identified in Factor 2 to turn off (set to 0) in a
field named in the Result Field; In Figure 5-73, bits 0, 3,
and 4 are turned off (set to 0) in the binary field labeled
CODE.

Numeric fields are initialized to Hexadecimal 'FO'.

You should initialize the binary field containing the bits to
be set and tested to binary zero (Hexadecimal '00') at the
beginning of the program.

)

All other specifications are the same as those specified under
BITON Operation Code.

RPG

IBM

Intern.tion.. BUline. MlChln.

Form GX21·9093
Printed in U.s.A.

CALCULATION SPECIFICATIONS

Corpo,..~on
1 2

Pt09,am
Programmer

Page
Dot.

c

~:~~~

I---

I! 1ft
51~ :j~ .~ ~1I11~
Aid

Line

3

4

7 8

IC

'01 2

IC

01 3

Ie
Ie
Ie
Ie
Ie

0,5
0 6
'
0,7

AL

Factor 1

Operation

Factor 2

,

,0: 1

014

75 76 77 78 79 80

[Do,_ ~~~a;:tion I I I I I I I

10

Name

I~

iiIIiiiii

'28 29 30 31 32 '33 34 35 38 37 38 39 40 41 42 143 44 45 48 47 48

~ I :r1f'l~N

' :..J~
..... '0 a:.'"
E l:I en

line

3

Indicators

~

0_

75 76 77 78 79 80

2

pageDJOf_

Date

Programmer

I

I

I

Comments

Compare

1>211<211=2
Lookup(Factor 2)is
High Low Equal
54 55 5657 5859 60 61 62 63 64 65 66 67 66 69 70 71 72 73 74

b~ 1717 ~R

I I

I I I I I 1.1 I J I I IIJ

r 11111111111111
I

I

I

I

I

I

I

I

I

I

I

I

I

I

Example
~

~)

Fields are sometimes present in customer master files to indicate particular types of customers. When such a master
file is created, each of the conditions indicating a particular
customer type is represented in a record by a one-position
field. Since each position occupies one byte of storage, four
positions indicating customer types will be stored in four
bytes of storage. You can use binary field operations to
convert each one-byte record position to one bit of information on disk. Therefore, four bytes of information can be
reduced to four bits of information on disk.
For example, assume you have a customer master file on
cards. You have four columns containing the following information:
• Whether the customer is a wholesaler or retailer.

.. ,
)

•

If the customer is entitled to a discount.

•

If orders should be checked by the credit department.

•

If due to a bad payment history, the shipment should be
sent cash on del ivery.

Now you want to place the card file on disk, and the information from the four columns in four bits in a binary
field labeled CHECK. The four columns will be labeled
WHLSE, DSCT, CREDIT, and COD respectively. The folowing operations should be performed:
1.

If WH LSE is equal to 1, turn on bit 0 in CH ECK.

2.

If DSCT is equal to 1, turn on bit 1 in CH ECK.

3.

If CREDIT is equal to 1, turn on bit 2 in CHECK.

4.

If COD is equal to 1, turn on bit 3 in CHECK.

INCREASING THE SPEED OF OPERATIONS (DUAL
I/O AREAS)
'During the normal RPG II cycle, a record is read, calculations are performed, and output is produced. The cycle is
repeated for each record.
The speed at which the cycle is done depends upon the
speed at which records are read and output produced. Calculations take less time than reading, printing, writing to
disk, or punching. The speed of doing output can be increased by using dual input/output areas.

Dual Input Areas
When dual input areas are used, the program cycle is
changed. First a record is read. At the same time, calculations are being performed on this record, another record is
being read. Thus, the contents of two records are in the
computer at the same time. Figure 5-76 shows how the
records are processed when two input areas are used.
Dual input areas can be specified for sequential disk files or
direct disk files processed sequentially, for card files designated as input files, or for tape input files. No stacker
selection can be specified for card files. Dual input area~
cannot be specified for combined or update files, table, or
demand files. When shared input/output is specified in the
header card, all devices which can use shared input/output
are automatically excluded from use of dual input areas.
(Note to Model 6 Programmers: Dual input areas can be
used for data recorder input files. Dual input areas cannot
oe assigned to disk, data recorder, or ledger card device files
using a shared input/output area, specified in column 48
of the Control sheet.)

Figure 5-75 shows correct coding for this problem. Remember that before setting up data in a binary field, the
binary field should be set to binary zero. This can be done
by the BITOF instruction (Line 1, Figure 5-75).

Controlling Operations In An RPG II Program

5-69

RPG

IBM

Form GX21·9093
Printed in U.S.A.

CALCULATION SPECIFICATIONS

InternatIonal Busine" MachIne CorpOr"ion

1 2

Program

D.t.

Programmer

-

C

Indicators

At

AL

Factor 2
Name

E

~
6

'0

z0

z

Length

0

Z
9 '0 1112 13 14 1S 16 17 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 33 34 35 36 31 38 39 40 41 42 43 44 45 46 41 48 49 5051

3

4

o
o

1
2

C

IlAlu ~III~

o

3

C

h~ ~rr

o

4

c

,.. I Joj 'f-

o

5

c

.. t,..!1J

o

6

C

sir rr~ 11= ' 1£2IL
,..,..

c

~r

IMlo
I/'Vlp

~',. ~Ip

ITII

Irlro 1I\Ilp

1... 1..

1 •

.1 ..

.'"'1

1~11

' ,.. ILJlc Irlw

ll~

11 L?
III~

''''''111

N \

M

N'

12

I

"'Iu It lr 10(
"'I~ Iclr lot
!rILl 1t'1.- It

~,

[3'

~IH ~~k

7'

'c

ILL

8

C

10-

9

c

11,
II L~

1 0

C

~

Comments

54 55 56 57 58 59 60 61 62 63 64 65 66 61 68 69 10 11 12 13 , .

'lI.J

11
I,
, lZ

(

lL

11

M~II

o

Compare

IIIIIII

1>211<211-2
Lookup(F.ctor 21i,
High Low Equal

II

l~

o

..

Operation

Factor 1

to-

5

Resulting
Indicators
Arithmetic
Plus IMinusl Zero

Result Field

~

line

75 76 77 78 79 80

P.ge~Of_ ~~~;~f:ation

I

11 '

,..

Figure 5-75. Example of Binary Field Operations

(~,

Input area 1

)
Input area 2

Record B

Input area 1

Record C

~ ::~~:~.o;;!~;~ c
f B is processed.

)

Input area 2

Input area 1

Input area 2

is read while Record

l

Record 0

Records A and Bare
initially read into
storage.

i

After Record B is
processed, Record 0
is read while Record
C is processed.

Dual input areas require more computer storage space than
one input area, because two records are in storage during
each cycle. If you have a large program, you might not
have enough storage space to accommodate two input areas.
The effect of dual input areas can be determined only if you
have knowledge of a program's processing requirements and
experience in RPG II programming. In some cases, you can
only make a final determination by actual experimentation.
(Note to Disk Programmers: If your program plus two input
areas require more space than is available, certain RPG II
object cycle routines remain on disk during execution and
are called into storage as needed. If too many routines remain on disk, the performance of your program may be decreased by the use of dual input areas rather than increased.)

Specifications

One entry on the File Description sheet is required to specify dual input areas: any digit (1-9) in column 32 assigns du'al
input areas for the specified file. Figure 5-77 shows the file
MASTER has been assigned dual input areas.

Note: The shaded areas represent records being processed.

Figure 5-76. Dual Input Areas

5-70

c

File Description Specification
File Type

)

End of File

Record Address Type
Type 01 file
Organization
or Additional Are.

Sequence
File Format

Line

.e
~
__

C

5

<::

~w~~
3

4

o

2

o
o
o

3

5

1

8

9

N

Block
Length

Record
th
long

Overflow Indicator

~~ g

10 11 12 13 14 15 16 11 18 19 20 21 22 23 24 25 26 21 28 29 30

-J

Device

~:~liC

Key field

.~ ~ ~'34

Number of Tracks
for Cylinder O•• rflow

Name of
Label Exit

Number of Extents
r-::Ta-pe--:--i
Aew;nd
~

W
~

Core I ndex

U

~ 5

~ ~

.~

Continuation Lines

~:~~!.!

Option

Entry

~

Z

Condition
Ul us

~

.

r--

35 36 31 38 39 4041 42 43 44 45 46 41 48 49 50 51 52 53 54 55 5& 51 58 59 60 61 62 63 64 65 66 61 68 69 10 1\ 12 13 14

4

5

I-+ +-+-+-+-+-f-++-+-+-+-+-I-+-+-+-t-++-I-+-+--t-if-+-I-+-If-t-I
O 6

o

Extent Exit
for DAM

Length of Key Field or
of Record Address Field

File Designation

Filename

File Addition/Unordered

Mod. of Processing

7

F

o8
o9

F

1 0

F

Specification of dual input areas
for ca rd fi les is a Iso do ne with
a digit in column 32.

F
F

Figure 5-77. Specifying a Dual Input Area

Dual Output Areas

)

When dual output areas are used, the program cycle is
changed. A record is written or punched out at the same
time calculation and output operations are being done internally to produce the next record. (Calculation operations are not done at the same time as writing or punching
when only one output area is used.) Figure 5-78 shows
how output records are produced using dual output areas.
Dual output areas, like dual input areas, require more computer storage. Consequently, the same space considerations
that apply to dual input areas also apply to dual output
areas. Dual output areas can be used for sequential and
direct disk output files, Model 10 printer files (5203 printer),
tape files, and card output files. Dual output areas cannot
be specified for combined or update files. Also, dual output areas cannot be assigned to Model 6 data recorder, disk
or ledger card device files and Model 10 or Model 15 disk
files that use a shared input/output area.

Specifications

)

One entry is required on the File Description sheet to specify dual output areas: any digit (1-9) can be entered in column 32 for an output file. Figure 5-79 shows the file
PRINT has been assigned dual output areas.

Controlling Operations In An RPG II Program

5-71

~

<

Output area 2

Record B

Output area 1

Record C

(

Record A is in output area 1.
While record A is being written
or punched calculations are
performed on record B, and it
is moved to output area 2.

~

"

When record A is finished, record
B is ready to be written or punched.
While record B is being written or
punched from area 2, record C is
calculated and moved into area 1.

~
Output area 2

(

Record D is calculated and
moved into area 2, while
record C is being written or
punched.

1

Record D

Note: the shaded blocks represent records being written,
punched, or printed.

Figure 5-78. Dual Output Areas

File Description Specification
lOa.

Fil.Type

F

~

End of Fila

n.

Sequence

Filename

Extent Exit
for DAM

~::gth of Key Fie~~ield

File Designation

A.

,Type

Device

Type of Fila

Symbolic
Device

Fila Format

.~

X,I
~g

11
3
1

4

0 12

10 13

5 16l--"-~.!Q

IFR

10 4

IF

0 15

IF

1

0 16

IF

1

0 17

IF

lola

IF

10 19

IF

1

1

11 10

IElAlf"I

Ir-~ I.I1LL

lrjl!

12 13 14

lip
,...

.I~ I

Block
ltng1l\

N

Record

length

I:)

~~_T,l ~~lf!11

F

121t;lh

1

IE

lll~ 12

1l3~

L2IA

~~~

,il~

IVY····~
Key Field

~
~
Condition
Ul-l!!!...-.

r~"I •••1.

Starting
location

61~.!!;l~65

166 167 6869 170171 72 73 74

hI! slk
IplR

I~

I~

K

.34'35 36 37 3S I~l~o 41~~~~46 147 46 49 50 51 52 5:l154 55 56]iL~59 60

rICKS

Number of Extents

Core Index

". Additional Ar••

Uno

Numoer OT

Name of
Label Exit

I'll!

tiN rlf:R

IF

l'"IF
1I. IL OL 69 89 L9 99 99 W t9 t9 19 01' 69 II'l L9 99 59

.s

ts t9 19 09 6.

a.

L. 9. 5 . . . t. t. I. Ot 6t 6t Lt 9t 9t

~

tt tt It at 6t lit Lt 9t st .t tt tl It 01 61 81 LI 91 51 .1 tl tl II 01

6

8L9S.ttl

Figure 5-79. Specifying Dual Output Areas

(
5-72

Review 5

'\

)

Additional Uses of Indicators
1.

What effect do halt indicators have on System/3 operations? How can you use halt
indicators to handle error situations?

2.

Describe a method to eliminate an output file for one program run without having to
rewrite specifications and recompile the program.

3.

When conditioning a calculation specification with an indicator, what happens when
the indicator is on? What happens when it is off?

4.

Describe what the TESTZ operation does.

5.

Result Field

Using this TESTZ specification, tell what the status of indicators 93, 94, and 95 will be
when the field TEST contains:
a. ABC
b. &/*
c.JOH
d.789·
I

6.

Result Field

Review 5

5-73

Using this COMP specification, tell what the status of indicators 96, 97, and 98 will
be when the fields FIRST and SECOND contain:
/~

Second

First
a. 16942

17942
15000
19645
18931

b. 16000
c. 19645
d. 18921

Controlling Operations on the Basis of the Next Record in a File
7.

Basically, what does the look ahead facility allow you to do? What limitations apply
to its use?

8.

To the input specifications given add those which will allow you to look ahead in
order to read the next part number (PARTNO) and next code in colun:m 96.

RPG

IBM

GX21·9094 U/M 050·
Printed in U.S.A.

INPUT SPECIFICATIONS

Intern.tionel Business Machine Corporation

1 2

Program
Page

Date

Programmer

~

I

Record Identification Codes

g

~.

~.,-

Filename

Line

Position

"E

~

6

7

8

~
0:;

'.. 0

~

m

g e~
0

z

S6

Position

m
~.e te

~S6

Position

75 76 77 78 79 80

of _

~~~;~f:ation I

go m'"
'0

t!

zu

a:

~~~
ci)Q::

,

From

:~
~

To

Field Name

~
·il

3

4

1

Ir Nip Il T

o

2

I

J

b

o
o

3

I

1

1':1,2

4

I

B3

o

5

I

]

15

:9~

~~

"''''

1i~

0

o

~

·8

~

j
"u:

0:;

Zero
Plus Minus or
Blank

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

AlA

IIt2l

Alb.

I,.

q

lO(

. . I

..

t"'~IH.

-

N I....

1['\lr 15'"
~

lilT

'-:!

Moving Data

5-74

IIIIII

Field
Indicators

Field Location

]

I--

5

CD

9.

With MOVE, which position of Factor 2 is moved first and where is it positioned in
the Result Field?

10.

What happens in a MOVE operation if Factor 2 is larger than the Result Field?
What happens if it is smaller?

11.

With MOVEL, which position of Factor 2 is moved first and where is it positioned
in the Result Field?

12.

What sign does a numeric Result Field have after a MOVEL operation?

/

Page of GC21-7567-2
Issued 21 December 1979
By TNL: GN21-5709

13.

FIE LD 1, a 4-position positive numeric field, contains 3456; FIE LD2, an 8-position
negative numeric field, contains 87654321. What will the contents of the Result Field
be after each of the following instructions is executed, if FIELDl and FIELD2 contain
the above values before each instruction is executed?

RPG

IBM

CALCULATION SPECIFICATIONS

Form GX21·9093
Printed in U.S,A.

International Business Machine Corporation

1
Program

Page
Programmer

-

Date

C

Indicators

At At

8.

Line

&
4

5 6

Operation

Factor 1

Factor 2
Name

a

1

C

a
a

2

C

3

C

a

4

C

5

C

a

6

C

a
a

7

C

8

C

n

!I

r.

a

a

a

Length

Z
Z
9 10 1112 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 JJ J4 35 J6 37 J8 39 40 41 42 4J 44 45 46 47 48 49 5051

Z

-

f-

75 76 77 78 79 80

IIIIII

Resulting
Indicators
Arithmetic

~

3

a

Result Field

2

[D0f_ ~~:~f:.tion I

~f'\ V~

Fr~

I

Fr I},;J D2.

M'" ViE L1= liE LIl:'2

1=r IE L C1

MI" viE FI IEL 'r. 2.

FT I~IL 1"'\1

Mr. 'VI~

J:r 1f"IL 1"'112

FTI~

In

1[11

Plu. IMinusl Zero
Compare

Comments

1>211<211-2
Lookup(Factor 21is
High Low Equal
54 55 56 57 58 59 60 61 62 63 64 65 68 67 68 69 70 71 72 73 74

)
Branching in Calculations
14.

What is the purpose of branching?

15.

How is branching specified in RPG II?

16.

By using branching, how can you structure a program, which has several record
types each of which requires different calculation operations, so that it is easy to
write and efficient to run?

17.

What must you always include in a program that has a loop? What will happen if
you do not include this?

Using Subroutines in Calculations

\

)

18.

When should a subroutine be used?

19.

What are the operations used to define and execute a subroutine? What entry must
be made in each calculation line of a subroutine that is different from all other
calculations?

20.

What limitations in the use of GOTO and TAG apply to subroutines?

21.

Where must subroutines be coded?

Review 5

5-75

Special Uses of Control Level Indicators
22.

When would you use the LO indicator?

23.

How can you specify calculations to be performed only on the first card of a group?

24.

When should you specify blank after (8 in column 39 of the Output-Format sheet)
for an output field?

Binary Field Operations
25.

What are bit switches used for?

26.

Code the calculation specification to:
a. Set on bits 4 and 7 in a field called TESTER.
b. Set off bits 1, 2, and 3 in TESTE R.
c. Test to see whether bits 1, 2, and 3 in TESTER are all on or all off. Set on indicator 01 if they are all on and set on indicator 02 if they are all off.

Dual Input/Output Areas
27.

5-76

For which device and file types can you specify dual input/output areas on your
system?

Answers To Review 5

1.

Halt indicators may be turned on as record identifying indicators, as a result of a
test on a field, or as a result of calculations. When they are on, they cause the
system to halt after all calculations and output operations have been performed for
that program cycle.
Because a program cycle is completed before the system halts, operations may be
performed on erroneous data. Halt indicators, when used as conditioning indicators,
allow you to bypass calculations and output operations which would usually be done.
They also alloW you to print error messages and stacker select any cards with erroneous information.

2.

Use an external indicator (U1-UB) to condition the output file and operations specified for that file. When the indicator is on the file is used; when it is off, the file is
not used. The file is conditioned by an external indicator specified in columns 71-72
of the File Description sheet. The output specifications must be conditioned by that
same external indicator entered in columns 23-31 of the Output-Format sheet.

3.

If the indicator is on,
not be executed.

4.

TESTZ examines the zone portion of the leftmost character in an alphameric field.
If that position contains & or A-I, the plus indicator will turn on. If that position
or J-R, the minus indicator turns on. For all other characters, the
contains -,
zero indicator turns on.

th~

step will be executed. If the indicator is off, the step will

f'

5.
a.
b.
c.
d.
6.
a.
b.
c.
d.

93

94

95

on
on
off
off

off
off
on
off

off
off
off
on

96

97

98

off
on
off
off

on
off
off
on

off
off
on
off

7.

Look ahead allows you to use data on the next record to be processed. Normally
only the data on the record currently being processed is available to the RPG " program. Look ahead is most often used with input files. If it is used with combined
or update files, information in the look ahead field while the combined or update
file is being processed will be from the record currently being processed, not from
the next record in the file.

B.

** must be specified in columns 19-20 to indicate that the fields listed are to be
looked at in the next card available for processing. Look ahead fields must be given
different field names than those used when describing the file. Any alphabetic
characters may be used in columns 15·16.

Answers To Review 5

5-77

Page of GC21-7567-2
Issued 24 May 1976

By TNL: GN21-5389
RPG

IBM

. GX21-9094 U/M 050'
Printed in U.S.A.

INPUT SPECIFICATIONS

International Business Machine Corporation

1 2

Program

Page

Date

Programmer

Record Identification Codes

I
-_~

5i

j

~

Position

";"N"ro
5

6

7

8

."
0

il

1l
r--r-5
o R Z

4

-'
-'

c

1)

Filename

~
0
z ~

.e

~

~

6

Position

~~
~u

~
~

6

Position

Field
Indicators

Field Location
C

Ol

Line

3

75 76 17 78 79 80

[00'_ ~~~:~f:ation I I I I I I I

z

t~

tl t

·in
0

0:

:::;

From

Field Name

C1.

To

0

~-tS

.!!"ii
u..~

j f:r
~6

E

in
z § ~~ 0::

.~

0

3

0

0

~

1

Zero

Plus Minus or

."

Blank

0;

i.i:

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

AlA

NP Jir

J~

o

1

It

o

2

I

lL

b

o

3

I

11

3~

o
o
o

4

I

1313

5

I

6

I

o

7

I

o

8

I

Al4

~Ih

**

~q

II
Iql~

'., I rt:

-

" '/i II'( I '"

I:lI ~,.
'IIY ..... H

~ INt=. IX liN
:ql~ Nix tr'"ln

9.

The righthand, low~order position of Factor 2 is moved first, to the righthand, loworder position of the Result Field.

10.

If Factor 2 is larger, the number of positions moved will be equal to the size of the
Result Field. If Factor 2 is smaller, the whole field will be moved and the lefthand
positions of the Result Field will be unchanged.

11.

With MOVEL, the leftmost position of Factor 2 is moved first to the leftmost position of the Result Freid.

12.

The sign of the Result Field after a MOVEL operation is performed will be the same
as that of the low-order character of Factor 2 unless Factor 2 is smaller than the Result Field in which case the sign is unchanged.

13.

a.
b.
c.
d.

14.

Branching alters the sequence in which calculations are executed. It allows you to:
a. Skip calculation operations.
b. Execute operations in an order other than the normal sequential order.
c. Perform the same calculations several times in one cycle .

/

. 15.

5-78

+
87653456
8765
4321
34564321

Branching in RPG II is specified by the operations GOTO and TAG. GOTO tells the
computer to branch to a location indicated in Factor 2 of the instruction. The TAG
statement is placed at the point in your program to which you want to branch. The
name in Factor 1 of the TAG statement is the same as the name in Factor 2 of the
appropriate GOTO. Every GOTO requires a TAG or the program will not know
where to branch to. Several GOTO statements may branch to the same TAG, but the
name on each TAG statement must be unique.

16.

Condition several GOTO statements with the various record type indicators. Write
the set of specifications for each record type separately and include them in the program. The set of specifications for each record type will begin with a TAG statement
and end with a GOTO stat~ment which branches to the end of all calculations. The
program will test the record type and branch to the correct set of specifications. At
the end of the set of specifications, it will branch around all other specifications to
the end of the calculation section.

17.

If a program has a loop, there must be some way to stop the looping. The branch
back instruction must be conditioned so that when certain conditions have been met,
the statement will not be executed. If this condition is not specified or cannot be
met, the program will go into an endless loop.

18.

A subroutine can be used whenever the same calculations must be executed at several
different places in a program.

19.

The first line of a subroutine must have the BEGSR operation code in columns 28-32
with the subroutin~ name in Factor 1. The last line in a subroutine must have
ENDSR operation code in columns 28-32. This line can have a name in Factor 1, and
this name can then be referenced by a GOTO statement. Every subroutine line mu~t
have SR in columns 7-8.

20.

No branches can be made from a GOTO statement within a subroutine to a TAG
statement outside that subroutine. No branches can be made from outside the subroutine to a TAG statement within the subroutine.

21.

All subroutines must appear on the Calculation sheetafter all detail and total
calculations.

22.

LO would be used if you need to perform some calculation steps at total calculation
time and there is no normal control level indicator (L l-L9) available. A common use
of this is to set on the other control level indicators when control fields are not
available.

23.

Detail calculations are distinguished from total calculations by the fact that columns
7-8 of the Calculation sheet are left blank for detail calculations. Since the control
level indicator stays on through detail calculations it can be used like any other indicator in columns 9-17 to control detail calculations. The control level indicator will
be on for only the first card of a new control group.

24.

Blank after should be used to reset a field to zero that. is used to accumulate and
print a total for each control group. This allows the field to start with a zero
value for the new control group.

25.

Bit switches are used to code and test for specified situations .. With System/3 Model
10 Disk System and Model 6, they are stored in one-byte alphameric fields in storage
and on disk. One example is credit information in an accounts receivable file. The
first bit might mean a COD only; the second, payment due in 30 days; the third,
credit limit $1000; etc. When these,conditions are coded as bit switches they take
up less disk space than single character codes that might be used in the same way.

26.

See coding sheet.

Answers To Review 5

5-79

Page of GC21-7567-2
Issued 24 May 1976
By TNL: GN21-5389
RPG

IBM

I
I

Program
Date

Programmer

C

I-Line

CALCULATION SPECIFICATIONS

International Business Machine Corporation

~
8.~
>-'
E !:

4

5 6

o

1

c

o
o
o
o

2

C

3

c

4

C

5

C

o

6

C

n 7

f'

Punch

I I
I I

I I
I I

I I

At

7

15

Operation

Factor 1

Jd

15

Page

Factor 2
Length

15

z

Z

9 10 1112 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 3B 39 40 41 42 43 44 45 46 47 4B 49 50 51

~III'

Jri

,
tr~ IslrIE' 112 I~ ,

If"!

II

rrlE Sir IER

'ILl l '

It- \

1112 I~

,

IIIIII

Comments

1'\
,..., ~r-,
It:~ rrlT ~N

~J

~t2

b-II w-

Mode/10 Card System:
•

M FCU input files (no stacker select; no table or demand files)

•

M FCU output files (no stacker select)

•

PR INTER output files

•

PR INTR2 output files

•

TAPE input file

•

TAPE output file

Mode/10 Disk System and Mode/12:

5-80

~~~;~f:.tion I

54 55 56 57 5859 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

It

I

27.

of_

Arithmetic
Plus Minusl Zero
Compare
1>21<211-2
Lookup(Factor 2lis
High Low Equal

h""1(; :5r, IE: R
(~I'" III~II"C

75 76 77 78 79 80

2

[I]

Resulting
Indicators

Result Field

Name

z

1

Card Electro Number

I I

'0

~8
3

Graphic

Instruction

Indicators

~

I-

Punching

Form GX21·9093
Printed in U.S.A.

•

MFCU or 1442 input files (no stacker select; no table or demand files)

•

MFCU or 1442 output files (no stacker select)

•

PR INTER output files

•

PR INTR2 output files

•

DISK input files (sequential and direct only)

•

DISK output files (sequential and direct only)

•

TAPE input files

•

TAPE output files

1111

1J:1c;;, IT

IT

N

2.15~

2l'ilJ121c;1r

Model 6:
•

DISK input files (sequential and direct only; no shared liD)

•

DISK output files (sequential and direct only; no shared liD)

•

DATA96 input files

Model 15: Same as Model 10 Disk System, plus:
•

2501 input files

•

MFCM input files (no stacker select; no table or demand files)

•

MFCM output files (no stacker select)

Answers To Review 5

5-81

i~

5-82

Chapter 6. Match Fields and Multifile Processing

)
CHAPTER 6 DESCRIBES:
How to assign match fields to one or more files.
Use of match fields to sequence check records in a file.
Using matching records to control the processing of multiple input files.

BEFORE READING THIS CHAPTER YOU SHOULD BE ABLE TO DESCRIBE:
How to identify input record types on the Input sheet.
How to use field-record relation.
How to specify stacker selection on the MFCU.

RPG II object program cycle.

AFTER READING THIS CHAPTER YOU SHOULD BE ABLE TO DESCRIBE:

)

Checking the sequence of records within a file using match fields.
Using match fields with field-record relation for more than one record type in a file.
Matching records when there is only one record type in a file.

RPG II logic for processing files by matching records.
Matching records when there are more than one record type in a file.
Matching records when all of the records in one of the files have been processed.
Using match fields and control fields in the same file.
How to determine whether a file should be primary or secondary.

Note: You can use the review questions contained in Review 6 at the end of this
chapter to test your comprehension of the topics in the chapter. Answers follow
the review questions.

)
Match Fields And Multifile Processing

6-1

INTRODUCTION
Match fields are data fields on separate records that are
compared to establish a relationship between the records.
Match fields have two functions, depending on whether the
related records are the same input type file or in separate
input type,files. (An input type file can be an input, update:
or combined file.)

Within a file, match fields are used to check the sequence
of records on which they appear. The sequence checking is
accomplished by comparing match fields in one record with
the match fields in the next record of the same file. When
two or more input type files are used by a program, the se, quence of each file can be checked just as sequence was
checked for a single file. All files that are sequence checked
by match fields must be in the same sequence, either ascending or descending.
In addition to sequence checking records within a file, match
fields can also be used to establish a relationship between
records that are in separate files. That is, match fields can
be used to match records from two or more input type files
. to determine which record is to be processed on the current
cycle. If two files are used in the same job and you do not
specify the order of processing, the primary file is completely processed first. Only then are records from secondary
files processed. By specifying that the order of processing
is to be determined by comparing the contents of match
fields, however, you can cause records from secondary files
that are related to a record in the primary file to be processed before the next primary record.
\

The processing of more than one input type file, with or
without match fields, is termed multifile processing. Selection of records from more than one file based on the contents of match fields is known as multifile processing by
matching records.
Multifile processing is commonly used in applications where
data files are set up to contain only a certain type of information. For example, a master payroll file might contain
data which does not change often, such as an employee's
pay rate. Another payroll file, which would consist of new
records every week, might contain data such as the number
of hours an employee worked in the week. To produce a
paycheck or other report, information from both files
must be used. Furthermore, the records from the two files
must be processed in a particular order. Matching records
can be used both to determine which record to process on
each program cycle and to sequence check the records within each file.

6-2

Note to Disk Programmers: For ease of depicting input records and files, card-like records are shown in illustrations
throughout this chapter. This does not imply that the processing must be done using card files. The files can be read
from any System/3 device that can be used as an input de"
vice. Also, throughout the chapter, two input-type .files
are used in examples to illustrate RPG II logic for matching
records. RPG II logic and the rules for record selection do
not change when more than two files are used. See the
RPG II reference manual for your system for examples
using more than two files.

CHECKING SEQUENCE OF RECORDS WITHIN A FILE

File Containing Only One Record Type
As you know, an A or D entry made in column 18 of a file
description specification indicates that the records in the
file described are to be in sequence. If you specify that the
file EMPLOYEE is to be in ascending (A) sequence, which
employee records in Figure 6-1 are in the correct order?
Actually all three arrangements show the file in ascending
order: the first is sequenced by department number, the
second by name, and the third group by employee number.
As you can see then, before the program can check the sequence of records in a file, you must specify the field or
fields which are to determine the order. The fields on which
the sequence is to be checked (called match fields) are identified on the Input sheet by coding one of the entries M1M9 in columns 61-62 (see Figure 6-2).
Records within a file r:nay be sequenced on the basis of one
or more data fields. Up to nine fields may be used by assigning one of the entries M1-M9 to each match field. Entering
M1 on the same line as you describe the DEPT field (Figure
6-2) causes the records to be sequence checked according to
department number. Thus, this file should be in ascending
order as shown in the first group of Figure 6-1.
When you specify more than one match field to check sequence, the program considers all the match fields to be one
continuous field, even though the fields may not be adjacent
in a record .. For this reason, all match fields assigned to a
particular record type are considered to have the same type
of data (alphameric or numeric). The individual fields are
checked in order according to the level of the match field
entry assigned to the field. M1 is the lowest level; M9 is
considered the most important.

'\
)

(425 /

3186

AKREJA

!

03

2043

THOMASSE

DAHM PA

029
037

"

I

NELSON KR

4061

NELSON KR I

I

3672

02

017

I

I

361 "

218

2043

THOMASSE I

03

037

I

L372 .' "
/

05

4061

03

051

03
02

3672
3186

05

051
017

029

1-

11-

I
DEPARTMENT
NUMBER

EMPLOYEE
NAME

I

NELSON KR

051

I

)

DAHM PA
I

017

I

05

I

AKRE JA

029

I

03

THOMAS SE

037

J
EMPLOYEE
NUMBER

Figure 6-1. Sequenced Files

Match Fields And Multifile Processing

6-3

IBM

Intf!rnallonal Business

RPG

M~lne Corporation

INPUT SPECIFICATIONS

GX21·9094 u/M 050'
Printed in U.S.A.

1 2

Program
Page
Date

Programmer

I
-

Record Identification Codes

5

~
;'

Filen.ame

Line

~
l-

6

j ~

E

~
5

~

-1--5
o R Z

r;:'No
1

8

Field Location
3

2

1

g

€.~

~
'2

Position

!

t

~~~
~

Position

_

!l

=~ ~
~u6

U6

~~§
~~
~u ~l~

From

To

Field Name

g 52-0°

.g

i:~

!

~~

]

E

1

~

Field
Indicators

~

a:
"E
."

~6 u:

Zero
Plus Minus or
Blank

"ii

9 10 11 12 13 14 15 16 11 18 1920 21 22 23 24 25 26 21 28 29 JO 31 3233 34 35 36 31 38 3940 4142 43 44 45 46 41 48 49 50 51 52 53 54 55 56 51 68 5960 61 62 6364 6566 6166 69 10 11 72 13 14

3

4

0

1

lle:: MPI-

0

2

I

0

3

I

II

.... fYS

tal

0 4

I

0 5

I

1
5
16
22

0'16

I

26

7

I

0

:~
~

ti

Position

75 76 77 7B 79 80

[D0f_ :~;~f~cati~ I I I I I I I

~E. ~IT

.~

~.L

13 ~A ME
19 ~~ U~ BEIR
2.~ 'f II II'< II

Figure 6-2. Assigning a Match Field for Sequence Checking

The input specifications shown in Figure 6-3 show that
three fields on an EMPLOYEE record are to be used for
sequence checking. Since all records in a particular region
are to be together, the REGION field is assigned the highest (M3) match field entry and, thus, is checked first ..
DSTRCT is the next match field (M2), and DEPT is the
last (M 1).

RPG

IBM

Figure 6-4 shows three records from the EMPLOYEE file.
The three match fields shown would be considered one
field. If the file is specified to be in ascending order (on
the'File Description sheet), the records are in order since
03037372 is lower than 03051218, which is lower than
05029425. However, if the file is to be in descending sequence, record 1 and record 3 must be switched.

GX21·9094 UIM 050'
Printed in U.S.A.

INPUT SPECIFICATIONS

Internallonal Business Machine Corporation

1 2

Program

Page

lIate

Programmer

Record Identification Codes

I

-

75 76 77 7B 79 BO

[0 of_ :~;~f:alion I I I I I I I

Field Location

g :!2-a
0

0

Filename

Line
0-

>

Position

I-

~
3

4

5

6

o

2

I

o

3

I

o
o
o

4

I

5

I

6

I

o

7

I

g
Z

1

8

t

tl
t'?

§tl

Position

t

§:e

~~

B
6

Position

ge
~ ~

t'?

tl

~

g

From

To

~ ii:

."~

Field Name

~
·il

]

~

.!!"ii
u..u::

Ii

Field
Indicators

~
"E

!

~

Zero
Plus Minus or
Blank

8 ::.u u:

c

9 10 11 12 13 14 15 16 11 18 19 20 21 22 23 24 25 26 21 28 29 30 31 32 33 34 35 36 31 38 39 40 41 42 43 44 45 46 41 48 49 50 51 52 53 54 55 56 51 58 59 60 61 62 63 64 65 66 61 66 69 10 11 12 13 14

Figure 6-3. Assigning More than One Match Field for Sequence Checking

6-4

~

E
;;; a:

5

.~

L
J 1l"lt7lIAII IlI..o~rr:

,""".'1'1'

I....

'-

~8 tl~IT Relr

/

425

\

3186

AKREJA

05

029

)

../
M3

218

372

I

4061

NELSON KR

THOMAS SE

2043

I

03

051

03 I 037

-

Record 3

-----+-

M2
I

Record 2

•

Record 1

I

05 : 0291 425
I

•

M1

I

-----+-

218

REGION

)

DSTRCT

I

·1

I

I
DEPT

DEPT
(M1)

Region
(M3)

DSTRCT
(M2)

Figure 6-4. Match Fields Checked According to Level Assigned

Processing halts when the first record out of sequence is
read. You can then correct the order of the records to continue processing. Note, however, that only an error in the
direction of the sequence is detected. When sequence checking a file with"match fields, RPG II does not cause the processing to stop when a duplicate match field is read. This
can be accomplished, however, by coding the sequence check
using calculation specifications.

In the last example, all records in the EMPLOYEE file were
the same record type; that is, they contained the same type
of information in the same location on each record. Therefore, a particular match field could always be found in certain positions for every record in the file.

Match Fields And Multifile Processing

6-5

the other employee records. Two different record types
are necessary because salesmen receive a percent commission on sales, while other employees receive a set weekly
salary. Although commission and salary fields appear on
only certain records, all EMPLOYEE records contain an
employee number, department, and district, as shown in
Figure 6-5. However, these common fields appear in different locations on different record types.

File Containing More than One Record Type
When some or all of the fields on a record are in different
positions than the fields on other records in the same file,
you have different record types. Suppose your EMPLOYEE
file is made up of two different record types, one type for
salesmen and one type for all other employees. An S in
position 96 identifies records of salesmen; an 0 identifies

IBM

International

RPG

B~'ineSl Machine Corporation

GX21-9094

INPUT SPECIFICATIONS
1 2

Program
Page
Date

Programmer

~

I

Filename

Line
0.

>

~
6

~

j ~

1l
r--,....g
o R Z

t-

5

Record Identification Codes

~

r---

fj;;N"'D

3

4

o
o

1

IE:MIFLCY~~AA

2

I

o

3

I

o

4

I

o
o

5

I

o

7

o

8

o

9

7

8

1

2

[I]
'"....
....

0

-"-;;;
~

0

Position

Position

Position

75 76 17 78 79
of_

~~:~f:aljOn I

From

To

1

Field Name

]

~

g

0

.3

.~

c:

0

:9-0
.9:!iii

LLi.L
.~ g'

~]

::;;:u

eo

IIIIII

Field
Indicators

Field Location
3

~.~

~

U1M 050'

Pflnledln U.S.A.

°
~
"C

j

Zero

Plus Minus or
81ank

"C

Q;

u::

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 21 28 29 30 31 32 33 34 35 36 31 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 51 58 59 60 61 62 63 64 65 66 61 68 69 10 11 72 13 14

916

~S
Il""

1

lQ

I"

1M

7
12
116

,

"'

6

\

'\

1 0

I~

11

I

1 2

I

1 3

I

1 4

I

1 5

I

1 6

I

1 7

I

1 8

I

1 9

I

2 0

I

96

C~

1

11

~

Il)!EiPi7

v

11 &j121~IALA RY
121 bSiTRCT

I

v
I

Record for Other Employee

135
1

Z

J,. ,

!~ .. ~~~".~?n··· . •• .. ··,,···· ..11···,,··· .. · . ·,,··~
Record for Salesman

Figure 6-5. File Containing Two Record Types

6-6

Since there are two different record types, a particular
match field may not always be in the same record positions.
For instance, DSTRCT is in positions 15-16 on salesmen
records, and in positions 20-21 on records for other employees. You must tell the program where to locate the
match fields for each record type (Figure 6-7). Once the
program determines the record type by checking the code
in position 96, it then looks at the appropriate match field
positions for that record type.

For this particular program, you want a list of all employees, in ascending sequence according to district. Furthermore, the records within a district are to be in sequence
according to department and employee numbers. To ensure
the sequence of the file, three fields on each record must be
checked, as shown in Figure 6-6. DISTRCT is the most important category and, therefore, is assigned the highest
match field entry.
M1

M2

M3

Record Type "0" for Other Employee

293
I Z

387

07564

04

3'SI7.t~"~~W~~W~~w~uu~nHVHH~~n

M3

M2

M1

Record Type"S" for Salesman

~~~--:--c/

-------'7

135
,

2

3

15
..

5

•

7

07

425
8

•

10 It

12 13 14 IS 16 17 18 It 20 21 U

23 21 25 21 27 21 29 30 31 32

Figure 6-6. Match Fields in Different Locations on Two Records

GX21-9094 U/MOSO"
Printed in U.S.A.

INPUT SPECIFICATIONS

RPG

IBM

International BU5ine$S Machine Corporation

I
I

Program

Date

Programmer

Graphic

Instruction

Punch

I
I

I I Card Electro Number
I I

I
I

Record Identification Codes

s

I

Punching

2

1

3

\

~

c.

Filename

line
0-

~
3

4

5

6

! f's

"O'R"A'No
7

8

~§
~.g ~
:l

Z

0-

0

Position

il

a:

~
~ ~~
z u u
Z

0

Position

-

~

~e ~

15.t:!

~

zuu

0

~
-.;

Z

c1l

~

Position

2

75 76 77 78 79 80

:::~':ation I

~o

~§

~~ ~

-in

From

~

To

Field Name

]

~
"g

~l~

]

.3

0

IIIIII

Field
Indicators

Field Location

~

]

I---

1

Page [ ] ] o , _

0
0

:2-0
.!!:!Qi

u..U:
.s~

-£ :s
~~
:2:u

~
"E

Zero
Plus Minus or

~

Blank

-0

-.;

u:

9 10 11 12 13 14 15 16 17 18 1920 21 22 23 24 25 26 27 28 29 30 31 3233 34 35 36 37 38 39 40 4142 434445464 7 48 49 SO 51 52 53 54 55 56 57 58 5960 61 62 6364 6566 6768 6970 71 72 73 74

0 1

IF iMP

o

2

I

o

3

I

o

4

I

o
o

5

I

6

I

o

7

I

o

8

I

o

9

I

1 0

I

""y F"F:. ~A

rAl

g{,

rs

1

~~

A~

(/)2

96
1

rt,...,

lJ.I5

""

i~

71

00C

2

M

Ml

fYlM

1~ CE. 'PiT
1'6 r.,.;i~ It<
s:l

L

1'"/1, f"I

DE PT
"'f\1 1-'1\1 I

M2
I

M3

M

"11

2_" ilL

21

!I~

/=--

f..12. )

~RY
I~ 1

l~

,

Salesman
record

~~

,

Other employee
record
I

I

I

I

I

Figure 6-7. Assigni"ng Match Fields to Different Record Types
Match Fields And Multifile Processing

6-7

Fields from different record types which have been assigned
the same match value may have the same name. As shown
in Figure 6-7, M2 has been assigned both to the DEPT field
on salesman records and to the DEPT field on other employee records.

Match Fields the Same for All Record Types
Often, however, you may find that although there are different record types in a file, many of the fields are the same
on all record types. That is, many fields have the same
name, contain the same type of data, and are always found
in particular positions of any record type in the file. For
example, salesmen records and other employee records
might be organized as shown in Figure 6-8. For both record types, all fields are the same except the COMM and
SALARY fields and the record identifying code in position
96.

If, match fields are assigned to more than one record type in
a 'program, all of the records (with match fields) must be
assigned the same number of match fields. Furthermore, all
match fields (on different record types) which are given the
same value (M 1-M9) must be the same length. Thus, all M 1
fields must be the same length, all M2 fields must be the same
length, and so on. This, of course, means that the total
length of the match fields must be the same for each of the
records.

When only a few fields differ, record types can be described
on the Input sheet in an OR relationship. Instead of using
separate sets of input specifications, common fields need
to be described only once. As shown in Figure 6-9, entries
under Field Record Relation (columns 63-64) can then
identify the fields which are unique to a particular record
type. Notice that fields which are the same for all record
types are described first. All fields related to a particular
record type are then described before specifying the fields
related to one of the other record types.

In this example, the EMPLOYEE file contains only two
types of records and both are assigned match field entries.
However, match fields need not be specified for all record
types in a file. Record types which do not contain match
fields are processed in the order they are read. The sequence
check, then applies only to the record types to which
match field entries have been assigned.

DSTRCT, DEPT, and EMPNUM arethe three match fields
to be used in sequence checking the EMPLOYEE file.

USING MATCH FIELDS WITH FIELD-RECORD
RELATION FOR MORE THAN ONE RECORD TYPE
IN A FILE

Since they are described only once on the Input sheet without any field record relation entries, the match field entries
also need be assigned only once (Figure 6-9). When record
types are described in an OR relationship and a match field
entry is assigned to a field without any field record relation
entry, the match field will be used for all record types.

In the last example, each of the record types in the EMPLQYEE file is described with a separate set of input specifications. Since all of the fields to be used for matching are
in different columns on the different record types, the same
match field entries are assigned once for each record type.

DEPT
(1-3)

DSTRCT
(8-9)

COMM
(14-15)

EMPNUM
(25-27)

425

07

15

135

Salesman Record

IS)

I 2 1 .. 5 • 7 • , 10 11 12 13 ,4 15 16 17 ,. 19 2021 U lJ 21 25 Z6 27 28 29 30 )1-32
~_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _- - J

DEPT
(1-3)

DSTRCT
(8-9)

SALARY
(13-17)

~

I • ., . . I'

eo .' .s . . .0

.. t2 IJ . . . . . . t7 .. (

EMPNUM
(25-27)
Other EmployeR Record

}

~ ?~.

. . 9~
7

10 11

"

~ ?~ ~ ~

II 19 '0 "

22 . , 24 25

a.

27 . . 29 '0

"JZ ( .. ., ...... B7

. . . . .0 . . . . . , . . . .

?

t7 ..

j

Figure 6-8. Same Match Fields for Both Record Types

6-8

Page of GN21-7567-2
Issued 24 May 1976
By TNL: GN21-5389

RPG

IBM

)

GX21-9094-2 U/M 050'
Printed in U.S.A.

INPUT SPECIFICATIONS

International Busine$$ Machine Corporation

1 2

Program

Page
Date

Programmer

]

!~

Filename

Line
0.

~

>

I-

~
3

Record Identification Codes

~

I

~

4

5

6

.8

-~-5
o R
Z

"Ar-;;-o
7

go.

r~

0

Position

1!

~

-

~o ~

Z

:;;

i

Position

_.<:

U U

il

-~ e ~~

Position

~flc5

Field
Indicators

Field Location
3

2

1

75 76 77 78 79 80

[]]Of_ ~~;~f:ation I I I I I I I

~~
~u

~~~

'in

From

.e

To

Field Name

~
"2

~~~

~

]
e
~

0

0
0

~{3

.!!"ii

u..u:::

~

."

f:f £j .
~c5

."

Zero
Plus Minus or
Blank

9 10 11 12 13 1415 16 17 18 19 20 21 22 23 24 25 26 27 28 29 JO 31 32 JJ J4 35 J6 37 J8 3940 41 42 4J 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 5960 61 62 6364 6566 6768 69 70 71 72 73 74

8

MP La VE EAA
vR

(tJll

qc> Clc:

~2

'1~

0 1

IE

o

2

I

0 3

I

1

o
o
o

4

I

8

5

I

12.5

6

I

o

7

I

o

8

I

CIC

3 DE PT

q

os rrR CIT

2.7 EPo( PN UIM
15 2.C OMM
17 25 AL ARIV

lllJ

u.~

~2.

M3
1M!

leJl

I2Jll

Figure 6-9. Assigning Match Fields Once for Two Record Types

Match Fields Differ Between Record Types

)

In the last example, although some fields differed between
record types, all the fields to be used in matching were the
same (same name, format, and record positions). Suppose,
however, that one of the match fields, DEPT, is in different
record positions for each record type. The two record types
in the EMPLOYEE file are shown in Figure 6-10.

EMPNUM
(1-~)

SALESMAN RECORD
DSTRCT
(20·21)

15

SALARY
(10-14)

I

---5~,
387 293

~

2

J

..

S

,

7

07564
•

OTHER EMPLOYEE RECORD

____

DE;lT

I

07

425

EMPNUM
(1-3)

•

10 11

Il 13 .. 15 t6 17

(Record Identifying Indicator 01
turns on when this record type is read.)

DSTRCT

(Record Identifying Indicator 02

(_2_0~r._1_)_ _ _ _ _ _ _ turns on when this record type is read.)

t. t. 04

ZO 21 U U 2" Z5 21 Z7 ZI ZI 30 )1 32

o

U &l .... 15 II '7 . . II to II t2 13 . . IS H

t7 II

Figure 6-10. Match Fields Differ Between Record Types

Match Fields And Multifile Processing

6-9

(positions 12-14) on whichever record type was read. Of
course, the M2 match field is not in positions 12-14 on
either record type so you don't want this incorrect data to
be used in sequence checking. It won't be, because all of
the match field entries are checked before the sequence
checking is performed. If the record read is record type 01,
line 07 is performed. This entry tells the program that the
data in positions 10-12 should be used for the M2 field. On
the other hand, if record type 02 is read, line 08 is performed and the data in positions 5-7 is used instead of that
in positions 12-14. Actually, then, when either of the specifications in lines 07 or 08 is performed (depending onrecord type), the data used as the match field is changed, as if
the dummy entry had never been specified.

According to what you have learned so far, you might assign match field entries as shown in Figure 6-11.
However, the specifications shown in Figure 6-11 will not
work. There is an additional rule to remember in assigning
match field entries when field-record relation is used and
the match fields differ between record types. If one (or
more) of the match fields in either file is assigned without
a field-record relation, the rest of the match fields must be
assigned in the same way, without entries in columns 63-64.
Of course, the specifications which assign some of these
match fields with field-record relation are still necessary.
Notice in Figure 6-11 that two of the match fields (M 1 and
M3) are associated with all record types (without fieldrecord relation entries). Therefore, an additional entry
(dummy entry) should be made (see line 05 of Figure 6-12)
to assign the M2 match field (DEPT) to all record types also.

Although the specifications in Figure 6-12 will cause the
EMPLOYEE file to be sequence checked correctly, there is
a way to reduce the number of specifications required. As
mentioned, for a dummy entry you can specify any record·
positions which give the correct length for the match field.
However, if you specify the actual positions associated with
that match field on one of the record types, there is no
need for the specification which relates those positions to
the match field for that record type (Figure 6-13). Thus,
by entering 10 to 12 (line 05, Figure 6-13) as the positions
for the M2 field, you can eliminate the match field entry
(line 07) in which the M2 field is described for record type
01.

Actually the M2 match field isn't the same for all record .
types, since the location of the field varies. Therefore, how
do you know which entries to make in the Field Location
columns of this dummy match field entry? You know that
anyone match field is always the same length, regardless of
record type or location in the record.· In this case, DEPT is
three positions long. Any numbers which give the correct
length of the match field can be specified as Field Location.
As shown in Figure 6-12, positions 12-14 are specified for
the dummy match field. When this specification line is performed, the program looks at the three positions of data

International Business Machine Corporation

I
I

Program

I

Date

Programmer

I
r----

~
Filename

-!
5

6

i

R

'A"N'D

7

8

9

. Graphic

Instruction

Punch

I I
I I

T
T

T
T

2

1

Field Location
3

Ol

..J

j'l;

~
z

..J

0

Position

"E

Z

C

t;

E
~i
z u u

~

Position

- $2 ~
~

~

~~6

~

Position

~~

·in

i~ ~

75 76 77 78 79 80

Page [ O O f _

From

Field Name

]
e

Q.

To

~

.~

~u OUiIi:;

!

0

l;

12-t;
.!!'i)
u..u:

:~:~f:ation I
c

IIIIII

Field
Indicators

0

~

]
I:r
"
~6 u:

Zero
Plus Minus or
81ank

Q;

10 11 12 13 1415 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 J4 35 36 37 38 39 40 41 42 43 44 45 46 47 4849505 1 52 53 54 55 56 57 58 5960 61 62 6364 6566 6768 69 70 71 72 73 14

~1
~2

CS
96 ,.,,...

0

1

IF ~'P IL"" Y£ £AA

o

2

I

o

3

I

o
o
o

4

I

2<2

5

I

~

6

I

1rJ

o

7

I

o

8

I

o

9

I

tJR

1.j6

~I..I

Figure 6-11. Incorrect Match Field Entries for Records Described with

6-10

1 2

Card Electro Number

C.

,..--,..-1
o

~

4

~

Punching

Record Identification Codes

H

Line

3

GX21·9094 U/M 050'
Printed in U.S.A.

INPUT SPECIFICATIONS

RPG

IBM
I

1

5

1~

Fi~ld

r:: ...

~

.,

12

~.

1

lL

I

M

«c.;r
MI\I,

JE .... r

?

DE

1'"1 t. .... M

Record Relation

T
!J!:lly

,

!\

'1111

~''i

1J.1

aL

~2
~2 QZ \
~2 )

These
specifications
are incorrect.

J
I

Date

Programmer

8-

~

E

5

6

~
1i

r;"Nro

7

8

Punch

I
I
3

~

0

)~

~
0;
\;

Position

~~~

]

-

Position

~

e

Position

~

~ N

~o

~

'"

:!tuo

u6

~

$

2

75 76 77 78 79 80

~~::~f~ation I

Page [OOf __

-0;

~~ ~

From

~

To

Field Name

0;

.3

~

§ ~1~

j

~

IIIIII

Field
Indicators

Field Location

2

1

1

I .1 Card Electro Number
I I

I
I

'>'.

r--r-5
o R Z

.f

Graphic

Instruction

go.

i
~

Filename

Line

Punching

Record Identification Codes

s
11
]

I

f--

4

UIM 050·

Pnnted in U.S.A.

Intern.tion.1 BUliness Machin. Corporation

Program

3

GX21-9094

INPUT SPECIFICATIONS

RPG

IBM

·2

~

°
:B-t;
u.u:

.!!:!'i)

"E

.~~

~

~~

0;

-5

:~

Zero

Plus Minu$ or
Blank

-0

u:

::;;u

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 3233 34 35 36 37 38 39 40 41 42 434445464 74849505 152 53 54 55 56 57 58 5960 61 62 6364 6566 67 68 69 70 71 72 73 74
,.,.1 .. AA

o

1

I~ Mt.iL

o

2

I

o
o
o
o

3

I

C2llL

T'/;. ~H~

OR

(/J~

96
96

cs

I Dummy entry so that

1'I'r
~~

1

4

I

2~

5

I

1

6

I

o

7

I

o

8

I

o

9

I

Performing either of these
specifications actually voids
what has been done as a result
of performing the dummy entry.

-

I

I I

I I I

I I

I

I

I

I I I I

~1

It

I I I

~IJ'-'l

~

2'.1

~I

~1

MI~ ~

'kIV'/

~
~~ 'J.

71Z .... 1'-1 M'1"i

12 CE- PIT
r'E

. .:r

frJI2 ~

~:::; AL ~IB:"

1

all match fields are
assigned without
field-record relation.

fvil2~

IE~IT

1.
7

1

1-''fV ~M

~

Figure 6-12. Assigning Match Fields for Records Described With Field Record Relation

RPG

IBM

GX21-9094

INPUT SPECIFICATIONS
1

Program

)

Page

Date

Programmer

-I
Line

4

I!
5 16

I~I§

Filename

01 2

II

,01 3

II

014

II

015

II

16

II

,017

II

o Is

II

01 9

II
I~

ro Nioiill
IA

~

Position

Ar-

7

8

il=IM"

011

io

2

75 76 77 78 79 80

[0 of_ ::~;cation I I I I I I I
Field
Indicators

Field Location
2

1

!i
3

UIM 050·

Printed in U.S.A.

Internationel Business Machine Corporation

9 10 11 12 13

h

,'"' ,..

,.It- AlA

OR

~I§ J

Position

20 [21 22 23 24 25 126 27 28 29 30

~~

(Z2

3

II
I~I§

Position

'ii~

dl~

From

If
To

CO

:3

2

F igure 6-13. Eliminating Specifications in Assigning Match Field Entries

Plus Minus

I~l

CiA., 'fll.

~7

'/ IJ.

'1<.:" T

I~:'o
ISlank

44454647 48 49 50 51 152153 54 55 56 57 58 159 60 61 62 :63

36 37 38

I I I I I I I I I I I I I

f,

il

~16 ~S
~~

This entry eliminated
since the dummy entry
specifies the match field
is in positions 10-12.

j

Field Name

64

~66 6~ 68 169 70 171 72 73 74

~

~I~

--

H- f-

I-t- r-

In:1

I

"

I I I I

rtI.<'

I I I I

~

"'\1U1,

I

Dummy entry so that all match
fields are assigned without fieldrecord relation.

J
Match Fields And Multifile Processing

6-11

After performing the dummy entry (line 05), the program
knows the M2 match field is to be found in positions 10-12.
If record type 01 is read, the M2 field actually is in positions 10-12. Thus, line 07 doesn't have to be performed,
since it does not change anything. Of course, if record type
02 is read, the specification in line 08 is performed. This
says, for record type 02, use positions 5-7 for the M2 field
instead of positions 10-12.
The field name specified for the dummy entry can be any
name, since field names are ignored in selecting match
fields. I n this case, DEPT was specified since it happens
that the M2 fields on both record types have the same
name. If the names to be used differ, it is still a good practice to use a name given to the match field on one of the
record types.

MATCHING RECORDS: ONE RECORD TYPE IN EACH
FILE
One of the most common forms of multifile processing involves using one file to obtain data from another file. Figure 6-14 shows a weekly sales report to be printed which is
used to determine which items are selling best at which
location. A SALES file contains records of individual items
sold, giving the quantity and location. The description of
each item, however, must be obtained from an ITEM master file. The ITEM master file consists of one ITEM record
for each item in stock.

For this program, let's assume that each file contains only
one record type. All ITEM records are in one format and are
identified by the character I in position 1. All records in
the SALES file are identified by an S in position 1 and are
also in one format (certain type of information in same
location on everyrecord). The SALES records for a particular item can be associated with the related ITEM master
record by a common match field containing the item number (see Figure 6-14).

Processing Order: More Than One Matching Record in a
Secondary File
In the ITEM master file, there is only one record for each
item, but in a program run there may be several SALES records for that particular item. Let us suppose there is always
at least one SALES record for each ITEM record. Therefore, there should be no records in either file which do not
have a matching record in the other file. Both files are specified with match fields in ascending sequence.
To produce the report in Figure 6-14, in what order should
records from the two files be processed? First an ITEM
master record should be processed; that is, the item number
and description printed. Then, all the SALES records which
are for the same item (match fields the same) should be
processed. The quantity and location of each sale should
be printed under description. Thus, after every ITEM record processed, one or more SALES records must be processed before the next record from the ITEM master file is
processed.
How does RPG II know when to stop printing SALES records and to process the next ITEM? As we said, the SALES
records for a particular item are read one at a time and
printed. When the match field on a SALES record is for a
different item, that SALES record is not processed immediately. Instead, the next ITEM master record is processed to
print the description for the new item. Then the SALES
records for that item are printed. As you can see, to determine the correct order of processing, both files must be in
the same sequence according to the match field; in this case,
in ascending sequence by item number.

(
\ ..
6-12

SALES File

)

ITEM File

--

038

WS

049

MN

157

062

M.N

043

QTY

NUM

PRIMARY FILE

LOCATN

SECONDARY FILE
Match Field Containing
Item Number

)
SALES REPORT
ITEM

DESCRIPTION

QUANTITY

LOCATION

101

43
62
157
117

MN
SD
SD

~

49
38
67

MN
WS
MN

-------------Data From
ITEM Records

Data From
SALES Records

Figure 6-14. Matching SALES Records with Related ITEM Records to Produce a Printed Report

)
Match Fields And Multifile Processing

6-13

How RPG /I Logic Determines From Which File to Process
a Record

Using the same example, let's see how the RPG II logic determines from which file a record is to be processed. The
ITEM master records are the primary file and the SALES
records are the secondary file. When two input files are
used in a program, the program cycle is slightly different for
the first record read. You can follow the logic flow shown in
Figure 6-15 as we discuss the first program cycle and subsequent cycles for this job. Pay special attention to when
the record identifying indicator is on, identifying the record to be processed, and when the MR indicator is turned
on and off.
At the beginning of the first program cycle (Figure 6-15,
part A), a record is read from each file. The first step is to
determine which record to process. The program determines if match fields are specified for both record types.
In this case, both the ITEM record and the SALES record
contain an M1 field. The match fields from each file are
then compared to see which is lower in sequence. (If the
file had been in descending sequence, the program would
check for the highest match field.) In this case, neither
field is lower as the match fields on the primary and secondary records are both 101. When match fields from the
two files are the same, the record from the primary file is
always selected for processing.
Now the appropriate record identifying indicator is turned
on to identify the type of record selected for processing.
Thus, 01 would be turned on for the ITEM record from the
primary file.
Once a record is selected for processing and the record
identifying indicator is turned on, the program determines
whether the MR indicator should be on during processing
of the record. Since the match fields are equal (both 101),
a matching record condition exists. The MR indicator is
not turned on yet, however, because the selected record is
not ready to be processed yet.
First, the program checks to see if any total operations are
to be performed for previously processed records. Total
calculations and total output are performed only if control
fields change or if the last record in the file has already been
processed (LR on). Since there are no control fields in
either file, control level indicators will never be turned on
during this program. Furthermore, this is not the last record.
Neither condition has occurred; therefore, total-time operations are bypassed.

6-14

At this point, the M R indicator is turned on to indicate that
the matching record conditon exists. Now the program is
ready to perform the detail operations for the record which
was selected for processing. Thus, the item number and
description from the primary file record are printed. The
program knows which operations are to be performed because the operations are either conditioned to be performed
only when record identifying indicator Q1'and the MR indicator are on or they are not conditioned by indicators.
Once the processing of this record is completed, the record
identifying indicator is turned off (01 off). This completes
the first program cycle; that is, one record has been processed.
For the processing of all subsequent records, look at the
program cycle in Figure 6-15, part B. The entire cycle will
be repeated for each record processed.
At the beginning of the first cycle, a record was read from
both the primary file and the secondary file. However,
since only one record is selected for processing at a time,
one record (in this case, a SALES record) still remains in
the input read area. Therefore, a record from only one file
is read at the beginning of the second cycle and for all following program cycles. The record read will be from the
same file as the last record processed. Thus, for the second
cycle, the second record from the ITEM file would be read
into the primary file read area.

(
\.

Now that a record from each file is in the read area again,
the second record can be selected for processing. Once
again the first step in the logic is to determine if match
fields are specified for the records from both files. In this
program, there is only one record type per file and both are
assigned match fields. Therefore, the answer to this question is yes for every program cycle of this program.
The match fields from both records are then compared. In
this case, the secondary file SALES record is for the first
item number (101). Since the ITEM record for the first
item (101) has already been processed, the primary file record in the read area is for the second item number (117).
The match field on the SALES record is lower in sequence
than the match field on the ITEM record; therefore, the
SALES record is selected to be processed. Once again, a
record identifying indicator (02 for a SALES record) is
turned on to identify the type of record selected.
At this point, the MR indicator is still on because the previous comparison (item 101) did give a match. The setting·
of MR has nothing to do with the record which was just
selected for processing. The indicator will not be set to reflect the current condition until just before the record
selected for processing (SALES record for item 101) is
processed.

(
'"

Primary file

Secondary file

\.

•
•

•

•

"

Read record
from each
file. Turn 0
LR if last

Turn off record
identifying indicator

•
Input Read Area
Are match fields specified
for both?
Yes, so compare match fields
to select record
Turn on record identifying •
indicator

Perform heading output
and detail output for
selected record

•
Determine whether MR will
be set on or off

)

•
•

Perform detail
calculations for
selected record

•

Change in control field?
Yes, turn on control •
level indicator

Turn MR on or off
for selected record

•

Perform
total output

•
®

Perform total
calculations

•
RPG II Logic for First Program Cycle

Figure 6-15 (Part 1 of 2). Logic of Matching Records

Match Fields And Multifile Processing

6-15

Primary file

Secondary file

START

•
•

~

•

•
"-

Turn off record
identifying indicator

r---'

• 117

•

Read record
from one of
files. Turn on
',j---..... LR if last

I

iL _
ITEM
_ _ JI
Input Read Area
Are match fields
specified for both?
Yes, so compare match
fields to select record
Turn on record identifying •
indicator

Perform heading output
and detail output for
selected record

•

Determine whether MR will
be set on or off

•
•

Change in control field?
Yes, turn on control •
level indicator

Perform detail
calculations for
selected record

•

Turn MR on or off
for selected record

•

Perform total
Perform
total output

•

®

RPG II Logic for Subsequent Program Cycles

Figure 6-15 (Part 2 of 2). Logic of Matching Records

6-16

•

Since the next record to be processed has been selected, the
RPG II pr0 ram now determines how the MR indicator is
to be set for processing this card. Is there a matching record condition? You are probably thinking that there is not,
because the match fields are not the same (secondary file,
101; primary file, 117). However, when the match fields
are not equal and a secondary file record has been selected,
the match field on the secondary file record (SALES) is then
compared with the match field of the last primary file record processed. The last ITEM record processed has a match
field of 101, the same as the match field of the SALES record to be processed. Therefore, there is another matching
record condition.

For the rest of the SALES records related to the first item
number (101), the comparison of match fields would indicate that the secondary file records are lower in sequence
than the item number (117) on the ITEM record of the primary file. Thus, all sales records for item 101 are processed.
Furthermore, the MR indicator will be on during processing
of all the records, since the match fields (101) will always
be the same as the match field on the last primary record
processed.

1

At the beginning of the next program cycle, a SALES record for the next item number (117) would be read. On
comparing the SALES record match field with the match
field on the ITEM record in the read area, there is a match
again. The ITEM for item 117 would then be processed before the SALES records for that same item.

The MR indicator is not set again and the record selected
(SALES 101) is not processed (detail operations not performed) until after any total operations to be done for previous records are completed. Since there are no control
fields and this is not the last record in the file, total operations can be skipped in this program cycle.

Specifications for a Matching Records Program

Figure 6-16 shows the three specification sheets - File Description, Input, and Output - to be used for this program.
Since the data from the two input files is only to be printed,
calculation specifications are not necessary.

At this point, immediately before processing the selected
record, the M R indicator is set. Although MR is alreadyon
for the previous record processed, it is set on again for the
processing of this record (SALES record for item 101). All
detail operations conditioned for record type 02 (or for both
02 and MR indicators on) are then performed. Thus, the
quantity and location fields on the SALES record are printed.

The File Description sheet defines the two input files to be
used in matching, as well as the printer file, on which the
report is to be printed. Notice that the two input files must
both be specified as being in the same sequence (A in column 18). The P and S entries in column 16 indicate to the
system whether an input type file is to be considered as a
primary or secondary file.

'\.
I

,)

After printing the SALES record, processing for this record
is complete and record identifying indicator 02 is turned off.
In the next program cycle, another SALES record is read
from the secondary file to replace the SALES record just
processed.

File Description Specification
File Type

F

Length of Key Field or
of Record Address Field

File Designation

f---

File Addition/Unordered

Mode of Processing

End of File

Record Address Type
Sequence

Filename

Type of File
Organization
or Additional Area

File Format
Line

oJ

Device

W-

Symbolic
Device

~
en

Z

1!

Extent Exit
for DAM
Name of
Label Exit

.:l

~

Number of Tracks
for Cylinder Overflow
Number of Extents
Tape
Rewind

Core Index

~
Condition

Overflow Indicator
Record
Length

~

:)
3

4

5 6

o

2F

03

F

o5

F

o6

F

o
o
o

7

F

B

F

9

F

1 0

F

7

8

9

N

;
0:
~ :::

a

U
~S

Key Field
Starting
Location

.~

:::l

K

W

Option

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 4041 4243444546 47 4B 49 50 51 52 53 54 55 56 57 58 59

1 £~

L£S

Ul·~

Continuation lines

~

IIF

~ ~

16

MFtrUl

I~

~

6

~iF~~2

Entry

"<

~

~

6061 62 63 64 65 66 67 68 69 7071 72 73 74

Both files in
I
ascending sequence',-t-lI-+-t-II-++-t-+-+-+-+-t-+-t-I-+-+-t-+-+-t-+-+-+-+-++-+-t-+-+-+-++-t-+-+-t-+-t-I-+-+-+-+-t-H

II
II

.......,,',

I Figure 6-16 (Part 1 of 2). Specifications for Matching Records Program
Match Fields And Multifile Processing

6-17

I

Program

IProgrammer

I

Oat.

~
Filename

Line

~
I-

6

~
=5

ell

.8~

~

R

....

7

8

°

ii

zc~
~ ~ j
2
U U

Position

20

Position

I;;

ge~
~

N

1

II IIEilv,

2

I

o

3

I
I

'AfJ

(/,).

,

Position

~~

..

~u

~oO

iii

From

6

IS
I

o

7

I

o

8

I

To

I
I I I
One record type in each file.

AL1£5

PE

~

~

2~

~6 2,..

~S

lL

I~

IJ

.,

~
"C

J
"C
0;

Zero
Plus Minus or
Blank

;;:

ML ... ,

'I"r/.J

",r C~

M'L---

r

r/,'1I,

LI6

LI&

I I I II

I I III

Match field
r"i' in each file
i.-"~ containing
item number.

I I

LI" A'A 17 N

GX21-9090

SPECI FICATIONS

OUTPUT

1

J .1

I I III

UIM OSO'

Printed in U.S.A.

International Business Machine Corporation

I

0

u:: Space

-:E

Filename

~

I-

~
5

6

Output Indicators

Skip

e~
0_
-""
;. ; e
8.~ ~~
~~
E
~ 0"0
~
o R
~

Jd
Ii;

~

~

2

1

0

0

2

2

'A~fo
7

8

'"
Field Name

75 76 77 78 79 80

in
Output
Record

~

Zero Balances
to Print
Ves
No
Ves
No

~

No Sign

CR

I

A
B
C
0

2

3
4

J
K

L
M

~~~;~!:ation 1
X

a

I. 1 1 1 1 1

Remove

Plus Sign
V = Date
Field Edit
Z = Zero
Suppress .

/"

Constant or Edit Word

Q:

9 10 11 12 13 14 15 16 17 16 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 60 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

~
C~

·~e.l16

lIP

2

0

o 3

0

o 4

0

o 5

0

o 6

0

v.Jlu~

o 7

0

Int-I .....

o 8

0

o 9

0

I 0

0

11

0

I

2

0

I 3

0

I 4

0

0

End

8

'AUTO

o

I 6

Ves
Ves
No
No

Positon

011< '~Il. rr

0

Commas

v

tii
~
Xl

o I

I 5

2

Page [ D O ! _

Date

Line

I

~6

,1lJ l I ~~~

I."

Programmer

4

-fi:s

~

Program

3

.£g'

~

1U.11.A.1

~

~I;o

tl2

RPG

-

0

~-s

~~

]
e

,f

~

/

4

5

~

Field Name

.;;;

CI

1
!Ii

o

Field
Indicators

c:
0

9 10 11 12 13 14 15 16 17 18 1920 21 22 23 24 25 26 27 28 29 30 31 3233 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 SO 51 52 53 54 55 56 57 58 5960 61 62 6364 6566 6768 69 70 71 72 73 74

o

o
o

75 76 77 78 79 80

I IIIIII

Program
Identification

Field Location

'+=0 0

~

2

Page [ D O ! _

3

A~D

o

IBM

Punch

1

I r~.s.le~o Number
I I

I
I

Graphic

2

1

§ 'g
-f-o
1

~
5

I

Punching
Instruction

Record Identification Codes

~

I
-

4

UIM05O'

Printed in U:S.A.

International Business Machine Corporation

1

3

GX21-9094

INPUT SPECI FICATIONS

RPG

IBM

J;lT

(J
In
~

h~

~17

~

L

~13

~'f< (/.1

~M

11 1E.1f'J
I~ I

IJ ~T

RI 'fJ11 1J.~ ~I
It: CA 1111 'C~

rf~ l5t:

T¥

I

)

a2

16

I~l

It< l-'

;2:
~ITrr
~IC I"',ll ITN

'HII.J
~~

ITEM

1

Report that

I will be printed,

f-L-',

1-1-

101

r
117

r

Printing data from ITEM record.

)

1
!

Printing data from SALES record.

)
DESCRIPTION

QUANTITY

----

-

-

LOCATION

II-

I43

·MN

I-

62
157

SO
SO

I-

49

MN
WS
MN

I 7

0

I 8

0

I 9

0

38

2 0

0

67

1:-

I-

-

I1-

Figure 6-16 (Part 2 of 2). Specifications for Matching Records Program
/'

6-18

File description specifications also associate each input file
with a particular device. On the MFCU, the primary file is
usually entered through the primary hopper (device entry
MFCU1); the secondary file is usually read from the secondary hopper (device entry MFCU2). However, in multifile processing using the MFCU, either file may be associated with either of the two hoppers.

As you recall in the discussion of matching record logic, the
01 record identifying indicator is on whenever an ITEM record is being processed. Furthermore, ITEM records are
processed only if a matching record condition exists (MR
on). Therefore, conditioning the printing of the item number and description by MR and 01 ensures that the information is coming from the ITEM record.

The contents of the two input files are described on the
Input sheet, with a separate set of specifications for each
file. Entries in columns 19-27 identify the two record types.
Record identifying indicator 01 will turn on if an ITEM record is selected for processing; indicator 02 will turn on if a
SALES record is selected. The single match field in each
file is specified by assigning the M1 entry in columns 61-62,
as you learned previously.

The quantity and location are to be printed only when a
SALES record is being processed. Because the MR indicator is on during the processing of both ITEM records and
SALES records, it isn't sufficient to condition this output
line only on the basis of MR. Therefore, the printing of
quantity and location is conditioned by both the M R indicator and the 02 record identifying indicator.

Lines 01-04 of the Output sheet specify that headings are
to be printed at the top of every page of the report.

In this case, calcu lation specifications are not required.
However, if calculations are required and are to be performed only if a matching (or not matching) record condition exists, calculations must also be conditioned by the
MR (or NMR) indicator.

)

Match Fields And Multifile Processing

6-19

Processing Order: More Than One Matching Record in the
Primary File

Matching Records: Records Which Have No Match in the
Other File

For the example just presented, there was more than one
record in the secondary file with the same match field.
That is, a single ITEM record was related to a number of
SALES records. In such a case, the order of processing was
the first primary file record, followed by its related secondary file records, then the next primary file record, followed by its related secondary file records, and so on.

In the multifile programs presented, there was at least one
SALES record for every ITEM master record. Therefore, all
records had a related record in the other file. Of course, in
multifile processing, it is possible to have primary file records with no related records in the secondary file, as well as
secondary file records with no related primary file records.
In either case, the record with no related record in the other
file is called an unmatched record. For instance, if only
certain items are sold, there would be an ITEM master record for every item and SALES records for only some of
those items. The ITEM records for which no sales were
made would be unmatched records.

,/

Let's take a look at another set of files, in which each record has a matching record in the other file. Figure 6-17,
part A, shows that there may be more than one primary file
record which matches the same secondary records. In what
order do you think these records would be processed? The
first primary file record processed would not necessarily be
followed by its related secondary file records. Instead, all
primary file records with the same match field AA would
be processed; then all secondary file records for AA (see
Figure 6-17, part B).
Actually, the RPG II logic used to determine the order in
which such files are processed is the same as that discussed
previously. Remember that whenever the match fields on
the two records in the read area are the same, the primary
file record is always selected for processing. Thus, during
the first program cycle, the first primary file record (AA)
is compared to the first secondary file record (AA). The
match fields are the same, so the first primary file record is
processed. Then the second primary file record (again AA)
is read and compared to the first secondary file record (AA),
still in the read area. Since there is a match again, this second primary file record is processed.

Unmatched records can be in either or both files, but they
are usually found in the primary file. In this example, it is
quite probable that for anyone item, no sales have taken
place. However, it is not as likely that sales have occurred
for an item for which there is no record in the ITEM master
file.

/'

(

\",

For both of the last two examples presented, every record
in the secondary file had at least one or more related records in the primary file. Since a matching record condition
always exists, the MR indicator was on during the processing of every record in both files.

I

I

6-20

/'

1sT

)

LKP

P

LST
P

More than one
/KP
primary file
/KN
record with
same match field; fAA
AA

f

,5

IKN

5

/ AA

P

f

5

/KN

P

/KP

5
5

P

5

fAA

P

5

'AA

I-

II-

I-

i-

-

-

I-

..

""

!-

I-

.
Primary File

®

Secondary File

FI LES BEFORE PROCESSING

1 ST

5

tT

P

5

/KP
P

/KP

(KP

)

P

5

/KN

(

'.

5

/KN

~ PI

KN

5
5

J

1-

-

-

SJdarv records with match field AA

P

AA

Primary records with same match fields
processed before the secondary records
with same match field

®

ORDER OF PROCESSING THE FILES

."'"
.__/

Figure 6-17. More than One Primary File Record with Same Match Field
Match Fields And Multifile Processing

6-21

Processing Order: Unmatched Records

Let's assumethat the two files for this program consisted of
the records shown in Figure 6-18, part A, with the primary
file containing two unmatched records. The RPG II logic related to matching records would determine the order in
which to process the records (Figure 6-18, part B). As explained earlier, first the ITEM master record for item 101 is '
processed, followed by all SAl:,ES records for item 101. Remember, if a record is selected l for processing during a program cycle, the next record from that same file is read at
the beginning of the next cycle. Therefore, when the first
SALES record for item 117 is read, another matching record condition exists. Thus, the primary file record (ITEM
record for item 117) is processed first. The next primary
file record for item 124 is then read to replace the ITEM
record processed. Since SALES records with match fields
of 117 are lower in sequence than 124, the two SALES
records for item 117 are processed. Furthermore, although
the match fields (117) on the SALES records are not the same
as that of the ITEM record in the read area (124), they are
the same as the match field of the last ITEM record processed. Therefore, the MR indicator is on when each SALES
record for 117 is processed.
When the next SALES record (item 239) is read, there still
isn't a match with the ITEM record for 124. The match
field on the ITEM record is lower than that on the SALES
record; therefore, the primary file record for item 124, an
unmatched record, is processed first (Figure 6-18, part B).
Since the files are in ascending sequence, this means that
there is no record in the secondary file with a match field
of 124. Therefore, MR will be turned off just before the
ITEM record for 124 is processed.

6-22

This program cycJe shows that even if there is no matching
record condition, the primary file may be selected for processing. This is because RPG II logic looks for the record
with the lowest match field, regardless of whether the
record is from the primary file or the secondary file.
Now the next primary file ITEM record (239) is read. Since
it matches the SALES record in the read .area, the primary
file record is automatically selected for processing. Although
a matching record condition exists for the ITEM record
selected, at this point the M R indicator is still off because of
the last record processed (unmatched ITEM record for 124).
The status of MR is not changed until right before detail
operations for the selected record are performed.
Following the ITEM record for 239, the SALES record for
item 239 is processed. Then, as before, the unmatched
ITEM record for item 286 is processed, since it is lower in
sequence than item 321 on the next SALES record. To
complete the processing, the primary file ITEM record for
item 321 is processed, followed by the two sales records for
item 321.
In summary, then, RPG II sets the M R indicator to off immediately before processing any unmatched records. M R is
turned on before processing a record that has a matching
record in the other file. After a record has been processed,
the indicator remains as it was until it is set again immediately before the next record is processed.
Regardless of the records in a file, there is an easy way to
determine if a matching record condition exists and if the
M R indicator will be turned on:
1.

When a primary file record is selected for processing,
MR will be turned on if there is a secondary file record in the read area with the same match field.

2.

When a secondary file record is selected for processing, MR w'ill be turned on if the last primary file record processed had the same match field.

(5

)
/1 321
P

/1 239

P

/1 124

I 101

r- ...

101

-

'-

5
-'239

I

iJ]117

Item
Number

1-

-

1

101

ITEM Master File

SALES File

,(Primary File)

(Secondary File)

@

)

/S
/5

FILES BEFORE PROCESSING

5

321
321

/1321
/1286

LS

239

S

5

117

LS

1-

5

117

1-

P

LI117

/5
/5

1-

5

101

1-

5

101

5

101

i-

P

I 101

Unmatched
record

Unmatched
record

P

124

/5
/5

/1

P

{I 239

LI

i - lJ321

5

101

/5
5

l-

Item
Number

5

101

/5
r--i'U nmatched
re cord

P

\

5

-117

Record

P

LI 117

5

117

(5

r--r-----. Unmatched

5

239

LS

P

p

5

321

(5
/1-286

5

321

/5

'-

1-

,II-

I-

,-

®

1-

PROCESSING

ORDER

OF

FILES

Figure 6-18. Processing Files with Unmatched Records
Match Fields And Multifile Processing

6-23

St"acker Selectionof Unmatched Card Records

When records from two files are assigned match fields, a
record from one file may be processed, then a record from
the other file, and then a record from the first file again.
However, regardless of the order in which the records are
processed, all cards which enter through the primary hopper 'of the MFCU or MFCM are automatically stacked in
stacker 1. All cards entering through the secondary hopper
end up in stacker 4 (stacker 5 on the MFCM Model A 1).
If there are unmatched records in either file, you can separatesuch cards from the others in that file by stacker
selecting the unmatched cards into a different stacker. As
you .Iearned in the chapter Card Output Operations, cards
from an input file can be selected into a different stacker
by entering the number of the stacker on the Input sheet.
However, this can be done only when input cards are to be
stacker selected on the basis of record type.
Stacker selection of a card becaus~ it has no matching record inthe related file must be specified in column 16 of the
Output sheet (Figure 6-19, part A). However, an input file
cannot be specified on the Output sheet. Therefore, the
input file containing the card to be stacker selected (the
card with no related record) must be defined as a combined
file on the File Description sheet (Figure 6-19, part B). The
combined file name can then be used on the Output sheet
for stacker selection.
Notice on the Output sheet that stacker selection is specified for the combined file ITEM (line 11), since only the
ITEM file' contains unmatched records. The filename indicates fromwhichfile the cards will be output. Since a
matching record condition cannot possibly exist for any unmatched records, MR must be off. Therefore, the stacker
selection of records is conditioned by NMR (off).

:;-24

Any record, conditioned for stacker selection by the MR
indicator, should be specified as a detail-time record (see,
Figure 6-19, part A, column 15). Otherwise, the next record to be processed would be stacker selected instead of the
record you want. This is because the detail-time processing;
of a card is done within one program cycle and the processed record automatically passes into the normal output
stacker, if not stacker selected. The total-time operations
for that same record are not performed until the next program cycle, after another record has been selected for proc-:
essing. During total-time operations, although the status of,
the MR indicator is still set f()r the previously processed re~­
ord, the only record'available to be stacker selected is the:
card just selected for processing.
Whenever you wish to have a certain type of output based
on a matching or not matching record condition, it can be
important that a record identifying indicator be used with
MR or NMR to condition the output. The record identifying indicator determines from which record type the information will be punched, stacker selected, or printed. For
the printer output file, output can come from either the
SALES file or the ITEM file (Figure 6-19, part A). Therefore, record identifying indicator 01 or 02 is specified to
indicate which record type is to be printed (lines 05 and
08). Record identifying indicator 01 is entered on line 11
in addition to NMR so that stacker selection will occur for
the ITEM file only when an ITEM record has been processed.

(

RPG

IBM

)

OUTPUT

GX2'·~

SPECIFICATIONS
1 2

75 76 77 78 79 80

Program

Programmer

0

!~I~

Filename

line,

]
4

5

6

pageDJo,_

Date

I---

; 3

U/M 050·

Printed in U.S.A.

Internalional BUSiness Machtne Corporation

l;

J'b I~I~
Il

7

8

9 10 II 12

Output Indicators

Skip,

iSpace

~~~

1

Jd

!OLD'

~I,'

Field Name

!~

ru

.~

In 33

20121

1~la6

34 35 36 37 38139 14041 42 43

10 12
10 13
10 ,4

0

!t1

5

0

IP 6

0

NUM

[0 [7

0

I-~

lio 18
lio 19

.0

[0

0

Ot

~R

0

~1

MIf<

iJ

1

IIili'lil·

0'"

1[1

ITt:.trI

0

'I 13

V

0

K

~

Ii
144

Zero Balances
to Print

Yes
Yes
No
No

Yes
No
Yes
No

-

No Sign

CR

1

A

J

2

B

3
4

0

K
L
M

C

X - Remove
Plus Sign
Y - Date
Field Edit
Z - Zero
Suppress

Constant or Edit Word
45 4647 48 49 50 51 52 ~J 546566 57 68 59 60 61 62 63 64 6566 67 68 69 70 71 72 73 74

r;;TY

hM11(

I~i

mtlli

0

~ ..... Stacker selected during

0

detail output time.

~o ~~ IT IN

~1

I[

rf;.fv

~

I~

UA NT rrl'r

LO IC~ 71~

II'(

I

'1-"11

I~rl
I

~
~Il

KIF

(Z~

r-iIR

C 11

0

'1 12

;;

217
Gl'l

0

r
V

End
Positon
in
Output
Record

Commas

I. 1 1 1 1 1

I~

OIK~

r-t

il!

'AUTO

[0 [I

k"[1

fA

~~::~'~Cltion I

~l':5

12

15t1

I
I
File Description Specification

)

File Type

F
-

Mode of Processing

File AdditionNnordered

Extent Exit
for DAM

Length of Key Field or
of Record Address Field

File Designation
End of File

Record Address Type
Sequence

Filename

Type of File
Organization
or Additional Area

File Format

Une

c

ee

!l
~

~~

E

.f
3

4

5 6

:::.'"
7

8

9

ITEN

o

2

Fll

3

F~ ~L ~S

4

F

5

F

6

F
F

8

F

9

F

1 0

F

(ID

F

Block
Lenglh

10 11 12 13 14 15 16 17 18 19 20 21 22 2

o
o
o
o
o
o
o

7

e:::E
w

5

i ::§ 1'5
~

-0

~]

Field Name

iii
Position

~@j

Position

_

~

.'!l

e

o~

z u u

~

Position

~

zuu

~~
~

u

Iii

0

From

To

4

1

II ITE~

o

2

I

o

3

I

~

o
o
o

4

I

;2"

6

IlS ~L
I

o

7

I

o

B

I

o

9

I

1 0

I
I
I

1 3

I

1 4

I

1 5

T

~

2'
-.;

j

~

.3

GX21-9094 UtM 050·
Printed In U.S.A .

75 76 77 78 79 80
of_

~~~~;~f:ation I

IIIIII

Field
Indicators

~

0

-;:;
0

~~

.~

"ii

u..~

.~ ~

-5 :s
~~

::~

lL ell
lN cV"

1 C~

Z.
It.

2

~Iq ~~

Match field assigned
~1 ~~I once for item file.

LJ~ I~UI'v1

2

II-S

I

11'0'

26 ~I~ ~I Clf

Charge records.
~~ I~~ Cash records.
r

lL ~~ [7 'l

12
lL

~~

eA IIfj

~II ITN IIt1
r/l£l ,., Nr.Jfv
~~

liT NUM

~1 i"'-r-_

Match field

~'l III I "

both record
types of sales
file.

11J1,2 V assigned for

II I II I I I

I

Figure 6-21. Describing Record Types and Assigning Match Fields for Two Files
Match Fields And Multifile Processing

6-27

Match Field
(shaded)

I

1/*
S 20964

I
!inli

/
so

008

WS

013
039
_'-CS

I
/

l

?~?:

295

S 23746!iull
S30896

SO

iU'i!!

csltti~

NO

076

MN

038
049

WS
MN

1- .

1-

7

043
JULY

1969

MN
1-

5

1-

1-

11-

Category records with
no match fields
assigned

1-

/*
1945

SALES records
(secondary file)

SMALL APPLIANCES
0174

:-~~~-----~=::::aI_r++-I..L.. Unmatched

0268

Record

LAWN GARDEN EQUIPMENT
0485
0093

AUTOMOTIVE SUPPLIES

ITEM records
. (primary file)

Figure 6-22. Files Containing Records Without Match Fields

6-28

Unmatched
Record

The two record types in the ITEM master file and the three
record types in the SALES file would be described asshown
in Figure 6-23. On the basis of the record id~ntifying codes,
one of the record identifying indicators which are assigned
to the record types (positions 19-20) will turn on to indicate
which record type was read.

Processing Records Which Do Not Have Match Fields

)

Up to now, all records in a file have been assigned match
fields to be used in matching records from ·one file with
those in the other file. Some files, however, may contain
some records which are not to be matched; thus, such record types would not contain match fields.

Notice tha~ the input specifications (Figure 6-23) assign a
match field to only some of the record types present in the
two files. The category records from the ITEM file and the
date record from the SALES file are not to be matched
with records from the other file.

As you recall, the ITEM file was organized in ascending sequence according to item number. Item numbers are assigned such that items can be grouped according to a gen- .
eral category. Allitems assigned numb~rs from 100-199
are automotive supplies, those from 200-299 are lawn and
garden equipment, 300-399 are small household appliances,
and so on. In addition to the ITEM records for each item,
then, the ITEM master file contains a record preceding each
group, identifying the general category to which the items
belong (Figure 6-22). These category records are distinguished by an * in position 1.

Since match fields are used to determine the order in which
records are processed, when will the category and date records be processed? Records for which no match fields are
specified are processed immediately as they are read. To
understand the order of processing and when the MR indicator is on, then, let's discuss how RPG II logic operates
during the program cycles for this program.

The SALES file also contains a record type which does not
have a match field. In addition to the two types of sales
records, one for cash sales and one for charge sales, there is
a DATE record at the beginning of the SALES file, identified by 5 in position 96 (see Figure 6-22) ..

IBM

)

,
,

Program
Programmer

Oat.

a

I
r--

~
&

~

-2-

~

. A

I

)

5

6

7

8

J

2

1

[00'_

Field

ga

l!

~

Z 0

0

:;;

~

Position

g

Z c

tl

Position

i§~

'"

~

~e~

~fJ6

4i

Position

~~
~

~~~

Field Name

.;;

From·

J:.
~

To

; t ::

3
"0

c

6

~
j

:9~

.!!"ii

.~g>
:~

il

~6 u::

9 10 11 12 13 14 15 16 17 18 1920 21 2223 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45· 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62

4

0

1

II TlE.rtt

o
o
o
o
o
o

2

I

2

3

I

~

l4A

rJ.ll

1

~I

12':

4

I

5

I

6

I

7

II~ AL IE~~

o

8

I

o

9

I

lL~

1 0

I

~1

11

I

1~

lAE

(2;2

1

1fJ.. ,.

~'~
~q.

liN r.

f1~
~

,.,~

~

n

f"4f"1

2-

l2

C~

l25

I

":iii

I

":iii

1 4

I

1 5

I

1 6

I

q{-j DJ:;

Zero
Plus Min'j' or
Blank

/

64 65 66

rh 68

~AIT6

,

Ill' with match fields.

II«I-

'''r ~I£

e

L'~

IJ.

~,

row ,

\

I

( Category:records.

RY

,

~I

'(

'L.iJ ~R II N
)..7 (1jI ITN (;(\1

7rtiA

f'HJf'.1

Me,.. rv ....1 ttl

1. IUr
'"

>

Mil
Qj3

5(2 IiI NUM
J~

69 70 71 72 73 74

I

\

1 2

~I=\

1",-

~3

I

Inl'"'l""i

~~ ~

CI~

1 3

~I'

I,...

I

Indicat~rs

I
Ml ~I'lte~ records

4'0 'Nu\N

~(1)

IIIIII

"C

u.L,L

-£

!

.~

u O~~

3

75 76 77 78 79 80

~~~~;~f~ation I

Field Location
3

a
II

i

2

1

Page

T1

1

';..

'S
Z
:: 0 ~

f - - §.~

~o

1

Punch

I I Card Electro Number

I

~.

II

Filename

Instruction

Record Identification Codes

.~

Lin.

I

Graphic

Punching

GX21·9094 U/M 050'
Printedh, U.S.A.

INPUT SPECIFICATIONS

RPG
Int,rn.tion,1 BUlin", Machine Corpor.tion

l

~- f-f-

Cash and
charge
sales records
with match
fields.

(\1L 2l)l 1 I
I:

>'

I

Date record.

Mf'\.

I

I

Figure 6-23. Describing Records With and Without Match Fields Assigned

Match Fields An.d Multifile Processing

6-29

At the beginning of the first program cycle, the first record
is read from each file. RPG II then decides i't match fields
are specified for both records. Asmentioned, a record for
which no match fields are assigned is automatically 'selected
for processing before the record in the other fil~.
In this case, neither record in the read area has match fields.
Therefore, which should be processed? Without match
fields, the two records cannot be compared 'to see which is
lower in sequence. When both records do not have match
fields, the record from the primary file has priority and,
thus, is selected for processing.
Since match fields are not assigned to this record typeithere
can be no matching record in the other file. Therefore, immediately before a record without m'atch fields is process'ed,
the MR indicator is turned off.
For the next program cycle, the ITEM ,record for item 101
is read to replace the category record processed. The date
record from the secondary file is still in the read area. Since
the secondary file record has no match fields, no comparison
is made, and the date record is automatically processed.
Once again, the MR indicator is turned off right before processing a record without match fields.
The remaining records would be processed in the order
shown in Figure 6-24. When records with match fields are
in the read area, the record with the lowest match field is
selected for processing. If both match fields are the same,
the record from the primary file is always selected. Of
course, if one of the records has no match field, it is processed immediately after the record it follows, regardless of
which file it is in. As shown in Figure 6-24, there are matching SALES file records for the ITEM file record with a
match, field value of 286. Since a record without match
fields (the category record for SMALL APPLIANCES) follows this ITEM record in the primary file, the record without match fields is processed before the SALES records
which match ITEM record 286. You should be aware that
this processing order may be undesirabte in your program.

MATCHING RECORDS: WHEN ALL RECORDS IN ONE
FILE HAVE BEEN PROCESSED
When you are using two' or more input-type data files in a
program, end of file is always reached in one file before all
the cards in the other file have been processed. This is because the matching record function can only select one card
at a time for processing. Furthermore, each file often contains a different number of records.
Usually, in multifile processing~ you want the program to
contin ue until all records from all files have been processed.
RPG " logic will do this. The last record indicator (LR) is
not turned on until the last record in the last file is read.
Let's go over the last few program cycles in the example
last presented. At a particular point in the program, there
will be two records left in the primary file (item 321 and a
record) and three records in the secondary file which have
not been processed (two for item 321 and a /* record).

/*

At the beginning of a program cycle, the ITEM record for'
321 'and the first SALES record foritem 321 would be'in'
the read area. Since both match fields are the same, the
primary file record is processed, \lIiith the'MR indicator
turned on before processing.
The next primary file record, an end of file (/*) record, is '
then read. In a single file program, reading a /* rec~rd tells /
the program there are no more data records to process. The \"
last record (LR) indicator is then turned on causing total
time operations to be performed, and thEm the program
ends.
In multifile processing, however, reading a /* record from
one file does not necessarily mean that all records from all
files have been processed. Thus, the program must deter- ;
mine if ehd of file has previously been reached in'the other
file(s). In thiscase,the SALES file still contains three unprocessed records. Therefore, reading the /* rec'ord from,
the primary file merely indicates that there are no more
records from that' file to process. The. remaining data records in the SALES f!'e are processed, one at a time, in the
order in which they are read.
When ~he end of file record from the secondary file is read,
the program determines if end of file has been reached in
the other file. ,Since it has, the LR indicator,is'then turned
on. ,In this program, there are not total calculations ortotal
output to be pe~formed; thus, the program is ended.

6-30,

S'

20964

321

\

008 '

321

so

013 " WS

321' ~-------- 1945

:~r~~:#.~~~:~~~

5 14690
CS

No Match Field
Assigned

~:~~:r~§.~~{,

295

SMA~L

so

039
: NO

APPLIANCES

286

5

0174'

5
076

239
239
No Match Field
Assigned - - - -

0268

* LAWN GARDEN EQUIPMENT
124 -~--..;--- 0485

117

038
049

117
117

SO

, 062 ' SO

101

043

101

MN

0093
157

10358

WS

MN

0165
1969
5
Records With No / ;
Match Fields
-------------AUTOMOTIVE SUPPLIES
*

P
5
5
5
,-.......;.- Secondary File Record

P
5
P

Primary File Record

Figure 6-24. Processing Order of Records with No Match Fields

Match Fields And Multifile Processing

,6-31

You should be aware, however, that in a matching records
program, specifying the end of file entry for a particular file
will not always cause processing to end immediately when the/
last record of that file is processed. If the file which has not
been completely processed contains records which match
the last record processed from the completed file, the matc~­
ing records will be processed before the program is ended.
Furthermore, processing will continue for any records without match fields, until the next record with a match field i~
read.

In other multifile programs, you may want the program ended
when.a cer.tain file has been completely processed, although
there are records left in anotherfile. As you know, by entering an E in column 17 of the File Description sheet you can
specify which file is to end the program. For example, say
the rrEM and SALES files contain the records shown in .
Figure 6-25. Since both files are in ascending sequence, once
all SALES records have been processed, there wouldn't be
much point in processing the remaining ITEM master records for which no sales were made. Thus, an E (end of file)
entry could be specified for the SALES file.

File Description Specification
:

F

File Type

Mode of Processing

End of File

File Format
Q

elt:

l

~a:

~~... w<

11-

Field Name

1J

2.~

:I:I~~OO'.
It-i;CIS

~V"""

I
II

a~I[17N

,(jC ~.
AITN1

1'¢~~ ITY

L'6

Plus Minu, I~~ro
IBlank

In

1

I~

lL K!l
1

j
To

From

IIII II

Field
Indicators

Field Location

12 13 14 115 16 1718 1192 0 21 22 23 24 25 126 27 28 29 30 31 13233 134 35 36 37 38

~4

2

CD

1

Figure 6-28. Assigning the Same Field as a Match Field and as a Control Field

6-34

U/M

Printed in U.S.A.

International Business Machine Corporation

~

II I II I

I I

1656667 68,69 70 71 72 73 74

I I
~

~

Item number
fields used as
both match
fields and
control fields.

.,

START

•
•

•

•

•

Read another
record

•

Select record to
process in this cycle
and turn on record
identifying indicator

Turn off record
identifying indicator
and control level
indicators

for selected record

•
Detail output for
selected record

•
Detail calculations
for selected record

~

I

Detail-Time
Operations
Performed

•

Is Control Field on
selected record different?
If same, go to process
selected record
I f different, turn on
control level indicator

•
Control
Level
Function

MR set on or off
for selected record
If control level indicator on,

•

do total calculations and
output for previous control
group

•
•

•
Performed

Figure 6-29. RPG II Logic of Obtaining Totals for Matching Records

~',

record only if there is a matching record in the secondary
file. Likewise, if a secondary file record is selected, MR is
to be on for its processing only if a matching record from
the primary file has already been processed. If an unmatched
record is selected, MR is set off, of course. At this point,
however, the matching record function only determines how
the MR indicator is to be set; the status of MR is not actualIy changed yet.

Once the matching record function has selected the next
record to be processed, the control level function then considers the records as one file in determining if a control
break has occurred. This check is made before the selected
record is processed and, thus, before the M R indicator is
set for the record just selected (see Figure 6-29). The con- '
trol field (item number) on the selected record is checked
to see if it is different from that on the previously processed record. If it is the same, no totals are to be printed;

Match Fields And Multifile Processing

?-35

so the MR indicator is set, the QTY accumulated into
TOTAL, and the individual record is printed. However, if
the item number is different from that on the previously
processed record, this means that all individual sales for
the last item number have been printed. The change in the
control field causes a control level indicator (L 1 was as~
signed) to be turned on. Any total calculations and total
output (operations conditioned by the control level indicator) are then performed for the previous c,ontrol group. In
this case, the total of all sales for the previous item are
printed.
When total operations are performed, the selected record
has not been processed yet. Therefore, during total time,
MR is still set for the previously processed record. Once
total operations are completed, MR is then set for the
selected record (the first record in the next control group)
so it can be processed.

Whenever a control field changes (control break), a control
level indicator is automatically turned on. Furthermore,
whenever a control level indicator is on, total operations
will be performed. In a matching records program, however,
there may be times when a control break occurs and you
don't want total operations to be done. Thus, you must
specify that total operations are to be performed only under
certain conditions.
For this program, sales are to be added and the total printed
only if there is an ITEM master record with matching SALES
records for that item. In such a case, MR would have been:
set on for the last SALES record of the group. MR would
still be on, then, when the control break occurs. Thus, detail
operations to accumulate sales should be performed whenever M R is on and the total operations to print the TOTAL
should be conditioned to be performed only with L 1 and
MR on (Figure 6-30).

/
I

6-36

r-"

',-

Page of GC21-7567-2
Issued 21 December 1979
By TNL: GN21-5709
RPG

IBM

Form GX21-9093
Printed in U,S,A.

CALCULATION SPECIFICATIONS

International Business Mad"lIne Corporation

1 2

Program

Page

Date

Programmer

RPG

IBM

International Business Machine

OJ 0'_

GX21·9090

SPECIFICATIONS

OUTPUT

1

I~I~
Filename

Line

f
3

4

5

6

all

)

0

10 13

0

10 14
10 i 5

0

10 16
10 17

10

9 to 11 12

vlKI7

Output Indicators

Skip

I;

l~

Ijl~
1!liIA1010

AL

IAINIO

~

~

1
~

~

1~(/)6

.,..,
I.J

0
0

10
111

0

1 12
11 13
1 14

0

0

0

v

If I
l\ill
Positon
in
Output
Record

No

~

No Sign

CR

1
3

A
B
C

4

0

2

75 76 77 78 79 80
of _

J
K
L
M

:~;:;:ation 1 I. 1 I I I I
X = Remove
Plus Sign
V = Date
Field Edit
Z = Zero
Suppress

Constant or Edit Word

~

lP
~!F

r\1iR rtfL
M1<

t2l~

~lLl

!!I

,.;..,

'127 I'I
.,... IT'f'M
It ANIT
!~~
.:""I

!:fn 1213

Ves
No
Ves
No

No

IHT lIn "Nil

l.X CA !TII~

~Il

1"<11-

GITY

i}...c 1'11.£1 TN
1/

TY

J!

~

...J

::::

~

t

< ::
D..C

~
..J

Device

Symbolic
Device

~
1i

;;t~n~xit

:~~n:;r~~loW

Name of
Label Exit

Number of Extents
Tape
Rewind
~

.:J

W

-g

Core Index

Overflow Indicator U

r---- §
Key Field .~
Starting
Location

~

K

W

Option

Condition
Ul-U8

~

Continuation Lines

~

~a:

<

Entry::l

.2 .3 .4 '5 '6 17 '8 .9 20 2. 22 23 24 25 26 27 28 29 30 3' 32 33 34 35 36 37 38 39 404. 42 43 44 45 46 47 48 49 50 5' 52 53 54 55 56 57 58 59 60 6. 62 63 64 65 66 67 68 69 70 71 72 73 74

3

o

Ftc: t-t'

alock
Length

File AdditionlUnordered

~:~!~: ~~~~I~::;d

File Designation

KI

12l,~

ttl I

nlr Sk

I

plr:n NTIEIR

F

F
F
F
F
F
F
F
F

U IL OL 69 119 L9 99 59 t9 t9 Z9 19 09 69 as L9 9S 59 t9 t9 Z5 15 os 6. In' Lt !It 5.

»

t. Zt It 0.6t Ilt Lt 9t 5t tt tt zt It DC 6Z 9Z

a

9Z 5Z tZ tZ U

IZ OZ 61 81 LI 91 51 tl tl ZI II 01

6

8

L

9

5

•

t

Z

I

"""',

)

Answers To Review 6

6-49

2.

Input Specifications
RPG

IBM

GX21·9094 U/M 050'
Printed in U.S.A.

INPUT SPECIFICATIONS

International Businen Machine Corporation

1

2

75 76 77 78 -79 80

Program

Page [ [ j O ! _

Dale

Programmer

~

I

Record Identification Codes

]

i---

8.

~

~

c.

i
l

Filename

Line

~

~
=6 ~
ij-;;- '0

r-r-r-

a R

f;:'Nfo

zo

Position

~

j

~

e

~

Position

~ ~ c5

~

ge ~

- ~~e
~~
;,gu 3~~

Position

~~6

From

Field Name

~

To

~

a
a

1

III-'

2

I

a

3

I

a
a
a

4

I

~

5

I

l~lL

I_I ... I_I ...

6

I

a

7

I

a

8

I

1.:2
1213
12.14

II1212 I~IP liN 1121~ I~II IRlc; h'lr
121~ ~II=' IrlN l"'l1

12LI)

~I?

a

9

I

1

a

I

11

I

rll

lAlA

11-11-<

I

I,

~i':l

I.-Ir

1,*

ILj~ IrlE IPIT

1,.,1;... 1...1 ..

I~b'

Zero
Plus Minus or
Blank

u:

NIll IMI~
• '-If

Ir~

IA~h'

~I,.,

LL

1_1_1-

12

I-

I'U.

1I'l1l1l-

.. 1-111

I~

1 5

III 14~ 'r ~

1 6

I

12

4rz

1 7

I

I~

1,-,1.-.1

.

.-

1 8

I

Ir I, I... ,

""I:'

L

1 9

I

lLlL
It I"

b ~1 1u... -

."l

a

I

ir r

3.

,.

II

0'1

-

1112 N2

1111

ft11

In
\

If-

Output Specifications

RPG

IBM

~6

'0
Q;

It ~ IMI.2.
II ~ I

I"

1 4

2

~

]
f:f

Ir~

LL

~12

IAIA

1 3

0

j2-t;
.!!:!~

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 2526 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 67 58 59 60 61 62 6364 6566 67 68 69 70 71 72 73 74

12
lS

1 2

Field
Indicators

u.u.

1

Cl

1 1 1 1 I 1

0

]

-2

4

6

8

§ .~

:~

Ii

0

c

~

~

....

3

5

7

Field Location
3

2

1

~~~~;~!:alion 1

OUTPUT

GX21·9090 U/M 050'
Printed in U.S.A.

SPECIFICATIONS

Intern.tional Bu;:iness Machine Corporation

1 2

Program

Programmer

Date

o

~ Space

-.,.
~ t
Cl -

Filename

Line

~ ~

!
a

.f
6

3

4

a
a
a
a

1

0

2

0

3

0

4

0

I-;:;:~to
7

8

~

11

~

~~
~

'A fofo ~
R

I- '"

E

5

Output Indicators

Skip

e~

i---

75 76 77 78 79 80

Page [ [ j O ! _

!

0

z

0

Field Name

II
~

;3

0

z

z

!M]

'AUTO

:B

Positon
in

a:

~:~~~

g

Commas

Zero Balances
to Print

Ves

Yes

Yes

No

No
No

Yes
No

No Sign

CR

-

A
8
C

J
K
L

o

M

~~~;~!:ation 1 I.

I I I 1I

X = Remove
Plus Sign
Y = Date
Field Edit
Z = Zero
Suppress

Constant or Edit Word

Ii:

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 2; 28 29 30 31 32 33 34 35 3637 38 39 4041 4243 44 45 46 4748 49 5051 52 53 54 55 56 57 58 59 6061 626364 656667 68 69 70 71 72 73 74

IAIA ~~

Irl~

INI~~

~~

(
\,....

6-50

Chapter 7. Programmed Control of Input and Output
J

CHAPTER 7 DESCRIBES:
How to alter the order of processing input files using FORCE.
How to read one or more records per cycle from a demand file.
How to do repetitive or exception output during calculations.

BEFORE READING THIS CHAPTER YOU SHOULD BE ABLE TO DESCRIBE:
Multifile processing.
Look-ahead.
End-of-file condition.
*PLACE.
RPG II program logic (Chapter 1).

AFTER READING THIS CHAPTER YOU SHOULD BE ABLE TO DESCRIBE:
RPG II FORCE operation code.
Using FORCE with the look-ahead feature.
Using the RPG II READ operation code to process demand files.
RPG II EXCPT operation code.

Note: You can use the review questions contained in Review 7 at the end of this
chapter to test your comprehension of each topic in the chapter. Questions are
grouped according to the topic to which they apply. Answers follow the review
questions.

---,

J
Programmed Control of Input and Output

7-1

INTRODUCTION

Normally, records are read, identified, selected for processing, and output according to the fixed logic of the RPG II
object program. Sometimes, however, you need to have
direct control over the input and output of your program.
RPG II provides several operation codes which give you this
control. By using the FORCE operation code in your own
calculation routine, you can override normal RPG II multifile logic for selecting input records for processing. You
can also do certain kinds of input and output during calculation time by using the READ and EXCPT operation codes.
Note: The CHAI N operation code also allows programmed
control of input and output operations. The CHAI N operation is explained in IBM System/3 RPG 1/ Disk File Processing Programmer's Guide, GC21-7566.

ALTERING THE ORDER OF PROCESSING FI LES
(FORCE OPERATION)

RPG II uses two methods to determine the order in which
records are processed in a multifile program.
" If match fields are not specified for either file, all records
in the primary file are processed, followed by those in.
the secondary files in the order defined on the File Description sheets.
• When match fields are assigned, the RPG II logic of
matching records determines from which file the next
record is to be processed.
The order of processing determined by RPG II logic is appropriate for most of your multifile programs. However,
for certain programs, it may be necessary to have some of
the records in the two files processed in an order other than
that in which RPG " logic would select the records.
A record can be processed out of order only if you indicate
to the program that the file containing that record is to be
forced. To do this, you must code additional specifications
to override normal RPG II multifile logic.

7-2

Regardless of how your files are organized, the following
situations require that you alter the order of processing:
1.

Match fields cannot be assigned to the files and you
wish to:
a. Alternate processing between two files.
b. Process a primary file record followed by a particular number of secondary file records.
c. Process a secondary file record only when it
matches a primary file record.
'l

2.

Match fields are assigned to both input files. You
wish to process one primary file record, followed by
matching secondary file records, then the rest of the
matching primary records.

To alter the order of processing, you must first determine
which file is to be processed-when and under which conditions. Once you know the order, the next step is to determine, for a particular programming cycle, whether the RPG
II logic will select the appropriate record or if you must
force the processing of that record.
The first record to be processed in any program can only be
selected by RPG II logic in the usual way. Thereafter, to
alter the order of processing, you tell the program to force
a record from a file which would not ordinarily be processed
next. Once the forced record is processed, and providing another record is not forced, the RPG II logic selects the next
record in the usual way. This is the record which would
have ordinarily been processed if the other file had not been
forced .

Specifying the Next File to Process

To process a record out of its normal sequence, you specify
on the Calculation sheet the FORCE operation code and
the name of the file which is to be forced in the next program cycle (Figure 7-1).

/

)

Assuming a record type 01 from the primary file is being
processed, the calculation on line 01 is performed. The next
detail-time calculation specification for record type 01 indicates that the secondary file (SECOND) is to be forced. The
FORCE does not occur immediately, however. This specification only tells the program to remember that a record
from the file SECOND is to be processed next. Anyadditional calculations and/or output for the record being processed are performed first to complete the present program
. cycle.
At the beginning of a normal program cycle, RPG II logic
looks at the two records available in order to select the one
to process during that cycle. However, if the record from
the file which would not normally be selected is to be processed, this must be indicated to the program before the beginning of the ,cycle. If a file is to be forced, there is no
need for RPG II logic to compare the records and make a
selection. This is the reason that, if a file is to be forced,
the FORCE must be indicated during the program cycle
immediately before the cycle in which the FORCE is to
occur.

RPG

)

IBM

Depending on your program, you may not have to force a
record in every program cycle. For such situations, you
must indicate when the FORCE is to be done by specifying conditioning indicators in columns 9-17 of the Calculation sheet (Figure 7-1). Whether the FORCE is to be performed in the next cycle or not may depend on any of several conditions:
• The type of file or record type being processed at the
time.
• The number of records which have been processed.
• The result of a calculation performed.
• The contents of a field on the record being processed.
• The contents of a field on a record which has not been
processed yet.
With these points in mind, let's discuss a job in which you
can determine if the order of processing must be altered on
the basis of the type of record being processed.

CALCULATION SPECIFICATIONS

Form GX21·9093
Printed in U.S.A.

International Business Machine Corporation

12

Program
Programmer

Page

Oat.

C

Indicators

~

Result Field

At At

8-

Factor 1

Operation

Name

E

I;

15
z

Length

~

~

15
z

6

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 5051

3

4

o
o
o

1

C

2

C

3

c

o

4

C

o

5

c

o

6

C

o
o
o

7

C

8

C

9

C

1 0

C

~lJ.
~12
~Il

1_1.-

ITIA

~ITI'(

IAlnlo

11

IMlu IL T ICIQ IT~I~
11:r,... I~"

Condition under
which force is to
be performed.

lc;~ IL '~
It- 1..,1t-

757677787980
of _

:~:~f:ation I

IIIIII

Resulting
Indicators
Arithmetic
Plus IMinusl Zero

Factor 2

~

Line

CD

Compare

Comments

1 >iTl <2"f1-2
Lookup(Factor 2)i,
High Low Equal
54 55 5657 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

IT'"

~IMI~

INIT

III

Additional calculations.

I

Figure 7-1. Specifying the File to be Processed in the Next Program Cycle

Programmed Control of Input and Output

7-3

Alternating Processing Between Two Files

The two files in Figure 7-2 each contain one record for every
salesman in a company. The MASTER records are arranged
in alphabetical order by salesman name; the MONTH file is
arranged in ascending sequence by salesman number. Although there is no common match field, the records in the
two files are, nevertheless, in a one-to-one correspondence.
Salesmen numbers have been assigned such that they correspond to the order of the salesmen names. Thus, the first
record in each file is for Baker (salesman #10); the second
record in each file is for Costello (salesman #20), and so on.

The two files are to be processed to determine the amount
of commission earned by each salesman. To do this, a salesman's commission rate from his MASTER record must be
multiplied by the amount of his sales contained on his
MONTH record (Figure 7-2). The calculated commission is
then recorded in the salesman's MONTH record.

137896

367560
089760

55

159085

26

276848

40

345695

30

Commission
Rate

MASTER File
Figure 7-2. Files to be Alternately Processed

7-4

1

1
Date

Sales

MONTH File

'\ .......

This program must process the two files alternately; that is,
every primary file record processed must be followed by a
secondary file record. Likewise, every secondary file record
processed must be followed by another primary file record.
In this case, the MASTER record for a salesman is read to
make the commission rate available. His MONTH record is
then processed, to calculate the commission and record the
amount in the MONTH record. Then, the next MASTER
and the next MONTH record are processed in the same way
for the second salesman.

The two files are defined and the records described with
the specifications shown in Figure 7-3. MASTER, the primary file, is assigned record identifying indicator 01. Indicator 02 is assigned to the secondary file, MONTH. Since
MONTH is a card file to be used for both input and output,
it is defined as a combined file. (MONTH could also be defined as an update file, on another device.)

Fi Ie Description Specification
File Type

F
-

File Addition/Unordered

Mode of Processing
Length of Key Field or
of Record Address Field

File Designation
End of File

~

Record Address Type
Sequence

Filename

Type of File
Organization
or Additional Area

File Format
Una

E!e

8.

ee

~

)

4

5 6

7

8

2

FM ~5

o
o
o

3

F I"

4

F

5

F

IN

c~

Block
length

iii

Symbolic
Device

Device

.J

Z

Ui

1!

...rn;iR
H

:.<: 1;

Key Field
Starting
Location

:::::1-

~g

0:

::J

r;p ~I=
"'ls lAF=

Condition

-~

Ul-~

Continuation lines

~

Z

~

:>

KI

I II I I

MII= r JLl

Alb
Iqlb

Mll=r

RPG

Entry

Option

~

III

Other devices can
be used, depending
on the system and
configuration

?

GX21-9094

INPUT SPECIFICATIONS

U/M 050'

Printed in U.S.A.

International Business Machine Corporation

1
Date

Programmer

Record Identification Codes

I

~

c

~
0

§6

z u
6

7

8

~E

Position

~~

~u

tl

E

6

Positi~n

~~~~;~f:ation I

jl

'in

:::;
~ c ~
~ ~ co
15
Q Vi Ci::
z
0:

From

~

To

Field Name

Field
Indicators

§

0

~

'C

ILIL

1II

~.~
c

IIIIII

0

] ~~ j

0

hl

Position

75 '76 77 78 79 80
of_

Field Location

Filename

Line

2

[0

f---

5

~

Indicator 8
... Overflow
-6

Record
length

Page

4

Tape
Rewind

Core Index

Program

3

Number of Extents

.:l

~

Number of Tracks
for Cylinder Overflow

Name of
Label Exit

10 \I 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 3334 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 62 53 54 55 56 57 68 59 60 61 62 63 64 65 66 67 68 69 7071 72 7374

9

o

IBM

~

~~ W~IL

E
.f
3

E!

Extent Exit
for DAM

::.u

'C

;;

Zero
Plus Minus or
Blank

u::

9 10 \I 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

17l: I

o

1

lit/,

o

2

I

II

o

3

I

121~

I.,.

..J.

12.ll

-"

1... 1-

IA~ TII=IR

AlA

o

4

o
o

5

l'IYI

6

I

lL

o

7

I

Is

o

8

I

o

9

I

I
IV

11-1

Ala

12_(?j NIA 1f\1~

..

t1

~

~!2

J

12

14m J~ I~
IqO! ~~J MR IJ: R
',1.., 2C; ~ 1='5

Figure 7-3. Specifications to Define and Describe Files to be Processed Alternately

)
Programmed Control of Input and Output

7-5

Since no match fields are assigned, RPG II logic would normally process all records in the primary MASTER file before
any of the secondary MONTH records. To alternate the files,
you must tell the program to force a secondary file record
every time a primary file record is being processed. When a
MASTER record is being processed, record identifying indicator 01 is on. Thus, you should condition the FORCE
operation to be performed only if 01 is on (Calculation
sheet in Figure 7-4).
At the beginning of the program, RPG II logic automatically selects the first record, which is a primary file record.
Since 01 is on, the FORCE operation is performed; that is,
the program notes that a MONTH record is to be forced at
the beginning of the next cycle.

RPG

IBM

During processing of the forced record (02 on), the commission is calculated and recorded in the MONTH record
(Figure 7-4). Only the specifications for record type 02 are
done. Therefore, the FORCE operation is not performed.
Since no FORCE was indicated in this cycle (02 on), RPG II
logic again takes over to select a record, at the beginning of
the next cycle. Thus, the second primary file MASTER record is processed (01 on). Processing of the files continues
with the next MONTH record being forced and then another
MASTER record being selected by RPG II logic until all records have been processed.

Form GX21-9093
Printed in U.S.A.

CALCULATION SPECIFICATIONS

International Business Machine Corporation

12

Program

C

Page

Date

Programmer

Indicators

~

Line

.f85~

I;

6

7

8

z0

C

~~

c

~lL

o

C

0 4

C

c

,.

0

z

IRA

rrl='

1'1111

T 1c;IA

~n R"I~

RPG

IBM

,.

cf

1>2/1<2/1-2
'u - Lookup(Factor 2)is
OJ: High Low Equal

, 11= C.

'"I

",121-1

I~

NI' H

GX21..gog0

SPECIFICATIONS

OUTPUT

U/M 050-

Printed in U.S.A.

International Business Machine Corporation

1

Program

Programmer

Page

Date

o

~J

f---

Output Indicators

Skip

Space

I

0-

Line

Filename

~

-""
E
11;

~

E

3

4

o
o
o

1

5

0

6

2

0

3

0

~ D~

~~~
7

8

~~

~~ '" «
ci5

~

~

And
~

~

~

0

Z

0

Z

L

Field Name

End
Positon

~

;3

0

z

v

fl
(ill

"AUTO

j3

in
Output
Record

a:
-'

Commas

Zero Balances
to Print

Ves
Ves
No
No

Ves
No
Ves
No

2

CD

No Sign

75 76 77 78 79 80

~~~;~f:ation 1

of _

X -

CR

A
B
C

0

J
K

L
M

I. 1 1 1 1 I

Remove

Plus Sign
V = Date
Field Edit
Z = Zero
Suppress

Constant or Edit Word

'"

ii:

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 4041 4243 44 45 46 47 48 49 5051 52 53 54 55 56 57 58 59 60 61 626364 656667 68 69 70 71 72 73 74

I'""IN-I""

I~

Figure 7-4. Conditioning Operations on Basis of Record Type

7-6

Comments

~

~~

9 10 1112 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 5051 5253 54 55 5657 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

0 2
3

Length

Name

0 1

n

Zero
:e =Plus!Minu"J
Compare

Factor 2

Operation

Factor 1

I-'Ori
E ~ '"

4

3

Arithmetic

i'!

At

1 1 1 1 1 1

Indicators

...Ja:

AL

757677787980

~~~;~f:ation 1

of _

Resulting

Result Field

0_

=0
------ ~~~

CD

Page of GC21-7567-2
Issued 21 December 1979
By TNL: GN21-5709

In the last example, the FORCE operation was performed
only if a particular record identifying indicator was on.
Now let's consider a case in which you condition the
FORCE operation on the basis of whether a resulting indicator is on or off.

For this run, the ORDER file (Figure 7-5, insert A) contains
the week's order records for television sets, unit number
4607. The records show which customer placed the order,
and the quantity of television sets wanted. The STOCK file
consists of a separate record for each television set (unit
4607) in stock (Figure 7-5, insert B). Each record proviqes
the unit number, list price, and serial number of the item.

Suppose you have a number of customers who periodically
order items to be delivered from a central warehouse. One
record is kept for each unit in stock in the warehouse, and
another record for each customer's order of a particular
unit.

There are two purposes for processing the files. First, you
want an indication of which orders can be filled and which
orders cannot be filled. Secondly, the STOCK file is to be
kept up-to-date so it only contains as many records as there
are television sets available.

Forcing a Number of Records from a File

Orders are processed according to the type of unit ordered.
Therefore, for" a particular run, the primary file (ORDER)
contains all order records for only one type of unit, and the
secondary file (STOCK) contains all in-stock records for
that type of unit.

35905

WS61770

35905

4607

5648

10

)

4607

Customer
Number

Unit
Ordered

35905

K124110

S15206H

4224320

04

05

35905

09

4607

Qty

Unit
Number

®

4361G11

35905

07

4607

M320CEW

35905

12

4607

4607

35905

12

4607

TS91870

35905

I I
List
Price

D21AX32

126AJ41

Serial
Number

@

L-__________________________- J

ORDER file

STOCK file

Note: System/3 will allocate two decimal places in the list
price, although a decimal does not appear in the field.
The list price in the stock file is logically represented as
$359.05.
Figure 7-5. Files for Processing Customer Orders
Programmed Control of Input and Output

7-7

The program should produce a printed report showing which
orders can be filled, and the amount each customer owes
(Figure 7-6). Thus, you must determine the amount due
for each item and the total amount for each order. A record from each file must be available before you can calculate the information.
Files for this program must be processed in a specific order.
The quantity ordered (OTY) from an ORDER record must
be available first. This quantity is used to determine how
many STOCK records are to be processed. When enough
STOCK records for an order have been processed, the next
ORDER record is selected to repeat the process.
Looking at the two files, you can see that every record has
a common field containing the unit number. It does no
good to assign a match field to control processing order,
because the unit number is always the same for every record. All records in the primary file would be processed
before any secondary file records.
Remember, there is no way you can control selection of
the first record to be processed in a program. RPG II logic
always selects a primary file record first when match fields
are not specified. Since an ORDER record must be available first for this program, the ORDER file should be designated as the primary file.

Controlling the Number of Times FORCE is Performed

After RPG II selects and processes an ORDER record, you
must FORCE the processing of a number of STOCK records. The quantity ordered (OTY) from the ORDER record is used to control the number of times you force secondary file records. The quantity is stored in a field, called
COUNT, to keep track of how many records are left to be
forced for an order. Each time a STOCK record is forced,
the number in COUNT is reduced by one. When COUNT
reaches zero, enough STOCK records have been processed
for that particular order. Then RPG II logic can again take
over to process the next ORDER record (Figure 7-7).
The calculation specifications shown for this program (Figure 7-8) only determine if a record is to be forced in the
next cycle.
Assume the first ORDER record (record type 01) has been
selected, making the quantity ordered (OTY) available. The
first calculation specification (line 01) for this record type
stores the quantity in the COUNT field. Then the program
determines if any STOCK records are to be processed for
this order (line 05). If COUNT is greater than zero, indicator 27 turns on. With 27 on, line 06 is performed, indicating a STOCK record must be forced in the next program
cycle.

(
CUSTOMER

ITEM

QTY

1938

4607

09

2012

2637

3425

4607

4607

4607

SERIALNO

COST

TOTAL

126AJ41
DZ1AX32
4324320
S15206H
K124110
4361G11
M320CEW
TS91870
WS61770

359.05
359.05
359.05
359.05
359.05
359.05
359.05
359.05
359.05

359.05
718.10
1077.15
1436.20
1795.25
2154.30
2513.35
2872.40
3231.45

359.05
359.05
359.05
359.05
359.05

359.05
718.10
1077.15
1436.20
1795.25

398.95
398.95
398.95
398.95

398.95
797.90
1196.85
1595.80

367.03
367.03
367.03
367.03

367.03
734.06
1101.09
1468.12

05

04

07

Figure 7-6. Printed Report Showing Customer Orders Processed

7-8

At the beginning of the second cycle then, the first STOCK
record (record type 02) is selected (by being forced). Line
03 is performed to reduce ~he COUNT by one for this record being processed. The COUNT is then compared to zero
again (line 05) to determine if any more STOCK records are
to be processed for this order. If COUNT is still greater than
zero (27 set on again), line 06 is performed again, indicating
another STOCK record is to be forced at the beginning of
the next cycle.

START
RPG " selects
ORDER record

During processing of the second STOCK record, COUNT is
again reduced by one (line 03). Assuming COUNT is now
at zero, the COMPARE operation on line 05 sets indicator
27 off. With 27 off, the FORCE operation on line 06 is not
performed during this cycle. At the beginning of the next
program cycle then, RPG II selects the next ORDER record
from the primary file in the usual way.

YES
Is quantity greater
than zero?

NO

FORCE a'
STOCK record

Subtract 1

"I)

from quantity

Figure 7-7. Determining When Stock Records Must be Forced to
Fill an Order

RPG

IBM

Form GX21·9093

CALCULATION SPECIFICATIONS

Printed in U.S.A.

International Business Machine Corporation

1

Program'

Programmer

Date

C

~

line

~~~
'0 a;,"

Indicators

9~

~

E E~
85 fi

~

iJ

5

6

7

0 1

C

a
a

2

C:lf

3

C

a
a

4

C~

5

C

a

6

C

8

Length

.~
's

~

E

'2

15

z

0

9 10 11 12 1314 15 16 17 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 33 J4 35 J6 37 J8 39 40 41 42 43 44 45 46 47 48 49 50 51 52

~l

i?J2

27

rw11~ V'i;.

r-h IJNT

C;

rir1 11J~7

"'1" IMip
t-

R

it(

~rl~

~h

rzl.

r~ ,

r2JC2l

,"'~

It Ail

75 76 77 78 79 80
of_

:~;~;:ation I

IIIIII

Indicators

Factor 2
Name

of
4

Operation

Factor 1

~

2

[0

Resultirig

Result Field

At Jd

=0

3

Page

Arithmetic
PlusJMinusJ Zero
Compare

Comments

1>211<211-2
Lookup(Factor 2li,
High Low Equal
54 55 5657 5859 60 61 62 6J 64 65 66 67 68 69 70 71 72 73 74

ct2J

N,T
i2"1

Tlr leik

Figure 7-8. Controlling the Number of Times a File is Forced

)

Programmed Control of Input and Output

7-9

Page of GC21-7567-2
Issued 24 May 1976
By TNL: GN21-5389

At this point, add the specifications for calculating the
amount due and for printing the report (Figure 7-9). An
ORDER record is selected first, making the QTY available.
Calculation lines 01,02, and 06 in Figure 7-9 are performed
for this record (record type 01). First, a TOTAL field, to
be printed for each group of customers, is set to zero (line
01). Next, the quantity ordered is moved into the COUNT

RPG

IBM

field (line 02). If COUNT is greater than zero, indicator 27
is turned on (line 06), and line 07 is performed; the program is instructed to force a STOCK record at the beginning
of the next cycle. Before forcing, however, the output specifications (Figure 7-9, lines 08-11) are performed to print
data from the ORDER record.

Form GX21·9093
Prlntedl" U.s.A.

CALCULATION SPECIFICATIONS

International Business Machine Corporlt!On

1

Program

Page
Date

Programmer

C
-

Indicators

~

~
8.~

At

line

I- "0

EE

4

o

1

Factor 2

5 6

0

0

z

z

C

01

o

2

C

tiJl1.

o

3

C

t?J12

r- TA'L

~l2

o

4

C

5

C~

o

6

C

o

7

C

o

8

C

5 18
M'" IvlE

,-1",

1\1 IT

rh I

NrT

'ADI"
5~IB

E

IT~ TIAIL

tAI.L
~rrY

Ir,....

~l'" ~IT

~,...

54 55 5657 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

'7~

12~

JMr

..... IA

,.,.. UINT

rlJll.

',-It'- iftiP ~rl

l217

lK

l-

RPG

IBM

rr

1

I~i~

27
,-t'I

GX21·9090 U1M 050·
Printed in U.S.A.

SPECIFICATIONS

OUTPUT

International Business Machine Corporation

1

Program

0

"- Space

C

Filename

!l.

4

1

5

6

~~~

7

8

11

~~

III <{

211<211=2
Lookup(Factor 21is
High Low Equal

'fi1

0

z

II

~~~:~f:.tion I

Plus JMinusJ Zero

~

9 10 1112 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 33 34 35 36 37 3S 39 40 41 42 43 44 45 46 47 48 49 50 51 52

7

o

Length

Name

.f 8
3

.''g"
0

Operation

Factor 1

At

75 76 77 78 79 80
of_

Resulting
Indicators
Arithmetic

Result Field

>..J

2

[I]

RI IAl-

T~ ITAI!.-

12
20
2.5
3b
.;~

,bl

,
•

,

~

125

,

I"\TY

,

I

)

For this program, suppose ORDER and STOCK are card
files, and processing must continue until both reach end of
file. However, if one file runs out before the other, you
don't want to perform the usual calculations ard output for
the remaining file. The remaining cards must be processed
in another way; that is, by selecting them to a ~pecial stacker. If all orders are filled, any remaining STOCK cards
should be selected to stacker 3. If there aren't enough items
in stock to fill all orders, any remaining ORDER cards
should be selected to stacker 2.

Following output, the next cycle begins with a forced
STOCK record (record type 02) being processed. The cost
is added to a TOTAL field (line 03) to accumulate the total
amount due on the order.
Then, COUNT is reduced by one for the record being processed (line 04). Once again COUNT is compared to zero
(line 06) to determine if line 07 should be performed; that
is, to determine if another STOCK record is to be forced
for the next cycle. The COST and TOTAL calculated for
the STOCK record are then printed, by performing the output specifications on lines 12-15.

To continue the program until both files have been completely processed, specify end of file entries on the File Description sheet, either for both of or for neither of the two
input files (Figure 7-10). By doing this, the LR indicator
won't be set on to end the program until the last record of
the last fi Ie has been processed.

The record selected at the beginning of the next program
cycle depends on whether a FORCE operation was indicated
in the previous cycle. If calculation line 07 had been performed, another STOCK record would be processed (by being forced). If not, RPG II would select the next ORDER
record from the primary file.

With end of file specified for both files, let's consider what
will happen when only one of the files reaches end of file
(see Figure 7-9). First, suppose the STOCK file reaches end
of file before all ORDER cards are processed. Since both
files are not at end of file, processing will not stop. Instead,
after processing the next ORDER card, the program will try
to force the appropriate number of records from the STOCK
file. With no more STOCK cards to force, another ORDER
record will be selected. Once again, the program will try to
force STOCK records for that order. The process continues
until all primary file ORDER records have been processed.
Furthermore, every time a new ORDER record is processed,
it is printed on the report and the card goes into stacker 1,
as if the order were being filled.

Controlling Processing After Reaching End of File

)

In a multifile program, end of file entries can be specified
for any, all, or none of the input files. If an end of file entry
is specified for only one file, processing stops after all
records from that file have been processed. (Remember,
however, if match fields are assigned to the files, the program continues to process the records which match the last
record processed or which have no match fielcs.) If end of
file entries are specified for all or for none of the input files,
processing continued until all records in all files have been
processed.

A similar problem arises if the ORDER file reaches end of
file first. Suppose the last order has just been filled.
File Description Specification
File Type

F

Mode of Processing

File AdditionNnordered

Length of Key Field or
of Record Address Field

File Designation

I--

End of File

~

Record Address Type
Sequence

Filename

Type of File
Organization
or Additional Area

File Format
Line
0

S~

8-

~

~~...
:::::

~
3

4

o

2

o3
o 4
o5
o6
o 7
o8
o9

5 6

7

8

9

~

Block
Length

Record
Length

o~

a:

::J

W~II.

10 11 12 13 14 15 16 17 18 19 20 21 22 2

~

'"0

:::::t-

0:0

~:::::

..J

w

Device

Key Field
Starting
Location

Number of Extents
Tape
Rewind

Core Index

~
Condition

j

Ul-'r!!!:l

K

Option

Entry

~

~
~

a:

24 25 26 27 28 29 30 31 32 3334 35 36 37 38 39 40 41 42 4344 45 46 47 48 49 50 51 52 53 54 55 5& 57 58 59 60 61 62 63 64 65 66 67 6869 7071 72 7374

q~

M~

~S~

~

C1t.,

MIJ=f" 2

r::

,~,

,..,

~

Continuation Lines

F~ T~ rk
to(

in

Number of Tracks
for Cylinder Overflow

Name of
Label Exit

,---- g

~

Ft'( t-t-"

Z

Overflow Indicator U

~P!;

IHl

Symbolic
Device

.g

~~

FI(

Extent Exit
for DAM

F
F
F
F
F

""111

DR -N T,t: Q

II I I

1111

1111

I II I

Other devices can
be used, depending
on the system and
configuration
1.1 J L l i L 1 I i

I I I I I I I II I

Figure 7-10. Continuing Processing Until Both Files Reach End-of-File

Programmed Control of Input and Output

7-11

After processing the last STOCK card for th~t order, no
more STOCK cards are to be forced, so RfG II logic tries
to select the next primary file ORDER record. In doing so, .
the /* card from the ORDER file is read. Since the program
is to continue until both files are processed, RPG II logic
automatically processes the remaining records in the other
file (STOCK). As each remaining STOCK record is processed,
the calculations and output for that record type are performed and the card goes into stacker 4, as if the record
were being used to fill an order.

formed instead. Reading a /* card from a file will not necessarily indicate that end of file has been reached in all files.
The LR indicator is turned on only when the /* card of the /
last file has been read. Therefore, a trailer card should be
placed at the end of each file (Figure 7-11), before the /*
card, to indicate when all cards of the file have been processed. When a trailer card is read, the record identifying indicator associated with that card turns on to indicate which
file has been completely processed. For this program, the
trailer card in the ORDER file will turn on indicator 03,
while the trailer card in the STOCK file will turn on indicator 04.

Although processing is to continue until both files reach
end of file, you must have a way of determining when the
first file runs out and which file it is. This is necessary so
that normal calculations and output for the remaining cards
can be bypassed and stacker selection specifications per-

(
/1--1

/

-------.v

/

/

/

Trailer card
record type 03

[J

vlRDER

/

1-,/1------------

I~--------~

cards

V~

/

J~-Jj

I

--------,

11-----------.

)1

1_

~I

I....

1-

1-

ORDER file
Figure 7-11. Use of Trailer Cards to Control End-of-File Processing

7-12

record type 04

/r.-L- - - - -

record type 01

/

,(.- .-/'-=Jcard
(

/

'I

II

Let's look at the completed calculation and output specifications for this program (Figure 7-12) to understand how
the trailer cards are used to control processing.

STOCK file

(

/'

I,

\'"

calculations when 33 is on, merely by branc~ing to the end
of calculations. Normal output for STOCK reco~ds is then
conditioned so it isn't performed if indicator 33 is on (output lines 10-13). Output line 19 then instructs the program
to stacker select the STOCK card if 33 is on.

Assume the trailer card from the ORDER file (record type
03) isread, indicating all ORDER cards have been processed.
When record identifying indicator 03 is set on, you know
that any remaining STOCK cards are to be selected to
stacker 3. However, indicator 03 cannot be used to condition the stacker selection. As soon as the trailer card has
been processed and the first of the remaining STOCK cards
read, indicator 03 is set off and record identifying indicator
02 (for the STOCK card) is set on. Therefore, while the
trailer card is still being processed, you must set on an indicator which will stay on until the last STOCK card has been
stacker selected. As calculation line 01 shows, record identifying indicator 03 is used to SETON indicator 33. (The
use of N34 on line 01 will become clear as the program is
explained.)

Now, let's assume the STOCK file runs out before the
ORDER file. When the trailer card from the STOCK file
(record type 04) is read, you know that the remaining
ORDER cards must be selected to stacker 2. For the same
reason as previously explained, the record identifying indicator of the trailer card cannot be used to condition the
stacker selection. Therefore, record identifying indicator
04 is used to SETON indicator 34 (Figure 7-12, calculation
line 04).

Now when a STOCK card is selected for processing, the program must determine if normal calculations and output
should be performed for the record (record type 02). Since
indicator 33 is on, normal calculations and output should
be bypassed and the STOCK record stacker selected instead.
To do this, all of the specifications for record type 02 could
be conditioned to be performed only if indicator 33 is off
(N33). However, to eliminate the extra coding and indicator
testing, calculation line 02 instructs the program to skip the

In addition, while the trailer card is being processed, you
must determine if the last order was completely filled. If
there had been enough STOCK records to fill the order, the
quantity in the COUNT field would have been reduced to
zero. Therefore, when record identifying indicator 04 is on,
COUNT field should be checked (calculation line 05). If
COUNT is greater than zero, indicator 36 is set on. With 36
on, a message will be printed indicating how many items of
the last order could not be filled (output lines 14-17).

RPG

IBM

CALCULATION SPECIFICATIONS

Form GX21-9093
Printed in U.S.A.

I"ternational Business Machine Corporation

C
3

4

o

1

o
o

2
3

5

Length

'a

~

EE
.f8

0
z

6

7

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 5051 52

E

.~

0
z

c
~I,,"I'

BI~

6

o
o
o

7

C~

8

C

9

c
c
c

1 2

c~

, 3

c

1 4

C

, 5

c~

1 6

c

1 7

r.

IrJC

" i ...

~~~;~f:ation I

b

rtJlLJ
131LJ

!"n .IINIT

b,

h"h trlAIL

~Il
~12

If

t2j1,

"h l'IINrr

rrlA 11

blf:.1

PluslMinu;[ Zero
Compare
1>211<211-2
Lookup(Factor 2lis
High Low Equal

IIIIII

'~'Nln

I~ILJ

It

~"" ~Ip a~

I~II-.

r;h rr h

~NID

~It I~

rr- J,Tl411

M~ Ivl~

""ITly

~Inln

l-o-ir'o

SIIJIa

(2,1

!TIn ITIAIL
r-~
Ill"lr

Comments

54 55 5657 5859 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

I~I~

:N

t;b rr~

cf*

o

1

0

Factor 2

"0

5

,

Operation

Factor 1

I-

c
c

of _

Arithmetic

Name

0
z

CD

Resulting
Indicators

Result Field

I 1

~
8.~

c
c
c

1 0

Indicators

~

o
o

4

Page

Date

>...J

Line

75 76 77 78 79 80

1 2

Program

Programmer

nl7
17~

j;"11ol ArT 1!='Nln
I~
c;11< Ir'p "A I, I'-I.e; 1r:~IR
Q(: ~rr
'"'J: Ic;h" hrlK
C;T ~~Ik An- IEINr
w II<
r:: TIL
A15h'
5K IT Ip rll Irlc:. II=I""'IR
Iru: ~~ J"'\,f: hiD ,nil: ID~
r, IA IFI, In
lillJ:' I~h
1c;!J:'~
Jlp Irlrt ,~ IT~IR

rr h IT~ll

Lsrr

r I" ,INT

RiJ:' 'n I IrJ;
~I~ Irls

"1(' 1,INrr
1211

Irlr ~Ip I"ttl
t-

II:INID

I/'(

II-I,

1211
II-

:n:

Irlr-

tr~ IAN

rrh

N Jlrv Rr: r_
I~"" IRriJ:
1_1-

lh.ilT
'til,

r"!l~

J,.;

IR

"'I_!
...
!f:!H
~

T~~

Figure 7-12 (Part 1 of 2). Controlling Operations at End-of-File

)
Programmed Control of Input and Output

7-13

At this point, the first of the remaining ORDER cards is
read. Since indicator 34 is still on, all calculations for the
ORDER card are bypassed (see calculation line 06). The
normal output for the ORDER record is to be performed
only if indicator 34 is off. Thus, the printer output for record type 01 (output lines 06-09) is skipped and the record
is selected into stacker 2 instead (output line 20).

signals that the remaining STOCK cards should be stacker
selected. As the STOCK cards are stacker selected, one-byone, eventually you reach the end of STOCK by reading
the trailer card from the STOCK file. At this point, both
files have reached end of file, the LR indicator is automatically set on, and the program is ended.
When the ORDER file trailer card is read (03 set on), then
you want to know if the STOCK file has been completely
processed. If it has, the STOCK file trailer card (record
type 04) has already been read, and the indicator set on by
04 (indicator 34) would still be on. With 34 on, there's no
point in having record type 03 set on indicator 33. Likewise, if indicator 33 is on (ORDER at end of file) when the
STOCK file trailer card (record type 04) is read, there's no
point in having record type 04 set on indicator 34. For this
reason, the calculations on lines 01 and 04 of Figure 7-12
have been conditioned by N34 and N33, respectively.

As you have seen, the trailer cards from each file are used
to set on particular indicators. When the ORDER file
trailer card (record type 03) is read, indicator 33 is set on.
Likewise, indicator 34 is set on when the STOCK file trailer
card (record type 04) is read. The indicator which is set on
(33 or 34) is used to prevent certain operations from being
performed and to cause remaining records in the other file
to be stacker selected.
Of course, reading a trailer card does not mean there are
always cards remaining in the other file. For instance, assume all ORDER cards have been processed, but not all
STOCK cards. When the ORDER file trailer card is read,it

RPG

IBM

As you know, the setting of an assigned indicator can determine whether a FORCE is to be performed or not in the

OUTPUT

GX21·9090 UlM 050·
Printed In U.S.A.

SPECIFICATIONS

Inwrnational Business Machine Corporation

1 2

Program
Programmer

-

Page

Date

0

~

Space

Output Indicators

Skip

e~
o!!:.

Filename

line

!

~

E

6

~

~

~~

en
ADD

~.!!.-

~
5

;:~
~ ~

Jd

I

~« z0

Field Name

1

I

0

0

z

z

·AUTO

AND

7

8

'"
....

~;i

~
~

End
Positon
in
Output
Record

4

1

01'( Il-ItJ

2

0

tn

H
~R

'~~b

21q
311

0
0

o

5

0

o
o

6

0

7

0

Irlll 1ST

12

o
o

8

0

Irrr I~M

2~

9

0

~ITIY

2;-

1 0

0

0

1 3

0

1 4

0

1 5

0

1 6

0

1 7

0

1 8

0*

1 9

05

2 0

0

No Sign

CR

-

1
2

A
8
C
0

J

Ves
No
Ves
No

3
4

I. 1 1 1 I I

X'" Remove
Plus Sign
~ Date
Field Edit
Z • Zero
Suppress

/

V

K

L
M

a:

g

Constant or Edit Word

il::

I' p

3

0

to Print

Ves
Ves
No
No

~~~;~f:ation 1

,,",'f:

4

11

Zero Balances

75 76 77 78 79 80

of_

9 10 11 12 13 14 15 1617 18 19 20 21 22 2324 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 60 61 62 63 64 66 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

3

o
o
o
o

1 2

Commas

[0

hl
n

dr Il ~II

'6 Ie:R irA 'N I" ,
l~

I"IlrlY

lIlT !;~

fYit:J(

ITh TA Il

hslr

,

I

ali/. INl~~

1"\

n

(J)L.J

lc;1~ IRT ~I
r-1I"'t lc; T

r

rr AIL

3
~

NT

~

Blh

,..,...

_.....
H

I~~

l"~
1,1
.'~Q

'IS
I~I""

1'"113

II-IH

Dl2

I

II Nil IRlf r=

IT~

FI IL l.

I

~3
III

I

f:.. fYI~

"'F'

'W

J-W

I

~f~
3~

0

Figure 7-12 (Part 2 of 2). Controlling Operations at End-of-File

(
I

7-14

following program cycle. Either a record type, data on a
record, or the result of calculations performed during processing of a record can set the particular conditioning indicator on or off.

sible, you should organize your files in such a way that the
normal RPG II logic can determine the appropriate order of
file processing. In this way, you do not have to code additional specifications to control the order. Of course, from
time to time you may have jobs in which you must use
FORCE and look-ahead.

In the examples presented thus far, something about a record which was currently being processed determined whether
the conditioning indicator was set on and whether an unprocessed record was forced. In the last example, the QTY
field on the ORDER card determined how many STOCK
records were to be forced.

Doing Matching Records Without Match Fields
If two files are organized such that the same match fields
cannot be assigned to the two files, you can still process the
matching records together by using look-ahead fields and
the FORCE operation. (This cannot be done, however, if
the look-ahead file is defined as a combined or update file.)
Look-ahead can be used to determine if certain fields (not
assigned as match fields) on an unprocessed record match
those on the record being processed. If they match, FORCE
is performed to cause the matching unprocessed record to
be selected next.

Look-Ahead to Determine Whether a File is to be Forced
For some programs, you cannot determine whether a record
is to be forced in the next cycle until you know something
about the records which have not been processed yet. Thus,
you must look ahead in one or both files at the next record
which is not yet available for processing. In looking ahead,
you may be checking to determine what record type is next,
to see what data is on the next record, or to determine if
the next record has the same match field as the record being processed. What you find in looking ahead can determine which file is to be processed next and, also, whether
the file must be forced or not.

As an example, assume a report is to be prepared showing
the amount of each salesman's sales and his quota. The report should also compare the total of district sales with the
district quota.
The two files available for this program are described in
Figure 7-13. The primary file (MASTER) contains a district
record (record type 01), followed by all salesmen's MASTER

Before considering the use of FORCE with look-ahead, however, you should evaluate your system design. If at all pos-

RPG

IBM

GX21·9094 U/M 050·
Printed in U.S.A.

INPUT SPECIFICATIONS

International Business Machine Corporation

1

Program

Programmer

Page

Date

Record Identification Codes

s

I

Filename

Line

~
to

~
5

i

Jl

r--r-

~§ ~

iz l ]
0

0

Position

gel
-0

~

~ ~

z u u

Position

~

e

~

Position

o~~

zuu

go
~§

'';;

0

From

To

Field Name

~

Iii

.~

1

IM

a

2

I

I~

a
a
a
a

3

I

17

["Ill Inls rrlN JIM
lIb 171",1.-. ''"'frill

4

I

lLl~

121~ lol~ tTlJ\1 !r.,IR

5

I

6

I

I';).

1"-" !e: IN

/11'11

a

7

I

Ih

I"I~

I~

a

8

I

lllCi!l
12.11

9

I

1

a

I~

I '1 I I I

Field
Indicators

~

·8

0

:9~
"ii
LLU::
.~ g'
.~

]
g

-£ :S

iG~

8

0

4

:2:u

~
"

~

"u:

-;;

Zero

Plus Minus or
Blank

9 10 11 12 13 14 15 1617 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 5960 61 62 63 64 6566 67 68 69 70 71 72 73 74

lAS 1rll='IR

01111

~11

~121N 1:zj12

1,;1c;

I,

II

~In

II Irtc;

11

I~ lAlL

1 2

I

I/,

1 3

I

11i:~

lL\IA

~L:J,

District recordr

IrlM

?

~

.,

al

3

a

8

~·o

Z

a

6

7

~~"D

3

2

1

75 76 77 78 79 80

~;~~;~f:ation 1 I

of _

Field Location

11

]

~

2

CD

I"

12/" INIA IIYI,;
l'l.l, I;> I.-, 1"'lrlA

I

1,.,1" I.. I. I.. I.

~

I'll

I..II~

'11M

!

Salesman
I
master record J

SALES record

IAJh'
I I I I I I I I

Figure 7-13. Describing Files to be Matched Without Match Fields

)
Programmed Control of Input and Output

7-15

records (type 02) associated with the district. These are in
turn followed by the next district record (01) and its related
salesmen MASTER records (02) and so on. Although the
records are grouped by district, all salesman MASTER records in the file are still in ascending sequence by salesman
number. The secondary file (SALES) contains only one record type (03), a record for each individual sale. The SALES
file is also in ascending sequence by salesman number. While
the MASTER file contains a record for every salesman (assume there are no MASTER records missing), the SALES
file may contain only one, several, or even no records for a
particular salesman.

Start
RPG II selects
record from
primary file

No

record so selec
next primary
file record)

To produce the report, the records should be processed in
the following order:
1.

District record (record type 01).

2.

Salesman MASTER record (record type 02).

3.

All SALES records for that salesman (record type 03).

4.

Next salesman MASTER record.

5.

SALES records for that salesman.

6.

Next district record (after all salesman MASTER records associated with the first district have been processed).

There is no common field on all three record types which
can be assigned as a match field to cause the records to be
processed in this order. Totals are to be accumulated by
salesman number; but the MANNUM field is contained only
on the salesman MASTER and SALES records. The district
records do not contain this information.
If the MANNUM fields are assigned as M1 match fields for
only two of the record types, the records will be processed
in an incorrect order. Following the last salesman MASTER
record (02 record type) for a particular district, the next
record in the same file is another district card. Since district records have no M1 match field entry assigned (no
MANNUM field), the district record is processed immediately before the SALES records for the last salesman.
Although this program cannot be done using match fields,
you can match the records yourself by using the look-ahead
capability to compare fields (Figure 7-14). The object is to
match a salesman's SALES record with this salesman
MASTER record. Thus, the MANNUM field on a SALES
record is defined as a look-ahead field. While processing a
salesman MASTER record, you then look ahead (in calculations) at the unprocessed SALES record to determine if

No
(select next
primary file
record)

FORCE the
SALES record
to be processed

'"
No
(select next
primary file
record)

Figure 7-14. Using Look Ahead to Determine if Records Match

the salesman number is the same as on the record being processed. If they match, the FORCE operation code is used to
process the SALES record as if RPG II logic were performing a matching records job. You then continue to force the
rest of the SALES records which contain the same salesman
number. For each record, look-ahead is used to check the
MANN UM field to determine if the SALES record should
be forced. When look-ahead indicates that the next SALES
record is for a different salesman number, the SALES record is not forced. Instead, RPG II takes over to select the
next primary file record which is either another salesman
MASTER record or the next district record.

/

(

"7-16

)

shown. To actually prepare the report, you would need file
description specifications to define the files and additional
calculation and output specifications to accumulate totals
and print the data.

Now that you und~rstand the steps involved in this program,
look at the specifications in Figure 7-15. The Input sheet
describes the records in each file and defines the look-ahead
field for the SALES records. Only the calculations necessary to determine which record is to be processed next are
RPG

IBM

GX21·9094

INPUT SPECIFICATIONS
1

2

75 76 77 78 79 80

Program

pageDJo,_

Date

Programmer

I

!l

...~

~

5

7

8

9 10 11

1

1M AS T'~iR

2

I

o

~-;;

2

1

Field Location
3

:E-.""0

~

~
~~~
z u u

Position

Z

§.~ 8
z 0 ~

0

Zo~

Position

Position

~§~

go

~§

[;l

:~

Q;

!:.

~ ~ E:

From

To

Field Name

~~~

'2
0

~llL

11

1i'S1

7

I

5

I

6

I

3'

7

I

o

8

I

10
1m

2~

o

9

I

27·

~~- 2"

I

'Qj2.N ~21

1*
15 A' J:S

0

:9-8 ~

.~ ~
u.u.

I:r
~6

AA

II

113

I

"s

Ih

1 3

I

1112

1 4

I

1 5

I

1 6

I

AlA

*~

.~~

Salesman
master record

NA f'1F

/'"'~

l! ,

In TA

:

l':::~

..

1M

LlIN

r'

SALES record

1/

Look-ahead field
on SALES record

la~l1 III" I~II,,~

International BUlines. Machine

1-1-

Form GX21-9093
Printed in U.S.A.

CALCULATION SPECIFICATIONS

Corpor.t~on

1 2

pageDJof_
Date

Programmer

Indicators

~

~
8.~

Result Field

Jd Jd

~

Operation

Factor 1

E~

:E :;

Factor 2
Name

>-'
... "0

5

~~+-

I I I I I I I I I I

Program

4

u:

OS T'N liM

Qrf, M.1 1\11\1 1M

Ie,

RPG

3

Zero
Plus Minus or
Blank

District record

T

Line

"0
0;

rM

I

C

"E

!

DC; r'M GR

2~

~.

1 2

r-

Field
Indicators

0

I
5'fi"l ns TI~ JIM
I'; 2() "I "'TA

B

I

IBM

c:

IIIIII

ro!f)

3

-

~
g
.3

g

4

11

~

0

~

"0

~~~~:~':ation I

16 17 18 1920 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 6364 65 66 67 68 69 70 71 72 73 74

o
o
o
o
o

~
=5

"O'ii'"A'No
12 13 14 15

o

1 0

)

6

i
Jl

Filename

Line

4

Record Identification Codes

~
]

~

3

U/M 050'

Printed in U.S.A.

International Business Machine Corporation

15

15

Length

ce ~
g~

'u

15

~

Resulting
Indicators
Arithmetic
Plus IMinusl Zero
Compare
1>2/1<211-2
Lookup(Factor 2)is
High Low Equal

75 76 77 78 79 80

~~~~~:ation I

IIIIII

Comments

,f8

z

6

9 10 11 12 1314 15 16 17 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 5657 5859 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

7

0 1

c

o

2

Clf

o

3

c*

o
o

4

c~

6

C

o

6

C

z

NIZh

z

o :x:

Mod AiAI

M

',..", MP

kN II fill

~3

1

21~

Ir=h IQr IF .C; IAI Fe;
I~

\
If salesman numbers are the same (23 on),
force the next SALES record.

\

\
\
If salesman master record (02) or SALES
record (03) being processed, check salesman
number on the next SALES record

Figure 7-15. Using Look Ahead to Match Records

)
Programmed Control of Input and Output

7-17

Processing a Primary, Then Matching Secondary Records
Before Matching Primary Records

Another reason for looking ahead to determine which record to process next is when you want to process the files in
an order other than the usual order of matching record
logic. In such cases, all files must have match fields. The
match fields on the next records available for processing
are looked at to determine which record will ordinarily be
selected and, thus, if it is necessary to force a record instead.
To illustrate altering the order of matching record logic,
let's consider a sample billing program in which the records
are to be processed in a particular order. However, note that
the example is presented only to show you why and how
look-ahead fields are used to determine whether a particular
file should be processed. Actually, the desired results could
also be obtained by processing the records in a different

4C

01

order using the normal RPG II logic. We are not necessarily
suggesting that your files be organized in the same way for
your billing purposes. In fact, it is possible that the files for
the sample program could be organized in a different way
such that look-ahead with FORCE would not be necessary
to process the records in the desired order.

Organization of the Files: The two files for the billing application (Figure 7-16) can each contain two record types.
The primary file (F I RST) contains a name and address record for every customer (record type 01) followed by the
customer's charge record (record type 02) if any purchases
were made during the month. The secondary file (SECOND)
contains one record for every customer showing his previous
balance (record type 03). If the customer is entitled to a
discount, a record containing his discount rate follows the
balance card. As you can see, both files are in ascending sequence according to a common match field containing the
customer number.

998

735 GEST BRUCE 4856
NINTH STREET MPLS MN
02

5E

396

L_B__

15

04
____
2_76--...

C 631

3D

01

0000

450

N 631 DEAN THOMAS 986 OAK
GLEN DRIVE ST PAUL MN

6875

N 563 CARLSON V 46 FIRST
AVENUE HOPKINS MN
4B

3A

03

02

I

297

940

' R e c o r d Type 02
(Charge Record)

~----------------------~
N 402 AKRE J 311 HAWK
INS DRIVE BRAINERD MN

lJ

Record Type 01
(Name and Address)

-------10-----------.,

B 402

2986

Figure 7-16. Files With More than One Matching Record

J

I

.-

1-

FIRST file

--nTr
_1. . . .I-+-I+-IJ

J-._ _ _ _ _ _ _ _ _ _ _

1-

7-18

I

754

SECOND file

Record Type 04
(Discount Record)

R
Record
Type 03
(Previous Balance)

/

Page of GC21-7567-2 "
Issued 24 May 1976
By TNL: GN21-5389

The specifications in Figure 7-17 define the files for this application. As entries in col umn 18 of the In put sheet show,
record type 02 (charge records) in the primary file and record type 04 (discount record) in the secondary fi Ie mayor
may not be present for a particular customer. The use of
the look-ahead fields defined on lines 11-12 and 19-20 will
become clear as we explain the program.
File Description Specification
File Type

F

Mode of Processing

End of File

Record Address Type

Sequence

Filename

Type of File
Organization
or Additional Area

File Format

Uno

~

8-

Block
Length

~
~
(l

File Addition/Unordered

Extent Exit
for DAM

Length of Key Field or
of Record Address Field

File Designation

Record
Length

~

;;:

Key Field

~

~ ;:;,

Device

o

2

o
o

3

~
"2

Staning

~

Location

W

Continuation Unes

K

Option

R~G

INPUT SPECIFICATIONS

configuration

GX21"9Q94"2 u/M 050·
Printed in U.S.A.

International Business Machine Corporation

1

Program
Programmer

Page

Date

~

I

Filename

Line

~

)

S

j

t-

::~

Or;- ~ b
Ar,;j)"

6

~

3

4

7

o
o

1

IF

2

I

3

I

8

2

1

~

c:

~

0

~~j

Z

U

U

Position

-

~

~~ E
~uc5

Position

~~

~ U

"iii

"From

Field Name

,f

To

Jii

IR S1

NS

~1

11 CAl
3
17

25

5~ CU SN

22 NA ME

I

o

7

I

3

o

8

I

'1

o

9

I

1 0

I

51~ CU SN UJ.A il
8 I l ElM
11 1(lJIGrrv
V; 12. CHA R~E

3

:5K:lJ NX TN ON

1 4

IS
I

1 5

I

0

] ~~

~

]
I:i
~~

:;;u

"0

Zero
Plus Minus or
Blank

0;

ii:

'-'i4 ST RE EiT

6

1 3

Field
Indicators

uM Ll Ml

I

I

~

IIIIII

0

8

C

I

I

~~~;~f:'tion I

9 1011 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 JJ J4 35 J6 37 J6 J9 40 41 42 4J 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 6364 6566 6768 6970 71 72 73 74

4

1 2

of_

c:

g

~

"M

5

11

75 76 17 78 79 80

Field Location

ii
Position

2

[D

3

€·o

~.g ~

j
5

Record Identification Codes

~

~

•

Entry

4

IBM

o
o

Tape
Rewind
File
Condition
Ul-U8

Core Index

-3

4

3

o
o

Number of Extents

W

Overflow Indicator

0

Symbolic

Device

..J

Number of Tracks
for Cylinder Overflow

Name of
Label Exit

NS

EC OND

~2.

IAA

fl'~

NS

~3

1 CC

46

1(2)
13
1 ~B

6

N5

~q

11 CD

18

6~

CT YS irA

8rtJ eN UM IflR Ll ~:l

2:1 1B ~L NeE

1 6

I

1 7

I

6

1 8

I

11

12 1D SR AilE

1 9

I

2 0

I

16

80 NX Ire ST

BB

~~

, M'

:8:¢ (N ~M BR :LlIMl

Figure 7-17. Force With Look Ahead: Process Primary, Them Matching Secondaries Before Matching Primaries

)
Programmed Control of Input and Output

7-19

Page of GC21-7567-2
Issued 24 May 1976
By TNL: GN21-5389

Determining the Order of Processing: To produce a bill,
a customer's name and address are to be printed, followed
by his previous balance (Figure 7-18). Any additional
charges for the month are to be added to the previous balance to obtain a new balance. Some customers are entitled
to a discount, which must be determined before adding the
monthly charges to the previous balance.

If the two files are processed by RPG II logic according to
matching records, all matching primary file records are processed before any matching secondary file records. In other
words, first the name and address record is selected, followed by any charge records. Only after processing all the
primary records for a particular customer are his balance
and discount records processed.
Providing a customer has no charge records, the order of
processing determined by RPG II is correct. That is, after
the name and address record (the only primary record with
the same match field), the balance record from the secondary file is processed. If there is a discount record with the
same match field, it is then read, even though the discount
data is not necessary when there are no charges.

the look-ahead match field (NXTNUM) on the primary file
record not yet available to the match field (CUSNUM) on
the name record being processed. If the fields are equal (indicator 21 set on), you must force the balance record (line
02 of Calculation sheet).
While the balance record is being processed, you must determine from which file the next record is to be processed.
To do this, calcylation line 05 is performed. If there is a
discount record in the secondary file for this customer, the
match field on the next available secondary file record will
be equal to the match field on the balance record being
processed. Thus, the look-ahead match field (NXTCST) for
the secondary file is compared to the balance record match
field. If equal, indicator 22 is set on, indicating the next
available secondary record (a discount record) should be
. processed. Whether to force the discount record depends on
whether there are still primary file records which match. If
there were charge records in the primary file, the balance
record being processed was forced and, thus, indicator 21 is
still on.

On the other hand, for customers who have incurred charges',
the order of processing the matching records must be altered.
Instead of·processing all matching primaries before the matching secondaries, only the first primary record is processed.
The matching secondary records are then processed, followed by the remaining matching primary records.

ABC COMPANY

DATE

10-25-68

AKRE J
311 HAWKINS DRIVE
BRAINERD MN

/'

ITEM OTY CHARGE PREVo BALANCE $
Determining When to Force A File: The calculation and
output specifications to process the records anp print the
bills are shown in Figure 7-19. For every customer group,
the name and address record (record type 01) from the primary file is read first and printed at the top of thebilling
form. RPG II logic automatically selects this primary record as the first to be processed.

You want customer's balance record (record type 03) from
the secondary file to be processed immediately after the
name and address record. What you must determine then,
while the name record (record type 01) is still being processed, is whether the balance record dm be selected normally or if it must be forced. ,You know that if there is a charge
record for this customer in the primary file, it has the same
match field as the name and address record. Furthermore,
if there is a charge record with the same match field, this
record will be selected for processing rather than the secondary file balance record. Thus, while processing the name
record, you must look-ahead at the next available primary
record to determine if its match field is the same as the
match field of the record being processed. To do this, line
01 of the calculation specifications (Figure 7-19) compares

7-20

3A

02

8.46

4B

03

2.67

BALANCE DUE

ABC COMPANY

DATE

$

29.86

40.99

10-25-68

CARLSON V
46 FIRST AVENUE
HOPKINS MN
ITEM OTY CHARGE PREVo BALANCE $

7.54

Figure 7-18. Bill Showing Order in Which Data Must be Printed

Page of GC21-7567-2
Issued 24 May 1976
By TNL: GN21-5389
RPG

IBM

Form GX21·9093

CALCULATION SPECIFICATIONS

Printed in U.S.A.

International Business Machine Corporation

1 2

Program
Date

Programmer

C

~

Line

Page

Indicators

~

~
~~
>-'

At

.g

Factor 2

Operation

Factor 1

I- "0

E

~

zs

.fa
3

4

5 6

a
o

1

C

2

C

o

3

C~

o

4

C~

o

5

o

6

c
c

a

7

c~

o
o

8

c~
c~

9

11

J:

Plus IMinusl Zero

~~

r

r,..

1M

JISN

MP

':'" Q~

~B

c~

1

r.

MRI~

Irl\l

rr

22

2.1

IN

~2

2. 12

~12

2~

Mlp

y~S

R.~~

-

fl.F r'EIR IRA

",r"

,.

"1"\ I,. I...
1\,.,

1,.1,.

RlA 'N ~I~

rvJJ IUr

":'i RA rrl=

'c;.lJlA

D~ rNtr

AolD

r

RPG

OUTPUT

I...

N
I_~

~

...

~2~

,[F

32.

R~

~

AD

Dr 5~M
!R14 Nif- r;

1-

42

I

At"I,Q

T'""

R''; ,.
IR~

J:I'\

N

R~ rh IR"

rll. "

r I'IA ~,..

'"
P,R E.V

NT

I.. I~ 1,..,-

lBlA

GX21·9QS02 U1M 060·
Printed in U.s.A.

SPECIFICATIONS

International Business Machine Corporation

12

Page

Date

~ Space

~~
e-""
~ Ai

Filename

Line

~ u;~

~

I-

I-

~

•

N~.

~lQ

12.12 rs rrlu FIRJ: A 'ns ~tr
IY~ c;- IF''"' R"'~
R£ r?

~l' IT" 1ST

J:'-' Q~ ...

,.

~12

0

5

A. rf-jG

RE' blR 1)'1 TF

fF IBl4 Ii-IN" '1= '"

Programmer

)

-H ~RIF

L~ IIts

NX ITIN M
J:lc;~

Program

-

Comments

Compare

1>211<211-2
~~ LookuplFactor 2lis
'u e :I: High Low Equal

I

(zl3

c

1 1 1 1 1 I

Arithmetic

1=1"'1 Rrl,;

1 3

IBM

z

Qll
Qll 121

1 2

4

s

0

z

:~~~f:tion 1

9 10 1112 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 33 J4 35 36 37 J8 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 5651 58 59 60 61 62 63 64 65 66 61 68 69 10 11 12 13 14

7

c
c

1 0

Length

Name

75 76 77 78 79 80
of_

Resulting
Indicators

Result Field
~

At

OJ

3

4

o
o
o
o

1

6

2

0

3

a

4

0

o

5

0

o
o

6

0

7

0

o
o

8

0

o

9

0

0

11

0

1 2

0

1 3'

a

1 4

0

1 5

0

1 6

0

1 7

0

1 8

0

1 9

0

2 0

a

11

~

~~

Field Name

~

"A 0'0 ~
~

0

0

z

z

0

z

1

8

·AUTO

10

1(?j5

End
Positon
in
Output
Record

~

."
w
."

9 10 11 12 13 14 15 16 11 18 1920 21 22 2324 2526 21 28 2930 31 32 33 J4 35 36 31 38

IL LS

v

lj

li

r;-~to

08

1 0

R

~

....

Output Indicators

Skip

1~ll

rn

3

laJll

D 13

~13

~

rtJ2

l6~

Zero Balances
to Print

No Sign

CR

Yes
Yes
No
No

Yes
No
Yes
No

1
2
3
4

A
B
C
0

-

X

E

J

Y

~

K

L
M

I. 1 1 1 1 I

Remove
Plus Sign
Date
Field Edit
Z = Zero
Suppress

a:
-'

Constant or Edit Word

en

Q:

9 40 41 42 43 444 5 46 41 48 49 50 51 52 53 54 55 56 51 58 59 60 61 62 63 64 65 66 61 68 69 10 11 12 13'14

~A [ME

ro 11

r

Commas

757677787980

:~~~f~cation 1

of _

~l

UM ON n-H

D

OJ

vD ~V
ulv EA R'

lJ

h

~~

I.

lij
1

Srr R,E EI

2.5

~T )/S T~

2~

8A LN CEIJ
:Iir E.M

~~

iGTY

2(l

CH AR GIE!

8

I~

L

Print name, address, and date

I

Print previous balance
I
I

35

I

Print monthly charges
I

I

I I

I

I

I

I

I

I

I

lj.,J.
!BA LN ~E IJB

60

}

Print accumulated new balance
when name and address record
for next customer is read
I I

I

I

I

I

I

I

I

I

I

I

Figure 7-19. Specifications for Processing Matching Secondary Records Before Matching Primary Records

Programmed Control of Input and Output

7 -21

The FORCE of a discount record on calculation line 06 is
conditioned, then, by two resulting indicators: 22 on means
there is a discount record to be processed and 21 on means
that the discount record must be forced since the balance
record was forced.
After determining which file is to be processed next and,
then, whether that file is to be forced, output processing
continues for the record being processed. That is, the balance is printed on the bill.
Providing a discount record is present, this record is processed next. No calculations and output are performed for
this record, however. The discount rate (DSRATE) is merely
stored so that data can be used to calculate discounts when
charge records are processed.
In the next program cycle, RPG II logic determines which
record to process next. If there is a charge record in the
primary file, this record is selected since its match field is
the same as the match field on the previously processed
record.
When a charge record (record type 02) is selected, the first
step is to determine if the charge is to be discounted. If a
discount record was processed for this customer, indicator
22 is still on. Thus, the calculations on lines 10-11 are performed only if 22 is on. The charge, whether discounted or
not, is then added to the previous balance to accumulate a
new balance (line 13). The individual charge is then printed
and any remaining charge records are processed in the same
way.
When all charge records for this match group are processed,
a name and address record for the next customer is available
in the primary file, while his balance record is in the secondary file. As before, since both records match, RPG II
logic selects the primary file name record to process first.
Referring to the input specifications for this program, the
customer number field on the name record was assigned as a
control field, as well as a match field (see Figure 7-17).
Since the customer number on the name record just select~d
differs from that on the previous name record, a control
break occurs. Before processing the name record for the second customer, then, total operations for the previous group
are performed. Thus, the output specifications in Figure
7-19, line 13, cause the new balance (which has been accumulating for every charge record processed) to be printed
on the customer's bill.

Effect of Forcing on the MR Indicator

In this last example, we assumed that for every customer,
there is at least one record in the primary file (name record)
and one record in the secondary file (balance record). For
every record processed then, there exists a matching record
in the other file'.
Although a matching record condition actually exists for all
records, the MR indicator is not necessarily turned on for
every record. When RPG II logic selects records in the usual
order, the MR indicator is on during the processing of these
records. However, MR is never turned on for a record which
is forced. If a file is to be forced, the RPG 1/ logic doesn't
even compare the two files and, thus, doesn't determine if a
matching record condition exists. A forced record is processed, then, as if it contained no match fields.
The last example did not require that any calculations or
output be conditioned on the basis of matching records.
Nevertheless, you must be aware of the effect forcing has
on the MR indicator so you won't incorrectly think MR is
on when it is actually off.

PROCESSING DEMAND FILES (READ OPERATION)

Using the FORCE operation, you can override normal RPG
II logic for selecting records on the next program cycle.
Suppose, however, you want to select records to be processed during the current program cycle. For example, a
company maintains a file of employee numbers, NUMBRFLE.
Each number is on a separate record (Figure 7-20). Those
records containing numbers that are already assigned to employees are identified by a flag (character X in position 8 of
the record). If the number has not been assigned to an employee, the record does not have a flag.
For each record that is read from the fi Ie of new employee
records, NEWNAME (Figure 7-20), one or more records
must be read from NUMBRFLE to find a number that can
be assigned to the new employee. The new number must
be found during the current cycle, since the new employee
record is added to the employee master file, NAMEFILE
(Figure 7-20), after a number is assigned.

,/"--

7-22

)

WILLIAMS

ADAMS
NEWNAME input file
(New employee records on disk)

wi/PM/e

?}!

Read from the demand
file until an unused
number is found

READ

, ~ \ ~\~\ \~%, \~:f}~

)

0065321 X

NUMBRFLE
(Demand file of all
employee numbers)

WILLIAMS
7705220
2066421

NAMEFI LE output file
(Employee master file on disk)

ADAMS
0097694

Figure 7·20. Using the READ Operation and a Demand File to Assign Man Numbers to New Employees

)
Programmed Control of Input and Output

7-23

By designating NUMBRFLE as a demand file (Figure 7-21,
insert A) you can request input from the file as many times
as necessary during a single program cycle. In order to request input, you must use the READ operation code in the
calculation portion of your program (Figure 7-21, insert C).
Each time a READ operation is done, a record is read from
NUMBRFLE.

containing the READ operation will turn on after each
READ operation if an end of file condjtion is reached. In
the example, new employee records are listed on the printer /'
as they are added to NAMEFILE. If end of file is reached
on NUMBRFLE before numbers have been assigned to all
new employees, indicator 77 is turned on and the new employee records to which numbers have not been assigned
are listed with an appropriate identification.

It is possible that end of file for the demand file could be
reached during a program cycle. Two options are available
to handle this situation. In the example (Figure 7-21, insert
C), an indicator has been entered in columns 58-59. An indicator specified in columns 58-59 of the specification line

If an end of file indicator is not entered in columns 58-59,
the program will halt when end of file is reached on the demand file and each time READ is executed thereafter.

File Description Specification
"n,

Fil. Typo

F

File_ D..Igr>ltion

~~;;,;;~ ~':'~;Id

End of Fil.

Sequence

Filename

III

Line

I~

Record Add.... Typo

~ypo of Fil.

File Format

Device

iii

Symbolic
Device

I:!

I~

OT HacKS

,,~

Name of
L bel Exit
a

~Addition.1 At'"-~

i

;moer

Extent Exit
for DAM

I~

~

Core Index

!!.
A 0 in column 16 identifies an input, update,
: 5 .
~
or combined file as a demand file.

,.~ .."

IK

••;~

U. ~M"'~
!~A"

~

I~

!:,!"~~ion
V'°r--

'.'." .... "'''',.~.~'' •• 'N~3'''~"~''.' •• '•• ''.'......'"~ .. "'''_ .. m • • '.'M ... " .... "." ••• ,,, •• ,.,,,.,.,,
FIN~

10 12
I0 13
I0 14

F

If:
~ II"
IE
'-IL rlslr

II'" ,;

l/A\

r~"

~

.1 ... ,.-

N

I~A

1111

Aoh

~IFr"

qb

F 1215 b
~
F 1215 ~ 1 2. P,
1= Ill~~ 11 2~

7AI

~IV

RPG

----l1
J

9ra_m_ _ _ _ _ _- - ,_ _ _ _ _
f-p_ro_
Programmer

-

Date

Punching

Instruction

1

(11

A !2l1

pl~I NTi~IR

Other devices can

INPUT SPECIFICATIONS

Graphic
Punch

I I
I I

I

I

Record Identification Codes

I

J:t

n Ir S J(
II rzjll D II s ~

2

I
I

be used, depending
on the system and
configuration

Page

3

4

o

1

5

I

6

o

2

I

o
o

3

I

4

I

@~

7

8

NII=

9

g

a
Position

_

~

;
~u6
~~

Position

75 76 77 78 79 80

Field Location

';;;

Position

2

[JJoi_ ~~~;~f~ation I

3 '

Filename

Line

1

Card Electro Number

GX21-9094 U/M 050'
Printed in U.S.A.

From

~

To

Field Name

~

]

c:

l5

:2~

i£~

.E ~

:!:u

0

I I I I]

Field
Indicators

0

1~~

'~

I

~

j
."
0;

Zero
Plus Minus or
Blank

u:

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

d

A

... NiS

~lJ.

~Ni5

(2j!2

R

L

S

Iq~

N~ Mf'

1 Nil I........ It-K
e IFIL AIG

IRIp,

Figure 7-21 (Part 1 of 2). Coding to Use a Demand File to Assign Man Numbers to New Employees

(
7-24

RPG

IBM.

I
I

Program

)

Programmer

C

-

Date

=0

.1 Punch

Instruction

.1 I
I I

I I
I I

I I
I I

~~~

Operation

Factor 1

Factor 2

E !:l

5

(J)

~

8 5-

~

6

7

9 10 It 12 13 14 15 16 t7 18 19 20 21 22 23 24 25 26 27 2829 3031 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 5

3

4

o
o

1

C

2

c

o

3

C

8

@c
n I.., I

IBM

Len

Name

r- "0 a:

" "

z

z

It f"'\ ~!P

!'r[i\ Iio'.ciil'i
IRiF
·Cc

lAo I' ~I

NI717

I

r

I

L I 1 1 1 LJ
•

The indicator in columns 58-59 of a READ
specification will turn on each time READ
encounters an end-of-file condition in the
demand file. If no indicator is used, the
program halts each time end-of-file is
encountered.

f

1717!(

~;f>:i

~:L

Iy'

I

OUTPUT

~G

,

GX21·9090 U/M 050'
Printed .n U.S.A.

SPECIFICATIONS
1

Program

o

u:

Filename

Line

Page

Date

r--

Space

i ~he

Skip

Output Indicators

end-ol-lile indicator can be used to

i

condition operations which should or
~ should not be done when the demand
o'R file is at end of file.

:>

~
0::

~ en

345678

o
o
o

2

0

3

0

4

ol~/11

o

5

o

o

6

o

7

o

o
o

8

0

9 10 11 12 13

~ ,~ ,~

17 18 19 20 21 22 23 24 25

261~

Zero Balances

in

~~

~~s

9

0
0

1 1

0

1 2

0

1 7

0

1 8

0

1 9

0

75 76 77 78 79 80
of_

~~~;~;::ation 1
X

I. 1 1 1 1

I

= Remove

';g ; ,- ;;:'::"
~

;':~~ress

Z =

0::

~ ~ ~~~~~ ~

Constant or Edit Word

~

28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

INA'MIE

I
I

!B

!

lip

1 0

;

2

[I]

"';;" .0;:" ,o;.~

II
~~~,on

~~~~r-~--~~~~n-~~-r------~ w m

2 0

75 76 77 78 79 80

Program
Identification

International BUSiness Machme Corporation

Programmer

)

2

['tH,'!;

-1_-

''11'''\ l/otl,..

I

RPG

1

page~Of

I-'Ihp

INlti !KIN I I

Mirl IVE

Prin1ed.nU.S.A.

Card Electro Number

Result Field

AL At

..Jo::

line

Graphic

Punching

Indicators

~

0_

Form GX21·9093

CALCULATION SPECIFICATIONS

International Business Machine Corporation

I

f"IlR
11)

1

~11N17

1/"'\

lL

I'll 77

0

o
o
o
o
o

Figure 7-21 (Part 2 of 2). Coding to Use a Demand File to Assign Man Numbers to New Employees

-~'"

Programmed Control of Input and Output

7-25

Considerations for Using READ and Demand Files
The following files can appear as Factor 2 in a READ operation (all must be designated demand files with a D in column 16 of the File Description sheet):
1.

Sequential disk files processed consecutively and
specified as input or update files.

2.

Indexed disk files processed sequentially by key and
specified as input or update files.

3.

Indexed disk files processed sequentially within
limits and specified as input or update files.

4.

Direct disk files processed consecutively as input or update files.

5.

Console and CRT files specified as input files.

6.

Card files specified as input or combined files.

7.

Ledger card files specified as input or combined files.

8.

Data recorder files specified as input files.

9.

Tape input files.

10.

SIOC input and update files (SPECIAL device).

11.

Teleprocessing input and combined files (BSCA device).

12.

Device independent input files.

6.

When reading from several demand files during the
same RPG II cycle, record identifying indicators assigned to the demand files will remain on throughout
the cycle if the-previous READ operations were
executed successfully.

REPETITIVE OUTPUT (EXCPT OPERATION)
RPG 1/ has a special operation code called EXCPT which
allows you to write or punch as many records as are required during one program cycle.
Normally a record is written or punched at either detail or
total output time. Using EXCPT, records can be put out
during detail or total calculation time. Each time you use
the operation code EXCPT, specified records are written
immediately. For example, if you use eight EXCPT operation codes in succession, you can get an exception output
cycle eight times. The records are identical if the data fields
in the exception records are not altered between the EXCPT
operation codes on the Calculation sheet.
When you use the EXCPT operation code, you also must
specify which records are to be put out during calculation
time. These records are identified by an E in column 15 of
the Output-Format sheet. Only those output lines identified by an E will be put out during an exception output
cycle.

Using EXCPT and *PLACE

When using the READ operation for demand files remember:
1.

Demand files (except those assigned to the Model 6
KEYBORD) can only be processed by the READ
operation.

2.

Control levels, matching fields, and look-ahead fields
are not allowed with demand files.

3.

Numeric sequence testing on the Input sheet is not
allowed for demand files.

4.

The MR indicator may not be entered in columns
63-64 (Field Record Relation) on the Input sheet.

5.

When a demand file is conditioned by a U1-U8 indicator which is not on, no records will be read from
that file and the end-of-file indicator in columns
58-59 will not turn on.

7-26

The reserved word *PLACE duplicates fields and places
them on the same line. In the discussion of *PLACE in
Chapter 3, an example is used in which three mailing labels
were printed for each customer using *PLACE. If you
wanted to print 15 labels for each customer, however, you
could not use only the reserved word *PLACE. The only
way would be to print the same three mailing labels five
times in succession.
In the RPG II program cycle, each record specified is written
or punched only once per cycle. For each record read by
the program shown in Figure 7-22, the detail line specified in
lines 01-04 is written only once. Remember that the *PLACE
entry causes the field to be duplicated. Using *PLACE
one line is printed with three identical names. The same is
true for each of the other records specified. If you want to
print 15 identical mailing labels, you need all records printed
five times each.

RPG

IBM

)

1 2

Program
Programmer

0

"- Space

~I
e -

-""
~ lii

Filename

line

8. ~
~~

~

t-

E

a

.f
3

4

Page

Date

~

5

6

Output Indicators

Skip

~ ~«

At

III

r.t\o'D ~ '!1::;:
R

0

z

0

z

Field Name

L

7

8

II
a:

~ ~

~~

0

z

"AUTO

r.t\~fo

?>

I

End
Positon
in
Output
Record

Commas
Yes
Yes
No
No

Zero Balances
to Print

Yes
No
Yes
No

CD

No Sign

CR

1
2
3

A
C

4

0

75 76 77 78 79 80

~;~~;~f:.tion /

of _

/.

IIIII

X = Remove

J
K
L
M

B

Plus Sign
V = Oate
Field Edit
Z = Zero
Suppress

a:
..J

Constant or Edit Word

III

0::

9 10 11 12 13 1415 1617 18 1920 2122 2324 25 26 27 2B 29 30 31 32 33 34 35 36 37 38 39 4041 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

0 1

Olp IRtr NT

o
o
o

2

0

3

0

11"'1

1=\12.

·N AM~

1115

f*lp Il A rlf

lLlll;-

4

0
0

o
o

6

0

~f"'I OIR

7

0

o
o

8

0

~!p
"'I~
~Ip 1Ll4 rlF'

:n

1~15

f,y-:p I, A Ir I,:

0 5

!2

1315

UA

In

1"7~

IIlLl5*

1.2.

9

0

1 0

0

~1:

1 1

0

F;rr AITE

Trv-

lis
1?l5

1 2

0

v-ID UA rll=

1 3

0

~p Ill4 rlF·

b;5
lllLI5

1 4

0

1 5

0

1 6

0

1 7

'0

1;zI1:ip
~Ip IL A ~F
~Ip II A ~I=

1"715
lLlLl5

1 8

0

1 9

0

2 0

)

GX21·9090 U/M 050Printed in U.S.A.

SPECIFICATIONS

OUTPUT

Internation.1 Business Machine Corporation

1"'\

i~

I~I"

0

0
0
0

0
0
tL IL OL 69 69 L9 99 99

~

£9 ~g Ig 09 69 99 L9 99 99 V9 £!l ~!l 19 Oil 6~ 8~ L~ g~ S~

»

£~ ~~ I~ O~

6£ S£ L£ 9£ 9£

~

££

~£

1£ O£

6~ ~ Ll 9~ S~ ~~ £~ Z~ I~ O~

61 81 L I 91 !ll

~I

£1

~I

II 01

6

8

L

9

9

~

£

~

I

Figure 7-22. Detail Output Operations

Programmed Control of Input and Output

7-27

RPG

IBM

Form GX21·9093
Printed in U.S.A.

CALCULATION SPECIFICATIONS

International BUlineu Machine Corporation

,

Program

Date

Programmer

-c i~
Line
3

4

Page

2

75 76 77 7B 79 BO

[0 of_ ~~~~;~f:ation I I I I I I I

~~i~~;~rs
Arith",~etic

A'~d

A"d

I~ 3<1

51! 1: I~
7 '8

9

Operation

Factor 1

Ix
I:;;

Factor 2
Name

I~
~I .. 115115
117118 19 20 21 22 23 24 25 25

Length

Plus IMinusl Zero
Compare

Comments

1~1'>21'<21'·~

'34 35 35 37 38 39 40 41 42 143 44 45 46 47 48 149 50 51 52

,

:~I~i9~ 5~O;' :::~~ 60 61

52 53 64 65 56 67 68 59 70 71 72 73 74

,

Ie
Ie
J
If
o 3 Ie
0:4
Ie
~
Eaeh time EXCPT is executed, the
four output lines identified by an
E in column 15 are written
01'

0 12

~r

rpT

FX rlpT
~.A

,.,

RPG

IBM

Program
Programmer

I

\

0

\,

~,~ Space

I---

~

Line

Filename

~

f
4 5

6

1 0 1'
10 12

0

10 13

0

1 0 14

0

1015

0

~ 16

,0

\

! ': 17

0

1

lola

,0

013

10

I

7

8

10

0

'1'

0

Skip

~ DO

II-

Graphic

I~

.1
And

1

I~

I~

....
Field Name

~II

-AUTO

End
Positon
in
Output
Record

,*p ~A irE
Aln IDR

3~

*Ip II A 1rJ:
~Ip It A~f.

71.'1

rlr TV
~II '"

Constant or Edit Word

,/

2ls
~~

_I.-

It:.

7l'l

Arf

11~

, 14

0

, 15

0

, 16

,0

fl,r'I

,IA r

,~

75

, 17

0

~p

IL lA rlf

llL .t;

, la

'0
'0

,

ILlL'i"

IAV" ~

10

No Sign CR - X - Remove
Plus Sign
A J V ~ Date
Field Edit
B
2
K
C L Z ... Zero
3
Suppress
0
M
4

2

~p

, 19

Ii

I1II

2

~Ip

21 0

Ves
No
Ves
No

ao

l31'i'
1115
111lS

0

1

Ves
Ves
No
No

75 76 77 7B 79

~~~;~f:ation I 1.1

313:3_34 35 36 37 38 la9 40 41 42 43 1441454547484950515253~555557585950515253~556557~~~ l71 72 73 74

10

12

Zero Balances
to Print

2

[0 of_

-4

NIA IMF.

If

Commas

v

til

I

;l(lp IL AirE:.

If:

'

Page

I

3
1

I'
I'

U1M 050-

Printed in U.S.A.

Card Electro Number

I

Instruction

Output Indicators

I~ ,! ~

9 10 11 12 1 " 1 7 1811920121

vt' IWIl. HI

Punching

I

\

3

GX21·9090

SPECIFICATIONS

OUTPUT

In'"n.';on.' Bu.;n... MOCh;\ Corporo';on

?,
i~IP

~5

0
10
10
,0

-

10

tL IL O. 59 89 L9 99 S9 1>9 &8,Z9 19 09 6! 8! LS 99 S9 1>9 ts ZS IS 05 5t 8t U 9t St tt tt Zt It Ot 6t 81: Lt 9t St tt tt Zt It 01

Figure 7·23. EXCPT Operation Code Used with Exception Records

7-28

sc:

8Z LZ 9Z 9Z tZ tz zz IZ OZ 51 81 LI 91 91 tl tl ZI II 01

6

8

L

9

S

t

t

Z

I

'
)

Figure 7-23 shows the specifications necessary to print 15
mailing labels per customer. The *PLACE specifications on
the Output-Format sheet will cause three mailing labels to be
printed side by side on the paper. Each EXCPT code used
on the Calculation sheet causes all records identified by an
E in column 15 of the Output-Format sheet to be printed
one time in the order shown on the sheet. Because all four
lines are to be printed on the mailing label, all are identified
by an E. The five EXCPT codes will cause five rows of three
mailing labels each to be printed.
Anothe~ set will not be printed at detail output time, because all records having an E in column 15 can be printed
only at calculation time when the EXCPT operation code
is encountered.

Conditioning the Use of EXCPT Operation
There are two ways you can condition an EXCPT operation: (1) on the Calculation sheet; and (2) on the OutputFormat sheet.
The EXCPT operation can be conditioned on the Calculation sheet in the same way as any other operation. As
shown in Figure 7-24, the EXCPT records are put out only
when MR is on.
An indicator used on the Calculation sheet controls the
printing or punching of all EXCPT records. Individual
EXCPT records are controlled by indicators specified in
columns 23-31 of the Output-Format sheet. These indicators are used in the same way for EXCPT records as they
are for all other records.

EXCPT can be used with punched cards or disk as well as
printed output. It operates in the same way in all cases.
Each time the EXCPT code is encountered, output lines
identified by an E in column 15 are executed.

Restriction: Overflow indicators cannot be used to condition an EXCPT line. This means that an EXCPT record
cannot be a record that is printed only when the end of the
page has been reached.

Only output files may have EXCPT records specified;
EXCPT cannot be used for combined files.

Remember, these lines are exceptions. They print only at
calculation time, not at output time. Therefore, they could
/not possibly be printed when other overflow lin~s are.
An EXCPT line may be, however, printed on the overflow
line. If it is, the overflow indicator will be turned on as
usual. EXCPT lines can even fetch overflow. You may
place an F in column 16 of any exception line. If the overflow indicator is on when the EXCPT line having an 'F in
column 16 is reached, all lines conditioned by the overflow
indicator will be printed before the exception line is printed.

)

RPG

IBM

CALCULATION SPECIFICATIONS

Form GX21-9093
Printed in U.S.A.

International Business Machine Corporat!on

,

Program
Programmer

C

Date

Indicators

~

f--

90:

~e

Line

E

~

3 4 I; 6

,

At

~5~
'0 a:

I-

Page

Factor 1

Operation

85

~

en

~

7

8

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

~

Indicators

Factor 2
Name

Length

15

z

1,.11"1

5tT"

~Inl'"

Ir- /rIAll

46

75 76 77 78 79 80

Resulting

Result Field

Jd

2

[]]Of_ :~~f:ationl I 1'1 I I I

47 48 49 50 51

Arithmetic
Plus I MinusI' Zero
Compare
1>211<21',-2
Lookup(Factor 21is
High Low Equal

Comments

54 55 5657 58 59 60 61 62 63 54 65 66 67 68 69 70 71 72 73 74

0 2

c
c

0 3

C

:-,:1"

0 4

C

-,

0 5

C

0

lj'tjiR

IJ:lx ~Iph"

"

1I'Iol

"

- Figure 7-24. Conditioning the EXCPT Operation Code

)
Programmed Control of Input and Output

7-29

./

.r

Review 7·

FORCE

1.

What processing situations would require you to alter normal RPG II multifile logic
by using the FORCE operation?

2.

What two considerations are necessary to determine how the order of processing
must be altered in a program?

3.

Describe what occurs when a FORCE operation is performed.

4.

A commission report is to be prepared listing each salesman and his commission
amount. For each salesman record (MASTER file), there are seven commission
records (COMMIS file). The records are described as follows:

RPG

IBM

GX21·9094 U/M 050·
Printed in U.S.A.

INPUT SPECIFICATIONS

International Business Machme Corporation

1

Program

Date

Programmer

)

Page

Record Identification Codes

a

I
-

~

~
Filename

Line
t-

c:
cJj

r--r-~
o R

~

Z

r;"Nf[)

:2{g

~

Q;

j

u...u::::

~

g

]

.;;;

Position

J

~~j
Z

U

U

Position

-

~

~@j

ZUU

o;

Position

~Cl

~

§

Iii

From

To

Field Name

Cl

4

1

I

0

2

I

z..

0

3

I

7 I~IL IO.L
112 ~IL 102.
1:1 ~Is It 5 NIBR
[38 ~lA M~

6

8

I .. "

IH'")

'-ifR

AlA

f1l:L.I

0

4

I

0

5

I

l~

o

6

I~

0

7

Ir

o

8

I

J

a

9

I

Itt

1

a

I
I

1 2

T

.3

.2

.S~

-£

:~

~~

::;;u

"u:0;

Field
Indicators

Zero

Plus Minus or
Blank

11 'r":l
A
13

1 1

0;

IIIIII

9 10 11 12 13 1415 16 17 18 1920 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

3

a

5

7

~

.a

0

1

c:

..,a

0
0-

.,

';..

~

75 76 77 78 79 80

~~~~;~f:ation I

of _

Field Location
3

2

1

2

OJ

.".1"1 1~

~IB

C1J1

1

rx
I

B~r MR J.\tJ" ~
LI.:'\ (1)1 11'1 NIU""
I/-'Iol SII 5N IBR

Review 7

7-31

Page of GC21·7567·2
Issued 21 December 1979
By TN L: GN21·5709

a. Are the following calculation specifications correct for the required order of file
processing?

RPG

IBM

F",m GX21·9093
Prin1edinU.S,A.

CALCULATION SPECIFICATIONS

'nt,rn'lion,1 BusiMU Machin. Corpor.tion

12

Program
Program"",r

C
I----

011.

Indicators

~

9~

At

-0

line

Page

!~~
gill

Resulling
Indicators
Arllhmllic
~- Plus IMinu.1 Zero
:€
Il ~
Campa ..
Length ... 5 1>211<211-2
~~ Lookup(Faclor 2)i •
2 :;;
OJ: High Low Equal

Operation

Factor 1

At

=

Factor 2

E

•

5 6

o
o
o
o
o

1

C

2

c*

7

3

C~

4

c

5

CH

o

6

c

~

1

f-

-

8

~

757677787960

of _

:~;~f:llion I

0

z

9 10 11'2 13 I. 15 16 17 18 19 20 21 22 23 2. 25 26 27 28 28 30 31 32 33

~1I

-

rlr lI~rr

r1.l7
rzl7 Nl. 1

~-

.~

llA

r:"'"

~

~,.

-

,.~

J

r:r

,.,..,

35 36 37 38 39 40 41 42 .3 44 45 46 .7

AD 07

..

.a

Comments

49 50 51 5253 54 55 68 57 5859 60 61 62 63 64 65 66 67 68 69 70 71 72 73 7.

NT

l~

NT

1~

1.1

ITII"I 1 .IOt
I

I

b. On what condition will a record from MASTER be processed?
c. On what condition will a record from COMMIS be processed?
d. What specification changes must be made to process seven COMMIS records
following each MASTE R record?
e. Is FORCE necessary to process the records? Why?
5.

Consider again the MASTER and COMMIS files as described in question 4, without
match fields. However, assume that, for every MASTER record, there may be any
number of related COMMIS records.
Using look·ahead fields and FORCE, code the necessary input and calculation
specifications for determining the proper order of file processing. Compare the
number of specifications to the number required if the files were processed by
matching record logic.

READ
6.

7·32

I I I I I]

Result Field

Name

.f~5~
3

IT]

List four ways in which a demand file differs from an ordinary secondary file.

/

EXCPT
l'

7.

What occurs when the EXCPT operation code is executed?

8.

In a program, you need to punch a specified number of cards for each item. This
number will be punched in each input card. Refer to the coded Input sheet for
record layouts and code the Calculation and Output-Format sheets for the program.

.I

RPG

IBM

GX21·9094 U/M 050'
Printed in U.S.A.

INPUT SPECIFICATIONS

Intern.tional Business Machine Corpor.tion

1

Program

Page

Oat.

Programmer

Record Identification Codes

I

~
c;
z

I

./

5

6

~6

~~

~u

Position

J

~

~

Cl

~~ a::
1:) t

§ a~

From

...J

g

~

Cl

1

11 N:t- I[ L J;

o

2

I

o
o
o
o

3

I

S~

4

I

11

5

I

6

I

o

7

I

o

8

I

o

9

I

1 0

I
I

1 3

I

1 4

I

1 5

I

1 6

I

1 7

I

1 8

I

1 9

I

2 0

I

Field Name

'2

4

I

~

To

3

1 2

8

~

_C i!!

Position

'0;

o

11

7

°

il

Filename
Position

75 76 77 78 79 80

of_

~~:;~f:ation I

~

]
e
~

.§
0

j2.g
.!!~

"-"-

.~~

"fi

:s

~6

IIIIII

Field
Indicators

Field Location

~

Line

2

[0

~

]

Zero
Plus Minus or

Blank

-c

~

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2B 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

~l

IAA

1 "11

12

7

lrrr IEM AJI~

IS2 0N JM RJ;IR
Iq /0 I'A RD

I
I

I
I
I
U IL OL 69 89 L9 99 59 t9 t9 19 19 09 65

as

L5 95 59 t9 t9 l5 19 09 6~ 8~ L~ 9~ 9~ t~ t~ l~ I~ O~ 6t

at L£ 9£ 5t tt ££ l£ 1£ Ot

til

u a

9l Sl ~l £l l~ Il Ol 61 81 LI 91 51 ~I £1 U

II 01

6

8

L 9

9

~

£

Review 7

l

I

7-33

Answers To Review 7

1.

a. Match fields cannot be assigned to the files and you need to:
• Alternate processing between two files.
•

Process a primary file record followed by a number of secondary file records.

•

Process a secondary file record only when it matches a primary file record.

b. Match fields are assigned to both files and you need to alter the order of matching record logic to process a primary file record, then matching secondary file
records before matching primary file records.

·7-34

2.

a. When each file must be processed and under which conditions.
b. Whether RPG II logic would select the appropriate record or if the file must be
forced.

3.

No action occurs at the time the specification is performed. At the beginning of the
next program cycle, the next record from the file specified as Factor 2 of the
FORCE operation is selected (by being forced) for processing.

4.

a. No, the specifications a.re incorrect.
b. A MASTER record will be processed in every program cycle until end of file is
reached.
c. A COMMIS record will not be processed until all records in the MASTER file
have been processed.
d. Lines 05 and 06 should not be conditioned by record identifying indicator 07.
The COMP operation should be performed for every record type to determine if
the FORCE is to be performed. It may be necessary to force a COMM IS record
following either a MASTER record or another COMMIS record. For this reason,
you must be able to perform the FORCE operation while processing either of
the record types.
e. The FORCE operation is not necessary. The RPG II logic of matching records
can determine the proper order of processing if the SLSNBR fields on each
record type are assigned as match fields on the Input sheet.

5.

look~ahead

Input specifications to define

field:

'\

)

RPG

IBM

GX21·9Q9.I

U/M 050'
Printed in U.S.A.

INPUT SPECIFICATIONS

International BUSiness Machine Corporation

1 2

Date

Programmer

Record Identification Codes

I

2 '

I---

'Field Location
3

~

c:

:~

Filename

Line

Position

~

Position

~~ j

Position

From

To

6

3

4

1

1M A~

o

2

1

o
o

3

1

4

1

o

5

1

o

6

1

o

7

1

o

11

8

1

lll~

o

9

1

12

1 0

1

11

1

1 2

1

.

7

8

~.~

l

.~

Field
Indicators

~

]..,

l·~
~& u:

Zero
Plus Minus or

Blank

0;

9 10 II 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 86 67 68 69 70 71 72 73 74

tr ~,R

1

I'Ir:
i IFIL to!
12. f: II 11"'12.
lL, rts Il5 MiBR

2
R

lll3
ltls
1

~

1"111"1

-

u..u..

c

o

5

] ~~

Field Name

~

~u6

5

75 76 77 78 79 80

pageITlo,_ ~:;~f:ation I I I I I I I

Program

1

IRQ

l3g

N~ ~F=

,.~

.

IrllK AiT'f

~'L

lL"

~",

1-,0

'"'

~u: N~

~

M

N

~N R~
N~t(

I

T

)

Calculation specifications to determine order of file processing:

RPG

IBM

CALCULATION SPECIFICATIONS

Form GX21·9093
Prlnt.d in U.S.A.

International BUlin.ss Machine Corpor.tion

1 2

Program
Programmer

C

~

Line

Date

Indicators

~

0_

Operation

Factor 1

E ~ '"

j:z:

Length

Name

&85~
4

o
o

1

C

2

c

O 3

5 6

7

4

CIJt

5

Cill

o

6

C

..

Arithmetic

Plus IMinusl Zero
Compare
1 >211 <2(1-2
~~ Lookup(Factor 2hs
~ :;;
c:t: High Low Equal

Comments

~ ~

(;
(;
Z
z
9 10 1112 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 81 62 63 64 65 86 67 86 89 70 71 72 73 74

N'A

,.,.,IMP

N'~If'(

Cit

lsN I~'R.

~I

II h hK ~~ "'h IIl1I'11
~l4

12.~

I~IE.I'

Mf- F" 'Rr- E-

C~

o
o
~

8

Indicators

Factor 2

~oti

3

Resulting

Result Field

AL At

=~
~3~

75 76 77 78 79 80

pageITlo,_ ~::~:'.tion I I I I I I I

~

Il.lL

IME ~IN5
AND M lsT

If"IN

TIHlfA!~

N~

~h M~ rl§ 511 I'Ilf\I
J:c::. ~Ir: f'\ RIE: Fn Ri~

X1

IPR ,"V"

'~r~ Irh Dn

Ir

C;

II=~IR.

AN hrr II-IER MA 5rr ER

T!~IE.
RI~

r I IRIA ~ 1\1 IT ~IA It ~ IC;M ~N
IRI[

I

)
Answers To Review 7

7-35

If match field entries had been assigned to the SLSNBR fields on the Input sheet,
input specification lin~s 10 and 11 would not be necessary to define the look-ahead
field. No calculation specifications would be required to determine the order of
processing.
6.

a. ,A demand file is processed only by the READ operation code during calculations.
Demand file records are never selected by normal RPG II multifile logic.
b. Match fields cannot be assigned to a demand file.
c. Look-ahead fields cannot be defined for a demand file.
d. Reading an end of file record (/*) from a demand file does not set the LR
indicator on. Instead, an end of file indicator can be entered in columns 58-59
of the READ specification line. This indicator will turn on each time a READ
is executed which encounters an end of file condition in the demand file.

7.

Immediate output for specified records occurs. These records are coded as exception records by an E in column 15 of the Output-Format sheet.

8.

See Specification sheets.

RPG

IBM

Form GX21·9093
Printed in U.S.A.

CALCULATION SPECIFICATIONS

Intern,tion.1 BusiMIf MKhine Corporation

1 2

Program
Olle

Programmer

-

C

Indicators

~

!l
>

Line

~
E
..J

3

4

Factor 1

Operation

5 6

0 1

C

o
o
o
o

C

5

o

6

o

7

A

~

2
3

C

4

c
c
c
c

~IT ~IRrr

/

I

54 55 56 51 58 59 60 81 62 63 64 65 66 67 68 89 70 11 12 13 14

rr~IG

I=r ~Ipir

(ll
~1

tZl

Comments

Compare

1>21<21-2
LookuplFlclor 2li.

High Low Equal

9 10 1112 13 14 15 16 17 18 19 20 21 22 23 24 25 26 21 2829 30 31 32 33 34 35 36 31 38 39 40 41 42 43 44 45 46 41 48 49 5051

7

-

IBM

Length

~

~

Indicators

Plu. JMinu.lzero

Factor 2
Name

~

~5

S 1 lA

L

r;h iTh

~I ... AR~

RPG

OUTPUT

rlla:;

N

GX21·!J090-2 VIM 050·
Printed in U.S.A.

SPECIFICATIONS

Intern'lion,1 Business Machine Corporation

1

2

75 76 77 78 79 80

Program

pageDJo,_

Dale

Programmer

-0

Skip

Output Indicators
Field Name

Line

~

in
Output

E

Record

.f
5

6

3

4

o
o

2

0

3

0

f-.---"'
T"""II I
~r
End
Positon

Filename
l-

1

8

[?>

Commas

Ves
Ves
No
No

Zero Balances
to Print

Ves
No
Ves
No

No Sign

CR
A

J

B

K

0

L
M

e

~~;~f:llion 1

I. 1 1 1 1 I

X - Remove
Plus Sign
V - Dale
Field Edil
Z
Zero
Suppress

-

a:
:::;

~

Constant or Edit Word

9 10 II 12 13 14 15 16 11 18 1920 21 22 23 24 25 26 21 28 29 30 31 32 '3334 35 36 31 38 39 4041 4243 44 45 46 41 48 49 5051 52 53 54 55 56 51 58 59 60 61 626364 6566 67 68 69 70 71 7273 74

~II

7-36

I I I 1 1 I

Arithmetic

At At

E~

~~:;~':llion I

Resulling

Result Field

I- 0

.f8

75 76 77 78 79 80

page,DJo'_

\
Chapter· 8. Tables
....\

)
CHAPTER 8 DESCRIBES:
Uses for tables.
RPGII coding used to search tables.
Designing table input records .
. LOKUP operation code.
Use of table data in calculations and output operations.

BEFORE READING THIS CHAPTER YOU SHOULD BE ABLE TO DESCRIBE:
RPG II object cycle.
Matching records processing.
Use of indicators to condition, operations.

'AFTER READING THIS CHAPTER YOU SHOULD BE ABLE TO:
State uses for tables.
Define a table on the Extension sheet.
Code problems using a single table.
Code problems using related tables.
Define and code the LOKUP operation code with tables.
Describe data and store it in a table.
Note: You can use the review questions contained in Review 8 at the end of this
chapter to test your comprehension of the chapter. Answers follow the review
questions.

Tables

8-1

INTRODUCTION

Search Word
/'

If you wish to make a telephone calltoaperson; you must
first determine his telephone number. Imagine trying to obtain the number if no telephone directories were available!
For such reasons, similar items of information are grouped
and organized so they can be'referen,ced easily and qU-ickly.
A table is a collection of related data organized in such a
way that each item of information can be referenced by its
position within the table. A telepho-ne directory consist~ of
two tables of information:' a narre'listarrarigedalphabeti~ :
cally and a number list arranged in no apparent order. Each
telephone number, however, occupie's ~ po'sition in the number list corresponding to the position of a particular name in
the name list.
Each item within a table is called a table element., Thus,
each name would be an element of the name tabl~, while
each number would be an element of the telephone number
table.
If you wished to determine Ken Adams' telephone number,
you would look through the list of names to locate KEN
ADAMS. This procedure of checking the elements ofa '
table one at a time to find a particular entry is called searching a table. Before looking through the name list,-you must
know what information you wish to find, the name KEN
ADAMS. This data is referred to as the search, word. '
As shown in Figure 8-1, the name list is'searched to find
an entry which is equal to the search word. The matching
entry, KEN ADAMS, is found in the third element of the
name table. His corresponding telephone number, then, is
found by selecting the third element in the number table.
When two related tables are used, as in a telephone directory, actually only one table is searched (name table). When
the search condition (in this case, an equal match) has been
satisfied, the data in the corresponding element of the second table becomes available. Thus, the first table is used as
a means of locating data in the second table.
A telephone directory is an example of tables which organize information that we must reference over and over again
in our every day lives. Likewise, tables can be used to organize data which must be referenced repeatedly in your
data processing jobs.

8-2

NAME Table

NUMBE R Table

ABRAMS JOHN ,~

286-6424
289-2933

ADAMS KEN

•••

• 938-7515

ANDERSON THOMAS E ••

935-8381

BABITT ROBERTA • • •

288-7587

BARSNESS RICHARD • • •

938-3932

WIK GAl L

288-4663

• • • • . • • • •

Figure 8-1. Searching a Table

Let's assume that customers have purchased various items
from a company ~ales,~atalog. The sales file (Figure 8-2)
would contain records showing the customer's account number(CUSTMR), the item ordered (lTMORD), identified by
a code, and how many were ordered by that customer
(OTYORD).
Furthermore, the company keeps an inventory file (Figure
8-2) to contain data about each item which is carried in
stock. A separate record is kept for each item showing the
item code. (ITEM), the quantity on hand (OTYSTK), and
the unit cost of each item (COST).
Before you can ship the customer's orders, you must first
determine if the item ordered is still carried in stock. To do
this, a clerk could spend time looking up each item ordered
to see if that item is recorded in the inventory file. However, the same item will probably be ordered by many customers. Thus, the same inventory file records would have
to be referenced over and over again.

INVNTRV File'

SALES File

)

Record

Record

2

2

3

3

4
I

Z 31 5

37

"'~ZIlI"'5""""20'

4

CUST~

QTVORD
ITMORD

6

6

7

)
8

2600

1:10

•

IZI') I. 15 "

1

•

\' "
ITEM

\

11 II t9 :0

'

COST

~TVSTK

Figure 8-2. Data for Determining if Orders Can be Filled

)
Tables

8~3

Searching a Single Table

Designing Table Input Records

RPG II can search for the data in much less time by per: '
forming a table lookup function. As shown in Figure 8-3, ~
a table (TABITM) would be set up in sto'rage to contain ali
of the items available (see Loading Tables in this chapter
for methods of loading table data into storage).

Data used to create a table must be obtairied from table input records. These records can be taken from the~eyboard
or CRT, punched ca'rds, m'agnetic tape, or disk. The records
are read by the computer and entries are placed side by side
in storage to form the table.

The second field ,of each sales record tells the program
which item to look up. For every sales record read into th~
computer, TAB ITM is checked to see if the search word
(item code on the sales record) matches an entry in the
table.

The inventory file for this company indicates that 98 types
of items are carried in,stock. Therefore, the 98 item codes
must be contained in table input records to provide the entries for TABITM.

In addition to searching for data quickly, use of the table
lookup can often reduce the number of RPG II specifications needed in a program.)~11 you must~ois, set"up ,and,
define the table, and specify that the lookup operation is.
to be performed.

Number of Table Input Records Required fo.r a Table

/

How many records would be 'necessary to punch the 98
item codes? That is entirely up to you. The number of
records required to contain the table data depends on the
number of entries you want on each record.

TABITM
!

,

A 23

.'

A87 '
B 21
B 83'
C46

C 72
C89

!

Search

Y 33

Word

Y 58
,2i7

"F\,o"'''~m
CUSTMR

ITMORD

QTYORD

SALES record
Figure 8-3. Searching a Table for a Particular Data Item

8·4

Number of Entries on a Table Input Record

Table input records may either contain one entry or a number of entries. The point to remember is that all table input
records for a single table must contain the same number of
entries, except for the last record.
The use of one entry per record is very convenient if it is
necessary that the entries be in a particular order. Then to
add or delete entries, you merely add or remove a record.
Otherwise, you would have to recreate all of the records
from the point of change to the end of the table. However,
in the TABITM table, item code entries need not be in order,
so including ~~mber of e~tri~s in each record reduces the
number of records required.

a

For TABITM, 98 entries must be recorded on table input
records. If 96-column cards are used, 32 entries fit on each
record, since each item code is three characters long. Therefore, to save card space, you could punch three table input
records containing 32 entries each and a fourth table input
record for the remaining two entries. (See Figure 8-4.) In
this way, all records contain,the same number of entries
except the last record.
Of course, you do not have to fill the entire record with entries, as we have done. For instance, you may want the last
36 columns of a card to contain no punches. In that case,
you could punch 20 entries (card columns 1-60) into each
of four table input records. The remaining 18 entries could
then be punched into a fifth record.

Notice in Figure 8-4 that the two entries in the fourth table
input record are placed side by side. Since there are unused
card columns on the record, why not space the entries?
You cannot, because all entries must be continuous on the
record, with no blank columns between entries. Furthermore, the first entry on each record must begin in position
one.

)
2 Table
Entries

Describing Table Input Records with Extension Specifications
Once the table input records have been designed, you then
describe them to the RPG II Compiler program. Ordinarily,
the data on input records is described by entering specifications on the Input sheet. However, you describe the data
on table input records by coding extension specifications
on the upper half of the Extension and Line Counter sheet.
(Hereafter, we will refer to the upper portion of the form
as the Extension sheet and the lower portion as the Line
Counter sheet.)

Records

1,2 and 3
32 Table
Entries

Figure 8-5 shows the extension specifications needed to describe the table containing item codes. As you can see, a
single table can be described using only columns 27-45. Of
course, remember that the page and line number (columns
1-5) and form type (E in column 6) are also part of the entire specification line.

Figure 8-4. Four Table-Input Records for TAB,ITM Entries

)
RPG

IBM

EXTENSION AND LINE COUNTER SPECIFICATIONS

formX21.gog1
Printed in U.S.A.

IntematK)nal Business Machine Corporation

1 2

Program
Programmer

Page

Date

[0

75 76 77 78 79 80

Program
Identification

of_

rTTTrn

Extension Specifications

E

Record Sequence of the Chaining File

t--Line

Number of the Chaining Field

To Filename

8.

~

From Filename

~
3

4

5

6

0 1

E

o
o

E

2

3

E

0 4

E

0 5

E

0 6

E

0 7

E

0 8

E

7

8

Table or
Array Name

Number
of
Entries
Per
Record

Number
of
Entries
Per Table

Length
of
Entry

j~

:§ ~ ~

~~l

or Array

Table or
Length
Array Name of
(Alternating
Format)

Entry

~

~0: j

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 4344 45 46 47 48 49 50 51 5253 54 55 56

riA IPJlr rr~ 132.

Iq~

I~

Comments

fl

5i

~S6S600~~~~~S6~S6S6ronnn~

Irrr I~IM

Ir

'L I~I~

lIN sh"lJ<

,

E
E

-"
)

Figure 8-5. Describing Table-Input Records

Tables

8-5

The extension specifications provide the following information about each table to be used:

1.

Name of each table (columns 27-32).

2.

Number of table entries per table input record (col.'
umns 33-35).

3.

Number of table entries per table (columns 36-39).

4.

Length of each entry (columns 40-42).

5.

Whether packed or binary data is contained in the
table (column 43).

If possible, it is helpful to assign table names which are
meaningful. For this example, the name TAB ITM has
been assigned. Such a name gives an indication of what
kind of data is contained in the table (in this case, item
codes).
When a single table is being used, as in thi~ case, the table
name is entered in positions 27-32 of the Extension sheet
(see Figure 8-5).

Number of Table Entries per Table Input Record

6.

Number of decimal positions in each num~ric entry
(column 44).
" ,

7.

Sequence of table entries, if any (column 45).

Each type of entry will be discussed in turn. 'From Filename (columns 11-18), To Filename (columns 19-26), and
the entries in columns 46-57 are described later in this chapter.

Assigning Table Names

Every table used in a program must be assigned a name
from three to six characters long. The table name may contain any combination of alphabetic characters and numbers.
However, the first three characters of the name must be
TAB.
With these points in mind, which of the following table
names are not acceptable and why?
TABA

15ABCD

TABC

TABSTATE

TB123

*TAB

TAB$2
TAB C and *TAB are not acceptable, as table names ,cannot
contain blanks or special characters, such as the *. TAB$2,
on the other hand, is an acceptable table name, since $ is
one of the three special characters which can be considered
an alphabetic character. (The other two are # and @.)
The names 15ABCD and TB 123 are invalid because they
do not begin with the alphabetic characters TAB. Since
TABSTATE contains more than six characters, it cannot
be an acceptable table name. T ABA and T AB$2 are the
only two valid table names shown.
8-6

The number of entries in each table input record is specified in columns 33-35. Figure 8-5 shows 32 entries per record for TABITM. In this way, the compiler program will
exp.ect all table input records to contain 32 entries, except
the last record which may have fewer entries. Notice that
,the number entered in these columns should end in column
35.

Number of Table Entries Per Table

The number of entries which can be contained in the entire
table is entered in columns 36-39 of the Extension sheet.
As shown in Figure 8-5, the number (98 for TABITM) should
end in column 39.

Length of an Entry

The length of each table entry is indicated in columns 40-42,
with the number ending in column 42. Numeric table entries may be up to 15 digits long, while alphameric entries
can be as long as the maximum record length for the device
(256 maximum).
For TAB ITM, the length 3 has been entered. It is possible
to specify only one length. Therefore, this necessarily means
that all entries in a table must be the same length.
At this point, you may be wondering what to do if all entries are not the same length. For instance, you might wish
to make a table contain,ing the months of the year. The
solution is simple - all entries are made.to be the length of
the longest entry . .The word SEPTEMBER contains the
most characters. Therefore, each entry should be 9 characters long. To make JUNE an entry with length of 9, you'
would place 5 blanks after the letter E (see Figure 8-6). Inserting extra blanks to lengthen the data entry is referred to '
as padding with blanks. If your table entries were numbers,
instead of letters, you would pad the short entries with
zeros or blanks. (For numeric entries, the zeros or blanks (
\
would probably be placed in front of the number.)

Entries with Decimal Positions

)

J

A N U A R Y

F E 8

b b

R U A R Y

M A R C H

b b b b

A P R

b b b b

M A Y

L

b b b b b b

U N E

b b b b b

J U L Y

b b b b b

J

A U G U 5 T

5

E P T

0 C T 0
N 0

When the entries of a table are numeric, it is necessary to
specify in column 44 the number of decimal positions (0-9)
in each entry. Even if a numeric entry contains no decimal
positions, a 0 must still be entered to indicate numeric data.
When decimal positions are not specified (column 44 left
blank, as in Figure 8-5), RPG II considers the table entries
to be alphameric.

b

b b b

E M 8 E R
8

E R

-

Longest Table Entry

b b

V E M 8 E R

D E C E M 8

Sequence of Table Entries

E R

b
b

For TABITM, the item codes need not be in any particular
order. Thus, column 45 is left blank in Figure 8-5. However, if the table entries are in ascending or descending
order, an A or a D is entered under Table Sequence (column
45). Note that if a table is to be in sequence the entry is
made on the Extension sheet. For input files, other than
table files, the sequence entry is always made on the File
Description sheet.

Table Of Months

Coding the Table Lookup Operation (LOKUP)
Figure 8-6. Making Table Entries the Same Length

)

Padding a table entry with blanks should not be confused
with spacing entries on a record. As mentioned, no blanks
can occur between entries. However, blanks can be part of
an entry in order to make all entries the same length.

Once the table input records have been described, you tell
RPG II to search the table by coding the LOKUP operation
on the Calculations sheet. This involves specifying:

1.

The LOKUP operation code.

2.

The name of the table to be searched.

3.

The data which is being searched for.

4.

Conditions which must be satisfied for a successful
search.

Packed or Binary Table Data (Systems with Disk Storage)

An entry must be made in column 43 if the data for a preexecution time table is in packed decimal (P) or binary (B)
format on disk or tape or in packed format on 80-column
cards (not allowed on 96-column cards). This entry applies
only to numeric tables. For numeric tables in packed decimal format, the unpacked decimal length of the entries
must be entered in columns 40-42 (Length of Entry). For
numeric tables in binary format, enter the number of bytes
required in storage for the binary field. For a two-position
binary field, the entry in column~ 40-42 is 4; for a fourposition binary field, the entry is 9.

Tables

8-7

As shown in Figure 8-7, the operation code LOKUP is entered in columns 28-32 of the Calculations sheet. This
operation code causes a search to be made for a particular
item in the table named in Factor 2. Thus the name of the
table being searched, TABITM, is entered under Factor 2
(columns 33-42), beginning in column 33. Remember that
the table being searched must have been previously described on the Extension sheet.
Factor 1 (columns 18-27) contains the field name of the
data which is used for comparison during the table search.
In this case, the second field of the sales record (called
ITMORD) contains the code for the item ordered (the
search data). Thus, ITMORD is entered, beginning in column 18.
The fields on each SALES record have been described on
the Input sheet. The field (lTMORD) which contains the
search data must have been described so that it agrees with
the way the table e,ntries have been described. That is, the
search data and the table entries must have the same length,
the same number of decimal positions, and the same format
(alphameric or numeric). As shown in Figure 8-8, both
ITMOR D and the table entries are defined as three characters long and as alphameric (no decimal positions specified).
In this case, the item which is being searched for must be
an exact match of the search data. This is referred to as
searching for an equal condition only. The lookup procedure would begin at the first element of TABITM and
continue, one element at a time, until an equal entry is
found. For this reason, it isn't necessary that the table
elements be in ar y particular order when searching for an
.
equal condition'
j

8-8

Of course, if the item searched for is not found after checking all elements of TABITM, the company does not carry
/'
that item in stock. Thus, the equal condition must be satis- i
fied if this search is to be successful.
But, how will you know if the search was successful? To
determine this, you must know if an equal match was found
or not. Thus, you should assign a resulting indicator for the
lookup which will turn on if (and when) the equal condition
is satisifed.
As shown in Figure 8-7, the indicator 05 is assigned by entering 05 on the Calculation sheet under Lookup Equal
(columns 58-59). If an entry cannot be found in the table
to correspond to the search dat~, the 05 indicator will turn
off.

TWO TABLE SEARCH

As you have seen, a single table can be searched merely to
see if certain information (an item code) is in the table.
However, usually you will want to do more than this. For
example, when the orders are shipped, you will also want
to send bills to each customer for the amount of the order.
Before RPG II can print the bills, it must calculate the
amount each customer owes. To do this, the unit cost of
each item must be determined. The unit cost of an item is ,/then multiplied by the number ordered to give the total
\
amount due from a customer for that type of item.

RPG

IBM

Fa.m GX21·9093
Printed in U.S.A.

CALCULATION SPECIFICATIONS

International Busin.ss Machin. Corporation

1 2

Program

Date

Programmer

C
r-4

Indicators

~

Indicators
~

-'a::
=0

AL

~~~

At

Operation

Factor 1

Name

..... '0 a:

5

.f

E

E~
85 za

6

7

0111

C

01 2 1

C

a

z

Length ~

;

Arithmetic
Plu. IMinusl Zero

Comments

Compare

1>211<211-2
~~
·2 '; LookuplFactor 2)j,

a

z

ox High Low Equal

9 10 11 12 13 14 15 16 17 lB 19 20 21 22 23 24 25 26 27 2B 29 30 31 32 33 34 35 36 37 3a 39 40 41 42 43 44 45 46 47 48 49 5051 52 53 54 55 5657 5B 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

8

I I I HI<\"\p ... 1",1 Bit ITIM I I I I I I I I I I
I III \ II II II II II II II
II II II II II II II II II II II II II II II II
I I I I I I I

I

.LIT IMIDKln

I
I

1.1

:e g

Factor 2

75 76 77 78 79 80

[00'_ ~~~~;~':ation I I I I I I I

Resulting

Result Field

0_

Line

3

Page

I I o1s Irlsl cr:-IT~M lrlNllslrlkl
II II II II
IIIIIIIIIIII
I I I I I I I I I I I I I I

Figure 8-7. Specifying a Single-Table Search

RPG

IBM

GX21·9094

INPUT SPECIFICATIONS
1

Program
Programmer

-

Record

I!
5 16

II

I n Ie

I~

lA'Nio

9 10 11 12 131'4 '51'6 17 18 19 20 .21 22 23 24 25126127 2B 29 30 31 32133 34,35 36 37

II~ AI 11=1c;

1
,2

10

8

Field
Indicators

IZero
Plus Minus ~~ank

I

To

ro~r-lili

7

75 76 77 78 79 80

Field Location

I~'" §

Filename

2

[00'_ ~~~~;~':ation I I I I I I I

2

1

Ij
4

Page

Date

I
Line

\ 3
.-./ 10

U/M 050·

Printed in U.S.A.

International Business Machine CorporatiOn

454647148 49 50 51152 53 54 55 56 57 58159 60 61 6216364 65 66 i67 6B 169 70 71 72 73 74

II

AlA

I I I

I I I I I I

Search
:
3 Alphameric Characters
Table Entry:
3 Alphameric Characters

RPG

IBM

ON AND LINE COUNTER SPECIFICATIONS

Form X21-9091
Printed in U.S.A.

International Business Machine Corporation

1
Page

To Filename

-..,

Table or

2

[0

rTTTrn
75 76 77 78 79 80

of_

Program

Identification

~

Comments

\,

~:igUre

8-8. Specifying the Same Length for Search Word and Table Entry

Tables

8-9

At this point, you have already created a table (TABITM)
listing the codes of all items the company sells. The unit
cost for each item (a 5-digit field on each inventory file
record) can be stored in a second table, called TABCST.
This table should be organized such that the position of a
cost within TABCST corresponds to the position of its related item code in TABITM (Figure 8-9).

a

Let's take look at one of the records in the SALES file
(Figure 8-10) and see how the two tables can be. used in
determining the "appropriate cost for the item ordered.
The procedure is much the same as the way you located
Ken Adams' telephone number in the telephone directory.

SALES record

569823

37

t

INVNTRY

file

OTYORD

I

ITEM

OTYSTK

\

COST

00140

<,

98
item
codes

-

-

Characters-

TABITM

A23

00140

01623

A87

00025

B 21

01623

00129

98

-

unit costs

~

---

-+- 3

00025

-

r---'

.-.00129
L ___ JI
C36

02575

C42

00249

C65

~5Digits-

TABCST
TABITM

Figure 8-9. Creating Two Related Tables
Figure 8-10. Performing a Two-Table Search
8-10

TABCST

)

First, TABITM is searched to find the table element which
contains the same item code as the search word (B83) on
the SALES record. If no match is found, that SALES record can be selected into a special stacker so the customers
can be notified of the orders which can't be filled. However, in this case, the equal entry is found in the fourth
element of TABITM. The entries in TABCST were organized to correspond with entries in TAB ITM. Therefore, the
fourth element of TABCST contains the unit cost for the
search word. The program can then use the information
referenced (unit cost) to calculate the amount to be billed.

I
I

2 Item Code Entries

I

32 Item Code Entries
32 Item Code Entries
32 Item Code Entries

. 1-:-

-

When two related tables are usea, as in this example, actually only one table is searched. When the search condition
(in this case, an equal match) has been satisfied, the data in
the corresponding position or element of the second table
(related table) becomes available. Thus, the first table is
used as a means of locating data in the second table. I n a
telephone directory, a person's name is used as a means of
locating his telephone number.

1Table-Input File
forTABITM
(4 records)

Designing Table Input Records for Two Tables

Records With Entries For Only One Table

)

In designing the table input records for T ABITM, you were
concerned only with entries for a single table. Thus, four
table input records were created to contain only item codes.
Another set of table input records could be created to contain the 98 unit cost entries for TABCST. Each unit cost
entry (from the inventory records) requires five columns
(three digits for dollars, t'wo digits for cents). Again, it is
up to you' to determine how many records you wish to use
and the number of entries to be contained in each record.
For example, let's say that 18 entries (columns 1-90) are
punched into each of five table input cards and the remaining eight entries are punched into columns 1-20 of a sixth
card.
As shown in Figure 8-11, you would then have two separate
table input files: records for TABITM containing only item
codes and TABCST records containing only unit cost
amounts.

I

I

J

I

I

8 Unit Cost Entries
18 Unit Cost Entries
18 Unit Cost Entries
18 Unit Cost Entries

18 Unit Cost Entries
18 Unit Cost Entries

i

1-

1-

-

-

Table-Input File
forTABCST
(6 records)

Figure 8-11. Separate Records for Each Table

Tables

8-11

Records With Entries For Two Tables
Another method of designing table input records allows you
to use only one table input file for both tables. This may
save input record space and will usually reduce the number
of RPG II specifications needed to describe the table input
records. Entries from the first table are alternated with
entries from the second table (Figure 8-12). The records
are then referred to as alternating format table input records.
As you can see, a table input record c:m begin (position 1)
with an entry from either the first table or the second table.
However, if you decide to use the alternating fqrmat, eve~y
record in the table input file must begin with the same type
of table entry (table 1 or table 2).
The number of entries that you put on an alternating fo'rmat, table input record is still up to you. If you wish, a
single record can contain one code for TABITM and one
unit cost from TABCST. Or, the record may contain as
many pairs of related entries as possible. In this case, all
records, except the last, must contain the same number of
entries.

For TABITM and TABCST, each pair of related entries will
require eight card columns. By punching 12 pairs of entries
in a record, an entire card can be filled. Thus a table input
file to contain all entries (98 pairs) from both tables can
c()nsist of 'niriealternating format, table input cards. The
first eight records might each contain 12 pairs of entries
and the last record might contain two pairs of entries.
As mentioned before, entries for TAB ITM are each 3-character alphameric data. For TABCST, 5-digit numeric entries are needed. All of the entries for a single table must
be alike; that is, all alphameric or all numeric. However,
the en!ries. f,of an alphqm~ric table and the entries for a
numeric table can both be on the same table input record
when an alternating format is used.
Although each table input record contains entries from both
tables, actually two separate tables are created in storage
from these records. The RPG II Compiler knows that two
tables are to be set up, rather than a single table, because of
the way the records are described on the Extension sheet.

Every record in file
begins with entry
for the same table

. Last record contains
two pairs of entries

Single Table - t"nput File.
Entries for TABITM a~d
TABCST in Alternating
Format.
'"''

Figure 8-12. Alternating-Format Table-Input Records
. l·'

8-12

Describing Two Tables with Extension Specifications

RPG

'\
)

When two related tables are used in a program, you have the
choice of designing two table input files (one for each table)
or only one table input file consisting of al,ternating format
table input records.
If you decided to set up TABITM and TABCST using separate files, as discussed earlier, the two tables would be described as shown in Figure 8-13. Since each table has its
own set of input records, a separate line of extension specifications is needed for each table.
Now take a look at Figure 8-14 which describes the same
two tables. Notice that only one extension line is coded
when alternating format, table input records are used.
Since one line is coded for each set of input records, the
second table of the alternating format record must be entered on the same extension line as the first table.

)

EXTENSION AND LINE COUNTER SPECIFICATIOI'

Notice that Number of Entries Per Record (columns 33-35)
and Number of Entries Per Table or Array (columns 36-39)
do not have corresponding specification columns for alternating tables. Since the number of entries per record and

RPG

To Filename

Table or
Array Name

Number
of
Entries
Per
Record

Number
of
Entries
Per Table
or Array

length
of
Entry

"

-

.£! 0

]~

ill

Table or
Array Name
(Alternating
Formatl

length
of
Entry

19 20 21 22 23 24 25 26 27 28 29 30 31 32 333435 36 37 38 39 40 4142 4344 45 46 47 48 49 50 51 5253 54

Qls
q'e

TA lair ITM 3rl
Ttl IBlr Ish" 1.8

l1
~

12

Figure 8-13. Describing Separate Table~lnput Records

Remem~er that two separate tables are created, even if you
use alternating format records. Therefore, both tables must
have unique names, which are specified on the Extension
sheet. The table whose entry appears firston a table input
record is named in columns 27-32. The name of the alternating table (in this case, TABCST) is entered in columns
46-51 of the same line. The alternating table is always the
table whose entry is the second one in a pair of related entries.

IBM

Extension Specifications

number of entries per table must be the same for each of
the alternating tables, separate specifications are not needed
for the second table.
However, the Length of Table Entry (columns 52-54) must
be indicated since it may be different for the two tables.
In Figure 8-14, a 3 has been entered in columns 40-42 as
the table entry length for TAB ITM, while a 5 has been entered in columns 52-54 specifying the length of the unit
cost entries for TABCST.
The unit cost entries for TABCST are in the form of 12467,
which would represent $124.67. Therefore, a 2 has been
entered for the number of decimal positions(column 56).
This specification indicates that the entry is numeric and
contains two decimal positions.'

EXTENSION AND LINE COUNTER SPECIFICATIONS

Form X21-9091

Printed in U.S.A.

International Business Machine Corporation

1

Program
Programmer

Page

Date

2

[0

75 76 77 78 79 SO

Of_

Program
Identification

rTITrn

Extension Specifications

E

Record Sequence of the Chaining File
Number of the Chaining Field

line

I-

~

)

To Filename

~

From Filename

Table or
Array Name

Number
of
Entries
Per
Record

Number
of
Entries
Per Table
or Array

length
of
Entry

~~

:)~~

~~j

Table or
Array Name
(Alternating
Formatl

length
of
Entry

.g

e

.

.~ ~

:3

"-

Comments

~ ~

~~j

Figure 8-14. Describing Alternating-Format Table-Input Records

Tables

8-13

The table entries Jor TABCST are not in any special alphabetic or numeric order which the RPG II Compiler program
could check for accuracy. Thus, no table sequence is specified for TABCST (column 57 is left blank). Likewise, telephone numbers in a directory are not in sequence. However,
just as phone numbers are arranged to correspond with related names, the T ABCST entries have been arranged so a
particular unit cost corresponds with its related item code.

Field length and decimal positions have not been entered in
columns 49-52. These specifications are not required since
the table named under Result Field (TABCST) was previously described on the Extension sheet. However, if you want
to enter these specifications again on the Calculation sheet,
the numbers must agree with those in the extension specifications. For TABCST, field length must be 5 (in column 51),
the length defined for a TABCST entry, and the number of
decimal positions must be 2 to agree with the Extension
sheet.

Coding the Table LooKup Operation (LOKUP)
Now that both tables have been set up, TABITM is to be
searched to find the table element which contains the same
item code as the code (search word) on the SALES record.
This simple lookup procedure is coded with the same calculation specifications as you used before (Figure 8-15).
The field name or literal constant which contains the search
code is entered under Factor 1 (ITMORD), the LOKUP
operation is specified in columns 28-32, and the name of
thetable being searched (TABITM) is entered under Factor
2. If an equal match is found in searching the table, resulting indicator 05 will be turned on, as specified in columns
58-59.
However, you want to do more than just see if the item
ordered is carried in stock. If the search is successful, you
also ,want to determine the appropriate unit cost for the
ordered item.

RPG

i~ f2~

\

. I--eg
~.5 ~
Lme
~~5~~
I;

6

I

C

01 2 1

c

011

1.1

I

7

8

I
I
I

9

I

And

I I I I /
I / / / I

/ Graphic

Form GX21·9093
Printed In U.S.A.

.1 Punch

I
And

Operation

Factor 1

Page

I

Factor 2

~

~

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 33 34 35 36 37 3B 39 40 41 42 43 44 45

~L

Length

46

47 4B 49 50 51

I I I 1//nI211<211-2
Lookup(Factor 2)is
High Low Equal
54 55 5657 58 59 60 61 62 63 64 65 66 67 58 69 70 71 72 73 74

r'JI~lll c.b[c; ITI tlFI IIITIM
I I
IIII ////I
II II II II II IIII
I I I I I I I I I II
Ill~

(

RPG

)

IBM

Internationel BUliness Machine

Form GX2l·9093
P.,.lnted in U.S.A.

CALCULATION SPECIFICATIONS

Corpor.t~on
1 2

Program

C
I--

Indicators

~.

.

5 6

o
o
o

1
2

c
c

3

C

Operation

Factor 1

.g

Factor 2

<

7

8

Length

Name
Z

~

Plus IMinusl Zero

:~;~f:ation I

IIIIII

Comments

Compare
~~ 1 >2Tl
<211-2

~~
u

....
~

~
Z

~

af85~
4

AL

At

j; Z

.E. "0=
J:> en

3

75 76 77 78 79 80

of _ .

Arithmetic

~Q

> ....

CD

Resulting
Indicators

Result Field

o_

&
Lin•

Page

Date

, Programmer

0:>:

LookuplFactor 2)is
H,gh Low Equal

9 10 1112 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 4B 49 5051 52 53 54 55 56 57 58 59 60 61 62 63 54 65 66 67 66 69 70 71 72 73 74

~lJ.

~l'i

1/'1

~lt

Irlk IFh-IAIB IIITI~

1t'C

;"'1 ... 1... 1... I,.f...

IMIL IllT

l.J

IT

,~

,.,,,'-

"'~IM

-

I.l\~ I,...

,

ItJh"

1ll1., r~IJ.." Ir~
IA'MIrll Nrr

1t.,!2

5rr

~IF

trrrM

Inll :~

-

"

Figure 8-16. Performing Calculations Only After aSuccessful Search,

However, if the item code was not found, indicator 05
would have been turned off and no cost entry would be
available for the item ordered. For the example given, you
could have the SALES record for the current lookup selected into a separa.te stacker. In this way, you can identify
which customers must be notified that their orders cannot
be filled.

Therefore, there must be a way to bypass the calculations
if the lookup is unsuccessful. This is done by entering 05
as a conditioning indicator in columns 10-11 (see Figure
8-16). The calculation operations will be done only when
05 is on. In this way, the same resulting indicator used to
determine the results of the lookup becomes a conditioning
indicator to determine if a calculation operation should be
performed.

Note: In order to select a stacker for input records on the

)

basis of a calculation operation (for example, LOKUP), the
file must be defined as a combined file on the File Description sheet and the stacker must be specified on the OutputFormat sheet. See the chapter entitled Card Output Operations for a discussion of stacker selection.

If the item is not carried in stock (05 off), any calculations
conditioned by 05 are not performed. The program then
performs the output specifications since there are no more
calculations to be done. (See Figure 8-17.) For this example, a card is selected into a different stacker only when
the search iS,unsuccessful, not for every item ordered. Thus,
the output specification is conditioned by entering N05
(05 not on) and the record identifying indicator in columns

Ordinarily, all calculation specifications are performed before any output is done. But if the search for an item was
unsuccessful, you would be unable to calculate a bill for
the customer correctly.

RPG
In order to specify stacker selection
based on the results of a calculation
operation (NOS), SALES must be
defined as a combi~ed file.

H

Line

Filename

>

!

I-

E

)

3

4

11

o

21

5

6

~trlD

7

8

9 10 11 12 13 1415

ol~lAl, IJ:I~I I
o 1 IT I II

!1~ 17
•

Punch

~

~

~

<

I I
I I

I I I I
I I I I

Itput Indicators

°

Z

Field Name

I~

z

End
ex:

0

0

Z

If:

'AUTO

~!g~~

w m

Positon

in
Output
Record

18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 3839 40 41 42 43

I I IN~!5

I"'L~

Graphic

Instruction

I I

~11

IIIII

IIIII

GX21-!I09O UiM 050'
Printed in U.S.A.

SPECIFICATIONS

OUTPUT

Punching

11

..

f-fJ
~~
A N

15
u.

o

i~~~
m
ci5

1

23-28.

I II

I II

I

Card Electro Number

I

1 2

Page

CD

75 76 77 78 79 80

of_

Commas

Zero Balances
to Print

No Sign

CR

"

Ves
Ves
No
No

Ves
No
Ves
No

1
2

A

J

8

K

3

C

4

0

L
M

~~~;~f:.tion I

1.1 1 1 1

X - Remove
Plus Sign
V • Date
Field Edit
Z - Zero
Suppress

ex:

:::;
~

Constant or Edit Word

"-

«%~~4B~~~~~54~~~~~~~~~54~66~M~W

71 72 73 74

I I 1111111 111111 I I I II I II T
1/ I I I I I I I I I I I I I j I I 11 1 TI T

Figure 8-17. Performing Output Only if Search Was Unsuccessful

Tables

8-16

At this point, then, you know that you mayor may not
want certain calculations and output specifications performed, depending on the results of a table lookup. This
is accomplished by using conditioning indicators.

REPORT
/'

QUANTITY

Referencing Data Following a Successful Search

-

With this logic in mind, let's take a look at the output wanted
from the table lookup program just discussed. TABITM contains the codes of all items carried in stock. The related table,
TABCST, contains the unit cost for each item. A SALES
file contains the records of c~stomer orders, providi~g th~
customer number, code for the item ordered, and the quan,tity ordered.
The purpose of the program is to calculate the amount each
customer owes and pi"int'the information on a report. The
report'is to contain more than just the total amount due,
however. As shown in Figure 8-18, each order should have
a line printed with data trom the SALES record, (item ordered, quantityordered), data looked up from TABCST
(unit cost), and data from calculations' (total amount du'e).

RPG
InternatiOnal Business Machine

a

~.5~
.... '0 a:

Form GX21·9093
Printed in U.S.A.

E ::;

5

7

Result Field

8

15

z

Operation

15

.~

Factor 2

/

(I)

& 85 ~
6

"

Factor 1

'g
Name'

Length ~

E

'2

z

0

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2B 29 30 31 32 33 J4 35 36 37 3B J9 40 41 42 43 44 45 46 47 4B 49 50 51 52

1

C

o

~lL

2

C

t2llS £1jl

a

3

C

.1 J 11'1

'H

rrA Ip,'- C;T

!ro,k I,

f't1ll 'iT

0

1-

-

IHlJ:j .1111'1
1,

...

,/

Once all calculations have been performed, the RPG 1\ program performs the output specifications (Figure 8-20) for
this same SALES record. The specifications in line 01 are
not pe'rformed, since the SALES record is selected'into
stacker 3 only if the search is unsuccessful (indicator 05
off). However, the rest of the outputspecifications are performed. Suppose the R EPO RT file is defined on the File

2

pageDJOf_

J~ Jd

g~

name

CALCULATION SPECIFICATIONS

Indicators

ig

, I'

What is the name of the field containing the cost? The
specifications in line 02 of Figure 8-,19 shows this instructi:on.
The name of the table (T ABCST) which' provided the cost '
has been entered under Factor 1. Whenever table
is used as a factor in any operation other than a LOKUP (in
this case, the operation MUL T), the name re~ers to the dat~1
item made available by a LOKUP. Thus, TABCST in line
02 refers to the unit cost of the item just looked up.

Date

~

,--

Figure 8-18. Output from a Table Lookup

1

C
I-4

-

CorpOret~on

Programmer

3
a

-

- --

Program

Line

.

-

-

TOTAL

Since the table na~e, TABCST, is used only as a factor and'
not as the result field of the MUL T operation (line 02), the
contents of the TABCST data item are :not changed. It still
contains the unit cost for the item on the sales record.

After the first SALES record is read into the co~puter,
Figure 8~19 shows thatTABITM is searched to find an entry
equal to the item code on that' SALES record (lTMORD).
If a successful search is made, indicator 05 is turned on and
the table entry looked up is availabl'e for use in' further calculations or output operations. I n this program, you want to
multiply the looked-up cost by the number of items the
customer ordered (field QTYORD on the SALES record).

IBM

UNIT COST

- ---

-c

According to the RPG II program cyCle, input specifications
are performed first, followed by calculations and then output. Thus, after reading a data record, all calculations for
that record and then all output operations for that record are,
performed, before the next data record is read and processed.

ITEM

h"A IB~ 5T
lAM" INT

Resulting
Indicators
Arithmetic
Plu. 1Minusl Zero
Compar.
1>211<211-2
Lookup(Factor 21is
High Low Equal

'

75 76 77 78 79 80

~~~;~f:ation I

1 I· 1 I· 1 1
"

Comments

54 55 5667 5B 69 60 61 62 63 64 65 66 67 6B 69 70 71 72 73 74

rJjl Cj

t,2

,/

Figure 8-19, Referencing Looked-up Table Data

8-16

RPG

GX21·9090 U/M 050'
Printlld in U.S.A.

SPECIFICATIONS

OUTPUT

1
Program

Programmer

Page

Date

o

Skip

Output Indicators

f---

Field Name
Filename

Line

tr

a:

~.'=

'AUTO
3

o
o
o
o

4

1

2

3
4

o

5

o
o

6

o

8

7

5

6

7

8

9

"0
W

en

~

S>
End
Positon
in
Output
Record

II

Commas
Ves
Ves
No
No

Zero Balances
to Print
Ves
No
Ves
No

2

[0

No Sign

75 76 77 78 79 80
of_

X

CR
A

~~~;~f:ation 1

.J

B

K

C
0

L
M

.

I. 1 1 1 1 1

Remove

Plus Sign
V' Date
Field Edit

Z = Zero
Suppress

a:

g

Constant or Edit Word

c:

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 3031 32 33 34 35 36 37 38 39 4041 4243 44 45 46 47 48 49 5051 52 5354 55 56 57 58 59 60 61 6263 64 6566 67 68 69 70 71 72 73 74

ole; IAll 11= Ie;

iI"Il~

aiR 1J:"lp l~rRIT
a
a
a
a
a
a

b

IN~ L;

11

rlll
Its ~lL

-I- .

~IL ~IT IMIR
I I I 1""1

1M

liT

n

trlA 1~lr Ie; rr L~
~IM I,-J II\[TI3

I~

112
Ill~

13 V'-

1511

Figure 8-20. Output of Data Looked-up in a Table Search

.
)

Description sheet as a printer output file. Lines 02-05 cause
the data from the SALES record to be printed on the report.
By referencing the name of the table looked up (TABCST)
in line 06, the program prints the data contained in the table
element, the unit cost for this first SALES record. Line 07
then tells the program to print the amount due, which was
previously calculated.
Once all output has been performed for the first record, the
RPG II cycle causes the input specifications to be performed
again. Thus, the next SALES record is read in, and a table

LOKUP is performed for the second record. On a successful
search, the unit cost for the second SALES record is made
available. The cost for the second item can then be used in
calculations and output specifications by referring to the
name of the table looked up.
Each table LOKUP operation performed searches for only
one entry from a table. This data is then available to be
used in calculations and output specifications for that record. The data available does not change until thp next table
lookup is performed for that table.

Tables

8-17

TABAMT TABTAX

TABAMT TABTAX

TABAMT TABTAX

TABAMT TABTAX

TABAMT TABTAX

.50
.51
.52
.53
.54
.55
.56
.57
.58
.59
.60
.61
.62
.63
.64

33.49
33.83
34.16
34.49
34.83
35.16
35.49
35.83
36.16
36.49
36.83
37.16
37.49
37.83
38.16

1.00
1.01
1.02
1.03
1.04
1.05
1.06
1.07
1.08
1.09
1.10
1.11
1.12
1.13
1.14

50.16
50.49
50.83
51.16
51.49
51.83
52.16
52.49
52.83
53.16
53.49
53.83
54.16
54.49
54.83

1.50
1.51
1.52
1.53
1.54
1.55
1.56
1.57
1.58
1.59
1.60
1.61
1.62
1.63
1.64

~:g~

.09
.10
.11
.12
.13
.14

16.83
17.16
17.49
17.83
18.16
18.49
18.83
19.16
19.49
19.83
20.16
20.49
20.83
21.16
21.49

66.83
67.16
67.49
2.02
67.83 i 2.03
68.16 i -2.04
68.49
2.05
68.83
2.06
69.16
2.07
2.08
69.49
2.09
69.83
70.16
2.10
70.49
2.11
70.83
2.12
71.16
2.13
71.49
2.14

83.49
83.83
84.16
84.49
84.83
85.16
85.49
86.83
87.16
87.49
87.83
88.16
88.49
88.83
89.16

2.50
2.51
2.52
2.53
2.54
2.55
2.56
2.57
2.58
2.59
2.60
2.61
2.62
2.63
2.64

5.16
5.49
5.83
6.16
6.49
6.83
7.16
7.49
7.83
8.16
8.49
8.83
9.16
9.49
9.83

.15
.16
.17
.18
.19
.20
.21
.22
.23
.24
.25
.26
.27
.28
.29

21.83
22.16
22.49
22.83
23.16
23.49
23.83
24.16
24.49
24.83
25.16
25.49
25.83
26.16
26.49

.65
.66
.67
.68
.69
.70
.71
.72
.73
.74
.75
.76
.77
.78
.79

38.49
38.83
39.16
39.49
39.83
40.16
40.49
40.83
41.16
41.49
41.83
42.16
42.49
42.83
43.16

1.15
1.16
1.17
1.18
1.19
1.20
1.21
1.22
1.23
1.24
1.25
1.26
1.27
1.28
1.29

55.16
55.49
55.83
56.16
56.49
56.83
57.16
57.49
57.83
58.16
58.49
58.83
59.16
59.49
59.83

1.65
1.66
1.67
1.68
1.69
1.70
1.71
1.72
1.73
1.74
1.75
1.76
1.77
1.78
1.79

71.83
72.16
72.49
72.83
73.16
73.49
73.83
74.16
74.49
74.83
75.16
75.49
75.83
76.16
76.49

2.15
2.16
2.17
2.18
2.19
2.20
2.21
2.22
2.23
2.24
2.25
2.26
2.27
2.28
2.29

89.49
89.83
90.16
90.49
90.83
91.16
91.49
91.83
92.16
92.49
92.83
93.16
93.49
93.83
94.16

2.65
2.66
2.67
2.68
2.69
2.70
2.71
2.72
2.73
2.74
2.75
2.76
2.77
2.78
2.79

10.16
10.49
10.83
11.16
11.49
11.83
12.16
12.49
12.83
13.16
13.49
13.83
14.16
14.49
14.83

.30
.31
.32
.33
.34
.35
.36
.37
.38
.39
.40
.41
.42
.43
.44

26.83
27.16
27.49
27.83
28.16
28.49
28.83
29.16
29.49
29.83
30.16
30.49
30.83
31.16
31.49

.80
.81
.82
.83
.84
.85
.86
.87
.88
.89
.90
.91
.92
.93
.94

43.49
43.83
44.16
44.49
44.83
45.16
45.49
45.83
46.16
46.49
46.83
47.16
47.49
47.83
48.16

1.30
1.31
1.32
1.33
1.34
1.35
1.36
1.37
1.38
1.39
1.40
1.41
1.42
1.43
1.44

60.16
60.49
60.83
61.16
61.49
61.83
62.16
62.49
62.83
63.16
63.49
63.83
64.16
64.49
64.83

1.80
1.81
1.82
1.83
1.84
1.85
1.86
1.87
1.88
1.89
1.90
1.91
1.92
1.93
1.94

76.83
77.16
77.49
77.83
78.16
78.49
78.83
79.16
79.49
79.83
80.16
80.49
80.83
81.16
81.49

2.30
2.31
2.32
2.33
2.34
2.35
2.36
2.37
2.38
2.39
2.40
2.41
2.42
2.43
2.44

94.49
94.83
95.16
95.49
94.83
95.16
95.49
95.83
96.16
96.49
96.83
97.16
97.49
97.83
98.16

2.80
2.81
2.82
2.83
2.84
2.85
2.86
2.87
2.88
2.89
2.90
2.91
2.92
2.93
2.94

15.16
15.49
15.83
16.16
16.49

.45
.46
.47
.48
.49

31.83
32.16
32.49
32.83
33.16

.95
.96
.97
.98
.99

48.49
48.83
49.16
49.49
49.83

1.45
1.46
1.47
1.48
1.49

65.16
65.49
65.83
66.16
66.49

1.95
1.96
1.97
1.98
1.99

81.83
82.16
82.49
82.83
83.16

2.45
2.46
2.47
2.48
2.49

98.49
98.93
99.16
99.49
99.83
100.16

2.95
2.96
2.97
2.98
2.99
3.00

.16
.49
.83
1.16
1.49
1.83
2.16
2.49
2.83
3.16
3.49
3.83
4.16
4.49
4.83

.00
.01
.02
.03
.04
.05
.06
.07

.08

Figure 8-21. Two Related Tables for Determining Sales Tax

8-18

TABAMT TABTAX

I

On the other hand, what if a customer ordered items which
total $5.767 TABAMT contains no such entry. Thus, indicator 23 is turned off, indicating an equal condition cannot
be satisfied. What the calculation specifications shown in
Figure 8-22, a correct tax amount will never be made available for this purchase.

Searching For Low, High, or Equal Conditions

Up to this point, table lookup operations have involved
searching for only an equal condition. However, in some
cases, you may have a search word which is less than or
greater than an entry in the table be!ng searched.
Assume that a 3 percent sales tax is charged in the state in
which you do business. Since the tax rate (3 percent) is the
same for all amounts, it is a simple data processing operation to calculate the amount of tax for every customer's
order. However, merely to show you how a low or high
search works, let's use a table lookup to determine the tax
due on an order.

However, since TABTAX contains all possible tax amounts,
a sales tax entry must be present for a purchase of $5.76.
Looking at the two tables in Figure 8-21, you can see that
a sale of $5.49 requires a tax of 16¢ . But the sale was
greater than $5.49; therefore, the tax will be more than 16¢.
Take a look at the next entry. For a sale of $5.83, the tax
is 17¢. Furthermore, any sale which is less than $5.83, but
greater than $5.49 (the previous entry), will also require a
tax of 17¢ .

The tax due on certain amounts is calculated, and the information is organized into two tables (see Figure 8-21).
T ABAMT is a list of various amounts of purchases while
TABTAXcontains the sales tax due on the amounts.

)

In this case, TABAMT is organized in ascending sequence.
Therefore, the T ABAMT entry (5.83) which will give the
appropriate tax for $5.76 is the first TABAMT entry higher
(greater) than the actual search word.

Assume you had to lookup the sales tax for a customer
order totaling $9.16. By placing a resulting indicator
(01-99) in columns 58-59 of the Calculation sheet (Figure
8-22), you specify that an equal condition is to be satisfied.
The computer then searches TABAMT, starting at the beginning of the table, until the table entry 916 (representing
$9.16) is located. At that time, the resulting indicator (in
this case, 23) is turned on and the sales tax of 27¢ is made
available.

RPG

IBM

As you learned previously, a resulting indicator must be
used to indicate what condition is to be satisfied for a successful search. To specify that a LOKUP is to retrieve a
table element higher (greater) than the search word, a resulting indicator must be entered in columns 54-55 (Lookup High) of the calculation specification.

Form GX21-9093
Print_din U.S.A.

CALCULATION SPECIFICATIONS

Intern'Clonal Busineu Machi",e Carpor,tion

1 2

75 76 77 78 79 80

Program

Oal.

Programmer

C

~

line

Indicators

~

0_

4

5 6

1'1
2
01 '

o

I

I

C

C

7

8

I,
I

0

z

Indicators

Factor 2
Length

Name

E E~ ..
85 ~

.f
3

Operation

Factor 1

t- '0 a;"

15

Z

9 10 II 12 13 I. 15 IS 17 18 19 20 21 22 23 2. 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 .9 5051

~lnIAIM-1

I II HkhlP T~I~Alrwtrl I I I i,lAlsrlAIx I I
I 1, l 'Jill""
II
" " I

'"'''' "
I

I

I

I

I

I

I

1.1

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

IIIIII

Resulling

Result Field

AL At

=~
~.s~

~;~;~':alion I

paee[Oo,_

I

I

Arithmetic
Plus IMinusl Zero
Compare
1>2\1<2\I 2
Lookup(Faclor 21is
High Low Equal

Comments

K

54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

I I [2.13 I I I , , , , , , , , , "
I , I """I""'"
I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

Figure 8-22. Searching for an Equal Condition

)
Tables

8-19

Since customer orders can be any amount, the table lookup
must be coded to handle all possibilities. For some orders,
an equal match can be found in T ABAMT; for others, the
table entry will be higher than the search word. Therefore,
the same resulting indicator (23) should be assigned to turn
on if either a high or equal condition is satisfied (see columns
54-55 and 58-59 of Figure 8-23).

Sequence of Tables

A table can also be searched to locate an entry which is
lower in value than the search Word. In such a case, the
table is searched for the entry which is lower (less) than,
yet closest in value to, the search word. Searching for a
low condition is specified the same way as searching for a
high condition, except the resulting indicator is entered in
columns 56-57, rather than 54-55.

However, when searching for high or low conditions, table
entries must be in either ascending or descending sequence.
This is because the program must select the entry which is
higher or lower than, yet closest in value to, the search
word. With the table entries in sequence, the program can
determine where in the sequence the search word value
would appear if it were in the table. For ,example, if table
elements 2-4-6-9-11 are in ascending sequence, a search
word of 7 would naturally come between elements 6 and
9. Thus, element 6 would satisfy the low condition, while
element 9 would satisfy the high condition (closest in value
and yet higher than the search word).

In coding a table lookup, either one or two conditions may
be specified. A particular search may be successful by satisfying:
,1.

An equal condition only.

2.

A high condition only.

3.

A low condition only.

4.

Either a high or equal condition.

5.

Either a low or equal condition.

RPG

If the table elements are not in sequence, as 2-4-11-9-6, the
LOKUP might retrieve the wrong element. The elements
are checked one at a time from the beginning of the table.
Therefore, the computer would determine that a search
word of 7 would come between the 4 and the 11. A search
for a low condition would incorrectly retrieve element4, '.
because the next element (11) is greater than the search
word (7). While the last element (6) is actually closer in
value to the'search word, it would not be made' available.
Likewise, a search for a high .condition would retrieve

CALCULATION SPECIFICATIONS

Form GX21-9093
Printed in U.S.A.

International Business Machine Corporation

1

Program

C

Indicators

::i
0_
..Ja:

line

4

5

I

a 1.1
01 2 1

6

7

8

Factor 1

Operation

C

I

C

1

15

Length

15

z

9 10 1112 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 4B 49 5051

I I I I Ink!. lip rrlAIBl4IMTI I I I TIA IBh" lAlx I I
I I I II II II II
II II II II II II II II
I I I I II II II II II II II
I I
I I I I I I

'iR1T"'~liY1-'
1.1

I

I

I

Figure 8-23. Searching for High or Equal Condition

8-20

I 1 I· I I I

Resulting

Indicators

Plus IMinusl Zero

Factor 2
'. Name

z

75 76 77 78 79 80

~~~~;~f:ation I

Arithmetic

t- (5 a;E ; (.I]

&8 5 ~
3

Result Field

AL At

=0

~..i~

2

Page [00'_

Date

Programmer

-

\"

Likewise, if the table is in descending sequence 11-9-6-4-2,
the search word (7) would come between 9 and the 6.
Regardless of the sequence (A or D), 9 would satisfy the
high condition, while 6 wouldsatisfyt,he low condition.

Searching for either a low or high condition (for the same
LOKUP operation) would not be specified, since a majority
of items in the table will satisfy one of the two conditions.
The condition(s) which must be satisfied can depend on the
type of data in the table, the data used as the search word,
and the sequence of the data within the table.

IBM

(---

To perform a table search for an equal condition only, it
isn't necessary that table entries be in any particular order.
Starting at the beginning of the table, the table elements
are checked, one at a time, until an equal entry is found or
the end of the table is reached, whichever occurs first.

Compare

Comments

1>21<211=2
L06kup(Factor 2)is
High Low Equal
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

11h

I lza

11111111111111

I1 ,II II,. "I I, ,I ,I I, ,I I, I, ,I II II II II II

c

\

\

)

element 11, because it is the first entry encountered after
element 4, which is greater than the search word. ,Element
9, which is closer in value, yet higher than the search word,
would not be retrieved since the table is not in sequence.

Up to now, we have discussed table entries containing
single items of data. However, a table entry may contain
more than one field of information. For example, each
entry in TAB 123 contains a 15-character ite,!Jl description,
followed by a 4-digit unit cost with two decimal positions
and a 3-digit quantity in stock. A pair of related entries
from TABCOD and TAB123 might appear as in Figure 8-25.

The sequence of a table is specified by entering an A or D
under Table Sequence (columns 45 and 57) on the Extension sheet (see Figure 8-24). When an entry is made in a
sequence column, the RPG II program will check the table
entries to ensure they are in the appropriate order (ascending or descending) when loaded.

TABCOD

Generally, table entries are arranged in ascending order, if
a sequence is necessary. For certain applications, however,
you may find descending sequence more suitable. For example, you may find that the entries with higher values
are to be referenced more often. By placing such entries at
the beginning of the table (highest to lowest), you may decrease the amount of time required to search a table.
Table entries to be in descending order are designated by
entering a D in the columns 45 and 57, rather than an A.

Defined as Numeric
Table Entry

TAB123

)

The fact that a table should be in sequence can affect the
design of the table input record. In general, when using cards,
table input records containing one entry per record
(or pair of entries if alternating format is used) are more
desirable for sequenced tables. In this way, when a sequenced table is to be updated with additions or deletions
the change cards can simply be inserted or removed.

~-"'-4D'
~3D'
.
- IQlt
15-Character
- IQlt
Description

Cost

Quantity

Defined as Alphameric
Table Entry

Moving Data in a Table Entry
Suppose you wish to use a table TABCOD to LOKUP data
from a related table, TAB 123. TABCOD contains codes
for all items carried in stock. TAB 123 contains information about each of the items.

RPG

mM

Figure 8-25. Table Entries of More Than One Data Field

EXTENSION AND LINE COUNTER SPECIFICATIONS

Form X21-9091
PrintedinU.5.A.

Intem.tion" Business M.chine Corporltion

1 2

Program
Page

Date

Programmer

[0

75 76 77 78 79 80

Program
Identification

of_

rTlTITl

Extension Specifications

-

E
Line

Record Sequence of the Chaining File

Number of the Chaining Field

To Filename

&
~

From Filename

~
3

4

6

6

Table or
Array Name

7

8

Number
of
Entries
Per
Record

Number
of
Entries
Per Table
or Array

Length
of
Entry

j~

Table or
Array Name
(Alternating
Format)

:1~~

~~!

e

length

of
Entry

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 333435 36 37 38 39 40 41 42 4344 45 46 47 48 49 50 51 525354 5556

01 1 1 E I J I I Jllil 11 I I I I I IrlA 1a.I.ll MIT I 1I 13~ I Ie; 12lA "'lAlsh'IRIX I 13
01 2 1 E I I I I I I I II I II I I I I II I I I I I II I I I
I I I II II
I

I

I

I

I

I

I

I

I

I

I

I

I

Comments

~

g j~
ii:
a:

~56~OO~~~54ffim~56mronnn~

2A

1111111111111111
II I I II I I II I I I I II
I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

Figure 8-24. Specifying Sequence of Table Entries

Tables

8-21

As you know, following a successful search, you can use the
entire looked-up entry in calculations and output merely by
specifying the table name. If the table name TAB123 was
specified on the Output sheet, the description, cost, and
quantity would all be printed or punched, as follows: 10
IN BAND SAW0950107. The data items would be run together, just as they appear in the table entry.
If a table entry contains several fields of data, often you
may wish to use only part of the table entry in a particular
program. For example, to do your billing, you need only the
item description and cost from TAB 123. To reference only
part of an entry, the data in the TAB123 entry must be
separated after the successful search. This is done by moving the data from TAB 123 into smaller separate fields, which
can then be used in calculations and output.
As shown in line 02 of Figure 8-26, first the contents of
TAB 123 are moved to the left into a 15-character alphameric field. This isolates the description, which can then be
printed by referring to the DESCRP field name on output
specifications. To isolate cost, which is in the middle of
the table entry, you must first move it, along with one of
the outer fields (quantity or description), into a temporary
work field. Thus, line 03 moves the rightmost seven characters (cost and quantity) into an alphameric field, WORK.
Since the cost is now in the left part of the WOR K field,
moving the field to the left only four places will isolate cost
from quantity. In this way, the field COST can be used to
reference only the cost information. Furthermore, COST
is specified as a numeric field so that cost data is in the
proper format for use in calculations.

RPG

IBM

The data from the table entry is now separated into new
fields which can be used in calculations or to output the
single items of data.

At some point, you may wish to make changes to the data
contained in a table. These changes can be temporary, for
a particular run; or they can be permanent, such that every
time a job is run which references that table, the program
uses the changed table data. '

Making Temporary Changes to Table Data

Temporary changes to the entries in a table can be made by
calculation specifications which are actually a part of your
RPG II program. For example, two tables provide the item
code (TABITM) and unit price (TABCST) for each part. If
you change the price of a part for a particular run, you must
necessarily change the entry in TABCST for that part.
As Figure 8-27 shows, TABITM is searched to locate a certain part code. On a successful search, the unit price for
that part is made available from the corresponding entry of
TABCST. This information is available for the table named
under Result Field (line 01).
By using the name of the table referenced (TABCST) in any
operation other than the LOKUP (see line 02), you are actually referring to the table entry last looked-up. Thus, by
moving the field to TABCST, you are actually storing the
new unit price for that item in the table.

Form GX21-9093
Printed in U.S.A.

CALCULATION SPECIFICATIONS

International Business Machine Corporation

1 2

Programmer

C

Page

Date

Indicators

~

-

Result Field

0_

=~

AL

~~~

t-ori

E E~

5

Jd

Factor 1

Operation

Factor 2
Name

Length

.~
'a

~

E

~

.~
(;
(;
z
z
C
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

J! 8 5 ~

3

4

o
o

1

C

2

o

3

o
o

4

5

c
c
c
c

o

6

C

-

-

6

7

8

[

~2

",

!K

') r'I 'k~

I~

'p- ~A R ',.

~In

rrlLl Pol I, ~

21~

''''!I= c;.". 'r:lP

2~

W,.. R.'k

,,,,,1'

MI\ v ,I;:

TA AI
riA R'J

~IL

pf-' viI='

WI"'! QIt

Mf

rJ~'

"Ill.

1"1""

"'/"'1 ~r

Figure 8-26. Isolating Part of a Table Entry

8-22

\

Modifying the Contents of a Table

Program

Line

,/
I

I, -

Yi

--

foiL

Resulting
Indicators
Arithmetic
Plus 1Minusl Zero

Comments

Compare

1>211<211-2
Lookup(Factor 2lis
High Low Equal
54 55 55 57 5859 50 61 62 63 64 65 65 67 68 69 70 71 72 73 74

411
l~

75 76 77 78 79 80

[DOf_ :~:~f:ation I I I I I I I

,..,,. Arr~

......

r'lFIF

ST jr" 'TV
""N LV T" NUM

,..,.. Si

tiL

P J L
r-,... ST

T"" riAL

h2.

T'"' riAL

i

lrTM ""'A T~

Pl LL

tot I-'

""f"'!

Dl

~

c·

RPG

IBM

)

International Business Machine

CALCULATION SPECIFICATIONS

Form GX21·9093
Printed in U.S.A.

Corpor.t~on
1

Program
Date

Programmer

C

Indicators

~

9;riQ

'---

Line

3

4

5

Operation

Indicators

.g

Factor 2
Length

IIIIII

Arithmetic

~

Factor 1

75 76 77 78 79 80

~~:;~':ation I

Resulting

Result Field

At Jd

& i.V;

2

Page [ ] ] o , _

:r: Plus IMinusl Zero
Compare

~ ~

Comments

~~~
E~~
~ 85

~
~

6

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 5859 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

0 1

C

a

2

C

o

3

C

7

8

Name

~

~~
'u

15

!!::

ox

z

lIlT Mif1 ~n

4b

111f1IK IC,T ~S 1 TIN
M~ Iv!;' rll AI\.! ric

IA~

I~T

I~~

~T

1>211<211-2
Lookup(Factor 2)is
High Low Equal

~~

Figure 8-27. Modifying a Table Temporarily

As you can see, the use of a table name as the result field
of a calculation operation is one means of modifying the
contents of that table. Since the changes are indicated by
specification entries, the changes must be planned for while
you are still writing the RPG II program. Otherwise, the
instructions could not become a part of the object program.

)

It is very important to note that any changes made to a
table during execution of the program exist for that run
only unless additional specifications are made that indicate
a permanent change. Thus, the next time the program is
run, the original table data is used.

Making Permanent Changes to Table Data

Whether the contents of a table must be permanently
changed generally depends on the type of data contained
in the table. For example, a table used to keep inventory
records will undoubtedly change quite often. Assume a
company uses a table to hold the quantity on hand for each
part manufactured. Every time the company manufactures
more of a particular part or sells (and delivers) a part, the
quantity on hand for that part must be increased or decreased, accordingly.

Short Tables for Adding New Table Entries

Rather than changing data already stored in a table, there
may be cases in which you want to add additional data to
an already existing table. For example, assume your company wants to keep a list of employee numbers and hourly
wages in two tables, TABEMP and TABWAG. At the present, there are 46 employees on the company payroll; thus,
there should be 46 entries in each table. However, you know
that the number of employees may increase to about 90-100.
Therefore, you will want to add entries to the table as new
employees are hired.
At the time the table input records are set up, you must describe them on t~e Extension sheet. This means that you
specify the number of entries per table. If you were to specify only 46 entries per table, it would be necessary to code
new extension specifications every time the number of table
entries changes. Since the extension specifications are compiled and become part of the object program, it would be
necessary to recompile the program to make such a change.

The only way to make a permanent change to the data in a
table is to change the table input records. If the data is
changed as a result of calculation specifications performed
during a run, the changed data can be punched into cards
or written to another output device during the run .. In this
w~y, the output can be used as table input records for the
next run.

)
Tables

8-23

If you know beforehand that the size of your table will increase, you can initially build a short table. I n a short table
only some of the table entries contain actual table data.
The program fills the unused entries with blanks. Thus,
TABEMP and TABWAG can be defined as 100 entries each;
although for now, you plan to use only 46 entries in each
table (see Figure 8-28). Of course, be aware that enough
storage wi" be reserved for 100 entri es. The storage required for the unused table entries will not be available to
hold any other data.

RPG

IBM

As new employees are hired, the new table entries can be
added by inserting additional table input records. The
original extension specifications still correctly describe the
table, as they merely indicate the maximum number of entries allowed for each table.

;'

Whether the RPG II source program and the table input records must be recompiled depends on which method was
selected originally for loading the table. The methods of
loading tables and their effect on short tables is discussed in
a following section.

EXTENSION AND LINE COUNTER SPECIFICATIONS

Form X21-9091
Printed in U.s.A.

InternatiOnal Busineu Machine CorPOration

1 2

Program

Page

Programmer

Date

m

75 76 77 78 79 80

[D0f_ ~~~;~f:ation I I i.1

Extension Specifications

E
line

Record Sequence of the Chaining File
Number of the Chaining Field

To Filename

...~

Table or
Array Name

From Filename

j

EMPLOYEE
NUMBER

Number
of
Entries
Per
Record

Number

of

Entries
Per Table
or Array

WAGE

Length
of
Entry

j~

Table or
Array Name

:3 ~ ~
~~i

TABEMP

~

---a..------

46

...

---z----

-

--------7 2 1 846
------------.

--

~

Unused
Entries

Length
of
Entry

e
~

-

~
~

--,

---- .. .........
Figure 8-28. Adding Entries to a Short Table

8-24

(

---------

~

---

~

---

------2.1 5
--- ----

----------

-

...-"L--

----"1

~

Comments

~ j
c: ~

TABWAG

-Table Entries to be
Added (Record
Inserted in PAYROLL
Table I nput Records)

(Alternating
Format)

--

46

100
Entries

LOADING TABLES

\ Table data can be loaded into the computer at two different
) points: at the time your RPG II source program is compiled
(compile time tables) or at the beginning of your RPG II
object program execution (pre-execution time tables. How
often you wish to make permanent changes to the data contained in the table usually dictates the time at which you
choose to load that table. The choice should be made as you
plan your application, since your decision may affect the
design of your table input records and the specification entries
required. Furthermore, loading of the table input records
differs, according to the type of table used.

Compile Time Tables

)

Tables loaded at the same time as your RPG 1\ source program are referred to as compile time tables. In other words,
the table file is compiled (or translated into the machine or
object language) along with the RPG \I source program. In
this way, the table data is actually a part of the object program. Every time you run the particular object program,
then, the table(s) are brought into storage at the same time
as the program. As you can see, one definite advantage in
creating compile time tables is that you avoid the necessity
of loading separate table files into the computer every time
you wish to run that object program.

tables must be loaded in the same order as they are described
on the Extension sheet. The end of file record (/* in positions 1-2) which usually comes at the end of the source program is then,placed after the last compile time table~
Model 10 Disk System, Model 6, and Model 15 users may
place compile time tables in the source library following
the source program. The samy record sequence as shown
in Figure 8-29 is used. See the applicable reference manuals for your system for specific procedures.

Pre-execution Time Tables
In general, if a table is to be permanently modified often, it
is better to create a pre-execution time table. Such a table
file is not compiled with your RPG II source program. Instead, only the source program is compiled or translated
into the object program. Once the object program has been
loaded into the computer to be executed, the table file is
loaded separately. Like any other input data file, the table
file is then used by the object program, r'ather than being a
part of the program.

Changing Compile Time Tables
Temporary changes to data in a compile time table exist
only for a particular run and are made as easily as for any
table. Calculation specifications which have been previously coded in the program can modify any of the table
elements.

a

Making permanent changes to compile time table or add~
ing new entries to a short compile time table requires recompiling the entire RPG \I source program along with the
new or changed table input records. The object program
produced then contains the current table data. Of course,
this process of recompilation requires extra time.

Loading Compile Time Tables

)

A table to be compiled with your program should follow
the RPG \I source program (Figure 8-29). There should be
a record immediately before the table containing ** in positions 1 and 2. Position 3 must be blank but remaining positions may be used for comments, such as the table name.
If more than one table is to be compiled, an ** record should
be placed before each table. Furthermore, the compile time

Card System Users: The source program
and table input records as shown here
are placed in the secondary MFCU
hopper. The RPG II compiler program
is placed in the primary hopper.

Figure 8-29. Loading Compile Time Tables

Tables

8-25

Changing a Pre-execution Time Table

Modifying a pre-execution time table takes much less time
and effort than changing a compile time table. Modifying
the contents of the table permanently (whether short
table or a full table) can be done by inserting and deleting
change records. In any event, only the table file is changed.
Since there is no need to make changes in the RPG " object
program, it isn't necessary to recompile the entire program.

a

Loading

Pr~-execution

Time Tables

Pre-execution time tables are similar to any other input data
files in that the RPG II object program uses the files when
the program is executed. However, unlike other data files,
pre-execution time tables are read completely before operations involving the tables are done. An end of file record (/*)
must follow every pre-execution time table file, regardless
ot'whether the table is short or full (Figure 8-30). The **
record that precedes each compile time table is not used for
pre-execution ti me tables.

The table files should be in the same order as for compile
time tables. All table files are to be loaded in the same
order as they are described on the Extension sheet. Furthermore, if both pre-execution time table files and other input
data files are to be used by a program, all tables must be
loaded before the data files.

Other Systems: Table files loaded at preexecution time may be loaded from console,
cards, disk, or tape.

Figure 8-30. Arrangement of Input for Pre-execution Time Tables
8-26

\

Specifications for Pre-execution Time Tables

Since a pre-execution time table is a separate file to be used
by the program, the entire file of table input records must
be defined on the File Description sheet, just as any other
file must be. This specification sheet is not required for
compile time tables because the records are not used as a
file. Instead compile time table data becomes a part of the
object program.
Figure 8-31 shows the file description specifications required
to define a pre-execution time table input file. A filename,
different than the table name, should be assigned to the entire table file (columns 7-14). In this case, the file called
SALESTAX contains data for both TABAMT and TABTAX.
An I in column 15 distinguishes that SALESTAX is an input
file. Notice, also that the File Designation entry (column
16) must be a T, to indicate that this is a table file, as well.
The Device entry (columns 40-46) indicates the device from
which the table file is read; in this example, we are using
MFCU2.
Ordinarily, if an input file is to be in a particular sequence,
an entry (A or D) is made in column 18 of the File Description sheet. However, when specifying a sequence for table
files, the sequence columns (45 and 57) on the Extension
sheet must be used, rather than the sequence column on
the File Description sheet. An E has been entered in column 39 of the File Description sheet to indicate that the
records in this table file are further described on the Extension sheet.

Model 10 Card System Users: The table files
are loaded from the secondary MFCU hopper.
The RPG II object program is loaded from
the primary hopper.

I

Looking at Figure 8-31, you can see that the filename assigned on the File Description sheet is also entered under
From Filename (columns 11-18) of the Extension sheet.
This common entry tells the computer that the extension
specifications describing TABAMT and TABTAX tables are
associated with the SALESTAX file defined on the File Description sheet. For compile time tables, no entry is made
in columns 11-18. This is because no file description specifications are made and, thus, no filename is assigned to compile time table records.

(

Page of GC21-7567-2
Issued 24 May 1976
By TNL: GN21-5389

File Description Specification
File Type

-F

--j

\1odeo~i~

Extent Exit
for DAM

~:,,~th of Key Fie~~ield
'T~I'"

-----

Filename

Symbolic
Device

Device

.. u"""'" u. """""

Name of
Label Exit

File Format

Una

t:°tI4:t-tIFHI-H~±::!:;±±~:±±jItINo entry made in column 18 - sequence
15-t-fi-f-F+-+-+- F Ie
differs
1
016
iF
ifrom table.
0

j-t-

,

IBM

IntemahonaIBus;nessMach;neCo,porohon \

. Program

.If-I- of table files specified on Extension sheet

.......

~
~

EXTENSION AN,D LINE

~Ching
Ins~

J

\

E

~~."

E in column 39 indicates Extension
specifications are used.

/'

'\

. Programmer

...... t'

t-t-b~

Graphic

.1

"'7~ SPECIFICATIONS

L.-1'

1

Y
1
~&n~lon Specifications

Form X21-9091
Printed in U.S.A.

1 2

Card Electro Number
Page

[DOf_

75 76 77 78 79 80

Program
IdentificatiQn

rTrTlll

,,,. Chaining File

f-Comments

,-

)

specification to a particular File
J'
""

Figure 8-31. Defining a Pre-execution Time Table File

I

./
Tables

8-27

OUTPUT OF AN ENTIRE TABLE

Writing or punching an entire table at end of job is very
easy to specify. Just as for any type of output, the output
file must be given a name and assigned t.o an output device
on the File Description sheet. However, no output specifications are necessary for end of job table output. You merely specify the name of the output file in columns 19-26 of
the Extension sheets on the same line'as you described the
table input records. With the extension specifications shown
in Figure 8-32, the table will be put out automatically at
end of job.

Up to now, we have discussed how to write or punch only
individual table entries, one at a time. In this way, only
table entries which satisfy a search condition (which have
been placed in the hold area) have been used as output.
For various reasons, you may want an entire table written
or punched out. Perhaps you want a listing of the table entries to determine if any changes should be made. If your
program updates a table, you may wish to output all the
entries to be used as table input the next time the program
is run.

The output data may not be exactly the same as the
input data, because table entries are put out as they are at
end of job. Thus, if your program has changed or updated
any table entries, the modified data will be put out, not the
original data. Except for printer output, however, the format of the table output records will be the same as the input records.

An entire table can be written or punched out only at the
end of the job; that is, after all other output has been completed (LR on). Even if the table is a short table, all entries
are put out including those which are unused (blanks or
zeros).

RPG

JBl«

EXTENSION AND LINE COUNTER SPECIFICATIONS

Form X21-9091
Printed in U.S.A.

Internallonal Busmess Machine Corporation

1 2
Page [ 0 0 1 _

Date

Programmer

IIIm

75 76 77 78 79 80

Program

::;:I:ation!'

Extension Specifications

E

Record Sequence of the Chaining File
Number

I---

Number 01 the Chaining Field
To Filename

Line

Array Name

0.

>

f-

From Filename

~
8

Length
01
Entry

00

:jii ;;C
0-

"-

"

ill

Table or
Array Name
(Alternating
Format)

0

1

E

o
o

2

E

3

E

-I

0

4

E

I

0

5

E

IL I 5T IIINIGI

1-A1~.l

lI II II I LI II II Jl
I I

~leTYpe

F

q~

13

I

Sequence

I

File AdditionNnordered

~

~~

]
o

2

F

o
o

3

F

4

F

o

5

F

o

6

F

::::117

9

0

~
w~~

Block
Length

10" 12 13 14 IS 16 17 18 19 20 21 22 2

rs Irlr NG

Iro.

Record
Length

II:

::J

Z
u;

!

Number 01 Tracks
for Cylinder Overflow

Name of
Label Exit

.:l

Number of Extents
Tape
Rewind

Core Index

~
Condition

-~

Continuation Lines
:>

K

Option

Entry

~

~

Ul-'r!!!-

~

242528 27 282930 31 J2 JJJ4 J5 J6 37 J8 J9 4041 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 6061625JM65 66 67 M69 707172 7374

11~12

Figure 8-32. Specifications for Output of Entire Table at End of Job

8-28

Symbolic
Device

Device

Indicator 0
... Overflow
r---ti
Key Field
Starting
£La
~::::
Location ~

!Io! 15
::::f-

Extent Exit
for DAM

~

-g

Line

0

5Tk

I

Type 01 File
:::!
Organization
w
or Additional Area

File Format

e~

r.t'\1

IrhIn r:lc.

I I

Record Address Type

!.

~~Wro~~5JM~~~MwronnnM

IIlrlM

length 01 Key Field or
of Record Address Field

End of File

5 6

~ i

Mode 01 Processing

File Designation

Filename

Comments

~

File Description Specification

/

4

0
~
II:

auses entire table to be
'printed at end of job.

1/

r----

1312

v'

14-t I I 111 I I

I

3

Length
01
Entry

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 J4 35 J6 37 J8 J9 4041 42 4344 45 46 47 48 49 50 51 52 53 54 5556

3

6

7

Number
01
Entries
Per Table
or Array

4

5

01
Entries
Per
Record

Table or

1.... 11'1f"C

IN

K

Review 8

)
(Answers to review questions follow the review.)
1.

a. Design the table input records for an inventory table of item numbers. Each item
number is a five-digit number. There are 123 unique items in stock. Use either one
record per item or one record for a number of items. State the maximum number of
. records necessary to contain the table data. State the minimum number of records
necessary to contain the table data.
b. Assign a name to the inventory table.
c. Define the table by coding the necessary extension specifications.
d. Code the calculation specifications necessary to search the table for an item number which matches the item number (ITEM NO) on an order record.
e. Why must a resulting indicator be specified in columns 58-59 of the Calculation
sheet for the LOKUP operation?

2.

a. Design alternating format table input records to create two related tables from the
following data. Put one set of entries on each record.

")
./

Item Number

Costs

10
17
27
68
102
700
1640
2796
4333

$ 10.00
75.00
125.00
1.25
.01
.05
7.03
72.05
111.11

b. Define the tables by coding the necessary extension specifications;
c. Using ITEM as the search word, code the calcul.ation specifications for a two-table
search which makes the appropriate cost available.
3.

. 4.

How does a programmer specify that a table search is to satisfy a high, low, or equal
condition?
What indicates whether a table lookup was successful or not?

5.

How does a programmer reference looked-up table data in calculation and output
specifications?

6.

If looked-up table data is to be referenced in calculations or output, how can a programmer ensure that the appropriate information will be used?

7.

How may table data be changed during execution of an RPG II program?

8.

What must be done to change table data permanently (to exist for more than the
present run of the program)?

Review 8

8-29

9.

What is a short table?

10.

What is the advantage of using a short table?

11.

Which specification sheets are necessary to program for output of an entire table at
end of job? What is the use of each type of specification required?

Review Problem
To perform invoice billing, a corporation processes two input files together in a matching
records program. As.the following input specifications show, the primary CSMSTR
(customer master) file contains a record for every customer who has placed an order, giving
the customer number, name, and address. The secondary ORDER file contains data about
each order: customer number, item ordered, weight of item, and cost.

RPG

IBM

GX21·9094

INPUT SPECIFICATIONS
1

2

75 76 77 78 79 80

Program

I

Record Identification Codes

E

]

I--

g

Filename

Line

E

,....-I-,.....§

.f

o

R

1"A"Nrci"
5

6

7

8

z

c

~.i5

~

.".'"
0

~

Position

~

~

t

e~

;;

Position

~ ~ <5

~

-

~

e !J~

~f)6

Position

%0 ~ ~ ~
~

From

lsrrR

L~

I

11

INS

rzll

1

12.~
KIL II:. If<

N'S

~12

1

ril-l

6

I

B

0 7

I

17

o

8

I

o

9

I

lLl2.
1115

1 0

Field
Indicators

0

0

j~
"''''

3

"-,,-

8

iJ

~

j
~

Zero
Plus Minus or
Blank

u:

r~

I
I

..,

lla~ rt 1ST N~
!2.1 :NA 11'1~

!3b 'A
k~ Irll

It<'"

1f\11

.......

c;rIN"

1\11

lLL au. IT I- !VI
II

'-I IlIA. II='T

lL "f I,!.

r;~T

SoT

I

.

According to company policy, merchandise is delivered by truck unless a customer has requested delivery by parcel post. To date, the following 15 customers (by number) have requested parcel post service:
174
195
·2105

2109
169
2733

596
456
1100

1157
1366
290

1475
377
1977

The customer always pays parcel post charges. The charge is in accordance with the weight
of the ordered item, as follows (assume no order weighs more than 30 pounds):

8-30

IIIIII

9 10 11 12 13 1415 1617 18 1920 21 22 23 24 25 26 27 28 29 30 31 3233 34 35 36 37 J8 39 40 4142 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 6364 65 66 67 68 69 70 71 72 73 74

0 2

I

~
]

0

0 3

5

~
'2

§ ~~~

I r IS 1M

0 4

Field Name

rf.

To

0 1

o
o

~~~;~f:ation I

Field location
3

2

1

g'.

~

1!

~
I-

4

pageDJOf_

Date

Programmer

3

U/M 050'

Printed in U.S.A.

Inte,n,1,onal BUSiness Mach.ne COrporallon

/

WEIGHT IN POUNDS

j#
2
·3
4

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

POSTAL CHARGES

-----------

_______ $0.45

-------~
--~
----~
--~

---------~
--------~
--~
.65
.65
.70
.70

---------

======
____
______

.75
.75
.75

------~
.80
.85
.85
.85
.90
.90
.95
.95
.95
1.00
1.00
1.05
1.05

Note: Any fraction of a pound over the weight
shown takes the next higher rate.

)

To produce invoices, the billing program must do the following:
a. Determine if a customer has requested parcel post delivery.
b. If so, determine how much postage is required for the weight ordered.
c. Print the amount of postage due on the invoice (printer output file named INVOICE).
This can best be done by setting up three tables:
•

A table of customers who have requested parcel post delivery .

• Two related tables of weights and postal rates.

)
Review 8

8·31

Your job is to:

1.

Design table input records for the three tables. The table of customers requiring parcel post service should be created as a pre-execution time short table to allow for frequent additions and deletions. A table of 24 entries should be sufficient for containing additions. The weight and postal rate tables should ~e loaded at compile time,
since they will not be modified.

2.

Define and describe the tables with file description and extension specifications.

3.

Code the LOKUP operation(s) on a Calculation sheet to determine how much postage is due, if any.

4.

Code the output specifications to print the amount of postage due on an order.

(
I

\.

(
\ ....

c
8-32

"

'0.' •

"•• _;.

~

Answers To Review 8

I

)

1.

a. The, maximum number of records necessary to contain the table data is 123, with
each record containing one item number entry in positions 1-5. The minimum
number of records necessary to contain the table data depends on the maximum
record length of th,e, device. For 96-column cards, for example, the minimum
number is seven records. Records one through six would each contain 19 item
number entries punched in columns 1-95. Record seven would contain the remaining nine item number entries punched in columns 1-45. For disk, all entries could
reside on a single record, since the maximum record length is 9999.
b. The table name assigned (for example, TABINV) must meet the following requirements:
• Three ,to six characters long
•

May contain any numbers and alphabetic characters (including, $, #, @)

•

Must begin with TAB

•

May not contain embedded blanks

c.
RPG

IBM

EXTENSION AND LlNE'COUNTER SPECIFICATIONS

Form X21-9091
Prmle-d In U,S,A.

InUtrnatlonal Business Mechine Corporation

1

Program
Page

Programmer

Date

2

75 76 77 78 79 80

[DOf_

Program
Identification

InTrn

Extension Specifications

E

-

Line

Record Sequence of the Chaining File
Number of the Chaining Field

To Filename

~
t-

From Fjlename

~
7

3

4

0

1

E

o

2

o

3

E*
E

0

4

E

0 5

E

5

6

0 6

E

0 7

E

0 8

Table or
Array Name

8

Number
of
Entries
Per
Reqrd

Number
of
Entries
Per Table

C

Length
of
Entry

_

Table or
Length
Array Name 01

j~

(Alternating
Formatl

~ ~ ~

~~j

or Array

Entry

0
~

~

j

9 10 1\ 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56

1

lL12~

I; It

rr~ Istr INV lLq

11 12 '?!

lJi

h"IA Islr N,v

Comments

~

a:

~56Wro~~~~~~~56~ronnnM

I~IN I-IR Y

~

~ ,1"'1:1".

;'"'

hR

MIA INI'f

~

~IN TIR II

f s~ IRE'"

E
E
E

Line Counter Specifications
10

L

-

Line

~

Filename

t-

1:

]
3

4

--...,

1

1

~

1

2

5 6

" E

:5£
7

8

~
~
z

~

" ::JE
.S:

-'z

a;

1)
~
z

~

C,O

~

:J

~

'ii ~

C,O

" E 2~
.!uz; .=-'z
uz
::J

1)
" E
.S:
::J

-'z

"ii ~
C.c

1)

" E
2' 5 :5:i

uz

~~
~ §
uz

~

" E
.S:
::J

-'z

~~

~ §
uz

.c

.~ §

-'z

Cii :u
C.c
~ §
uz

a;
.c

" E
.S:
::J

-'z

~
C,O
C

E

ll~

.1l
" E
.S:
::J

-'z

9 10 1\ 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 56 59 60 61 62

12

\I

~1i
C E

2 ~
uz

~

64 65

.c

" E
.E
::J

-'z
~

]:8E
C

2 ~
uz

1i

" E

:J~

~~

~ §
uz

67 56 69 70 71 72 73 74

L
L
L

Answers To Review 8

8-33

d.

RPG

IBM

Form GX21·9093
Printed in u.s.A.

CALCULATION SPECIFICATIONS

Internation,l Business Machin. Corporation

1 2

Program

Page

Programmer

C

Date

Indicators

~

-

~~

4

3

Factor 1

Operation

Factor 2
Name

.... '00:"

E ::.

5

(I)

Resulting
Indicators
Arithmetic
1'!
.g J: Plus IMinusl Zero
Compare
Length ~
1 >211 <211-2
~~ Lookup(Factor 2)is
2 ";
C :t: High Low Equal

Result Field

AL

AL

~.s~

line

75 76 77 78 79 80

[Do,_ ~~~;:f:ation I I I I I I I

Comments

;

& 8 ~j

z15

6

9 ,0 " , 2 '3 ,4 '5 16 17 '8 19 20 2' 22 23 24 25 26 27 2829 30 3' 32 33 34 35 36 37 38 39 40 4' 42 43 44 45 46 47 48 49 50 5' 52 53 54 55 56 57 58 59 6061 62 6364 6566 6768 69 707172 73 74

0 1

c

0

2

C

0 3

C

0 4

C

0 5

C

7

8

~

15

z

lilt:

IN

~~k

I...

IMtj

Nlv

!21L

rs !rtrM

~N

~IT h"IK

e. A resulting indicator must be set on if the item number is in the table to indicate
whether the search is successful or not.

2.

a. Nine records required for nine pairs of item number/cost entries:

006800125
4 I,

001001 000

I,

4,5

9,1011

001707500
2 I'
A.5

9.10 11

002712500
3 I'
4.'

9.10 II

1213 Tot

15 1617 181920

12 13 .. 15

I~

17 18 "

9 ,10 11

4,5

5

20

010200001
9,10
4.'

I,

11

070000005
6 I'
41'
1
9

121314151617181920

10 11

164000703
7 I,
4,5

1213 '4 15 16 17 18 1920

9,10 11

279607205
4.,

8 I'

121314151617181920

9

1213 '4 1516 17 181920

9t

1213 '4 151617 181920

(
10

"

1213

,.. 1516 17 1819 20

'" ', ......

433311 1 11

I,

41'

9.10 11

12 13 14 15 16 17 18 19 20

b.
RPG

IBM

EXTENSION AND LINE COUNTER SPECIFICATIONS

Form X21·9091
Printed in U.S.A.

International Business Machine Corporation

1 2

Program

pageDJof_

Date

Programmer

75 76 77 78 79 80

~~;:f:ationl

Ii Im

Extension Specifications

E

Record Sequence of the Chaining File

I'---

Number of the Chaining Field

To Filename

Line

Table or
Array Name

From Filename

3

4

o

1

o
o

2

3

8-34

5

6

7

8

Number
of
Entries
Per Table
or Arrav

c _

Length
of
Entry

:~ ~

~ ~
~~l
:)

Table or
L,mgth
Array Name of
(Alternating
Format)

Entry

0
~
0:

~

~

Comments

I
~

9 10 11 12 13 14 ,5 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 J3 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

rll~nHI'

E

Number
of
Entries
Per
Record

rv

1

q

5 '2

c.

RPG

IBM

/

Form GX21-9093
Printed in U,S.A.

CALCULATION SPECIFICATIONS

International Business Machine Corporation

I

1

Program

I

2

75 76 77 78 79 80

pageDJOf_

Date

C

Indicators

I--

At At

~
E

3

4

5

Arithmetic

Factor 1

Operation

:¥ g

Factor 2
Name

'0
z

IIIIII

Resulting
Indicators

Result Field

~

Line

~~~:~f:.tion I

Length

~ ~

Plus IMinusl Zero

Comments

Compare

1>211<211=2
~~ LookuplFactor 2)is
'2 ~
OJ: High Low Equal

~

~

6

9 10 11 12 13 14 1516 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 5051 52 53 54 55 5657 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

0 1

c

0 2

C

0 3

C

0 4

C

0

z

trlT If 1M

3.

~K

lip ITlA Blr TIM

I

~J"J

~

~li

To search for a high condition enter a resulting indicator in columns 54-55 on the same
line of the Calculation sheet as you have specified the LOKUP operation code.
To search for a low condition, enter a resulting indicator in columns 56-57.
To search for an equal condition, enter a resulting indicator in columns 58-59.
If more than one condition will satisfy a search, a resulting indicator should be entered
for each condition. The same resulting indicator may be used for both conditio~s or a
different indicator may be specified for each condition.

4.

The resulting indicator specified for the high, low or equal condition (columns 54-55,
56-57, or 58-59) will be set on if the particular search condition is satisfied. The indicator will be off if the search was unsuccessful.

5.

In any calculation and output specifications which follow a LOKUP operation, use of
a table name refers to the table data found by the lookup.

6.

The resulting indicator specified with the LOKUP operation can be used to condition
calculation and output specifcations that follow the LOKUP.

7.

When a table name is specified as the result field of a calculation operation, other
than LOKUP, the result of the operation is placed in the table, replacing the last element looked-up. This assumes that a search was previously performed on th~ specified table.

8.

The·table input records must be recreated. If calculation specifications change table
data during execution, the programmer may code specifications which cause the
changed data to be output as new table records. The new output records can then be
read in place of the old table input records the next time the program is run.

9.

A short table refers to table input records which contain fewer entries than the extension specifications indicate the table can contain.

10.

The advantage of using a short table is that entries may be added to a table without
changing the extension specifications which describe the table.

)

)
Answers To Review 8

8-35

11.

File Description sheet - assigns the name and device of the output file
Extension sheet - indicates automatic table output at end of job when name of the output file is entered in columns 19-26

/

I nput, Calculation, and Output sheets - not required

Answer to Review Problem
1.

Customer Number Table Input Records

Since the largest customer number is four digits in length, each entry would require
four positions. A customer number less than' four digits should be padded in front of
the number with zeros or blanks, to form a 4-position entry.
The simplest table input records to design and maintain for this table would contain
one entry per record in positions 1-4. With this design, 15 records would be necessary
for th~ 1q~ust.t>,mer numbers. To add entries to the table, merely add table input
records.
An alternative method is to place the 15 entries in positions 1-60 of a single record.
A record can contain a maximum of 24 4-digit entries. Entries may be added to the
table by placing new customer numbers in unused positions of the same record. However, to delete entries, the entire record would have to be recreated.
Weight and Postal Rate Table Input Records

The WEIGHT field from the ORDER input file is to be used as the search word for
locating the appropriate weight in the table. Therefore, the weight table entries must
be the same length and format as the search word: three digits in length with one
decimal position. The corresponding postal rates can be three digits with two decimal
positions, to accommodate the largest entry 1.05.

(

Using an alternating format, one record could be used for each pair of entries (positions 1-6), for a "total of 30 table input records. Otherwise, the first 16 pairs of
entries could be contained in positions 1-96 of one record with the remaining 14 pairs
contained in positions 1-84 of a second record.
If separate records are to be used for each table, the 30 weight entries could be in
columns 1-90 of one record, and the 30 postal rate entries in columns 1-90 of another
record. Using separate table format, 30 records would be required for each table, if
each record contained only one entry .
.f

(
8-36

..-

'....

~

.,. , '"

. . . . ':C''''

2.

Specifications to define and describe customer number table:
File Description Specification
File Type
File Designation
End 01 File

F

-

Record Address Type
Type 01 File

g Block

:l

5 '6 17 8

3

01 2
01 3
01 4

9

10

II Ii wl~li

12 13 14 115 '16 17118 119120 21

11

~I'

:>11 1'\

[,T
trp

t'(

1-11(

trs l4

M

~N II

IFlr
~

I

01 5, ,Fir NV I'Ilr rlf

o~

22

Length
23 24 25

26

I~5

~
27 28129

I~ 'g

~

34

44

45 46

r=1" F~ \12.
"'r 151-<

llol~

"'~Ir

Iqlb

If-,

41 42 43

1353637383!1

'"

,

Continuation Lines

I!

3

4

10 1
01 2
01 3
o
1

4

015
06

5 16 7 8
IE

Igth

'*

To Filename

~

IE
IE
IE

o 7

IE

lois

IE

*

01
Entries

Table or
Array Name

Per
Record

From Filename

ill 12 1~ 14 15 16 17 18
~IIJ SIN 1M

Number

Length
of
Entry
Per Table

211323

~

25 _26_ ~ 28 29 3031

13334 35
c:

irA ~r

Length
Array Name 01
(Alternating
Entry
Format)

of

Entries

or Array

~3()

7~

!i

V

~

12"'1

1

I~

~

VVU'

:'CCI'\;'

.,

u.

/

~""

Number

the Chaining Field

47 48 49 50 51 152 53

54

rl

Comments

lilill

155156 1~~~w~~~~~~~w~wnn73M
110<
I {;I\ T~ Y'I" II

,F

\

~
~

The devices used for these files
can vary, depending which
system and configuration you
use.

J

i

PR IrlN Ir~R

111~12

Number 01 Extents
Core Index

,

.

~~mber 01 Tracks

Name of
Label Exit

~

.:l

Starti~g
Location

131 32 133

30

Ib
IAF

Z

in

"'~-~1
Key Field

Record

length

Symbolic
Device

Device

,

File

torUAM

~

':il

,.. Additional Area

Line

!

Indicates this table file further
described on extension sheet.

~;"'::,~! ~~;~:I~ield

~--"""File Format

Filename

~

t,lode olProcessing

f"R
If- I,

ToO AI"

C;IN II ~

1',

II

2~

I

•

.....

~

"

'r-..

...............

~""'1

II II

MJ ,

"......

T

F('jT P1= R~

R~

J

----

Short table: 9 entries may be added
to the 15 entries present.

-- , - -

I

Specifications to define weight and postal rate tables:
Extension Specifications

E

-

Line

Number

of

Number of the Chaining Field

~
f-

~

To Filename

2

3

E*
E

1f"1IR

o
o

4

E~

~IR

E

o 7

E*
E

B

Number

Entries

Per

Length
of
Per Table Entry

of

Entries

Record

or Array

o

o 5
o 6

Table or
Array Name

From Filename

3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
o 1
E

o

~

/

Record Sequence of the Chaining File

E

22

23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
I", ,,.1-..
IT
lib
13~

ill

4041 42 43 44 45 46 47 48 49 50 51

I~

J

ITIJ.4 1M ~(,

1

13~

13 1

riA I"!II\ 'r,1T
w~ lRlR Air

1

,

~e

13 1

I~(J

13 .2.

hlR
IrlA181", hIT

E

ITA

I,..I~ Inl-t-

3~
.3~

13(l
l3~

Table or
Length
Array Name of
(Alternating
Entry
Format)

o 0

~~

13 1
B 12

IT
J

A

o.ln

I""

1\.,-

....

52 53

54

~

.g

e

"-

~

Comments

.~ ~

ill
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71

72

73 74

2- Mil It II" IPIA rrlR sil IR~ .... if'1 IRin,f

>

3 2. II

Ipl4IrlRIf'R Il='r irllRI'"'I

I)

Alternating
Format

II ~IN ITIR IT
___ I-'

1-

I 'l:N

M:U ,L IT
MIJ liT

/ 11':1 1= r.'" IRf"'I
It<
IKlI IK~

1-

1II-IN J IK 11-' ~II
If=. IN I ;W,

IE ..... 11

RE 1t'1....
R'E r'D

E
~

No entry indicates
compile time table

)

File Description sheet not required since they are compile time tables.

Answers To Review 8

8-37

3.

Calculation specifications for LOKUP operations: .
Line 01 - When a CSMSTR record is read (01 on), use CUSTNO field as search word
to deterrTJine if that customer requires parcel post service. Indicator 21 set on if
customer number in table.

./
\,

Line 03 - When an ORDER record is read (02 on) and that customer requires parcel
post (21 on from successful search), then search weight table using WE IGHT field as
search word. Indicator 23 set on when correct weight found (same number of pounds
or next higher entry if weight is in fractions of pounds). When 23 is set on, correct postal
charge is available from postal rate table.

RPG

IBM

Form OX21·9093

CALCULATION SPECIFICATIONS

Printed in U.S.A.

International Business Machine Corporation

1
Program

Prog~ammer

c

-

Page

Date

~.

Indicators

~

E~

4

5 6

(5

z

2

C

3

C

I I 1 I I I

Comments

~ 1>211<211-2
~

o

o

:I!

Z

Z

~~~;~f~ation 1

Compare

t;

Length

9 10 11 12 13 14 15 16 17 18 1920 21 22 232425 26 27 2829 3031 32 3334 35 36 37 3B 39 40 41 42 434445 4B 47 48 49 5051

7

Ole

o
o

Factor 2
Name

&8
3

Operation

Factor 1

~ ~

Line

76 76 77 78 79 80

of_

Resulting
Indicators
Arithmetic
~ Plu. IMinu •• Zero

Result Field

1:. ~

2

[0

Lookup(Factor 21i.
High Low Equal

53 54 55 56 57 58 59 50 61 62 53 64 55 66 67 68 69 70 71 72 73 74

*
wlt=IIIf-,H7

(

Output specifications to print postal charge on invoice:

4.

Line 01 - If customer required parcel post and correct postage charge has been determined
(23 on), print the postage chart from the postal rate table, TA.BRAT"

RPG

IBM

OX21 -9090 UiM 050"
Printed in U.S.A.

SPECIFICATIONS

OUTPUT

International Business Machine Corporation

1 2

Program

Date

Programmer

0

~

e~
e -

r----

-""~
;.
~ ~

Filename

Line

1:.

f-

~
E

o

~
3

4

5

6

ci5

Space

~~
CD

Jd

<{

A 100-

R

Output Indicators

Skip

~

~

~

0

1
z

z

"AUTO

7

8

...

It1

II

0

0

z

Field Name

'AND

~
~

End
Positon
in
Output
Record

[0

75 76 77 78 79 80

of_

Commas

Zero Balances
to Print

No Sign

CR

Ves
Ves
No
No

Ves
No
Ves
No

1

A

2
3
4·

B

K

C

L
M

~

0

~~~;~f~atiOn 1
X •

J

I. 1 1 I I I

Remove

Plus Sign
V - Date
Field Edit
Z - Zero
Suppress

Constant or Edit Word

a:

9 10 11 12 13 14 15 1617 18 19 20 21 22 23 24 25 26 27 2B 29 30 31 32 33 34 35 36 37 3839 40 41 42 43 44 45 4B 47 4B 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

0 1

Or INV 1'"\11

0 2

0

0 3

0

8-38

Page

~ ~

/'"'\

1~3

cl2
tr" Ir"Il... I" ....

41.5

' I~

I

"

Chapter 9. Arrays

CHAPT~R

9 DESCRIBES:

Use of arrays and RPG II coding to reference an entire array or individual elements
of the arrays.
XFOOT operation code.
LOKUP operation code.

BEFORE READING THIS CHAPTER YOU SHOULD BE ABLE TO DESCRIBE:
Use of and coding for tables.
Exception output.
RPG II object cycle.
OR relationship.

)

AFTER READING THIS CHAPTER YOU SHOULD BE ABLE TO:
Determine the use of arrays as opposed to the use of tables.
Define an array on the Extension sheet.
Code problems that reference all elements in an array.
Code problems referencing individual elements in an array.
Define and code the LOKUP operation code with arrays.
Describe data and store it in an array.

Note: You can use the review questions contained in Review 9 at the end of this
chapter to test your comprehension of the chapter. Answers follow the review
questions.

Arrays

9·1

Page of GC21-7567-2
Issued 24 May 1976
By TNL: GN21-5389

INTRODUCTION

DEFINING AN ARRAY

An array is a continuous series of data fields stored side by
side so they can be referenced as a group. In an array, each
individual data field is called an element. Figure 9-1 shows
an array of 12 elements containing the total sales for each
month of the year. Each element of the array has the same
characteristics; that is, each contains data in the same format (alphameric or numeric), of the same length, and with
the same number of decimal positions. An array element
may be positive, negative,· or unsigned; within a numeric
array, elements may be positive or negative.

You tell the RPG " program that you wish to set up an
array by coding extension specifications in much the same
way as you would code them for tables. As shown in Figure9-2, coding on the Extension she'et varies slightly, depending on when the array data is to be read into the array
that is set up by the RPG "compiler. Array data can be
stored in the array at three different times (see also Loading

An array is very similar in concept to a table. Both arrays
and tables are set up by coding extension specifications.
The type of data which you can put in an array is the same
as that which you can put in a table. The data can be
punched on cards, keyed in by the operator, or written on
disk or tape. The data can be loaded into an array at compilation time or just before execution time. An array can
also be built from data extracted from normal input files or
from data produced during the program as a result of calculations. The way data is arranged in storage is the same for
tables and arrays; one element of data immediately follows
another. The uses, however, of tables and arrays differ considerably.

Arrays):
1.

Compile time. The array records immediately follow,
and are compiled with, the source program. (If you
have a Card System, both array data and source program are loaded from the secondary hopper.)

2.

Pre-execution time. The array records are read like
any other data file, except that they are all read before any processing is done. (If you have a Card System, both array records and object program are loaded
from the secondary hopper.)

3.

Execution time. The array is loaded from information in input records or data generated by calculations.

The following Extension sheet entries are used to define and
describe arrays (see Figure 9-2):
/

WHEN TO USE AN ARRAY INSTEAD OF A TABLE

Columns 11-18 (From Filename): Pre-execution time arrays
In most cases, tables contain constant data such as tax rates,
shipping instructions, or discount rates. The constant data
is then used for calculations or printing with variable transaction data. Arrays are generally used for variable data and
totals which are used independently of the variable transaction data.
You should use arrays instead of tables when you want to
reference all elements at one time. Arrays can reduce the
number of RPG II specifications you must code for such a
program, as well as the time required to reference the
entries. Arrays should also be used when you are able to
directly reference a data item within a group of items and
do not need to do a look-up based on a search word.

Each element

are read from an input file similar to other data files. The
name of the file containing the array must be entered in columns 11-18 of the Extension sheet. This file mustbe designated as a table file in column 16 of the File Description
sheet. A table file is read completely and data is loaded into
the array before execution of the program begins.· The same
MFCU file can be named in these columns for more than
one array. Input files on other devices can contain only one
array. On the Card System, pre-execution time arrays must
be loaded from the secondary MFCU hopper.

Two decimal positions
in each element

1258.72
JAN

FEB

MAR

APRIL

Figure 9-1. 12-Element Numeric Array
9-2

MAY

JUNE

JULY

AUG

SEPT

OCT

NOV

DEC

RPG

IBM

)

EXTENSION AND LINE COUNTER SPECIFICATIONS

Form X21-9091
Printed in U.s.A.

Intern.tional Business Machine Corporation

1
Program

Date

Programmer

Page

2

m

75 76 77 78 79 80

[00'_ ::~a':tion I I I I

Extension Specifications

E

Record Sequence of the Chaining File

I--Line

Number

4

~
I-

5

6

0 1

E

o
o

2

E

3

E

o
o

4

E

5

E

the Chaining Field

To Filename

Table or
Array Name

From Filename

~
3

0'

7

8

Number
of
Entries
Per
Record

Number
of
Entries
Per Table
or Arrav

c _

length

0'

°

c

:~ ~

0-

Entry

11.

..

:)~~

~~l

Table or
Array Name
(Alternating
Format)

Length
of
Entry

o·
~

i

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 4344 45 46 47 48 49 50 51 52 53 54 5556

II\I~I ....

III'" FT III~

1A 1...

~
11

IA In lolAlv

P- !.12

112 171c; (J
1l(J

~

l~

~

D~~OO~~~54~mDm~ronnDM

1,.1 ""

lQ

11:\

Comments

i
!
I~

IPIR 11= - I='ly 11= ,. II
~I)( lJ:r

T I~IN

rrlT rlN

,

Figure 9-2. Defining Arrays

Columns 19-26 (To Filename): If you want your entire
array to be written to an output file at end of job, enter
the name of the output file in columns 19-26. You
cannot use the To Filename entry to write execution
time arrays to an output file; instead you must use
output specifications (see Output of an Entire Array,
later in this chapter).

)

Columns 27-32 (Table or Array Name): All arrays used in
your program must be assigned a name of six characters
or less which is entered in columns 27-32. The rules for
naming arrays are similar to those for naming tables; an
array name can consist of any combination of alphabetic
characters and numbers. However, while the first character must be an alphabetic character, an array name cannot
begin with the letters TAB. This is the way the compiler
distinguishes between an array and a table.

Column 43 (Packed/Binary): Disk or tape users may specify in column 43 that pre~executiontime array data is in
packed decimal or binary format. On a disk system, 80column card users can specify packed pre-execution time
data.

Column 44 (Decimal Positions): If the elements in an array
are numeric, the number (0-9) of digits to the right of the
decimal point should be entered in column 44. Even if no
decimal positions arepresent, a zero must be specified if the
elements are to be considered numeric. A blank in column
44 indicates that the elements are to contain alphameric
data. Remember, however, that if arithmetic operations are
to be performed on the elements, the array must be defined
as numeric.

Columns 33-35 (Number of Entries Per Record): For compile time and pre-execution time arrays, enter the number
of array elements in each input record. These columns must
be blank for execution time arrays.

Column 45 (Sequence): If your ·array data is in sequence,
enter A (ascending) or D (descending) in ·column 45. Sequence is not checked for execution time arrays, but this
column must contain an entry if high or-low look-up is used
(see LOKUP of an Array).

Columns 36-39 (Number of Entries Per Table or Array):
These columns are used to enter the number of elements in
the array (from 1 to 9999). This number should be entered
so that the last digit is in column 39.

Columns 46-57 (Alternating Arrays): Columns 46 through
57 are used if two related arrays are set up in an alternating
format on input records. Alternating arrays cannot be described with execution time arrays.

Columns 40-42 (Length of Entry): The length of each
element (number of characters, including blanks) should be
specified in columns 40-42, with the number ending in column 42. The length, which must be the same for every
element in the array, cannot be greater than 255.

The extension specifications.only res~rve. the appropriate
space in storage for the array. In a following' section, you
will learn how data is stored i~~he array.

Arrays

9-3

REFERENCING ALL ELEMENTS IN AN ARRAY

Array to Array Calculations

Suppose a company employs 15 sales clerks whose daily
sales are recorded on a punched card (SALES). As Figure
9-3 shows, field 1 ,contains sales for clerk #1, field 2 for
,clerk #2, and so on. There is one SALES. record for each
day. In addition to a daily amount, the company wishes to
have a monthly sales total for each clerk. Therefore, at the
end of the month, the daily sales amounts for a clerk must
be accumulated.

Once the first SALES record is read and the data stored in
the DAY array, the 15 elements of DAY are added to the
15 elements of MONTH. In other words, element 1 of
DA Y is added to element 1 of MONTH, element 2 to element 2, and so on (Figure 9-5).

As shown in Figure 9-4, an array (MONTH) of 15 elements
is set up to contain 'the ,monthly totals. Another array,
called DAY, could be set up to contain the 15 sales amounts
for one particular day. The daily sales record is read and
each clerk's sales amount is placed in the appropriate
element of array DAY.

I~I

,Daily record
for January 1

I~I

Icle7k1"21

1cle;k21

-----

I~I
1~31

SALES

9-4

I~I

1~41

I~I

Ic~1
I~I
Ic~1

I,~I

1cl;;k71 1de;k81 1de;k91 I~I

Iclerk 11 I 1de;k121

Figure 9-3. SALES Records

Iclerk 3 I I~I
Iclerk 8 I I~I

1cle;k"i41 1cle;k151

Records

---- """""""---- -----,...,...,.. --

--..-~

~

-",

~

I

~

~

~

.......-

~

/

clerk 1
sales

clerk 2
sales

clerk 3
sales

clerk 4
sales

clerk 5
sales
SALES record

clerk 11
sales

3

2

4

5

6

sales

sales

sales

clerk 10
sales

clerk 12
sales

clerk 13
sales

clerk 14
sales

clerk 15
sales

8

7

clerk

10

9

12

11

13

14

15

000000

000000

14

15

DAY array

000000

000000
2

000000

000000
4

3

00000o

000000

5

6

00000o

000000

000000

000000

000000

9

10

11

8

7

000000

000000

12

13

MONTH array

'\

)

Figure 9-4. Using Arrays to Contain Sales Data

DA Y array (totals for day 4)

,
0015.21 0012.86 0025.31 0008.93 0017.83 0019.24 0015.67 0032.81 0042.21 0021.87 0019.67 0018.46 0013.45 0028.37 0023.95

t

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

+

+

+

(

)

I

+

+

+

+

+

+

+

+

+

+

+

+

0072.18 0142.96 0063.90 0089.61 0076.95 0128.76 0134.21 0062.34 0079.83 0052.24 0148.75 0063.69 0057.24 0138.78 0053.96

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

MONTH array (accumulated totals for days 1,2 and 3)

\

j j j j

j j j j j

j j

j j j j

0087.39 0155.82 0089.21 0098.54 0094.78 0148.00 0149.88 0095.15 0122.04 0074.11 0168.42 0082.15 0070.69 0167.15 0077.91

2

3

4

5

6

7

8

9

10

11

12

13

14

15

MONTH array (accumulated totals for days 1,2,3 and 4)

Figure 9-5. Adding One Array to Another Array
Arrays

9-5

The 15 accumulated sale amounts (results of the add'itions)
are stored in MONTH. Then, another SALES card is read
into the DAY array. The new DAY fields are then added
again to the accumulated totals in MONTH.

of the entries looked up. An addition operation would then
be required to add the two entries and place the result in the
month table. After all this, you have accumulated a total
for only one of the sales 'clerks.

This method is similar to using two tables and adding ~m
entry from one'table to an entry in the other table. However, performing the operations using tables requires more
specifications than to doing the job using arrays.

To repeat the same procedure 14 more times for the other
sales clerks' entries, the program must read 14 records and
go through 14 program cycles. This occurs when you use a
table name in specifications. The name refers to only one
element, the entry just looked up.

With tables, you must reference each element (sales amount
for a clerk) separately. First, you must perform a table
lookup to find the appropriate sale amount from the day
table. Of course, since you do not know the amount of
each sale, you cannot search the day table directly. A related table of sales clerk numbers must be set up and
searched. Only after you find the appropriate sales clerk
entry is the corresponding sale amount in the day table
made available. Then you must lookup the corresponding
element of the month table. At this point, use of the table
names in calculations or output would finally refer to each

RP~

IBM

On the other hand, if you have defined your groups of data
as arrays rather than tables, only one calculation specification is necessary. The' name of an array actually refers to
all of the elements in that array. Adding the array DAY to
the array MONTH causes every element of one array to be
added to corresponding elements of the other array (1 to 1,
2 to 2, 3 to 3, etc.). Since the MONTH array is specified
under Result Field, the result of each addition is placed back
into the appropriate element of MONTH (Figure 9-6).

EXTENSION AND LINE COUNTER SPECIFICATIONS

FOl"mX21-9091
Printed in U.S.A.

International Business Machine Corporation

1

Program
Programmer

2

75 76 77 '78 79 80

I I I' m

~~~f~cation I

pageDJof_

Date

Extension Specifications

E
r--line

\.

Record Sequence of the Chaining File

Number of the Chaining Field

Table or
Array Name

To Filename

!

From Filename

~
7

Number
of
Entries
Per Table

length
of
Entry

or Array

Table or
length
Array Name of

00

~~

(Alternating
Format)

:i ~ ~
~~:

0
~

Entry

Comments

II:

B

~

N

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 333435 36 37 38 39 40 41 42 4344 45 46 47 48 49 50 51 52 53 54 5556

~

3

4

0

1

E

1r-11n 'Mlrlu

1'-,\

IA 12

T~

~'r~

o
o

2

E

I"'~IV

115

~

Ir~

IHie l'"

3

E

6

5

8

Number
of
Entries
Per
Record

RPG

IBM

~~~50~~~M~OO~mmWnnnM

I~

Form GX21·9Q93

Page

l-

85

6

7

011 I

C

01 2 1

c

I

At

8

I

Operation

Factor 1

At

0

z

Length

0

z

IrluNll'll-Illll1
1I

~Inld

I

IDlAlvl I I I

,..I.J.• L.I..1
I

I

I

·'IUI'''"IHI

I " I " I I I II J 111111111 I
I

I

I

I

I

I

I

Figure 9-6. Referencing All Elements of an Array

9-6

~~~;~f:atlon I

Plus IMinusl Zero

Factor 2

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 48 47 48 49 50 51

I
I

of _

IIIIII

Resulting
Indicators

Result Field

Name

~ ~ ~
~

~

OJ

Arithmetic

9~
::-0

E

I

Indicators

~

~~~
'0 a:

I;

757677787980

12

C

4

lSlL Is

c:,lA It 1~1c;

Printed in U.S.A.

Programmer .

3

MN IrH
C~V

CALCULATION SPECIFICATIONS

Program

Line

~

International Business Machine Corporation

'--

I

(r'

II

"

r1 II

Comments

Compare

1>211<211-2
lookup(Factor 2lis
High low Equal
54 55 5657 58 59 60 61 62 63 M 65 66 67 68 69 70 71 72 73 74

I

I

I I AttlLlIM 1c;lt\III,:151 I
I" I III" IIII
1 1

1

I

I

Notice on the Calculation sheet in Figure 9-6 that no resulting indicators have been specified for this arithmetic operation. When an array name is specified in a calculation, the
operation is performed on every element of the array. Therefore, there are a multiple number of results; in this case, 15
sales totals. A resulting indicator can indicate the condition
of only a single result. Thus, resulting indicators cannot be
used when referencing an entire array as a Result Field.
There are two exceptions when resulting indicators can .be
used, as explained under Adding All Elements Within An
Array and Searching An Array For A Particular Element.

Suppose, as shown in Figure 9-7, that DAY only contains
12 elements while the MONTH array contains 15 elements.
In such a case, the operations are performed only until the
last element in the shortest array has been processed. Thus,
the 12 elements of DAY are added to the first 12 elements
of MONTH, and the 12 results are placed in the first 12
elements of MONTH. The remaining three elements of the
result field (MONTH) remain unchanged. Likewise, if the
result array is shorter than any of the factors (arrays), the
operation is repeated only for the number of elements in
the shortest (result) array.

Operations Which Can be Performed on Arrays

Calculations Using Arrays and Single Fields (or Constants)

As mentioned, an operation to be performed on an array is
performed for every element in the array. A result is then
produced for each element operated on. For this reason,
certain operations cannot be performed on arrays, because
the results have no meaning. The operation codes COMP
(compare), TESTZ (test zone), MVR (move remainder),
TESTB (test bit), BITON (set bits on), BITOF (set bits off),
and DSPL Y (display) cannot be used with an array.

Another way in which you can perform calculations onan
entire array is by adding (or multiplying, etc.) the same
value to every element in the array. For example, suppose
the sales clerks are to receive a commission of 10 percent of
thei,r sales, to be paid !3t the end of the month. After all
dailysales have been accumulated into the MONTH array,
you want to multiply each of the 15 elements in MONTH
by the value .10 and to place the commission amounts in
another 15-element array called COMMIS.

Performing Operations on Arrays of Different Lengths

To do this, it is not necessary to set up a 15-element array
for the commission rates, with each element containing
the value .10. In an array operation, when one of the
factors is a field (containing a value) or a constant, the
operation is performed using the same field or constant on
every element in the array.

In the last example, all arrays used in an operation were of
the same length; Factor 1, Factor 2, and the result array
each contained 15 elements. Thus the operations were
carried out until all elements were processed.

2

3

4

5

6

7

+

+

+

8

9

10

11

12

+

+

+

+

9

10

11

DAY array

+

+

2

+

+

3

4

5

6

MONTH array

7

+

8

12

13

14

15

Unchanged

Figure 9-7. Operations on Arrays of Different Lengths

)
Arrays

9-7

You can also use a field or constant as both factors to place
the same result in every element of an array. The calculation
specifications in Figure 9-8 show the single field named
DISCNT being subtracted from the single field AMOUNT,
with the result placed in a 5-element array named DUE. The
value (017) in DISCNT is subtracted from the value (243)
in AMOUNT, and the result (226) is placed in each of the
five elements of the DUE array.

The XFOOT operation code (Figure 9-9, columns 28-32)
tells the computer to sum the contents of every element in
the array named in Factor 2. Columns 18 through 27 . (Factor 1) of the Calculation sheet are left blank since the
XFOOT operation involves only the values in one array.
The sum of the DAY array elements is then placed in the
single field named in columns 43 through 48 (Result Field).
In most types of array calculations, multiple results are
produced in accordance with the number of elements in an
array. However, performing an XFOOT operation provides
only one result, the total of all elements. For this reason,
you specify a single field name rather than an array name,
under Result Field. Furthermore, since there is only one
result, a resulting indicator may be assigned in columns
54-59 to determine if the sum is plus, minus, or zero. In
this case, a resulting indicator was not specified (Figure 9-9)
because the sales amounts will always be positive.

Adding All Elements Within An Array
In accumulating a monthly sales total for each clerk, the
amount each clerk sold was determined. Suppose, in
addition, the company also wants to know the total of all
sales each day.
As mentioned before, each clerk's daily sales are stored in a
separate element of a 15-element array named DAY. To
obtain a total of all sales for the day, you must add together
the contents of all elements in the array. The sum can then
be placed in a single field.

RPG

IBM

Form GX21·9093
Printed in U.S.A.

CALCULATION SPECIFICATIONS

International BusinlSl Meehine Corpor.tion

12

Programmer

-

C

Date

Indicators

~

0_

..Ja:
=0

line

I-

5 6

011 I
0'2'
1.1

C
C

Operation

Factor 1

Factor 2

0 a:,"

E E~

•

7

8

~

Indicators

Arithmetic

Name

02 85 :'i
3

Length

0
z

0
z

.a

IAIMruNrr-1 , , , ~'u'BI , 100 1sC.~'T' I , I lolulEl , , , ,
II I II I I I I I , , , II II· II I II II II ,

9 10 1112 13 1. 15 16 17 18 19 20 21 22 23 2. 25 26 27 28 29 30 31 32 33

,I
I

I

I

I

~

35 38 37 38 39

41 .2 0

• • •548.748 .9 50 51

I

"

G
B

AMOUNT field

DISCNT field

r~z::::;=~"""""\---"
226

I

226

element 1 element 2

I 226
element 3

226
element 4

226
element 5

Figure 9-8. Storing the Same Data in All Array Elements

9-8

1 1 1 I· 'I 1

Resulting

Result Field

AL At

!.
~Z
,...J«

757677787980

P~ge OJ of _ ~~~;~f:.tion 1

Program

DUE array

Plus IMinusl Zero
1>211<211-2
Lookup(Factor 2lis
High Low Equal
Compare

Comments

, , ,
, , 11111'"11111'

54 55 5657 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

T

11111'""""

/

RPG

IBM
/

Form GX21-9093

CALCULATION SPECIFICATIONS

PrinttdinU.S,A.

International Business M,etune Corporation

1 2

Program
Programmer

C

Indicators

~

0_

~

Line

I-

E l:l '"

3

4

5

01 '1
01
21

Operation

Factor 1

8 5"

6

7

8

C

1

c

I

Length

Name

~

'0

z

Indicators

.g

Factor 2

'0 c£

.f

Resulting

Result Field

Jd At

-Ja:

::0

~~~

'0
z

7576 77 78 79 80

[00'_ ~~~:~':ation I I I I I I I

Page

Oate

Arithmetic

X PlusTMinu,r Zero

~I
2 ':;

Comments

Compare

1 >211 <211-2
LookuplFactor 2)"

C :I: High Low Equal
9 10 1112 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 5051 5253 54 55 56 57 5859 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

J 1 1 1 I I I 1){IFi(.1 ~ij 11AI'r'1 I I I I I I II 011 IIJIAI", 1171, 1 1 1 1Til I I rTl I I T1T
I'T I I I I I I I I I I I I I I I I I I II I I I I I I I -.I
.,I I .,I II I I I I I I I I I I i I
1 .1

1.1

I

I

I

II

I

I

I

1

I

1

I

I

I

I

I

I

I

9
DAY array

I

I

I

I

I

-'·1

T

I

11

12

13

I

I

14

I

I

I

I

I

I

15
TOTDA Y field

Figure 9-9_ Adding All Elements of an Array

"',
)

Output of an Entire Array
You may want to have an entire array writte:1 or punched
out. Perhaps you want to look at the contents of the array
at some point during the program run or at the end of the
run. Or, you may want to have array elements put out to
be used as input the next time the program is run_ Output
of an entire array can be specified in two ways, with extension specifications or with output specifications.

Arrays

9-9

By Extension Specifications

By Output Specifications

Like tables, compile time arrays and pre-execution time
arrays can be written out at end of job by simply entering
the name of the output file under To Filename (columns
19-26) on the Extension sheet (see Figure 9-10). The output file must be named on the File Description sheet, but
no output specifications are necessary. The entire array, :
including unused elements (blanks or zeros), is put out.

The second method of specifying output of an entire array
is with output specifications. By specifying the array name
under Field Name (columns 32-37) on the Output sheet, all
elements within the named array are punched, printed, or
written on the indicated output file (Figure 9-11). All types
of arrays, compile, pre-execution, and execution, can be put
out using output specifications.

With the Extension specifications shown in Figure 9-10,
the array, AR RAY1, is put out automatically at end of job.

Any output conditioning indicators specified in columns 23
through 31 of the Output sheet determine when during the
program the array elements will be printed or punched. If
no indicators are specified, the entire array is printed or
punched every time a record is processed. Indicators can be
specified to put out array data during detail cycles or at
total time. You may want to put out array data at total
time by customer or inventory item, for example, to be
used as input to subsequent update runs.

The data output may not be exactly the same as the data
input. Your program can change or update array entries,
causing modified data to be put out, not the original data.
Except for printer output, however, the format of the
array output records will be the same as the input records.

RPG

IBM

/'

EXTENSION AND LINE COUNTER SPECIFICATIONS

FormX21-9091
Printed in U.S.A.

Intern.tionel Business Machine Corporation

1

2

Pr~ram

pase[]]of_

Date

Programmer

rllTrn
75 76 77 78 79 80

Program

Identification

Extension Specifications

E

r---

Number of the Chaining Field

~

From Filename

~
4

6

5

0

1

E

o

2

E

o
o

3

E

4

E

Table or
Array Name

To Filename

8.

Line

3

/'

Record Sequence of the Chaining File

7

8

Number
of
Entries
Per
Record

Number
of
Entries
Per Table
or Array

length
of
Entry

Table or
length
Array Name of

j~

(Alternating
Format)

~ ~ ~

~~j

Entry

.g

e

Comments

~~
f!
~~ Ii

~~!

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3738 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 7172 73 74

'"" IITIFlrlL E

1\ -

....

~~r~~

lL l~ ltla'l1 I '" 12

I

I III II

If

~~~~+-~~+4~+-~~~I~~~1-~~+4~+-~

I

o 5 E
~~++++++~~~!-~~~rrrr~++++~;-ri
o 6 E

Causes entire array to be
.put out at end of job.

I

-r+-r+~~-r~r+1-~~~r+1-~~~-1

I I I I I I I I I I I I I I I~HrHr~++++++~~~Hr~HH

File Description Specification
r, I. Type

F

V
Filen1me

I

c

File Designation

length of Key Field or
of Record Address Field

~:~ormat

~;~:::

End

!

.

4

2

5 6

7

Fit-

o3

F

o
o
o

4

F

5

F

6

F

g~
~ ~

i
a

~

g~w<~

j
3

Type

or Additional Area

Una

o

File AdditionlUnordered

Mode of Processing

8

9

Block
Length

~
~g

Record

l<:

Length

::: I-

:l

Extent Exit

~

~:~I~

Device

~::~ ~~it

-g

Number of Trocks
for Cylinder Overflow

for DAM

NUmbe~;:~nts
~

Core Index

Overflow Indicator 0

Condition

~ .~
Starting

~

location

W

Continuation lines
K

Option

Entry

z

~

U1-\!!!-

~

lJ 11 12 13 14 15 16 17 18 19 20 21 22 Z! 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 4041 42 43 44 45 46 47 48 49 50 51 52 53 64 55 58 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

IT F I

If:

.......

n

I...

,t-',K1NIt-IK

(
Figure 9-10. Specifications for Output of an Entire Array at End of Job

9-10

)

RPG

IBM

International

OUTPUT

,

SPECIFICATIONS

Busine~s Machine Corporation
1

Program
Programmer

0

~ Space

-.. ~ ~
t::0 tf
~ iii

Filename

Line

~

~

AreD

E

o

&
6

e

t

~~

~

I-

5

Output Indicators

Skip

@"§

~

3 4

Page

Date

R

"A"N'o
7

Jd

e

~

~

0

0

z

z

L

Field Name

I

a:

IC (;;

;3

0

z

'AUTO

5

~~

'3>
End
Positon
in
Output
Record

II

Commas

Zero Balances
to Print

Ves
Ves
No
No

Ves
No
Ves
No

2

OJ

No Sign

CR

1

2.
3

A
B
C

4

0

GX21 ·9090 u/M 050'
Pnnted in U.S.A.

75 76 77 78 79 80

~~~;~i:ation 1 "I.

of _

J
K
L
M

1 1 1 I I

X = Remove
Plus Sign
V = Date
Field Edit
Z = Zero
Suppress

a:

~0::

Constant or Edit Word

9 10 II 12 13 1415 1617 16 19 20 21 22 2324 2526 27 28 29 30 31 32 33 34 35 36 37 36 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

8

01 1 1 o IRI~lpld~TI
0/2/ ') / /"/
/

/

/

T

I' I
/

/

I

!R

I I II I
MONrr/H/

I II
IIRI_'i"

I I 1111111 111 I I I 1111 1'1 I 1 11
I I 111111/ / / I-I / / III / / / /
I

I

I

I

"'

Figure 9-11. Output of an Entire Array

",

)

RPG II determines where the array data is to be put out on
a card, printer file, disk or tape by the end position column
you specify in columns 40 through 43 of the Output sheet.
The array elements are put out such that the last element of
the named array ends in the column indicated. Note, however, that if all elements in the array cannot be put out on
one output record, the array elements must be referenced
separately on the Outp'ut sheet. Output of individual elements will be discussed 'later.
The output of an entire array by means of output specifications. requires only one specification. An entire array can
be written, printed or punched at any time during th,e run
or at end of job, depending on how the output specification
is conditioned. Again, during the run, this is possible only'
if a single output record can contain this entire array.
You must specify how you want the data elements to appear
on the output record. Alphameric elements appear on an
output record just as they appear in storage; however,
numeric array elements may be edited or unedited. If no
editing is specified, the elements are printed or punched just
as they appear in storage, with the last element ending in the
end position column of the output file. In other words, one
element will immediately follow another with no punctuation and no blanks between elements.

)

Usually, printed array output is easier to read and has a
better appearance if edit codes or edit words are used to
punctuate the data and insert spaces between elements. If
punched output, disk output, or tape output is desired,
generally the array output records are used as input the
next time the program is run. Therefore, editing is usually
not specified, so the elements will be in the appropriate
format to be used as input.

Editing affects the position which is specified as the end
position of the output record. If each element in a 5element array contains seven characters, 35 positions would
be necessary to output the entire array in unedited form.
On the other hand, if punctuation and blanks are inserted
for each element, the number of positions required increases.
When specifying an end position, you must allow enough
positions to output all edited elements.
Regardless of whether editing is specified or not, when output of an entire array is performed, every element of that
array is put out in the same format. ,If an edit code or edit
word is specified, every elementis edited in the same way.
Since all elements of an array contain the same type of information, ordinarily you want the elements punctuated in
the same way. If, however, one element must be edited differently from another element in the same array, you must
put out the elements separately. The means of referencing
individual elements of an array is discussed later in this section.
When an edit code is specified in column 38 of the Output
sheet, every element of the named array will be punctuated
accordingly. Furthermore, any edit code specified for an
entire array also causes two blank spac~s to be inserted between each element. The insertion of blanks is taken into
consideration by the program so that the last element ends
in the position specified.

Arrays

9-11·

blanks to be automatically inserted in the output record before each array element. Figure 9-13 shows an edit word
specified without blanks; one element of SALES immediately follows the next on the output record. Any extra
blanks which are to appear must be indicated in the edit
word by an &. Notice, in Figure 9-14 that the two blanks
specified are to be printed as part of every element. Thus,
the second blank following the last element will be the
character which ends in the end position column. Notice
that an additional two columns have been allowed for each
element (five elements). The end position column has thus
been increased by ten over that in Figure 9-13.

As shown in Figure 9-12, the edit code 3 causes all five
elements of the SALES array to be printed with decimal
points inserted, leading zeros suppressed, and zero balances
present. In addition, two blanks are automatically printed
before each element since an edit code was specified.
If no edit code specifies exactly how you want the array
fields to be edited, you can specify the punctuation by
using an edit word (columns 45-70). In this way, you can
edit array elements with dollar signs, zero suppression,
blanks, constant words, or any combination of punctuation
desired. When edit words are used, all punctuation must be
specified. Unlike edit codes, edit words do not cause two

RPG

IBM

OUTPUT

Page

Date

0

u: Space

~J
c -

r--Filename

Line

~

E

~
5

6

E~

8. -lI
~~

Output Indicators

Skip

11

~~«
OJ

"Aro:o ~l!! ~
~~'D

I-

7

8

0

0

z

z

~

~

Field Name

v

(ii

m
·AUTO

~

-'"0=
w

Positon
in
Output
Record

Commas

Zero 8a lances
to Print

Ves
Ves
No
No

Ves
No
Ves
No

:liii

No Sign
1

2
3
4

2

[0

75 76 77 78 79 80
of_

CR

-

A

J

B

C
0

K
L

M

~~~;:f:.tion I
X •

IIIIII

Remove

Plus Sign
V· Oat.
Field Edit
Z • Zero
Suppress

Constant or Edit Word

/'

0:

(

9 10 II 12 13 14 15 1617 18 19 20 2122 23 24 25 26 27 2:1 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

01 1 1 OIRIElp()Rh-1
01 2 1
111111

004561 01783

1 1

29684

~~ero suppressed

3 blanks

I

00000

Two blanks inserted before element

4.56- I 17.83

I II
" III
F;IAI\ .1~lsl I~IR 1IIIb

I I

~

°

08063

II
I1

""111111""
IIIIIIIIIIIII
1

11.
II " I II IIII
II " I

'"

Array

Two blanks inserted before element

U

Three zeros suppressed

296.84-----.00

-...--

80.63

, 5 blanks

Output of
array
position 112

Figure 9-12. Output of an Entire Array With Edit Codes

(
9-12

,

GX21-9090 U/M 050·
Printed in U.S.A.

SPECIFICATIONS
1

Programmer

4

\'........

International Business Machine CorpOration

Program

3

/'
.

GX21 9090

SPECIFICATIONS

OUTPUT

RPG

IBM

I

Program

Programmer

0

LL

Output Indicators

Skip

-~ ~ ~ ~

~

Field Name

".
0-

!

t-

E

~

And

And

0:

in en

~DO ~
~

o

;3

.. !2~

0

z

z

"AUTO

,

"0

:>
End

8

7

Commas

Ves
Ves
No
No

II

Positon
in
Output
Record

Zero Balances
to Print

2

OJ

NoSign

75 76 77 78 79 80

~~~~;~f:ation I

of _

CR

X

Remove

V "

Date
FIeld Edit
Zero

Plus Sign

Ves
No
Ves
No

K

L
M

Z

Suppress

Constant or Edit Word

-'
<

>-

~
f-

f-

~
6

l.:
cl5

~

Output Indicators

Skip

-

~~

r:o:roro

R

Jd
~

~

~ z0
211<211-2
Lookup(Factor 2)is
:I: High Low Equal

~~
'(3

II

BR Nrl-l

AD I::

R:(;.

Ar"'C

ISTIR
IRR INr--H

AnD

~FIG

r;

Irl- MP

~

:A" ,.. JIM

IBR Nrl~ :1""1r
JIM iR E: (; tJ"n :fAIL
'A'r r 11M .... ,..., f".P Tn iTll

H

I~KIN

RE(:.

'A, " r

ron IMP

GX2I,9090

SPECIFICATIONS

OUTPUT

U/M 050"

International Business Machine CorpOration

1 2

Page

Date

Programmer

0

~ Space

Filename

Line

&

~

3

4

0

1

0

o
o
o

2

0

3

0

5

6

4

0

0 5

0

0 6

0

0 7

0

o

0

~~
o !!:
-""
:;. Ai
& 1l
~J3

o R
~'Nro
7

8

I

And

~
f

~

-'"

Output Indicators

Skip

~~

'"

fp;fo"o

E

~

8

1 1 1 1 -I 1

Indicators

Arithmetic
Plus IMinusl Zero

Program

-

~~~~;~f:ation 1

Z
o
9 10 II 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 46 49 50 51 5253 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

RPG

IBM

Factor 2

Operation

75 76 77 78 79 80
of_

Resulting

Result Field

At

[I]

1

Field Name

I

°

Z

0

,2

;3

0

Z

End
Positon

~

i;;

~

fEi

"AUTO

~

in
Output
Record

[I]

75 76 77 78 79 80
of_

~~~;:f:.tion 1

Commas

Zero Balances
to Print

No Sign

CR

-

X

Ves
Ves
No
No

Ves
No
Ves
No

1

A
B
C
0

J
K

V = Date
Field Edit

2

3
4

L
M

Z

==

:a

I, 1 1 1 1 1

Remove
Plus Sign

,

Zero

Suppress

a:
..J

Constant or Edit Word

'"

~

9 10 II 12 13 14 15 1617 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 46 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

It:.r

:I'\L1

'n
~

5iTiR

J 1213

ILl
I..
"·... ,KIN

r
r

1~13

.....

1M

1122.

31R 1122

112
1R.lfle;

3lB

J22

11"''''' IM[p

3

l22

IL R

Figure 9-20. Accumulation and Output of Group Totals Using Arrays
Arrays

9-19

I

Indexing an Array
As you learned, if a calculation or output specification contains an array name alone, that specification is automatically
performed for every element of the array. To reference only
a single element of an array, you must identify that element
for the RPG II program. This is done by placing a comma
after the array name, followed by an index which points to
the particular element (Figure 9-21). This index can be
either the actual number of the element to be referenced or
the name of a field containing the number of the element to
be used.
Recall Defining an Array. The name used to refer to an array cannot exceed six characters in length. When referencing
individual fields, both the array name and an index are necessary to refer to the data. Therefore, usually the array name,
plus the comma, plus the index cannot exceed six characters.
The name used to refer to an individual array element must
be one to six characters long unless the name (with index)
used to refer to an individual array element is specified only
as Factor 1 or Factor 2 on the Calculation sheet. In this
case, the array name plu5comma plus index may be as 10hg
as ten characters. However, the array name portion of the
reference still cannot exceed six characters.
Figure 9-21, line 01 ,shows a valid reference to the ninth
element of an array named ARY1. However, if the array
contains ten or more elements, some of which may have to
be referenced, the name of this array would have to be
shortened to provide enough positions for the index (Figure 9-21, line 04). The limit of six characters applies even
if the name of a field is used as an index. As line 07 shows,

RPG

IBM

if an index field IF LD is specified, only one character (B)
can be used as the name of the array because the indexed
name is specified under Result Field. However, COM,
INDEX on line 07 is valid, even though longer than six
characters, because it is specified only under factor columns.

''-...

Specifying an Index Which Does Not Change

If you know exactly which element is to be used in a calculation or output operation and the specification is to reference the same element in every program cycle, you may
use a'constant as the index., Assume a 7-element array
(SLS) is defined to contain a salesman's six daily commission amounts and his total commission for the week. The
six daily amounts from one of the salesmen's input records
are read into elements 1-6 of the array. The seventh
field on the input record contains zeros and is read into
element 7 of the array (Figure 9-22, insert A).
The array elements are defined as 5-digit numbers with two
decimal positions. Once the data is in the array, the XFOOT
calculation operation is performed to add all elements ~f the
array and place the total in the seventh element (Fi~ure
9-22, insert B). The weekly total for every salesman is always stored in the seventh element. Therefore, the actual
number 7 can be specified as the index. In addition, a $25 //
bonus is to be added to a salesman's total if his weekly com- "
mission exceeds $175 (Figure 9-22, insert C).' Thus, in every
program cycle, element 7 must first be compared to $175 to
determine if the bonus is to be added to the contents of
element 7.

CALCULATION SPECIFICATIONS

Form GX21·9093
Print_din U.S.A.

Internationa' Business Machine Corporation

1

Program

Programmer

Page

O.t.

2

[0

75 76 77 78 79 80

of_

~;::~f:ation I

IIIIII

_~~;:;s
Factor 1

OperatIon

Factor 2

110
I,g I~

1.' .
Ii I

I 'iii 1;:

Name

Length

ADin

1(lj

~IRIY .1

_ Cornpa-,e

Comments

I~ 1 >211 <211-2

1~li

t9 20 21 22 23 24 25 26 27 '28 29 30 31 32 '33 34 35 36 37 J8 J9 40 41 42 143 44 45 46

AIRYLl,. A

Arithmetic
Plus IMinu,l~ro_

Hi9hJ.~O::"J~~U.1

'2);,

f=f=~ Actual number used as index.

11 72 73,74

-1-1--

II I I I \I

(
\~

Figure 9-21. Referencing a Particular Element of an Array

9-20

I

I

027.80

042.37

031.87

025.93

000.00
DOE, JOHN

SLS array
Element

2

3

RPG

4

5

6

®

7

CALCULATION SPECIFICATIONS

Reference every Reference only
element of array 7th element of array

SLS array
Element 7

RPG

CALCULATION SPECIFICATIONS

©

Element 7

Figure 9-22. Specifying a Number as an Index

Arrays

9-21

Specifying an Index Which Can Be Changed

Output of Individual Elements of an Array

On the other hand, if the array element will vary when a
particular specification is performed, the index should be a
field name rather than an actual number. In this way, the
number stored in the index field can be changed during the
program to indicate which array element is to be referenced.

To put out individual elements of an array, you code the
same output specifications you would for normal fields.
The only difference is that under Field Name on the Output
sheet you must specify the array name followed by a comma
and an index. The index then points to the particular
element to be put out (Figure 9-24).

An array (STK) is used to contain the quantities in stock of
all parts manufactured by a company. Element 1 of the array contains the quantity for part #1, element 2 for part
#2, and so on. When additional parts are manufactured, the
values in the appropriate elements must be updated. Therefore, records are punched daily for each type of part produced. Each record contains the part number (NM) and the
quantity of that part produced (OTY).
To perform the updating, the contents of the OTY field
must be added to one of the array elements for every record processed. Thus, an index must be used in order to
reference only the individual element to be updated. Since
each daily record is for a different part number, the array
element to be increased will vary each time the specification
is performed. For this reason, an actual number cannot be
specified as the index, because OTY would be added to the
same element for every part number. Instead, the NM field,
which contains the part number for each record, can be
specified as the index (Figure 9-23). Then, every time the
addition specification is performed, the part number just
stored in NM indicates which element of the array is to be
referenced.

RPG

IBM

Thus, referencing individual array elements for output is
the same as referencing them for calculations. If the same
element is to be put out every time the output specification
is performed, an actual number can be used as an index.
Otherwise, if different elements are to be put out individually, a field should be specified which contains the changing
index value. In any case, the array element (array name
plus comma plus index) on the Output sheet cannot exceed
six characters in length.
Edit codes and edit words can be used to punctuate an individual numeric array element. If an entire array is to be
put out but the elements require different punctuation, each
element and its editing should be specified individually.
Editing to be done on an individual array element is specified
and performed just as it would be for any normal element.
This means that, if an edit code is specified for an individual
array element, two blanks are not automatically inserted before the element, as was the case with an entire array. Furthermore, although any type of output can be edited, editing
is generally not specified for an array element which is to be
punched on a card or written on disk to be used as input to
another run.

1 2

Page CD of _

Date

Programmer

C

9~
:=0

~3~rr."'

.... (5

E~

.f
3

4

Indicators

~

Line

5 6

011 I

Form GX21·9093
Printed in U.S.A.

CALCULATION SPECIFICATIONS

International Business Macnine Corporltion

Program

-

,/

C

8

I

AndI

~

IIIIII

Resulting
Indicators

Arithmetic

Operation

Factor 1

Factor 2
Name

~ ~
~

85
7

At

Result Field

75 76 77 78 79 80

~~~;~f:ation I

Length

15
z

Plus IMinusl Zero
Comments
Compare
1>211 <211-2
Lookup(Factor 2Jis
Hi 9h !,LOw \,E ual
54 55s 56 577 58 59 60 61 62 63 64 65 66 67 68 69 70 71
Q

9 10 1112 13 14 15 IS 17 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 5051

Sh-Ikl ,INIM I I I IAbo11 drlYllll1 j I c.h'IKI INM
I

I

I

I

JJ

" " I

JI~li»\l'-I~1 ~IN'VII'"

72 73 74

IIUM.IY

Figure 9-23. Specifying the Name of a Field as an Index

r

I

\ ......

9-22

RPG

IBM

GX21-9090

SPECIFICATIONS

OUTPUT

1

Program
Page
Date

Programmer

0

S Space

- "" ~~0-

Filename

Line

;.

lltS

~~

~

"ADD

~

~
6

3

4

o
o
o

1
2

0

3

0

o

4

0

~

Qj

~~D
7

8

At
~

~

--"

Output Indicators

Skip

~~

I--

5

U/M 050'

Printed in U.S.A.

International Business Machine Corporation

~

0

z

Field Name

1

0

z

:g
8

0

z

RiT

5

0

6

0'-

o

7

0

o

B

0

"0

w

11"1

;C:;IL 5

o

.t:

'AUTO

Positon
in
Output
Record

IAR OS

7 B

12.1~

,..,
STI<

N'fvl~

1~12

Zero Balances

Commas

to Print
Ves
No
Ves
No

Ves
Ves
No
No

ILJ

9 10 11 12 13 1415 1617 18 19 20 2122 2324 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

°IK 1t:1J-"

o

....

If]

~ii:

2

[I]

75 76 77 78 79 80

~~:;~f:.tion 1

of

No Sign

CR

1
2

A

J

B
C
0

K
L
M

3
4

I. 1 1 1 I· I

X = Remove
Plus Sign
= Date
Field Edit
Z = Zero
Suppress

V

Constant or Edit Word

«~.Q.~50M~~~H~D~~50M~~MU~D~~ro

I

I I I I I I I

I I I I I I

II

Referencing the same element
by using actual number as index
I Ll I III l J-J 11 1 1J

I

I

71 72 73 74

!

.

I I II I I II II
I I II I1·1I II II II
J

J

J J

J

J

Referencing different elements
by using a field as the index

I

Figure 9-24. Output of Individual Array Elements

Referencing Only Part of a Field

)

When a field is referenced in a specification, all characters
within that field are used in the calculation or output.
However, you may wish to reference only some of the data
stored in a field. For example, consider the case during
address printing where the·zip code is within the same field
as the city and state on an input record but must be printed
on a separate line on the output record (Figure 9-25).

The indexing capability of arrays can be used to enable you
to reference specific characters from an input field. This is
accomplished by setting up two arrays; one to contain the
entire field of data and one to hold only the specific characters you want to reference,

Output record

Input record

1458761 NELSON KENNETH RAY
NELSON KENNETH RAY
NORTH'

~UENORTH
\HJ:rti}$!fi;M!i!!~~

.

" " CSZ field to be printed as:

I
-")
J

ROCHESTER;t5MINN1S55901-!:%f:Ststst5t5lSrS

I

CSZ field

Figure 9-25. Referencing Parts of a Field Separately
Arrays

9-23

First, the entire field from which you wish to use data is
stored in an array of the same name as shown in Figure
9-26; (See Loading Arrays, Storing Input Data into Execution Time Arrays later in this chapter for an explanation of
this method of loading an array.) This array is previously
defined as containing as many one-byte elements as there
are characters in the field' to be referenced. Thus, each
character of the one field is actually stored in a separate
element of the array. The array elements can then be referenced one at a time (using an index) until an element containing a specific character is located. This process of checking the elements of an array for particular data is referred to
as field scanning.
After scanning the elements and locating a specific character, you can then move that character and any characters
(elements) on either side of it to a smaller array. This ar-

ray will then contain the portion of the original input field
which you wish to reference separately in calculations or
output.
For an address printing program, let's assume the input records
are defined as shown in Figure 9-27. The CSZ field contains
the city/state and zip code. Although names of the city and
state may vary in length, the zip code is always five digits
long. Any righthand, unused positions of the CSZ field will
contain blanks.
The two arrays for this program are defined with the extension specifications in Figure 9-28. CSZ is set up to contain
30 elements, one for each character of the CSZ field from
the input record. The five elements of the ZIP array will be
used to contain the zip code portion of the CSZ-field.

CSZ field (30 characters)
ROCHESTER;t5MINNt555901~

I' R

I 01 C I HIE

1 SiT 1 E

"R I '

115

I'M II

I N I N I 15 I 5

15

I9

I 0 11

CSZ array (30 elements)

ZI P array (5 elements)

Figure 9-26. Isolating Part of a Field

9-24

I is liS

'is 115 liS 115 liS liS I ~ I

/

RPG

IBM
/

InternatIonal

GX21·9094 UiM 050'
Printed in U.S.A.

INPUT SPECIFICATIONS

Bu~ine51 Machine Corporation

1 2

Program

Page

Programmer

Oate

Record Identification Codes

~

I

~

r--

.~

Co

Filename

Line

~
I-

~

~

11

~
=6 ~

j

'Or;-

....

~

0

Position

~; 'E

5 .~

~

~

CO

Position

o~j

zo c::~

~~ ~

Position

~fl6

z u u

~c

~ 3i c::

a~ g
~ § OU5o:

From

To

~

4

5

6

0

::;u

C

IIIIII

Field
Indicators

.g

1 iI

~
'g

~
'0

Zero
Plus Minus or
Blank

~

7 8 9 10 II 12 13 1415 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 5960 61 62 6364 6566 6766 69 70 71 72 73 74

0 1

lit Nip Il

0 2

I

~h D~

I

I
i.tJ

~

0 3

35

NIA MI£

o
o
o

4

I

3b

h.5

5

I

ql~

6

1*

It!~

0 7

~~~;~f:ation I

3 !! j

Field Name

-"

~

A'NO
3

of_

Field Location
3

2

1

75 76 77 7B 79 BO

0]

T

"Is~

IAA

IFlr I~IL D

~lL

I,..,...

,..t.. ~I... NI~

"Ir Tly -~"" I J Pt

-

II~

-;z 1101

srr RE lET

1"'15;1

"

.~

I
-

r'\

ROCHESTER,~MINNb55901~~~~~~~~~

Figure 9-270 Defining a Field to be Scanned

CSZ field

/

RPG

IBM

EXTENSION AND LINE COUNTER SPECIFICATIONS

Form X2HI091
Printed in U.s.A.

Intimation. Business Mec:hine Corpo,.tion

1 2

Program
Programmer

Page

Oate

0]

rTTTrn
75 76 77 78 79 80

of_

Pr~ram

Identification

Extension Specifications

E
Line

Record Sequence of !he Chaining File
Number of !he Chaining Field

To Filename

8-

~

j

From Filename

Table or
Array Name

Number
of
Entries
Per
Record

Number
of
Entries
Per Table
or Array

Length
of
Entry

j~

:)~~

~~l

Table or
Length
Array Name of
(Alternating
Formatl

Entry

S

~

c::

~

~

Comments

f!

Ii

j

Figure 9-28. Defining Arrays for Field Scanning

Arrays

9-25

To locate the zip code in the CSZ array, the elements must
be scanned one at a time, beginning with the last (rightmost)
element of the array. Thus, the index field (C) for referencing the individual fields of CSZ is initially set up in the
Calculation sheet to contain the value 30 (Figure 9-29, line
01). When the last (rightmost) character of the zip code is
located, it should be, moved to the rightmost (fifth) element
of the ZIP array. Therefore, a 5 is initially set up in the index field (Z) which will reference a particular field of ZIP
(Figure 9-29, line 02).'
With the index fields set up, the program can begin scanning
CSZ for the zip code. The elements of CSZ are checked,
from right to left, until the first nonblank character is
located. As line 04 shows, a character is compared to a
blank. If it is blank, the index value is decreased (line 05)
so the next character to the left can be compared to a blank.
When one of the characters checked is not a blank (indicator
20 off), the last character of the zip code has been located.
This ends the field scanning.

RPG

IBM

The program can now proceed to perform the next group of
calculations which move the located character to the rightmost position of the ZIP array (line 09). The character in
the CSZ array which was moved to the ZIP array is now
made blank (line 10) so the city and state line can be,printed
without the zip code. The index values for both arrays are
decreased by 1, so the next zip code character (to the left
of the last one moved) can be moved from CSZ to the next
portion in the ZIP array. When the value of Z become~ 0
(indicator 21 is on), all five characters of the zip code have
been moved to the ZIP array and made blank in the CSZ
array.
After calculations, the output specifications in Figure 9-30
cause the name and address to be printed~ The NAME and
STREET fields are printed exactly as they appear on the input record. City and state, on the other hand, are printed
from the CSZ array rather than the input field, because the
zip code has been blanked out. The zip code, which was
moved to the ZIP array, is then printed alone on the next
output line.

Form GX21·9093
Printed in U.S.A.

CALCULATION SPECIFICATIONS

International Business Machine Corporet!on

1

Programmer

C
I--Line

Date

Indicators

~

9Q?

E

~ 211<211-2
Lookup(Factor 2);s
High Low Equal

~fJ

r

75 76 77 7B 79 BO

~~~;~f:ation I

f_

R.. ulting
Indicators
Arithmetic
Plus IMinusl Zero

,.

1 2

.

E

c

1

1 8

.~
~
'2

0

4

8

Length

z

3

7

Factor 2
Name

a
a
a
a
a
a
a
o
a

5 6

Result Field

At At

::0

~~~
t- '0 a:,-

2

pagernO

Program

l

plR !rl~ T'6. lt"I 1\1\111

51"\

~.I-I

H

:JT

~N

~L L

i: III-'

1~1~t-

p,~ TIH

,""

AI,.. Inl"

I...

MlvE INlxT "H AIR

iriS
I~

1~lp 1"0

~It Ip" !n
rrlN nJ:ix nl=

~llJrr

/

)

GX21·9090 U/M 050·
Printed in U.S.A.

SPECIFICATIONS

OUTPUT

RPG

IBM

International Busin'51 Machine Corporation

1 2

Program
Page
Programmer

Date

0

u:: Space

~]j~

Filename

Line

~ ~ ~
I- cii

~

I-

3

4

1

5

«

ADD

~
o
o
o
o

Output Indicators

Skip

~c -I~-+---.--r---~----~---;

Commas

Zero Balances
to Print

Yes
Yes
No
No

Yes
No
Yes
No

j

75 76 77 78 79 80

[]]Of_ ~~~:~f:ation I I I I I I I
-

No Sign

CR

1
2
3

A

J

B
C
0

L
M

4

K

X ~ Remove
Plus Sign
Y = Date
Field Edit
Z = Zero
Suppress

Constant or Edit Word

9 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

6

2

3

0

4

0

0 5

0

o

6

0

0 7

0

o

0

8

Only city and state will be printed since
zip code blanked out.
Only zip code will be'printed.

Figure 9-30. Output of Part of a Field

)

LOKUP OF AN ARRAY

1.

The search word to be used.

Searching an Array for a Particular Element

2.

The LOKUP operation code.

An array can be searched to determine if a particular
element of data is stored in the array. Actually, ~he array
lookup is coded and performed in almost the same way as
a single table lookup. As the Calculation sheet in Figure
9~31 shows, you specify:

3.

The array to be searched.

4.

The condition which must be satisfied.

5.

The resulting indicator which turns on if the condition is met.

RPG

IBM

Form GX21·9093
Printed in U.S.A.

CALCULATION SPECIFICATIONS

International Bu,ines. Machine Corporation

1

Program

Page
Programmer

C
I-Line

Indicators

~

0_

~.s~

... 15 a:
g ~~ ~

&
4

o
o

1

c

2

C

o

3

o
o

4

c
c
c

5 6

Factor 1

Operation

Name

'0

'0

~~~:~f:ation I

IIIIII

Arithmetic

:~ ~

Factor 2

of_

Resulting
Indicators

Result Field

AL Jd

..Ja:

:::0

3

5

Date

75 76 77 78 79 80

2

[0

Plus 1Minusl Zero
Compar.
Length
1>211<211-2
LookuplFactor
2lis
'u c:z: High Low Equal

~J

Comments

85

~

7

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 33 34 35 36 37 36 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 58 67 5859 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

8

z

z

~TI~

IIII

.... )( nll\lnll\l/I

I~
Actual search word
or field containing
search word

IIIII

~I
Name of array
to be searched
I

I

I

I

I

I

I

I

I

I

I
I

I I 116 I I I I I I I I
Y 1
IIIIIIII

T

Condition which satisfies search
and which resulting indicator
is turned on

Figure 9-31. Searching an Array for a Particular Element

Arrays

9-27

Page of GC21-7567-2
Issued 24 May 1976
.By TNL: GN21-5389

With arrays, however, you also have the capability of beginning an array search at any element you specify. Under
Factor 2, you specify the array name, followed by a comma
and an index. The index, whether an actual number or the
name of a field containing a number, points to the array
element where the search is to begin (Figure 9~32).

The array lookup continues, one element at a time, until
the search condition is satisfied or the end of the array is
reached, whichever occurs first. As is the case for table
lookups, array elements must be in sequence (A or D) if
searching for either a low or high condition. Additional
coding is necessary if searching an out-of-sequence array
for either high or low. (See Searching an Array for More
Than One Element and Output During an Array Search.)
Although array and table searches are similar, there is an
important difference you must be aware of. Remember,
the array lookup is similar to a single-table lookup, not a
two-table lookup. Only one array is specified in the lookup operation. Any element which is referenced as the result
of a successful search can only be from the array actually
searched. In other words, the array can not be searched to
make an element from another array availa~le, as is the case
when two related tables are used in a lookup operation. For
this reason, no result field may be specified in an array lookup operation.

In a large array where you know that the value you are
searching for is not in a particular section of the array,
search time can be greatly decreased by beginning the
lookup at a particular element. Suppose you have a 300element array name ARY containing the values 001 through
300 in ascending sequence. To locate a value of 047, only
47 elements would have to be checked before the search
co~dition was satisfied. However, to locate the value 289,
289 elements would have t6 be checked, if the search began
at the first array element.
Now, divide the array into three parts of 100 elements each:
Elements 1-100:

values 001-100.

Starting the Search at a Particular Element

Elements 101-200:·

vallJes 101-200.

Another very important difference between tables and arrays concerns where the search can begin. In a table search,
only the name of the table to be searched can be specified
as Factor 2 of the lookup operation. As a result, a table
search always begins at the first table element. Likewise, if
only an array name is specified as Factor 2 of a lookup
operation, the search automatically begins at the first
element of the named array.

Elements 201-300:

values 201-300.

RPG

IBM

'ntemationar Business Machine

Form GX21·9093

CALCULATION SPECIFICATIONS

Printed in U.s.A.

Corpo,..ti~n
1

Program

Programmer

c

~

,!

line

13 _"

5

11

Iii

IJ~ I.~

i o 11

C

10 1 2
1 0 13

Cf){. ~IR
c

1

0 14

AI\d

Factor 1

Aid

1111,~

1131141

~

116117

18

il-

19 20 21 2.2 23 24 25 26 27 '28 29 30 31 32 33 34 35

C\IQ

rlJ ilAJln

~IA '-U

WD

"'H I' ....
,..11( II

C

0 16

Ic

~'N~mmlmllJ

I
!

Figure 9-32. Starting an Array Search at a Particular Element

9-28

I

~~ rl
I

~

~~;:;:ation I

IIIIII

Comments

=Q-1»211 <,211-£.

'! l~i9:51~o:7::~~

'Actual number
as index

'-1-:-

I I IJ I

Length

41'42 L4 414.454R 47 "" '495051 "

-roo

10 AQ

75 76 77 78 79 80
o!_

:r

Name

Ito

2

[0

Resulting
Indicators
Arithmetic
Plus IMinusl Zero
.:;:
Compare

Factor 2

Operation

IC

10 15
1

Page

Date

I

60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

~Ib

:2.11,

I I I I IIII
ing

j

)

For any value of less than 101, the first third of the array is
searched, beginning at element 1. For values greater than
100, but less than 201, the second third of the array is
searched, beginning at element 101. Likewise, a search is
started at element 201 to locate any value greater than 200.
In any case, no more than 100 elements have to be checked
to satisfy the search condition.
For this example, the number of the array element at which
the search is to begin will vary, depending on the value being
searched for. Figure 9-33 shows that three LOKUP's have
been coded. Only one of the lookup operations is performed
for a particular value.

)

To determine which LOKUP (line 04,05, or 06) is performed, you must first determine in which part of the array
the value is located. The first COMP (compare) operation
(line 02) checks for a value in the first 100 elements. If the
value is less than 101, indicating the first one third of the
array, indicator 33 is set on. If 33 is on, the LOKUP beginning at element 1 is performed (line 04). However, if the
value is not in the first third of the array (33 off), another
compare (line 03) is necessary to determine if the value is in
the second third of the array (indicator 44 set on). Thus,
the LOKUP beginning at element 101 (line 05) is performed
with indicator 44 on. If neither indicator (33 or 44) was set
on, the value must be in the last third of the array, if it is in
the array at all. Therefore, with both 33 and 44 off, the
LOKUP beginning at element 201 is performed.

RPG

IBM

For the first LOKUP (line 04), it is not necessary to actually
specify the numeric value 1 as the index, in the same manner as 101 is specified for the second LOKUP. When no index is specified with the array name, the search automatically begins at the first field, as if the index were 1.

Note: Setting off indicator 44 (line 01) prevents an error
in the lookup function. What would happen if the SETOF
operation was not used and indicator 44 was set on in the
first cycle and 33 in the second cycle? In that case, 44
would not be set off in the second cycle because the N33
condition would not be satisfied in line 03. Thus, both
lines 04 and 05 would be executed. The LOKUP operation
in line 04 would be successful and indicator 66 would turn
on. The LOKUP operation in line 05 would not be successful and 66 would be turned off. Thus, a not-found condition would result even though the LOKUP was successful.
If the value of the index changes, as in this case, you can
use an index field to contain the number of the array field,
rather than using the actual number. In this way, it is necessary to code only one LOKUP. Of course, you must
place the appropriate number in the index field every time
before the lookup operation is performed. Thus an index
field will not always reduce the number of specifications
required.

Form GX21·9093
Printed in U.S.A.

CALCULATION SPECIFICATIONS

International Business Machine Corporlt!on

1 2

Program

Oate

Programmer

C
-

Indicators

~-

4

'0
z

'0
z

85

~

7

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 5051

o 4

C

I~~

o

5

c

"ILl

o

6

C

o 7

C

o

C

8

Length

~

8

VA I IJIF
VA I Jle:

INI~:l,

~

.

VA I

'I

75 76 77 78 79 80

of _

~~~~;~f:ation I

IIIIII
-

Resulting
Indicators

Plu,_LMinusLZero

Factor 2

6

o 3

o 2

Operation

Name

c
c
c

o 1

)

I;

CD

Arithmetic

Factor 1

.... '0 a:

E E~ -

3

Result Field

At At

-'a:
::0

~~~

Line

Page

5E rrhlF
IlJlL

~Ip

2J?Jl1.

'JIE

:lO:K

V~ , liE
viA , 'JI~

hif,(

't 11"'111<

',...

54 55 5667 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

44

""(") Mlp
,.~

Comments

Compare

1>211 <211 a2
Lookup(Factor 2)is
High Low Equal

l1B
1'f14

.. ,..

,,",Jot "-IY
'1"11\

rJl\

I" "I,.,.

,11 lill
121151

FI IR C;T
t;E

rn ND

'bib ST lARrr
b"~ ST AR,T

~IJ.I IrlR 10?
~H IT IR n?
IFI! 1"1 ~11

~IT

I=ll n

'bb ST aRT 11=11 n

t:t.~ illJ
:..t2 ~l

Figure 9-33. LOKUP with an Actual Index

Arrays

9-29

As shown in Figure 9-34, first the compare operations. are
performed to determine whether the value is in the first,
second, or last-third of the array. The results of the compare operations determine which number should be zeroadded into the index field, IXFLD, before the lookup is
performed.
See the previous Note for an explanation of the use of the
SETOF operation in Figure 9-34 (line 01).

then begins at the element number specified. The array
lookup continues, one element at a time, until the search
condition is satisf,ied or the end of the array has been
reached, whichever occurs first. If an index field is specified, the number of 'the array element first satisfying the
search condition is stored in the index field. However, if
the end of the array is reached and none of the elements
satisfy the search, a 1 is placed in the index field. In' any
case, if an actual number, not an index field, is specified as
the index, the actual index is not changed to reflect the
success of the search.

\

Determining if a Search Is Successful

At this point, we should discuss the index field and how its
contents are changed as a result of the lookup operation.
Before the look,up is performed, you determine the value
which is to.be placed in the index field. The array search

RPG

IBM

The way in which you determine a successful search is
whether the resulting indicator assigned hasbeen turned C!n
or off. Thus, if the resulting indicator is off and an index.
field had been specified, the index field should contain the
value 1, the result of an unsuccessful search. If the first
field of an array satisfied the search condition,' the index
field would also contain the value 1; however, in such a case,
the resulting indicator would be on.

CALCULATION SPECIFICATIONS

Form GX21·9093
Printed in U.S.A.

t"ter"atlonal BUSiness Machtne CorpOrltion

1 2

Program

Date

Programmer

C

t---

~
~~

5

."

Factor 2

0

Plus IMinusl Zero

0

Compare

Length ~

E

9 10 1112 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 5051 52

o

5

c
c
c
c

o

6

c

o

7

c

o 8

C

ft

Operation

6

o 2

ft

Factor 1

Name

7

u

:£

0

0

\/iA L ll~

r,... mlp

IE.

rn Mlp

VAL

1_~13
lu

IE

1"\'1<'

54 55 5657 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

nl\ D

1

~ Ii '1<151
:'HIrR (')1
'N't""I -I~ I=r 'Nr TI-l IT ~ n?

'4~

z- '"I.... ..... '"
~- AID "" ~l
t- Alo "'2 ~l

VAL

1>211<211~2

:~B

,."

ItJlq
INI~ I~I"I

1~11
2.~ll

, II xl~ In

IxlF D
IxlF n
IIXIF 0

Comments

Lookup(Factor 2)is
High Low Equal

'-ILl

SF' rrhF
INI~I~

(

Indicators

z0

C

o 4

I

And

z

IIIIII

Arithmetic

Eg
8

o 1

o 3

At

75 76 77 78 79 80

r~~;~f:ation I

Resulting

Result Field

I- '0

~
4

Indicators

~.

>..J

line

3

pageDJOf_

R(2l

~T ~RT

srr iAIRT

I" ~

14T r: In ... ~
1Ft n I#IL ~L

I" rr IAIRT lc J..1"

~12 ~11.

~

Figure 9-34. LOKUP with an Index Field

(
9-30

...

Referencing an Element Which Satisfies a Search

./ After a successful search, you can use the data from the
element which satisfied the condition only if the array name
with an index field is specified in the LOKUP specifications.
If an index field is specified, the number of the field which
satisfied the search is stored in the index field. Therefore,
specifying the array name with the index field in a subsequent calculation or output specification refers to the
element which satisfied the search.
However, if no index field is available (array name specified
alone or with a numeric index), the number of the element
cannot be determined and, therefore, the data cannot be
referenced. You can only determine if one of the array
elements does contain the data for which you searched,
according to the on-off status of the resulting indicator.

RPG

)

IBM

The ability to reference a data item which satisfies a search
is one of the major differences between an array lookup
and a table lookup. During a table lookup, when a field is
found which satisfies the search, the table name alone refers
to the data item which satisfied the search. Following a
lookup for an array, specifying the array name alone refers
to the entire array, rather than to any particular element.
The only wayan individual array element can be referenced
is by specifying the array name with an index.
Assume you wish to search an array CH G to check for
amounts over $100. If you only want to determine if there
are any elements containing a greater amount, the search
can be coded as shown in Figure 9-35. If indicator 16 is on,
indicating a successful search, you can then print a message
stating there is a charge over $100. Otherwise, if indicator
16 is off, you can print a message stating all charges are
under or equal to $100. With the LOKUP specification
shown, however, you would have no way of knowing how
many elements or which elements satisfied the search
condition.

Form GX21·9093

CALCULATION SPECIFICATIONS

Printed in U.S.A.

Intern.lional Business Machine Corporation

1

Program

Page

Programmer

C
Line

Oate

Indicators

~

0_

Result Field

~3~
.- "0

Factor 1

Operation

E :. en

~85~
4

0

1

C

0

2

C

0 3

C

5 6

7

8

"

z

Resulting
Indicators
Plus IMinusl Zero

Factor 2
Name

a:.~

3

75 76 77 78 79 80

Arithmetic

AL Jd

...Ja:

:::0

2

[DOf_ ~~~;:f:ation I I I I I I I

"

Length

z

9 10 1112 13 14 IS 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51

1~~

rtJ~

"'I< lP r"H~

Compare

Comments

1>211<211=2
Lookup(Factor 2)is
High Low Equal
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

I1b

Figure 9-35. Determining Only if a Search Is Successful

Arrays

9-31

Searching An Array for More Than One Element

If you wish to know which element satisfied the search or,
perhaps, how much over $100 the amount is, the array
lookup should be coded with an index field (Figure 9-36).
The index field can be preset to contain the value 1, so the
search begins at the first element of the array. If the search
is satisfied, IX will contain the number of the first element
over $100; and the resulting indicator will be turned on.
The contents of IX can then be printed to indicate which
element satisfied the search. The actual contents of that
element can be printed by specifying the array name with
the index field (Figure 9-36, Output sheet).

The previous exam'ple points out an important consideration: an array LOKUP operation is completed when the
first element is found which satisfies the search condition.
If you wish to find all elements which satisfy the condition,
you must code additional specifications which cause the
program to loop back in calculations to repeat the lookup
operation from the point where the last search was successful.
As an example, assume your company manufactures 25 different items, identified by item codes 1-25. A 25-element
array QTY (Figure 9-37) is used to keep track of the quantity in stock of each item. The first element contains the
quantity of item code 1, the second element contains the
quantity of item code 2, and so on.

RPG

IBM

Form GX21·9093

CALCULATION SPECIFICATIONS

Printed In U.S.A.

I,..ternational Busine" Machine Corporation

1

Program

Date

Programmer

C ~::0

~

..Ja:

At

I;

4

~

en

6

7

At

Operation

Factor 1

.g

Factor 2

C

0 2

C*,

o

c*

3

:r Plus IMinusl Zero

~~
"C;:o'

1>211<211~2

OJ:

High

Low Equal

II "-l!(l

~Ik [lllp

'~().

rrlx

B~

"IJ.I (;: ~ Iry

ill

GX21·9090

SPECIFICATIONS

OUTPUT

1

Programmer

Page

Date

o

"- Space

e~
o !t:

~

Line

Filename

!

~ ~
....

8

9

Output Indicators

Skip

I

~

~~

ADD
~
~~AND

E

6

~~ e
u;

~

And

~

0

0

z

z

L

Field Name

ill

;3

0

z

·AUTO

~

Positon
in
Output
Record

Commas
Yes
Yes
No
No

Zero Balances
to Print

Yes
No
Yes
No

2

CD

No Sign

75 76 77 78 79 80
of_

CR

-

A

J

B

K

C

L

0

M

~~:;~f:ation I

I. 1 I 1 1 I

X = Remove

Plus Sign
Y = Date
Field Edit
Z = Zero
Suppress

a:

g

Constant or Edit Word

0:

10 11 12 13 14 15 16 17 18 1920 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 4041 4243 44 45 46 47 48 49 5051 52 53 54 55 56 57 58 59 60 61 626364 656667 68 69 70 71 7273 74

3

4

1

On llTPJi

2

0

Ill'

3

0

"'HG,

4

0

5

0

7

-v

{i

[ill

o
o
a
o

D

Ib

rx

Figure 9-36. Determining Which Array Element Satisfies the Search

9-32

U/M 050·

International Business Machine Corporation

Program

o

Comments

Compare

9 10 1112 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 5051 5253 54 55 5657 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

RPG

5

I I 1 1 1 1

E «
'u - Lookup(Factor 2)is

15

C

IBM

Length

z

~- lAin I~ll

0 1

0 4

8

0

z

75 76 77 78 79 80

~~~~;~f:ation I

of _

Arithmetic

Name

~85~

2

CD

Resulting
Indicators

Result Field

I-ori
E

3

Indicators

~j~

line

Page

,/

QTYARRAY
Array Element

//

3-

2

4

047 068 051 023

6

5

7

8

9

10

11

12

13

14

15

16

17

18

19

20

076 083 105 069 053 117 014 087 032 046 083 106 024 048 071

21

22

23

24

25

029 108 067 035 p08 075

Below stock level of 25

Figure 9-37 _ More than One Array Element Which Satisfies the Search Condition

100 items are to be manufactured and added to stock whenever the quantity of an item falls below 25_ To determine
which items are to be manufactured, every week the QTY
array is searched, comparing the array elements with a search
word (M FGPT) of 25 from a data card. When a quantity is
found to be less than 25 (search condition Low), the item
. code and quantity in stock are printed.
From Figure 9-37 you can see that four items must be manufactured. The specifications in Figure 9-38 will not locate
all of the items with quantities less than 25. The lookup
operation shown will locate only the first quantity below
25. If only one data card (containing the search word) is
read, the specifications are performed once. As you know,
for every data card read, the program cycle is repeated. However, even if several data cards with the same search word

RPG

IBM

International Business Machine

are read, every time the lookup is repeated, the search begins
again at element 1 of the array. Therefore, the same array
element satisfies the search every time, and the other three
quantities are never found.
To locate more than one element satisfying the same search
condition, the LOKUP must be repeated within a single program cycle. Not only must the LOKUP be repeated, but the
search must begin at the point where the previous search
ended. You can repeat the LOKUP using the GOTO and
TAG operations, as shown in Figure 9-39. To make sure the
repeated search begins where the last search left off, you
must specify the array name with an index field in the
LOKUP specification. The contents of the index field is
then updated after each successful search to indicate at
which array element the next search should begin.

Form GX21-9093
Printed in U.S.A.

CALCULATION SPECIFICATIONS

Corporat~on
1

Program

Programmer

C

Indicators

0_

~ '0

E

4

5

~

en

Factor 1

Operation

Name

Length

8 5~

~

6

7

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 J8 39 40 41 42 43 44 45 46 47 48 49 5051

S
z

75 76 77 78 79 80
of_

~~~;~f:ation I

IIIIII

Resulting
Indicators
Plus Minusl Zero

Factor 2

.f

8

2

[0

Arithmetic

cl

01 1 1 C I
01 1 C I
2

Result Field

AL Jd

-'0::

::0

~~~

Line

3

Date

~

-

Page

S
z

MIF r;lph-1 I I I I 'dOKlulp dTlvllllll1 I I I I I I I
I I I I I I I I I I I I I 1r TTTTII T T II I I I I

Compare

Comments

1>211<211-2
Lookup! Factor 2) is
High Low Equal
54 55 56 57 5859 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

I !313 I bTl "I ILElslsl tr'"IAI"II~lr
I I I 11 I I I I I I I I I I I I

"

)

Figure 9-38. Array Search Which Locates Only One Element

Arrays

9-33

The first search should begin at element 1. Thus, as Figure
9-39 shows, the index field IX is initially set up to contain
the value 1. (The field is zeroed before adding 1, since you
have no way of knowing the contents of IX at the beginning
of the program run.) The TAG operatio'n is not performed;
therefore, the computer skips this specification and performs the LOKUP.
When the first OTY element less than 25 is found, the number of the element (04) is placed in the index field. Providing the LOKUP was successful (33 on), a 1 is added to
the value in the index field, to indicate at which element
the next search should begin. The value in the index field is
then compared to 26 to see if the entire array (25 fields) has
been searched. If there are still array elements to be checked
(indicator 44 on), the program branches back (GOTO) to
perform the LOKUP again. The search would then begin
again, only at the element following the last element which
satisfied the search. The calculation specifications would
be repeated over and over until all items to be manufactured
are located and until the end of the array is reached.

Output During an Array Search
The specifications in Figure 9-40 search through the OTY
array to locate more than one element. In this case, it does
no good to search through an array unless you know what

RPG

IBM

data was found. For this reason, each quantity less than 25
and its related item code are printed. Following each successful search, the item code number (same as the number
of the array element containing the quantity) is stored in
the index field IX. Thus, the field IX can be printed. The
actual quantity which satisfied the search can be printed by
specifying the array name with the index field in the output
speci fi cati on.
Since the output specifications usually are not performed
until all calculations are done, normal output would be invalid since there would be an attempt to reference array
element 26.
In order to print each item code (field number) located in
the array search (and its quantity), output must be done before the contents of the index field are c~anged.
You have learned that using the EXCPT operation on the
Calculation sheet makes it possible to perform output specifications before calculations are finished and then to return
to finish the calculation operations. As Figure 9-40 shows,
following a successful LOKUP, the EXCPT operation then
causes the data placed in the index field to be printed, followed by the contents of the array element which satisfied
the search. After the exception output has been performed
(output lines identified by an E in column 15), the program
continues with the calculation specifications by executing
the calculation which follows the EXCPT operation.

Form GX21-9093

CALCULATION SPECIFICATIONS

Printed in U.S.A.

Internation.1 BUliness Machine Corpor.t!0n

1 2

Program
Programmer

C
f--

Indicators

5

Result Field

§

~

~c(

]

.... z

6

8

~

Lin.

pageDJof_

Oat.

8.

3

4

o
o
o

1

C

2

C

3

C

o
o

4

C

6

c

o

6

C

o
o
o

7

C

8

C

9

C

Operation

Factor 1

Jd

Jd

Factor 2
Name

~

rr." 0

.... :.--

V

r\

-:--. .....

An nr11

I ,.. Ifl

ADn

au

Tr

rl'" ~p

2.1-1

/(;

r

fx

~9

C
50 51 52

~r:.

-~~

~I.J
OTN

~-

-~ ....
,-

I

Figure 9-39. Repeating a LOKUP to Locate All Array Elements Satisfying the Search Condition

9-34

IIIIII

Comments

54 55 5667 58 59 50 61 62 63 64 65 66 67 66 69 70 71 72 73 -74

TlC

",'"

75 76 77 78 79 80

:~;~f:ation I

Resulting
Indicator.
Arithmetic
Plus 1Minusl Zero
Com par.
1>211<211-2
Lookup(Factor 21is
High Low Equal

2.Cl

,..,.. -IY TX

rx

~I'l,

"-

~-

'T At;

Af:.t AIN
tvr: t=wPT

V
V I"I~

~
E

~

'2

9 10 II 12 13 14 15 1617 18 19 20 21 22 23 24 25 26 27 2B 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 4B

":l.
4L1

Length

~

0

z

/'

ST AIRrr

Air

"'TY

l~

55 Til

ADO

70

~I\ID

n~

II N

I=lD
II

ttl
.,ro

')FX

Aft ",III

II,?

Nr"I -~ "A R"""" NE' tT

./

LOADING ARRAYS

Compile Time Arrays

In the beginning of this chapter (Defining an Array), you
learned that arrays are divided into three types based on
when the array data is stored into the array. The three
different times are compilation time, pre-execution time,
and execution time. Data can be stored in any of the following ways:

Arrays loaded at the same time as your RPG II source program are referred to as compile time arrays. The array is
compiled along with the RPG II source program. The array
data actually becomes partof the object program. One
definite advantage in creating compile time arrays is that
you need not load separate array files into the computer
every time you wish to run that object program.

• Compilation time: keyed in on a console (keyboard)
device; read from punched cards, tape, or disk source
library

• Pre-execution time: keyed in on a console device; read
from punched cards, tape, or disk

• Execution time: Extracted from an input file on a console device, punched cards, tape, or disk during execution of the program

• Execution time: Created by calculations performed
during the program
RPG

IBM

I
I

Program

Programmer

C

Date

Instruction

Page

~-

E

4

6

~

en

7

8

o
o
o

1

C

2

C

3

C

4

C

At

Operation

Factor 1

At

:E =-

Factor 2
Name

t!- lAD !1"'I·0'l1
Irv-:F ~IPT

5

C

3~

~)(

6

~3

lrx

o

7

c
c

=\~

~4

~3

I

Program

I

: Programmer

Date

I
I

0

S Space

~~

O-

~~

Filename

5s

1l. ti ~ :t
~~

~

r;:;: D~J

I-

§
u.

.£
A
8

RPG

/

I

~"o

/·1

Punching
Instruction

I

I /

I

...

HRh'

If:'

Il IEMlr "NIE

Punch

I
I

IIY

Jd

1

Field Name

0

°

z

z

'AUTO

;E

1
Page

v

til

~

0

z

-s

GX21·9090 UiM 050'
Printed in U.S.A.

Card Electro Number

II

m

i:ND bl= I\n nl" 'I
NI"I
IJ:'~ IRr ~ IN~ XT

144

I
I

PositO"
in
Output
Record

21"

PR rlNlr IRF DI> ""rv
AnD rr'" If\! nl~Y

SPECI FICATIONS

OUTPUT
Graphic

rl~ Af\!

""TY II E lslS

1':\3

Output Indicators

Skip /

~

r

':Jrl.

trlY

II hlk 1'-' IY I~ rlx
HI=' Iylr PW
...........
IOJl1
l4lnlo
'1 r 1"~lp 21~
I
II (;I~ ITb ~r.. Atr 1\1

I

International Business Machine Corporation

7

Comments

~~

rr-iAr,

I

6

IIIIII

'u - Lookup(Factor 2)is

o

5

Plus IMinusl Zero
Compare

Length ~ ~ 1>211<211-2

b

0

~(; IAIIN

Line

~~;~f:ation I

of_

Z
z
OJ: High Low Equal
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 33 J4 35 36 37 38 39 40 41 42 4J 44 45 46 47 48 49 5051 5253 54 55 56 57 5859 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

o
o

IBM

75 76 77 78 79 80

2

[0

Resulting
Indicators

Result Field

..... ori
5

1

Card Electro Number

-'0:

.f85~

)

I
I

Arithmetic

=0

3

-

Punch

Indicators

~~~

Line

Graphic

Punching

Cl

"---

)

Form GX21·9093
Printed in U.S.A.

CALCULATION SPECI FICATIONS

International Business Machine Corporation

75 76 77 78 79 80

2

[0

Commas

Zero Balances
to Print

No Sign

CR

Ves
Ves
No
No

Ves
No
Ves
No

1
2
3
4

A
B
C

0

of_

J
K

L
M·

~~~~;~f:ation I

IIIIII

X = Remove

Plus Sign
V = Date
Field Edit
Z = Zero
Suppress

I

0:

g

Constant or Edit Word

211<211-2
Lookup(Factor 2)is
High Low Equal

Comments

85

~

7

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 5051 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

8

z

3

4

a
o
o

1

C

~l

2

rill

o
a

4

c
c
c

5

C

rz~

o

6

c

rl1

a

7

C

o
a

8

C

9

C

1 0

c

11

C

3

LLLL

]

If

5

0

i~

j

1

line

0

0;

~
"2

IIIIII

Field
Indicators

~

t:

~

Position

75 76 77 78 79 80

~~~~;~f~ation I

Field Location

4

IBM

2

pageDJOf_

3

2

1

1

Card Electro Number

3

6

8

I
I

0

5

7

Instruction

go.

II

Filename

Line

I

Graphic

Punching

Record Identification Codes

~

I--

""II
,/

Comments

~

a:

INPUT SPECIFICATIONS

RPG

Programmer

)

Entries

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 4041 42 4344 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

I I I I I I I II

E

Number

of

or Array

Program

\.

Table or
Array Name

To Filename

~
I-

of
Entries
Per
Record

ell
rl!L

0%

z

~Io lIE ~F J In1
MI" V~ ~IF 1D2

M" V'~ lAlJ: in"::\
MI""I V'E ~~ :tlo""l
MI""I V~ l41,: :"In~
M'" Vf ~Ij: il Ii'll,
(

>
~

fMlp 1.
(:,M
I

Ip,2.

£MIp,;
J;MIp, ~
~M Ip.> 5

!;:~ Ip,'b

I
. Additional calculations using the
ar;ay data.

I
I

I I I I II I II II I I I I II '-]1

Figure 9·46. Loading Array Data From Scattered Fields by Assigning Unique Field Names

Arrays

9-41

Page of GC21-7567-2
Issued 24 May 1976
By TNL: GN21-5389

Array Data Consecutive on More Than One Record (Model
10 Card System)

All System/3 Models (Except Model 10 Card System and
Model 15C): Figure 9-47 shows a second way to load an
. array from scattered fields. The array name with an index
is assigned to each field of data in the input record. In this
way, the data is loaded directly into the array as the fields
are'read. No move calculations are necessary.

RPG

IBM

Consider a case where the array data on all input records is
organized consecutively. Data for a 25-element array named
TAX is contained on two input records (Figure 9-48). The
first record contains 19 fields, the second record, six. Each
numeric field is five characters long. The data is Qrganized
on the records in the order it is to be stored in the array.

Form X21-9091
Printed in U.S.A.

EXTENSION AND LINE COUNTER SPECIFICATIONS

Internallonal Business Machine Corporation

1

Program
Programmer

Page

Date

2

CD

75 76 77 78 79 80
of_

~~~~;~f:ation I

IIIIII

Extension Specifications

E

Record Sequence of the Chaining File
Number

r----

Number of the Chaining Field

To Filename

Line

Table or
Array Name

From Filename

3

4

o

1

o
o

2

5

6

7

8

of
Entries
Per
Record

Number

of
Entries
Per Table

Length
of
Entry

or Array

~

~
"-

Table or
Array Name

1~

(Alternating
Format)

g~
.~
0 £

Length
of
Entry

Ci

Comments

$

g j~
Ci:
II:

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 51 58 59 60 61 62 63 64 65 66 67 68 69 70 11 12 73 14

~MP

b

5

~

3

RPG

IBM

GX21·9094

INPUT SPECIFICATIONS

U/M 050·

Printed in U.S.A.

International Business Machine Corporation

12

Program
Programmer

Page

Date

Record Identification Codes

~

I

]

~

11

Filename

Line

!

Ii

j ~

1l
-,--5

j

~~_z

1

f:e;
~

]

0

~

Position

II;

~e~

b ~ ~
z u u

Position

Ii;

~~ ~

~u6

0;

Position

757677787980
of _

~~~;~f:ation I

Field Location
3

2

CD

~ U'l

c::

30 ~ ~ ~
.2 '"
~

From

Field Name

~

To

~
.g

§ uViQ:

Field
Indicators

0

15
:!a-t;

] Li:~
e i:~
~

0

CD

~

c:

IIIIII

~
"E

!

"0

Zero
Plus Minus or
Blank

~cS u:

0;

AND
3

4

5

6

7

8

9 10 11 12 13 14 15 16 11 18 1920 21 22 23 24 25 26 21 28 29 30 31 3233 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 6566 6168 69 70 71 72 73 14

0 1

Ilr INlp III IT

0 2

I

0 3

I

IAA

(;']IJ

ll. InR

I."
1,1::a.

~ Ell'1!Pll.ll
111 IE: II" IPI,12

0 4

I

lll~

I,

0 5

I

o

12'-"
31.;
14~

12C, IE IN jp, [Lj
13!q II=I~ PI'~
~S IEIM PI, 13
Igq

6

I

0 7

I

o

8

I

111,

o

9

I

IQ~

1 0

I

J lIlt-! Ig~

1... 1. .

ILIKI~

II:.

IE~ Ipl't 15

Figure 9-47. Loading Array Data From Scattered Fields by Means of Input Specifications

(

9-42

/

1

2

3

..

5

6

7

8

9

10 11

12 13 14 15 16 .7 18 19 2021 2.2 23 2. 25 26 27 28 29 30 31 32

1

2

3

..

5

6

7

a

9

10 11

12 13 '4 15 16 17 18 19 2021 Z2 23 2" 25 2& 27

333.3536373839404' .2 .3 U

2
~

•

7

4

3

5

B
A
8

B
A
8
4
2

6

9

8

11

10

13

12

46.7484950 51 52 535 .. 55 5657585960616263

'4

B

20

4
2
1
B

~U~~~g~~ro~n~~~uvHH~~U~

1

29 3031 32

~~~~a_m~m~m~~oom~ro~~MmM~~~~m~~~m~

~~~~amm~m~m~~oom~ro~~MmM~~~~m~~~m~

B
A
8
4
2
1
B
A
8
4
2

4'

2'

A
8

A
8

4

4
2

2

21

23

22

24

A
8
4
2

25

~u~~~v~~ro~n~~~uvHH~~U~
A
8
4
2

~»~~~"~n~~Q~«6"aUU~~~~~"~D~"~~~~H~

~»~~~"~n~~Q~«6"aUU~~~~~"~D~"~~~~H~

A

A

A

A

8

8

8
4
2

8
4
2

~

14

15

16

17

18

~

19

1 ~"~u"ronnnu~nnnn~~~~u~H~H~~~~~M~"1

65 66 67 68 69 70 71 72 73 74

IBM 3700

TAX Array

76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 tot 95 96

1

--------------~--------------- ~
1-19

RPG

IBM

j

IBM 3700

20-25

EXTENSION AND LINE COUNTER SPECIFICATIONS

FormX21-9091
Printed in U.S.A.

International Business Machine COrporation

1 2

Program

Date

Programmer

75 76 77 78 79 80

Page [ D O f _

~~;~f:ation I

I I I I I· I

Extension Specifications

)

E

Record Sequence of the Chaining File

r---

Line

2i

5

6 7 8

E

Entries
Per
Record

From Filename

~
01 1 I

Table or
Array Name

To Filename

~

3 4

Number
of

Number of the Chaining Field

I

.g

:5

Table or
Length
Array Name of

~

~;
] ~

(Alternating
Format)

~~l

g

Comments

:!
a:

2
~

4344 45 46 41 48 49 50 51

I~

Entry

I

~

52 53 54 55 56 U56W~~~~54~56U56~MnnnM

I I I II

II

I II I I I I I I I I I I I I I
GX21·9094

INPUT SPECIFICATIONS

U/M 050·

Printed in U.S.A.

International Business Machine Corporalion

t Programmer

I
I

Date

I
-

~

Filename

!

~

3 4 5 6

~

j

Punching
Instruction

I
I

Graphic
Punch

I I Card Electro Number
I I

I
I

Record Identification Codes

.1

Line

)

Per Table
or Arrav

I I II I II h-IAIYI I I I I I ILI5

Program

o

Entries

Length
of
Entry

9 10 It t2 t3 14 15 16t7 t8 t9 20 21 22 23 24 25 26 27 28 29 30 31 32 33 J4 35 36 37 38 39 40 41 42

I I I I I I I II

RPG

IBM

c _

Number
of

2

1

Field Location
3

c.

~

::0

r~

~~ 'E
§ .~

r'Q'R- zo ~
~Nro

~

Position

g o

~

tl

o~j

Z u u

Position

~e

~

N

~t36

Position

go

'0 ~
Zu

~~

f!:

From

To

~~~

7 8 9 10 It t2 13 14 15 16 17 t8 19 20 2t 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51

1

II

INlp ~rr

APt

011

11 Ol1.

AA

WlJ2

lL n12.

1 2
Page

[0

~b

!2
17

b triA be ~ 12~
II L rr14 I.r. (2.1

2

I

3

I

o
o
o

4

I

5

I

6

I

o

7

I

1L11

o

8

I

o

9

I

12.12
:211

11~

~~;~f:ation I

the array elements on the
second record need not be
loaded separately on the
Model 10 Disk System,
Model 6, or Model 15,
since the MOVEA operation
code is available on these
systems.

12

o
o

75 76 77 78 79 80
of_

IIIIII
ors
~

Zero
or
Blank

69 70 n 72 73 74

trl4lX

ITIAIX, ~2
121 rrlA Ix, i23
12~ rrlAlx 12.'1
BL rr~ Ill't 2.;
ll.~

Figure 9·48. Loading Array Data Consecutive on More than One Record (Model 10 Card System)
Arrays

9-43

Page of GC21-7567-2
I!;sued 24 May 1976
By TNL: GN21-5389

(.

It is important ,to note that when data is stored in an array
by spedfying the array name as the field name, the information is placed at the beginning of the array. Thus, the 95
columns of data from this first input record are stored in
elements 1-19 of the array (Figure 9-48).
Although the data on the second record is also arranged
consecutively, each element is loaded separately. The second record cannot be defined as a single array field and
stored automatically in the array because the data would
be stored at the beginning of the array, destroying the d~t.a
previously stored at the beginning of the array. Instead, the
data from the second record is loaded by defining the individual fields as array elements on the Input sheet (Figure
9-48). The data could also be loaded by assigning a unique
fieldname to each field of array data on the second record
and using MOVE operations to move ea~h field to its proper
array element. In this case, specifications would be similar
to those for the EMP array in Figure 9-46.
In this example, the method of defining and storing data in
the TAX array is relatively simple. tiowever, if there are a
large number of data fields contained on records other than
the first, storing the data can require a great number of
coding lines. Suppose, for example, the TAX array consists
of 50 fields. Three records are required to contain the data.
The first two records contain 19 fields each; the third contains 12 fields. Storing the data using the method shown in
Figure 9-48 requires 31 separate lines of coding to load the
data on records two and three. Because of this, you might
want to consider loading the array as a compile time or preexecution time array, instead.

9-44

.I

Array Data Consecutive on More Tha. n One Record (Model
6, Model 10, Model 12 and Model 15)

\ On the Model 6, Model 10, Model 12 and Model 15, it is
much easier to load array data that"i's consecutive on more
than one input record. Consider the previous example
(Figure 9-48). The cr°lt.y data on the second record can be
described as a ~lgle field on these systems, because the
MOVFA operation code is available on these systems to
move data from a field to an array. Figure 9-49 shows the
coding necessary to load the TAX array when the MOVEA
operation is used in calculations.
Using the MOVEA operation, data that is consecutive on
many input records can conveniently be loaded during
program execution. See your RPGII Reference Manual for
a complete description of the use of MOVEA.

/'

RPG

IBM

EXTENSION AND LINE COUNTER SPECIFICATIONS

FOrm X21·9091
Printed in U.S.A.

Intern.liona' BUline51 Machine Corporation

1

2

75 76 77 78 79 80

Program
Programmer

pageDJOI_

Date

~;~;~f:ation I

IIIIII

ExtensiolYSpecifications

E

Record Sequence 01 the Chaining File

t---

Number
01
Entries
Per
Record

Number 01 the Chaining Field

Line

Table or
Array Name

To Filename

...~E

From Filename

~
3

5

4

7 8

6

1

International

c _

Table or
Array Name

,90

Length
01
Entry

~~

:J ~

(Alternating
Format)

~

~~j

~
!!.

Length
01
Entry

Comments

Il

~ j

5

ii:

10 11 t2 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 :8 39 4041 42 4344 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

9

01 1 E I I 1111111
01 2 1 E I I I I I I I II

IBM

Number
01
Entries
Per Table
or Array

1111111 Tlo.lxl I I I I I 12.1; Its

RPG

8USin~ss MKhinl Corporation

II II I I I

I I II I I I

IIIIIII III"

1111111111111111

II II I I I

1111111111111111

GX21·9094

INPUT SPECIFICATIONS
1

2

75 76 77 78 79 80

Program

Programmer

pageDJOI_

Oat.

Record Identification Codes

I

Filename

3

)

5

4

o
o
o
o
o

6

7

1

I T

2

I

3

I

4

I

5

I

8

j

~
0
z ~
u u

Position

Field
Indicators

go

~§

~~

~

From

To

~

]

~

u..u..

I·~

1 ~B

'2

~

(;

~~

.!!]!

0

.g
~

j
"0

~

Zero
Plus Minus or
Blank

NIPll IT

IAlA

II Inl

Form GX21·9093

CALCULATION SPECIFICATIONS

Printed in U.s.A.

Intemationll BUlin... Mechine Corporation

1 2

C

----

Indicators

~

!

~~
Ez

I-

"0 Ii

~

85 -i

6

7

~ ~~

3

4

o
o
o

1

c

2

c

3

C

8

Jd

-

Operation

Factor 1

:~ g

Factor 2
Name

~

:~~;~f:ation I

IIIIII

Resulting

Result Field

Jd

75 76 77 7B 79 80

pag·DJOf_

Oat.

>.J«

I;

!

~~ a:
t; :u

~

Field Name

IIIIII

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 JJ 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

Programme,

Line

~~

Position

~u 0

RPG

IBM

:j

a:

Position

~~~;~I:ation [

Field Location

r--Line

U/M 050·

Printed in U.S.A.

Length ~

Indicators
Arithmetic
Plu. IMinusi Zero

Compar.
S 1>211<211-2

Comments

~~

'0 :: Lookup(Factor 2)i,

~

C J: High Low Equal
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 JJ 34 35 J6 37 J8 J9 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 5657 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

~2

II
II
I I

P1

.JIVI~

I
I

IJ

I I I rlAlrl, hlzl I I
I I I I I II I JJ J I J Jl

~lxld~ol

I I I I I I I I

I I I I I

I I

I I I II I I I I I I I I I I I I
J j I II I I I I I I I I I I I I
I

I

I

I I I I I I I I I I I I I I

• Figure 9-49. Loading Array Data Consecutive on More Than One Record (Model 6, Model 10 Disk System, and Model 15)

)
Arrays

9-45

Array Data Scattered on More Than One Record
Regardless of how many records are used to contain array
data, if the fields are scattered on the records, each field
must be individually loaded into its appropriate position in
the array. However, a separate specification is not always
necessary for each field of data to be loaded. In some cases,
th~ same specification can be used for all the records. This
depends on whether all the input records for a single array
are organized in the same format and whether the fields
from different records can be assigned the same name.
Assume that a 22-element array, named ARA, is defined.
The data for the array is scattered on six input records, as
shown in Figure 9-50. Although the array data is not consecutive, the four fields on each of the first five records are
in the same format on each record. The remaining two fields
on the sixth record are in the same format as the first two
fields on all other records.
Since the array data follows the same organization on all
records, describing one set of fields (Figure 9-51) actually
describes the fields on all records; except the last. A separate input specification should be coded to indicate that
record 6 only contains two of the fields. (Note on the Input sheet that records 1-5 are described in an OR relationship. Therefore, a specific card sequence cannot be specified in columns 15 and 16. You can assume that the arra-y
input records are in sequence. Record type 1 is the first
record read and record type 6 is the last.)

9-46

6

I FLD221

)
S

I

I

F~D171

FLD1al

IFLD191

I FLD20 I

I

FLD14\

FLD1S1
IFLD161
IFLD101

IFLD91
IFLD1d

I
IFLDSI

2

FLD12 I

FLD6
IFLD7J
I FLDal

I FLD1

)

I

I

I

FLD21

FLD31
I FLD41
Organized in
Same Format

Figure 9·S0. Array Data Scattered on More than One Record

)
Arrays

9-47

RPG

IBM

GX21·9094

INPUT SPECIFICATIONS

Internat,onal"Bul,nISS Machin. Corpor.tlon

1 2

Program

s

I

Filename

~

~

0

1

o

2

o

3

o

4

o

5

o

6

o

7

o

8

o

9

1 0
11
1 2

5

6

j

~
=0
~-;;-

§ .~

~
4

Ii

'oRr- zo

r;'No
7

8

~·5

~

,~

~

Position

]

k;

z0 ~
~ §~

Position

~

~~ ~
~u6

Position

~~;~f:ationl

Field Location
3

2

1

8'.

!!

3

Record Identification Codes

~

-:---

75 76 77 78 79 80

page[Dof_ .

Oate

Programmer

Line

U/M 050'

Printtd in U.S.A.

~e
~~

~ ell a:
~ t ::J

From

To

~~~

~

Field Name

~
'il

~
u

.s

~

~:2

~~

!.~

~ ~~

8

0

i

1 I- I

I

I

./

I

\

Field
Indicators

a:

j
:s!

Zero
Plu. Minus or
Blank

~

9 10 11 12 13 14 15 1617 18 19 20 21222324 25 26 27 28 29 30 31 32 33 34 35 36 37 38 3940 4142 43 44 45 48 47 48 49 50 51 52 53 54 55 58 57 58 5960 81 62 6364 65 66 6768 69 70 71 72 73 74

III NP JT
I
I
I
I
I
I
I
I
I
I
I

IAA

1f'1~R

iejl

leJI2

IL InJ
lL 02
lL n~

hlR

rl:13

~'R

12'l

l1.

hlR

~5

lL In"

h~

i;

I()~ FL

2.1, rtF lola

41

L.l1~ "C

I~b

lL

In~

In 1"'1

171~

IRA

inlA

2:.~

nib

l'i
12.l~

at1 Ir:.

In~

:217 ttlr: LnR

Figure 9-51. Describing One Set of Array Input Fields for Several Records

(

(

'--

9-48

Page of GC21-7567-2
Issued 24 May 1976
By TNL: GN21-5389

~J

Because the fields on the different records have the same
field names, only one MOVE specification is necessary for
each unique field name. The specification on line 07 of
Figure 9-52, when repeated for .each record, moves FLDA
of that record to the appropriate element of the ARA array.
Lines 09 and 10 are performed for every record except the
last, which does not have fields FLDC and FLDD.
Since the fields on the input records are in the same order
as they are to be stored in ARA, a definite pattern is established as to where the data is to be moved. Fields from record 1 are stored in array elements one through four, fields
from record 2 in array elements 5 through 8, fields from
record 3 in array elements 9 through 12, and so on.
Array index fields can be used to indicate to which array
elements that data is to be moved. For each unique field
name, an individual index field should be set up. In this

RPG

IBM

)

way, the values in the index fields only have to be changed
every time another array input record is processed. When
the first record is read, the index fields A, B, C, and Dare
initialized to 1, 2, 3, and 4, respectively, to prepare for
moving the fields from record type 1 (Figure 9-52, lines
01-04). After the four fields are moved, the value 4 is
added to each of the index fields so they pointto where the
four fields on the next record should be stored (Figure 9-52,
lines 12-15). The same calculation specifications are repeated until fields F LDA and F LDB from the sixth record
have been moved to the last two array elements.

Conditioning Operations Until All Array Data is Stored
All information must be stored in an array before you can
reference the data by specifying the array name or array
name with an index. Thus, any specifications to load the
data into the array must be specified before any calculations
which use the array information.

CALCULATION SPECIFICATIONS

Form GX21-9093-2

Printed in U.S.A.

International Business Machine Corporation

12

Program
Programmer

-

C

Page

Date

Indicators

~

~
&~

Result Field

At Jd

Factor 1

Operation

.~

Factor 2

> ....
f- 0

line

EE

.fa
5

6

0

0

z

z

1

C

ClJ

2

C

o

3

C

o
o

4

C

5

C*

o

6

C*

o

7

C

lolvE FL DIA.

o
o

8

C

OVE FL B

C

11

C,*

1 2

C

1 3

C

1 4

C

1 5

C

1 6

C

E

c

o
o

C

"8

~

"2

15

z

4

9

Length

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 J9 40 41 42 43 44 45 46 47 48 49 50 51 52

3

1 0

7

Name

l4D!D

(2l

z-

i!- lAD 102

((jl
Qjl

~-

AD ~3

-A OIC:q

Na

NCt~

~

2(2

~

AI~ :AI,IA

ARI~I.IE!

olvle FL c
lOVE FL ID

ARIA .II:

B

M~

A
B

~ID
~D

C

N~

rn

ADD
ADD

N~
N~

18

2.~
2~

IA

AI~ I~ .C

A

~

tD

2~

CD

Resulting
Indicators
Arithmetic
Plus IMinusl Zero
Compare

757677787980
01_

:~;:I:ation I

I 1 1 1 I· I

Comments

1 >211 <2TI-2
Lookup(Factor 21is
High Low Equal
54 55 56 57 5859 60 61 62 63 64 65 66 67 66 69 70 71 72 73 74

SEll UP liN DEl(
FI El DS iFKJR
MO VI NIG ~A Il~

Mia vie D~ rfA rrb
PR lop elf< AR R~N
FII El IDS
~N ell< E~ SE I~ DE:X
Mic ~E

V~ LU ES T(;
D~ irA FR b~

RE ckJ RD

HE ~T

Figure 9-52. Using the Same MOVE for Fields from Several Records

Arrays

9-49

For every record of array data, RPG II goes through a complete program cycle, just as it does to process any other data
card. This means that input, calculation, and output specifications can be performed every time an array input record
is processed. You want input specifications to be performed
to describe the array record to the system and, perhaps, to
load the array data at the same time. Perhaps, calculation
specifications which move the data from the record to the
array should also be performed. However, if. there are still
some array records which have not been processed (thus,
not stored in the array), calculations and output which reference the array must not be performed. For example, if
only five fields of data have been loaded into a 10-element
array, adding all elements of the array or printing all elements will certainly not provide the results you want.
Once the last array input record has been stored, any specifications referencing the array elements can be performed.
Thus, you must specify a conditioning indicator (columns
9 through 17 on Calculation sheet and columns 23 through
31 on Output sheet) which indicates When the last array
record has been processed.

RPG

IBM

Lines 02 through 13 of the Calculation sheet in Figure 9-53
are performed to move data from the six array input records (see Figure 9-50) into the array ARA. When the last
record is processed (record identifying indicator 06 on), the
two array operations on lines 16 and 17 can be performed
during that program cycle. Therefore, when record type 6
has been stored, indicator 33 is set on (Figure 9-53, line 14).
Indicator 33 (or any other indicator which is set on) can
then condition the XFOOT and SUB operations to be performed in a program cycle.
The record identifying indicator 06 was not specified to
condition the array operations, because 06 is on only for
the cycle inwhich the sixth array record is processed. Since
the array operations on lines 16 and 17 must be performed
in the following program cycles also (for example, if normal
data records follow the array records), they must be condi-'
tioned by an indicator which is on during the following
cycles. Once indicator 33 has been set on, it remains on '
through following program cycles, until set off (line 01)
when another group of array records are processed.

CALCULATION SPECIFICATIONS

Form GX21·9093
Printed in U.S.A.

International Business Machine Corpor.tion

1 2

Progra~

Date

Programmer

C

Indicators

r-~
E

5

Factor 1

Operation

0

Length ~

E

()

.~

()

z

z

6

9 10 "

12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 43 49 50 51 52

3

4

1
2

C

o

3

o
o

4
5

c
c
c

o

6

C

C

z

c

~1

01::.1

rtJlL
1211

~

01
(2;1

.. An "'1

A

A'C r"l12
An I~

121

~-

AD J'I~

....,~

VJ: IF ln~

M'" Vf J: lOB

o

7

C

8
9

c
c

1 0

C

N~~

A

Ann

11

C

N(i~

~

NQJb
Nrlb

AD,O

1 3

c
c

,.A

A [I""

1 2

ILj
l&.j

1 4

C

1 5

C*

1 6

c
c

,..,f'I VE F In ....

N~b

t"J ..... Vl~

N~I..

!2 ~i:.l

n

131~

l3B

An:O

AlA A~ 12.12

D

12~

AR ~,A
AIR lA, B
AIR AJ'r

~IRA

A
.B

Figure 9-53. Conditioning Operations Until All Array Data is Stored

:"

,.

'"
1c:.11 M14I.

~IRA 12.2

13l~

7~

Comments

54 55 56 57 5859 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

12~

ilia

~

XIF I_I ... irA IRIA
SI 113
l~

Compare

12rlJ

,..

11= L Inn

-;'E, "''-1'(

Plus IMinusl Zero
1>211<211z2
LookuplFactor 21is
High Low Equal

~3

~Ii!,-

o
o

9-50

0

Factor 2

&

o
o

1 7

Indicators
Arithmetic

Name
()

75 76 71 78 79 80

[DOf_ ~~~;~f:.tion I I I I I I I

Resulting

Result Field

,At Jd

8.

Line

Page

Figure 9-54 shows how the array operations must be conditioned for another situation. In this case, record identifying
indicator 06 does not set on indicator 33 because information (DSCNT) from data records following the array records
must be available before the array operations can be performed (line 16). If indicator 06 caused indicator 33 to be
set on, the array operations would be performed during the
program cycle in which the sixth array record is stored. At
that point, the DSCNT data is not available. Therefore, record identifying indicator 09 (the first type of data card following the array records) sets on the conditioning indicator
33 instead.

RPG

IBM

At this point, we must mention a problem which can come
up if array elements art;: contained on more than one record
(or the same record typ,e), and the records contain normal
input data as well as arr~y data. Assume t~~ee cards contain the array data and a~1 the data must be stored in the
array prior to performing\any calculation or output operations. This means the three records must be read before
processing. As each new record (of the same" record type)
is read, the data from the previous record is,.destroyed, unless it has been moved or stored in a special place, such as
an array. Since normal input data (nonarray fields) from
the first two records is no longer available once the third
record has been read,any calculation or,c>utPlJt specifications which reference this input data might give incorrect
results.

CALCULATION SPECIFICATIONS

Form GX21-9093
Printed in U.S.A.

International Business Machine Corporation

1
Program

Page

Date

Programmer

C
-

Indicators

Operation

Factor 1

~

'g

~

5

z

6

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

'0

'0

z

'0

~

z

o
o
o

1
2

C

~l

l- ~D 101

3

C

IZll

o
o

4
5

c
c

~- ~D In 2.
~- ~ID ID~
~- ~ID 11'l~

IA
IB
r
D

o

6

C

o
o
o

7
8

1M!"Iv IE. ,:/ [)A
Mh W~ FI iDe
MI~ Vf J: 11 ""r
Min VI=. I=IL ron

AIR 'AlA
A'RIA R
lAIR A)"
~IR Al'"'

~In'"

~Il

C

""'I~ II

~Il

rlll.

9

1 0

c

'I

IA

11

C

NI~~

.A

~IDn

L.f

B

1 2

c
c

NrJ.lh

r

L/

r

IN~I~

~ID'"

1 3

Ir"

lAID. D

1.1

'n

1 4

C

~fq

1 5

c~

1 6

cko'

1 7

C

1 8

C

2 0

INI~I~
IN~I,=
INWlI~

A

~IE:

",

I~I~
~

AR A} 212

....

"

....

09 set on by reading first data
record following array input records.

Plus IMinusl Zero
Compare

Comments

1>211<211m2
Lookup(Factor 2)is
High Low' Equal
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

12rl

\

~~
12~

1212

...
Move data
from input
record into
array
'-.-

I
\

I

.

-.
".

I

T"'tJ

~ R
lit ...

13[3

Arithmetic

38

J't"

c
c
c

1 9

~

&

4

----I

Length

E
'il

3

1 1 1 1 1 "I

Indicators

Factor 2
Name

75 76 77 78 79 80

Resulting

Result Field

Jd Jd

~

line

2

[DOf_ i~~;~~ationl

Ia.~
~

Nil"

it\IRA

~IR ~1 :2.[2

.... ~

5 MIAIlll

,

......

......

'-I

I

l

Field of data on the data records which follow
the array input records.

-,- -f-

I Figure 9-54. Conditioning Operations Until All Array Data is Stored and Input Data is Available

Arrays

9-51

,/

'--

9·52

Review 9

"\
)
1.

In which of the following ways is an array like a table (state true or false and the
reasons for your answer)?
a. Each can be referenced as one group of information.
b. Each is a continuous series of data fields (elements) stored side by side.
c. A particular item of data can be individually referenced in either a table or an
array.
d. Each is defined by coding extension specifications.

2.

Can one array be compared to another array to determine which is greater or less?
State the reason for your answer.

3.

Explain what happens if an array (a) of i8 elements is added to an array (b) of three
elements, with the result placed in an array (c) of 18 elements.

4.

The following array (ARASIX) is to be set up during a program run:

2

)

a.
b.
c.
d.
e.

72

5

20

15

Define the array on an Extension sheet.
If ARASIX is multiplied by 3, what data will be placed in the result array RESARA?
Should the result array RESARA be defined on the Extension sheet also?
If so, code the necessary extension specifications to define RESARA.
What is accomplished by defining an array on the Extension sheet?

5.

a. Explain what happens when an XFOOT operation is performed.
b. If ARASI X (refer to question 3) is specified on the Calculation sheet as Factor 2
of an XFOOT o'peration, what data would be placed in the result field?

6.

How does a programmer sp~cify that an entire array is to be printed or punched (a)
during output time in the object program cycle; (b) at end of job?

7.

How does a programmer specify whether an entire array or only a particular array
element is to be operated upon or used for output?

)
Review 9

9·53

~.

Data for a SALES array is recorded on a one·record input file called INF I LE in the,
following format:
/

Field

Columns

Field

Columns

Clerkl
Clerk2
Clerk3
Clerk4
Clerk5

1·10
11·20
21-30
31·40
41·50

Clerk6
Clerk7
Clerk8
Clerk9
record code

51·blJ

\,

61~70

71·80
81-90
91 (not array data)

Each of the clerk fields contains data with two decimal positions. Code the specifi·
cations necessary to:
a. Define the array as a pre-execution time array.
b. If necessary, describe the input record and store the data in the SALES array.
9.

Show two ways that data from the first five fields of the following record could be
stored in an execution time array named SET (15 elements, three numeric characters
each, no decimal positions). Column 1 of the record contains aP as the record
identifying code.

Field

Columns

Field

Columns

Fld1
Fld2
Fld3
Fld4
Fld5

2·4
6·8
1()'12
14-16
18-20

Fld6
Fld7
Fld8
Fld9
Fld10

22·24
26·28
30-32
34-36
38-40

Field
. Fld11
Fld12
Fld13
Fld14
Fld15

Columns
42·44
46-48
50-52
54-56
58-60

10.

a. Code the output specifications to print the 13th element of the array SET
(output filename PRINT).
b. Code the specifications to print the entire array SET at end of job (output
filename PRINT).

11.

SEARCH is the name of a field containing data you wish to locate in the 6-element
PAY array. Code the specifications to search the array to determine if the data is
present. If present, print the number and contents of the array element. If more
than one array element satisfies the search, each isto be printed.

12.

Code specifications to:
a. Add ARA 1 to ARA2 and place the result in ARA2.
b. Sum all elements of ARA2 and place the result in TOTAL.
c. Print both results.

c
9·54

Answers To Review 9

1.

a. False. Only one table element can be referenced at one time.
b. True.
c. True.
d. True.

2.

No .. An operation to be performed on an array is repeated for each element in the
array. Therefore, a compare (COMP) operation cannot give a meaningful result for
the entire array. The two arrays, however, could be totaled using the XFOOT
. operation and the resulting totals could be compared.

3.

The first three elements of array a would be added to the three elements of array b,
with the three results placed in the first three elements of array c. The remaining
15 elements of array c (result array) remain unchanged.

4.

a. Entries shown are required; no other entries should be made. The entry in
column 44 is necessary to indicate the elements are numeric for arithmetic
operations.
Extension Specifications

E

Record Sequence of the Chaining File

~

Line

4

5

6

Entries
Per
Record

From Filename

~
3

Table or
Array Name

To Filename

~
f-

)

Number
of

Number of the Chaining Field

7

8

Number
of
Entries
Per Table

Length
of
Entry

or~.rray

j~

~ ~ ~

~~j

Table or
Array Name
(Alternating
Format)

Length
of
Entry

.2

0

'g

~

0..

.,

Comments

ilJ

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2B 29 30 31 32 33 34 35 36 37 38 39 4041 42 4344 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

01 1 E I I 1111111 I I I I /I I 1/\ lolnlt! h- ~ II II~ I 12.
01 1 E I I LLI]J]] I I I I I I I 111J J JJ J 11 11
1

fl·

2

II II I I I
I] JJ J I I

LIII II I I 11111 -' -' 1
I I I I I II J ] J I I I I I I

b.
3

6

216

60

15

45

c. Yes, all arrays to be used in a program must be defined on the Extension sheet.
d. Entries shown are required; no other entries should be made. Length of array
element (columns 40-42) must be 3 to contain the largest addition result.
Extension Specifications

E

Record Sequence of the Chaining File

Number

:--

Number of the Chaining Field

Table or
Array Name

To Filename

Line

From Filename

3

4

oj 11

5

6

E

7

8

Number

Entries

of
Entries
Per Table

Per
Record

Length
of
Entry

orArr~y

c _
o Q

~~

:) ~ ~

~~j

Table or
Array Name
(Alternating
Format)

Length
of
Entry

.2 a
.~ ~

0..

0:: -

~ ·1

Comments

.,

"

i

0:0(1)

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2B 29 30 31 32 33 34 35 36 37 38 39 4041 42 43 44 45 46 47 48 49 50 51 5253 54 5556 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

l l It III II
I

)

of

I

I

I

I

I

1.1 ILL I I
I

I

I

I

I

I

I

RIEI5~IRlL1
I I I I
I

I I -' J Jb JJ3
I

I

I

I

I

I

I

I?J

II
II J II II
I I I I I

""""""""
I I "

I I ( I

I I I

I I I I I

e. An area in storage sufficient to contain the array data is reserved. The actual
array data may be stored in the array later, when input records are read or
during calculations.
Answers To Review 9

9-55

Page of GC21-7567-2
Issued 24 May 1976
By TNL: GN21-5389

5.

a. The XFOOT operation causes all elements in the array specified as Factor 2 to be
added together. The single result of the additions is placed in the result field
specified with the XFOOT operation.
b. The total of all elements in the ARASIX array (115) would be placed in the
result field.

6.

a. The name of the array is specified under Field Name (columns 32 through 37)
on the Output sheet. The filename (columns 7 through 14) mustalso be specified,
as for output of any field.
b. The name of the output file is specified under To Filename (columns 19-26) on
the Extension sheet. No entry is necessary on the Output sheet. (This method
of array output cannot be used for execution time arrays.)

7.

The array name is specified alone (on the Calculation or Output sheet) to reference
the entire array. The array name must be followed by a comma and an index
number or index field to reference only a particular array element.

8.

a. Extension specifications to define the array:

Extension Specifications

E

Record Sequence of the Chaining File
Number

f---

Number of the Chaining Field

Line

~

f-

From Filename

~
3

5

6

01 1 1

4

E

Table or
Array Name

To Filename

7

8

of
Entries
Per
Record

Number

of
Entries
Per Table

.2

Length

of
Entry

c

Table or
Length
Array Name of

.g

e

~

(Alternating
Formatl

"-

"
~

~~

:J ~

~~l

or Array

Entry

.~

:J ~

Comments

~

~~j

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 4344 45 46 4748495051 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

I I rlNIF II ILiEI I " I II I I
1

1

1

1

1

1

1

1

1

~141,

I

I

1

I~

Iclel
1

1

,2.
lL~
1

II A

1.1

I

I

I

1

1

111J I I I I I I I I I I I I

11 I J I II
1

1

1

I

1

1

1

I

1

I

I

1

I

I

1

1

1

1

1

1

1.1

1

b. Input specifications to describe the input record and store the data in the SALES'
array are not necessary, since the array is automatically loaded before execution
of the program.
9.

First method:

RPG

IBM

GX21,9094

INPUT SPECIFICATIONS
12

Program

Page

Date

Programmer

Record Identification Codes

I

~
0
2

8

o 1

II

o

2

I

o

3

I

o

4

I

o 5

I

o

6

I

o 7

I

0

il

Filename
Position

e ~~
~ r5

Position

~~
~u

Ii;

~

6

Position

CD

757677787980

of _

~~~;~f:ation I

Field location

f---

9-56

U/M 050·

Printed in U.S.A.

International Business Machine Corporation

~

0

N

~ U

Ii;
1:;

~

g~

'u;

'"

:::J

From

~

To

Field Name

~
'2

;a

cil Ii:

~
]

1

0

c:

I I /. / / /

Field
Indicators

0

''

~
:9-0
.!!'"ii
0

u.i.L

.~~

"fi :s

~o5

1
'0

Zero
Plus Minus or
Blank

0;

u:

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

'Nlp J1"

lAA

rL1i

L

I'P
12.

~

~f IT

"

IB

5.E' ITI) 2..

11~
1~

lils

1

l~ Sf: iTl.3
~E IT ~ l.l
2~ c::'E h"1,5

11"

"

Second method:

/

RPG

IBM

GX21·9094

INPUT SPECIFICATIONS

International Business Machine Corporation

1

2

75 76 77 78 79 80

Program

~Z~;~f:ation 1

pageDJOf_

Date

Programmer

Record Identification Codes

I

Filename

Line

1 1 I 1 I I

Field
Indicators

Field Location

t--Field Name

Zero

Co

....>

Position

Position

From·

Position

To

Plus Minus or

Blank

~
3

4

5

6

OIl

o

2

I

o

3

I

o

4

I

o

5

I

o

6

I

1

8

9

10 11 12 13 14 15 16 11 18 19 20 21 22 23 24 25 26 21 28 29 30 31 32 33 34 35 36 31 38 39 40 41 42 43 44 45 46 41 4B 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 61 68 69 10 71 72 13 74

r'Nlp~Jrr

~~FlIDl
J.lb~ F

'D14

2~/2F 015

IS
RPG

IBM

Form GX21-9093
Printed in U.S.A.

CALCULATION SPECIFICATIONS

International Business Machine Corporation

1

75 76 77 78 79 80

2

Program

C

Indicators

ci

2!_
...Ja:

~

:E !.

Factor 2
Name

Length ~ ~

g~

f-

E ::. '"

5

~85~

4

a
a

1

C

~1

2

C

(Zll

a

3

C

o
a

4

c

~L
(2.1

5

C

7

8

"-11

Comments

Lookup(Factor 2)is

High

Low Equal

rr ,!/

M" Iv~ I=t IDL
Mf'I ViE ~l In 2.

blf:

'M'n IVIE. F' 103
t\1'1"l ~IE F In "I
M'" [ViE 1=' n5

s~ IT» 3
s~ II.1.'1.I

s.e-rr 2
S:E. 1T}5

ao Output of 13th element of SET array:

10.

RPG

IBM

::::

c :x:

Arithmetic
Plu. IMinu.1 Zero
Compare
1>211<211-2

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 4B 49 50 51 52 53 54 55 56 51 5859 60 61 62 63 64 65 66 61 68 69 10 11 72 73 74

3

6

0;

15

Z

Z

,

SPECIFICATIONS

OUTPUT

Internationa,1 Business Machine Corporation

1 2·

75'7677 787980

o

u:: Space

-""
~ Qj e
i'l.-t5 ~~
~

Filename

line

~~

Ii"

o

R

r;-ND
1

5

6

0

2

0

3

0

7

8

Output Indicators

Skip

~~
c ~

I---

4

pageDJof_

Date

Programmer

3

GX21·9090· U/M 050'
. ,Printed in U.S.A.

Program

o
o
o

IIIIII

Indicators

c

Operation

Factor 1

~~~;~f:.tion I

Resulting

Result Field

At At

:::0

~~~
'0 a::

Line

Page D J of_

Date

Programmer

/

U/M 050·

Pnnted in U.S.A.

roo

Jd

e

~

~

0

z

0

z

L

-'"

Field Name

0

z

°AUTO

!ei

Ves
Ves
No
No

l[jj

~
~

Positon
in
Output
Record

Commas

Zero Balances
to Print
Ves
No
Ves
No

No Sign

CR
A

-

X

s

J

V

s

Z

~

8

K

C

L
M

0

~~~~;~f:ation I: I.

I 1I I I

Remove

Plus Sign
Oate
Field Edit
Zero
Suppress

a:

g

Constant or Edit Word

<>:

9 10 11 12 13 14 15 16 11 18 19 20 21 22 23 24 25 26 27 2B 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 474849 50 51 52 5354 65 56 57 5859 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

IPIRlr NIT

Answers To Review 9

9-57

b. Output of entire SET array at end of job since SET is an execution time array,
must be done using output specifications, as shown below:

OX2l -9090

SPECIFICATIONS

OUTPUT

RPG

IBM

1 2

75 78 77 78 79 80

Program
Page [ J J O f _

Programmer

-

O.t.

0

~ Space

~~
........
Filename

Line

0

.....

=.

:u

~

~

E

o

~

;

5 6

Field Name

11

<

III

-'"

Output Indicators

Skip

~ il

&'"
> ~ ~

j

A ~D

~

3 .4

U/M 050'

Printed In U.s.A.

Intern'tion,l Busin'ss Machin. Corporation

R

~«

C;

I

z

'AUTO

~NO

olp IRrr Nir

0 2

0

0 3

0

End

"0

in
Output
Record

28 29

Zero Balances
to Print
Ves
No
Ves
No

No Sign

CR

1

A

J

2

B

3
4

C

L

0

M

K

I. I I I II

X • Remove
Plus Sign
V· Oat.
Field Edit
Z • Zero
Suppress

a:

g

Constant or Edit Word

Q;

w

7 8 9 10 II 1213 14 15 16 17 18 1920 2122 2324 25 26 27

0 1

~,"

Commas
Ves
Ves
No
No

Positon

0

z0

z

....

(I

::;~f:tion I

30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 65 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

IR

T

rJl2.

5f'T

If SET were a compile time array or a pre~execution time array, output of the
entire array could be accomplished by entering the output filename in To Filename (columns 19-26) in the extension specification for the array:

RPG

IBM Int.rn'~iO"'1

FOO'm X21,9091

EXTENSION AND LINE COUNTER SPECIFICATIONS

Printed in U.S.A.

Business Machine Corpor.tion

1 2

Program
Programmer

Page [ J J O f _

Date

75 78 77 78 79 SO

~~~;~f:atiOn I

I I ,., I I

Extension Specifications

E

~ecord

Line

Sequence of the Chaining File
Number

I---

Number of the Chaining Field

To Filename

I!l

~

From Filename

~
3

4

5

6

7 8 9 10 "

0 1

Ef)f

o
o

2

E

3

Eift

0 4

E

0 5

E

9-58

Table or
Array Name

lr~

'If

of
Entries
Per
Record

Number

of
Entries
Per Table
or Array

Length
of
Entry

.20

~~

:§ ~ ~

~~l

Table or
Array Name
(Alternating
Format)

Length
of
Entry

~
a:

~

~

Comments

!l

j

12 13 14 15 16 17 18 t9 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 4041 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

11"l""

Tr IMI~.

!f;

""1(

plR IE- IE l( E.r
I!.JJH

IN

S:E. T'

[5

15

.3 tZ

N

5~rr

I.! I;

lit;

.~

Tr oN rTr M'E. :

rzl

11.

)
RPG

IBM

F.... G)(21·9OI3
Prlnt.d In U.S.A.

CALCULATION SPECIFICATIONS

International BUllntlS M.chine Corporation,.

1 2

75 78 77 78 7& 80

Program

C
t---

Indicators

~

'Oa:.-

~

85

E

Jd

~

en

7

8

~

1

C

2

C

o

3

C

o
o

4

C

5

C

~;3

o

6

C

12.8

o

7

C

,2.~

8

Length

:i8 g Plu. !Minu.! Zero

""

~

::!::

IAt.. !AT it\!
.-

l"'~ IIolf"ll:

1m

rx

z- IA'D lelL

sa

69 70 71 72 73 74

TIA~

hI< JIJ:l IpA:Y T't

~

~I~

~)C t"

rx

A nl"l 1I.
,.,..., M'p 11
(;f'I Tn lAr; 14tr N

rx
2.~

'f"IN

IN"" Ic~

..il--. ..

Ph"

IX
24

C

,.

RPG

IBM

OUTPUT

G)(21·8090 U/M 050"
Printed In U.S.A..

SPECIFICATIONS

International Business Machine Corporation

'1

Program

Page

Date

Programmer

)

Comments

Compare

; 1>2I1<2!1-2

~~ Lookup(Factor 2)is
u

b

b

o
o

n

Factor 2

Operation

Factor 1

Z
Z
C :z: High Low Equal
9 10 11 12 1314 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 36 39 40 41 42 4344 4S'..J<

line

, page[Oof_

Oato

Programmer

-0

iL: Space

Line

Filename

~~~~

~

I-

I-

]
3

4

o

1

o
o
o

2

0

3

0

4

0

5

6

Output Indicators

Skip

w:S

~ ~~-+---r--t----~I---~I--~
;:~at
,I
,I

o

R

Ui

And

Field Name

And

f,", il*
Positon

Commas

Ves
Ves
No
No

Zero Balances

to Print
Ves
No
Ves
No

2

75 78 77 78 79 80

[0 of_ ~~:~f:tion I I I I I I I

No Sign

x -=

CR
A

B
C

o

Remove

Plus Sign
J

V - Date

K

Field Edit
Z - Zero
Suppress

L
M

!

"A'Do ~ !<

Constant or Edit Word

0

Z

·AUTO

fAND
7

8

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 5J 54 55 56 57 58 59 60 61 62 63 64 65 66 67

0plRlr NT

sa

69 70 71 72 73 74

213

Irx

15
1714

)
Answers To Review 9

9·59

RPG

form aX21·t0S3
Prl.led I. U.s.A.

CALCULATION SPECIFICATIONS
1 2

Progrlm
Progrlmmer

C

~

Lin,

3 4

o
o
o

Dill

Indicator.

~

9l
it
!
1~

! dS j

is

8

1

C

2

C

3

C

IBM

7 8

. Qperation,

Factor 1

Jd

,1,

.' '~'; ~;" .. ,,"

!.

..

Length

.'

j

..,g:r
'Mlnul' Zero
. Compare
1-=.~ 1>2,1<2/1-2
PlUI

Factor 2·
Name

IIIIIII

Raulting
IndlCltorl
Arithmetic

Result Field
"

J

75 78 77 78 79 80

PIGI[DOf~ ::~"f~Cltlon

J;

Comment.

Lookup(Flctor 2111
High Low Equll

I to It 12 13 14 t& 18 17 18 II 20 21 22 23 24 2& 28 27 28 28 30 31 32 33 34 3& 31 37 31 31 40 41 42 43 44 4& 48 47 48 .1 eo &1 02&3 &4 && &1&7 &1&8 eo II 82 &3 &4 85 &I 87 &I

AR ~ll

~Db
iX.lto

GXUIOIO U/M oeo'
PrI.IOdI.U.S.A.

SPECIFICATIONS

\

Intern.cion" aUlineu Mechine Corpor.lion

1 2

Progrlm

0

@I
e ....

I---

Spa«

Output Indicators·

Skip

Filename

!
!

!i

Al

ell

~~ro

~!elt!

Name

And

0(

~ro~

*

1 '.l '"'"

t:d:

Line

[

! i

~

z

0(

.

"11

II

a:

~!

0
z,

'AUTO

1

Op Rt N~

~!

End
POllton
In
Output
'Record

2

0

o

3

0

o"

0

..

I"

A'R ~2
Tb rrAIL

.'
~

.;

'.,

'1,,:-

,9-60
.-.{ ,

:

'

"

...
":'

..

3 4 8 8 7 8 8 10 It 12 13 14 1& 18 17 18 18 2Ci 2t 22 21 24 2& 28 27 28 2820 31 32 33 34 '35 31 3' 3131 40 41 42 43

o
o

75 78 77 78 711 80

PIGI[DOf_

Da" .

Programmer

70 71 72 73 74

~~

M

OUTPUT

RPG

ee

ilR A,2

AIR All
IIH iHAI2

~~
cqLj

a:

::J

~

Co";mal

Zero aallncn
to Print

No Sign

CR

-

Vis
Va
No
No

Vn
No
Vn
No

1
2
3

;A

J

"

8
C
D

K
L
M

::::Cltlon

IIIIIII

X - Remove
PlulSlgn
V- Olte
Field Edit
Z - Zero
SupprHl

Constant or' Edit Word

444848~48~&oIIU2&3&4&1&187&1"eollU2&3&4"&l87eeee~

71 72 73 74

, Chapter 10. ~orki... With Data S"uet"r,

CHAPTER 10 DESCRIBES:
Representation of characters on cards.
Represent.ation of characters in storage (disk and inside the compu'ter) ..
Packed and binary data.
Collating sequence of characters.
Move zone operations.
File translation.

AFTER READING THIS CHAPTER· YOU SHOULD

B~

ABLE TO:

Describe the representation of characters and negative numbers on cards.
Describe the representation of characters on disk and in~ide the computer.

)

Define byte, bit, zone portion and digit portion.
Compare the storing of characters on cards to the stori~g of characters in storage.
Identify bit combinations with numerical values.
Assign numerical values to zone and digit portions.
Define unpacked decimal format, packed decimal format. and binary format.
Describe the hexadecimal numbering system.
Describe the collating sequence of characters.
Code specifications to change the collating sequence.
Alter the structure of characters in storage by using move zone operation~
Translate characters by coding the Translation Table ~n~ Alternate Collitin.. S~eet.
Note: You can use the review questions contained i., RlWitIW 10 al the end of this
chapter to test your comprehension of each topic in the chapter. Questions are
grouped according to the topic to which they apply. Answers follow the review
questions.

Working With

Da~a Structure

10-1

CHARACT'ER STRUCTURE" ,",

Since there are six punch positions available, the number
/'
and positions of the holes may be varied to form 64 different punch combinations. Each unique combination o f "
punches is associated with a particu lar character. Therefore, you can represent anyone of 64 different characters
in a card column (Figure 10-1).

Representation of Characters on 96-Column Cards
Punched cards provide data the computer is to work with.
Each of the 96 columns of a card can contain punches for a
single character. Therefore, up to 96 characters of information can be represented on a single record.

A card column consists of both a zone portion and a digit
portion. 8 and A are referred to as zone punch positions,
while 8,4,2, and 1 are digit punch positions. The combinations of zone and digit punches make it possible to
separate the characters into three groups (Figure 10-1):

Each column of a ~ar~ consists of six punch positions,'
labeled 8, A, 8, 4, 2, and 1, from the top of a column to
the bottom. Characters are represented by a combination
of from zero to six holes punched in the punch positions of
a single column.

•

Alphabetic letters are represented by at least one punch
in both the zone and digit portions of a column.

• The 28 special characters can consist of no punches,
only zone punches, only digit punches, or both zone
and digit punches.
o Positive numbers are represented by holes only in the
" digit punch po'sitions. The one exception is the number
which is represented by a single punch in the A zone
'punch position.

Numeric Characters

0
Zone

B
I--

A
;

8

Digit

o

' ,

A

Punch
Positions

1 2 3 4 5 6 7 8 9

~
~

2 2
1
1

r--,-

"'

"

4

4

8

B

4' 4

/

2 2
1
1

1

, "

Alphabetic Characters
A
Zone
Punch
Positions

Digit

B C D E

B B '8
A A A

B

t::
8
~
~

F G H I

J

B B B
A A A

B B B B
A A A

4

4

K L M N 0
B B

B B

P

-,-

1

2 2
1

4

1

2 2
1

x y

Z

A A A A A

A

8

8

R S T U V W

B B B B
A

8 8
4

a

A

8 8
4

1 1

2 2
1

4

4

4

1

2 2
1

4

1

2 2
1

4

4

4

1

2 2
1

1

:

Special Characters
~

Zone"

i I- ,

".,

B

B B

'A

A

"A A

f--

4

Digit

¢

~
8

Punch
Positions

. ,J'

B

;:

B B

A A

A

~

2 2
1

4 4

10-2

.'

I

$

B

B

B B

-, -

1

;

B

B B B

A

':'

I

4

2 2
1

A'A A

2 2
1

- >

A A

A

?

:

#

@

,

=

"

A

8 8 8 8 8 8 8 8 8 8 8 8

4 '4 :4
1

%

&

8 8' 8 8 8 8

4 '4

2 2
1
1

Figure 10-1. Character Set and Punch Combinations

.

I

8' :8 8i 8 8 8

f--

2
1

< (::

4

"

4

1

1

4, 4

4

2 2 2 2

2 2
1

1

1

4

4 4

2 2
1
1

~

CHARACTERS

Representa-don of Negative Numbers

)

I

Punch
Position

Note that positive numbers are represented only by digit
punches. Negative numbers (-1 through -9 and -0) can
also be represented to the computer. However, to indicate
that a number is negative, a column must contain both the
punch combination for the number and the punch combination for the minus sign. As column 7 of Figure 10-2
shows, the 8 and 1 digit-punch positions are punched to
represent the number 9. A -9 is represented in column 12
by the same digit punches plus a hole in the B zone-punch·
position.

B

A

8
4

•

'J' The RPG II program determines whether the punch com-

bination is a letter or a number according to whether an
entry has been made in column 52 of the input specifications. Column 52 is used to specify the number of decimal
positions in a field. If an entry is present, the RPG II program assumes any charaCter in that field to be numeric. Absence of an entry in column 52 tells the RPG II program
that it is reading either a letter or a special character in an

•

10 11

R

12 13 14 15 16 17 18 II 2021 U

:}

2
1

-8

-9

-0

• •
• • • •
• •
• •
•
•
•
•

•

IIIIIIIIII
K

L

M

N

o

P

Q

R

• • • • • • • • • •
•
• •
• • • •
• •
• •
•
•
•
•
•

Figure 10-3. Negative Number Punch Combinations the Same as
Punch Combinations for J-R

23 24 2526 27 28 29 3031 32

..

.....:

g~"UU~~~~~~ro~uu~nuvH»~~ne

e'
A

-7

Negative 9 Character
(Prints as "R")

Positive 9 Character

Digit Punches
Only for Positive
Number

-6

•

Punch
Position

itself, it can exist as a punch combination in the units
position ota data field.

8

-5

• • • • • • • • • •

2

7

-4

A

2

Note: Although the value -0 (negative zero) is not used by

9

-3

B

4

f

,

-2

8

As mentioned, all 64 possible punch combinations are associated with a character. Therefore, adding a B'zone punch
to the punch combination of a number means the punch
combination for any negative number is the same as the
punch combination already assigned to one of the 64 characters. The negative numbers -1 through -9 are represented
by the same punch combinations as the letters J through R;
-0 has the same punch combination as the special character

-1

"B" Punch for Minus Sign
Digit Punches for Number

A
8
4

8
4
2

2

~n~~H~U"~~«O"~«~«U~~~U~""~U"~~~""~
A

)

J

A

8

8

4

4

2

2

1

""~""Mnn»~nnnnn~~u"""""""~~U""""'
181013700

Figure 10-2. Punches for Negative Numbers
Working With Data Strudure

10-3

alphameric field. By examining column 52, the RPG II program recognizes when the 8 zone punch is associated with
the punch combination of one of the letters J through R or
the punch combination of a negative number.
In the discussion so far, you have learned how data is recorded in a form which the computer can understand. The
·data is represented as punched holes on 96-column cards.
Before the RPG II program can use the data, as in calculations or output operations, it must store the information.
The data is then available in computer storage whenever it
is needed during the run of a program.

Representation of Characters in Storage
When you look at the punch area of a card, you cannot
immediately determine which characters are stored on the
card. First, you have to determine which character is associated with a particular punch combination. The punched
holes, then, are the means of representing characters on a
card. Similarly, a character such as the letter A is not stored
on disk or inside the computer in a form you would recognize as the letter A. On disk or inside the computer, there
is also a means of representing characters.
Information from each of the 96 columns of punched cards
can be transferred to disk. Data from each column is stored
in corresponding positions on disk in the form of magnetized
spots.
Characters are represented electronically in computer storage.
The storage area of the computer consists of a number of
magnetic bits, which can be turned on or off by passing an
electric current through them. The exact details of how this
is done is not important to this discussion; what is important
is that each bit can be in either an on state or an off state.
We use a 1 to show a bit that is on; while a 0 represents a bit
that is off (Figure 10-4).

The magnetic bits inside the computer or on disk are arranged in groups, called bytes, just as the punch positions
on a card are arranged in groups called columns (Figure
10-4). Just as each column on a card can contain a character, each byte in storage can also contain a character. A
particular combination of on and off bits in a byte represent
a certain character inside the computer, just as a particular
combination of punched and unpunched positions in a column represent that character on a card.
Data is represented on a card, character by character; likewise, data is stored inside the computer, character by character. Just as you can look at a punched card and refer to a
character by the particular column containing that character's punch combination, the computer can reference a
character by the particular byte in storage which contains
that character's bit combination.

Difference Between Character Representation on Cards
and in Storage
Although there are many similarities in the way a character
is represented in storage and on a punched card, it is important to note one difference. While a card column consists of six positions, a byte consists of eight positions or
bits. Thus, within the computer, eight positions are used
to represent a single character, whereas only six positions
are available on a card.
A byte is divided into a zone portion and a digit portion,
just as a card column is (Figure 10-5). The four digit positions, in both a byte and a column, are labeled 1,2,4, and
8. However, a byte contains four zone positions, whereas
a card column contains only two zone positions.

"off" bit

\

o

1 0

1 100 1

101

jOn"bit

,

I

100 1 1

I

1 101

0

1 1 0

--------------- --------------- --------------Byte 1
(Containing Bit Combination
for a Single Character)

Byte 2

Figure 10-4. Representation of Characters in Storage

10-4

Byte 3

/

...N

.2 13 14 15 l' 17 'I "

2021 U

23 24 25 26 27 28 2S1 3031

32

•

Zone
Portion

c.'
~m~~~~~~~oom~~~~MmM~~~~mm~mmm

Digit
Portion

8

",
"

4

•

2

()

•

B
A
8

•
•

7

• • 10 II

12 13 ,4 1!Ii .. t7 ,I II 20 21 22232425262728293031 32

4
2
1
B
A

4
2
1
B

•

33 3.t 35 ,,. 37 3. 31 "0 4. U

43 .U 45 "

4' ... ott 50 51 !liZ 53 5.f 5S .56 57 !l8 !Ii 60 61 62 63 U

8
4
2
1
B

A

A

8
4
2

8
4
2

1

"MUM"~nnn~nn"»n~~~"u""v""W~n"H"ul
11"'3700

BYTE

8 4

2 1 8 4 2

1

~~

Zone
Portion

Digit
Portion

Figure 10-5. Correspondence Between a Byte and a Card Column

)
Working With Data Structure

10-5

Since there are four digit positions in botn a byte and a
card column, the digit portion of a byte corresponds onefor-one with the digit portion of that' character's punch
combination. That is, if a digit punch posit_ion is punched,
the corresponding digit bit is set on (1) in storage. Likewise a digit bit is set off (0) if the corresponding punch position does not contain a punch. To check this, note how the
digit portion of the plus sign (+) character is represented on
a card and in storage (Figure 10-6); (Note: Ampersand (&)
is an exception to this rule; see Figure 10-7.)
The zone portions of a card column and a byte do not correspond one-to-one, however. This is because there are four
zone bits in storage for each character, while there are only
two zone positions in a card column. Looking at Figure
10-6 again, you can see that even though A and 8 punch
positions contain punches for the plus sign character, the
2 and 1 zone bits in storage are not on.

Since the zone portions differ, a translation takes place
when a card is read and the data (characters) is stored inside
the computer. The machine reads the punch combination
on the card and electronically produces the appropriate bit
combinations in storage. Such translations (shown in Figure 10-7) are automatic; therefore, you need not becon~"
cerned with how the computer knows which bits to turn on
and off.
When programm ing in RPG II, however, you do have to be
concerned with zones and digits as they are represented'inside the computer.; The division of the' card column into
zone and digit portions is only for conv~nience.
On the Input sheet, you can specify record identification
codes. If you choose to use only the zone portion of a
character, you will be using the zone positions as they are
in storage. Assume that a record identification code with

1

2

3

..

+
5

6

7

1).9

.

10 11

12 13 ,. 15 16 17 18 19 2021 Z2 23 z.4 25 26 27 28 29 30 31 32

~~"~~mm~~~~~~Mm~~~MMmMMwm~mm~mm~

•

B

•
•
•

A
8
4
2

•

2

,
B

,

3"'7.'W"~n~~~n~~w~n"~UUvHHro~ll~

" .

A
8
4
2

. ,

n~~~n~»~~o~«~~nu~~~~~~"~n~~~~~~~

, , '

A

c,.

B
A
8

8
4
2

4
2
IBM 3700

• • • • •
Punch
Position

B

A

8

2

4

o

0

Column 5 of the card

'.1

o

Byte in Storage Containing Plus (+) Character

1
Bit
Position

--------------8

4'

2.

8

4

2

Zone
Portion

(
Figure 10-6. Similarity in Digit Portion of Byte and Card Column

10-6

\..

/

.......

)

Punch
Combination
Character

Zone

I

B A /S

Bit
Combination

Digit
4

2

1

-6

1
(period)

<
(

(I

+

I
&

I
$

*
)

;

-,
(minus)

)

I
,
%

-

(u nderscore)

>
?
:

#
@

,
(apostrophe)

=
"

Character

Zone

Digit

0100

0000

0100

1010

C

0100

1011

D

(blank)

••• •
••• ••
••••
•••• •
••••
••••••
•• •
• • •
• • ••
• ••
• •• •
• •••
• ••••
•
•
•
•• ••
•••
••• •
••••
•••••
• •
• ••
••
•• •
•••
••••

Punch
Combination

B
A

B

0100

1100

0100

1101

0100

1110

0100

1111

0101

0000

0101

1010

E

F

G
H

I
} or-O

0101

1011

0101

1100

0101

1101

0101

1110

0101

1111

0110

0000

J or-1
K or-2
L or-3
M or-4
Nor -5
Oor-6
P or-7

0110

0001

Qor-S

0110

1011

R or-9

0110

1100

S

0110

1101

T
U

0110

1110

V

0110

1111

W

0111

1010

X

0111.

1011

y

0111

1100

Z

0111

1101

+0

0111
0111

1110
1111

1
2

3
4
5
6
7
S
9

-""'
"
___)igure 10-7.

Zone

Bit
Combination.

Digit

Ais

4

2

1

••
••
•
••
••
•• •
•• • •
•• ••
•• •••
•••
•••
•
••
•
•
•
•
•
••
•
•
•
• •
••
•
•
•••
• •
• •
•
•
•
•
••
• •
• • •
• ••
• •••
••
••
•
•
•
•
••
0

•
•

0

••

•••
•
•
•

Zone

Digit

1100

0001

1100

0010

1100

0011

1100

0100

1100

0101

1100 .

0110

1100

0111

1100

1000

1100

1001

1101

0000

1101

0001

1101

0010

1101

0011

1101

0100

1101

0101

1101

0110

1101

0111

1101

1000

1101

1001

1110

0010

1110

0011

1110

0100

1110

0101

1110

0110

1110

0111

1110

1000

1110

1001

1111

0000

1111

0001

1111

0010

1111

0011

1111

0100

1111

0101

1111

0110

1111

0111

1111

1000

1111

1001

Bit and Punch Combinations for Characters

Working With Data Structure

10-7

the zone of a $ character in column 1 is to turn on resulting indicator 21. If an input record is read with the character J in column 1, indicator 21 will not turn on. Even
though the card zone punches for $ and J are the same (both
have the 8 zone punched), the bit combinations in storage
for the $ and J do not have identical zone portions (Figure
10-8).

ZONE PORTIONS OF CARD

ZONE PORTIONS IN STORAGE
Punch Combination for Character $

- - 9 7 9 8 991OO101102103IO1t07108anO 111 112"3 "" 115 115 117 118"9120 IZl12212312",251Z6127128

B.

-----rA

B
A

4

8
4

2

2

~'l3. "'8.~"n~u~.~~~ro~uU~~~V»Hro~n~
A

A

8
4

8
4

2

2

~»~~"""n~~tlu«~«~"U~~g~~""~""~~~n«~
A

A

8
4

8
4

2

2

1 e""""~nnn~~n"nn~~~"ue""""~~"""""1
IBM 3700

Figure 10-S. Difference in Zone Portions of a Byte and a Card Column
10-S

2

8

\

'.

''\
)

There are exceptions which should be noted in specifying
that the zones of characters be used to identify records.
According to Figure 10-9, the zone of the letter J is used
to identify record type 01, while the zone of a minus sign
is used to identify record type 02. Recorded on cards, both
characters have a B zone punch. However, inside the computer, their zone representations differ.

RPG

IBM
Program

Date

Programmer

I

c.

8

0

-c

j

J

....
i
& ~ 1
.8
~

Filename

!

.8421

Record Identification Codes

5

~

I--Line

EJoooo

INPUT ~

International Business Machine Corporation

c-I-c-§
z
0 R

Position

Position

Positiol

j

'A'No
3

0001

8421

Although the zones differ, the RPG II program considers
the two the same. Thus, a card with a minus punched might
turn on either the 01 or 02 indicator. Likewise, a card with
. the letter J could turn on either indicator.

4

o

1

o

2

5

6

7

8

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 2526 27 28 29 30 31 32 33 34 35 36 37

11= Til IF;A
1i¥

lAA

~'1

R~

I~.J

ISR

~2.

A(l

iZ-

o

3

I

o

4

I

Figure 10-9. Exception: Zone Representation Considered the Same

Similarly, the zone of the character blank is treated the
same as the zone of 0 through 9. Also, the zone of &
(ampersand) is treated the same as the zones of the letters
A through I. To avoid confusion, you should not specify
both (zones of the characters J and -; blank and 0-9; & and
A-I) for identification of record types which are to be used
in the same program.
'"\

)

Figure 10-1 0 shows the groups of characters that have
zones that test as equal for purposes of record identification and the TESTZ operation. Notice that these groupings are different from the groupings of characters for
purposes of collating sequence by zone (Figure 10-28).

)
Working With Data Structure

10-9

Character

Bit
Combination
Zone

4

Digit

0100

1010

0100

1011

Collating
Sequence
of
Zones

Bit
Combination
Zone

Digit

0110

0000

·1101

0000

1101

0001

}

<

0100

1100

(

0100

1101

K or-2

1101

0010

1101

0011

1

J or-1

,

0100

1110

L or-3

0100

1111

M or-4

1101

0100

I

0101

1010

N or-5

1101

0101

$

0101

1011

o or-6

1101

0110

P or-7

1101

·0111

1101

1000

+

*

0101

1100

)

0101

1101

Qor-8

;

0101

,110

R or-9

1101

1001
0010

2

-,

0101

1111

S

1110

I

0110

0001

T

1110

0011

,

0110

1011

U

1110

0100

%

0110

1100

(underscore)

0110

V

1110

0101

1101

W

1110

0110

1110

0111

1110

1000

3

>

0110

1110

X
y

?

0110

1111

Z

1110

1001

:

0111

1010

0100

0000

#

0111

1011

b
(blank)

@

+0
0111

1111

0000

1100

1

1111

0001

2

1111

0010

,

0111

Collating
Sequence
of Zones

(minus)

(period)

4

6

7

(

1101

(apostrophe)

=

0111

1110

3

1111

0011

"

0111

1111

4

1111

0100

5

1111

0101

6

1111

0110

7

1111

0111

8

1111

1000

9

1111

1001

&

0101

0000

A

1100

0001

B

1100

0010

C

1100

0011

D

1100

0100

E

1100

0101

F

1100

0110

G

1100

0111

H

1100

1000

I

1100

1001

5

Figure 10-10.Character Groups With Zones that Test as Equal for
Record 10 and TESTZ

10-10

Character

8

Page of GC21-7567-2
Issued 24 May 1976
By TNL: GN21-5389

Consider another example which points out the difference
in how negative numbers are stored and how you may think
they are stored. The minus sign alone is represented ~n a
card and in storage as shown in Figure 10-11, insert A.
Only the zone portion of the card contains a punch. Figure 10-11, insert a, shows how a positive 5 is represented
on a card and in storage. In this case, only the digit portion
of the card contains punches. Note Figure 10-11, insert C,
for the punch and bit combinations which represent a -5.

)

When checking the cards you can see that the digit punches
for the positive ~ and the negative 5 are the same. Furthermore, the digit bits in storage for the two characters are also
the same. The zone punch for -5 is the same as the zone
punch for the minus sign character. However, the zone bits
in storage for the two characters are not the same. Therefore, you should not always assume that in storage, the
zone bits for a negative number would be identical to the
zone bits for the minus sign (Figure 10-11).
The reason is that the computer checks the entire punch
combination (both zone and digit portions) of a column to
determine which zone bits are to be on or off. Since the
entire punch combinations (not only zone punches) for the
minus character and the negative 5 are different, their zone
bits in storage are also different.

/

A conclusion can be drawn from the previous examples:
each unique punch combination is associated with a different bit combination. Of course, in discussing negative
numbers before, we stated that the punch combinations of
-1 through -9 and -0 are the same as the punches for the
letters J through R and ~ . Thus, the bit combinations
for the negative numbers are also the same as those for J
through R.
Consider again the number of positions available to represent a character. A characteristic of codes involving different
combinations (such as bits on and off or punches) is that the
greater the number of positions available to represent any
one combination, the greater the number of combinations
that are possible. As mentioned, with six pun~h positions,
64 unique punch combinations can be made, and, therefore,
64 different characters can be represented on a card. With
eight bits (positions), 256 unique combinations of on-off
bits can be created and, therefore, 256 different characters
could be represented inside the computer. However, you
only need 64 characters to program the computer; therefore, only 64 of its 256 bit combinations are associated with
a printable character.

I

Working With Data Structure

10-11

Representation of "5" Character (Positive)

Representation of Minus (-) Character

~."m~mm~~um~~~m~MMM~mMM~m~~~~m~~

B .

B

A

A

8
4
2

B
4
2

1
B
A
8
4
2

o

5'7 ••

B
A
B

4

2

2
5'7 ••

~:~u~~wn~~~~UnNnHV"H~~U~

A

A
8
4
2

A

B

B

4

4

~

~n~"»»HH~~UU«~"U"U~~~"~""»""~~~""~

B
A
B

4 ·

~'230

~u~u~~wn~~W~UnNnHV"H~~U~

A

~."m~mm~~~m~~~mmMMM~mMM~m~~~~m~~

~

.'

Bn~"u»»H~~UU«~"U""~~~"~""»""~~H"«B

A

A
B

A
B

8

8

4

4

4

4

2

2

2

2

1 "NVA"~nnn~n~nHn~~U"Nn"V""~~H"«R"1

1"NVA"~nnn~n~nnn~~U"M""V""~~H""""1

JIM 3700

JIM 3700

BIT

8

o

o

o

8

4

2

o

o
4

2

o

o·
8

®

2

4

8

o
4

2

Representation of "-5" Character (Negative)

,

2

3

..

5

•

7

•

•

N

to· 11

12 13 "

15 11 17 'I ,. 20 ZI Z2 23 Z4 2! 21 27 28 2t 30 31 32

'....

~."m~mm~~um~~~mmMMM~mMM~m~~~~m~~

B .

B

A
B

A
B

4 .

4

2

2

1 .
1
B' 230 5 ' 7 • • ~u~u~~wn~~~~UnNnHV"H~~UB

A

A
8

B
4

4
2

2

~n~"»»HH~~UU«~"U"U~~~"~""»~"~~H""~
A

A

B

8

4

4

2

2

1 "NVA"ronnn~~~nnn~~U"M""V""~~H"«n"1
JIM 3700

@

BIT

8

Figure 10-11. Representation of a Negative Number

10-12

4

o

!o

2

8

o
4

Identifying Bit Combinations with Numerical Values.

F

Each unique combination of eight bits can be associated
with a numerical value. Before discussing how the numerical
value is determined for a character, perhaps first you would
like to know why numerical values are assigned.
As mentioned before, data can be represented on punched
cards. Actually, after reading a card, the computer does not
immediately determine what character is punched. It can,
however, distinguish one punch combination from another
punch combination. Furthermore, the particular combination of punches indicates to the computer which bits should
be set on and off to represent that punch combination inside the machine. At this point, the representation on the
card is just a particular group of punches and the representation in storage is merely a particular combination of on and
off bits.

A

A

8
4

8
4

2

2

~nunHnH»~~UU«~U~UU~~U~~"~~9"~~U"«~
A

A

8

8

4

4

2

2

1

eMvg"ronnnunnnnn~~uuN""uun~~"""""l
111013700

\

One Byte in Storage

To use the byte of data for output, the computer must
know what character to punch or prjnt. This is done by
associating a numerical value with each unique bit combination. The computer automatically knows that a certain
value is related to a particular character, such as the value
209 indicates the character J.
Consider how a numerical value and how the character are
determined. Each of the eight bits in a byte are assigned a
number. The values begin with 1 for the 1 bit and are
doubled for each of the next bits (Figure 10-12). By adding.only the numbers which correspond to bits which are
on (1), anumerical value is obtained for a byte. As Figure
10-12 shows, first the punch combination (for the character F) in column 7 is translated into the bit combination in
storage. The bits on result in a numerical value of 198,
which the computer associates with the character F.

------------------~.
BIT
Numerical
Value
Assigned

o

o

o

8

4

2

1

8

128

64

32

16

8

t t t t

Add Value of
Bits That Are On

128 + 64

t

---o
4

1

2

t t t

4

2

+4+2

198

NUMERICAL VALUE 198 = F CHARACTER

Figure 10-12. Determining a Numerical Value for a Character

Any difference in the bit combination results in a difference in numerical value. Therefore, every character is associated with a different numerical value. The greatest
numerical value which can be associated with a bit combination is 255 (all eight bits on), while the lowest numerical
value is 0 (all eight bits off). This results in a total of 256
possible numerical values. Only 64 different characters can
be represented on a 96 column card; therefore, we are concerned with only 64 of the different numerical values. However, as Figure 10-13 shows, the 64 numerical values associated with the characters can range anywhere from 0 through
255. The numerical values missing from the chart are not
related to any printable character.

Working With Data Structure

10-13

Page of GC21-7567-2
Issued 24 May 1976
By TNL: GN21-5389
Bit
Combination

I

00000000
00000001
00000010
00000011
00000100
00000101
00000110
00000111
00001000
00001001
00001010
00001011
00001100
00001101
00001110
00001111
00010000
00010001
00010010
00010011
00010100
00010101
00010110
00010111
00011000
00011001
00011010
00011011
00011100
00011101
00011110
00011111
00100000
00100001
00100010
00100011
00100100
00100101
00100110
00100111
00101000
00101001
00101010
00101011
00101100
00101101
00101110
00101111
00110000
00110001
00110010

Numerical
Value
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

Character

-

,

46

47
48
49
50

Bit
Combination
00110011
00110100
00110101
00110110
00110111
00111000
00111001
00111010
00111011
00111100
00111101
00111110
00111111
01000000
01000001
01000010
01000011
01000100
01000101
01000110
01000111
01001000
01001001
01001010
01001011
01001100
01001101
01001110
01001111
01010000
01010001
01010010
01010011
01010100
01010101
01010110
01010111
01011000
01011001'
01011010
01011011
01011100
01011101
01011110
01011111
01100000
01100001
01100010
01100011
01100100
01100101

Numerical
Value

Character

51
52
53
54
55

/

"

56

57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
72
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

Blank

~

<
(

+
I
&

I
$

*
)

;

-,

I

.'

Figure 10-13 (Part 1 of 3). Numerical Values Associated with Characters

~­

/

10-14

Bit
Combination

)

I

01100110
01100111
01101000
01101001
01101010
01101011
01101100
01101101
01101110
01101111
01110000
01110001
01110010
01110011
01110100
01110101
01110110
01110111
01111000
01111001
01111010
01111011
01111100
01111101
01111110
01111111
10000000
10000001
10000010
10000011
10000100
10000101
10000110
10000111
10001000
10001001
10001010
10001011
10001100
10001101
10001110
10001111
10010000
10010001
10010010
10010011
10010100
10010101
10010110
10010111
10011000

Numerical
Value
102
103
104
105
. 106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
.122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152

Character

,
%

-

>
?

:

#
@

,

=
"

Bit
Combination

Numerical
Value

10011001
10011010
10011011
10011100
10011101
1001111 0
10011111
10100000
10100001 .
10100010
10100011
10100100
10100101
10100110
10100111
10101000
10101001
10101010
10101011
10101100
10101101
10101110
10101111
10110000
10110001
10110010
10110011
10110100
10110101
10110110
10110111
10111000
10111001
10111010
10111011
10111100
10111101
10111110
10111111
11000000
11000001
11000010
11000011
11000100
11000101
11000110
11000111
11001000
11001001
11001010
11001011

153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
. 182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203

Character

-",

A
B
C
D
E

F
G
H

I

Figure 10-13 (Part 2 of 3). Numerical Values Associated with Characters

)
Working With Data Structure

10-15

Bit
Combination
11001100
11001101
11001110
11001111
11010000
11010001
11010010
11010011
11010100
11010101
11010110
11010111
11011000
11011001
11011010
11011011
11011100
11011101
11011110
11011111
11100000
11100001
11100010
11100011
11100100
11100101
11100110
11100111
11101000
11101001
11101010
11101011
11101100
11101101
11101110
11101111
11110000
11110001
11110010
11110011
11110100
11110101
11110110
11110111
11111000
11111001
11111010
11111011
11111100
11111101
11111110
11111111

Numerical
. Value
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226 .
227
228
229
230
231
232
233,
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255

Assigning Numerical Values to Zone and Digit Portions
Character .

( or-O
J or-1
K or-2
L or-3
M or-4
N or-5
o or-6
P or-7
Qor-8
R or-9

You have seen how a single numerical value is determined
for a combination of eight bits. The numerical value of a .
character in storage can also be expressed as a pair of numbers, rather than a single value. One number designates
the value of only the four zone .bits; the other number
represents the value of the four digit bits.

I
I,

/"

\,-

You may be wondering why a character would ever be associated with two paired numbers, since it can be associated with just a single number. In certain jobs, you may
be concerned with only the digit po~tion or only the zone,
portion of a character. For example, if records within a
group are to be sequence checked only on the basis of the
zone of a character, the computer must look at only the
zone bits and determine a numerical value for the zone portion alone in order to make the comparison. Also, if you
want to alter the collating sequence or translate a file, both
to be discussed later, you must know the separate values
for the zone and digit portions of a character.

5
T
U
V
W
X
Y
Z

0
1
2
3
4
5
6
7
8
9

Determining separate zone and digit values is similar to determining a single value for an entire bit combination; that
is, values are assigned to each of the bit positions. The
values which correspond to on bits (1) are then added to
obtain a value.
(

To determine separate values, the zone and digit portions
are each treated as separate 4-bit combinations. The four
bits in each portion are assigned the values 1,2,4, and 8
(Figure 10-14), The rightmost zone and digit bits each have
the value 1; while the leftmost bits in each portion are assigned the value 8. A value for the zone portion of a byte
is determined by adding only the values corresponding to
zone bits which are on (1). Likewise, a digit value is obtained by considering only digit bits which are on.

Zone

o
Bit

Figure 10-13 (Part 3 of 3). Numerical Values Associated with Characters

Assigned
Value

8

8

(",

Digit

o

o

0

4

2

842

4

2

8

4

2

Figure 10-14. Assigning Values for Zone and Digit Portions of a
Character

(
10-16

)

As Figure 10-15, insert A, shows, the bit combination for
the slash (/) character produces a zone value of 6 and a digit
value of 1. Putting the two values together, the entire character can be expressed as the value 61. Note, however, that
this is not the same as the numerical value 61 in our decimal
numbering system. If we were to determine a numerical
value for the entire a-bit combination, we would obtain the
value 97 (Figure 10-15, insert B).
As mentioned before, with eight bits or positions in a byte,
256 different a-bit combinations can be formed. The 256
combinations can be associated with the numerical values
0-255 (Figure 10-16, insert A). If either the zone or digit
portion are considered separately, however, only four bits
or positions are available. Therefore, a maximum of 16 different 4-bit combinations can be represented in either the
zone or digit portion of a byte. The 16 zone or digit combinations can be associated with the values 0 through 15
(Figure 10-16, insert B).

values (0-15). Putting the two hexadecimal numbers for
the zone and digit portions together gives a hexadecimal
value for the entire character. 61 is the hexadecimal value
for the / character. Keep in mind that this hexadecimal
value is actually two separate values, one for the zone and
one for the digit portion.
All of the 256 possible a-bit combinations can be represented by a hexadecimal value; that is, two hexadecimal
numbers. However, each hexadecimal number can take up
only one position. If a zone portion has the value 15 and
a digit portion has the value 12, the hexadecimal value for
the character cannot be expressed as 1512. Consequently,
a zone or digit portion whose numerical value is 10 or
greater (2-position number) must be represented in a slightly different form. This is done by assigning a single letter
as a substitute for the number. The letters A through F
serve as the hexadecimal forms of the values 10 through 15
as shown in Figure 10-17.

The value obtained for a zone or digit bit combination is
referred to as hexadecimal number. Hex means 6, while
decimal referes to 10. Hexadecimal, then, means 6 + 10, or
16. A hexadecimal number can be anyone of 16 possible
DETERMINING NUMERICAL VALUE FOR ENTIRE BYTE

)

VALUE BY ZONE AND DIGIT
Digit

Zone

Bit Combination
for" /" Character

0

Bit

8

Values For
"ON" Bits

@

0
4

2

Bit

0

0

0

8

4

2

4 + 2

Zone Value

Value Assigned
To Bit
Maximum
Numerical
Value
+ 1

6

Digit Value

8

4

2

128 64 32

16

128 + 64 + 32 + 16

+

8

4

2

8

4

2

8 + 4 + 2 + 1

=

255

®
DETERMINING NUMERICAL VALUE FOR ZONE OR DIGIT
DIGIT

ZONE
VALUE FOR ENTIRE BIT COMBINATION
Bit Combination
For"I" Character
Bit
Values For
"ON" Bits

®
)

o
8

o
4

2

64 + 32

Value

o

0

0

Bit

8

4

2

8

4

2

8

4

2

Value Assigned
To Bit

8

4

2

8

4

2

+ 1

97

Figure 10-15. Difference in Value of Entire Character and Value
of Zone and Digit Portions of Character

8+4+2+ 1 = 15
Maximum Numerical
Value For Zone Bits

8 + 4 + 2 + 1 = 15
Maximum Numerical
Value For Digit Bits

Figure 10-16. Maximum Values for Entire Character and for Zone
and Digit Portions

Working With Data Structure

10-17

Character
Decimal
Number
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

Hexadecimal
Value
0
2
3
4
5
6
7

8
9
A
8
C
D
E
F

81ank
c

.

<
(

+
I
&

I
$

*
)

;

"1

I

,
%

-

Figure 10-17. Hexadecimal Values of Numbers 0-15

>
7
:

An 8-bit combination with a zone value of 15 and a digit
value of 12 is expressed as having a hexadecimal value of
FC. Because the complete numbering series is composed
of numbers 0 through 9 followed by letters A through F,
a hexadecimal value for the zone and digit portion of an
8-bit combination can appear as a pair of numbers (61), a
letter and a number (C4, 4F), or a pair of letters (DB).
Since zone and digit values are determined separately, a
single combination of eight bits can have the same hexadecimal number for both the zone and digit portion. Thus,
11, 22, 33, AA, and other such values represent 8-bit combinations which have the same bits on in both their zone
and digit portions.
Entirely different 8-bit combinations can have identical
zone hexadecimal numbers or identical digit hexadecimal
numbers, but not both. That is, the zone portion of one
character can contain the same bits on and off as the zone
portion of another character. In such a case, the identical
zone bit combinations would give identical zone hexadecimal values. However, if they are different characters
and the zone values are identical, the digit bits and, thus,
the digit values, must differ. This is because no two characters can have the same 8-bit combination.

#
@
,

=
"
A
8
C
D
E
F
G

H
I

} or-O
J or-1

K or-2
L or-3
M or-4

N or-5

o or-6
P or,-7
Qor-8
R or-9
S
T
U

V
W

X
y
Z

Figure 10-18 shows the hexadecimal values associated with
the 64 printable characters the computer recognizes. The
hexadecimal values are in sequence just as the regular numerical values are. Furthermore, the hexadecimal value associated with a character is equivalent to the numerical
value associated with that character. However, there is no
need for you to be able to translate back and forth between
numerical values and hexadecimal values. If you must use
a character's hexadecimal vlaue in your programming, you
can refer to the chart showing the appropriate value.
10-18

0
1
2
3
4
5
6
7
8
9

Hexadecimal
Value
40
4A
48
4C
4D
4E
4F
50
5A
58
5C
5D
5E
5F
60
61
68
6C
6D
6E
6F
7A
78
7C
7D
7E
7F
C1
C2
C3
C4
C5
C6
C7
C8
C9
DO
D1
D2
D3
D4
D5
06
07
08
09
E2
E3
E4
E5
E6
E7
E8
E9
FO
F1
F2
F3
F4
F5
F6
F7
F8
F9

Numerical
Value
64
74
~5

I

!,

76
77
78
79
80
90
91
92
93
94
95
96
97
107
108
109
110
111
122
123
124
125
126
127
193
194
195
196
197
198
199
200
201
208
209
210
211
212
213
214
215
216
217
226
227
228
229
230
231
232
233
240
241
242
243
244
245
246
247
248
249

Figure 10-18. Hexadecimal Values Associated with Characters

(

(

Saving'Disk Storage Space

)

As you have learned, each byte of storage, whether on disk
or in the computer, can contain one character. That character can be a decimal number or an alphabetic or special
character. The format of the characters is known as un- ,
packed decimal format. Each byte of storage is divided into
a 4-bit zone and a 4-bit digit part. Figure 10-19 shows the
unpacked decimal format.
The zone part of the low-order (rightmost) byte indicates
whether the decimal number is positive or negative. In unpacked decimal format, the zone part is included for each
digit in a decimal number; however, only the zone over the
low-order digit serves as the sign. The low-order digit is the
only digit which makes use of the zone portion. Figure
10-20 shows the unpacked decimal format for decimal number 9,269.

The sign part of the low-order byte is used to indicate
whether the numeric value represented in the digit parts is
positive or negative. Compare how the decimal number
9,269 is represented in packed decimal format (Figure
10-22) with its unpacked representation (Figure 10-20).

o - - - - - - -...~~
Digit

Digit

Digit

Sign

Figure 10-21. Packed Decimal Format

Positive
Sign

Packed Decimal Format

)

7 0 -----------~~~ 7

In packed decimal format means that one byte of storage
can contain two decimal numbers. A decimal number will
occupy the zone portion which is unused in unpacked decimal format; This format allows you to put almost twice as
much data into a byte as you can using the unpacked decimal format.

_-------3 Bytes--------

'Figure 10-22. Packed Format of Decimal Number 9,269

'The low-order byte in packed decimal format is also divided
into two 4-bit parts. Each byte, except the low-order byte,
contains one decimal digit in each A-bit part. The low-order
byte contains a decimal digit in the leftmost 4-bit part (bits
0-3) and the sign of the decimal field in the rightmost 4-bit
part (bits 4-7). Figure 10-21 shows packed decimal format.

o----...~~7'0 - - -.....~7'O ----1.... 7'0 - - -.....~7'O

.. 7

1101
1111

= Minus sign
= PI us sign

Figure 10-19. Unpacked Decimal Format

Zone

Zone

Zone

Positive
Sign

- - - - - - - - - - - 4 Bytes - - - - - - - - - - -

Figure 10-20. Unpacked Format of Decimal Number 9,269
Working With Data Structure

1O~ 19

You can specify packed input, output, table, or array fields:
•

Packed input fields. Enter a P in column 43 of the Input
sheet. This causes the data to be unpacked before it is
stored.

•

Packed output fields. Enter a P in column 44 of the
Output-Format sheet. This causes the data to be packed
before it is written out.

•

Packed table or array fields. Enter a P in column 43 and/
or 55 of the Extension sheet. The data will be unpacked
before it is stored. Packed tables or arrays are allowed
only at pre-execution time.

Since data must be represented in unpacked decimal format
once it is inside the computer, you must give the RPG program an indication when input fields are in a different format.
Because data must be represented in unpacked decimal format before It can be processed, unpacked decimal fields
may be stored on disk to eliminate converting the fields
from packed to unpacked format during input. However,
storing unpacked fields on disk requires more space than
storing packed fields.

Each two-byte binary field consists of a sign bit followed
by a 15-bit numeric value. This value can be as large as
9,999. When a two-byte binary field from disk storage is
read into the computer, the RPG II program converts it to
a four-byte unpacked decimal field. Figure 10-23 shows a
two-byte field in binary format.

o

1- -

-

-- -

-

-

-15

I~ I
Figure 10-23. Two-Byte Field in Binary Format

Each four byte binary field consists of a sign bit followed
by a 31-bit numeric value. This value can be as large as
999,999,999. When a four-byte binary field from disk
storage is read into the computer, the RPG II program converts it to a nine-byte unpacked decimal field. A four-byte
binary field is shown in Figure 10-24.

o

1-

I~ I

-

-

-

I

-

-

-

-

NU~ber

-

-

-

31

I

I

Binary Format
Figure 10-24. Four-Byte Field in Binary Format

You can save even more disk space than in packed decimal
format by storing numeric data in binary format. In binary
format, each numeric field on disk must be either two or
four bytes long. Each two-byte binary field can contain a
value equivalent to four decimal places; each four-byte
binary field can contain a value equivalent to nine decimal
places. In other words, a numeric value in binary format
occupies approximately half as many bytes of disk storage
as the equivalent value in unpacked decimal format.

In each case, the sign portion of the high-order byte (leftmost) is used to indicate whether the numeric value is
positive or negative. Notice that in the binary format the
zone portion of the decimal number is not given. Compare
how the decimal number 9,269 is represented in binary
format (Figure 10-25) with its packed and unpacked representation (Figure 10-20 and 10-22).

Positive
Sign

o : 8192

o
*

o

: 4096 : 2048 : 1024 : 512

o

o

o

128

64

o

o

o

32

16

8

o

4

2

o

The numeric value for each binary byte is obtained by adding the numbers which correspond to the bits that are on.
(Bits that are on are represented as 1 's.) The sign bit is not included in the value of the number. The bit to the right
of the sign bit is always 0, because the maximum value of a two-byte binary field is 9,999.

Figure 10-25. Binary Format of Decimal Number 9,269

10-20

256

= 9,269*

Since data must be represented in unpacked decimal format w~en it is inside the computer, you must indicate to
the RPG II program when fields are in another format.
You can specify binary input, output, table, or array fields:
•

Binary input fielc!s. Enter a B in column 43 of the Input
sheet. The data is then converted into decimal before it
is stored.

•

Binary output fields. Enter a B in column 44 of the
Output-Format sheet. The data is then converted into
binary before it is stored.

•

Binary table or array fields. Enter a B in column 43
and/or 55 of the Extension sheet. The data will be converted to decimal before it is stored. Binary tables or
arrays are allowed only' at pre-execution time.

To further point out the need for a set order of characters,
assume the computer must check to make sure records in a
file are in proper order according to a department field.
Some department codes are alphabetic, as department A;
while some department codes are numbers, such as department 8. Should the numeric department records appear before the alphabetic department records, or vice versa? It is
likely that the answer would depend on who is asked. However, for efficient data processing, you certainly do not want
records sorted one way one time and another way the next
time. Thus, the computer must use one set order of characters.
Every character recognized by the computer must hold a
certain position in this order in relation to the position of
the rest of the characters. Such an order is referred to as a
collating sequence of characters. By definition, to collate
means to arrange or verify that data appears in proper order
or sequence.

COLLATING SEQUENCE OF CHARACTERS

To perform data processing applications efficiently, you
usually organize your information in some order or sequence.
Imagine trying to locate a person's phone number if the
names in a telephone book were not in alphabetical order.
Of course, before using this order or sequence, you must
know what it is. Through the learning process, you know
that alphabetical order means that A comes before B, B
before C, and so on. Likewise, in numerical sequence, 1 is
less than 2,2 less than 3, and so on.
In most of your data processing applications, the computer
must be able to recognize an order or sequence of data. For
example, if you instruct the computer to sequence check a
file according to an alphabetic department code on each
record, it must be able to determine if the department T
record should appear before the department X record, or
vice versa. I n another instruction, perhaps the computer is
to compare two quantities, such as 3 and 8, and turn on an
indicator if the first quantity is less than the second quantity. The computer must determine if 3 is less than 8 or if
8 is less than 3.
The previous two tasks would be easy for you to perform
because, through memorization or habit, you know the
natural order of the alphabetic characters A through Z and
the numbers 0 through 9. However, a computer has not
memorized such orders. For the computer to perform these
tasks, an order or sequence of characters must be esta~lished.

There can be any number of collating sequences. The sequence used depends on the particula'r order in which characters are to be recognized. In any case, the computer
should use only one collating sequence at a time.
The standard collating sequence of 64 characters is shown
in Figure 1,0-26. The blank, which is the first character, is
considered as the lowest in, the sequence while the number
9, the last character, is the highest in the sequence. Note
that all of the special characters, except the
(brace), are
first in this sequence, followed by the alphabetic characters
A through Z in their natural order, and then the numbers 0
through 9 in their natural order. The only character which
you might not expect to be in its position is the } which
comes between the letters I and J.

f

This collating sequence is the order used by the computer
for the purpose of sorting cards, comparing numbers to determine which is greater or less, checking the sequence of
records in a file, and matching records from two files to de~
termine which record should be processed next. According
to the collating sequence, the computer compares two characters to determine if one comes before or after the other,
or is less than or greater than the other.. Of course, you
specify which characters (or fields of characters) are to be
compared.

I

/
Working With Data Structure

10-21

Page of GC21-7567-2
Issued 24 May 1976
By TNL: GN21-5389

For sorting, sequence checking, and matching, you can
specify an ascending or descending collating sequence. For
example, if records are to be in ascending sequence, the
characters being checked should be in the order shown in
Figure 10-26. That is, a card with a blank sh"ould come before a card with the letter K. (The blank character is lower
in sequence than the letter K.) Likewise, a card with the
letter K should come before any records containing one of
the numbers 0 through 9. If you specify descending sequence, the computer compares to make sure they are in
theopposite order, the characters higher in sequence coming
first.
As mentioned, a computer cannot memorize the order of
characters; it must use another method for remembering
the collating sequence. To do this, it uses the values associated with characters to determine each character's relation
to another character in the sequence.
In a previous discussion, a value is calculated for each bit
combination in storage. The value can be thought of as a
" single numerical value"for the entire 8-bit combination or
as a 2-digit hexadecimal value, which is actually one hexadecimal number for each 4-bit combination (zone and digit).
A hexadecimal value is another way of representing a numerical value.
Once a value is calculated, the computer uses it to determine which character is represented. Thus, the numerical
value 193 (same as hexadecimal value C1) is associated with
the character A while the numerical value 243 (hexadecimal
valueF3) is associated with the numeric character 3. Perhaps you wonder why a particular value, such as 193 (C1)
is related to the letter A, rather than a different value.
The values associated with the 64 characters were originally
assigned such that the natural sequence of the values corresponds with the positions characters are to hold within the
collating sequence. For example, the character A is associated with value 193 (hexadecimal C1), 8 with 194 (C2), C
with 195 (C3), and so on. Just as A is lower than 8 and 8
is lower than C in the collating sequence, 193 (C1) is less
than 194 (C2), and 194 (C2) is less than 195 (C3).

10-22 "

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

Blank

e

<
(

+
I
&
I
$

*
)

,

I
- (minus)

I
,
%
_(underscore)

>
?
:

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

#
@

,

"-;;--

A
B
C

0
E
F
G

H
I

}
J

K
L
M
N

0
P

Figure 10-26. Standard Collating Sequence

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

Q

R

S
T
U
V

W
X

Y
Z
0
1
2
3
4
5
6
7
8
9

/

Page of GC21-7567-2
Issued 24 May 1976
By TNL: GN21-5389

Figure 10-27 shows the 256 possible bit combinations, their
numerical and hexadecimal values, and the characters associated with each. In this list of bit combinations, the numerical values are in 'order from 0 through 255 (hexadecimal
values 00 through FF), and the associated characters are in
the standard ascending collating sequence.

As you can readily see, the value associated with a character does not always immediately follow the value associated
with the previous character in the sequence. For example,
the <;:haracter S follows the character R in the collating sequence of characters. However, the numerical value of S,
226 (hexadecimal E2), does not immediately follow the

/:1

Bit
Combination

Character

00000000
00000001
00000010
00000011
00000100
00000101
00000110
00000111
00001000
00001001
00001010
00001011
.' 00001100
00001101
00001110
00001111
00010000
00010001
00010010
00010011
00010100
00010101
00010110 .
00010111
00011000
00011001
00011010
00011011
00011100
00011101
00011110
00011111
00100000
00100001
00100010
00100011
00100100
00100101
00100110
00100111
00101000
00101001
00101010
00101011
00101100
00101101
00101110
00101111
00110000
00110001
00110010

Hexadecimal
Value
00
01
02
03
04
05
06

07
08
09
OA
OB
OC
OD
OE
OF
10
11
12
13
14
15
16
17

18
19
1A
1B
1C
1D
1E
1F
20
21
22
23
24
25
26
27
28
29
2A
2B
2C
2D
2E
2F
30
31
32

Numerical
Value
0
1

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

18
19
20
21
22
23
24
25
26
27,
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

Bit
Combination
00110011
00110100
00110101
00110110
00110111
00111000
00111001
00111010
00111011
00111100
00111101
00111110
00111111
01000000
01000001
01000010
01000011
01000100
01000101
01000110
01000111
01001000
01001001
01001010
01001011
0100110
01001101
01001110
01001111
01010000
01010001
01010010
01010011
01010100
01010101
01010110
01010111
01011000
01011001
01011010
01011011
01011100
01011101
01011110
, 01011111
01100000
01100001
01100010
01100011
01100100
01100101

Character

Blank

e
<
(

+
I

&

I

$

*
)
;

I

I

Hexadecimal
Value

Numerical
Value

33
34
35 .
36
37
38
39
3A
3B
3C
3D
3E
3F
40
41
42
43
44
45
46
47
48
49
4A
4B
4C
4D
4E
4F
50
51
52
53
54
55
56
57
58
59
5A
5B
5C
5D
5E
5F
60
61
62
63
64
65

51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100 '
101

Figure 10-27 (Part 1 of 3). Characters and Values Associated with the 256 Bit Combinations

!I

Working With Data Structure

10-23

numericalvalue of R, 217 (hexadecimal D9). The reason
for the gap is because the bit combinations with the numerical values 218 through 225 are not associated with any of
the 64 printable characters. Regardless, the computer determines that R is lower in sequence than (comes before) S
because the value of R (217 or hexadecimal D9) is less than
the value of S (226 or hexadecimal E2).

Bit
Combination
01100110
01100111
01101000
01101001
01101010
01101011
01101100
01101101
01101110
01101111
01110000
01110001
01110010
01110011
01110100
01110101
01110110
01110111
01111000
01111001
01111010
01111011
01111100
01111101
01111110
01111111
10000000
10000001
10000010
10000011
10000100
10000101
10000110
10000111
10001000
10001001
10001010
10001011
10001100
10001101
10001110
10001111
10010000
10010001
10010010
10010011
10010100
10010101
10010110
10010111
10011000

Character

,
%

-

>
7

:

#
@

,

"

Hexadecimal
Value
66
67
68
69
6A
6B
6C
60
6E
6F
70
71
72
73
74
75
76
77
78
79
7A
7B
7C
70
7E
7F
80
81
82
83
84
85
86
87
88
89
8A
8B
8C
80
8E
8F
90
91
92
93
94
95
96
97
98

Numerical
Value
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152

Bit
Combination
10011001
10011010
10011011
10011100
10011101
10011110
10011111
10100000
10100001
10100010
10100011
10100100
10100101
10100110
10100111
10101000
10101001
10101010
10101011
10101100
10101101
10101110
10101111
10110000
10110001
10110010
10110011
10110100
10110101
10110110
10110111
10111000
10111001
10111010
10111011
10111100
10111101
10111110
10111111
11000000
11000001
11000010
11000011
11000100
11000101
11000110
11000111
11001000
11001001
11001010
11001011

Figure 10-27 (Part 2 of 3). Characters and Values Associated with the 256 Bit Combinations
:0-24

Character

A
B
C
0
E
F

G
H
I

Hexadecimal
Value
99
9A
9B
9C
90
9E
9F
AO
A1
A2
A3
A4
A5
A6
A7
A8
A9
AA
AB
AC
AD
AE
AF
BO
B1
B2
B3
B4
B5
B6
B7
B8
B9
BA
BB
BC
BO
BE
BF
CO
C1
C2
C3
C4
C5
C6
C7
C8
C9
CA
CB

Numerical
Value
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
..
178
179
180
181
182
183
. 184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
100
101
202
203 ...

Collating By Zone Or Digit

)

)

Bit
Combination
11001100
11001101
11001110
11001111
11010000
11010001
11010010
11010011
11010100
11010101
11010110
11010111
11011000
11011001
11011010
11011011
11011100
11011101
11011110
11011111
11100000
11100001
11100010
11100011
11100100
11100101
11100110
11100111
11101000
11101001
11101010
11101011
11101100
11101101
11101110
11101111
11110000
11110001
11110010
11110011
11110100
11110101
11110110
11110111
11111000
11111001
11111010
11111011
11111100
11111101
11111110
11111111

Character

}
J
K

L
M
N

0
P
Q

R

S

T
U
V
W
X
y

Z

0
1
2
3
4
5
6
7
8
9

Hexadecimal
Value
CC
CO
CE
CF
00
01
02
03
04
05
06
07
08
09
OA
OB
OC
00
OE
OF
EO
E1
E2
E3
E4
E5
E6
E7
E8
E9
EA
EB
EC
EO
EE
EF
FO
F1
F2
F3
F4
F5
F6
F7
F8
F9
FA
FB
FC
FO
FE
FF

Numerical
Value
204
~05

206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255

Figure 10-27 (Part 3 of 3). Characters and Values Associated with
the 256 Bit Combinations

)

You learned from a previous discussion that the zone and
digit portions of characters can be treated as separate and
distinct groups of four bits, each with its own hexadecimal
number.
Different characters may have identical zone bits or identical digit bits, but not both. Consequently, different characters may be associated with the same zone hexadecimal
number of the same digit hexadecimal number but not both.
As an example, the character A is associated with the value
C1, B is associated with C2, and K is associated with 02. A
has the same zone value (C) as B, while K has the same digit
value (2) as B. However, B is the only character with both
a zone value of C and a digit value of 2.
In most data processing tasks, the computer uses entire
characters or the values of those characters to make comparisons, to determine which is greater or less, and so on.
However, for certain purposes, such as sorting cards, you
may wish to have the computer check only the zone or
only the digit portion of characters. In such a case, the
computer must use a collating sequence based on zone or
digit values rather than the standard collating sequence
based on the entire value.
If the computer uses a collating sequence based on the zone
portions of characters, any differences in the digit bits are
ignored. Only the value of the zone bits are considered.
The reverse occurs if a collating sequence based on the digit
portions of characters is to be used.
The fact that certain characters have the same zone or digit
values can be used to group characters within a collating sequence. On the basis of zone values, the 64 printable characters are divided into eight groups (Figure 10-28). The
zone bits (and values) are identical for all characters within
a group. If collating is to be on the basis of digit values, the
characters can be divided into. 16 groups (Figure 10-29). In
such a case, digit bits (and values) are identical for all characters within a particular group.
Using the standard collating sequence, the computer considers each character to hold a specific position in the sequence. Therefore, no two characters can be considered
equal; one must come before another or be less than another character.
On the other hand, using a collating sequence based on zones
or digits, one group of characters follows another group of
characters. The characters within a group can occupy any
position within that group. Thus, there is an order of groups
but no particular order of characters within a group.

Working With Data Structure

10-25

Character

b
(blank)

4

Bit
Combination
Zone

Digit

0100

0000

0100

1010

0100

1011

Collating
Sequence
of
Zones

(period)

<

0100

1100

(

0100

1101

+

0100

1110

I

0100

1111

&

0101

0000

I

0101

1010

$

0101

1011

*

0101

1100

)

0101

1101

;

0101

1110

-,
-

0101

1111

0110

0000

1

2

(minus)

I

0110

0001

Character

Bit
Combination
Zone

Digit

A

1100

0001

B

1100

0010

C

1100

0011

D

1100

0100

E

1100

0101

F

1100

0110

G

1100

0111

H

1100

1000

I

1100

1001

}

1101

0000

J or-1

1101

0001

K or-2

1101

0010

Lor -3

1101

0011

M or-4

1101

0100

Nor -5

1101

0101

o or-6

1101

0110

P or-7

1101

0111

Oor -8

1101

1000
1001

,

0110

1011

R or-9

1101

%

0110

1100

S

1110

0010

0110

1101

T

1110

0011

>

0110

1110

?

0110

1111

:

0111

1010

#

0111

1011

@

0111

1100

0111

1'101

(underscore)

,
(apostrophe)

=

0111

1110

"

0111

1111

Figure 10-28. Collating Sequence by Zone

3

4

U

1110

0100

V

1110

0101

W

1110

0110

X

1110

0111

y

1110

1000

Z'

1110

1001

+0

1111

0000

1

1111

0001

2

1111

0010

3

1111

0011

4

1111

0100

5

1111

0101

6

1111

0110

7

1111

0111

8

1111

1000

9

1,111

1001

Collating
Sequence
of Zones

(

5

6

(
7

8

c
10-26

Character

()

Bit
Combination
Zone

Digit

0100

0000

Collating
Sequence
of
Digits

Character

(blank)
&

0101

0000

-

0110

0000

1

Bit
Combination
Zone

Digit

H

1100

1000

Qor-8

1101

1000

Y

1110

1000

(minus) '.

8

1111

1000

}

1101

0000

I

1100

1001

+0

1111

0000

R or-9

1101

1001 .

/

0110

0001

-

Z

1110

1001

9

1111

1001

¢

0100

1010

A

1100

0001

J or-1

1101

0001

1

1111

0001

!

0101

1010

B

1100

0010

:

. 0111

1010

K or-2

1101

0010

0100

1011

S

1110

0010

2

1111

0010

C

1100

0011

Lor -3

1101

0011

T

1110

0011

3

1111

0011

D

1100

0100.

M or-4

1101

0100

U

1110

4

1111

0100

E

1100

0101

Nor -5

1101

0101

V

1110

0101

5

1111

0101

F

1100

o or-6

1101

2

Collating
Sequence
of
Digits

9

10

11
I

(period)
3

$

0101

1011

,

0110

1011

#

0111

1011

<

0100

1100

*

0101

1100

%

0110

1100

@

0111

1100

(

0100

1101

)

0101

1101

0110

1101

0111

1101

+

0100

1110

0110

;

, 0101

1110

0110

>

0110

1110

=

0111

1110

0100

1111

0101

1111

0100

4

5

-

,
6

0110

6

1111

0110

G

1100

0111

P or-7

1101 .

0111

?

0110

1111

"

011,1

1111

0111

7

1111

0111

14

7

(apostrophe)

1110

1110

13

(underscore)

W

X

12

I

-,
8

-

15

16

Figure 10-29. Collating Sequence by Digit

)
Working With Data Structure

10-27

Note that in the collating sequence by zone shown in Figure 10-28, any character in group 5 is considered lower in
sequence than any character in group 6. If records are
sorted in ascending order by zone, a record with the letter
D (group 5) comes before a record with the letterN (group
6).

Now consider a case in which characters from the same zone
group are to be compared. Assume one record contains the
letter D (group 5) and the next record contains the letter F
(group 5). Which should be sorted first according to a collating sequence based on zones? Since the computer ignores
the digit bits of each character, they are considered equal
because they both have the same zone value. Therefore, no
one character must. come earlier in the sequence than another character from the same group. The sequence of the
characters is the same order in which the records are read.
Thus, if the D card is read first by a sort program, the
D record comes before the F record. On the other hand,
if the F card is read first, the F record comes before the
D record. In either case, the records are in proper sequence
based on zones.

For example, you may want alphabetic characters to follow
the numbers instead of preceding them. Suppose that a company originally started with a few departments. The depart.
ments were assigned numbers from 01-99. Two columns
were devoted to department numbers in various records.
The company expanded and departments increased. Soon
there were more than 99 departments. To avoid having to
change the department field from two to three characters
in all records, the manager decided to use the letters of the
alphabet to represent department numbers: 99, AO, A 1,
etc. In this case, A must follow the number 9 in the se~
quence. Thus it is necessary to alter ,the collating sequence
so that numbers come before alphabetic characters.

/r

There can be other reasons than the one just explained for
altering the collating sequence. Your language may demand that you have characters such as A', A', 0, if, E'included in the alphabetic sequence (A, A', B) . . Since the 64
graphics do not include these characters, other seldom used
characters can be substituted for them and repositioned in
the collating sequence. For example, a number-symbol (#)
repositioned between the letters A and B can substitute for
an
an at-sy~~ol (@) repositioned be~ween 0 and P substitutes for an O.

A;

ALTERING THE COLLATING SEQUENCE
A collating sequence is the order in which characters are arranged. As you know, all characters are associated with different numerical values in order that the computer may
recognize them. The sequence of numerical values (ascending or descending sequence) determines the order in which
characters associated with the values are recognized.
The association of a particular character with a numerical
value is an arbitrary decision. Thus, the collating sequence
itself is arbitrary. System/3 is programmed to expect the
collating sequence discussed previously in the section Collating Sequence of Characters. This does not mean, however, that you must always use this sequence. You can
change it and there may be times when you desire to do so.

10-28

These are only a few reasons for "altering the collating sequence. You may have others. Just remember that you
can alter the collating sequence in any way that fits your
needs.

/-I

\

Specifying Changes in Collating Sequence
To change the collating sequence, you must associate characters with different numerir,al values. The following sections will explain how this is done.

."

"

C·

International Business Machines Corporation

IBJ.1:

~

..a

~

I

Date

?

Program

."

o

CD

It
CD
a.

....

Page

CD

Program

Identification

IIIIIII
..

Cor.
Line

Size to

[ .~

Cor.
Size to

i~

Er~f~

-¥.

~

c

,,... ....

1:1

i;;

:;

.£ ~

Number

Of Print

!
~

.~

Refer to the specific System Reference Library manual for actual entries.

International Business Machmes Corporation

IB~

Form X21-9096
Printed in U.S.A.

TRANSLATION TABLE AND ALTERNATE COLLATING SEQUENCE CODING SHEET

~

..
..

75 76 77 78 79 80

1 2

I Graphic I I I I I I I I
Instruction I Punch
I I I J I I I I

Punching

Control Card Specifications

Z

::;:'

Form X2HI092

Programmer

~

l>

./

Printed in U.S.A.

CONTROL CARD AND FILE DESCRIPTION SPECIFICATIONS

RPG

CD

~

\

"'-_--I

)

:J
Cl

CD

n
2-

Di

;.

Ie
C/)

CD

.c
c:

CD

:J

n

CD

C/)

"C
CD

n
::;;

..o·
~r
:J

III

:E

Q
7'

5'

co

:E
~.

:T

o

~
Cl

~

2

~

c:

@

9

I\)

<0

Code
00000000
00000001
00000010
00000011
00000100
00000101
00000110
00000111
00001000
00001001
00001010
00001011
00001100
00001101
00001110
00001111
00010000
00010001
00010010
00010011
00010100
00010101
00010110
00010111
00011000
00011001
00011010
00011011
00011100
00011101
00011110
00011111
00100000
00100001
00100010
00100011
00100100
00100101
00100110
00100111
001 01 OO(»
00101001
00101010
00101011
00101100
00101101
00101110
00101111
00110000
00110001
00110010

System/3
Graphic

Entry
00
01
02
03
04
05
06

07
08
09

OA
DB
DC
00
OE
OF
10
11
12
13
14
15
16
17
18
19
lA
lB
lC
10
lE
lF
20
21
22
23
24
25
26
27
28
29
2A
2B
2C
20
2E
2F
30
31
32

Replaced
BylTakes
Place Of

Code
00110011
00110100
00110101
00110110
00110111
00111000
00111001
00111010
00111011
00111100
00111101
00111110
00111111
01000000
01000001
01000010
01000011
01000100
01000101
01000110
01000111
01001000
01001001
01001010
01001011
01001100
01001101
01001110
01001111
01010000
01010001
01010010
01010011
01010100
01010101
01010110
01010111
01011000
mOll00l
_.01011010
01011011
01011100
01011101
01011110
01011111
01100000
01100001
01100010
01100011
01100100
01100101

System/3
Graphic

Blank

¢

<
(

+

I
&

I

$
)

-,
I

Entry
33
34
35
36
37
38
39
3A
3B
3C
30
3E
3F
40
41
42
43
44
45
46
47
48
49
4A
4B
4C
40
4E
4F
50
51
52
53
54
55
56
57
58
59
5A
5B
5C
50
5E
5F
60
61
62
63
64
65

Replaced
BylTakes
Place Of

Code
01100110
01100111
01101000
01101001
01101010
01101011
01101100
01101101
01101110
01101111
01110000
01110001
01110010
01110011
01110100
01110101
01110110
01110111
01111000
01111001
01111010
01111011
01111100
01111101
01111110
01111111
10000000
10000001
10000010
10000011
10000100
10000101
10000110
10000111
10001000
10001001
10001010
10001011
10001100
10001101
10001110
10001111
10010000
10010001

~10010011
10010100
10010101
10010110
10010111
10011000

System/3
Graphic

%

-

>
?

:

#
@

..

=

Entry

Replaced
BylTakes
Place Of

66
67
68
69
6A
6B
6C
60
6E
6F
70
71
72
73
74
75
76
77
78
79
7A
7B
7C
70
7E
7F
80
81
82
83
84
85
86
87
88
B9
8A
8B

:~- - - - BE
8F
90
91
92
93
94
95
96
97
98

Code
10011001
10011010
10011011
10011100
10011101
10011110
10011111
10100000
10100001
10100010
10100011
10100100
10100101
10100110
10100111
r-10101000
10101001
10101010
10101011
10101100
10101101
10101110
10101111
10110000
10110001
10110010
10110011
10110100
10110101
10110110
10110111
10111000
10111001
10111010
10111011
10111100
10111101
10111110
10111111
11000000
11000001
11000010
11000011
11000100
11000101
11Oci0110
11000111
11001000
11001001
11001010
11001011

System/3
Gr.phic

A
B
C
0
E
F
G
H
1

Entry
99
9A
9B
9C
90
9E
9F
AO
Al
A2
A3
A4
A5
A6
A7
A8
A9
AA
AB
AC
AD
AE
AF
BO
Bl
B2
B3
B4
B5
B6
B7
B8
B9
BA
BB
BC
BO
BE
BF
CO
Cl
C2
C3
C4

C5
C6
C7
C8
C9
CA
CB

Replaced
BylTakes
Place Of

Code

System/3
Graphic

Entry

11001100
11001101
11001110
11001111
11010000
11010001
11010010
11010011
11010100

}

lln101n1

N

n~

11010110
11010111
11011000
11011001
11011010
11011011
11011100
11011101
11011110
11011111
11100000
11100001
11100010
11100011
11100100
11100101
11100110
11100111
11101000
11101001
11101010
11101011
11101100
11101101
11101110
11101111
11110000
11110001
11110010
11110011
11110100
11110101
11110110
11110111
11111000
11111001
11111010
11111011
11111100
11111101
11111110
11111111

0
P

06
07
08
09
OA
DB
DC
DO
DE
OF
EO
El
E2
E3
E4
E5
E6
E7
E8
E9
EA
EB
EC
ED
EE
EF
FO
Fl
F2
F3
F4
F5
F6
F7
F8
F9
FA
FB
FC
FO
FE
FF

J
K

l
M

Q

R

S
T
U
V
W

X
Y

Z

0
1
2
3
4
5
6
7
8
9

CC
CO
CE
CF
00
01
02
03
04

Replaced
BylTake.
Place Of

Forms For Altering the Collating Sequence

Figure 10-30 illustrates two forms on which you must
specify changes to the collating sequence. One form is the
RPG II Control Card and File Description sheet; the other
is the Translation Table and Alternate Collating Sequence
Coding Sheet which is used for listing the actual changes in
'sequence. Both forms are used in conjunction with the
RPG II Input, Output and Calculation sheets.
A letter S entered in column 26 of the RPG II control card
notifies the program that additional information will be
furnished to the program so that the collating sequence
can be altered. All other columns contain the information
that must normally be entered to process a job.
The Alternate Collating Sequence Coding Sheet lists 256 bit
combinations along with their hexadecimal numerical values.
As you learned from discussions of character structure, hexadecimal values are written in the form of two character
values. One value represents the numerical value of the character's zone; the other represents the numerical value of the
character's digit. The 64 printable graphics are listed beside
the bit combinations and numerical values with which they
are associated.

Character Associated
with Bit Combination

Numerical Value of
the Replacement Character

/
Code
11110000

System/3
Graphic

Entry

0

FO

Replaced
by

11110001
1
F2
F1
--------. ---. - - -------------- -_._----- - - - - 11110010

2

F2

11110011

3

F3

11110100

4

F4

11110101

5

F5

\

Numerical Value
+
of Bit Combination

F1 ...-,

IF

II
II

I~

8-Position Bit Combinations

2 Replaces 1

1 Replaces 2

Figure 10-31. Explanation of Alternate Collating Sequence Sheet

Coding a Change in Sequence

Effect of the Coded Change in Sequence

Each change in the collating sequence is specified in the
Replaced By column on the coding sheet. In this column,
place the hexadecimal value of the graphic whose position
in the normal sequence is to be changed. The character
corresponding to the hexadecimal value entered in the
Replaced By column replaces the character which is presently associated with the bit combination shown on the same
line.

Any alternate collating sequence you specify is used temporarily. It is used only for the program which contains
the alternate collating sequence specifications. Even more
specifically, it is used in that program for operations which
involve sequencing, such as checking sequence of records,
comparing fields, or matching records.

Figure 10-31 illustrates entries made to change the normal
collating sequence. Hexadecimal values entered on the second and third lines of the sample coding sheet reverse the
order in which the numbers 1 and 2 are recognized by the
computer.
Numerical values entered on the second line of the sample
specify that the number 2 (hexadecimal value F2) replaces
the number 1. In other words, in the new sequence the
number 2 is associated with the value F 1 instead of the
number 1. Hexadecimal values on the third line specify that
the number 1 (hexadecimal value F 1) replaces the number
2. These two specification lines cause 2 to come before 1
in the collating sequence (0,2, 1,3).

10-30

You may think, according to specifications in Figure 10-31,
that the character 2 read into the computer is always replaced by a 1. This is not true. The computer associates
characters with the values you specify only before sequencing operations involving:

1.

Compare operations on alphameric fields.

2.

Matching or sequence checking match fields.

How does the computer keep track of the collating sequence
to use? ,The computer keeps all your instructions for altering the sequence in storage. The area in storage which holds
this information may be pictured as shown in Figure 10-32.
These instructions combined with the pattern for normal
sequence give the computer the correct collating sequence to
use.
Associated Characters

Numerical Value
of

Normal Collating
Sequence

Bit Combinations
FO

Altered Collating
Sequence

0

0

/------'-------- - - - - . -_ .. _ - - - - - - - + - - - - - - - - - - /

F1
1
2
-------_.. _- --_._---- ...... - - - - - - - - - - - - - 1 - - - - - - - - - /
F2
2 :-_.__ .. __ ._------_.1 - - - - - -... - - .. _----_. -_.- F3
3
3
1 - - - - - _... ------------_ ..
F4
4
4
1-- ... _---_.
..-.------------ --.-.-------- .. -.-.-.------.-.. - - - -..-----.---.-----

_._---_. F5 ._--_

.....

_---

--.-------F6
. _. -_.. _.. _------

-._.

F7

5 ._----

._-.-..

-----_._--------_.6 ----_._--

-

__

.

__._--_.-

---.. -. -_... _--.5

- - - - - - - - -6- - - - - - -

7

7

Figure 10-32. Storage Area Holding Alternate Collating Sequence
Instruction

)

Figure 10-33 illustrates how the program u~es the alternate
sequence. Two cards are read into the read area. Just before the compare operation which is done to determine
which match field has a lower value, the program checks to
see if the characters used in the compare are affected by the
alternate collating sequence instructions. They are. The
character 1 normally associated with the value F 1 is replaced
by the character 2; the character 2 normally associated with
the value F2 is replaced by the character 1.
When doing the compare, the program substitutes these
values. For the match field having the character 2, the.
program uses the bit combination whose value is F1 instead
of the bit combination for F2. Similarly for the match field
containing a 1, the program uses the bit combination of
F2 instead of the bit combination for F 1. As a result of the
compare, the primary card containing a 2 iJl the match field
is chosen for processing. This card was chosen because F1
(now associated with character 2) is lower in sequence than
F2 (now associated with the character 1).
After the compare, characters are again associated with
values as assigned in the normal collating sequence.

Consider the use of an altered sequence when determining
which record to select for processing in a multifile program.
The collating sequence has been changed so that 2. comes
tiefore 1.
F.1 and 1

----~.

F1 and 2

F2 and 2 ----.~ F2and1
F3 and 3

---_I

F3 and 3

)
Working With Data Structure

·10-31

Match

B
A
8
4
2e
1

Primary File

Secondary File

Bit Combinations in
Storage
Compare to· determine
low Match Field. For
Compare should alternate
collating sequence be used?

F1

F2

COLLATING SEQUENCE
Numerical
Value of
Bit Combination
FO
F1
F2
F3
F4

YES

Associated Character
Normal
Coli. Seq.
0
1
2
3
4

Altered
Coli. Seq.
2
1

I

/'

}

Substituted Bit
Combinations

~1,-;;::::::::::::;:::::::
11110001

Compare to

i

11110010

I~.------------------

F2

F1

Use altered sequence for
compare by using
values associated with
characters as spaclfied.

2

B
A
8
4
2e
1

Figure 10-33. Using Alternate Collating Sequence (0, 1,2,3,4,9)

Primary file card selected
for processing because F1
is lower in value than F2.
The new collating sequence
is 0, 2,1,3,4, etc.

,/'
I

\.
1O-3~

Coding Characters to be Equal
Entries can be made to allow two characters to occupy the
same position in the collating sequence; that is, they are associated with the same numeric value. When two characters
occupy the same position in the sequence, the computer
recognizes one character as being the same as the other.

Figure 10-34 illustrates the specifications which allow a
blank or zero to occupy the same position in an altered
sequence (assume the field is alphameric). The hexadecimal
value associated with the character blank is replaced by the
hexadecimal value (FO) which is already associated with the
zero. Because the zero and blank are associated with the
same numerical value, they are recognized as the same character. Figure 10-35 shows why a field containing a blank
is equal to a field containing a zero when the altered sequence is used.

International Business Machines Corporation

Form X21-9096
Printed in U.S.A.

TRANSLATION TABLE AND ALTERNATE COLLATING SEQUENCE CODING SHEET

Code

System/3
Graphic

:~~ac:!
Entry

Place Of

Code

System/3
Graphic

Entry

Replaced
BvITakes
Place Of

Code

System/3
Graphic

Entry

Replaced
BvITakes
Place Of

~.-t----t---~:~--1t-----I

10011001
99
66
~~ ~~~ ~~
10011010
9A
67
10011011
35
01101000
9B
68
10011100
36
01101001
69
9C
10011101
37
01101010
90
6A
38
01101011
6B
10011110
9E
%
10011111
39
01101100
6C
9F
60
10100000
3A
01101101
AO
6E
10100001
38
01101110
Al
>
6F
3C
01101111
A2
10100010
70
10100011
A3
3D
01110000
71
A4
10100100
3E
01110001
10100101
3F
01110010
72
A5
10100110
73
A6
Blank
40
~ trJ
01110011
10100111
74
41
.'",
01110100
A7
10101000
AB
75
1---:0::-,~0000~1;-,:0'--t_ _ _+--=4~2___- t_ _ _-l .........01110101
10101001
A9
76
43
~110
01000011
10101010
AA
77
01000100
44
01110~
01000101
45
01111000
..........
01111001
~~
r;~""~~;..,;~,;.~~~~",,I-t_ _ _+--=:~c-;~;--t------I
01000110
46
01000111
47
~~~~~~~~ ~
Zero Replaces Blank. -=~-=-::~:-:-:7~~=-=~-I----+-""':~":~=--+----l
01001000
48
01001001
49
I---:~~~~~~~~~~~~,-t~@~-~~~=~~-+-~~,~ ~;~~~:~~~~~~~~---4--=~~~~-t----l
01001010
¢
4A
01001011
4B
01111110
=
7E
...... f>'~""'.;;.OI:,..:I-=-OO::.::O:..:.I-+_ _ _-+-...::.B:.,:.I_-+_ _ _ _-I
01001100
<
4C
01111111"
7F
1-"'7-'-~""",,11;..::0-l_ _ _-+-....:B:..:2'---+_ _ _-l
01001101
(
40
___
_ _ _--I
01001110
+
4E
00110101
00110110
00110111
00111000
00111001
00111010
00111011
00111100 .
00111101
00111110
00111111
01000000
01000001

~:~~~~I-t

+-~:U~_-+

I---'~~=~"-'~"'~-t---+-~:~~--+-----I
01010001
01010010
01010011
01010100
01010101
01010110
J!..1010111
~011000

01011001
01011010'\
01011011
~
-'l1011100
01011101
I
01011110
0'0'11"'"
01100000
01100001
I
01100010
01100011
01100100
01100101

51
52
53
54
SS

56
57
58
59
. 5A
5B
5C
50
5E
5F
60
61
62
63
64
65

10000100
10000101
10000110
10000111
10001000
10001001
10001010
10001011

84

85
86
87
88
B9
8A
8B

I---':-::~",,-:-~~~~~,-t---.-+--:.=-'~'---+------I
10001110
10001111
10010000
10010001

8E
8F
90
91

94
95
96
97
9B

System/3
Graphic

Entry

11001100
11001101
11001110
11001111
11010000}
11010001
J
11010010
K
11010011
L
11010100
M

CC
CO
CE
CF
DO
01
02
03
04

11010101

01;

N

Replaced
By/Takes
Place Of

11010110
0
06
11010111
P
07
11011000
Q
08
11011001
R
D9
11011010
OA
11011011
DB
11011100
DC
11011101
DO
11011110
DE
11011111
OF
11100000
EO
11100001
El
11100010
5
E2
11100011
T
E3
11100100
U
E4
11100101
V
E5
11100110
W
E6
11100111
X
E7
11101000
Y
E8
11101001
Z
E9
10110111
B7 ..........
11101010
EA
1;101011
10111000
B8
...........
EB
10111001
B9
..........
11101100
EC
1-"~0~11~1~01~0-l_ _ _-+-....:B~A~-+_ _ _-l~~I~I1~0~1~10~1-1_ _ _-+-....:E~0~-+-----I
10111011
BB
fl'NJ110
EE
10111100
BC
11101 ~::: :::::::~:~t::::::::::::::::: ::::::::E$:::::..
10111101
BO
10111110
BE
11110010
2.............. ··F2

~~~~~~~:~~~:~~~"""",,~---1r--=::":!~-+----l
~~~ :~:~~

~ ~

~~~~

~~

11000001
11000010
11000011
11000100

A
B
C
0

Cl
C2
C3
C4

11000111
11001000
11001001
11001010
11001011

G
H
I

C7
C8
C9
CA
CB

~--+---+-~:~~-~----~
10010100
10010101
10010110
10010111
10011000

Code

1111 0011
11110100
11110101
11110110
11110111
11111000
11111001
11111010
11111011
11111100
11111101
11111110
11111111

3
4
5
6
7
8
9

F3
F4
F5
F6
F7
F8

-';;F~9--t----~

FA
FB
FC
FO
FE
FF

Figure 10-34. Specifying Blank Equal to Zero in New Collating Sequence

)
Working With Data Structure

10-33

Compare Field A to Field B
Field A = Blank

/

Field B = 0

Bit combinations
in storage

~I

~1~rtJ~~~~

1111¢¢~

--.- ---.--

Compare Field A to Field B.
- - - - - - - - - - - - - - - . For compare should Alternate
Collating Sequence be used?
,

40

'.

FO

I

I

Numerical
Value of
Bit Combinations

I

40

I

I
I

Yes

Associated Character
Normal
Coli. Seq. '
Blank

Altered
Coli. Seq.

0
'.

E9

Z

FO
F1

1

I

Substituted
bit combinations

~I

I

I

l
1111~~~

Use Alternate Sequence,
Compare to

~¢rtJ~ 1. .·-----.
~:I;:k~:~~e~s~~;h

--.----.--

1111
--.- --.-

FO

FO

Result: FO is the same as FO
Fields are equal; Blank
is the same as zero.

Figure 10-35. Using Alternate Collating Sequence (Blank Equals Zero)

10-34

0

Characters as Specified

/'

Example of the Coging of an Altered Sequence

Figure 10-36 shows a part of the normal collating sequence,
and one of several ways in which the sequence can be
changed. Arrows depict changes required in the positions
of characters to alter the sequence as shown at the right side
of the figure.
In Iike manner, arrows in Figure 10-37 show entries on the
coding sheet which must be specified to alter the sequence.
Note that letters B through I are to be repositioned to allow
the at-symbol (@) to appear between letters A and B. Identical results could be achieved by repositioning the value for
the letter A to the line above, making it correspond to bit
combination 1100000.
To produce the sequence shown in Figure 10-36 and 10-37,
the appropriate hexadecimal values must be specified in the
Replaced By column beside each graphic involved in the
change. Figure 10-38 shows the actual coding required to
alter the sequence.

PORTION OF THE
NORMAL SEQUENCE

I

./

1
"

o
------

D

E
F
G

H
I

TJ

1
2
3
4
5

6
7
8
9
A
@

K

B

L

C
D

M
N

o
P

Notice that each number which is to be collated before the
alphabetic character is assigned a hexadecimal value which
has no graphic associated with it. These values have no associated graphics that could have been assigned to the values
previously associated with numbers. This is not necessary,
however, because these values have no associated graphics.
When two graphics are involved in the change, then both
must be assigned different values except when they are to
be considered equal.

ALTERED SEQUENCE

Q

-s--.
R

E
F
G

H

--L.J

K
L

T
U
V
W
X

M

y

P

N

o
Q

R

~

2
3
4

5
6
7
8
9

S
T
U
V

W
X
Y
Z

}

Figure 10-36. Normal Sequence Versus Altered Sequence

I

./

Working With Data Structure

10-35

International Business Machines Corporation

Form X21-9096

Printed in U.S.A.

TRANSLATION TABLE ANO ALTERNATE COLLATING SEQUENCE CODING SHEET

System/3
Graphic

Blank

<
(

+

Entry

Replaced
ByfTakes
Place Of

33
34
35
36
37
3B
39
3A
3B
3C
3D
3E
3F
40
41
42
43
44
45
46
47
4B
49
4A
4B
4C
40
4E

1-.~I___-II-_4~F_-+_____-t

&

I

/

50
51
52
53
54
55
56
57
58
59
5A
5B
5C
50
5E
5F
60
61
62
63
64
65

Code

01100110
01100111
01101000
01101001
01101010
01101011
01101100
01101101
01101110
01101111
01110000
01110001
01110010
01110011
01110100
01110101
01110110
01110111
01111000
01111001
01111010
01111011
01111100
01111101
01111110
01111111
10000000
10000001
10000010
10000011
10000100
10000101
10000110
10000111
10001000
10001001
10001010
10001011
10001100

:::::~~

System/3
Graphic

%

>

Entry

77

.•:./t.:.:

7B
79
7A
7B
7C
7D

= '\

7E
7F
BO
Bl
'82
~

8~
B5 "\.
86
"\
B7
'\
88'
89"\.
8A"\.
8B
"\.
8C
~

-80-- -----'1\

8E
I
10001111
8F
10010000
90
t-1:=:00"-'1:.::;000==1-+_ _ _-+-...:9:.:.1_ _+_____

~.-+---+-~:=~'--+-----l
10010100
10010101
10010110
10010111
10011000

Code

66
67
6B
69
6A
6B
6C
60
6E
6F
70
71
72
73
74
75
76

94
95
96
97
98

Figure 10-37. Changes Necessary for Altered Sequence

10-36

Replaced
ByfTakes
Place Of

10011001
10011010
10011011
10011100
10011101
10011110
10011111
10100000
10100001
10100010
10100011
10100100
10100101
10100110
10100111
10101000
10101001
10101010
10101011
10101100
10101101
10101110
10101111
10110000
10110001
10110010
10110011
10110100
10110101
10110110
10110111
10111000
10111001
10111010
10111011
10111100
10111101
10111110
10111111

System/3
Graphic

__
-

Replaced
ByfTakes
Place Of

Entry

99
9A
9B
9C
90
9E
9F
AO
Al
A2
A3
A4
A5
A6
A7
AB
A9
AA
AB
AC
AD
AE
AF
BO
Bl
B2
63
B4
B5
B6
B7
BB
B9
BA
BB
BC
... RO
BE BF

11011010
\
OA
11011011
,
DB
11011100\
DC
11011101
'DO

11100000
11100001

...

--

C4

~~~i-~tHr:-~·---t------f
C8

C9
CA
CB

Replaced
By/Takes
Place Of

~.:~-- ~'--\,--+---"~:..:::~--+----I

C3

C7

Entry

M'
N'

r711';:0~000;;;;-;-10;;-'::f.!:~B':il:;:;c-:.--+---;;;C~2--t-----l

11000111 ;; G ;:;:
11001000 :; : H:;:::,
11001001 ': ~ I :;;;;:
11001010 r;=t::;:
11001011

System/3
Graphic

11001100
CC
11001101
CO
11001110
CE
11001111
:::::::::::
CF
11010000 ;: } .!::;:
DO
11010001
'::n:'
01
K\
02
11010010
11010011
L 1___t-=03"----i_ _ _--i
11010100
04
11010101
n<;
11010110
0 \
06
11010111
P '_-+--'0""7'---+_ _ _-1

,,1--:::-:-:~=-=OO~OO:-=I-+""'..A:-:.-.-'---i---=~=-=I'---+-----t
11000011 :;' C:;;;;:
11000100: ; 0 :;:;

Code

\
EO
--\\-l---'E=-=I'---+-----t

11100010
1 E2
11100011
T
\
E3
11100100
U
J E4
11100101
V
I
E5
11100110
W
,
E6
11100111
X /
E7
11101000
Y /
E8
11101001
Z./
E9
11101010
r
EA
11101011
EB
11101100
___+_-"-EC"-~I_----11101101
ED
11101110
EE
11101111
.':::;:::
EF
11110000 ;;;'0;;;;:
FO
11110001 ::;·1 ;:;::
Fl
11110010 :;;; 2 ;;;;;
F2
~11:;::3:;;;;
F3
111101l)!J"":;:;4 :;:;:
F4
11110101 :;:: 5 :;:;:
F5
11110110 :;: 6;:;::
F6

::::~~

LHf- ~i-,--t----I

11111001 ;;;9 ;:;'
11111010 . :,::::::.,
11111011
11111100
11111101
11111110
11111111

'F9
FA
FB
FC
FO
FE
FF

International Business Machines Corporation

Form X21-9096
Printed in U.S.A.

TRANSLATION TABLE AND ALTERNATE COLLATING SEQUENCE CODING SHEET

)

System/3
Graphic

Blank

Entry
33
34
35
36
37
38
39
3A
3B
3C
3D
3E
3F
40
41
42
43
44

¢

<
(

+
I
&

I

.
i;

I

..,
I

45
46
47
48
49
4A
4B
4C
4D
4E
4F
50
51
52
53
54
55
56
57
58
59
5A
5B
5C
50
5E
5F
60
61
62
63
64
65

Replaced,
By{Takes
Place Of

Code
01100110
01100111
01101000
01101001
01101010
01101011
01101100
01101101
01101110
01101111
01110000
01110001
01110010
01110011
01110100
01110101
01110110
01110111
01111000
01111001
01111010
01111011
01111100
01111101
01111110
01111111
10000000
10000001
10000010
10000011
10000100
10000101
10000110
10000111
10001000
10001001
10001010
10001011
10001100
10001101
10001110
10001111
10010000
10010001
10010010
10010011
10010100
10010101
10010110
10010111
10011000

System/3
Graphic

%

-

>
?

:

Ai.:.::@;.,:

.. . :-x
~

=
.. \

\

Replaced
By{Takes
Place Of

Entry

\
\

\

Code

66
67
68
69
6A
6B
6C
60
6E
6F
70
71
72
73
74
75
76
77
78
79
7A
7B
7C
7D
7E
7F
80
81
82
83

\64
~5

~
81\
88 \
89 \
8A
8B
8C
8D
8E
8F
90
91
92
93
94
95
96
97
98

\

I'

............

.....

10011001
10011010
10011011
10011100
10011101
10011110
10011111
10100000
10100001
10100010
10100011
10100100
10100101
10100110
10100111
10101000
10101001
10101010
10101011
10101100
10101101
10101110
10101111
10110000
10110001
10110010
10110011
10110100
10110101
10110110
10110111
10111000
10111001
10111010
10111011
10111100
10111101
10111110
10111111
11000000
11000001
11000010
11000011
11000100
11000101
----;tODo 11 0
11000111
11001000
11001001
11001010
11001011

System/3
Graphic

....•.•
:;~;:::::

:·B:::::
·:C:;:;
·0::::
; E;:;:
; F :;:;
::G::::

: H::::

·:1;:;:

;:f.;:;.

Entry
99
9A
9B
9C
90
9E
9F
AO
Al
A2
A3
A4
A5
A6
A7
A8
A9
AA
AB
AC
AD
AE
AF
BO
Bl
B2
B3
B4
B5
B6'
B7
B8
B9
BA
BB
BC
BD
BE
BF
CO
Cl
C2
C3
C4
C5
C6
C7
C8
C9

CA
CB

Replaced
By{Takes
Place Of

:fl
I

~

"7~

C
C

r~.
,.~

.(

.... """-

Code
11001100
11001101
11001110
11001111
11010000
11010001
11010010
11010011
11010100
11010101
11010110
11010111
11011000
11011001
11011010
11011011
11011100
11011101
11011110
11011111
11100000
11100001
11100010
11100011
11100100
11100101
11100110
11100111
11101000
11101001
11101010
11101011
11101100
11101101
11101110
11101111
11110000
11110001
11110010
1~
11110100
11110101
11110110
11110111
11111000
11111001
11111010
11111011
11111100
11111101
11111110
11111111

System/3
Graphic

'. ~ }:~..:.
,:3;.;.

K\
L\

MI
N \

05

t

P

I

o \
R \
\

I

\
\
\

\
\
S
T
U
V
W

X I

vI

,

zJ

,:,:.;:.:0.
:'O~::::

'1:;:;
2 :;::
3 ;:::
: 4 :;:;
; 5 ;::::
6 ;:::
7 ::::
8 :;:;
:9,:::'

:::::!::::

Replaced
By{Takes
Place Of

CC
CO
CE
CF
DO
01
02
03
04

. :.:..:.::....

o

Entry

\

I

I
I

06
07
08
09
OA
DB
DC
DO
DE
DF
EO
El
E2
E3
E4
E5
E6
E7
E8
E9
EA
EB
EC
ED
EE
EF
FO
Fl
F2
F3
F4
F5
F6
F7
F8
F9
FA
FB
FC
FD
FE
FF

DO

Figure 10-38. Coding for Altered Sequence

)
Working With Data Structure

10-37

Recording Specifications for the Altered Sequence
After you have coded all specifications for the alternate collating sequence, you can record them so that they can be
used by the computer. Records describing the alternate sequence are to be formatted as follows:

Coding Sheet. The last two positions in a group are for the
hexadecimal value taken from the Rep/aced By column of
the coding sheet (Figure 10-39).
More than one record may be used to specify changes in
collating sequence. However, each additional record must
be formatted in the same way as the first.

Positions

Entries

1-6

AL TSEQ (This entry allows the computer to recognize that this record is
describing an alternate sequence.)

The first blank appearing in positions 9-96 is recognized by
the compiler as the end of the record. Consequently, blanks
must not appear between pairs of hexadecimal values.

7-8

Blank

A record containing **k) (two asterisks and a blank) in positions 1 through 3 must precede the sequence records.

9-96

The hexadecimal values involved in
changing the sequence.

In positions 9-96, there are 22 groups of 4 positions. Each
group (9-12, 13-16, etc.) must contain two hexadecimal
values involved in changing the sequence. The first two
positions of a group are for the hexadecimal value taken
from the Entry column of the Alternate Collating Sequence

All records (except the RPG II control card) used for altering the collating sequence must follow RPG II specifications
(or file translation specifications, when used) and must precede any tables being entered.

Note:
Although a card is shown in this
figure, remember, alternate collating
sequence data can also be entered
by means of keyboard or disk.

Form X21-9096
Printed in U.S.A.

HEET

System/3
Graphic

Entry
99
9A
9B
9C
90

i

----

B2
B3
B4
B5 .••.

I

2

3

~

S

,

.-:::::W::::::::::::

87F088F189F2BAF3BBF4BCF5
7

•

9

10 11

12 13 ,.. 15 16 17 18 '9 20 21

zz

:::: ::{i17

23 24 25 26 27 28 29 30 31 32

----.::- :::~

~?~~~:~Z~~~~~:~~~:~~?,~~~~~S2~~~;~~ ~

C 6C 5C 7C6C8C 7C9C8CAC9EAD0
6' 66 67 68 69 70 71 72 73 74 75 76

!l7 98 99 100 101 102 103

B • •

••

n

78 79 80 81 82 83 84 85 86 81

'~~~;%~::t~~:~~~
•
:::~

112

.::::::.

11~

•.•

, ,: 92 93 '4 95 96

114 115 116 1:7 1:8 119 ;20 121 122 1:?3 IN '''5 U6 127

•

•••

•••

•••

12~

B

~ : : ;: : 0 ,,;,::; 0'0; : 0; 0: : ;: :: ; 0:; ;: ~
,4

I

! . .. ::: ·:::::tji::j~::::::::: . : :
.' ,

...

5

6 '7 :•• :+.;1.-,.-»:.)3

8

15

17

11

19 20 :<'1 22 23 2<1

~5 ~E

•••

•••

••

: : : : : : : .~
8

••

••

2 ••••••••••••••••••••••••
1

••

33 34 35 36 37 38394041 4243 U

B.
A.

•
•

•
•

•
•

•
•

•
•

1

•
•

•
•

•••
•••

•••
••••
•

2

B
A

8
4
2

~~~~~~~n~N~~~~~~~~~~~~~~MR~~~~~"1
IBM 3700

Figure 10-39. Punching Alternate Collating Sequence Cards

1 ()"38

.4

•••••••••
•••••
1
~G ~7 59 !i! 60 GI 62636.

45 46 '7 48 4950 51 52 5354 5S

8
• • • •
4
•
•
•••
•
2 •••
•••••
•••
•
•
•

A
B
C
0

17 2!1 29 30 31 32

••

4

i

G
H

I

BA
BB
BC
BO
BE
BF
CO
C1
C2
C3
C4
C5
C6
C7
C8
C9
CA
CB

~

t..---

:::::::::;:~::::::::'.
~ ~::::::

:::::::.

:::::.:::: ;::::::::.

7l.
('
('\

..-

,.,.'"

.A"

I-

5

6

0

-~-il~
o

~
4

- ~.~
~§ ~

7

8

0

;::
.;;;

~

Position

~

e

8

1

Position

g

~

~ ~

75 76 77 78 79 80

Position

6

ge
~

;ji

g

c::

From

To

~

co

\,

Field
Indicators
.~

0

:2-0

] ......
g .~ g'
~~
8 :;;u

J:
~

..J

~

Field Name

IIIIII

~~~~;~f:alion I

of _

Field Location

~

Line

3

U/M 050-

Printed in U.S.A

International Business Machine Corporation

.~

:§

~
'C
0

~

Zero
Plus Minus or

Blank

'C

z
A
Z 0
~
z
z U
ii:
0
~
<5
-f---AND
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 3031 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
0

0

0

~'J

RPG

IBM

~----

C
-

~~
QiS2

6 6

0 1

C

0 2

C

o

C

3

At

~5~6
.... '0 rr.
E ; '"

4

@. c

TAnd

FaCTOr 1

Operation

.~

Factor 2
Name

Length

~

E
~

8 56

~

7

9 10 1112 13 14 1516 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 5061 !:i2

8

~

Z

~

z

-- -2.~

VA

J~

~1-4 J~ .... lvA

r:

M/""\ V~

,,.."'"

-- .• AJ\1 ~l NT

-

V/J.' IF
11M r\, AJT

OJ

75 76 77 78 79 80
of _

~~~~;~f:ation I

I I I I IJ

Resulting
Indicators

Result Field

Figure 10-43. Using Move Zone Operations to Change the Sign of a Field

10-42

1 2

Page

Indicators

::i

~
3

Printed in U.S.A.

------------~------,-----r_~-~~.~~~~--------~

~m

Line

Form GX21-9093

CALCULATION SPECIFICATIONS

International Busines. Machine Corporation

Arithmetic
Plus IMinusl Zero
Compare

Comments

1>211<211-2
Lookup(Faclor 2)is
High Low Equal
54 55 56 57 5859 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

A2
2
?

:

#
@

..

=

Entry
66
67
6B
69
6A
• 6B
6C
60
6E
6F
70
71
72
73
74
75
76
77
78
79
7A
7B
7C
70
7E
7F
80
81
B2
83
84
85
86
87
88
89
8A
8B
8C
80
8E
8F
90
91
92
93
94
95
96
97
98

Replaced
ByITakes
Place Of

Code
10011001
10011010
10011011
10011100
10011101
10011110
10011111
10100000
10100001
10100010
10100011
10100100
10100101
10100110
10100111
10101000
10101001
10101010
10101011
10101100
10101101
10101110
10101111
10110000
10110001
10110010
10110011
10110100
10110101
10110110
10110111
10111000
10111001
10111010
10111011
10111100
10111101
10111110
10111111
11000000
11000001
11000010
11000011
11000100
11000101
11000110
11000111
11001000
11001001
11001010
11001011

System/3
Graphic

A
B
C
0
E
F
G
H
I

Entry
99
9A
9B
9C
90
9E
9F
AO
Al
A2
A3
A4
A5
A6
A7
A8
A9
AA
AB
AC
AD
AE
AF
BO
Bl
B2
B3
B4
B5
B6
B7
B8
B9
BA
BB
BC
BO
BE
BF
CO
Cl
C2
C3
C4
C5
C6
C7
C8

C9
CA
CB

Replaced
ByITakes
Place Of

Code
11001100
11001101
11001110
11001111
11010000
11010001
11010010
11010011
11010100
11010101
11010110
11010111
11011000
11011001
11011010
11011011
11011100
11011101
11011110
11011111
11100000
11100001
11100010
11100011
11100100
11100101
11100110
11100111
11101000
11101001
11101010
11101011
11101100
11101101
11101110
11101111
11110000
11110001
11110010
11110011
11110100
11110101
11110110
11110111
11111000
11111001
11111010
11111011'
11111100
11111101
11111110
11111111

System/3
Graphic

}

J
K
L
M
N
0
P

0
R

S
T
U
V
W
X
Y

Z

0
1
2
3
4
5
6
7
8
9

Entry
CC
CO
CE
CF
DO
01
02
03
04
05
06
07
08
09
OA
DB
DC
DO
DE
OF
EO
El
E2
E3
E4
E5
E6
E7
E8
E9
EA
EB
EC
ED
EE
EF
FO
Fl
F2
F3
F4
F5
F6
F7
F8
F9
FA
FB
FC
FO
FE
FF

Replaced
ByITakes
Place Of

TRANSLATING CHARACTERS
In the previous discussion, you learned that the program
can alter the structure of characters by moving zones. But,
through the file translation function of the RPG II language,
it can do even more. It can translate one character into another.

Only column 43 in the RPG II control card relates to the
change in sequence. A letter F entered in column 43 notifies the computer that additional irformation furnished for
translating files. All other columns contain the information
that must normally be entered for a program.

The translating function is known as file translation because
characters can be translated either when they are read in or
before they are recorded in the output file. The program
acts like an interpreter. Just as a human interpreter translates languages (a word in German for a word in English),
the computer translates characters by replacing one character with another.

The Translation Table and Alternate Collating Sequence
Coding Sheet lists 256 bit combinations along with their
hexadecimal numerical values. You learned from discussions of character structure that the left-hand number in
the hexadecimal value represents the numerical value of the
character's zone and the right-hand number represents the
numerical value of the character's digit; The 64 printable
characters are listed beside the bit combination and hexadecimal values with which they are associated.

Need for File Translation

Coding the Translation

Think of the use for file translation when translating codes.
Codes are often used as a security measure to prevent access
to classified information. Information is recorded on cards
in coded form. In order to process the information, it must
be decoded. A coded character must be replaced by the corresponding decoded character.

Each character that will be affected during the translation
of a specified file must be identified on the coding sheet.
In the column entitled Replaced By, enter the hexadecimal
value of the character which is to replace the character presently associated with the bit combination shown. This
means that the character associated with the value found in
the Entry column will be translated into the character associated with the value entered in the Replaced By column.

For example, a firm which keeps all information 'classified
uses the characters in the word FITZGERALD as a code
for the numbers 0 through 9. F is the code for zero, I for
one, etc. When recorded on a card, the number 1432 appears as IGZT. If a field containing IGZT is read into the
computer and used in arithmetic operations, results received
are wrong. IGZT must first be decoded, or translated into
1432.

Figure 10-45 illustrates the entry made on the coding sheet
to translate a character. If an input file is to be translated,
this entry means that the letter F wi" be translated as the
number 0 (FO is the hexadecimal value associated with 0).

Character Associated
with Bit Combination

Specifying File Translation

System/3
Code

Figure 10-44 shows the forms on which you must specify
the way in which files are to be translated. One form consists of the RPG II Control Card and File Description sheet;
the other consists of the Translation Table and Alternate
Collating Sequence Coding Sheet for listing the characters to
be translated. Both forms are used in conjunction with the
RPG II Input, Output, and Calculation sheets.

Numerical Value of
Replacement Character

Graphic

Entry

11000100

0

C4

11000101

E

C5

11000110

F

C6

11000111

G

C7

11001000

H

C8

11001001

I

C9

\

Nu merical-V:;-ue
of Bit Combination

8-Position Bit Combination

Replaced
By

FO_~_

/

L

/

/

Is translated to 0

Figure 10-45. Explanation of File Translation Coding Sheet

10-44

(
\..

/

Specifications for file translation are identical to those used
to alter the collating sequence.

Forms Used for a File Translation

\,

(

\

)

If the output file is to be translated, this entry means that
the number 0 will be translated back into an F before being
written out. You can think of the character associated with
the value in the Entry column as being the character read in
or printed out. On the other hand, the character associated
with the values in the' Replaced By column is the character
represented in the machine (Figure 10-46).

Differences Between File Translation and Alternate
Collating Sequence
Because of the similarity of entries used in coding an alternate collating sequence and a file translation, these functions
may seem identical. They are not, however. The difference
occurs in the way the program works with the characters involved.
When alternate collating sequence is used, the characters
are altered only temporarily for sequencing operations.
The original bit combination of the character, obtained
from the punch combination for that character, is not
changed. Temporary substitution of another bit combination is done instead.

)

What Files Should Be Translated?
Any input files which contain information recorded in
coded form should be translated if correct results are to be
obtained. All characters which you specify to be translated
are translated whenever they are encountered. This means
if you specify an F to be translated to 0, all F's read in will
be translated. When there are several other fields on the
cards in addition to the one containing coded information,
remember all characters specified to be translated are translated regardless of fields.
When printing or punching information out, you mayor
may not find it necessary to specify file translation for the
output files. If you have translated (decoded) your input
file, you should translate information back into coded form
before it is written or punched out. If all F's are translated
as D's when read in, then all D's should be translated to F's
before they are put out. Keep in mind that only characters
which you specify are involved in the retranslation.

For file translation, bit combinations are actually changed.
As a result, one character is changed (translated) into another. This translation occurs before your program instructions are executed.

Worki ng With Data Structure

10-45

International Business Machines Corporation

Form X21·9096
Printed in U.S.A.

TRANSLATION TABLE AND ALTERNATE COLLATING SEQUENCE CODING SHEET
/

System/3
Graphic
1

Entry

Replaced
ByfTakes
Place Of

33
34
35

-

System/3
Graphic

Code
01100110
01100111
01101000
01101001
01101010

Entry

Replaced
ByfTakes
Place Of

66
67
6B
69
6A
6B
6C
60

-

-

---

- - -- -

-

-

--

'EFZTG

-

-

-

IIII

:;
Input File

Input data is
translated
u ..........

-

--

".~~. Un

-.-

EFZTG- 50324
50324 x 10 = 503240
503240- E F.ZTG F

-

System/3
Graphic

Code
10011001
10011010
10011011
10011100
10011101
10011110
10011111
10100000
10100001
10100010
10100011
10100100
10100101
10100110
10100111
10101000
10101001
10101010
10101011
10101100
10101101
10101110
10101111
10110000
10110001
10110010
10110011
10110100
10110101
10110110
10110111
10111000
10111001
10111010
10111011
10111100
10111101
10111110
10111111
11000000
11000001
11000010
11000011
11000100

~'*~~11000111
11001000
11001001
11001010
11001011

Entry

99
9A
9B
9C
90
9E
9F
AO
Al
A2
A3
A4
A5
A6
A7
A8
A9
AA
AB
AC
AD
AE
AF
BO
Bl
B2
B3
B4
B5
B6
B7
B8
B9
BA
8B
BC
BO
BE
BF
CO
A
Cl
B
C2
C
C3
0
C4
E
C5.
F - - r--=.
C6
G
C7
H
C8
I
C9
CA
CB

Replaced
ByfTakes
Place Of

&7
F~

F5

r:cd
F¥

/:1

Code
11001100
11001101
11001110 '
11001111
11010000
11010001
11010010
11010011
11010100
11010101
11010110
11010111
11011000
11011001
11011010
11011011
11011100
11011101
11011110
11011111
11100000
11100001
11100010
11100011
11100100
11100101
11100110
11100111
11101000
11101001
11101010
11101011
11101100
11101101
11101110
11101111
11110000
11110001
11110010
11110011
11110100
11110101
11110110
11110111
11111000
11111001
11111010
11111011
11111100
11111101
11111110
11111111

File Translation specifications used
for translating both input and output
files as follows:

Data is translated
before being put out
EFZTGF

F I T Z G ERA L

0

I 1I 2I 3I 4I 5I 6I 789
III

o

Output File

Figure 10-46. File Translation

1046

System/3
Graphic

}

J
K
L

M
N
0
P

a

R

S

T.
U
V
W
X

Y
Z

0
1
2
3
4

5
6
7
8
9

Entry
CC
CO
CE
CF
00
01
02
03
04
05
06
07
DB
09
OA
DB
DC
DO
DE
OF
EO
El
E2
E3
E4
E5
E6
E7
E8
E9
EA
E8
EC
ED
EE
EF
FO
Fl
F2
F3 '
F4
F5
F6
F7
F8
F9
FA
FB
FC
FO
FE
FF

Replaced
ByfTakes
Place Of

F8

1=';'

F.2

F=3

//

If you'do not specify file translation for output files, information is put out exactly as it is in the machine. If you
'do not intend to translate card or printer output files, be
certain that all characters from the input file are translated
into a value 'associated with a printable graphic. Anyhexadecimal value which does not have an associated graphic
cannot be written or punched out (Figure 10-47).' If an unprintable graphic is specified to be put out, a blank appears
in its place.

International Business Machines Corporation

Form X21·9096
Printed in U.S.A.

'TION TABLE AND ALTERNATE COLLATING SEQUENCE CODING SHEET

I Syste~:3

I

Entry

Replaced
ByITakes
Place Of

r+oi:::6~

"I;

-

lational Business Machin es Corporation

_: ALTERNATE CO LLATING SEQUENCE CODING SHEET

·am/3
ntry

II

Replaced
ByITakes
Place Of

-

I

j

C6 (F) when changed
to an AO can not be
printed for A o has
no associate d graphic.
The printer output
file must be translated so that AO
will print ou t as F.

'-

Code
10011001
10011010
10011011
10011100
10011101
10011110
10011111
10100000
10100001
10100010
10100011
10100100
10100101
10100110
10100111
10101000
10101001
10101010
10101011
10101100
10101101
10101110
10101111
10110000
10110001
10110010
10110011
10110100
10110101
10110110
10110111
10111000
10111001
10111010
10111011
10111100
10111101
10111110
10111111
11000000
11000001
11000010
11000011
11000100
11°0Q!9~
11000110
11000111
11001000
11001001
11001010
11001011

\

System/3·
Graphic

,

---

Replaced
ByITakes
Place Of

Entry
99
9A
9B
9C
90
9E
9F
AO
A"
A2\
A31
A4
A~ \

A6 I
A7 \
AB
A9 \
AA \
AB I
AC
AD
\
AE
\
AF
\
BO
\
Bl
\
B2
B3
B4
B5
B6
B7
BS
B9
BA
BB
BC
BO
BE
BF

J

.-

Code

10011011
10011100
10011101
10011110
10011111
10100000
10100001
10100010
10100011
10100100
10100101
10100110
10100111
10101000
10101001
10101010
10101011
10101100
10101101
10101110
10101111
10110000 '
10110001
10110010
10110011
10110100
10110101
10110110
10110111
10111000
10111001
10111010
10111011
10111100
10111101
10111110
10111111
11000000
11000001
11000010
11000011
11000100
11000101
11000110
11000111
11001000
11001001
11001010
11001011

System/3
Graphic

_.

Entry

Replaced
ByITakes
Place Of

11001100
11001101
11001110
11001111
11010000
11010001
11010010
11010011
11010100
11010101
11010110
11010111

99
9A
9B
9C
90
9E
9F
AO
Al
A2
A3
A4
A5
A6
A7
AS
A9
AA
AB
AC
AD
AE
AF
BO
Bl
B2
B3
B4
B5
B6
B7
B8
B9
BA
BB
BC
BO
BE
BF

~-:::-11011010
11011011
11011100
11011101
11011110
11011111
11100000
11100001
11100010
11100011
11100100
11100101
11100110
11100111
11101000
11101001
11101010
11101011
11101100
11101101
11101110
11101111
11110000
11110001
11110010
11110011
111101cV
111l¢ill

co
A
B
C
0
E
F
G
H
I

Cl
C2
C3
C4
C5
C6
C7

C8
C9
CA
CB

System/3
Graphic

Code

./

Fa>'

./

4,{:~::~
11111000
11111001
11111010
11111011
11111100
11111101
11111110
11111111

}

J
K
L

M
N

0
P

9
R

S
T
U
V
W
X
Y
Z

..

0
1
2

---

;Y
4
5
6
7
8
9

./

Entry
CC
CO
CE
CF
DO
01
02
03
04
05
06
07
08
09
OA
DB
DC
DO
DE
OF
EO
El
E2
E3
E4
E5
E6
E7
EB
E9
EA
EB
EC
ED
EE
EF
FO
Fl
F2 .,
F3
F4
F5
F6
F7
FB
F9
FA
FB
FC
FO
FE
FF

Replaced
By/Takes
Place Of

--

co
A
B
C
0

F
G
H

Cl
C2
C3

C4
C5_
C6
C7

C8
C9
CA
CB

C6 (F) when changed
to a FO will print
out as a zero. No
further translation
is necessary.

Figure 10-47. Printable Graphics
I

/
Working With Data Structure

10-47

Recording Specifications for the Translation Table
After you have written all specifications for file translation,
you can record them so that they can be entered into the
system. Records containing these specifications must be
formatted as follows:

Positions

Entry

1-6
or

*FILES

1·8

A filename

7-8

Blank if not required

9-96

Numerical values involved in translating
characters

If all files (both input and output) are to be translated, use
the entry *F I LES in positions 1 through 6. If only one file
is translated, use that filename in positions 1 through 8. If
several, but not all files, are to be translated, you must format separate records for each file.
, In positions 9 through 96, there are 22 groups of four positions. Each group (9-12,,13-16, etc.) must contain two
hexadecimal values involved in the translating of one character. The first two positions of the group are for the hexadecimal value taken from the Entry column of the Translation Table and Alternate Collating Sequence Coding Sheet.
The last two positions are for the hexadecimal value taken
from the Replaced By column of the coding sheet.

10-48

More than one record can be used to specify the characters
which must be translated. However, each additional record
must be formatted in the same way as the first. All records
for one file must be grouped together. An error will occur
if four records are entered in the following order:

1.

FILEA

2.

FILEA

3.

FILEB

4.

FILEA

Also, the first blank appearing in positions 9 through 96 is
recognized by the computer as the end of the translation
specifications. Consequently blanks should not appear between pairs of hexadecimal values.
A record containing * *L? (two asterisks and a blank) in positions 1 through 3 must precede the file translation records.
All records used for file translation except the RPG II control card must follow RPG II input, calculation, and output
specifications and must precede any tables or alternate collating sequence records used.

/

Review 10

Character Structure
1.

Into what two portions may every column of a 96-column card and every byte in
storage and on disk be divided?

2.

Do all characters that have an A zone punched in the zone portion of a 96-column
card have the same zone representation in storage? Why or why not?

3.

Calculate the numerical value of each of the following binary numbers as recorded in
one byte of storage:
a. 11000100.

b. 11010101.
c. 11101000.
d. 11110011.
4.

Express the numerical value of the bytes shown in Question 3 as a pair of numbers
(hexadecimal value), rather than as a single value.

Collating Sequence of Characters

)

5.

What does the computer use to determine the collating sequence of characters?

6.

Arrange the following characters in ascending collating sequence. Arrange the same
characters in ascending collating sequence by zone and digit.
Character

Hexadecimal
Value

I

Numerical
Value

C

C3

195

I

61

97

p

07

215

J

01

209

*

5C

92

T

E3

227

R

09

217

4

F4

245

6-

50

80

9

F9

249

0

FO

240

Review 10

10-49

Altering the Collating Sequence

7.

Fill in the Alternate Collating Sequence Coding Sheet to:
a. Insert a between U and V (use the # sign to represent
b. Make a blank fall in the same sequence as zero.

U

U).

Show how this information would be recorded in an alternate collating sequence
record.

8.

In what RPG II operations is the alternate collating sequence used? .

9.

Where is the sign located in a numeric field?·

Altering the Structure of Characters
10.

The TESTZ operation checks the zones of:
a. any position in a field.
b. only the low-order position in the field.
c. only the high-order position in a field.

11.

A field may be alphameric for any move zone operations. Check those fields (Factor
2, Result) which can be numeric for the following move zone operations:

Operation

12.

a.

MHLZO

b.

MLHZO

c.

MLLZO

d.

MHHZO

Factor 2

Result

Code the calculation specifications to make the contents of a positive numeric
AMTDUE field negative.

Translating Characters

13.

What is the difference between the way the computer works with characters involved
in an alternate collating sequence and the way it works with characters involved in
file translation?

14.

Fill in the coding forms to translate A's to l's and 8's to 3's. Show how these specifications would be recorded in a translation table record when all files are to be
translated.

(
10-50

Answers To Review 10

)
1.

Zone and digit.

2.

All characters which have the same zone punch in a 96-column card do not necessarily have the same zone representation in storage. There are four zone bits for
each character in storage and only two zone positions in a 96-column card column.
Therefore a translation must take place when the character is read. The computer
checks the entire punch combination (both zone and digit) of a character to determine
which bits are turned on or off in order to represent the character in storage.

3.

a. 196

o

o

1
0
1 0 0
128+64+0+0 + 0+4+0+0 = 196
b. 213
c. 232
d.243
4.

a. C4

o

1 0 0
1 1 0 0
C = 8+4+0+0 + 0+4+0+0 = 4
b. D5
c. E8
d. F3

5.

The computer uses the numerical values associated with characters to determine the
collating sequence of characters.

Answers To Review 10

10-51

6.

When characters are collated by zone and digit, they are collated in this order:
Character

Numerical
Value

,/

......

&

80

*

92

/

97

C

195

J

209

p

215

R

217

T

227

0

240

4

244

9

249

When characters are collated by zone the left half of the hexadecimal value is used to
determine the order; when collating by digit the right half of the hexadecimal value is
used. When characters are collated by zone or digit, several may hold the same position in the sequence and thus belong in the same group. Within that group they may
hold any position.

Characters collated by zone are in this order:
Character

Hexadecimal
Value Used

£0
~C

10-52

I

Character
0

&
/

Hexadecimal
Value Used
FO

}

*

}

*

5Q
61

/

61

C

Q3

J

Q7

C

~1

T

.Q9

4

F4

E3

p

07

F4

R

F9

9

FO

*

T

*

Characters collated by digit are in this order:

Characters within brackets
may be in any order since
they are in the same group.

}.
}.

01
C~

E3

09
F9
5C

* Characters within brackets
may be in any order since
they are in the same group.

7.
International Business Machines Corporation

)
Code

System/3
Graphic

~.

)

Form X21·9096
Printed in U.S.A.

TRANSLATION TABLE AND ALTERNATE COLLATING SEQUENCE CODING SHEET

00110100
00110101
00110110
00110111
00111000
00111001
00111010
00111011
00111100
00111101
00111110
00111111
01000000
01000001
01000010
01000011
01000100
01000101
01000110
01000111
01001000
01001001
01001010
01001011
01001100
01001101
01001110
01001111
01010000
01010001
01010010
01010011
01010100
01010101
01010110
01010111
01011000
01011001
01011010
01011011
01011100
01011101
01011110
01011111
01100000
01100001
01100010
01100011
01100100
01100101

Blank

"'\
\.
\.

Replaced
ByfTakes
Place Of

Entry
33
34
35
36
37
38
39
3A
3B
3C
3D
3E
3F
40
41
42
43
44
45
46
-\.47

Fm

~

4~

¢

<
(

+

I
&

4A\.
4B \.
4C ~
40
4E
4F
50
51
52
53
54

55_

!

$
)

-,
/

56
57
58
59
5A
5B
5C
50
5E
5F
60
61
62
63
64
65

---

\.

System/3
Graphic

Code

01100110
01100111
01101000
01101001
01101010
01101011
01101100
%
01101101
01101110
>
01101111
?
01110000
01110001
01110010
01110011
01110100
01110101
01110110
01110111
01111000
01111001
01111010 .•:~:::.;.
01111011 ::#':::
01111100 ':~~:::
01111101
=
01111110
"
01111111
10000000
10000001
10000010

66
67
68
69
6A
6B
6C
60
6E
6F
70
71
72
73
74
75
76
77
78
79
7A
7B

-~
70
7E
7F
80
81
B2
83

--

"'rn08QQ..l,

10000100
10000101
10000110
10000111
10001000
10001001
10001010
10001011
10001100
10001101
10001110
10001111
10010000
10010001

Jl4
8586
87
88
89
8A
8B
8C
-80

-

-

8E
8F
90
91
92
93
94
95
96
97
98

~.
10010100
10010101
10010110
10010111
10011000

2

3

..

5

Ii

Code
10011001
10011010
10011011
10011100
10011101
10011110
10011111
10100000
10100001
10100010
10100011
10100100
10100101
10100110
10100111
10101000
10101001
10101010
10101011
10101100
10101101
10101110
10101111
~ .112.110000
1011uuu
10110010
10110011
10110100
10110101
10110110
10110111
10111000
'-WJ..llOOI
101110llr10111011
10111100
10111101
10111110
10111111
11000000
11000001
11000010
11000011
11000100
11000101

r--

System/3
Graphic

...............

A
B
C
0
E

Replaced
ByfTakes
Place Of

Entry
99
9A
9B
9C
90
9E
9F
AO
Al
A2
A3
A4
A5
A6
A7
A8
A9
AA
AB
AC
AD
AE
AF
BO
Bl
B2
B3
B4
B5
B6
B7
B8
B9
BA

11001100
11001101

---.

r-M-BC
BO
BE
BF
CO
Cl
C2
C3
C4

---

1iOo011o ' F - - ~C6
11000111
11001000
11001001
11001010
11001011

G
H
I

Systcm/3
Graphic

Code

C7
C8
C9
CA
CB

-~--

CO
~

L
M

CF
DO
01
02
03
04

N

_OS

0
P

06
07
08
09
OA
DB
DC
DO
DE
OF
EO
El
E2

}

J
K

a
R

S
T

E3

::U:::',

::V::::::
~::: :W:::::
::: X:::::
::: y::::'
::: Z:::::
::: ::::::::::.,

...

. ::::::~:"

1l"T'roe9Q..':: :0;:::::
11110001 ::: ::t:::::::
11110010
11110011
11110100
11110101
11110110
11110111
11111000
11111001
11111010
11111011
11111100
11111101
11111110
11111111

Replaced
ByfTakes
Place Of

CC

~10Qlli.'L
11001111
11010000
11010001
11010010
11010011
11010100
11010101
11010110
11010111
11011000
11011001
11011010
11011011
11011100
11011101
11011110
11011111
11100000
11100001
11100010
11100011
11100100
11100101 :::
11100111
11101000
11101001
11101010
11101011
11101100
11101101
11101110
11101111

Entry

..'.

'.~:

3
4
5
6
7
8
9

E4
E5
E6
E7
E8
E9
EA
EB
EC
ED
EE
EF
FO
Fl
F2
F3
F4
F5
F6
F7
F8
F9
FA
FB
FC
FO
FE
FF

4~F0E57BE6E5E7E6E8E7E9E8

ALTSEQ
1

Replaced
ByfTakes
Place Of

Entry

1

•

9

10 11

12 Il M 15 11 17 18 It 20 21 2.2 Z3 24 25 26 27 21 29 30 31 32

E AE9

B
A

~M"~~mm~m"m~~~m~~~~~m~~~w~mmmmm~

8
4

B
A
8
4

2

2

~I

2 3'

"7"W"UU~~~~~~ro~un~~~naH~~U~

A

A

8
4

8
4

2

2

~u~~~n»»~~UO«6"a"d~~~~~~~~»~~~~nH~
A

A

8
4

8
4

2

2

1

"H~H"Mnnn»nnnnn~~~n"~"~""~~"n"""'
18N37oo

)
Answers To Review 10

10-53

8.

An alternate collating sequence is used only for alphameric compare operations and
matching or sequence checking operations done on match fields.

9.

The sign of a numeric field must be in the low-order (rightmost) position of the loworder byte.

10.

C

11.

Factor 2

Result Field

a.

X

b. X
c. X

X

d.
12.

RPG

IBM

Form GX21·9093
Printed in U.S.A.

CALCULATION SPECIFICATIONS

Internatlonel Busin... MKhine Corporation

12

Program

Date

Programmer

C

Indicators

At
~

~
~
~

3

Result Field

1

~

Line

Page [ [ ] of _

Operation

Factor 1

~

zb

~

~i

~~

zb

IIIIII

Comments

9 10 1112 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 5657 5859 60 61 62 63 64 65 68 67 68 69 70 71 72 73 74

4

5 6

C

II I

o
o

2

c

IORI

3

C

I I I

-

I

13.

10-54

lS

Length

Name

0 1

~

:i ~

Factor 2

Resulting
Indicators
Arithmetic
Plus IMinusl Zero
Compar.
1>211<211-2
Lookup(Factor 2)is
High Low Equal

757677787980

~~:;~f:ation I

I

W'-1

1
,.,

I, 2. ~,

MIL It

~ ~I

lJ

I

.1 '

AM IrlD I'l F=
AM ITn II

~

I

In file translation a character is actually translated into another character because the
computer changes bit combinations. All affected characters are changed for the entire
program. The bit combinations for characters involved in an alternate collating
sequence are not changed. Bit combinations are substituted for others during sequencing operations only.

/
I
\ ........

14.

\

)

International Business Machines Corporation

Form X21·9096
Printed in U.S.A.

TRANSLATION.TABLE AND ALTERNATE COLLATING SEQUENCE CODING SHEET

Code

)

00110011
00110100
00110101
00110110
00110111
00111000
00111001
00111010
00111011
00111100
00111101
00111110
00111111
01000000
01000001
01000010
01000011
01000100
01000101
01000110
01000111
01001000
01001001
01001010
01001011
01001100
01001101
01001110
01001111
01010000
01010001
01010010
01010011
01010100
01010101
01010110
01010111
01011000
01011001
01011010
01011011
01011100
01011101
01011110
01011111
01100000
01100001
01100010
01100011
01100100
01100101

System/3
Graphic

Blank

¢

<
(

+
I
&

!

$
)

-,
J

Entry
33
34
35
36
37
38
39
3A
3B
3C
3D
3E
3F
40
41
42
43
44
45
46
47
48
49
4A
4B
4C
40
4E
4F
50
51
52
53
54
55
56
57
58
59
5A
5B
5C
50
5E
5F
60
61
62
63
64
65

Replaced
ByfTakes
Place Of

System/3
Graphic

Code
01100110
01100111
01101000
01101001
01101010
01101011
01101100
01101101
01101110
01101111
01110000
01110001
01110010
01110011
01110100
01110101
01110110
01110111
01111000
01111001
01111010
01111011
01111100
01111101
01111110
01111111
10000000
10000001
10000010
10000011
10000100
10000101
10000110
10000111
10001000
10001001
10001010
10001011
10001100
10001101
10001110
10001111
10010000
10010001
10010010
10010011
10010100
10010101
10010110
10010111
10011000

%

-

>
?

:

#
@

=

"

Code
10011001,
10011010
10011011
10011100
10011101
10011110
10011111
10100000
10100001
10100010
10100011
10100100
10100101
10100110
10100111
10101000
10101001
10101010
10101011
10101100
10101101
10101110
10101111
10110000
10110001
10110010
10110011
10110100
10110101
10110110
10110111
10111000
10111001
10111010
10111011
10111100
10111101
10111110
10111111
11000000
11000001
11000010
11000011
11000100
11000101
11000110
11000111
11001000
11001001
11001010
11001011

66
67
68
69
6A
6B
6C
60
6E
6F
70
71
72
73
74
75
76
77
78
79
7A
7B
7C
70
7E
7F
80
81
82
83
84
85
86
87
88
89
8A
8B
8C
80
8E
8F
90
91
92
93
94
95
96
97
98

*FILES

B
A

Replaced
ByfTakes
Place Of

Entry

System/3
Graehic

Entry

Replaced
ByfTakes
Place Of

99
9A
9B
9C
90
9E
9F
AO
AI
A2
A3
A4

A
B
C
0
E
F
G
H
I

A5
A6
A7
A8
A9
AA
AB
AC
AD
AE
AF
BO
Bl
B2
B3
B4
B5
B6
B7
B8
B9
BA
BB
BC
BO
BE
BF
CO
Cl
C2
C3
C4
C5
C6
C7

Fl
F~

C8

C9
CA
CB

~~~~~mm~~~m~~~mmro~M$m~M~~~~m~mmm

}

J
K

L
M
N

0
P
Q

R

S
T
LT
V
W

X
Y
Z

0
1
2
3
4
5
6
7
8
9

Entry

Replaced
ByfTakes
Place Of

CC
CO
CE
CF
DO
01
02
03
04
05
06
07
08
09
OA
DB
DC
DO
DE
OF
EO
El
E2
E::l
E4
E5
E6
E7
E8
E9
EA
EB
EC
ED
EE
EF
FO
Fl
F2
F3
F4
F5
F6
F7
F8
F9
FA
FB
FC
FO
FE
FF

B
A
8
4

2
1

11001100
11001101
11001110
11001111
11010000
11010001
11010010
11010011
11010100
11010101
11010110
11010111
11011000
11011001
11011010
11011011
11011100
11011101
11011110
11011111
11100000
11100001
11100010
11100011
11100100
11100101
11100110
11100111
11101000
11101001
11101010
11101011
11101100·
11101101
11101110
11101111
11110000
11110001
11110010
11110011
11110100
11110101
11110110
11110111
11111000
11111001
11111010
11111011
11111100
11111101
11111110
11111111

System/3
Graphic

C1F1C2F3

8
4

B
A

Code

2
I

2

3

•

5

•

7

8
4
2

•

9

10 \I

12 13 .,. 15 \6 17 18 19 20 21 22 23 2' 25 26 272. 2. 30 3\ 32

1

B
A
8
4
2

~n~~~n~n~~uo«~~~~uro~~~~M~~"M~~~~"~
A

)

A

8

8

4
2

4
2
IBM 3700

Answers To Review 1 0

10-55

/

'I)'

c
10-56

Chapter 11. DEBUG

)
CHAPTER 11 DESCRIBES:

How to use the DEBUG operation.
Format of records created by DEBUG.

·BEFORE READING THIS CHAPTER YOU SHOULD BE ABLE TO DESCRIBE:

RPG Illogic for indicators (see Chapter 1, RPG /I Logic).

AFTER READING THIS CHAPTER YOU SHOULD BE ABLE TO:

Code the Control Card and Calculation specifications necessary to employ the
DEBUG operation.
Place the DeBUG operation within your program so that it will provide meaningful
data.
Note: You can use the review questions at the end of this chapter to test your comprehension of this topic. Answers follow the review questions.

)

)
DeBUG

11·1

INTRODUCTION ','

It would certainly be helpful to you to find out just how
far along in your program everything is working correctly.
But how can you find out information your program is
working with at various points in your program?

A program that you write may not always work perfectly
the first time or even the first few times it is run. The
reason for this is that the program contains errors - errors
that you were not aware you were making when you wrote
the program. Some of the errors you can make are easy to
find; others may be very difficult to find. Nevertheless,
they all have to be corrected. But how do you do this?
Where do you start?

The RPG II language has a special operation code which
shows you so~e 'ofth~ 'i'nfor~ati~~'th'e'computer is working with. This c()de is known as the DEBUG code. The
code received it~"name from the slang term "bugs" which
is used to mean errors in a program. To debug a program,
~
~:
J
therefore, means'to get all the errors out of it. This is what
the DEBUG code helps you do.
,

Just knowing the types of errors which are commonly made
can give you a hint as to w,hat YOLJ shoLJld check., Most of
the errors made fall into o~e of the fol'lowlng'tategories: ,.,,'
•

Incorrect use of RPG II entries on the specification~
sheets.

•

Errors in describing input data or the format bfoutput
data.

,

I

:'

.

.'

"

','ybu:

•

Specifying calclJl~ti~n'operationsin':the wro:ng se'quence.

The RPG II Compiler, when compiling your program, will
diagnose the specificatiohs t6 see if they contain errors. 1('
they do, the compiler will print messages teliirig:you the'"
errors made. In this way, you can find errors made in the
specifications.

USING THE DEBUG FUNCTION

You may, however, have made all correct entries on the
sheets and still get the wrong results. What can you do
then? You can, of course, check through your work. But
this does not always show you where the error(s) lies.
Sometimes, the specifications you write will not cause the
computer to do what you think they will. It is often possible to miss an error because you assume that a statement
or group of statements needed to perform a certain task
work correctly, when, in fact, they do not. For example,
you may pass statement 06 believing it is correct when it is
not and spend hours looking for errors in the rest of the
statements which are really correct.

!

I

';,

' , ' , ",

What data is contained in a specified field.

• What indicators are on.
, ~'.

Errors in specifying the calculation operations.

.'.

" The' DEBUG cotJe will"ciausec{maximum of two different
types of records to be printed or punched out showing

•

•

.

I :"",'"

J

I,

'.f

i.~ . .

One of the most commonerror~ found in a program is the
incorrect use of indicators. If the programmer fails to
thoroughly understand RPG' Ii"logfc, he may condition an
operation using an indicator which he thinks is on when it
is really not. Thus the program does not work properly.
If,' at any poiht'in your calculatiOn's, you want to check to
see if you are using indicators properly you can specify
DEBUG. This code will cause a record to be put out showing what indicators are on at the point DEBUG is specified.
If you wish to know the contents of a field in addition to
knowing what indicators are on, you can also specify so in
the DEBUG statement. A second record type will then be
put out showing the contents of the field.

/

Specifications for DEBUG

When using DEBUG, the first specification which you must
make is on the control card. A 1 in column 15 indicates
that DEBUG is going to be used (see Figure 11-1). If this
column is left blank, all DEBUG statements will be treated
as comments.
Then in columns 28-32 (Operation) on the Calcultion
sheet, specify the code DEBUG. You may specify it at any
point in the calculations and as many times as you want.
For each DEBUG statement, enter in columns 33-42 (Factor
2) the name of the file on which DEBUG records will be
written or punched (see Figure 11-1). Use the file name
previously assigned on the File Description sheet. The same
output file must be used for all DEBUG operations in a pro- (
gram.
",
\

"

r',

11-2

IBM

GX21-9092 UMI05O·
P\-intedinU.S.A.

RPG CONTROL CARD AND FILE DESCRIPTION SPECIFICATIONS
International Business Machine Corporation

75 76 77 78 79 80

Program
Programmer

::,,!~af:tioo I

Date

IIIII I

Control Card Specifications

i~~~OO~~~~~oo~Mroronnn~

all DEBUG specifications will be treated_as comments.

RPG

IBM

11T1111-[111 1 1 rill 1

Form GX21·9093
Printed in U.S.A.

CALCULATION SPECIFICATIONS

International Business Machine Corporation

1 2

Program

C

Indicators

~

0_

I---

~~~

t- 15 a:

EE

Operation

Factor 1

Factor 2
Name

~

15

85

~

7 8

9 10 11 t2 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 33 J4 35 36 37 J8

0 1

C

o

2

C

o

3

C

o
o

4

c
,..

o

6

o
o

8

C

5

z

Z

!nlcr-

9

C

1 0

c

I

I

C

I

2

C

I

3

C

II

40 41 42

.g £

Plus IMinusl Zero

~ ~

Compare

Comments

,>2£1<21,-2
~~ LookuplFactor 2)is
High Low Equal
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 M 69 70 71 72 73 74

4J

T PI IL 'E.

V

DEBUG may be specified at IL .....
any point in the program.
1,\ 1""-_

1-1o 7
'-I-

Ir.. '"

J9

Length

i

Arithmetic

~~

15

~
3 4 5 6

'->-

)

c/)..

2

75 76 77 78 79 80

[DOf_ ~~~~;~f:tion I I I I I I I

Resulting
Indicators

Result Field

AL At

-'0:

;iQ

Line

Page

Date

Programmer

....Ir EB JG hJ T'F III

\

~

"

\
\

Inl~t:l

~~

Ilf I~:r IL iE-

Figure 11-1. Specifications for DEBUG,

DEBUG

11-3

The ent\jes just descri~ed will give you a record showing
what indicators are on. If you also want to know the contents of a field, you must make another entry: The name
of the field whose value you wish to know must be entered
as the Result ,Field in Columns 43~48 (see Figure 11-2, insert A).

Format of Records Created by DEBl)G
Two records may be created by the DEBUG operation.
Record 1 is required; Record 2 is optional. Record 1 (Figure 11-3) will look like this:

Columns 18-27 (Factor 1) are optional. If you have several
DEBUG statements, you may wish to know which records
were caused by a particular DEBUG statement. You can
name the DEBUG statement by entering a literal in columns
18-27. This name will then be included in the records which
the statement causes to be put out (see ·Figure 11-2, insert

Positions

Entry

1-8

DEBUG =

9·16

The name entered in Factor 1 of the debug statement. These columns will be
blank if no entry is found in Factor 1.

17-18

Blank

19-33

INDICATORS ON

34

Blank

35-37,

Name of the indicators which are on.
Each indicator is followed by a blank.
If a large number of indicators are on,
more than one record may be requir~d
to show all indicators.

B).
Columns 7-17 may contain any valid conditioning indicator.
The external indicators Ul-U8 are most often used here.
They make the DEBUG statement optional. Through their
u'se you can establish, prior to a run, whether or not you
wish to use DEBUG (see Chapter 5, Controlling Operations
in an RPG /I Program for uses of Ul to U8). Columns
53-59 cannot be used for the DEBUG statement.

38-40,
etc.

RPG

IBM

Intern.tional Business Machine

CALCULATION SPECIFICATIONS

Form GX21-9093
Prlnted!n U.S.A.

Corpor.t~on
1 2

Program
Programmer

--C

Line

Indicators

~

~L

~~

~~~
'0 a:

Operation

Factor 1

Jd

'0

~85~

3

4

o

1

C

o
a

2

C

3

C

o 4
o ;

C

c

a

C

I

Result Field

Factor 2
Name

E ::: en

6

Page

Date

I-

5

=

6

7

8

Length

'0

z

z

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2829 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 4i; 47 48 49 50 51

®
I~
I

I

1"'1J::IA r...r

IT~ Ir LIE.

75 76 77 78 79 80

[00'_ :~;~;'ation I I I I I I I

R..ulting
Indicators
Arithmetic
Plus JMinusJ Zero
Compare
1>211<211-2
Lookup(Factor 21is
High Low Equal

Comments

54 55 5657 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

!=Lr IE.IL "

plR [INT trJ\l nit r:II IFIL 10

J:r 1:1 r

N,Jl 1'11,;

I I

I

\ I....

. . . 1 ....

I.... ,

'

OE. IBJ r.. 1"'1 Jtr Ftr

IE

nle R

,:,..

I

Figure 11-2. Additional Entries Which Can Be Made for DEBUG

(
\" ..

114

Record 2 (Figure 11-3) will look like this:

)

Positions

Entry

1-14

FIELD VALUE

15 -

The contents of the field named as the
result field in the debug statement. If
the field is rather large, only 80 of the
rightmost characters are displayed.

example, if you are concerned about the status of an indicator at a certain point in your program, be sure to position
DEBUG so that the indicator has no chance to change before it is displayed.

=

Getting Results from DEBUG
DEBUG will not automatically provide you with the specific
reason your program is in error. But by showing the indicator setting and contents of fields at various points, it can
give you a clue as to where the error lies. From there, you
will have to work through the logic of sections in your program to find specific bugs.

Placement of DEBUG
DEBUG statements can be placed anywhere in the calculations. However much thought should be given to their position. If they are not placed in proper positions, they may
give misleading information and be of no help at all. For

If you want to find out if a statement or group of statements is working correctly you must know what is in the
field involved immediately before and after the statement(s).
This means placing DEBUG before and after the statement(s) you are checking. In order to determine if the results obtained from these statements are correct, you will
have to manually make the same calculations and compare
the two results. In this case, however, you must make certain your own calculations are correct. Much time can be
wasted trying to make the computer arrive at the same
wrong answer you have calculated.

Making Your Program Work for All Cas.es
Be certain that you test your program to see that it will
handle correctly all possible situations which might arise.
If you test for only one or two situations, you can be sure
your program works only for those situations. This means
that the data you use to test your program be complete
and valid so that it tests all possible situations. In this way,
you can be sure your program can handle all situations
without encountering hidden 'bugs'.

)
Record 1
DEBUG = DEBUG 1

INDICATORS ON = 204202 11 MR

Record 2
FIELD VALUE

= 005648219R

Figure 11-3. Format of DEBUG Records

)
DEBUG

11-5

(
\.

(
11·6

Review ,11

./,'

1.

What does DEBUG do in an RPG II program?

2.

Write a DEBUG statement to display on the file called OUTFILE a field called
ANSWER and the indicators that are on at this point. Identify the DEBUG records
with the constant - TEST1. What entries in other specification sheets must be made?

J
./

Review 11

11-7

Answers To Review 11

1.

DEBUG allows you to display the contents of a data field in your program and to list the
indicators that are on.

2.

A 1 must be entered in column 15 of the RPG II control card.

RPG

IBM

Intlm.,ionel Bu.ioeu MKhin.

Form GX21·9093
Printed in U.S.A.

CALCULATION SPECIFICATIONS

Corpor.~on
1 2

Program

Oat.

Programmer

C

4

0_

=0
-'II:

!~~

Line

3

5

Jd

~g~
&~5I
6

0 1

C

0 2

C

o

3

C

0 4

C

'11-8

Indicators

~

r--

Page

7

8

Result Field

Jd

Factor 1

Operation

:i ~

Factor 2
Length

Name

z1>

l!I

~

~i
~~

15

Z

75 76 77 78 79 80

[00'_ ~~~;~':ation I I I I I I I

R..ulting
Indicators
Arithmetic
Plu. \Minus\ Zero
Compar.
1>2\1<2\1-2
Lookup(Factor 2lis
High Low Equal

Comments

9 10 11 12 1314 15 16 17 18 Ii 20 21 22 23 24 25 26 27 26 29 30 31 32 33 34 35 36 37 36 39 40 41 42 43 44 45 46 47 48 49 50 51 52 63 54 55 5657 5859 50 61 62 63 64 65 66 67 68 69 70 71 72 73 74

'IT I~~ h"lL

I

In:r is:. I.

~h IUT il=l1

LIE

1\

~

,..If'!!

Index

* (asterisk; star), printing on cards 4-3
* * (look ahead fields) 5-21
*PLACE 3-19
conditioning by indicators 3-22
used with EXCPT 7-26
*PRINT (unformatted printing on cards)

4-6

accumulating totals 5-59
advancing printer forms 3-6
aligning printer forms 3-12
altering character structure 10-38
altering the order of file processing 7-2
alternate collating sequence 10-27
alternating format
arrays 9-3
tables 8-12
alternating processing of files 7-4
ALTSEQ card 10-38
arithmetic operations
using.<1 results 5-13
arrays
accumulating groups of totals 9-14
adding elements (XFOOT) 9-8
array to array calculations 9-4
calculations with single fields or constants
compile time arrays 9-35
defining 9-2
of different lengths 9-7
editing 9-11
execution time 9-38
indexing 9-20
loading
compile time 9-36
execution time 9-38
pre-execution time 9-36
LOKUP 9-27
MOVEA operation 9-44
operation codes, restrictions 9-7
output
during a search 9-34
of an entire array 9-9.
of individual elements 9-22
pre-execution time 9-36
referencing all elements 9-4
referencing individual elements 9-19
referencing part of an element 9-23
,. storing data into (see loading)
when to use array instead of table 9-2
XFOOT 9-8
artificial control break (LO) 5-56
asterisks, punctuating with 3-16
automatic overflow (page formatting) 3-2

)

\,

balances (see editing)
BEGSR (begin subroutine) operation code 5-48
binary field operations 5-67
BITOF operation code 5-67
BITON operation code 5-67
TESTB operation code 5-68
binary format 10-19
BITOF (set bits off) operation code 5-67
BITON (set bits on) operation code 5-67
bits (numerical value of) 10-13
blank after function (with resulting indicators) 1-31
branching in calculations
backwards 5-42
bypassing calculations 5-36
for an error condition 5-41
GOTO operation code 5-36
in a matching records job 5-41
repeating calculations 5-42
TAG 5-36
when different record types require different operations
bypassing calculations 5-36
bytes, definition 10-4

9-7

5-41

calculation specifications
using results of arithmetic operations 5-13
for arrays
accumulating groups of totals 9-14
adding all fields (XFOOT) 9-8
array to array 9-4.
using single fields or constants 9-7
binary field operations 5-67
branching 5-36
conditioning 5-7,5-12,5-59
subroutines 5-44
used to control input and output 7-1
using table data 8-14
(see also individual operation codes)
card column structure 10-2
card path, MFCU (diagram). 5-17
card type, stacker selection based on 4-15
cards, printing on 4-2
cards, stacker selection of 4-14
carriage tractors (see dual feed carriage)
catch-all record identifying indicator 2-15
CHAIN operation code (see IBM Systeml3 RPG II Disk File
Processing Programmer's Guide, GC21-7566)
changing field type 5-34
changing array data
compile time 9-36
execution time 9-38
pre-execution time 9-36
changing table data
compile time 8-22
pre-execution time 8-26

./

Index

X-1

character set 10-2
character groups with zones that test equal 10-9
character structure
altering 10-39
on cards 10-6
negative number 10-3
in storage (core or disk) '10-4,
characters, translating, 10-44
checking tor duplicate records
using look ahead 5-20
using move operations 5·31
checking sequence' of records
using match fields 6-2
using move operations 5-31
checking sequence of record types 2·6
codes, use in file translation 10-44
collating sequence
altering of 10-30
ALTSEQcard 10-38
specifications 10-38
by zone or digit 10-25
combined file
definition 4-8
used with look ahead 5-28
used to read and punch the same card 4-8used with stacker selection 4-14,4-17
compare operations
using the results 5-14
compile time arrays 9-35
compile time tables 8-25
conditioning calculations
based on information in next card 5·17
based on LOKUP operation 8·14,9·27
based on results of other calculations - 5·12
using external indicators 5-7'
using halt indicators 5·2
using overflow indicators 5-11
conditioning use of input files 2~19, 2·22 '
conditioning operations when storing array data '9·49
conditioning output operations '5·2
conditioning subroutine statements 5·54
consecutive file (see IBM System/3 RPG /I Disk File Processing
Programmer's Guide, GC21·7566)
in calculations with arrays 9· 7
use in editing 3-18
control break 2·2
artificial (LO), 5-56
control card
alternate collating sequence 10-38
file translation 10-48
setting external indicators (Model 10 Card System) 2·21
control fields
definition 1·5
logic for initial program cycles' 1·7 '
with field record re-fi:ltion '2·18'
with match fields 6-34
split control fields 2·5
control group
determining first only record in 5-26
determining last record in 5·28
incorrect records in 2·11
number of each record type in 2·11

optional record types in 2·'11
order of record types in 2·6
sequenced and unsequenced record types 2·14
unexpected or unused record types in 2·14
control level indicators
artificial control break (LO) 5·56
to condition calculations 5·59
to condition subroutines 5·54
fi rst cycle difference 1·7
general use 1·5
group printing 5·59
special use 5-55
controlling printer output 3·1
cycle, RP\.i Illogic 1·1
first cycle 1·7
last cycle 1·16

dashes, punctuating with 3·16
data structu re 10-1
binary format 10-20
negative numbers 10-3
packed decimal format 10-19
unpacked decimal format 10-19
DEBUG function 11·1
format of debug records 11·4
decimal positions in table entries 8-7
demand files (READ operation) 7·24
end-of.file indicator 7·24
coding rules and considerations 7·26
designing table. input records - 8-4
detail time
logic 1·6
operations 1·4
device name, dual carriage printers
PRI NTER; PRI NTR2 3·28
TRACTR1; TRACTR2 3·29
digit, collating by 10-25
digit portion of character
card 10-2
disk 10-4
direct files (see IBM System/3 RPG II Disk File Processing
Programmer's Guide, GC21·7566)
dollar sign, punctuating with 3-14
,fixed 3-14
floating 3-14
dual feed carriage printer 3·27
dual input/output areas 5-69
dummy match field 6-10
duplicate information, printing (*PLACE) 3-19
duplicating constants 3·24
duplicate records, checking for 5-20

edit codes 3-12
chart 3-13
edit words 3-12, 3-16
editing
definition 3-12
arrays 9-11
I/'
i

)

)

'"\ I

)

with asterisks 3-16
with blanks 3-18
on cards 4-8
with constants 3·18
with dashes 3·16
end position 3-19
fixed dollar sign 3-14
floating dollar sign 3-14
zero balances 3-13
zero suppression 3-13
element
array 9-2
table 8-2
end·of.file
input file 2·23
FORCE operation 7·11
multi·file processing 6-30
READ operation (demand files) 7·24
end of job (see end·of·file external indicator; halt indicator;
last record indicatod
end position
when editing 3-19
when using *PLACE 3·22
ENDSR operation code 5-48
entries (see table entries)
equal search condition 8-19
error conditions 5-41
(see also halt indicators, Hl·H9)
errors in program, finding 11·1
EXCPT operation code 7·26
conditioning EXCPT 7·29
used in a loop 5-42
with *PLACE 7·26
execution time arrays 9-38
EXSR operation code 5-48
extension specifications
for arrays 9-2
for one table 8-5
for two tables 8-13
external indicators (U1·U8)
conditioning input files and calculation operations 5-7
conditioning input files 2·19,2·22
conditioning input files and output operations 5-8
conditioning output file and output operations 5-9
conditioning output operations only 5-11
setting on Model 10 Card System !indicator contror'card) 2·21
setting on Model 10 Disk System and Model 15 (SWITCH OCL
statement) 2·21
setting on Model 6 (SWITCH keyword) 2·22

fetch overflow 3·8
field indicators, logic 1·25
field record relation
with control fields 2·18
with match fields 6-8
OR relationship with 2·16
field scanning 9-23
file designation
'determining whether file should be primary or secondary
file translation 10-42
final totals, printing 5-59

6-38

first page (1 P) indicator, logic 1·13
first program cycle 1·7
fixed dollar sign 3-14
floating dollar sign 3-14
FORCE operation code 7·2
altering the order of file processing 7·2
alternating processing between tvvo files 1·4
controlling number of FORCE operations 7·9
controlling processing at end-of.file 7·11
effect on MR 7·22
with look ahead 7·15
performing matching records without match fields
use of trailer card 7·12
format of data (see data structure)
format of DEBUG records 11·4
formatted printing on cards 4-2
formatting reports 3-2
forms advance (fetch overflow) 3-~ 2
forms alignment 3-12
forms length 3-4

GOTO operation code
group indication 2·2
group printing 5-59

7·15

5-36

halt indicators
conditioning operations 5·2
logic cycle 1·35
halting
for record out of sequence in a control group 2·10
for record out of sequence in a file 6-5.
for errors in data 5-2
for incorrect record type in a control grouil 2·13
hexadecimal values (chard 10-18
high search condition
arrays 9-31
tables 8-19

increasing speed of input and output (dual 1/0 area)
indexing arrays 9-20
indicators
definition 1·2
control level (L1·L9)
function 1·5
special uses 5·55
to control calculations and output
external (U1·U8)
conditioning operations 5-7
,b:·
setting 2·21
field indicators, logic 1·25
field record relation 2·16
first page (1P), logic 1·13
halt indicators (Hl·H9)
logic 1·35
to prevent operations on an error 5-2

5-69

Index

X·3

last record (LR), logic 1-16
LO 5-55
matching records (MR), logic 1-42
overflow (OA-OG, OV) 3-4
record identifying, logic 1-19
resUlting
logic 1-31
use with arithmetic operations 5-13
setting indicators (SETON, SETOF) 1-43
indicator control card (Model 10 Card System) 2-21
input areas, dual 5-69
input data, storing in execution time arrays 9-38
input files
conditioning use of 2-19
merging input and output cards 4-27
stacker selection 4-14
input, programmed control of 7-1
input records
arrays 9-35
tables 8-4
interpreting punched data 4-2

last record (LR) indicator, logic 1-16
level indicators (see control level indicators)
line counter specifications 3-4
loading arrays
compile time 9-36
execution time 9-38
pre-execution time 9-26
loading tables
compile time 8-25
pre-execution time 8-26
logic, basic data processing 1-2
logic, RPG II (see RPG Illogic)
LOKUP operation code
arrays 9-27
with one table 8-7
with two tables 8-14
look ahead feature
checking for duplicates 5-20
with combined or update files 5-28
finding last record in group 5-28
with FORCE 7-15
logic cycle for 5-23
with MFCU files 5-17
records available 5-18
to find single record groups 5-26
specifications 5-20
loop in calculations 5-42
loop with EXCPT 5-42
low search condition
arrays 9-33
. tables 8-20
LR (last record) indicator 1-16
LO (internal control level indicator) 5-55 .
L 1-L9 indicators (see control level indicator~)

match fields
assigning, rules for 6-7
with control fields 6-34
definition 6-1
dummy match field entry 6-10
with field record relation 6-8
rules 6-10
in different locations in a file 6-26
M1-M9 entries 6-2
sequence checking with
one record type in file 6-2
more than one record type 6-6
matching records
definition 6-2
with control fields 6-34
end-of-file with 6-30
first cycle 6-14
performed using FORCE with look ahead 7-15
logic cycle 6-14, 6-38
more than one matching secondary 6-12
more than one record type in a file 6-26
one record type in each file 6-12
processing records without match fields 6-29
record identifying indicator with
6-14
total operations with 6-14,6-34
matching records indicator (see MR)
merging input and output file cards 4-24
MFCM output operations 4-1
printing on cards 4-2
formatted 4-5
unformatted (*PRINT) 4-6
punched output 4-2
combined files 4-8
stacker selection 4-14
MFCU files, look ahead with 5-17
MFCU output operations 4-1
printing on cards 4-2
formatted 4-3
unformatted (*PRINT) 4-6
punched output 4-2
combined files 4-8·
interpreting punched data 4-2
summary punching 4-2
stacker selection 4-14
MHHZO (move high order zone to high order zone)
operation code 10-40
MH LZO (move high order zone to low order zone)
operation code 10-40
MLHZO (move low order zone tohigh order zone)
operation code 10-40
MLLZO (move low order zone to low order zone)
operation code 10-40
modifying table contents 8-22
MOVEA operation code 9-44
move zone operation codes 10-39
example 10-41
field format 10-41
model character 10-42
operation codes 10-41
moving data
to change the field type 5-34
MOVE operation code
MOVEL operation code

,/

\,

(

(
Index

X-4

)

to sa . information 5·31
to separate fields into two parts 5·33
in a table entry 8·22
MR (matching records) indicator
effect of FORCE on 7-22
logic cycle 1-42
used to condition subroutines 5·54
when on 6-17
when turned on 6-14,6-22
multifile processing
definition 6-2
end-of-file specification 6-30
general description of logic 1-42
(see also match fields; matching records; MR indicatod
M1-M9 (see match fields)

output-format specifications
arrays
during an array search 9-34
entire array 9-9
individual fields 9-22
dual feed carriage printer 3-27
staCkerieection using 4-15
using tabl data 8-14
output area, dual 5-69
output car· s
mergip'g with input cards 4-19
stacker selecting 4-17
output operations
conditioned by external indicators
MFCU 4-1
output, printer 3-1
output, programmed control of 7-1
output, table 8-28

5-8

overflow
negative numbers, structure of 10-3
number of each record type in a control group
numerical values
of bit combinations 10-12
of zone and digit portions 10-15

automatic
2-11

3-2

fetch overflow 3-8
calculations with 5-11
1-41,3-2

indicators

line counter specifications
logic 1-41
overflow line, standard

3-4

3-2

. overlay, controlling with subroutines

)

object program cycle (see RPG II logic)
operation codes
BEGSR 5-48
BITOF 5-67
BITON 5-67
DEBUG 11-1
ENDSR 5-48
EXCPT 7-26
used in loop 5-42
EXSR 5-49
FORCE 7-2
GOTO 5-36
LOKUP 8-14,9-27
MHHZO 10-40
MHLZO 10-40
MLHZO 10-40
MLLZO 10-40
MOVE 5-29
MOVEA 9-44
MOVEL 5-29
READ 7-22
TAG 5-36
TESTB 5-68
TESTZ 5-14
XFOOT 9-8
operations
arithmetic, using results of 5-13
binary field 5-59
compare, using results of 5-14
controlling with look ahead 5-17
detail
1-4
total 1-4
optional record types in a control group
OR relationship 2-15
with field record relation 2-16
with stacker selection 4-15

5-54

packed decimal format 10-19
*PLACE
with constants 3-24
different spacing 3-23
with EXCPT 5-42
formation of print lines

3-22

with indicators 3-24
specifications 3-22
pre-execution time arrays

9-36

pre-execution time tables 8-25
preventing operations when an error occurs 5-2
primary files, determining whether files should be primary or
secondary

6-38

primary tractor (dual printer files)
PRINTER device name 3-28
*PRINT

3-37

4-6

Printer files, dual }:27
printer forms alignment . 3-12

2-11

printer forms, designing 3-12
printer output, controlling 3-1
printing duplicate information 3-19
printing on cards 4-2
printing only final totals 5-59
printing over the perforation 3-6
PRI NTER2 device name 3-28
print-head (MFCM) 4-5
processing order of files (see matching records; multifile processing)
program cycle 1-2
(see also RPG II logic)
programmed control of input and output 7-1

Index

X-5

program errors, finding (see DEBUG)
punch combinations 10-2
punched output (MFCU) 4-2
summary punching 4-2
punching into a blank card 4-11
punching into the same card that is read
punctuating a field (see editing)

4-8

reading and punching the same card 4-8
READ operation code 7-22
record identification code 2-6
record identifying indicators
catch-all indicator 2-15
in field record relation 2-15
logic for 1-19
with matching records 6-14
in sequence checking record types 2-9
recording specifications for an altered collating sequence
records, designing table input 8-4,8-11
record types
branching in calculations for different 5-41
OR relationship of 2-15
sequence checking of
2-9
reducing coding and storage requirements
in calculations (subroutines) 5-44
in describing similar or identical records (field record
relation) 2-15
when printing duplicate information 3-19
when punching and printing cards 4-8
reducing job time
dual input/output areas 5-69
referencing individual array elements 9-19
related tables 8-13
repeating calculations
by branching 5-42
using subroutines 5-45
repeating the first print line 3-12
repetitive output (EXCPT operation) 7-26
resulting indicators
with arithmetic operations 5-13
logic for 1-31
with LOKUP 8-7,9-27
with READ 7-22
with TESTB 5-68
rolling of totals (arrays) 9-14
RPG II logic
detail time 1-6
fetch overflow 3-8
first program cycles 1-7
related to indicators 1-7
field indicators 1-25
first page (1 P) indicator 1-13
halt indicators (H 1-H9) 1-35
last record indicator (LR) 1-16
matching records indicator (MR) 1-42,6-14
overflow 1-41
record identifying indicators 1-19
resulting indicators 1-31
setting indicators 1-43
total time 1-6

10-38

saving disk storage space
binary data format 10-20
packed decimal format 10-19
saving information by move operations 5-29
scanning fields 9-23
searching arrays 9-27
determining search success 9-30
for a particular element 9-27
output during search 9-34
starting the search at a particular element 9-28
referencing the element found 9-31
searching tables 8-2
for high, low, or equal 8-19
referencing the data found 8-.16
secondary file
determining whether a file should be 6-38
secondary tractor (dual carriage printer) 3-27
selecting a stacker on the MFCU 4-14
separating a field into two parts 5-33
sequence checking
by calculation specifications 5-31
of a file using match fields 6-2
of record types in a control group 2-6
sequential disk file (see IBM Systeml3 RPG /I Disk File Processing
Programmer's Guide, GC21-7566)
setting external indicators 2-21, 2-22
setting indicators (SETON, SETOF) 1-43
SETOF operation code 1-43
SETON operation code 1-43
short tables 8-23
skipping 3-29
skipping calculations (branching) 5-36
spacing 3-29
split control fields 2-6
with field record relation 2-18
SR (subroutine) lines 5-48
stacker selection 4-14
at total time 4-17,5-10
of combined file cards 4-17
of input cards
based on calculations 4-15
based on card type 4-15
of output fi Ie cards 4-17
of unmatched records 6-24
standard forms length 3-2
standard overflow line 3-2
storing data into execution time arrays 9-38
structure of characters (see character structure)
subroutines
calling 5-48
conditioning 5-54
fields available 5-49
limitations 5-52
overlays 5-52
repeating calculations 5-45
specifications 5-48
valid operations in 5-52
subtotals (group printing) 5-59

('

' .......

_______I-'-'ndex_><..6

----------------------------------------

/

)

summarizing data (group printing) 5-59
summary punching 4-2
example 5-10
suppressing leading zeros 3-13
SWITCH keyword (Model 6) 2-22
SWITCH OCl statement (Model 10 Disk System
Model 15) 2-21
switches
binary field operations 5-67

update files, look ahead with
U1-U8 indicators 2-19

5-28

and~

tables 8-1
assigning !able names 8-6
binary table data 8-7
compared to arrays 9-2
compile time 8-25
definition 8-2
describing input records 8-5
designing input records
one table 8-4
two tables 8-11
entries with decimal positions 8-7
length of entry 8-6
loading 8-25
modifying contents of
8-22
moving data in an entry 8-22
number of entries per input record 8-4, 8-6
number of entries per table 8-6
number of input records required 8-4
output 3-28
packed table data 8-7
pre-execution time 8-25
related 8-8
searching 8-2, 8-14
sequence 8-7
short 8-23
TAG operation code 5-36
TESTB operation code 5-60
testing the con,~ents of a field 5-12
TESTZ operation code 5-14
character groups with zones that test equal (table)
total operations
logic 1-6,6-38
with matching records 6-14,6-34
tractors (dual carriage printers) 3-27
TRACTR1 device name 3-29
TRACTR2 device name 3-29
trailer card
use in force operation 7-12
translating characters
coding for 10-44
forms used 10-44

XFOOT operation code

9-8

zero balances 3-13
zero, negative 10-3
zero suppression 3-13
zone portion of character
collating by 10-25
testing (TESTZ) 5-14
zones that test equal (table)
zone punches 10-2

10-10

OA-OG, OV indicators (see overflow indicators)
01-99 indicators (see record identifying indicators: resulting
indicators: field indicators)
1P indicator logic for 1·13
1403 Printer 3-2
2222 Printer 3-27
2560 MFCM 4-2
5203 Printer 3-27
5213 Printer 3·2
5424 MFCU 4-2

10-10

unexpected record types in a group 2-14
unformatted printing on cards (*PRINT) 4-4
unmatched record
stacker selection of 6-24
unsequenced record types in a control group 2-14

Index

X-7

/'

READER'S COMMENT FORM

)

IBM System/3
RPG II Additional Topics
Programmer's Guide

GC21·7567·2

YOUR COMMENTS, PLEASE •••
Your comments assist us In Improving the usefulness of our publications; they are an important
part of the input used in preparing updates to the publications. All comments and suggestions
become the property of IBM.
Please do not use this form for technical questions about the system or for requests for additional
publications; this only delays the response. Instead, direct your inquiries or requests to your IBM
representative or to the IBM branch office serving your locality.
Corrections or clarifications needed:

Comment

Page

)

Please include your name and address in the space below if you wish a repl.,'.

•

Thank you for your cooperation. No postage necessary if mailed in the U.S.A.

GC21-7567-2

Fold

Fold

NO POSTAGE
NECESSARY
IF MAILED
IN THE
UNITED STATES

)

c

,..f

S

BUSINESS REPLY MAIL
FIRST CLASS

PERMIT NO. 40

c:

ARMONK, N.Y.
'\

\,

POSTAGE WI LL BE PAID BY ADDRESSEE:

I BM Corporation
General Systems Division
Development Laboratory
Pu bl ications, Dept. 245
Rochester, Minnesota 55901.

ac:
Fold

Fold

G

('
1\

.
.~
to:

a

International Business Machines Corporation
General Systems Division
875 Johnson Ferry Road N. E.
Atlanta, Ga. 30342
IBM World Trade Corporation
821 United Nations Plaza, New York, New York 10017
--(Internation-al)----------------------------------------

READER'S COMMENT FORM

)

GC21-7567-2

IBM System/3
RPG II Additional Topics
Programmer's Guide

YOUR COMMENTS, PLEASE ...
Your comments assist us in improving the usefulness of our publications; they are an important
part of the input used in preparing updates to the publications. All comments and suggestions
become the property of IBM.
Please do not use this form for technical questions about the system or for requests for additional
publications; this only delays the response. Instead, direct your inquiries or requests to your IBM
representative or to the IBM branch office serving your locality.
Corrections or clarifications needed:
Page

Comment

)

Please include your name and address in the space below if you wish a reply.

•

Thank you for your coooeration.

No on!:t~np

npt'PC:C:<>ru

if .,.,,,ilo"" i~ +I.~

I I ...

A

GC21-7567-2

Fold

Fold

III

NO POSTAGE
NECESSARY
IF MAILED
IN THE
UNITED STATES

»
0.

0.
;::;"

o·

BUSINESS REPLY MAIL
FIRST CLASS

PERMIT NO. 40

::J
Q)

-i

r

ARMONK, N.Y.

POSTAGE WILL BE PAID BY ADDRESSEE:

-n
(1)

Z

IBM Corporation
General Systems Division
Development Laboratory
Publications, Dept. 245
Rochester, Minnesota 55901

Fold

?

Cf)

w

~
~

Fold

I nternational Business Machines Corporation

General Systems Division
875 Johnson Ferry Road N. E.
Atlanta, Ga. 30342

IBM World Trade Corporation

I~---­

I"
I

~~821-Un~~Nation~P~H~New~MkrNew~Mk~Oml~~~~~~~~~~~~~~~~~~~~~~~~JI~~~
(I nternational)

I

'\

)

)

_.....

:.

~

",

'.

>,

-.
-"

i

\

,
~~..:

"

.:- \ ~ ,.,0'.

IT:

:"

,;

; :

~ ~;j

1 -:

'"!

,i.) III ~\',H'

,I

t

II I ;

I' ~

~

'l'

..

c

-,;)\'1 • ~ ~ , I ,

;~ t

I • ..

~ ~ 1~

.:" ~ j

;"ilii( I~' I.I f.di;)1t
; , , \ i:; PIt. i ~ f.; Ii, Ii;

[.

~ ,: ~ j

:"Ii':'

"

i

I

:

'~i," i .~

,'it"

"

-



Source Exif Data:
File Type                       : PDF
File Type Extension             : pdf
MIME Type                       : application/pdf
PDF Version                     : 1.3
Linearized                      : No
XMP Toolkit                     : Adobe XMP Core 4.2.1-c043 52.372728, 2009/01/18-15:56:37
Create Date                     : 2011:10:08 19:02:12-08:00
Modify Date                     : 2011:10:09 02:32:58-07:00
Metadata Date                   : 2011:10:09 02:32:58-07:00
Producer                        : Adobe Acrobat 9.46 Paper Capture Plug-in
Format                          : application/pdf
Document ID                     : uuid:a616902a-c44a-4f6a-ac26-c01473585c7e
Instance ID                     : uuid:ad8d8a13-bd6b-4c68-991d-bb0f10cde495
Page Layout                     : SinglePage
Page Mode                       : UseNone
Page Count                      : 516
EXIF Metadata provided by EXIF.tools

Navigation menu