GC21 7567 2_IBM_System3_RPGII_Additional Topics Programmers Guide_Dec79 2 IBM System3 RPGII Additional Guide Dec79

GC21-7567-2_IBM_System3_RPGII_AdditionalTopicsProgrammersGuide_Dec79 GC21-7567-2_IBM_System3_RPGII_AdditionalTopicsProgrammersGuide_Dec79

User Manual: GC21-7567-2_IBM_System3_RPGII_AdditionalTopicsProgrammersGuide_Dec79

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

DownloadGC21-7567-2_IBM_System3_RPGII_Additional Topics Programmers Guide_Dec79 GC21-7567-2 IBM System3 RPGII Additional Guide Dec79
Open PDF In BrowserView PDF
IBMSystem/3
RPGll AdditionalTopics
Programmer's
Guide

Program
Numbers:
(Model10)
5702-RG1
(Model15)
5704-RG1
(Model15)
5704-RG2
5705-RG1(Modet12l.

P a g eo f G C 1 l 1, 7 5 6 7 . 2
l s s u e d3 O J u n e 19 7 8
By TNL: cl!21'5616

Third Edition(July1974)
This is a malor revision of , and obsoletes,GC21-7567-1. Inf ormation concerning lBlVl
S y s t e m / 3 l V l r : d e l1 5 h a s b e e n a d d e d a n d n u m e r o u s c o r r e c t i o n s h a r v eb e e n m d i l e . C h a n g e s t o
t o x t a n d i l l u s t r a t i o n s a r e i n d i c a t e d b y a v e r t i c a l l i r r e t o t h e l e i t o f t h e c h a n g e ; n e r , vo r
e x t e n s i v e l y r e v i s e c ii l l u s t r a t i o n s a r e d e n o t e d b V t h e s ' r ' m b o l o a t t h e l e f t o f t h e c a p t i o n .

T h i s e d i t i o r ra p p l i e st o t h e { o l l o w r r r gI B M S y s t e r n / 3R P G l l p r o g r a mp r o d u c t s
Version

Mod if icat ion

Program Number

System/3 Model

15
6

00
00
00
00

5 7 0 2 - RO 1
5 7 0 4 - RG 1
5 7 C ) 4F r G 2
5 7 0 5 - RG 1

'l
I and 0 Disl.
1 5 A ,B , C
15D
12

zl

4

r e r i o d i c a l l ym a d e t o t h e i n f o r m a t i o nh e r e i n : b e l o r eu s i n gt h i s p u b l i c a t i o n
C h a n g e sa r e p
in connectirsn
w i t h t h e o p e r a t i o no f I B M s y s t e m s r, e l e r r a t h e l a t e s tI B M S V s t e m / 3
B ' i b l i o g r a p h yG, ,C 2 0 - 8 0 8 0 ,{ o r t h e e d i t i o n st h a t a r e a p p i i c a b l ea n r l c u T i e n t .
T h i s p u b l i c , 3 t i o cn o n t a i n se x a m p l e so { d a t a a n d r e p o r t su s e di n d a i l y b u s i r r e sosp e r a t i o n s
J o i l l u s t r a t ,tsh e m a s c o r n p t e t e l ya s p o s s i b l et,h e e x a t n p l e si n c l u d et h c n a m e so f
i n d i v i d u a l sc, o m p a n i e sb, r a n d s ,a n d p r o d u c t s . A l l o f t h e s en a m e sa r e f i c t i t i o u sa n d a n y
s m i l a r i t y t o t h e n a m e sa r r da d d r e s s euss e db V a n a c t u a l b u s i n e s e
s n t e r p r i s ei s e n t i r e l y
coincidental.
L J s et h i s p u b r l i c a t i o no n l y f o r t h e p u r p o s e ss t a t e d i n t h e P r e f a c e .
P u b l i c a t i o n s a r e n o t s t o c k e d a t t h e a d d r e s s b e l o w . R e q r , l e s t sf o r c o p i e s o f I B M p u b l i c a t i o n s
and for technical inforrnation about the system shoulcl he made to your IBM representative
c,rto the lEi\4 branch office serving your locaiity.

1 ' h i sp u b l i c a t i o nc o u l d c o n t a i n t e c h n i c a li n a c c u r a c i eosr t y p o g r a p h i c ael r r o r s . U s e t h e
F l e a d e r 'C
s o r n m e n tF o r m a t t h e b a c k o f t h i s p u b l i c a t r o nt o m a k e c o m m e n t sa b o u t t h i s
p ' u b l i c a t i o n .l f t h e f o r m h a s b e e n r e m o v e d ,a d d r e s sy o u r c o m m e n t st o I B M C o r p o r a t i o n ,
F u b l i c a t i o n sD
, e p a r t m e n t2 4 5 . R o c h e s t e r M
. i n n e s o t a5 5 9 0 1 . C o m m e n t sb e c o m et h e
p r o p e r t yo l l B M .

( ) l n t e r n a t i c , n aBl u s i n e s M
s a c h i n e sC o r p o r a t i o n1 9 - 1 1
. 1974

P a g eo f G C 2 1 ' 1 5 6 1 - 2
l s s u e d2 4 M a y 1 9 7 6
B v T N L : G N 2 1- 5 3 8 9

Preface

T h i sr r r a n u aplr e s e n tasd v a n c e R
d P Gl l p r o g r a m m i ntgo p i c s
f o r a p r p l i c a t i opnr o g r a m m e rasn d s t u d e n t sw, h o m u s tc o d e
p r o g r a mfso r I B M S y s t e m / 3 :

ORGANIZATTON
OF THE MANUAL
T h i s p u b l i c a t i o n h a s e l e v e nc h a p t e r s . C h a p t e r s1 - 6 c o v e r
i n f o r m a t i o n t h a t i s b a s i ct o m o s t d a t a p r o c e s s i n gj o b s :
R P G l l p r o g r a ml o g i c ,c l e t a i l e d
i n f o r m a t i o na b c u t w r i t i n g

o

M l o d e l6

o

l V o d e l8

o

M l o d e l1 0 ( C a r d S y s t e m )

i n p u t , o u t p u t , a n d c a l c u l a t i o ns p e c i f i c a t i o n sa n d t h e c o n c e p t sa n d s p e c i f i c a t i o ni sn v o l v e di n m u l t i f i l e p r o c e s s i n g .
A d d i t i o n a l p r o g r a m m i n gt o p i c s t h a t y o u m a y r e q u i r ef o r
y o u r j o b a r e p r e s e n t e di n C h a p t e r s7 - 11 : c o n t r o l l i n g i n p u t

o

M l o d e l1 0

a n d o u t p u t d u r i n g c a l c u i a t i o nt i m e , t a b l e s a
, r r a y s ,d a t a
s t r u c t u r e a, n d t h e D E B U G o p e r a t i o n .

o

lVlode1
l 2

o

l V l o d e l1 5

RELATED PUBLICATIONS
T h e r ea r e n u m e r o u sI B M S y s t e m / 3p u b l i c a t i o n sc o n t a i n i n g
further information on RPG ll. The following are the rel a t e d r e f e r e n c em a n u a l s :

T h e S i y s t e m / 3M o d e l 8 i s s u p p o r t e db y S y s t e m / 3 M o d e l 1 0
c o n t r o l p r o g r a m m i n ga n d p r o g r a m p r o d u c t s . T h e f a c i l i t i e s
d e s c r i b e di n t h i s p u b l i c a t i o nf o r t h e M o d e l 1 0 a r e a l s o a p p li cable to the Model 8, although the Model 8 is not referred
t o . l \ o t e t h a t n o t a l l d e v i c e sa n d f e a t u r e st h a t a r e a v a i l a b l e

.

IBM System/3 Card System RPG ll Reference Manual,
S C 21 - 7 5 0 0

o n t l r e M o d e l 1 0 , a r e a v a i l a b l eo n t h e M o d e l 8 . T h e r e f o r e ,
Model 8 usersshould be familiar with the contents of the
IBM liystem/3 Modet 8lntroduction,cc2l-5144

.

IBM System/3 RPG ll ReferenceManual,SC2l 7504
(Model 10, Model 12 and Model 15)

|

o IBM System/3 Model 6 RPG ll Reference Manual,

sc21 7511

PREFIEQUISITES
T h i s r n a n u a la s s u m e st h a t y o u h a v ec o d e d a n d t e s t e d s o m e
b a s i c R P G l l p r o g r a m st h a t i n c l u d e l i s t i n g r e c o r d so n a
p r i n t e r , s i m p l ec a l c r - r l a t i o ngs r, o u p t o t a l s , a n d t h e u s e o f

l f y o u a r e p r o g r a m m i n go n a d i s k s y s t e m ,i t w o u l d b e h e l p f u l i f y o u w o u l d u n d e r s t a n dt h e d i s k c o n c e p t sa n d d i s k f i i e
p r o c e s s i n gi n f o r m a t i o n i r r t h e f o l l o w i n g b o o k s b e f o r e r e a d -

m o r e t h a n o n e r e c o r d t y p e . Y o u m a y h a v e g a i n e dt h i s
e x p e r i e n c et h r o u g h I B M e d u c a t i o nc o u r s e s ,p r o g r a m m e d
instruction courses,or previous data processingexperience.
l n t r o < T u c t i o nt o R P G l l , G C 2 1 . 7 5 1 4 ,c o n t a i n ss o m e o f
t h i s b a s i ci n f o r m a t i o n .

ing this book:
o IBM System/3 Disk ConceptsanclPlanning Guide,
G C Z | - 7 5 71
.

IBM System/3 RPG ll Disk File Processing Programmer's
Guide. GC217566

How To UseThe Manual

This publication is a programmer's guide; it is not intended
to servethe same purpose as a referencemanual of language
specificationsand does not replacea referencemanual.
R P C il l p r o g r a m m i n gt o p i c s a r e a p p r o a c h e da n d o r g a n i z e d
a c c c , r d i n gt o t h e i r n o r m a l u s e i n a d a t a p r o c e s s i n gj o b , u s i n g
e x a r n p l e sw h e n e v e rp o s s i b l e . U n l i k e a r e f e r e n c em a n u a l ,
i n d i ' r i d u a lc h a p t e r sa r e s e l f - c o n t a i n e du n i t s o f i n f o r m a t i o n ,
interrdedto be read from beginning to end. However, if you
d e s i n ei n f o r m a t i o n a b o u t a s p e c i f i ct o p i c , y o u m a y g o
direrctlyto that topic by using the index or the table of
c o n t e n t s . l t a n i n d i v i d u a lc h a p t e r h a s a s p e c i a lp r e r e q u i s i t e
t o p i c , t h a t t o p i c i s c l e a r l y i d e n t i f i e do n t h e t i t l e p a g eo f
the r:hapter.
Altfrough the chapters are complete units, there is a logical
progressionof topics through chapters 1-6. Therefore, you
may wish to read them consecutively. lf you have read the
RPC;ll Programming Fundamentals Programmed Instruc
tion course, Vou do not need to read chapters 1-6 consecutivelly.

For easeof illustration.many of the examplesin this book
usecard-likefiguresto representrecords.This doesnot
imply that a carddevicemust be usedfor input or output
in thesesituations.Any of severalinput/outputdevices
might be used,dependingon which System/3modeland
configurationyou are using.

ReYiewOuestions
Reviewquestionsand answersare providedat the end of
eachchapter.Wherechapterscontainseveralrelatedtopics.
thesequestionsaregroupedby subtopic. lf you wish,you
may turn to the end of the chapterafter you completeeach
subtopic.to answerthe reviewquestionsand reinforcewhat
you havelearned,beforecontinuingthe chapter.

P a q ec t G C 2 1 - 7 5 6 7 - 2
l s s u e d2 1 D e c e m b e r1 9 7 9
By TNL: cN21-5709

Contents

HOW TO USE THE MANUAL
C H ] A P T E R1 . R P G I I L O G I C
Introduction
Basic Data Processing Logic
B a r ; i cR P G l l L o g i c
Specific Steps in Easic RPG tl Logic
First Program Cycle .
Sumrnary of Basic RPG ll Logic
R P t Gl l L o g i c R e l a t e d T o I n d i c a r o r s
1P (F rst Page) Indicators
Last []ecord Indicator (LR) .
Record ldentifying Indicators (0,|-99)
Field Indicators(01-99)
R e s u l t i n g I n d i c a r o r s( 0 i - 9 9 )
H a l t I n d i c a t o r s ( H 1- H 9 )
Overf ow Indicator (OA-OG. OV)
Matching Records Indicator (MR)
Setting Indicators

iii
1-1
1-2
1-2
1-4
t-r)
1-1
1-7
1-7
1-13
t - t o

1-'19
1-25
1-31
I -JJ

1-41
1-42
| -z+J

IRE'VIEW1

145

TANSWERS
T O R E V I E W1

146

I3HAPTEIR
2 , D E S C R I B I N GA N D U S I N G I N P U T

2-1

Introduction
llontroi F:ir3ldg
Split Control Fields

Checkingthe Sequenceof FlecordTypes
Orderof RecordTypes Within a Group
Check.ing
the Order of RecordTypes in a Group
Incorrect Records Withrn a Group
Sequenced and Unsequenced Record Types in
a Group
Unexpected or Unused Records Within a Group
Field Record Relation lndicators
r O RR e l a t i o n s h i p
t0R Relationship With Field Record Relation
En t r i e s
Field llecord Relation with Control Fields
Field Record Relation with Split Control Fields
CorrditiorringUse of lnput Files (External Indicators)
Using t)ne Prograrn to do More Than One Job
lEndingThe Program Before Processing All Files
Completely

2-5
2-6
2-6
2-12
2-12
2-14
z- tq

2 - 15
2-15
2-16
2-18
2-18
2-'t9
2-'t9
2-22

RE\/f EW i2

2-25

I\NSWERS TO REVIEW 2 .

2-28

CI-IAPTER3. CONTROLI-ING PRII\ITEROUTPUT
Inlroduction
Using Overflow and Fetch Over-flow To Control Page
Formatlrng
Overtlow Indicators
Specificarions for Usrng Overflow Indicators
P r e v e n t i n g R e c o r d s F r o m P r - i n t i n gO v e r l - h e
P e r fo r a t i o n
Fetch Overflow
Aligning Forms
Editrng
Methods ot Fditinil
Editing and End Posrtron
Using *PLACE To Print Duplicate Information
Specifrcatrons For Llsing *PLACE
FormationOf Print Lrrres
P r i n t r n g A F i e l c JS e v e r a l T i m e s O n T h e S a m e L i n e
Using Two Pnnter Uutput Filesin One Program
Model 10 Card and Disk Systems
Model 6 .
F i i e D e s c r r p t r o nS n e c i l r c a l r o n s
Output Format Specifications
Example: Enij of the-Monrh Billing
REVIEW 3
Overflow and Fetch Over{low
F o r r n sA l i g n m e n l
Editing
*PLACF

3-1
3 2
32.
?,)

3 4

. 3-6
3 8
J -

l l

3 -1 2
312
3 19
3- 1 9
?

11

3-22
3-26
) a a

328
328
328
3-29
3 -3 1
. 3-33
2?
"

334
334
3-35
3-35

Dual PrinterOulpul t ites
ANSWERS TO REVIEW 3 ,

. 3-36

CHAPTER 4. CARD OUTPUT.OPERATIONS
Introductron
P u n c h i n g A n d P r i n t r n gO n C a r d s
Punched Output
P r i n t r n gO n C a r d s
Using One File For tsoth lrrput And Output
Punching into The Sanre Card That ls Read
Punching Into A Blank Card In The File
When To Specify A Combinecl File
Stacker Selection
Input Arrd Cornbined FileCards
Stacker Selectirig Output File Cards
Merging Input And Output FileCards

.
.
.
.
.

REVIEW 4
P u n c h i n g a n c JP r i i ' r t i n gO n C a r d s
Using Orre FrleFor Both Input And Or.rtprut
Stacker Selcction
ANSWERS TO REVIEW 4

4-1
4-2
4 2
4-2
4 2
4 8
4-8
4-11
4 14
414
415
4 1 1
415
4-21
4-21
421
423

. 4-25

CHAPTER 5. CONTROLLING OPERATIONS IN AN
RPG II PI1OGRAM .
lrrtroductiorr
Additional Llses of Indicators To Control Calculations
;:nd Output
Preventing Operations From Being Done When
An Errrlr Occurs .
Controll ng Which Operations Are Done for a
Specific Program Run
Controllrng Calculations When Overflow Occurs
Performing Calculations On The Basis of the
Resultr;Of Other Calculations
Conlrolling t]perations on the Basis of the Next
llecord In A File
Process ng Card or Disk Files
CheckinE For Duplicates
Doing Special Operations When There ls Onlv
One Record In A Group
Doing Special Operations For The Last Record
In A Group
Additiorral Points To Consider About Look Aheao
Moving Data
Specifications For Moving Data
Saving Information From A Field Bv Move
Operatrr:ns
Separating One Field Into Two Parts
C h a n g i n g F i e l d T y p e ( A l p h a m e r i co r N u m e r i c )
Branching In Calculations
Bypassirrg Calculations
Branching Backward
Using Subroutinesin Calculations
Using Subroutines To Do The Same Calculations
Several Times In One Cycle
Controlling Overlay by Using Subroutines
RPG ll LinkageEditor
LinkageEditor Map
Simple Ctverlays
Speciai Open
Overlay litarting Addresses
Fitting Available Storage
R P G l l l . - o g i ca n d F u n c t i o n S h i f t i n g
S p e c i a l U s e r so f C o n t r o l L e v e l I n d i c a t o r s
Internal Control Level Indicator L0
Using Control Level Indicators As Calculation
ConditioningIndicators
Group Printing
B i n a r y F i e l c lO p e r a t i o n s ( C o n t r o l l i n g S w i t c h e s )

BITON OperationCode
BITOFOperationCode
TESTB0peration Code
Example
'Ihe
Increasing
Speed of Operations (Dual l/O Areas)

D u a l I n p r uA
t reas
D u a l O u t p u tA r e a s

R E V I E W5

5-1
3 1

5-2
5-2
5-7
5 - 11
5-12

A N S W E R S T O R E V I E W5 .

5 - 17
5 - 17
5-20

C H A P T E R6 . M A T C H F I E L D SA N D M U L T I F I L E
PROCESSING

5-26
5-28
s-28
5-28
5-29
q_e 1
E_??

5-34
5-36
5-42
5-44
5-45
5-54
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-tl

5-73
5-73

Additional Uses Of Indicators
Controlling Operations On The Basis of the Next
Record In A File
Moving Data
B r a n c h r n gI n C a l c u l a t i o n s
Using SubroutrnesIn Calculatiorrs
Special Uses Of Control Level Indicators
Binary Field Operatrons
Dual Input/Output Areas

5-14
5-74
5-75
5-75
5-76
5-76
5-76
.

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 Orre Record Type in a File
Match Fields The Same For All Record Tvpes
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
M a t c h i n g R e c o r d s : nr"ora" Which Have No Match
In The Other Fiie
Matching Records: More Than One Record Type In
A File .
Match Fields In Different Locations In The
Same Frle
Processrng Records Which Do Not Have Match
Frelds
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

R E V I E W6
ReviewProblern
ANSWERSTOREVIEW6.
Solutron l-o The Review Problem

. 5-77

6-1
b-l

6-2
6,2
Cr-b

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
6-41
6-44
.6-46
6-49

P a g eo f G C 2 1 - 7 5 6 7 - 2
lssued21 December 1979
By TNL: GN21-5709

C H A P T E R7 . P R O G R A M M E DC O N T R O LO F I N P U T
AI{D OUTPUT
Introduction
l\lterringThe Order of Processing Files (Force
0peration)
i3peofy'ing The Next File To Process
Alternating Processing Between Two Files
Forcing A Number of Records From a File
l-ook-Ahead To Determine Whether A File ls To
Be Forced
Pro,ressingDemand Files (Read Operation)
llonsirjerations For Using READ and Demand
Files
f ] e p r e t i t i v eO u t p u t ( E x c e p t O p e r a t i o n )
lJsing EXCPT and *PLACE
llonditioning The Use of EXCPT Operation

]lE\/tEW 7
FC)RCE
I 1 E A D.
EXCP'T
l\NrSU,/EtlSTO REVIEW 7
CH,APTER 8. TABLES
lntr,cductron
l S e a r c h i n ga S i n g l e T a b r e
Desigrring Table Input Records
D e s c r i b r i n gT a b l e I n p u t R e c o r d s W i t h E x t e n s i o n
S p e c i fi c a t i o n s
{loding The Table Lookup Operation (LOKUP)
l-wo Table Search
Designing Table Input Flecords For Two Tables
D e s c r i L r i n gT w o T a b l e s W i t h E x t e n s i o n
S p e c i fi c a t i o n s
Codinq The Table Lookup Operation (LOKUP)
L J s i u g I a b l e D a t a I n C a l c u l a t i o n sa n d O u t p u t
Conditiioning Operations On The Basis of a Table
Lookup
l ? e f e r e r r r c i n gD a t a F o l l o w i n g A S u c c e s s f u l S e a r c h
llearching For Low, High, or Equal Conditions
lVoving Data In A Table Entry
l V l o d i fy i n g T h e C o n t e n t s O f A T a b l e
t.oading liables
llomp le Time Tables
P r e - e x € ' c u t i o nl - i m e T a b l e s
l*oading Pre-execution Time Tables
Oulput or an EntireTable

flE\/lEW I
lleview Problem

7-1
l-2
. 7-2
. 7-4
1

1

/- tc

7-22
7-26
7-26
7-26
7-29
. .7-31
7-31
7-32
7_33
.7-34
8-1
8-2
B-4
g-4

B-5
B-7
8-8
8 - 11
8 - 13
B - 14
8 - 14
8 - 14
8 - 16
8 - 19
8-21
8-22
8-25
B-25
B-25
B-26
8-28
. 8-29

CHAPTER 9" ARRAYS
Introduction
When To Use an ,ArravInsteadof a Table
DefiningAn Array
ReferencingAll ElementsIn An Array
Array to Array Calculations
CalculationsUsing Arrays and Single Fields(Or
Constantsi
Adding All ElementsWithin An Array
Output of an Entire Array
AccumulatingGroups Of Totals
ReferencingIndividualElementsof an Array
IndexingAn Array
Output of IndividualElementsof An Array
ReferencingOnly Part of a Field
LOKUPOf An Array
SearchingAn Array For A ParticularElement
SearchingAn Array For More Than One Element
Output During An Array Search
LoadingArrays
CompileTime Arrays
Pre-execution
Time Arravs
Storing Input Data Into ExecutionTime Arrays
Arrav Data ConsecutiveOn 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-g
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

REVTEWI

. 9-53

A N S W E R S T OR E V I E W g .

.9-55

C H A P T E R1 0 . W O R K I N G W I T H D A T A
STRUCTI.JRE
CharacterStructure
Representation
Of CharactersOn 96-ColumnCards
Representation Of Negative Numbers
Representation of Characters In Storage
Difference Between Character Representation on
Cards and In Storage
ldentifying Bit Combinations With Numerical
Values
Assigning Numerical Values to Zone ancl Digit
Portions
Saving Disk Storage Space
Collating Sequence of Characters
Collating By Zone or Digit
Altering the Collating Sequence
Specifying Changes In Collating Sequence .
Coding Characters To Be Equal
Recording Specifrcations For The Altered
Seouence

. 1O-1
1O-2
10-2
. 10-3
. 10-4
10-4
10-13
10-16
1 0 -1 9
10-21
10-25
10-2_8
10-28
10-33
10-38

8-30

vll

C H A P T E R1 1 . D E B U G
lntroduction
Using The DEBUG Function
SpecificationsFor DEBUG
Formatof RecordsCreatedBv DEBUG
Getting ResultsFrom DEBUG
Placementof DEBUG
Making Your ProgramWork For All Cases

't
1"1
11-2

R E V I E W1 1

11-7

10-48

A N S W E R S T O R E V I E W1 1

11-8

1049
10-49
10_49
10_50
10-50
10_50

INDEX

Alterrng The Structure of Characters
How Move Zone Operations Work
Coding a Move Zone Operation
D i f f e r e n c , e sI n T h e M o v e Z o n e O p e r a t i o n s
Field Forrnat and Move Zone Operations
Example of a Move Zone Operation
C l ' r o o s r n gt h e M o d e l C h a r a c t e r F o r F a c t o r 2
T r an s l a t i n g C h a r a c t e r s
Need For FileTranslation
Specifyrn'gFile Translation
Recording Specifrcations For The Translation
Table

10-39
10-39
10-39
10-40
10-41
10-41
't0-42

REVIEW 1O
Character Structure
Collating liequence of Characters .
'l-he
Altering
Collating Sequence
Alrering l-he Structure of Characters
T r a n s l a t i r r r ;C h a r a c t e r s

ANiSYYgPgTO REVTEW10

10-44
10-44
10-44

.
.
.
.

1O_S1

I t-l

11,-2

.r
1-5
11 , 5

x"1

Chapter1. RPG ll Logic

CHAPTER 1 DESCRIBES:
B a s i cR P G l l l o g i c .
R P G l l l o g i c r e l a t e dt o i n d i c a t o r s .

A F T E R R E A D I N G T H I S C H A P T E RY O U S H O U L D B E A B L E T O D E S C R I B E :
job.
B a s i ct h r e e - s t e pl o g i c o f a d a t a p r o c e s s i n g
D e t a i lt i m e a n d t o t a l t i m e .
S p e c i f i cs t e p si n a b a s i c R P G I I j o b t h a t i n c l u d e sd e t a i l a n d t o t a l o p e r a t i o n s .
R P G l l l o g i c r e l a t e dt o t h e f o l l o w i n g i n d i c a t o r s : 1 P , L R , r e c o r d i d e n t i f y i n g
i n d i c a t o r s ,f i e l d i n d i c a t o r s ,r e s u l t i n gi n d i c a t o r s ,h a l t i n d i c a t o r s( H 1 - H 9 ) , o v e r f l o w
i n d i c a t o r s( O A - O G , O V ) , m a t c h i n gr e c o r d si n d i c a t o r ( M R ) .
fuofe.' You can use the review questions contained in Review / at the end of this
chapter to test your comprehension of the chapter. Answers follow the review
o u e s t ot n s .

RPGll Logic

1-1

INTRODUCTION

R P G l l l o g i c i s b u i l t a r o u n d t h e s ei n d i c a t o r s . T h e i r s t a t u s
( o n o r o f f i a f f e c t st h e s e q u e n c eo f t h e p r o g r a m ' so p e r a t i o n s .

W h a t p r o c e d u r e sd o y o u f o l l o w i f y o u a r e p r e p a r i n gb i l l s t o
s e n dt o c u s t o m e r s ?B e f o r e y c u c a n d o a n y t h i n g y o u n e e o
s o m e i n l o r m a t i o n . Y o u h a v et o k n o w t h r e et h i n g s : ( 1 )
t h e c u s t o m e r ' sb a l a n c ea t t h e b e g i n n i n go f t h e m o n t h ; ( 2 )
h i s p u r c h a s e sa; n d ( 3 ) h i s p a y m e n t s . O n c e y o u h a v e
g a t h e r e dt h i s i n f o r m a t i o n , y o u c a n p e r f o r m t h e n e c e s s a r y

T h e l o g i c i s s e t u p t o t e s t t h e s t a t u so f v a r i o u si n c l i c a t o r sa t
s p e c i f i ct i m e s . B y t e s t i n g i n d i c a t o r s ,t h e p r o g r a m k n o w s
what to do next.

c a l c u l a t i o n st o f i n d t h e a m o u n t d u e . F i n a l l y y o u r e c o r d
t h i s a m o u n t o n t h e b i l l . Y o u g o t h r o u g h t h e s es a m ep r o c e d u r e sf o r e a c h c u s t o m e r .
T h i s i s a t y p e o f j o b y o u c a n e a s i l yh a v ey o u r c o m f l u r e r o o
f o r y o u , T o d o t h e j o b , h o w e v e r ,t h e c o m p u t e r m u s t k n o w
t h e s a m et h i n g s y o u k n o w . Y o u m u s t , t h e r e f o r e ,t e l l i t
e x a c t l y w h a t i n f o r m a t i o n t o e x p e c t ,w h a t t o d o w i t h t h e
i n f o r m a t i o n ,a n d w h a t t o g i v ey o u a s a r e s u l t . T h i s y o u d o
t h r o u g h s p e c i f i c a t i o n sy o u w r i t e : F i l e D e s c r i p t i o n ;E x t e n .
s i o n ; L i r r e C o u n t e r ; I n p u t ; C a l c u l a t i o n ;a n d O u t p u t - F o r m a t .
T o d o t h i s b i l l i n g j o b , y o u d o t h i n g s i n a l o g i c a lo r c j e r . y o u
r e a d i n f o r m a t i o n f i r s t . Y o u d o c a l c u l a t i o n ss e c o n d . F i n a l l y ,
a s a r e s u l t o f t h e c a l c u l a t i o n sy, o u r e c o r d t h e a m o u n t o w e d .
T h e n y o u b e g i n t o d o t h e s a m et h i n g s r n t h e s a m eo r d e r f o r
tne next customer.
T h e c o n r p u t e rm u s t a l s o d o t h i n g s i n a l o g i c a lo r d e r . T h e
i n f o r m a t i o n y o u s u p p l y t h r o u g h s p e c i f i c a t i o n sd o e s n ' t g i v e
t h e c o m p u t e r t h e l o g i c i t n e e d st o d o y o u r j o b ; t h e R p G l l
C o m p i l e r s u p p l i e st h i s . R P G l l l o g i c s u p p l i e db y t h e c o m p i l e r i s t h e f r a m e w o r k f o r y o u r j o b . W h e n y o u r s o u r c ep r o g r a m i s r : o m p i l e d ,y o u r s o u r c es t a t e m e n t sa r e f i t t e d i n t o t h e
f r a m e w o r k o f R P G l l p r o g r a ml o g i ct o m a k e a c o m p t e t e
p r o g r a m . T h e g e n e r a t e dp r o g r a mt h e n h a s a l l t h e i n f o r m a t i o n i t n e e d st o d o y o u r j o b i n a l o g i c a lm a n n e r .
W h a t h a p p e n si f , i n d o i n g y o u r b i l l i n g j o b , y o u f i n d t h a t a
c u s t o m e rp a i d m o r e t h a n h e o w e d ? Y o u k n o w i m m e d i a t e l y
t h a t h e h a s a c r e d i t b a l a n c ea n d i n d i c a t es o o n t h e i n v o i c e .
H o w d o e s t h e B P G | | p r o g r a m r e c o g n i z et h i s s i t u a t i o n ?
And how doesit know what to do when sucha situation
occurs?
T h e R P G l l p r o g r a m u s e ss i g n a l sw h i c h t e l l i t w h e n a p a r t i c u l a r s i t u a t i o no c c u r sa n d w h a t t o d o w h e n t h a t s i t u a t i o n
d o e s o c c u r . T h e s es i g n a l sa r e k n o w n a s i n d i c a t o r s . T h e r e
a r e m a n y d i f f e r e n t k i n d s o f i n d i c a t o r sw h i c h s i g n a rm a n y
d i f f e r e n t s i t u a t i o n s . Y o u , a s a p r o g r a m m e r ,m u s t k n o w h o w
t o s p e c i f y t h e i n d i c a t o r ss o t h a t t h e y s i g n a lt o t h e c o m p u r e r
what you want them to.

t-z

R P G | | p r o g r a m l o g i c i s d e s i g n e dt o t a k e c a r e o f a l l t y p e s o f
j o b s . Y o u m u s t u n d e r s t a n dt h i s l o g i c t o w r i t e s p e c i fi c a t i o n s
w h i c h m a k e c o r r e c t u s eo f i t .
B e c a u s et h e l o g i c i s a r a t h e r c o m p l e x t o p i c , i t i s d e s c r i b e d
s e g m e n tb y s e g m e n t . H o w e v e r ,w h e n y o u h a v e f i n i s h e d
r e a d i n gt h i s s e c t i o n .y o u w i l l h a v ea p i c t u r e o f h o w t h e
c o m p l e t e R P G l l p r o g r a m l o g i cw o r k s .

B A S I C D A T A P R O C E S S I N GL O G I C
U s u a l l y ,a l l r e c o r d si n a f i l e o f i n p u t r e c o r d sa r e n o t r e a d a t
o n c e . Y o u r c o m p u t e r p r o b a b l y i s n o t l a r g ee n o u g ht o s t o r e
a n d w o r k w i t h i n f o r m a t i o n f r o m a l l r e c o r d sa t t h e s a m e
t i m e . T h e r e f o r e ,r e c o r d sa r e r e a d o n e a t a t i m e . T h r e e
s t e p s ,a s s h o w n i n F i g u r e 1 - 1 , a r e d o n e f o r e a c h r e c o r d r e a d .
The phrasepragram cycle refersto all the operations performed from the time one recordis readuntil the next reco r d i s r e a d . O n e p r o g r a m c y c l e i s t h e r e f o r eo n e r e v o l u t i o n
a r o u n d t h e c i r c l e u s e dt o i l l u s t r a t et h e p r o g r a m l o g i c . S i n c e
o n e p r o g r a mc y c l e ( o n e r e v o l u t i o n ) i s n e e d e df o r e a c n r e c o r d r e a d , m a n y p r o g r a m c y c l e sa r e r e q u i r e df o r e v e r y j o b .
C o n s i d e rh o w t h e t h r e e s t e p l o g i c s h o w n i n F i g u r e 1 - l w o r k s
f o r a j o b w h i c h r e q u i r e sa d e t a i l e dl i s t i n go f p u r c h a s e sm a d e
b y e a c h c u s t o m e r . T h e i n p u t f i l e i s i n a s c e n d i n go r d e r b y
c u s t o m e rn u m b e r . E a c h r e c o r d c o n t a i n sc u s t o m e rn a m e
( N A M E ) , n u m b e r ( N U M ) , a n d c h a r g e( C H R G ) . I n f o r m a t i o n
from the record is merely transferred to the printed page.
O n e l i n e i s p r i n t e d f o r e a c hr e c o r dr e a d . E a c h r e c o r d r e a d
is known asa detail recordand each line printed is a detail
line.
T h e j o b b e g i n s : t h e f i r s t r e c o r d i s r e a d . N o c a l c u l a t i o n sa r e
p e r f o r m e d . A r e c o r d i s t h e r r p r i n t e d . T h i s e n d st h e f i r s t p r o g r a m c y c l e . T h e s e c o n db e g i n sw i t h t h e r e a d i n go f a n o t h e r
r e c o r d . F i g u r e 1 - 2 s h o w st h e i n p u t a n d o u t p u t o f t h e d e t a i l
p r i n t i n gj o b .
S u p p o s e ,h o w e v e r ,i n s t e a do f m e r e l y l i s t i n gt h e c h a r g e s
m a d e b y e a c h c u s t o m e ry o u a l s ow i s h t o f i n d t h e t o t a l
c h a r g e sf o r e a c h c u s t o m e r ,a s s h o w n i n F i g u r e 1 - 3 .

a

\

Writeor punch
results

a record

Perform calculations

.@

F i g u r e 1 - 1 . B a s i c L o g i c o f a D a t a P r o c e s s i n gJ o b

1796 JOHN BART
I762 BILLBELL

2493

13142

1645 JOE AARON
,I&5

JOE AARON

742

1645
1645

J O EA A R O N
J O EA A R O N

7.42
6.43
13.85*

1762

BILL BELL

'13'1
.42
131.42*

1796
1796

J O H NB A R T
J O H NB A R T

24.93
2.98

Printed reoort

Figure 1-2. Detail Printing Job

F i g u r e 1 - 3 . C a l c u t a t i n ga n d P r i n t i n g T o t a l s
RPGll Logic

T o d o t h i s , y o u m u s t d o c a l c u l a t i o n st o a c c u m u l a t e
a total
i n a d d i t i o n t o p r i n t i n g o u t i n d i v i d u a l ( d e t a i l )r e c o r d s .
But
w h e n d o y o u p r i n t o u t t h e t o t a l y o u h a v ec a l c u l a t e d ?
The
t o t a l f o r a c u s t o m e r ,o f c o u r s e ,s h o u l d b e p r i n t e d a f t e r
all
d e t a i l r e c o r d sf o r t h a t c u s t o m e rh a v e b e e n p r i n t e d ( F i g u r e
1 - 3 ) . H o w e v e r ,i n t h e t h r e e - s t e pl o g i c d i s c u s s e ds o f a r ,
there
i s n o p r o v i s i o nf o r p r i n t i n g a t o t a l r e c o r d . N e i t h e r i s
there
a w a y t o d i s t i n g u i s hb e t w e e ni n d i v i d u a l i n p u t r e c o r d s
in
o r d e r t o d e t e r m i n ew h e n a l l r e c o r d sf o r a c u s t o m e r h a v e
b e e nr e a d .

BASIC RPG II LOGIC
R P G l l l o g i c ,t h e r e i o r e , i s a n e x t e n d e dv e r s i o no f t h i s 3 - s t e o
l o g i c . l t c a l l sf o r c a l c u l a t i o n sa n d o u t p u t o p e r a t i o n st o b e
done at two different times in one program cycle (see Fig.
ure 1-4). The namesdetail and total have been given to the
t a m e sa t w h i c h c a l c u l a t i o na n d o u t p u t o p e r a t i o n sa r e D e r formed. Total time, as the name suggests,is the time in
which total operations are done on data accumulated from
a group of related records. The printing of total chargesfor
J o e A a r o n ( F i g u r e 1 - 3 ) i s a n e x a m p l eo f a t o t a l t i m e o p e r a -

l f t h e R P G l l p r o g r a m u s e do n l y t h e t h r e e - s t e pl o g i c .
it
w o u l d n o t b e a b l et o d o t h i s j o b a n d m a n y o t h e r s l i k e i t .
I t c o u l d a d e q u a t e l yw o r k w i t h i n f o r m a t i o n f r o m o n l y
one
r e c o r da t a t i m e , a s i n t h e d e t a i l p r i n t i n g j o b . l t c o u l d
not
correctly do operations to accumulate data from
several
records.

t i o n . D e t a i l t i m e i s t h e t i m e i n w h i c h o p e r a t i o n sa r e p e r f o r m e d f o r i n d i v i d u a lr e c o r d s . A n e x a m p l eo f a d e t a i l t i m e
o p e r a t i o n i s t h e p r i n t i n g o f a n i n d i v i d u a lc h a r g ef o r J o e
A a r o n . R e m e m b e r ,d e t a i l o p e r a t i o n sa r e d o n e f o r e v e r y
record read. but total operations are done only after a cer_
t a i n g r o u p o f r e c o r d sa r e r e a d ( s e eF i g u r e 1 - 5 ) .
o

Perlorm detail
output operations

Reada

Detail
time

Perlorm detail
calculations

Total
time

o

O

Perform total
output operations
o

Figure 1-4. Basic RPG ll Logic
14

P a s eo I G C 2 1 - 7 5 6 7 - 2
l s s u e d2 4 M a y 1 9 7 6
By TN L: GN21-5389

Detail operations

1 7 1 3 L E E A R M S T R O N G3 7 9

Donefor
everyrecord

1713 LEE ARMSTRONG 571

L E E A R M S T R O N G4 7 5

L E E A R M S T R O N G2 9 8

G R O U P2

i C u s t o r r t enr u m b e r
f i e l d( N U M )

1645 JOE AARON

742

Total Operations
Done only after
a l l r e c o r d si n
one group have
been processed.

,/

o^ou,

Figure1-5. DetailVersusTotalOperations

B e c a u s et h i s b a s i c R P G l l l o g i c i s o n l y a f r a m e w o r k f o r y o u r
j o b , v r c u h a v et o s u p p l y a d d i t i o n a l i r r f o r m a t i o ns o t h a t y o u r
j o b w i l l b e c o m p l e t e . O n l y t h e n w i l l y o u r p r o g r a mw o r k

f e r e n t c u s t o m e rn u m b e r i n t h e N U M f i e l d , y o u k n o w t h a t
y o u h a v e g a t h e r e da l l t h e i n f o r m a t i o n f o r o n e c u s t o m e r .
( Y o u c o u l d u s et h e N A M E f i e l d t o t e l l y o u t h i s , b u t t h e r e

c o r r e c t l y . F o r e x a m p l e ,t h e R P G l l c o m p i l e rs u p p l i e sy o u r
p r o g r a mw i t h t h e l o g i c f r a m e w o r k w h i c h e n a b l e si t t o d o

i s a c h a n c et h a t t w o c u s t o m e r sm a y h a v et h e s a m en a m e . )
Y o u w o u l d t h e n r e c o r d t h a t t o t a l b e f o r e g a t h e r i n gi n f o r mation for the next customer.

detail and total operations. But you must tell it when total
o p e r a t i o n ss h o u l d b e d o n e a n d w h i c h c a l c u l a t i o na n d o u t p u t
o p e r a t i o n sa r e t o b e d o n e a t d e t a i l t i m e a n d w h i c h a r e t o b e
done at total time.
R e m r - ' m b etrh a t t h e o n l y w a y y o u c a n t e l l t h e p r o g r a m
w h a t t o d o i n c e r t a i n s i t u a t i o n si s t o u s e i n d i c a t o r s . C o n t r o l l e v e l i n d i c a t o r sa r e u s e dt o t e l l t h e p r o g r a m :
1.

Whento do total operations.

2.

W h a t o p e r a t i o n sa r e t o t a l o p e r a t i o n s .

l f y o u w e r e f i n d i n g t o t a l m o n t h l y c h a r g e sf o r e a c h c u s t o m e r , h o w w o u l d y o u k n o w w h e n t o r e c o r dt o t a l s f o r
e a c hc u s t o m e r ? W h e n y o u e n c o u n t e ra r e c o r d w i t h a d i f -

A n y f i e l d u s e d t o c o n t r o l a n d d i r e c t p r o c e s s i n gi s k n o w n
as a control field. You indicate to the compiler program
w h i c h f i e l d i s a c o n t r o l f i e l d b y a s s i g n i n go n e o f t h e c o n t r o l
l e v e li n d i c a t o r s( L 1 - L 9 ) t o t h e f i e l d i n c o l u m n s 5 9 - 6 0 o f
t h e I n p u t s h e e t . Y o u a l s o u s e t h i s s a m ec o n t r o l l e v e l i n d i c a t o r t o t e l l t h e p r o g r a m w h i c h c a l c u l a t i o n sa r e t o t a l c a l c u l a t i o n s b y e n t e r i n gt h e i n d i c a t o r i n c o l u m n s 7 - 8 o f t h e
C a l c u l a t i o ns h e e t . T h o s e c a l c u l a t i o n st h a t a r e n o t c o n d i t i o n e d b y a c o n t r o l l e v e li n d i c a t o r ( i n c o l u m n s 7 - 8 ) a r e
d e t a i l c a l c u l a t i o n s .C o n t r o l l e v e l i n d i c a t o r sa r e n o t u s e d
i n t h e O u t p u t - F o r m a t s h e e tt o i n d i c a t ed e t a i l a n d t o t a l
r e c o r d s . R a t h e r a T i s u s e d i n c o l u m n 1 5 t o i n d i c a t ea
t o t a l o u t p u t o p e r a t i o n ;a n d H o r D i s u s e dt o i n d i c a t e
a n o o e r a t i o nd o n e a t d e t a i l t i m e .
RPG ll Logic

1-5

SpercificSteps in Basic RpG ll Logic

A c c o r d i n g t o R P G l l l o g i c ,a f t e r a r e c o r d i s r e a d t h e p r o g r a m
c h e c k st o s e ei f i n f o r m a t i o n i n t h e c o n t r o l f i e l d o f t h e r e c o r d

F i g u r e 1 - 4 s h o w s v e r y g e n e r a l l yt h e s e q u e n c eo f

e v e n t si n a n
R P G l l p r o g r a n cr y c l e . T h e R p G l l l o g i ca c t u a l l y
conststs
o f c l e f i n i t es t L . l i st a k e n d u r i n g t h e c y c l e " W h e r ry o u d o j o b
a
y o u m e n t a l l r la s k y o u r s e l f q u e s t i o n ss u c h
,,Do
as,
I do this
n o v r ? D o I h a v ea l l m y i n f o r m a t i o n ?W h a t s h o u l d
I do
n e x t ? " R P G l l l o g i c a l s o a s k sq u e s t i o n s . l t u s e sy o u r p r o g r a r nt o f i n d t h e a n s w e ra n d t h u s d e t e r m i n e s
what to do
n e x t . T h e q u e s t i o n s ,a n d s p e c i f i cs t e p st a k e n b a s e d
on the
a n s \ r y e rt o
s t h e q u e s t i o n s ,a r e s h o w n i n F i g u r e 1 _ 6 .

J u s ts e l e c t e di s d i f f e r e n t f r o m t h e c o n t r o l f i e l d i n f o r m a t i o n
i n t h e p r e v i o u sr e c o r d . ( T h e p r o g r a ma l w a y ss a v e st n e c o n _
t r o l f i e l d i n f o r m a t i o ns o t h a t i t c a n m a k e a c o m p a r i s o n . )l f
t h e r e i s a c h a n g e ,t h e p r o p e r c o n t r o l l e v e l i n d i c a t o r
{the one
y o u a s s i g n e di)s t u r n e d o n . ' f h i s m e a n st h a t a l l r e c o r d s
f r o m o n e g r o u p h a v e b e e n r e a d . A l l t o t a l o p e r a t t o r r sc a n
t h e n b e p e r f o r m e d . C o n t r o l l e v e l i n d i c a t o r sa r e a l w a V s
t u r n e d o f f b e f o r et h e n e x t r e c o r d i s r e a d .

o

o

o
O

O

o
R e a da r e c o r d

Turn off control
l e v e li n d i c a t o r s
L1-L9.

o

o

Perform detail
output operations
{those identified
byDorH)
Detail
time

4\

o

Total
time

. / /
P e r f o r md e r a i l
c a l c u l a t i o n s( t h o s e
w i t h b l a n k si n
c o l u r n n s7 - B )
/

O

a/

/

a

//

,/
/

./
/

\

Move data from
/
recoro reao at
b e g i n n i n go f c y c l e
intoprocessing
area

a

Perform total

Perform total output
operations(those
r d e n t r l l e d D y al ,

o
o

Figure 1-6. Stepsin RpG ll Total and Detail_Time
Loqic

| -ft

c a l c u l a t i o n s( t h o s e
c o n d i t i o n e db y L 0 - L 9
o r L R i n c o l u m n s7 - 8
o f C a l c u l a t i o ns h e e t )

C h a n g ei n c o n t r o l f i e l d ?
I f y e s ,t u r n o n c o n t r o l
levelindicatiors
;

N o t l c e t h e s t e p b e t w e e nt o t a l a n d d e t a i l t i m e . H e r e d a t a
f r o n r t h e r e c o r d r e a d a t t h e b e g i n n i n go f t h e c y c l e i s m o v e d
i r r t o a p r o c e s s i n ga r e aa n d b e c o m e sa v a i l a b l et o u s e i n c a l c r . r l a t i o nasn d o u t p u t . D a t a f r o m t h i s r e c o r d i s n o t a v a i l a b l e
a ' tt o t a l t i m e . T o t a l o p e r a t i o n sa r e p e r f o r m e d o n l y o n d a t a
a r : c , r m u l a t e fdr o m p r e v i o u sr e c o r d s . D e t a i l o p e r a t i o n so n
t l r e r e c o r dw h i c h c a u s e dt h e c o n t r o l l e v e l i n d i c a t o r t o b e
t u r n e d o n a r e d o n e o n l y a f t e r t o t a l o p e r a t i o n sf o r p r e v i o u s

Summary of Basic RPG ll Logic
F i g u r e 1 - 7 s h o w s s p e c i f i c a t i o n sf o r t h e g r o u p p r i n t i n g j o b
p r e v i o u s l yd i s c u s s e da n d t h e l o g i c f o r t h e f i r s t f o u r p r o g r a m c y c l e s . F o l l o w t h e l o g i c i n v o l v e di n e a c h p r o g r a m
c y c l e s t e p b y s t e p . R e m e m b e r ,t h e c y c l e r e p e a t si t s e l f f r o m
the time the program is started until the last record is
processed.

p1.'66rrds.
V / h v a r e t o t a l o p e r a t i o n sd o n e b e f o r e d e t a i l o p e r a t i o n s ?
-[hirrk
o f w h a t w o u l d h a p p e ni f t h e r e c o r d w h i c h c a u s e d
t l n ec o n t r o l l e v e l i n d i c a t o r st o b e t u r n e d o n w e r e p r o c e s s e d '

B e s u r e y o u u n d e r s t a n dt h i s b a s i cl o g i c b e f o r e p r o c e e d i n g
further.

l n f o r m a t i o n o n t h i s r e c o r dw o u l d b e a d d e dt o i n f o r m a t i o n
f r o r n r e c o r d si n t h e p r e v i o u sg r o u p . A s a r e s u l t ,t h e t o t a l s
p,rirrted
w o u l d b e i n e r r o r s i n c et h e y c o n t a i n e di n f o r m a t i o n
f r o r n o n e r e c o r d i n t h e n e x t g r o u p ( t h e r e c o r di u s t r e a d ) .
'l-o
p r e v e n td a t a f r o m t h e f i r s t r e c o r d i n a n e w c o n t r o l g r o p p

RPG II LOGIC RELATED TO INDICATORS

f r o r n b e i r r ga c c u m u l a t e di n t h e t o t a l s f o r t h e p r e v i o u s
g r o u p , t o t a l o p e r a t i o n sa r e d o n e b e f o r e d e t a i l o p e r a t i o n s '

l o g i cs h o w n i n F i g u r e1 - 4 '

First Program Cycle
; r e s p e c i f i e df o r a r e c o r d ,t h e f i r s t p r o When control fieldsa
g r a r nc y c l e m a y b e s ; l i g h t l yd i f f e r e n t f r o m t h e o t h e r s .
C o n t r o l l e v e li n d i c a t o r sa r e t u r n e d o n b y t h e f i r s t r e c o r d
c o r r t a i n i n gc o n t r o l { i e l d s . T h i s h a p p e n sb e c a u s ec o n t e n t s
o f t h e c o n t r o l f i e l d so n t h i s r e c o r da r e d i f f e r e n t f r o m t h e
b l a n k c o n t r o l f i e l d a r e a st h a t w e r e i n m a i n s t o r a g eb e f o r e
t h e r e c o r d w a s r e a d . T o p r e v e n tp r i n t i n g o f b l a n k t o t a l s o n
t h e f i r s t c y c l e , R P G l l l o g i c c a u s e st o t a l o p e r a t o n s t o f l e
b y p a s s e do n t h e f i r r ; tc y c l e .
, N o t e : l t t h e i n i t i a l i n p u t r e c o r d sd o n o t c o n t a i n a c o n t r o l
f i e l d . t o t a l c a l c u l a t i o n sa n d t o t a l o u t p u t o p e r a t i o n sa r e
b y p a s s e do n e a c h p r o g r a mc y c l e t h r o u g h a n d i n c l u d i n gt h e
f i r s ; tc v c l e i n w h i c h a r e c o r d w i t h c o n t r o l f i e l d s i s r e a d '

I t w a s p r e v i o u s l ys t a t e d t h a t R P G l l l o g i c i s b u i l t a r o u n d
i n d i c a t o r s . T h i s s e c t i o nd i s c u s s ehs o w l o g i c r e l a t e dt o i n d i c a t o r sf i t s i n t o t h e b a s i c R P G l l d e t a i l a n d t o t a l t i m e

I n y o u r s p e c i f i c a t i o n sy, o u u s e i n d i c a t o r st o t e l l t h e p r o '
g r a mw h a t t o d o a n d w h e n t o d o i t . A l t h o u g h y o u u s ei n d i c a t o r s ,y o u d o n o t s e t t h e m ' N a t u r a l l y t h e i n d i c a t o r s
d o n ' t t u r n o n a n d o f f b y t h e m s e l v e s .T h e c o m p i l e r s u p p l i e s
l o g i c w h i c h i s n e e d e dt o c o n t r o l t h e s e t t i n go f i n d i c a t o r s '
I n d i c a t o r sa r e s e t t o s i g n a lv a r i o u sc o n d i t i o n st h a t o c c u r
d u r i n g t h e e x e c u t i o no f a p r o g r a m . I n a d d i t i o n t o s e t t i n g
i n d i c a t o r s ,R P G l l l o g i c a l s o c a u s e st e s t st o b e m a d e f o r
v a r i o u si n d i c a t o r sa t c e r t a i nt i m e s i n t h e p r o g r a mc y c l e '
S p e c i f i co p e r a t i o n sa r e p e r f o r m e d a s a r e s u l t o f t h e s et e s t s '
I t i s v e r y e a s yt o t h i n k t h a t a n i n d i c a t o r i s o n w h e n i t r e a l l y
is off or viceversa. lt is extremelyimportant that you know
w h e n i n d i c a t o r sa r e o n a n d w h e n t h e y a r e o f f i n t h e p r o g r a m c y c l e . M a n y p r o g r a m sf a i l i u s t b e c a u s et h e p r o g r a m m e r d i d n o t u n d e r s t a n dR P G l l l o g i c c o n c e r n i n gi n d i c a t o r s '
T h e f o l l o w i n g p a r a g r a p h sw i l l d i s c u s st h e t i m e i n t h e p r o g r a m c y c l e a t w h i c h i n d i c a t o r sa r e s e t a n d t h e t i m e a t
which they aretested.

RPG ll Logic

1-7

RPG INPUTSPECIFICATIONS
IBI|I,"

" . , " " " a u s n . $ M . c hn e c o , o o r a i o n

Record ldentif ication CocJes

]H]A]RF]I

i lf i r i r

lillll

iii

l-'

I

ift

rti

RPG
IBlt,,".".,",.

CALCULATION SPECIFICATIONS

a.nnesMa.h,nsc.rp.ran.n
-

7--T

'r:Y F,e-l L i
P!.ch,ns

I

GEPhic

I

67 6a

SPECIFICATIONS
IBI{

",",",

6S

70 ?r

7? 71

7a

cx21 m0
u/M o50.
p.if,redin U s.A

,^" aunnen Machie cd,oors, on

15 16 11 7a 79 80
ldenrncar,onl

End

Constantor Edit Word

i l

TI

+ f

il

i r

l

l

1

1

l

lr Jl
l r

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

|

|

|

|

|

I

'

11645

J O EA A R O N

164s

JoE AABoN

742

7.42

o

o

o
o

a
Turn off
control level
indicator L 1

o

I645 JOE AARON

742

o
Perfcrm detail output
Print the record

o

a
P e r f o r m d e t a i l c a l c u l a t i o n:
Add CHG to TOTAL

a

C h a n g ei n c o n t r o l f i e l d ?
Yes, turn on control
levelindicator L1

00000
742
oo742

o

Move data from record
s e l e c t e di n t o
p r o c e s s i n ga r e a

o

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

o
o

o

R e c a l lt h a t t h e r e i s
a l w a y sa c o n t r o l b r e a k
on the first cycle,
a l t h o ug h t o t a l o p e r a t i o n s
are bypassed.

f:igure 1-7 (Part2 of 5). lllustration of Detail and Total Time

RPG ll Logic

1-9

JOE AARON
JOEAARON

7.42
6.43

o

a

6 4 5 J O EA A R O N

o

o

Perform detail output:
Print the record

Perform
detail calculation:
Add CHG to TOTAL

j

o

oo742
643
01385

C h a n g ei n c o n t r o l f i e l d ? N o

a

Movedat€ from record
sol€ctedinto
processing
area

o
o

Figure 1-7 (Part 3 of Sl, lllustration of D€tait and Total
Time

o

o

o
1762BILL BELL 1342

o

o

o
C h a n g ei n c o n t r o l f i e l d ?
Yes, turn on control lwel
indicator L1

Perform detail calculations:
Add CHG tO TOTAL

00000
1342
01342

o
Move data from rscord
selected into
processingarea

O

Perform total output:
Print TOTAL,
reset field to
zelo

o

,,,,1

Figure 1-7 (Part4 of 5). lllustration of Detail and Total Time
RPG ll Logtc

1645
1645

J O EA A R O N
J O EA A R O N

7.42
6.43
I796 JOHN BART 2493

13.85*
B I L LB E L L

13.42
13.42-

J O H NB A R T

24.93

a

a

o

o
o

Turn off
control level
indicator L1

1 7 9 6 J O H NB A R T 2 4 9 3

O

Perform detail output:
Print the record

a
Performdetailcalculation
:
Add CHGto TOTAL
00000
2493

o

o2493

a

C h a n g ei n c o n t r o l f i e l d ?
Yes,turn on control
levelindicator L1

o

Move data from record

selectedinto
processing
ares

Perform total output:
Print TOTAL,
reset field to
zefo

o

:::::::::::tj:
:.:.:.;,:t:.;

1645
1645

J O EA A R O N
JOEAARON

7.42
6.43

O

:::;::iit;
l::j::::i::;
.:;::::;:i

.i::j:::ij;

.:.j.:.:.i
'::::::;;i

13.95*
1762

B I L L B EL L

,'.j.t""

13.42

F i g u r e 1 - 7 ( P a r t 5 o f 5 ) . lllustration of Detail and
Total Time
1- 1 2

O

T h e 1 P i n d i c a t o irs t u r n e do n o n l y f o r t h e b e g i n n i nogf t h e
f i r s t c y c l e . l t i s t u r n e do f f b e f o r ea r e c o r di s r e a da n d i s
n e v e ru s e da g a i nd u r i n gt h e p r o g r a m( s e eF i g u r e1 - 8 ) '

1P'(F:irstPage)In - 4 /o t t h e s a m el r n e
I
asthe edit corle
I' f f i -

SPECIFICATIONS
IBIII

.,..,.,.,"

su, nes Ma.h.e co,oo,ai.i

II
t-l
I

I

lr

t1
ll

i'i,i
ji

rir

F i g u r e 3 - 1 8 . E d i t W o r d f o r T e l e p h o n eN u m b e r

SPECIFICATIONS
IBIL

"

^,,,,.

Gx2r-ffi

U/M OS.

sline$vrh ilcc.,D.,a,.n
75 76 77 78 79 80
rdenrincarronl

|

|

|

I

I

I

Constant or Edil Wor.l

t rl+
ll 'tl

iTl

ii

F i g u r e 3 - 1 9 . E d i t W o r d f o r S o c i a lS e c u r i t y N u m b e r

Controlling Printer Output

3-17

PageoI GC21 :,t567-2
l s s u e d 2 1 D e c e , m b e r, | 9 7 9
By TNL: GN2'l-5709

Punctuating by Leaving Btanks

RPG

A , c o m p a n vh a s r a t h e r l o n g a c c o u n t n u m b e r s . T o m a k e
t h e m e a s i e rt o r e a d a n d h a n d l e ,b l a n k sa r e l e f t a f t e r e v e r y

OUTPUT

"- l " ' ; ; ' 1 I I

SPECIFICATIONS

--T

t",;-il_ll

third digit when the number is printed.
l s t h e r e a c o d e t h a t w i l l i n s e r t b l a n k s ? N o , a g a i ny o u h a v e
t o s p e c i f y y o r . l ro w n e d i t w o r d . I n a n e d i t w o r d . b l a n k s i n dicate where the digits go and ampersandsindicate wnere

Punctuating fuy Adding Constant lnformation
For shipping purposes,the catalog department of a department store must know the weight of every item it sells.
T h e w e i g h t i n p o u n d s a n d o u n c e si s r e c o r d e di n a 6 - d i g i t
f i e l d . T h e l a s t t w o d i g i t s a r e o u n c e s ,t h e f i r s t f o u r d i g i t s
are pounds. lVhen printed out on a report, the consrants
LBS and OZ rnust be inserted. Otherwise. the data would
n o t b e u n d e r s t a n d a b l e .A g a i n t o d o t h i s , a n e d i t w o r d i s
n e e d e db e c a u s en o e d i t c o d e w i l l i n s e r t L B S a n d O Z .

Figure3-20. Edit Words

T h r ap r i n t e d f i e l d i s s h o w n o n t h e p r i n t e r s p a c i n gc h a r t i n
F i g u r e3 - 2 1 . r S n es p a c ei s n e e d e db e t w e e nt h e d i g i t a n d
LBS and betvrreen
the digit and OZ. Two spacesseparate
p o u n d s f r o m r l u n c e s . R e m e m b e ri n t h e e d i t w o r d , b l a n k s
a r e s p e c i fi e d f o r d i g i t s ,a m p e r s a n d sa r e s p e c i fi e d f o r b l a n k s ;
ancl constant information is inserted where desired. The
e d i t w o r d s h o u l d b e a s l o n g a st h e f i e l d s h o w n o n t h e p r i n t e r
spacingchart. Figure 3-20, insert B, shows the correct edit
patternfor this f ield.

r+

Fold bo(t or dofi.d

DATE_'-

,L
Figure3-21. Print Chart {WeightField)

3 - 1t |

_ Ill
End

b l a n k sw i l l q c , . T h e a c c o u n t f i e l d c o n s i s t so f t e n d i g i t s .
T h e e d i t w o r d s h o w n i n F i g u r e3 - 2 0 , i n s e r tA , w i l l p u t
b l a n k sa f t e r e v e r y t h r e e d i g i t s .

i:1rirl

tin.

ll_]c.,or,*"*'-',1

i

1 2
fTt
t

1

l

E d i t w o r d sc a nd o a l l k i n d so f e d i t i n gf o r y o u . T h e y c a n
e v e nb e s e tu p t o d o t h e s a m et h i n ga st h e e d i t c o d e s .A l l
y o u h a v et o d o i ss h o ww h e r et h e c o m m a sd, e c i m apl o i n t s ,
c r e d i ts i g n se, t c .s h o u l da p p e a r .A z e r oi s u s e dt o i n d i c a t e
w h e r ez e r os u p p r e s s i osnt o p s . F o r e x a m p l ei n F i g u r e3 - 2 0 .
insertC, the 0 showswherezerosuppression
is to end in
t h e W E I G H Tf i e l d .
E t i os n

3.

Whenis the overflowindicatorturnedon and when is it tested?

4.

Describea situationwhereprintingcan occur belowthe overflowline.

tr

alterthe normalprogramcycle?
How doesthe l'etchoverflowspecification

6.

G i v e nt h e f o l l c l w i n gi n f o r m a t i c l ns,u p p l yt h e F e t c hs p e c i f i c a t i o nfso,r t h e o u t p u t
s h o w ni n F i g u r e3 - 4 0 ,w h i c hw i l l p r e v e n pt r i n t i n gr e c o r d so n o r o v e rt h e p e r f o r a t i o n .
N u m b e ro r p r i n t i n gl i n e sp e r p a g ei s 6 6 " T h e o v e r f l o wl i n e i s 5 8 .
a T h e r ea r es e v e nt o t a l l i n e si n a l l . S i n c ea l l a r ec o n d i t i o n e db y t h e s a m ec o n t r o l
l e v e li n d i c a t o rt.h e y w i l l a l l p r i n t w h e na l e v e l1 c o n t r o lb r e a ko c c u r s '
o O v e r f l o ws h o u l db e f o r c e di f t h e o v e r f l o wl i n ei s p r i n t e dp r i o r t o b e E i n n i ntgo t a l
output.
r

o T o t a l l i n e s1 , 2 , a n d 3 , m u s tp r i n t o n t h e s a m ep a g e .T o t a l l i n e s4 t h r o u g h7
m u s tP r i n to n t h e s a m eP a g e .
RPG

OUTPUT

u/MC$.

cx2rM

SPECIFICATIONS

,.,"fii.,_

Prqr.h'

75 76 71 78 19 8Q

fff-T-T--l_l

rdeni',carionl

I

I

I

l_L-'J

OutL'u1 lndicalors

53 59 60 61 62 63 64 65 66 67

i- r
rl

Figure 3-40. Total Specifications (Ouestion 6)
Review 3

3-33

F o r m sA l i g n m e n t
7.

W h y i sa c c u r a t e
f o r m sa l i g n m e n titm p o r t a n t ?

8.

w h a t e n t r i e sm u s tb e m a d ei n t h e R p G l r s p e c i f i c a t i o n
s h e e t st o r e p e a p
t r i n t i n gt h e
f i r s t h e a d i n gl i n eo f a r e p o r tu n t i rt h e f o r m sh a v eb e e n
c o r r e c t r ya r i g n e d ?

Editing
9.

C h o o s et h e c o r r e c t e d i t c o d e sf o r t h e f o l l o w i n g p u n c t u a t i o n
a. 1,342,650.00CR (for zero balance,print .00)
b . 1 , 2 4 6 , 9 0 0 - ( f o r z e r o b a l a n c e ,l e a v et h e f i e l d
blank)
c . 1 6 9 4 8 2 4 . 2 5 - ( f o r z e r o b a l a n c e ,l e a v et h e f i e l d b l a n k l
d. 12/13/71

10'

C o n s t r u c ta n e d i t w o r d f o r a 1 2 - d i g i ta c c o u n t n u m b e r s o
that it will print out with
the format XXX XXX XXX XX-X.

11'

o n t h e o u t p u t - F o r m a t s h e e t ,s p e c i f y t h e e d i t c o d e a n d
a n y o t h e r e n t r i e sn e c e s s a r y
t o p r i n t o u t a d o l l a ra m o u n t w i t h t h e f o r m a t
$ * * 1 , 2 3 4 . 5 6 C R . T h e f i e l dm u s t e n d i n
position50. lf the tield is zero,print 00.

IPLACE
12. What is the function of
13 .

*PLACE?

I n t h e e x a m p l es h o w n ,is

*PLACE

usedcorrectly? lf not, why not?

SPECIFICATIONS
llBlrl

.,.,".,...

",,,n.$Md,n.co,po,.,;n

Ooiput Indicators

Constano
t r Edil Word

1 4 . W r i t et h e o u t p u ts p e c i f i c a t i o nt os p r i n t t w o m a i l i n gl a b e l si n a r o w u s i n g" P L A C E "
T h e f i r s t l a b e le n d si n p r i n t p o s i t i o n2 5 , t h e s e c o n di n 6 0 . E a c hm a i l i n gl a b e lw i l l
h a v et h r e el i n e sa n d l o o k l i k e t h i s :
NAME
ADDRl
ADDR2

1 2 5c h a r a c t e r s )
I25}
ZTPCODE
Ir 8)

(5)

Dual PrinterOutput l:iles
15.

Whatdoesthe tlseof the dual feed printerallow you to do?

16.

forms for usewith the Dual FeedCarriage
What limitatiorrsexistwhen designing
Featureon the 5203 printer?

sheets?
17. How do you distinguishbetweenthe two feedson the RPGll specification

Review 3

3-35

AnswersTo Review3
1.

S i x t y - s i xl i n e sa r ea s s u m e pd e r p a g e .F i r s tl i n ep r i n t e di s
0 6 a n d t h e o v e r lfo w l i n e
is 60.

2.

F i l e D e s c r i p t i o n S p e c i fi c a t i o n

F
Extent Ex t
lor DAM

l- "*
|
o

|

|

I I I t----r-t

t

Devrce

r eFo,ma'
t

Name ol

Symbolrc

Labe Exi

Device

Core Inder

I

: i I l : l 'L.6, ! m| L" *eqh-' o

I ] -l : l i l

.

FftUl U8

r

I

I
I

E n l ,y

- . . ^ t _ _ _ _

l o r r r l rr l c

l.____
I LL j

Line Counter Specifications
8

Fc
Ii'"l.l

iFl*,*
r!+!
L

2

9

t0

a

.RlItNiI

q

Y

: :

::

lL

i1

L

L

a:

2

T

? ,

a

i E

1 l

1+

'

1 1

t

l

I

F o r m l e n g t h i s 5 0 l i n e sa n d o v e r f l o w l i n e i s 4 2 . A n y o v e r f l o w
i n d i c a t o ro A - o G o r
o V m u s t b e e n t e r e di n c o l u m n s 3 3 - 3 4 o f t h e F i l e D e s c r i p t i o n
sheet. L must De
e n t e r e di n c o l u m n 3 g t o i n d i c a t et h a t L i n e c o u n t e r s p e c i f
i c a t i o n sa r e u s e d .
?

l f t h e p r i n t e r h a sp r i n t e d o n t h e o v e r f l o w l i n e e i t h e r d u r i n g
total or detailoutput.
t h e o v e r f l o w i n d i c a t o r s p e c i f i e di n t h e F i l e D e s c r i p t i o ns h e e t
is turned on. The over.
f l o w i n d i c a t o r i s t e s t e da n d o v e r f l o w o u t p u t p e r f o r m e d
only after total output.
a . w h e n m o r e t h a n o n e d e t a i ro r t o t a l r i n e i s p r i n t e d d u r i n g o n e
c y c r ea n d a r i n e
o t h e r t h a n t h e l a s tt o t a l l i n e i s p r i n t e d o n t h e o v e r f l o w l i n e .
b . w h e n t h e l a s td e t a i l l i n e f o r a c o n t r o l g r o u p p r i n t s o n t h e o v e r f l o w
l i n e .t h e t o t a l
l i n e sf o r t h a t g r o u p w i l l p r i n t b e l o w t h e o v e r fl o w l i n e .

5.

3-36

The overflow indicator is tested prior to printing each line specified
with fetch overf l o w r a t h e rt h a n w a i t i n g u n t i l a l l t o t a l o u t p u t h a so c c u r r e d .
l f t h e i n d i c a t o ri s o n
w h e n t e s t e d ,o v e r f l o w o u t p u t i s p e r f o r m e d i m m e d i a t e l ya n d t h e n
the line specified
is printed.

6.

F i n c o l u m n1 6 o f l i n e sI a n d 7 o f F i g u r e3 - 4 0 . F i r rc o l u m n1 6 o f l i n e 1 c a u s e s
formsto advanceif the overflowindicatoris on, assuring
that total 1 will not print
belowthe overiilowline and total 3 will not fall overthe perforation.Sincetotals4
through7 musl:all print on the samepageand will not all fit belowthe overflowline,
enterF in the specifications
for total 4 to causea skip to the next pageif the overflow indicatoris on. Sincetotals$7 must print on the samepageastotal 4, no fetch
specification
shouldbe enteredfor them.

7.

Formsmust be alignedaccuratelyso that printingis correctlypositionedon each
pageand so thertprintingoccursexactlywhereyou want it, not aboveor below.

8.

Theremust be at leastone line on the output sheetsconditionedby the 1P indicator.
A ' 1 ' m u s t b e e n t e r e di n c o l u m n4 1 o f t h e c o n t r o lc a r d ,

9.

a .A
b.K
c.M
d.Y

10.

Blankspaces
strowwheredigitsareto be placedand &'s show whereblanksgo. The
entireword must be enclosedin quotes.
RPG

IBII

,!rin.n

xd'm

Co'Fr.ron

OUTPUT

U/MO@'

GX2lm

SPECIFICATIONS

**ffi"

7 5 7 6 7 7 7 8 7 9 S

P,q.om [T_fT_T_T-l
ld.nriridtionl
I

I

I

I

I

I

Output Indicators

Answers To Review 3

3-37

11'

T h e A e d i t c o d ew i l l z e r os u p p r e sasn d i n s e r tc o m m a sd, e c i m apl o i n t s ,
a n dt h e c r e d i t
signCR. The asteriskenteredin columns45-47will causeall placeszero
suppressed
to
b e f i l l e dw i t h a s t e r i s k sT. h e d o l l a rs i g nm u s tb e s p e c i f i e od n t h e l i n ef o l l o w i n g
the
edit code. when printedin position3g, it wiil come right beforethe
asterisks.

SPECIFICATIONS
Card €lecro

Numh.

GX?19@

--

" "- "t_L,t
1| l "
No Sis.

^

End

CB

a
c
D

L

/8 79 80

:rd"",,i,c",,o.1
l * ' i l I T|T |_ T| - IT _| T| - ]

_

J

F i l e n am e

175,76,77

U/MOS'

z

12. T h e f u n c t i o no f * P L A C Ei s t o e a s i l yc o d et h e p r i n t i n go f d u p l i c a t ei n f o r m a t i o no n

t h e s a m eo u t p u t l i n e . * P L A C Ep l a c e si n f o r m a t i o nf r o m p r i n t p o s i t i o n1 . t h r o u g h
the highestend positionpreviouslydefinedfor a field into the print positionsindicatedby the end positionin the "pLACE entry.

1 3 . I t i s n o t c o r r e c t .T h e e n d p o s i t o ni n t h e * p L A c E s p e c i f i c a t i oins n o t h i g he n o u g h .

T h ed u p l i c a t e d
i n f o r m a t i o nw i l l o v e r l a yt h e f i e l dc a l l e dA C C T N O . T h e e n d p o s i t i o n
o n t h e * P L A c E l i n es h o u l db e a t l e a s t w i c et h e h i g h e set n d p o s i t i o np r e v i o u s l y
specifiedfor that record.

1 4 . Two labelsmust be printed. Therefore,for eachline you must specifythe original
f i e l da n da " P L A C Ee n t r y ,w h i c hw i l l c a u s et h e c o n t e n t so f t h e o r i g i n afli e l d t o b e
duplicated.

P a g eo f G C 2 1 - 7 5 6 7 - 2
l s s u e d2 4 M a y 1 9 7 6
By TNL: GN21-5389
c x 2 1 9 G 0 U / M0 S '
P r . r e d , nU s A

1

2

4 e f-Tr
L
1-]or

r

r

.

q

,

rru"',i.,'-

75 76 17 7A 19 aO
J m t t l t t l

I

I

|

|

I

I

rr€rzrLt0t6€fftc9e

15

T h e d u a l f e r e dc a r r i a g ea l l o w s t h e p r i n t i n g o f t w o i n d e p e n d e n tr e p o r t ss i m u l t a n e o u s l y .

i6.

A n r i n i m u n ro f s e v e n t e e np r i n t p o s i t i o n sm u s t b e l e f t b l a n k b e t w e e nt h e t w o o u t o u t
forms.

| 1 7 . Model l0 c'ard System, Model l0 Disk system, and Model l2:

The only difference
i s t h a t t h e < l e v i c en a m e o n t h e F i l e D e s c r i p t i o ns h e e tf o r t h e l e f t c a r r i a g ei s P R I N T E R
a n d f o r t h e r i g h t c a r r i a g ei s P R I N T R 2 .

M o d e l 6 : 1 - h eo n l y d i f f e r e n c ei s t h a t t h e d e v i c en a m e o n t h e F i l e D e s c r i p t i o ns h e e t
for the left tractor is TRACTR 1 and for the right tractor is TRACTR2.

A n s w e r sT o R e v i e w 3

3-39

340

Chapter4. CardOutputOperations

C H A P T E R4 D E S C R I B E S :
P u n c r r e do u t p u t .
P r i n t i n go n c a r d s .
U s i n go n e f i l e f o r b o t h i n p u t a n d o u t p u t .
S e l e c t i n gt h e s t a c k e rf o r o u t p u t c a r d s .
M e r g i n gi n p u t a n d o u t p u t f i l e c a r d s .

B E F O R E R E A D I N G T H I S C H A P T E RY O U S H O U L D B E A B L E T O D E S C R I B E :
U s i n gt h e p r i n t e r t o p r o d u c ea s i m p l e l i s t i n g .
U s i n gc o n t r o l f i e l d s .
R P G l l o b j e c t p r o g r a mc y c l e f o r d e t a i l a n d t o t a l o p e r a t i o n s .

A F T E R R E A D I N G T H I S C H A P T E RY O U S H O U L D B E A B L E T O D E S C R I B E :
C o d i n g f o r p u n c h i n ga c o m b i n e d o r o u t p u t c a r d f i l e ; s u m m a r y p u n c h i n g .
Formattedprintingand unformattedprinting (-PRINT) on cards.
U s e sa n d c o d i n g f o r c o m b i n e d f i l e s .
S t a c k e rs e l e c t i n gi n p u t , c o m b i n e d ,a n d o u t p u t c a r d f i l e s .
C o d i n g f o r m e r g i n gi n p u t a n d o u t p u t c a r d f i l e s .
Note: You can use the review questions contained in Review 4 atthe end of this
c h a p t e rt o t e s t y o u r c o m p r e h e n s i o no f e a c ht o p i c i n t h e c h a p t e r . Q u e s t i o n sa r e
g r o u p e da c c o r d i n gt o t h e t o p i c t o w h i c h t h e y a p p l y . A n s w e r sf o l l o w t h e r e v i e w
qu e s to
i ns.

C a r dO u t p u t O p e r a t i o n s 4 - 1

!NTHODUCTIOI\
T h u s f a r - ,i n t h i s m a r r r , r atlh, e p r o g r a m o u t p u t u s u a l l y h a s
b e e n a p r i n t e d f o r n r o r r e p o r t . p u n c h e dc a r d sg e r r e r a l l y
h a v e b e e r iu s e da s a s J u r c eo f i n p u t d a t a . H o w e v e r ,c a r d s
c a n b e u s r - . fdo r o u t p u t a s w e l l a s i n p u t . T h i s c h a p t e rd e s _
c r i b e s R P G l l c o d i n g f o t . o u t p u t o p e r a t i o n su s i n gt h e I B M
5 4 2 4 M F C U , a v a i l a b l eo n t h e S y s t e m / 3 M o d e l s 1 0 a n d 1 5 ,
and the IUM 2560 MFCM,available
o n t h e S y s t e m / 3M o d e l
15onlv.
Y o u m i g h t w a n t t o h a v ec a r < o
Jutput for many reasons.
P e r h a p sy o u w a n t t o g e n e r a t ea n e w f i l e o r c h a n g ea n i n p u t
f i l e i n s o n r ew a y , s u c h a s b y r e f o r m a t t i n gt h e r e c o r d s ,a d d i n g d a t a , d e l e t i n gd a t a "a d d i n g r r e w r e c o r d s ,o r d e l e t i n gu n _
w a n t e d r e c o r d s . T h e o u t p u t y o u c h o o s em i g h t b e d a t a
p u n c h e do n t h e c a r d s ,p r i n t e d o n t h e c a r d s ,o r b o t h .
In_
f o r m a t i o n c a n b e p r i n t e d o n c a r d sf o r i d e n t i f i c a t i o n ,i n t e r _
p r e t a t i o n o f t h e p r , r n c h e d a t a , o r a n y o t h e r p u r p o s ey o u
d e s i r e . Y o u c a n p u n c h a n d p r i n t d a t a o n b l a n k c a r d so r o n
c a r d st h a t a l r e a d yc o n t a i n d a t a . y o u c a n a l s o d i r e c t c a r d s
t o a s p e c i fi c s t a c k e ro r m o r e o L t t p u tf i l e c a r d sw i t h c a r d s
from an inputfile.

P U N C H I N GA N D P R I N T T N GO N C A R D S
P u n c h i n ga n d p r i n t i n g o n i n d i v i d u a lo u t p u t c a r o sa r e c o n _
t r o l l e d s e p , a r a t e l yP. u n c h e dc a r d sn e e d n o t b e p r i n t e d ;
p r i n t e d c a r d sr r e e dn o t b e r r u n c h e d .

Punched Output
P u n c h e do u t p u t c a n b e u s e dt o :
o C r e a t ea f i l e o f c a r d st h a t i s d i f f e r e n t f r o m t h e i n p u t
card
f ile
.

A d d n e w r e c o r d st o a c a r d f i l e

o A d d f i e l d st o i n p u t r e c o r d s
o

P u n c ha s u m m a r yc a r d f r o m a g r o u p o f i n p u t c a r o s

R P G l l c o d i n gf o r p u n c h e do u t p u t i s s i m i l a rt o c o d i n gf o r
p r i n t e r o u l p u t . E i t h e r t h e p r i m a r y h o p p e r ( d e v i c en a m e
M F C U l o r M F C M l ) o r t h e s e c o n d a r yh o p p e r( d e v i c en a m e
M F C U 2 o r M F C M 2 ) c a n b e u s e da s t h e o u t p u t d e v i c e ;t h e
o t h e r h o p p r e ri s u s e da s t h e i n p u t d e v i c e . I n s o m e c a s e s ,
p u n c h i n gc a n b e d o n e o n t h e i n p u t c a r d st h e m s e l v e s( s e e
Using One File for Botir lnput and Output, in this chapter).
R e m e m b e r h, o w e v e r ,i f o n l y o n e M F C U h o p p e ri s
u s e d ,i t
m u s t b e M F C U l ( M o d e t 1 0 C a r dS y s t e mo r r l y ) .

4-2

O n t h e O u t p u t - F o r m a t s h e e t ,y o u c a n s p e c i f y h e a d i n g ,d e tail, and total output, just asyou can with a printer file. ln
s o m e c a s e sy, o u m a y w a n t t o p u n c h o n l y t o t a l r e c o r d sb y
s u m m i n gt h e d a t a o n s e v e r a il n p u t r e c o r d sa n d p u n c h i n ga
separatecard for the total. This is known as summary
punching. Do not specify an edit code for punched output
u n l e s sy o u w a n t t o h a v e p u n c t u a t i o n p u n c h e d i n t o t n e o u t put cards.

Printing On Cards
I t i s a d v a n t a g e o utso p r i n t t h e s a m ei n f o r m a t i o n o n t n e
c a r d a s w a s p u n c h e do n t h e c a r d . T h i s w a y y o u c a n e a s i l v
i n t e r p r e tw h a t i n f o r m a t i o n i s r e c o r d e do n t h e c a r d . A l s o ,
p r i n t i n g i n f o r m a t i o n o n t h e c a r d m a k e si t e a s i e rt o r e c r e a t e
a card that is damaged to the extent that it cannot be read
b y t h e M F C U o r M F C M , o r d u p l i c a t e db y t h e d a t a r e c o r d e r .
A l t h o u g h y o u m a y p r i n t t h e s a m ei n f o r m a t i o n o n t h e c a r d
t h a t i s p u n c h e d o n t h e c a r d , i t i s n o t a l w a y s . n e c e s s a troy
d o s o . Y o u m a y p r i n t e n t i r e l y d i f f e r e n t f i e l d sf r o m t h o s e
that are punched.
T h e 9 6 - c o l u m n c a r d h a s s p a c ea t t h e t o p f o r f o u r l i n e so f
p r i n t i n g( F i g u r e4 - 1 ) . E a c h l i n e c a n c o n t a i n3 2 p r i n t e d
c h a r a c t e r sf,o r a t o t a l o I 1 2 8 p r i n t p o s i t i o n s .
T h e 8 0 - c o l u m nc a r d c a n b e p r i n t e d o n l y o n t h e M F C M
Model A1 with the optional print feature. Up to six print
l i n e sc a n b e u s e d . E a c h l i n e c a n c o n t a i n u p t o 6 4 p r i n t e d
c h a r a c t e r sf,o r a t o t a l o f 3 8 4 p r i n t p o s i t i o n s .
T h e M F C M p r i n t h e a d sc a n b e s e t t o p r i n t i n 2 5 d i f f e r e n t
p r i n t l i n e p o s i t i o n s ,f r o m a b o v e t h e 1 2 - p u n c hp o s i t i o n t o
b e l o w t h e 9 - p u n c h p o s i t i o n s( F i g u r e 4 - 2 1. T h e p r i n t h e a d s ,
n u m b e r e d 1 t h r o u g h 6 , m u s t r e m a i r ri n s e q u e n c ef r o m t o p
t o b o t t o m , w i t h p r i n t h e a d 1 a t t h e t o p . T h e r e f o r e ,w i t h
s i x p r i n t h e a d si n s t a l l e d ,p r i n t h e a d 1 c a n n o t b e s e t b e l o w
l i n e 2 0 a n d p r i n t h e a d 6 c a n n o t b e s e t a b o v el i n e 6 . l n t e r m e d i a t el i n e p o s i t i o n sa r e l o c a t e do n a n d b e t w e e ne a c h r o w
o f p u n c h p o s i t i o n s . P r i n t - p o s i t i o n5 ( b e t w e e nt h e 1 1 - r o w
a n d O - r o w )s h o u l d b e a v o i d e d ,i f p o s s i b l e b
, e c a u s et h e f e e d
w h e e l m a y c a u s es o m e s m u d g i n go f c h a r a c t e r sp r i n t e d i n
t h a t p o s i t i o n . I n p u n c h e df i e l d s ,p r i n t i n gi n e v e n - n u m b e r e d
l i n e p o s i t i o n ss h o u l d b e a v o i d e db e c a u s ep u n c h i n g m a y
obl iterate some characters.

Formatted Printing (MFCU)
Usingformattedprinting,you may print a field or constant
i n a n y o f t h e 1 2 8 p r i n t p o s i t i o n as v a i l a b loen a 9 6 - c o l u m n
c a r d . T h e f i r s t t h r e el i n e sa r et h e l i n e su s u a l l yp r i n t e d .T h e
fourth is printedonly if necessary
printingon the
becar.lse
fourth line increases
considerably
the amountof time needed
to print, and thus increases
the time neededto do the job.
Printinglines-1

6

7

3

I

r0

1 6 r ? 1 6 1 9 2 0 2 1 2 2 3 2 4 2 5 2 6 2 7 2 A 2 9 3 0 Xt l2

33 3a 35 36 37

53 sa 55 s6 st

556567536970111?J371

5 16 ro7ro3 r@ flo

B

30dS2a33.a5€6S73a30

il5 ar il6 ilg r20 ra 12 r23r

)

a
2
1

21 22 23 Xl 25 26 2j 2A 2s 30 11 32

a

1

a

2
I

I

a
1
65 S

67645910

7112

131.

30 3r a2 A3a4

35 66A7

3eA990

9t 92 93 94 9s95

a
4
2
I

tlt37@

Figure4-1. Printing Lines on a 96-Column Punch Card

'l

2
J

4
5
0000000000000000000000008000000000000000000008000000000000000008000000u00
6
1 l l l l 1 I I I I i I I I 1 1 1 I 1 ' l1 l l 1 I I 1 I 1 1 1 1 I 1 1 I I I | 1 I 1 1 1 I I I I I l l l t I 1 l ' t I I I 1 I 1 1 1 t t t I I I 1 1 1 I I 1 1 I 1
o
o

2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 21202 2
't'l
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 31323 3 3 3 3
13
4 4 4 4 4 44 44 44 4 44 4 4 4 44 4 4 4 44 4 44 4 4 4 4 44 4 4 4 4 4 44 4 4 4 4 4 4 4 4 4 4 4 4 44 4 44 4 4 4 4 4 4 4 4 4 4 4 4 44 4 4 4 44 4 4
14
t z : l s o i 8 9 1 0 i t 2
15
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
5 5 5 5 5 5
16
17
6 6 0 6 6 6 0 6 6 6 6 6 6 6 b 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 5 6 6 6 6 6 6 6 6 6 6 61 8
6 6 6 6 6 6
19
1 1 7 1 1 1 1 1 7 1 1 1 1 1 1 1 1 1 1 7 7 1 1 1 1 1 7 7 1 1 7 1 7 1 1 7 1 1 1 7 1 1 1 7 7 1 1 1 7 11 11 71 11 17 11 71 11 11 11 11 11 .177 7 1 7 1
20
2'l
8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 . 8 & 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 22
8 8 0 8 8 8
23
9 9 3 9 S 9 9 9 9 9 9 9 9 9 9 S S 9 9 9 9 9 9 9 9 9 S 9 9 9 9 9 9 9 9 9 S 9 S S 9 9 9 9 9 9 S 9 9 S 9 3 S S 9 9 S 9 9 S S 9 9 S S S S 9 S S S 9 S 9 9 9
24
25

F i g u r e 4 - 2 . P r i n t i n g L i n e s o n a n 8 O - C o l u m nP u n c h C a r d

Card Output Operations

4-3

P a g eo f G C 21 -i t i 6 7 - 2
lssued
3 f JJ u n e1 9 7 8
-l-Nr*:
By
cN21-5616
F o r e a c h f i e l , l o r c o n s t a n ty o u w i s h p r i n t e d b y t h e M F C U ,
y o u m u s t m a k r :t h e f o l i o r v i n gs p e c i f i c a t i o n so n t h e
O u t p u t S p e c i ifc a t i o n ss h e e :t

- J A NI C E T S W E N S O N
C H A R L E S VLTL E , I D A H O

71632118

9 1 71 5 8

l f a f i e l d i s t o b e p r i n t e d ,e n t e rt h e f i e l d n a m e i n c o l
u m n s3 2 - 3 7 .
E n t e r " i n c o l u m n 4 0 t o i r r d i c a t et h a t t h e f i e l t l i s r r _ r
b e p r i n t , , d n t - l tp L n c l t e d .
E n t e r a n y e n d p o s i t i o nf r o m 0 0 1 t o 1 2 8 i n c o l u m n s
41 43.
i f a c o n s t a n tr s t o b e p r i n t e d ,e n t e rt h e c o n s t a n ti r r
c o l u m n s4 5 - 7 0 .
F o r e x a r n p l et,o p r i n t t h e f i e l d so n t h e c a r d s h o w n i n F i g u r e , 4 - 3 t, h e s p e c i t i c a t i o ni sn F i g u r e4 - 4 l i n e s0 6 - 1 0 a r e
n e c o s s a r y .Y o u i n d i c a t ep u n c h i n go f t h e s ef i e l d s b y s p e c i f y i n g a n e n d p r t s i t i o nw i t h o u t t h e a s t e r i s k( s e eF i g u r e4 - 4 ,

Figure 4-3. Formatted Printing on a 96-Column Card

l i n e s0 2 - 0 5 ) . l f y o u i n t e n d t o p u n c h f i e l d sa n d p r i n t f i e l d s ,
y o u n e e dt w o : ; p e c i f i c a t i o npse r f i e l d . l f y o u h a v es e v e n
f i e l c l st o b e b o t h p u n c h e d a n d p r i n t e d , y o u n e e d i 4 s p e c i f i ,
c a t io n s .

a f i e l d r v i t h o u tp r i n t i n gi t . l f y o u p u n c h a n d p r i n t t h e s a m e
f i r : l d ,y o u m a y p u t e a c l -irn d i f f e r e n t p o s i t i o n s . l r r o t h e r
w o r d s , y o u m a y f o r m a t t h e p u n c h e df i e l d si n a c l i f f e r e n t
w a y t h a n y o u f o r m a t t h e p r i n t e df i e l d s .

p r i n t i n ga n d p u n c h i n ga r e t w o s e p a r a t e
Because
functions,
i t i s p o s s i b l et c p r i n t a f i e l d w i t h o u t p u n c h i n gi t a n d p u r r c h

t;;""1F,,,;,

RPG
I'l

I t'

l_

i

1------

lto|

1

OUTPUT

i

'

t ' :

tl

t

r

|

lrr,l
li
1l l;l ffi
lL-'

I l-;.r;','

'l''l'

i l,i I l"lclAlRDloiur
lD

itl-[:11ill
l[,,.]'l]'l

lii,tl'llli
ll,';1;1rl

e Mle

DiR
CT
AL

luie
t_l-

5

c c TN C
AL

iriAlrU S

F i g u r e 4 - 4 " S p e r : i fi c a t i o n s f o r P u n c h i n g a n d P r i n t i n g o n a C a r d ( F o r m a t t e d

44

.",.,.,",,;,,,".]

SPECIF
ICATIONS

Printing -

MFCU)

|

/t

l

r

rj

, ,, /8_rt,81l

-

I

i

l=ormatted Printing - MFCM
[Jsingformattedprinting,you can print a field or constant
o n a n y s i x o f t h e 2 5 p r i n t l i n e sa v a i l a b loen a n g 0 _ c o l u m n
card. For eachfield or constantyou wish printedby the
l / l F C M ,y o u m u s tm a k et h e f o l l o w i n gs p e c i f i c a t i o nosn t h e
O u t p u t - F o r m asth e e t :
1.

W h e np r i n t i n ga f i e l d .e n t e rt h e f i e l d n a m ei n c o l u m n s
32-37.

tL.

S p e c i f ya p r i n t h e a dn u m b e r( 1 - 6 )i n c o l u m n4 1 .

:1.

S p e c i f ya p r i n t e n d - p o s i t i o(n0 i - 6 4 ) i n c o l u m n s4 2
a n d4 3 . ( T h el e a d i n gz e r oi s r e q u i r e dw h e ns p e c i f y i n g
p r i n t p o s i t i o n0
s 1- 0 9 . )

4..

W h e n p r i n t i n g a c o n s t a n t ,e n t e r t h e c o n s t a n t i n
c o l u m n s4 5 - 7 0 .

F o r e x a m p l et,o p r i n t t h e f i e l d ss h o w ni n F i g t . r r4e- 5 ,t h e
specifications
shownin Figure4-6 are necessary.
Coding
l i n e s0 2 t h r o u g h0 5 c a u s et h e f i e l d st o b e p u n c h e d .C o d i n g
l i n e s0 6 t h r o u g h10 c a u s et h e f i e l d sa n d a c o n s t a n t ,
BALANCE.to be printed. As you can see,two specifications
are requiredfor eachfield that is to be both punchedand
p r i n t e d . I n o r d e rt o o b t a i nt h e d e s i r e dp r i n t i n gr e s u l t st,h e
M F C Mp r i n t h e a d sm u s tb e a l i g n e dm e c h a n i c a l lpyr i o rt o
r u n n i n gt h e p r o g r a m .
Note: The fourth line of printingalsocould havebeen
printedusingprint head4, with print heads5 and 6 set to
l i n e p o s i t i o n lso w e ro n t h e c a r d .
B e c a u sper i n t i n ga n d p u n c h i n ga r et w c s e p a r a tfeu n c t i o n s ,
i t i s p o s s i b l teo p r i n t a f i e l d w i t h o u t p u n c h i n gi t a n dt o
p u n c ha f i e l d w i t h o u t p r i n t i n gi t .

'ftulnttn'r

I I r nrr
riiiiilll'I'ft InAHBnu
r
iiilt:

000000010I1001000000000c00110[00100000000!00000010000000r]!c0000000!000000rJLrirrr

'

l l t r r I I I 1 I 1I 1 1 1 I 1 I r l 1 I I I i 1 i I r I I I I I r t I r r r r 1 r r I I 1 I 1 l I I I I I I J I I i 1 I I J I I I 1 1 I i ! I I I i i I 1 1
22't-2222.221222a22222222'ttizlzz222r???22)222r?ai2?22222tittL22222t2t?22222r2221122t
BRTANEE
174.38
3 3 3 3 1 3 3 l i J 3 3 J i 3 3 i 3 : : l l r t l i I 3 3 l l 3 l j : i : r i tl rr - ?s i 3 l t I 3 I 3 3 3 I r 3 3 : : t l j : ij 3 I 3 - 1 .! l I j 3 . t3 j . i r : l I i i r r r
4 4 4 4 4 ,14 ,i 4 4 4 4 4 4 4 '1.14 4 ,i 4 4 4 4 4 4 t, ^ 1 N4 4 4 4 4 | 4 ii .'.ti ,'.| 4 ,14I I 4 4 4 4I 4 ,1,t 4 4 4 4 4 4 . t 4 4 4 4 q 4 4 4 ,t 4 4 !. + 4 4 4 ;:
55l5bl:55i5lli,!l5555t5t5515li5flirbri5b5i5555fi5i55iilttrrigb55hr5rrft5bi5ilrtrr!:r!:,!
066666{i66[106616[rie6f66t66!!6i6"cG[66i,ril[s616ri66666{iciIr]ijb.6666b56665666[ttc6t]6f,
1 t l t 1 1 1 i 1 t t 1 1 1 t t 1 1 1 t t 1 1 1 l 1 1 l 1 1 t 1 1 t 1 t t 1 1 l l t t 1 1 t 1 1 t t a t i t 1 1 t t 1 1 r l i 1 t 1 1 1 1 t 1 i t t t 1 i t t i
8888888888tj88888rtiIBll68e8888iisBlsssBlsaBs888sel8dtllal68r8rii)r88Bit8trrtii]t88Est
99913s!999999r!9$99ss99f9999199segfs99!99999!!99999sst!9s!9999s9!srssl!9sl]9999!!

o

F i g u r e 4 - 5 , F o r m a t t e d P r i n t i n g o n a n 8 O - C o l u m nC a r d

Card Outout Operations

4-5

RPG

OUTPUT

SPECIFICATIONS
P,q'!m

""*fitl",-

ld.nrl,c.r,onl

75 76 77 78 79 80

fTl-T-T-T-l
|

|

I

I

|

|

a 2

l +
0 l
T
0

:
0

:

T

I
I

i
I

I

l

o

l ; i g u r e 4 - 6 . S p e c i f i c a t i o n s f o r P u n c h i n ga n d P r i n t i n g o n a C a r d { F o r m a t t e d P r i n t i n g - M F C M I

UnformattedPrinting (*PRINT) - MFCU and MFCM
Usingformattedprinting,recallthat if you wish to both
p u n c ha n d p r i n t a f i e l d .y o u m u s th a v et w o e n t r i e sp e r f i e l d
, o nt h e O u t p u t - F o r m asth e e t :a p u n c he n t r y a n da p r i n t
e n t r y . l f y o u w a n t s e v e r af il e l d st o b e b o t h p u n c h e da n d
printed,thereis a greatdealof codinginvolved.
R P Gl l h a sa s p e c i arle s e r v ew
d o r d , * P R l N T ,w h i c ha l l o w s
y o u t o p u n c ha n d p r i n t f i e l d sa n d c o n s t a n tw
s i t h l e s sc o d i n g .
*PRINT
When
i s s p e c iife d ,i t c a u s easl l p r e v i o u fsi e l d s
d e s c r i b efdo r t h e r e c o r dt o b e p r i n t e d . U s eo f * P R I N T i s
printing.
k n o w na s u n f o r m a t t e d
F i g u r e4 - 7 s h o w st h e u s eo f t h e - P R I N T s p e c i f i c a t i o n .
N A M E ,A D D R , A C C T N O a
, n d B A L a r et o b e p u n c h e d .
F o l l o w i n gt h e s ef i e l dn a m e si n c o l u m n s3 2 - 3 7i s t h e e n t r y
" P Rl N T . T h i se n t r yc a u s etsh e p r e v i o u fso u r f i e l d st o a l s o
be printedon the card (seeFigures4-8 and 4-9).

* P R I N Tw i t h
Using
t h e M F C Uc a u s efsi e l d sa n d c o n s t a n t s
to the punchposito be printed in positionscorresponding
t i o n s .F o r e x a m p l eA, C C T N Oi s p u n c h e di n p o s i t i o n 4s 1 - 4 8
s1-48.
a n da l s oi s p r i n t e di n p o s i t i o n 4
on
On the MFCM,there is not spaceto print 80 characters
one line. Therefore,datapunchedin columns1-64is
printedin print positions1-64by print head1; data punched
in columns65-80is printedin positions49-64 by print
h e a d2 ( F i g u r e4 - 9 ) ,
*PRINT
can be usedonly oncefor a recordand
The word
must be enteredafter the descriptionof all fieldsthat are
to be both punchedand printed. Suppose,insteadof print, ndBAL),
i n ga l l f o u r f i e l d s( N A M E ,A D D R . A C C T N O a
y o u w a n t t o p r i n t o n l y N A M E a n dA C C T N O . I n t h i s c a s e ,
* P R I N T m u s tf o l l o w N A M E a n d A C C T N O .
theentry
* P R I N Te n t r y
A D D R a n d B A L m u s tb e d e s c r i b eadf t e rt h e
(Figure
4-10).
Columns7-22 and39-74must alwaysbe left blankon the
*PRI NT
specificationline.

4-6

P a g eo f G C 2 1 - 7 5 6 1 - 2
l s s u e d2 4 M a y 1 9 7 6
By TNL: cN21-5389

RPG

OUTPUT

SPECIFICATIONS

O L l t ) u 1I n d i c a t o r s

i) l":;ry1'::Ui;i'

F el(l Name

I

ill

t-

Ena

sla
-l

9

,l

B

Ye5

hl

N.

Y.5

Cofs

' .

l l
I

i

l

r l
'

4lYEil

_
lDDiRl
rcclT}lf
.A,L., i
,PlRIiN:

l

i i l l
;Lh
q6

, i ' l i i :

'

r l

:

l

t i ii ii ,i l

t

a
a a

a

a a

a

a

B

a o
a
a

a
a
a a
a a a a a a a a a a O

a
a

a

a
a
a
a

a

a a
a a

a a a a

a

2
l

a

a

a

a
a
a

- ; - C i

a . . a a a - a a a

r a a

a

2
1
B

o .
a

a a a

a

a
a a a a a a
1 a ] l 5
a

l , i l

a

a

a

2
l

. .

a a a
a

!,i

1

s, 'e ror

a

a

l l

i

,!

. . . . a .
a a

Y'\

LIt

i l;

a

v",

a
a a a
a a
a
a

a

a

a
a

a a

a a

a

a

a
2
l
B

a

a

2
1

2

Figure4-8. Unformatted Printing on a 96-Column Card
F i g u s e4 - 7 . P u n c h i n ga n d P r i n t i n g o n a C a r d U s i n g * p R l N T
{ U n f o r m a t t e d P r i n t i n g}

J E NI C E

I tll
t l
'

T

lsr.tENsoNill
TAILEfriliE,
lll
tt
Ir
I

rIAH!
7463?44A0t7459

.000000010II001000000000000IItj{rrcI00(iir0I]!r'rlj000000000c0000irii000000000000110t
l I r 1 1 1 1 1 1 1 1 I I I 1 i i I I i r 1 I r r I I I 1 r i r 1 r r r l r 1 r r i 1 r r I r 1 I 1 I I I i i 1J I I I 1 I I I i I i I I 1 I i 1 l I I I I I 1
2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 2 2 1 1 i 2 2 a 2 ? t 1 1 2 2 2' ,?! 2 7' -i t2121t 22 '2, 2
\ i)21t22i2222?t)112?222i22227
3 3 3 3 1 3 3 1 3 3 r J 3 i ]3 3 3 3 i l 3 l i {3 r l i r 3 3 l I 3 l : J3 r 3 3 I 3 i i 3 3 j i i I 3 3 3 3 : t3 I I 1 : J3 3 3 I i t3 : j3 3 3 l : j : l 3 3 I j I j j ! !
4 4 4 4 4 14 4 , 1 4 44u 1 4 ! 4 4 4 I 4 4 4 4 i , 1 , 4i , l{ t , 4 4 4 4 1 4 : ! !i t) ,14 , 14 / 4 , i4 4 4 t : r ,44t , 4 4 4 4 . 1j r,11. r 1 4 , 1 1 1 44I t I 4 4 4 I
5 5 1 5 5 1 5 5 s 5 5 l l r 5 1 5 5 5 5 5 5 5 5 5 15 l i i r l 5 ! 5 r i ! i 5 5 r r r r! 5 5 5 5 5 | r | 5 ! | 5 5 5 5 5 5 i 5 5 5 5 5 5 5 r 5 ! 5 ! ! l 5 r )!
i 6 6 6 6 ti i 6 u Il 6 l; ol o t lj b r 6 6 6 6 6 6 t 6 tj r i; rj 6 6 i 6 ti 6I 6 e 6 0 r] 6 6 6 6 b 6 6 6 t t i,6 6 0 f [ 6 ! 6 ij i r]l 6 6 6 6 it ir 1 i 6 0 l, r, fJ
1 1 t i J 1 1 1 t 1 1 t J t 1 1 i t 1 1 1 1 l 1 1 1 t 1 t 1 1 1 1 i 1 1 1 1 t t t 1 1 t 1 1 t 1 t 1 1 i l l 7 t 7 t t 1 1 t 1 t l l t t 1 1 1 t l t l t i t t 1
6 I I 8 8 I 8$ 8 8 s I I t j8 8 I I I I r l 8 I 8 8 8 I 88 s 8 l I s 8 B l I I s s 8 8 8 6 I I 8 I I 8 6 I I I 8 3 I g I i 8 8 8 8 s F a e B l s f lI I B l I l i

ssslssgrs$999999r!9r9!9f9E9919S9991-q9999999999S99S9993999S999999!99!9l]9!9!9

Figure4-9. Unformatted Printing on an 80-Column Card

CardOutput Operations 4-7

RPG

OUTPUT

SPECIFICATIONS

RPG

OUTPUT

f:":'il

SPECIFICATIONS

I ";;,,,,"

l

I

i

l

Oulprrl I ri{ii(nlors

f

,
l

l

I c..ir ;;;n: , ,, i

I

r L

r'-,..,

r l

L.rl

i t-

;l:
,,,1.,
.

l

1 1

1

l

.L]L

rtl

,2J

,

All'lE
DDR
L

b

.

r

1

,

i
l

.PRI N

F i g u r e4 - 1 1 . C o n d i t i o n i n g* P R I N T E n t r y
Figure 4-10. Using *PRINT to Specify Fields When Some are
Punched Only

USINGONE FILE FOR BOTH INPUT AND OUTPUT
Y o u m a y u s e a n y i n d i c a t o r i n c o l u m n s 2 3 - 3 . 1t o c o n d i t i o n
-PRINT
the
e n t r y . T h a t s p e c i f i c a t i ow
n ill thenbe perf o r n r e do n l y w h e n t h e c o n d i t i o n s e t b V t h e i n d i c a t o rr s
m e t . F o r e x a r r p l e ,a c c o r d i n gt o t h e s p e c i fi c a t i o n i n F i g u r e 4 - 1 1 , l i n e 0 5 . t h e f i e l d sw i l l b e p r i n t e do n l y w h e n 1 0
a n d 2 1 a r e b o t h o n a t t h e s a m et i m e .

In your experience
w i t h R P G l l , y o u h a v eu s e dc a r d f i l e sa s
f
i n p u t i l e sa n d o u t p u t f i l e s . S u p p o s e ,h o w e v e r ,y o u w a n t e d
t o p u n c h i n t o t h e s a m ec a r d t h a t w a s r e a d i n t o t h e c o m p u t e r . l s i t p o s s i b l et o u s e i n p u t a n d o u t p u t f i l e s t o d o t h i s ?
N o , i n p u t c a r d sa r e o n l y r e a d a n d o u t p u t c a r d sa r e o n l y
p u n c h e d o r p r i n t e d . W h a t y o u n e e r li s a c o m b i n a t i o n o f t h e
two. The RPG ll language
a l l o w ss u c ha f i l e c o m b i n a t i o n .
This type of f ile is called a contbined file.

Editttng A Fielo' Printed on the Card
A n y f i e l d t h a t i s t o b e p r i n t e d , u s i n ge i t h e r f o r m a t t e d o r
u n f o r m a t t e d p r i n t i n g , c a n b e e d i t e d . T h i s , o f c o u r s e ,w i l l
m a k t .t' h e p r i n t e d f i e l d e a s i e rt o r e a d a n d u n d e r s t a n d .
E d i t i n g a f i e l d t . o b e p r i n t e d o n t h e c a r d i s d o n e r r )r n e s a m e
way aseditinga f ield to be printed on the printer. How,
e v e r ,e d i t i n g s h o u l d b e k e p t a t a m i n i m u m s o t h a t t h e l e n g t h
o f t h e p r i n t e d f i e l d w o n ' t b e c o n s i d e r a b l yl a r g e rt h a n t h e
l e n g t h o f t h e p u n c h e d f i e l d . Z e r o s u p p r e s s i o no r m e r e l y r e m o v a l o f t h e s i g t na r e o f t e n d o n e s i n c et h e v d o m a K et n e
p r i n t i n g e a s i e rt o r e a d , b u t s t i l l k e e p t h e p r i n t i n g i n a o n e t o - o n e r e l a t i o n s h i pw i t h t h e p u n c h e s .

N o t e : l n t h i s d i s c u s s i o no. n l V t h e M F C U i s u s e d f o r r " eef r e n c e ;u n l e s sn o t e d o t h e r w i s e ,t h e M F C M c a n b e u s e d i n t h e
s a m ew a y .

Punching Into the Same Card that is Read
A c o m p a n y k e e p sa d a i l y r e c o r d o f t h e a m o u n t o f e a c h i t e m
sold. At the end of the week the daily amount sold for each
i t e m i s p u n c h e d i n t o t h e c a r d i n s i x d i f f e r e n t f i e l d s ,o n e f i e l d
p e r d a y . T h e s ec a r d sa r e t h e n u s e d i n a p r o g r a mw h i c h t o t a l s
t h e d a i l y a m o u n t s o l d f o r e a c h i t e m a n d p u n c h e st h a t t o t a l
i n t o t h e s a m ec a r d t h a t c o n t a i n e dt h e d a i l v a m o u n r s .
F i g u r e4 - 1 2 s h o w st h e f o r m a t o f t h r : d a t a c a r d w h i c h i s r e a d .
E a c h c a r d c o n t a i n st h e e n d o f t h e r r u e e d
kate (DATE), the
i t e m n u m b e r ( I T E M N O ) a n d d a i l y a m o u n t ss o l d ( F L D 1
t h r o u g h F L D O ) . F i g u r e4 - 1 3 s h o w st h e s a m ec a r d a f t e r i t
h a s b e e n p u n c h e d . T O T A L i s t h e f i e l d p u n c h e da f t e r t h e
t o t a l a m o u n t s o l d h a s b e e nc a l c u l a t e d .

4-8

I

r r

r r r

r !

t t r a . o . r . t

:

t r u , ! r . r ! r a t , r r : , r o , r , ,

. a a r r o l r t r r r . a r r a ! r s r a o a r a a . r s

o

I

!n

l

u

n!

M

t

t

Et rlt

rl.

16 rr.

t
'r.o

[,

rr

i

I oere | ,rerrnruo
lr,-olrr-olr.o
leuoi
i . t ' . . Il
l r l ,zo I :lr r sr rI .d rl , rcx , 6ln ,u8 ?

:

"'

i
A

lrr{ er{
? r 35x ' t s1! t 6! . ]1r . o . ,

l

l

.r.r {$

;

o

:
2

!, r rre r!r. rtr. rr.0.,.,.r..

I

F i g u r e4 - 1 2 . C o m b i n e d F i l e C a r d R e a d

.!...!

{.r.a.r

50'

sr rr l. t5 $ rt

al6aratat

i

t

tt r$ rn tr rr] rr. r- rra trt rr

I

t

l

l
l

t
l

t

r

a

a

ootr rrEMNoF.o lrro I F L D I F L D F L D e
I
l 1 1 2 rl s tl c tl s : ;
?

+'"1""1
;;;.
u
? uI

22 2t t. 2. 2. rr r.,

I

ro !r rr

B
A

a
4

rr ra r. .o .! .l

2
I

Figure4-13. Combined File Card After Punching

Card Output OPerations

4-9

T o d e s c r i b teh i s p r o g r a my, o u w i l l n e e df o u r t y p e so f
s p e c i f i c a t i o ns sh e e t s :F i l eD e s c r i p t i o nI n
, p u t ,C a l c u l a t i o n ,
a n d O u t p u t - F o r m a tO
. n t h e F i l e D e s c r i p t i osnh e e t y, o u
d e f i n et l - r ef i l e a sa c o m b i n e df i l e w i t h a l e t t e rC i n c o l u m n1 b .
F i l e D e s c r i p t i oenn t i r e sf o r a c o m b i n e df i l e a r et h e s a m ea s
t h o s ef o r a n i n p u t f i l e e x c e p ft o r c o l u m n1 5 . ( S e eF i g u r e
4 - 1 4 ,i r r s e rAt . ) C a r d sw i l l b e b o t h r e a da n d p u n c h e do n
M F C U l . W i t l rt h e e x c e p t i o no f t h e d e v i c en a m e ,s p e c i f i c a t i o n si n F i g u r e4 - 1 1a p p l yt o t h e M F C M .a sw e l l

O n t h e I n p u t s h e e t( F i g u r e4 - 1 4 , i n s e r tB ) y o u s h o u l dd e f i n e o n l y t h e f i e l d s w h i c h a r e t o b e r e a d . R e m e m b e rt h e
T O T A L f i e l d i s n o t i n t h e c a r d sw h e n t h e c a r d sa r e r e a d
a n d t h e r e f o r e ,i s n o t d e s c r i b e do n t h e I n p u t s h e e t . S i n c e
t h e T O T A L f i e l d i s t o b e c r e a t e dd u r i n g t h e j o b , i t i s d e f i n e d o n t h e C a l c u l a t i o ns h e e t( F i g u r e4 - 1 4 , i n s e r tC ) .
T h e O u t p u t - F o r m a t s h e e t ( F i g u r e4 - 1 4 , i n s e r t D ) d e s c r i b e s
only the information that is to be punchedinto the card.
H e r e a g a i ny o u d e s c r i b et h e T O T A L f i e l d .
N o t e : B e s u r e t h e c a r d c o l u m n s t o b e p u n c h e dc o n t a i n
b l a n k s ,t o p r e v e n t p r o b l e m sw i t h i n v a l i d p u n c h c o m b i n a t i o n s .

F i l e D e s c r i p t i o n S p e c i fi c a t i o n

L!.91h
ol

ol Kcy

Be.otu

F,.l(l

Addfe$

or
F.h

J.r Cy ,n0.r

014

iil

0 5
016

il.

il - t l
+ . l

RPG INPUTSPECIFICATIONS

ATf.

rD-r".I,D2:
,LD3-.
.L,D-'ll.

r,o5,
F i g u r e 4 - 1 4 ( P a r t 1 o f 2 ) . S p e c i f i c a t i o n sf o r R e a d i n ga n d P u n c h i n g E a c h C a r d
4-10

Ovr'iloP

R P G C A L C UL A T I O NS P E CFI I C A T I O N S
llBll

",",^","^" ",.ne$

Form GX2l S93
Pn.red^USA

M a c hn e c o . o o , ! , o n
z5

C a r d E L e c t r oN u m & r

**fL

OUTPUT
1181,L.,",.",,".",

76

77

GX21.W

SPECIFICATIONS

78

79

Pfqa. tT-TTt-I_]
roenr..,canonl |
|
|
|

80

|

l

U/M050.

-,.,n0sMd,.. corpo,6.on
15 76 11 78 79 80

End

Yes
v
*
N
o

J
r

Yes
I
N
o
Y
e
s

l
?
3

Figura 4-14 lPart 2 ol 21. Specifications f or Reading and punching Each Card

Prunching
into a BlankCardin the File
You havejust learnedhow to usea combinedfile when you
wish to readand punchthe samecard. What if you wishto
rerad
severalcardsand then punchanothercardin the same
file? Rememberany time you want to readand punchcards
from the smefile, that file must be definedasa combined
file.
Assumethat a companywhich keepsa weeklyrecordof
itemssold,usestheserecordsat the end of the month to
determinethe quantityof itemson hand. For eachitem,
fo,ur6111.r.n,typesof cardsareread(Figure4-15).

1.

O n h a n dw
. h i c h c o n t a i n st h e n u m b e ri n s t o c ka t t h e
b e g i n n i nogf t h e m o n t h .

2.

l s s u e sw, h i c hc o n t a i n st h e n u m b e rs o l dd u r i n gt h e
month. Thereis one of thesecardsfor eachweek.

3.

Receipts,
which containsthe numberaddedto stock
throughreorder.

4.

N e w O n h a n dw
, h i c h i s b l a n k . A f t e r c a l c u l a t i o nhsa v e
beenperformedto determinethe numberon hand,
this numberand the dateand a codeare punchedinto
the card. This card,when punched.will be usedas
n e x t m o n t h ' sO n h a n dc a r d ,a n d w i l l b e i n t h e s a m e
format asthe currentOnhandcard.

Card Output Operations

4-11

Eachof thesecardtypesis identifiedby a code in column
96 (seeFigure4-15). (Thiscodewould be column B0 if
the MFCM wereused.)

r

I

r

I

$

ra !! I

r

rarrratr202tp2t2.2,

It n

ar .r .3 {

!r.o

a! {.7

rJ r. fi

B

t

!

i

o0

,. 1a -

udsbrsbtu16no

; , , , . . . ,| .
l

!2 3J !a r! $

0 a2 a! aa a5 x

l

l
I INSTOK
l

r

t

l
I

t.

I

rarrttrr$lr

n

ar aa at ro rr 12 rr ra r! x

r

2

37

fi u n3 r! rs

r

r
l
a
l
4 ITEMNO I DATE
2
l

ra a, lo'

|

r

at aa at aa ar?o

r

B

A
a
.
z

l

l

a

r

a! a aT.a al $

ran

m 0 nr 6 u

L

rt 6

ar {

!t !t

tt u

at aa ara

D

I

l
l
t

nr il

l
l

t

rr s

r

il

l

tr ra I

ro I

!r !

ar aaD

rrEMNo loare I necer |
lt
t
r

....-",4

l

!r .o rr ., at {

&

I

rI

6

at o

!r

at s

t, tt t. t

r! tr f!

s

6

t

raa rt It

t
r

B
a

:

t

l

,

,

rr rr t. It i

Ir la il $1

It

E
a

I
Br!ss!a!rnrr&.r

. _7 o_ . 5 s r 9 ! ! g 5 ! $ r $ $ 6 . r d G a .

1

6 B

; :

4

uJa
O a
O z
O r

O a

,
I

2
I

o z
...r...roir.7t7.Brn7.n

6...r..tF'r.""r.rP.

t

37@

Onhand Card

l

t .

I

ReceiotCard

!

r a r T r a r r 2 o

t ! ! ! t r a ! 7 x ! a . o . r . 2

t! a.!3 xrr

a l a a a r a a a r r o

,

a

i

ebr

$ r ! a a ! . a ! x r r a . a r s r r 1 2 ! a r . $ x

x

ab!so!trpt16r€no

l
t

,

l

t

l

u.a

$re.t.:.t

a

r

ndg60Drilroft

@a

n

arr

fi n

n

raar s

-

i

!r lr

at o

!

argaar

6 n nt il n! r

nt n

to

xttnt

il mrD rrr![a

aro

tatt g

atg

6t

6ria6

B

B

l

A

r r E M N o l o n r e l , s s u |e s
ll
t
t
l
l

:

,
,

x t t i l t s n l ;

a
4

a
4
l

6
4
r

2

t .

a

r ! r a r r r a E

1
B

a i l r t 2 . t ! i t r l a t r s l ! r

a
4

4

'|

1

B

B
I
4
2
1

I ssues Card

Figure4-15. Four CardType

a
4
1

New Onhand Card

llJ

o
o
o

a
4
2
1

Again,you will needfour typesof specificationsheetsto
w r i t e y o u r p r o g r a m :F i l e D e s c r i p t i o nI n
. p u t ,C a l c u l a t i o n ,
and Output-Format.On the File Descriptionsheet,you
m u s te n t e rt h e f i l e n a m ef.i l e t y p e ,a n d d e v i c e( s e eF i g u r e
4 - ' l6 . i n s e r tA ) . S i n c et h i sf i l e i s b o t h r e a da n d p u n c h e d ,
the f ile type must be C to denotea combinedfile.
Orrthe Input sheet.you must describeall four cardtypes
anrC
assignrecordidentifyingindicators.Theseindicators
wiillbe usedlaterto conditionthoseoperationswhich are
to occuronly when a specificcardtype hasbeenread.

Thesecardsmust be readin a certainorder. The onhand
c a r dm u s tc o m ef i r s t ,t h e n e wo n h a n d( b l a n k )c a r dm u s t
c o m el a s t , T h e i s s u eas n d r e c e i p t cs a r d sm a y b e i n e i t h e r
order,but must alwaysbe in the sameorder for any prog r a m . F o r t h i s p r o g r a ma, s s u m teh a t r e c e i p t cs a r d sf o l l o w
issues.Rememberto indicatethat cardsareto be in a cert a i n s e q u e n cbey u s i n gn u m e r i cs e q u e n ceen t r i e sf o r a l l c a r d
types. Theseentrieswill directthe programto checkfor
s e q u e n c eF. i g u r e4 - 1 6 ,i n s e r tB , s h o w si n p u t s p e c i f i c a t i o n s
for this program.
O n t h e C a l c u l a t i osnh e e t y, o u d e fi n et h e c a l c u l a t i o n s
( F i g u r e4 - 1 6 ,i n s e r tC ) w h i c hm u s tb e p e r f o r m e dt o d e t e r m i n ea m o u n to n h a n d . T h e r e c o r di d e n t i f y i n gi n d i c a t o r s
assigned
on the Input sheetare usedto conditioncalculat i o n s . F o r e x a m p l eo. n l y w h e na n i s s u ecsa r di s r e a d( 0 2 i s
o n ) w i l l n u m b e rs o l d ( I S S U E Sb) e s u b t r a c t efdr o m I N S T O K .

F i l e D e s c r i p t i o n S p e c i fi c a t i o n

Lengrh

oi Key

oi 8€cord

F eld or

Add.ess

Field

SrarIng

,u
lBl't ",".,.

F*
E@a";

F o r t h e M F C M , c h a n g e9 6 t o
8 0 i n t h e s ep o s i t i o n sa n d
c h a n g et h e d e v i c en a m e .

fi

i i

RPG INPUTSPECIFICATIONS

@

l+

f
T

F i g u r e 4 - 1 6 { P a r t 1 o f 2 ) . S p e c i f i c a t i o n sf o r R e a d i n ga n d P u n c h i n g C o m b i n e d F i l e C a r d s

Card Output Operations

4-13

RPG

CALCULATION SPECIFICATIONS

l-f

T;;,r*l

tT l'ffi]

I-'':-l-"*lI:Ill-l

Fdctor 1

)t i)

I

Ooeralon

) 1 ) 4 2 t 2 b 2 7 1 2 A2 9 t 0 l t

32

OUTPUT
IBril

.,..,," .""

**ffir

I

SPECIFICATIONS

".,.?$M.chnec.rn.,a,.i
75 76 77 78 79 80

"*ffi "_',jffIil",."fl-fffn

o

Skrp

a

F ilename

Output I ndicatofs
Freld Name

i
c

d

E

:

1 Y e ,I
!a
I
\
|
I
[__\"

I
i

lo
a

:t;l
0

3

l

;l;Tl o

I

F

I

r'
No

:
I
I
I

1
z
,
a

a l r l Y : u a r e
F'erdto',
e |
|
ze'o
c l- lz
p_lll
s.eere$

Constant or Edit Word

z

)

l0 11 r? 1311!

)lvfr
I

I

I

-tIr

l

il+

_LtI

-t1
I

1 l

F o r t h e M F C M ,c h a n g e9 6 t o 8 0 .

F i g u r e 4 - 1 6l P a r t 2 o t 2 ) . S p e c i f i c a t i o n s f o r R e a d i n g a n d p u n c h i n g c o m b i n e d F i l e c a r d s

O n t h e O u t p u t - F o r m asth e e t( F i g u r e4 - 1 6 ,i n s e r tD ) y o u
m u s ts h o wt h e f i e l d sw h i c ha r et o b e p u n c h e d .S i n c eo n l y
t h e b l a n kc a r di s p u n c h e dp, u n c h i n go c c u r so n l y w h e n0 4
is on, Because
the cardpunchedwill be usedas next month's
O n h a n dc a r d ,I T E M N O ,D A T E , I N S T O C Ka n da c o d em u s t
be punched.

WhenTo Specifya CombinedFile
How do you know whetherto describea cardf ile that must
be readinto the computerasan input or asa combinedfile?
l f y o u r e m e m b etrh e s eb a s i cr u l e sy o u w i l l h a v en o t r o u b l e
decidino.
1.

ff the file containscardsthat areto beboth readand
punched,it must be a combinedf ile.

2,

lf cardsin the f ile areto be stackerselectedon some
basisother than cardtype, the file must be described
asa combinedfile (seeStackerSelection,Selectingon
a BasisOther Than Card Typel .

4-'t4

S T A C K E RS E L E C T I O N
Stackerselectionis the meansby which you can separate
certaincardsfrom all othersin the file. lf stackerselection
entriesare not made,all cardsautomaticallyfall into specific, predefinedstackers:
M F C U l : S t a c k e 1r
M F C U 2 : S t a c k e 4r
M F C M l : S t a c k e r1
MFCM2: Stacker4 (ModelA2) or Stacker5 (Model
A1)
y'y'ofe.'
appliesto
Unlessstatedotherwise,this discussion
b o t h t h e M F C Ua n d t h e M F C M .

Input and CombinedFile Cards

Selecting on a Basis Other Than Card Type

I n p u t f i l e c a r d sa r e s t a c k e rs e l e c t e db y i n p u t s p e c i f i c a t i o n s .
C , o m b i n e df i l e c a r d sc a n b e s t a c k e rs e l e c t e db y e i t h e r i n p u t
o r o u t p u t s p e c i fi c a t i o n s .

S u p p o s ey o u w i s h t o s t a c k e rs e l e c ti n p u t f i l e c a r d so n s o m e
b a s i so t h e r t h a n c a r d t y p e . s u c h a s t h e r e s u l to f c a l c u l a t i o n s ,

Selecting on the Basis of Card Type
S t a c k e rs e l e c t i o nb y i n p u t s p e c i f i c a t i o n sm u s t b e o n t h e
b a s i so f c a r d t y p e . T h i s m e a n sV o u m a y s e p a r a t ea l l c a r d s
o l ' o n e t y p e f r o m t h e i n p u t f i l e b y s p e c i f y i n ga s p e c i a l
s t , a c k eirn t o w h i c h t h e y s h o u l d b e s t a c k e d .
S u p p o s ey o u w a n t t o c r e a t ea m o n t h l y l i s t o f a l l i t e m s i n a
r e t a i ls t o r e " T h r e e c a r d t y p e s a r e u s e d : o n e f o r n e w i t e m s ,
o n e f o r d i s c o n t i n u e di t e m s , a n d o n e f o r a l l o t h e r i t e m s .
T h e m a n a g e rw a n t s t o t a k e a l l c a r d sd e s c r i b i n gd i s c o n t i n u e c J
i t e m s o u t o f h i s f i l e . H e c a n d o t h i s b y s p e c i f y i n gt h e s t a c k e r
i n t o w h i c h t h e c a r d t y p e i s t o b e s e l e c t e d .T h e s p e c i f i c a t i o n
i n F i g u r e4 - 1 7 , i n s e r tA , l i n e 0 2 , w i l l s e p a r a t et h e d i s c o n t i n .
u e d i t e m c a r d s ( c a r d i d e n t i fi e d w i t h a D i n t h e l a s t c o l u m n )
from the other cards by pLtttingthem in stacker 2.
N o t i c e t h a t t h e O R r e l a t i o n s h i pw a s u s e d i n d e s c r i b i n gt h e
three card types. When stacker selection is done with the
O l l r e l a t i o n s h i po n e r u l e m u s t b e k e p t i n m i n d : e a c hc a r d
t y p e w i l l f a l l i n t o t h e s t a c k e ri n d i c a t e df o r i t . F o r e x a m p l e ,
F i g u r e4 - 1 7 , i n s e r tA . s h o w st h e s t a c k e rs e l e c t i o ne n t r y 2
for the second card type. The other card types have no
stacker selectonentry. 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
t o F i g u r e 4 - 17 , i n s e r t B , c a r d t y p e 0 2 f a l l s i n t o s t a c k e r2 ,
c a r d t y p e 0 3 f a l l s i n t o s t a c k e r3 . W h e r ed o e s c a r d t v p e 0 1
f a l l ? l t w i l l f a l l i n t o e i t h e r s t a c k e r1 , 4 , o r S c l e p e n d i n g
u p o n t h e d e v i c eu s e da n d t h e h o p p e r i n w h i c h t h e f i l e w a s
entered.

t h e r e s u l t so f m a t c h i n g r e c o r d s .o r t h e c o n t e n t so f a n i n p u t
f i e l d . F o r e x a m p l e ,a s s u m et h a t t h e c a r d sw h i c h c o n t a i n
i n f o r m a t i o n c o n c e r n i n gn e w , d i s c o n t i n u e d ,a n d a v a i l a b l e
i t e m s i n t h e s t o r e a l s oc o n t a i n t h e a m o u n t o n h a n d a t t h e
e n d o f t h e m o n t h . I n a d d i t i o n t o l i s t i n ga l l i t e n r s ,r e c o r o s
of items which need to be reordered are selectedto a
s e p a r a t es t a c k e r . T h e c r i t i c a l r e o r d e rp o i n t o c c u r sw h e n
t h e r e a r e 2 5 i t e m s o r l e s sl e f t o n h a n d . ( T h i s , o f c o u r s e ,
d o e s n o t a p p l y t o d i s c o n t i n u e di t e m s . )T h u s , i n t h e c a l c u l a t i o n s ,O N H A N D i s a l w a y s c o m p a r e dt o 2 5 . l f t h e
a m o u n t i s e q u a l o r l e s st h a n 2 5 , t h e i t e r n n e e d sr o D e r e o r d e r e d . A l l c a r d sd e s c r i b i n gi t e m s t o b e r e o r d e r e oa r e t o
b e s e p a r a t e df r o m t h e o t h e r s i n t h e f i l e b y s t a c k i n gt h e m
i n a s p e c i a ls t a c k e r .
W h e r ew o u l d y o u s p e c i f y t h e s t a c k e rs e l e c te n t r v t h a t
w o u l d d o t h i s ? T h e r e a r e o n l y t w o p o s s i b i l i t i e s- - I n p u t
s h e e to r O u t p u t - F o r m a t s h e e t . R e m e m b e rt h a t i r r p u t c a r d s
can be stacker selectedon the I nput sheet on the basisof
c a r d t y p e o n l y . I n o u r e x a m p l e ,n o t a l l c a r d so f a n y o n e
t y p e w i l l d e s c r i b ei t e m s t h a t n e e d t o b e r e o r d e r e d . T h e r e f o r e , t h e s e l e c t i o ni s n o t o n t h e b a s i so f c a r d t y p e a n d c a n n o t b e s p e c i f i e df o r a n i n p u t c a r d o n t h e I n p u t s h e e t . T h i s
l e a v e so n l y t h e O u t p u t - F o r m a t s h e e to n w h i c h t o s p e c i f v
t h i s s t a c k e rs e l e c t i o n . B u t s i n c eo u r f i l e i s n o t a n o u r o u r
f i l e , h o w c o u l d i t b e s p e c i f i e do n t h e O u t p u t - F o r m a t s h e e t ?
R e m e m b e rt h a t a c o m b i n e d f i l e s e r v e sf o r b o t h i n p u t a n d
o u t p u t . T h e r e f o r e ,a f i l e f r o m w h i c h c a r d sa r e t o b e
stacker selected must be defined as a combined file.

Card Output Operations

4-15

RPG

INPUT SPECIFICATIOI\S

F ietd
i ndrcators

tsilef;me

l
I

3
e

I F
l t A

,ri
. l , r , , n ' , " , .

F o r t h e M F C M ,c h a n g eg Ot o 8 0 .
RPG

INPUTSPECIFICATIONS

;*l^.f
P ' j

s

^

tstontatstul
P,uq'am l ll-f-!-T-l
l
-,d.,,".r',,j L L | | i i_Ji

'llirt
Figure 4-17. Stacker Selecting Cards in an OR Relationship

4-16

i

Figure 4.-18shows tlre ent;ies whicir are ne{:ess.rry
to stacker
s e l e c ta i l i ; a r c l s( e x c e p td i , c o n t i n u e d ) c a r d s )w h i c h c o n t a i n
2 5 o r l e s si n t h e O N H A N D f i e l d . T h e f i l e w o u l d b e d e s c r i b e da s a c o m b i n e d f i l e b y p l a c i n ge C i n c o l u m n 1 b o l
t h e F i l e D e s c r i p t i o ns h e e t .
F i g u r e4 - 1 8 , i n s e r tA , s h o w s' r . h i rrth e O N H A N D f i e l r j i s
compared with 25, ll the cornpare is equal or less,inC i c a t o r l 0 t u r n s o n t o i n d i c a t et h a t t h e i t e n r s h o u l d b e
ord+:rEd.Indicator 'l 0 is ihen used on the Output-[:.rrmat
s h s e t t o c t n d i t i o n t h e s t a c k e rs e l e c t l o ne n t r y ( F i g u r c 4 - . 1g ,
i n s e r t B , ! i n e 0 1 l . W h * i i 1 0 i s o n { t h e r ea r e Z E o r i e s sr : i
the ittiri.r!eftl arrd tfrc card is not a discontinucil itern {int l i c a t o r 0 l l i s n o r c r ' ) . t h e c a r r l i s s e l e c i e di n t o s t a c k e t2 .
A l l o t h e r c a r d sg o i n t o s t a t k e r 1 .

card tVpes by irrput specifications anci otlrers by outputfc.rrmatspecificatiorrs. However, one card type should not
have both types of stacker selection sfrecificarierns.lf it
does, the input entry is ignorer.i. [-urthermore. if you are
p r - , r r c h i nogr p r i n l i r r go n c o m b i n e d f i l e c a r d st h a t a r e a i s o
to be stacker selected.the stackL-rselectionentrv i"nustbe
on the OLrtput-Forrnatstteut.

Stacker Selecting Output File Cards
Liuttrir;ttile cartis e re stacker seIectedby {.]1.!tput
specificat i o n s . F o r e x a n r p l e ,s t a c k e rs e l e c t i o nb y o u t p u t s p e c i f i c a rions can [rr:made on the ba$ii of resu!tsof calculatiorrs,
matching recorrJs,c{}ntent of f ields, ancl error conditions.
Output stacker selection can be basedon card type, but
carri type selection is usually done with irr;rut specifications.

Rutes far Stacker Selecting Cardr from a Combined Fite
Combirred file cards can be stacker selectedb!' bottr inLrr"rt
a n d o u t p u t - f o r m a t s p e c i f i c a t i o n sI.n p u t s t a c k e rs e l e c t i o n
is basecjon card type aione; outilut stacker seleition can
be on any other basis. In fact, you can stacker select sorne

C o r i s i d e ra n e n d - o f - t h e - m o n t hi n v e n t o r y p r o g r a mt h a t : ( 1 )
lintls the balarrceon harrd for cach item, {2) determines if
:rnd when an itern should be reordered;and (3) f intls any
iterns that are overstocked.

cALcLlLATloN
SPEclFlcATloNs
lE rr ":ll::::':y::r'lj
:rr11ri

;:.

:+.

' -- l-;*;ra
"'*l
L**+I.i r,ili:]
_i
-f
_,_.

j, i
-C_
- t l : r____=,J_]

:::;::'J:";:'
I

,.,"Lii'lflil",."ffirt|

.r,^;_
lT_n:Lrl
--tt]{',ffi

_-l

I

|
| |
n"
'","
c.nncn,.
r,r,;ri |
l.',,"i ,,ll
l i ' ; i ; i ; ; i _lffintf
; ,ii i
i"'ii:i'H#
il
,:fc'-f-*f"1+*iirffir
- :'-"]' _ f=l;jTftp[diTff;fl
|
I

8 ) i 'i l I
ISM

i,i

. , , . . ,n r! ! ! n . n ' a .nh. l ' . , , n , a , o

-

:

;t;;;-r , -l,p""l
_T:-

[[o_'

I

|

RPG

OUTPUr

|

r

SPECTFiCAT|ON$

-1";r;
f-.-*'l-Tr-;;";::
i i+l_J,j"'']""]

.:T;;"; [-

ri I r r;,j; i ., ,Ji
;::rtr",.";"',I

**LJ'l'n:il,,..iaffi-fll

.1,l_]--;;-.1--lI

, '^:1.ir:i I
,,
II Ii
titr[J-l-L]-l:___]-[rl
,.
l.l
llij
li
: J Jn ,5, d. , u
I ili
# , H . 1 , [] - [ l ;
l[l I [l
i li
F i g u r e 4 . 1 8 . S t a c k e r S € l e c t i o no n t h e B a s i so f C a l c u l a t i o n s

C a r d O r , r t p u tO p e r a t i o n s

4-17

T w o f i l e s a r e u s e d :a n i n p u t f i l e a n d a n o u t o u t f i l e . T h e
i n p u t f i l e c o n t a i n st h r e e t y p e s o f c a r d s( F i q u r e4 - 1 9 ) :
1

2.

l n v e n t o r y B a l a n c ec a r d s ,w h i c h c o n t a i n t h e n u m o e r
i n s t o c k a t t k r eb e g i n n i r r go f t h e m o n t h , a n d t h e m a x i m u n r a n d m i n i m u m q u a n t i t i e sw h i c h s h o u l d b e r e o t
in str:ck"
l s s u r s: u m r n a r yc a r d s ,w h i c h c o n t a i n t h e t o t a l n u r n b e r
i s s u i l dd u r i n g e a t ; hw e e k . S i n c et h i s i s a n e n d o f t h e
rnonth job, thL'remay be severalof these.

;

|
|
ll
t.r*o
,rrro* | MAX
lootr |
i
I
li
t

"

?

A

;:

:

rrrir
rvtrrt

4

Each itenr ,'nusthave a balancecard. The other t\,vocards
i t r e o p t i o n a l . T h e o u t p u t f i l e c o n t a i n sb l a n k c a r d s .

;

.,

B
A
d
4
2

"

..

"

I
I
I
t

, , . , " . , . o. , 't . :

"

o

"

I n v e n t o r y E a l a n c eC a r d

t h e s a m ea r ;t h e i n p u t b a l a n c ec a r d , s r n c et h i s o u t p u t c a r d
i s u s e da s t h e b a l a n c ec a r d f o r n e x t r n o n t h ' s i n v e r r t o r v .
l J e f o r et h e b a l a n c eo n h a n d i s p u n c h e d i n t o t h e b l a n k c a r d s .
t h e a m o u n t i s c o m p a r e dt o t h e m a x i m u m a n d m i n i m u m
q u a n t i t i e si n s t o c k e s t a b l i s h e df o r e a c h i t e m t o d e t e r m i n e
r e o r d e r p r c , c e d u r e .A s a r e s u l t o f t h e c o m p a r i s o n ,f o u r c o n ditionscould occur:

:2.

lf thea
r m o u n ti s g r e a t e trh a nz e r ob u t e q u a lt o o r
bel z
i <

,;

I
F i g u r e 5 - 1 4 , C o n d i t i o n i n g a C a l c u l a t i o nb y a n O v e r f l o w I n d i c a t o ;

Using the Besultsof Arithmetic Operations
Considerhow the resultof a calculationcan be usedto det e r m i n et h e n e e df o r f u r t h e rc a l c u l a t i o ni sn a b i l l i n gp r o gram. For eachaccount,it is necessary
to f irst determine
the amountowed by addingchargesand payments(paymentsare recordedas negativenumbers)to the balancedue
at the beginningof the month. For any customerowing
m o n e ya t t h e e n d o f t h e m o n t h ,a s e r v i c e
c h a r g eo f 1 - 1 l 2
percentis addedto the amountdue. lf he hascreditcoming,
he must be senta credit memoinsteadof a bill. Thusa test
m u s tb e m a d eo n t h e a m o u n td u e f i e l d t o d e t e r m i n ei f i t i s
p l u so r m i n u s . l f i t i s p l u s ,t h e c u s t o m eor w e sm o n e ya n d
the servicechargemust be figuredbeforethe bill is printed.
l f i t i s m i n u s ,h e h a sa c r e d i ta n d m u s tb e s e n ta c r e d i tm e m o .
The cardfor the customerwith a minusbalanceis stacked
into a specialhopper. lt is laterusedin a credit memorun.

H o w c a n y o u c a u s ea t e s t t o b e m a d e o n t h e d a t a ? R e m e m b e r i n F i g u r e 5 - 1 h o w y o u t e s t e df o r a m i n u s q u a n t i t y . B y
e n t e r i n ga n i n d i c a t o r { 0 1 - 9 9 , H 1 - H g ) i n c o l u m n s 5 4 - 5 9 , y o u
c a n t e s t f o r p l u s , m i n u s , o r z e r o d e p e n d i n gu p o n w h e r e y o u
olace the indicator.
F o r t h i s p r o g r a m ,i n d i c a t o r 9 9 i s p l a c e di n c o l u m n s 5 4 - 5 5
t o t e s t f o r a p l u s c o n d i t i o n ( s e eF i g u r e 5 - 1 5 ) . W h e n a c o n t r o l
break occurs (all transactionsfor one account are processed)
and when 99 is on, the 1-112 percent servicecharge is found
a n d a d d e dt o a m o u n t d u e ( A M T D U E ) t o f i n d t o t a l a m o u n t
due.
l f i n d i c a t o r9 9 i s o f f ( n o a m o u n t d u e ) w h e n t h e c o n t r o l
break occurs, these last two operations are not performed'

I ICATIONS
C A L C U L A T I O N S P E CF

a

F i g u r e 5 - 1 5 . C o n d i t i o n i n g C a l c u l a t i o n sb y a n I n d i c a t o r S e t a s a R e s u l t o f a n A r i t h m e t i c O p e r a t i o n

C o n t r o l l i n gO p e r a t i o n sI n A n R P G l l P r o g r a m

5-13

T h e r e s u l t o f a n y a r i t h m e t i co p e r a t i o n ( A D D ,
SUB, MULT,
D l V , Z - A D D , ; Z - S U BM
, V R ) c a n b e t e s t e db y s p e c i f y i n g
re_
s u l t i n g i n d i c a t o r si n c o l u m n s 5 4 " 5 9 . T h e r e s u l t i n g
indica_
t o r s w h i c h a r e s e t a s a r e s u l to f t h e t e s t c a n c o n d i t i o n
those
operations whir:h are to be performed on the
basisof the result of that t€]st.

Using the Results of Compare Operations
I n a c o m p a r eo l c e r a t i o n( C O M p ) , f i e l d s o r l i t e r a l s
of the
s a m et y p e ( a l p f r a m e r i co r n u m e r i c ) a r e c o m p a r e d
to each
, f t h e r t o d e t e r n r i n et h e i r r e l a t i o n s h i p
t o e a c ho t h e r . I n d i c a _
tors entered in ,cslgrn6, 54_59are used to indicate
whether
t h e f i e l d o r l i t e r a l i n F a c t o r . l i s h i g h e rt h a n , l o w e r
tnan, or
r : q u a lt o r h e f i e l d o r l i t e r a l i n F a c t o r 2 .
-[he

r e s u l t so f a c o m p a r ec a n a l s o c o n t r o l w h i c h c a l c u l a t i o n s
s ; h o u l db e d o n e n e x t . F o r e x a m p { e ,w h e n d o i n g
an inventory
a n d r e o r d e ra p p l i c a t i o n ,t h e c o m p a r eo p e r a t i o n ( C O M p )
i s u s e dt o d e t e r r n i n ei f a n y i t e m n e e d st o b e r e o r d e r e d .
ln
t h e e x a m p l es h o w n i n F i g u r e5 _ 1 6 ,t h e f i e l d c a l l e d
MIN
( m i n i m u n r ) c o n t a i n st h e c r i t i c a l r e o r d e r p o i n t .
The field
O N H A N D i s c o r n p a r e dt o M l N . l f t h e a m o u n t o n h a n d
is
l e s st h a n o r e q u a l t o M l N , i n d i c a l . o r9 9 i s o n . T h e
reorder
c l u a n t i t yi s c a l c u l a t e db y s u b t r a c t i n ga m o u n t o n h a n d
from
t h e n u m b e r i n t l r e f i e l d c a l l e dM A X w h i c h c o n t a i n s
the
n n a x i m u mn u m L r e rw h i c h s h o u l d b e i n s t o c k . l f
amount on
l ^ a n di s g r e a t e rt h a n M l N . n o r e o r d e r i n gn e e d b e
done and
this calculation s not done.

Using the Resultsof the TestZone (TESTZ) Operation
Anotheroperationcode,TESTZ,is availableto test ctata
d u r i n gc a l c u l a t i o nsso t h a t y o u c a nd e t e r m i n e
w h i c hc a l _
culationto do next. TESTZ testsonly thezoneportion of
the leftmost character of an alphameric field. TESTZ does
n o t t e s ts p e c i f i c a l lfyo r p l u s ,m i n u s o
, r z e r o ;h i g h .l o w , o r
e q u a l . R a t h e r i,t t e l l sy o u i n t o w h i c hg r o u po f z o n e st h e
z o n et e s t e df a l l s :
a T h e z o n e so f t h e c h a r a c t e&r ( a m p e r s a n d ) ,
A _ lc a u s e
t h e P l u si n d i c a t o e
r n t e r e di n c o l u m n s5 4 _ b bt o b e t u r n e d
on.
o T h e z o n e so f t h e c h a r a c t e r s ( b r a c k e t )_, ( m i n u s ) ,
and
)
J - R c a u s et h e M i n u si n d i c a t o er n t e r e di n c o l u m n s5 6 _ 5 7
t o b e t u r n e do n .
o T h e z o n e so f a l l o t h e rc h a r a c t e rcsa u s et h e i n d i c a t o r
enteredin columnsS8-S9to be turnedon.
The test zoneoperationcould provevery usefulin a large
b i l l i n ga p p l i c a t i o nC
. o n s i d etrh e c a s eo f a c o m p a n yw h i c h
n a ss o m a n ya c c o u n t tsh a t b i l l i n gm u s tb e d i v i d e d .C u s t o m e r s
whoselastnamesare in the first part of the alphabetare
b i l l e do n t h e 1 s t h o f t h e m o n t h ;a l l o t h e r sa r eb i l l e da t t h e
l a s to f t h e m o n t h . T h e m a s t e fri l e u s e di n b i l l i n gi s o r g a n i z e d
in ascending
orderaccordingto accountnumber.
The recordsin this file could be sortedby nameso that you
c o u l dd i v i d et h e f i l e f o r b i l l i n g . H o w e v e rt,h i sf i l e i s u s e d
so often for other purposes
that it is a wasteof time to
repeatedlysort it accordingto nameand then sort it again
accordingto accountnumber.

RPG CALCULATION
SPECIFICATIONS

P"rl

R6ult

Field

E
E

':
0
l

o1

I

;l

l

f

'.
i3
*+

t !

Figure5-16' conditioning calculation$
by an lndicator set as a Resultof a compare operation

5-14

r-r
I

lot

!r betterway to do the billingis to test the namefield in
eachrecordto seein which part of the alphabetthe namefalls.
Eluringthe first of the month, if the lastnamebeginswith
lettersA-1,you wish to find amountdue. TESTZ will test
tlhefirst letter in the field and tell you in what part of the
alphabetit is. Figure5-17 showsthe calculationspecificawhoselastnamesfill into
to bill customers
tions necessary
categoryA-1.

Naturallyat the end of the month you will want to bill the
restof the customers.But you don't want to write another
programfor end of the month billing. So you write one
programto do both jobs and useexternalindicatorsto condition the specificationsfor eachjob (seeFigure5'18).

FqFGx2ldB

RPG CALCULATIONSPECIFICATIONS

P.inrd

dd !!!i.-r6ituco@nso

lBIt,""'-

ftq,.m l-l-TTl-Tl
ld.ntific.tionl
|
|
|
|

Ord El.cvo NumEr

Gr.Dhic

I orb

c

ih U,l.A.

757A71187e80
|

|

R6ulr Fi€ld

lndicaton

3

t ,i i

1.. l;
t t

5 E

. . . t :! = ,
t

l

Fdor

Opaotion

1

Plur lMinull z.ro

Factor 2

I

Length

Name
-l

Commant,

l r

- l

"l:t, :l

Hich

I

Low

lEqul

Figure 5-17. Conditioning a Calculation by an Indicator Sat .s a R6ult of tha TESTZ Operation

tun OX2l.F
td.rd l. Ul.a,

RPG CALCULATIONSPECIFICATIONS
IDll'".-.,-r.nffi

rdhco@ddq.d

Gr$hic

El.cto

*,ll'_

Numbr

I O.r

c

ix

!l
6 6

Facto. I

I

r l I l r lI r t I

clrrlrr

T'FIT;
ffi
lmld

Opar.tion

-

F*tor 2
Namo

e h o L rh r h l r r

Rduhiry

Esult Fi6ld

lndicrtorr

Comhantt

L0ngn
)okuo(F.do
Hilh

r l 4 a r a

1 6 7 A 1 1 1 6 7 e n

[:l;;""1]-[l_TTl

I

Low

2li

lEcu.

. r i r i l 6 6 a a 7 d c

t7 1t ,'

ltO

Fi5lrc 5-18. Uring TESTZ and Extcrnel Indicttort

C o n t r o l l i n g O p e r a t i o n sl n A n R P G l l P r o g r a m

5-15

Yuu can useTtjSTZ to test for any specialcodeyou
serup
by usingthe zoneof a character.This is most often done
'whenyou have
no spaceon your recordsfor any other kind
,ofidentifyingirrformation.For example,
when establishing
ir code for the F,ercentage
of commissionreceivedby each
salesman,
you could usethe & to indicate6 percent
and
ltheminus(-) signto indicate15 percent.you would,
of
course,haveto punchthis code in the leftmostposition
of
a numericfield because
this is the positiontestedby the

TESTZ operation. Figure5-19 showshow the code is
placedin the field containingsalesman
number. However,
you must definethe field as alphamericsincethe
TESTZ
operationcan only be performedon an alphamericfield.
Figure$20 showsthe TESTZ usedon the SALSNO(salesman number)field, which containsthe commissioncode,
in orderto f ind rate of commission.The resultsof the test
determines
what other calculations
will be done.

SALESMAN.
Whosenumberis 17657779
Who earns15%commission
Has17657778punched
in SALSNOfietd
a 5 e a 7 . s a 9

p?03ro.036o?uror

^

B

8
4
a a a o a a
2
a a
a a a
r a a
a a a a

a

a
a
4
2
1

2 5 [ , , I m r c n ' :

a
^
2
a 1 3!
$3.3'r.!'s.'

^
a
4
2
..

B

*_

"*".

l

B
4
z
1
!5 !a.7 !. !rro
37@

", "r

r"

a
8
4
2
1
". ""."

Figure 5-19. Punching a Code

CALCULATTONSPECI
FICATIONS

Form cx21.S93
Prin€d,n

---_l
Pror.mmer

joate

I

Punchins
In(rucno.

Figure 5-2O. Tosting a Fiold to Determine a Code

5-16

Grd El€cro NumEr

,"*lii",

P,q,an

_

75

76

17

fT-t-T-I-T-l

tdenrtricationl

|

|

U.S.A

78

|

7g

|

80

|

I

C C } N T R O L L I N GO P E R A T I O N SO N T H E B A S I S O F T H E
N E : X TR E C O R D l N A F I L E
S o r m e t i m e sc,a l c u l a t i o n st o b e p e r f o r m e d m a y d e p e r r du p o n
i n f o r m a t i o n i n t h e n e x t r e c o r do r o n t h e t y p e o f t h e n e x t
record to be processed. For example, in a certain kind of
p r o g r a m .y o u m i g h t w a n t t o b y p a s sc a l c u l a t i o n sf o r t h e c u r rent recordif you knowthe next recordin the file is identical.
The RPG f l languagehas a specialfeature calledlook ahead,
w h i c h e x t e r r d st h e b a s i c R P G l l l o g i c . l t w i l l a l l o w t h e c o m p u t e r t o l o o k a t i n f o r r n a t i o ni n t h e n e x t r e c o r d t o b e
p r o c e s s e dw h i l e i t i s p r o c e s s i n gt h e c u r r e n t r e c o r d . T h i s
m e a n st h a t i n f o r m a t i o n i n r e c o r d B c a n b e u s e dw h i l e r e c o r d
A i s b e i n g p r o c e s s e d .B y u s i n gt h i s f e a t u r e ,y o u c a n
write a program that usesinformation from the next record
a v a i l a b l ef o r p r o c e s s i n g .

ProcessingCard or Disk Files

l

MFCU Files; (Refer to the representationof the M FCU
c a r d p a t h i n F i g u r e 5 - 2 1 d u r i n g t h i s d i s c u s s i o n .A) s C a r d
A i s r e a d ,d a t a r e c o r d e do n i t i s t r a n s f e r r e dt o t h e i n p u t
a r e a . T h e c a r d t h e n m o v e so n t o t h e w a i t s t a t i o n . A c c o r d i n g t o t h e R P G l l p r o g r a mc y c l e , i n f o r m a t i o n i s t r a n s f e r r e d
from the input area to the processingarea right before det a i l t i m e . A t d e t a i l t i m e , t h e n , c a l c u l a t i o n sc a n b e d o n e o n
d a t a f r o m t h e c a r d p a t h w h i c h i s i n t h e w a i t s t a t i o n ( C a r dA ) .
, n o t h e rc a r d ( C a r d
H o w e v e r ,w h e n l o o k a h e a di s s p e c i f i e d a
a
r e p e r f o r m e di n
t
i
m
e
o
p
e
r
a
t
i
o
n
s
B ) i s r e a d b e f o r ed e t a i l
a
n
d
informationfrom
s
t
a
c
k
e
d
the currentcycle. Card A is
p
r
o
c
e
s
s
i
n
g
T
hen information
a
r
e
a
.
C a r d A i s m o v e dt o t h e
t
o
t
h
e
i
n
p u t a r e aa n d i s
on Card B iust read istransferred
p
r
o
c
e
s
s
i
n
g
A
,
n
ow in the
C
a
r
d
a v a i l a b l ef o r u s e w h i l e
stacker.

L o o k a h e a dc a n b e u s e dw i t h c a r d , t a p e , o r d i s k i n p u t f i l e s .
T h i s s e c t i o nd i s c u s s e lso o k a h e a dw i t h c a r d ( M F C U ) a n d
d i s k f i l e s . F o r M F C M , t a p e , a n d o t h e r f i l e s ,t h e c o n c e p t
is s;imilar.

.a>
L---\
€>
P r in t
Station

Punch
Station
Secondary
Hopper

Primary
Wait Station

Primary
Hopper

C a r d A i s s t a c k e da n d d a t a f r o m c a r d A
i s m o v e d t o t h e p r o c e s s i n ga r e a .

Before card A is processed,data from
card B is read into the input area,
w h e r e i t i s a v a i l a b l ew h i l e p r o c e s s i n g
card A.

FigureS-21 . The Look Ahead Function with a Card File

C o n t r o l l i n g O p e r a t i o n sI n A n R P G l l P r o g r a m

5'17

Disk Files: Figure5-22showsprocessing
of threeof the
r e c o r d sf r o m t w o d i s k i n p u tf i l e s ,o n e p r i m a r ya n c o
t ne
s e c o n d a r yT. h e r e c o r d sa v a i l a b lfeo r l o o k a h e a dd u r i n q
the
processing
of theserecordsare:

Record Processed
P1

P 2 a n dS 1

P2

P 3 a n dS l

S1

P 3 a n d5 2

PRIMARY FILE

1
Read first record
from primary file (Pl ). i,t::ri:

2

2

SECONOARY FILE

3
(P5

(P4)

lP2

RecordsAvailable

'

Match Field
Value

L

Area into which records
are read (read areal.

----J
I

I
I
I

I

Area into which records
are selected for
processing (process area).

I

- -

2

L?Read secona
record from
primary f ile.

2
(P3l (P4

- _ _J

3
(P5

,,aLi

Read Area

Process Area

r.-_._
Select first record
from primary file
for processing,

Fitgwe 5-22 (Part I of 2). Records Available for
Look Ahead: Two Input Files
5.18

___J

In general.when the recordbeingprocessed
is from an inp r u tf i l e ,t h e n e x t r e c o r di n t h e i n p u tf i l e i s a v a i l a b laesa r e
the recordswhich werereadbut not processed
from tne
o t h e rf i l e s .

@
1

@neaotniru
record from
primary file.

2

2

3

(s4
.,i,

i----R e a dA r e a

P r o c e s sA r e a

f r o m p r i m a r yf i l e f o r
p r o c e s snr g .

6

3

(s3) (s4)

(s5)

s e c o n dr e c o r d
@*."0
f r o m s e c o n d a r yf i l e .

T

Read Area

P r o c e s sA r e a

l-- l

Oru,..,

first recordfrom

s e c o n d a r vf i l e f o r p r o c e s s i n g .

L-1P-2]i processed
Records

- - -l
l-1-

i--grl
F i g u r e 5 - 2 2 ( P a r t 2 o f 2 ) . R e c o r d sA v a i l a b t ef o r L o o k A h e a d : T w o I n p u t F i l e s

C o n t r o l l i n gO p e r a t i o n sI n A n R P G l l P r o g r a m

5-19

Checkingfor Duplicates
Duplicaterecordsor recordswith duplicatefieldsare sometimesconsidered
erroneous.Orrlyone of the duplicates
shouldbe usedfor the job.
Consider,for example,the caseof a companywhich hasa
largeturnoverin inventoryitems. Ouite frequentlynew
itemsareaddedand othersdeietedfrom the inventory.
A
numberfor a deletedpart is to be assigned
to a new part.
Somenristakes
haveoccurred,however,and one part num_
ber hasbeenassigned
to two clifferentitems. As a resultof
this error,inventorybalances
for theseitemshavenot been
updateo:orrectly.and errorshavebeenmadeon customer
i n v o i c e s l.f t h i s s i t u a t i o ni s p o s s i b l ea, r e g u l acr h e c ks h o u l d
be madefor duplicatepart numlrcrs.
Eachmonth, a report is createdshowingthe completein_
ventory. All part numbersare listedon the report. you
could look throughthe reportto checkfor duplicatepart
numbers,but it would be easierand moreaccurateif you
rcouldadd a few specifications
tlrat would checkfor duplicatesand indicateon the reportwhich item numbersare
rCuplicate.

By usingthe look aheadfeatureyou haveaccess
to informa_
tion that is comingup. You canthen usethis information
to determinewhat operationsto do. lf you are processing
a recordwith part number64322,and you know that the
next recordalsohaspart number64322,you can print a
message
indicatingduplicatepart numbers,then halt. But,
if you are processingthe recordwith part number 64322
and you do not know that the next recordalsohaspart
number64322,you can do nothingspecialbecause
you are
not awarethat you are processing
a recordwhich contains
a duplicateentry.

Writing Specifications for Look Ahead
Any field which you want to look at in the next recordto
be processed
must be definedasa look aheadf ield. lf that
f ield is alsousedin normalprocessing
(otherthan asa look
aheadfield), it must be defined in the normalway also.
Thus,most look aheadf ieldswill be specifiedtwice.
Figure$23, lines01-05,showsspecifications
neededto
describethe input file usedin preparingan inventorylisting.
Whencheckingfor duplicates,PARTNO is the field you
want to usewhen lookingaheadat the next record;therefore, PARTNOmust be definedasa look aheadfield. The
specifications
in Figure5-23.lines06-07,do this.

RPG INPUTSPECI
FICATIONS
I8M,,,",.,,,".",

GX219@4

U/M 050'

M d c h , nc€o , m . a n o n
",,,nes
Graohic

C.rd Electo Numh'

,.*r-tTi.,-

75 76 17 18 79 AO

r r q r at m
t t t t t l
rde.',ioro.l | | I | |

Field
I ndicators

!

Field Name
I

l

I
I
l

Figure 5-23. Look Ahead Specifications

I

I
T

j

All look aheadfields must be definedas being in a record
type different from the othersdefined. This is done by
usinga uniquealphabeticsequence
entry in columnslS-,|6.
No record identifying indicator (01-gg) can be used. A
doubleasterisk('*) is placedin columnsl9-20 to specify
that the fields describedin the following linesare look
aheadfields. Field location is also specifiedfor look ahead
fields.

Everylook aheadfield must be named,but the namegiven
must be different than when it wasdescribedas a normal
input f ield. The samefield is giventwo namesso that you
can distinguishbetweenthe field on the record being
processedand that samefield (the look aheadfield) on the
recordthat is to be processednext (Figure 5-24).

@

(NEXTNO)
NEXTNO refersto
positions1-5in the
record to be processednext.

I N P U TA R E A

I

I

iriii:iriilii

a:ati
ti:::
aa:;l;ll|

tSiriii

(PARTNO)
PARTNO refersto positons
1-5 in the recordcurrently
orocessed.

ii'iiii
','.#i
: t -rliilli
ntiiii:iilt

:iiiiiiiiiii.

P R O C E S S I NAGR E A
llllilr,l.:',i

i!iiii:ij:.:.:i:iiiiiiiii:,iiiiiiiiiii'iiliiiiiiiiiiiiili,i,,i,r,,,,,,

Figure 5-24, Look Ahoad Field: A FieH with Two Nam6

C o n t r o l l i n g O p e r a t i o n sI n A n R P G l l P r o g r a m

5-21

Using Loak Ahead lnformation

t h e y a r e e q u a l ,i n d i c a t o r0 7 i s t u r n e d o n . N o t i c e o n t h e
Output-Format sheet that when 07 is on, the word duplica,e is printed.

N o w t h a t y o u h a v es p e c i f i e tdh e l o o k a h e a df i e l d ,y o u c a n
u s ei t a sy o u w o u l da n y o t h e rf i e l c l .T h eo n l y e x c e p t i o n s
a r et h a t y o u c a n n o tu s ei t a sa r e s u l tf i e l d i n c a l c u l a t i o n s ,
n o r c a n i t b e b l a n k e da f t e rf o r o u t p u t .

T h e S E T O N a n d S E T O F o p e r a t i o n si n l i n e s0 2 - 0 4 fo f t h e
C a l c : r l a t i o ns h e e ta r e u s e d s o t h a t t h e c o m p u t e r v v i l l i n d i c . . e a d u p l i c a t ew h e n t h e s e c o n dr e c o r d h a v i n gt h e d u p l i c a t ep a r t n u m b e r i s p r o c e s s e d .

I n t h e l i s t i n gp r o g r a my, o u h a v et o m a k ea c o m p a r i s o n
betweenpart numbersfrom two records.lf pARTNO on
t h e r e c o r db e i n gp r o c e s s i ni sgt h e $ a m ea s N E X T N Oo n t h e
n€xt recordto be processed,
you wishto print a message
i n , C i c a t i nd gu p l i c a t ee n t r i e s .l f t h e P A R T N Oa n d N E X T N O
f i e l d sd o n o t m a t c l r t, h e r ea r en o d u p l i c a t efso r t h a t p a r t
n u r m b e ar ,n dt h e i t e m i s m e r e l vl i s t e d .

C o n s i d e r ,f o r e x a m p l e ,r e c o r d sA 1 , A 2 , a n d B . T l r e f i r s t
t w o r e c o r d sa r e d u p l i c a t e s ;t h e t h i r d i s n o t . W h e r rA 1 i s
p r o c e s s e dt,h e p r o g r a m l o o k s a h e a dt o A 2 a n d , b \ r c o m p a r i n g ,k n o w s t h a t A 2 i s t h e s a m ea s A 1 . W h e n A , 2 i s
p r o c e s s e dt,h e p r o g r a m l o o k s a h e a dt o B . T h e c o r n p a r ew i l l

F i g u r e5 - 2 5s h o w ss p e c iifc a t i o n sf o r t h e p r o g r a mT. h e o p e r a t i o n i n l i n e0 1 o f t h e C a l c u l a t i osnh e e ct o m p a r etsh e p a r t
n u m b e ro n t h e r e c o r db e i n gp r o c e s s e(dP A R T N O )t o t h e
p a r t n u m h e ro n t h e r e c o r dc o m i n gn e x t ( N E X T N O ) . l f

RPG

s a y t h a t A 2 i s n o t a d u p l i c a t e s i n c ei t d o e s n o t m e t c h B 1 .
B u t A 2 r e a l l y i s a d u p l i c a t e b e c a u s ei t i s t h e s a m ea s A 1 .
T h u s , w h e n p r o c e s s i n gA 1 , y o u h a v et o s e t a n i n d i c a t o r
w h i c h w i l l b e o n w h e n A 2 i s p r o c e s s e da n d w h i c h w i l l i n d i c a t e t h a t A 2 i s a d u p l i c a t es i n c ei t m a t c h e st h e p r e v i o u s
record.

CALCULATION SPECIFICATIONS

i

I

;

I

I

',,"r;;n.",

l.i i r1 iL__

I

l

**ff]'-*

Fa..rat2

Comnier,c

I

l +i

RPG

,,J
-T-t

OUTPUT

S P E C IIFC A T I O N S

l ; , " , " .I i I | | I l 1 . . ' , , ' " " ' ^ \ - , ' ; ; - , ' l
t
t-t + I +-JI I
L P u n ' h t l l l l l L l

Il

Figure 5-25. using lnformation from the Look Ahead Field to check for Duplicates

5.22

P,oqram [-Tf
rde.rr(a'ont

I

|

|

fT
.l*LLl

n

W h e n P A R T N O e q u a l sN E X T N O , 0 7 t u r n s o n . T h i s . i n
t u r n , c a u s e si n d i c a t o r 5 1 , w h i c h i s u s e dt o i n d i c a t et h a t a
d u p l i c a t er e c o r d i s p r o c e s s e dt,o t u r n o n . D u r i n g t h e n e x t
p r o g r a m c y c l e , t h e c o m p a r ed o e s n o t i n d i c a t ed u p l i c a t e s ;
t h e r e f o r e0 7 i s n o t o n . B u t 5 1 r s o n , m e a n i n gt h a t t h e r e c o r d b e i n g p r o c e s s e di s a d u p l i c a t es i n c et h e p a r t n u m b e r o n
i t m a t c h e d t h e p a r t n u m b e r o n t h e p r e v i o u sr e c o r d . T h e r e f o r e , 0 7 i s s e t o n . R e m e m b e r0 7 c o n d i t i o n st h o s e o u t p u t
o p e r a t i o n sw h i c h a r e t o b e d o n e f o r d u p l i c a t e s .

12455 DOOR KNOB

48

l n d i c a t o r 5 2 i s s e t o n i n l i n e 0 3 t o i n d i c a t et h a t t h e l a s t
d u p l i c a t er e c o r d i s b e i n g p r o c e s s e d .I n d i c a t o r 5 2 t h e n c o n
d i t i o n sl i n e 0 4 s o t h a t i n d i c a t o r5 1 w i l l b e s e t o f ! a n d n o t
i n d i c a t ed u p l i c a t e si n t h e f o l l o w i n g c y c l e . F i g u r e5 - 2 6
s h o w st h e p r o g r a m l o g i c f o r t h i s j c l b .

DTJPLICATE

a
Read a

N o t e : T h i s r e c o r di s r e a do n l y i f
the Look Ahead feature is used.
I t l s r e a da f t e r d a t a f r o m t h e
f irst record is moved into
a
t h e p r o c e s s i n ag r e a .

Record

12455
T u r no n
O
recordidentitying
indicator01

a
Perform detail
output

o

o

a

Perform detail calculations:
C o m p a r eP A R T N O f i e l d s :
1 2 4 5 5t o 1 2 4 5 5
T h e y a r e e q u a is o t u r n 0 7 o n
0 7 i so n s oS E T O N5 1 .

Movedata from record
s e l e c t e di n t o p r o c e s s i n g
area. lf Look Ahead is
u s e d ,r e a d a n o t h e r r e c o r d .
l f c a r d s ,t h e f i r s t i s s t a c k e d .

o
a
o

o
o

a

F i g u r e 5 - 2 6 ( P a r t 1 o f 3 ) . Logic for Look Ahead

C o n t r o l l i n gO p e r a t i o n sI n A n R P G l l p r o g r a m

5,23

12455 DOOR KNOB

48 OUPLICATE

12455 HINGE,6" .,,

90 DUPLICATE

a

a

o
a

o
o

Turn off
recordidentifying
indicatorOl

Y{"
12456

l
I
I

o

12455

I
I
I

I
I
J

Turn on
recordidentifying
indicator01

Perform detoil
output

o

o
Performdetailcalculations:
ComparePARTNOfietds:
12455 to 12496
Not equalso turn 07 off
SETONO'l and32usingSt from
p r e v t o ucsy c t e . S E T O F5 1 a n d5 2

O

a

Move data from record selected
i n t o p r o c e s s i n ga r e a . l f L o o k
A h e a d i s u s e d ,r e a d a n o t h e r
r e c o r d . l f c a r d s ,t h e f i r s t c a r d
is stacked.

o

o
o
o
o

Figure 5-26 (Part 2 of 3). Logic for Look Ahead

5.24

1 2 4 5 5 D O O RK N O B

48 DUPLICATE

12455HINGE,6"

90 OUPLICATE

12456 H|NGE,8"

75

a

o

-

, " "
o //-

/r
rl

li

.t! '
nk;r--;;

o
Turn off
record identifying
indicator 01

a

o

)r.;,qs{--a
!
I
F
J

e
T u r no n
recordidentifying
indicator01

Perform detail
output operations

o

a

a

Perform detail calculatrons:
ComparePARTNO fieros:
12456 to 12457
U n e q u a ls o t u r n 0 7 o f f .

a

o

Movedata from record selected
i n t o p r o c e s s i n ga r e a . l f L o o k
A h e a d i s s p e c i f i e d ,r e a d a n o t h e r
r e c o r d . l f c a r d s ,t h e f i r s t c a r d
is stacked.

o
a

I

F i g u r e 5 - 2 6 ( P a r t 3 o f 3 ) . Logic for Look Ahead

C o n t r o l l i n gO p e r a t i o n sI n A n R P G l l P r o g r a m

5-25

Doing Special Operations When There is Only One Record
in a Group
It is often important to know if and when you are processi n g t h e o n l y r e c o r d i n a g r o u p . T h e p r o g r a md e s c r i b e di n t h e
f o l l o w i n g p a r a g r a p h si s s u c n a c a s e .
A report is preparedshowing chargesmade by customers
d u r i n g t h e m o n t h ( F i g u r eE - 2 7 1 . T h e i n p u t f i l e i s o r g a n i z e d i n a s c e n d i n go r d e r b y c u s t o m e rn u m b e r . D u r i n g t h e
month some customerswill hav,amade one charge;others
several.
When only one charge is made per customer, the total line
i s n e a r l y a d u p l i c a t eo f t h e o n l y d e t a i l l i n e . I n t h i s c a s e ,
y o u d o n o t n e e dt o p r i n t b o t h t h e d e t a i l a n d t o t a l l i n e b e c a u s et h e t o t a l l i n e w i l l d o .
B u t h o w w i l l y o u k n o w d u r i n g a n y o n e p r o g r a mc y c l e
whetherthe current record is the only one in a group?
Y o u c a n f i n d o u t b y l o o k i n g a t i n f o r m a t i o no n t n e n e x t
r e c o r d . R e m e m b e r ,a n y t i m e i n f o r m a t i o n f r o m t h e n e x t
record is necessaryto determine how to processthe current record, you must use the look ahead feature. Account
n u m b e r i s e s t a b l i s h e da s a l o o k a h e a df i e l d i n t h i s p r o g r a m .
Any look ahead field specified applies to all record types. Thus
each record read contains infornration that will be looked at

M O N T H L YC H A R G E S
ACCTNO

NAME

CHARGE

47653

JILL ARNDT

a.97
1
5.99 ) Detail linat
n.87 )

47653

JILL ARNDT

34.98 r Tot.l

'[9832

NANCY BENNET

87.93 r Tot l

59821

JOAN BOND

7.42

Doralt

Figure 5-27. Format of Monthly Charge Report

Whenever
a recordis read,the currentACCTNOfield is
compared
t o t h e o n ec o m i n gu p . l f t h e f i e l d sa r ee q u a l y, o u
know you are processing
a recordthat is not the only one
i n a g r o u p . T h e r e f o r ea, d e t a i l i n es h o u l db e p r i n t e d . l f
t h e A C C T N Of i e l d sa r en o t e q u a la n dt h i s i s t h e f i r s tt i m e
the presentaccountnumberhasbeenencountered,
the curr e n t r e c o r di s t h e o n l y o n e i n t h e g r o u p ,a n dt h e d e t a i ll i n e
shouldnot print. Figure5-28showsthe specifications
for
the program.

before the record itself is processed. By looking ahead into
this f ield you will know whetheror not the next record
to be processedis part of a new group.

RPG INPUTSPECIFICATIONS

IBIT
T:--

C a , d E l e c i r oN u m e r

I
I Pros.ammer

I oare

Figure 5-28 (Part 1 of 2l' Using Look Ahead to Determine When There is Only One Record
in a Group

GX2l g
U/M050.
p n ^ r d , nU S . A

*'ffi"
_

75 76 77 78 79 80
r q , s m l t t t t t l
j
ldenlnetionl
|
|
I
|
|

C A L C UL A T I O NS P E CFI I C A T I O N S
C.rd Erecto Numhr

P,q,!m
_

TT-TT-IT]

lde^rl,cononl

SPECIFICATIONS

I

I

I

GX21m

I

I

I

U/MoS'

181t,.,..".,,"".,
",,,{sMd,dco.ts,,n6
Grd

Aq.mre.

o

Faeld Name

o
Filename

li

l:
lo

o

5

0

6

o

7

0

;

0

9

o

F
t:

t+tt

z

R

n
" '' '' ', '"1;
I

v*
v*
*.
o

|
|
|
I

I
|
|
" *o _ . _ I
N
Nu

r
.
.
4 l

i
I
j
p l

a
s
c
M

I J lY
lr
I
lL lz
l

-l

oare
l
F'erdtdtrl
z*.
I
s u p p r e s l

Constanl or Edit Word

.AUTO

t 9 t

I

t ll<

h

'tAl

1f
fl;
t l
th
lp

l.

i12

lo
T I
lo

I

l. IF
f

l t q

T"l
T"1
l"l
E

c

lol
lol
-t--1
lol

I

z
I

I

I

1r
l12

T;l
lo

1
I
|
l N

End

E

t l

T

Nuhb'

) | -*- ;^';.i;11.*J""',*f""
I l" ::-r

Oulput Indrcato.s

*ip

;

0

Electo

I o.n

| | l

I

llr

J

t;
I

l't

I

f

Figure 5-28 lPart 2 of 21. Using Look Ahead to Dstermino When There is Only One Rscord in a Group

C o n t r o l l i n g O p e r a t i o n sI n A n R P G l l P r o g r a m

5-27

DoingSpecialOperationsfor the Last Recordin a Group
I n s o m ep r o g r a m si t, m a y b e n e c e s s a troy d o s p e c i aol p e r a t i o n so n t h e l a s tr e c o r do f a c o r r t r ogl r o u p . T h i s i s b e c a u s e ,
u n l e s tsh e l a s tr e c o r di n t h e c o n t r o lg r o u pi s o f a d i f f e r e n t
t y p e ( h a v ed i f f e r e n tr e c o r di d e n t i ifc a t i o n ) i,t i s i m p o s s i b l e
g e l a s tr e c o r di n t h e
t o k n o w w h e ny o u a r ep r o c e s s i nt h
g r o u p . W h e na l l r e c o r d sa r eo f t h e s a m et y p e ,y o u h a v et o
k n o w w h a t i s o n t h e n e x t r e c o r db e f o r eV o u k n o w w h e t h e r
g e l a s tr e c o r di n t h e g r o u p . T o
o r n o t y o u a r ep r o c e s s i nt h
l o o k a t i n f o r m a t i o ni n t h e n e x t r e c o r d y, o u m u s tu s et h e
l o o k a h e a df e a t u r e .

47654
(Account field
specified also as
a l o o k a h e a df i e l d )

Figure5-29showsfour recordswhich areto be processed.
T h e f i r s t t h r e eb e l o n gt o o n ec o n t r o lg r o u p ;t h e f o u r t h i s
t h e b e g i n n i nogf t h e n e x tg r o u l : . T h e l a s tr e c o r do f t h e
g r o u p( t h et h i r d r e c o r di n t h i s r : a s er)e q u i r es p e c i a l
p r o c e s s i n gI n
. o r d e rt o k n o w v u h e nt h e l a s tr e c o r di n t h e
group is to be processed,
you ntustlook at the accounr
n u m b e ri n t h e n e x t r e c o r d .W f r e ni t i s d i f f e r e n ty, o u k n o w
that the lastrecordin the grou;cis beingprccessed.

I n t h e p r o c e s s i n go f
t h i s r e c o r d ,t h e L o o k
Ahead featureshows
that the next account
n u m b e ri s d i f f e r e n t .
T h e r e f o r e ,t h i s i s t h e
last record of a group
and as such requires
s p e c i a lo p e r a t l o n s .

AdditionalPointsto ConsiderAbout Look Ahead
Y o u m u s tc o n s i d etrh e f o l l o w i n gt h i n g sw h e ny o u a r e
p l a n n i n gt o u s el o o k a h e a d :
a W h e n l o o k a h e a di s u s e d w i t . h a c o m b i n e d o r u o d a t e
file, and that file isthe only input file in the program,
t h e f i e l d l o o k e d a t i s n o t o n t h e n e x t r e c o r d ,b u t o n
the record currently being processed.Therefore, there

Figure5-29. Using Look Ahead to Find Last Record in a Group

i s l i t t l e u s e f o r l o o k a h e a dw i t h u p d a t e o r c o m b i n e d
f i l e s i n a s i n g l ef i l e p r o g r a m . I n a p r o g r a mw i t h r n u l t i p l e

MOVING DATA

i n p u t - t y p e f i l e s , l o o k a h e a df i e l d s c a n b e u s e fu l i n u p d a t e
a n d c o m b i n e d f i l e s . F o r e x a m p l e ,i f t w o f i l e s w i t h l o o k
a h e a df i e l d s a r e b e i n g p r o c e s s e d- a n i n p u t f i l e a n d a
c o m b i n e d f i l e ( o r u p d a t e f i l r : ) - l o o k a h e a df i e l d s i n t h e

Y o u c a n i n s t r u c t t h e p r o g r a mt o m a n i p u l a t ed a t a i n m a n y
different ways. You can causedata to be added, subtracted,
m u l t i p l i e d , c o m p a r e d ,t e s t e d o r d i v i d e d . Y o u c a n a l s o c a u s e
data to be moved. When data is moved, a copy of the data
i n o n e f i e l d i s t r a n s f e r r e dt o a n o t h e r f i e l d . I n t h e p r o c e s s
o f t r a n s f e r ,i t m a y o r m a y n o t b e c h a n g e dd e p e n o i n gu p o n
your specifications.

c o m b i n e d f i l e a r e a v a i l a b l ea s t h e i n p u t f i l e i s b e i n g
processed(see Figure 5-22).
L o o k a h e a di s n e v e ru s e dw i t h c h a i n e d ,d e m a n d , o r o u t put files.

Y o u m a y w i s h t o m o v e d a t a f o r m a n y r e a s o n si,n c l u d i n g :

Only one look ahead record type specification may be
u s e df o r a f i l e . T h e r e m a y b e s e v e r a fl i e l d s l i s t e d u n d e r

T o s a v ei n f o r m a t i o n f r o m a f i e l d .

that one record type specification however,

To separateone field into 2 or more parts.

A n y l o o k a h e a df i e l d s s p e c i { ' i e a
dpply to all types of reco r d s i n t h e f i l e . T h e r e f o r e ,a l l r e c o r d sr e a d f r o m t h e f i l e
w i l l b e t r e a t e d a s i f t h e y h a v e l o o k a h e a df i e l d s .

3.

T o c h a n g ea n u m e r i c f i e l d i n t o a n a l p h a m e r i cf i e l d o r
vice versa.

T h e p r e c e d i ntgo p i c sw i l l b e d i s c u s s el d
a t e ri n t h i ss e c t i o n .
First,however,you must learnhow to usethe moveoperation codes.

5-24

iSpecifications
for MovingData
-fwo

operationcodescan be usedto movedata: MOVE or
I V I O V E L .F o r b o t h o p e r a t i o nFs a c t o r2 a n d t h e R e s u l t
l F i e l da r ea l w a y su s e d . F a c t o r2 m a y b e e i t h e !a. f i e l do r
c o n s t a n t .A n y c o n d i t i o n i n g
i n d i c a t o rm
s a v b e u s e d .H o w _
e v e r ,F a c t o r1 a n d r e s u l t i n g
i n d i c a t o rm
s a y n o t b e s p e c iife d .
-fhe

MOVE operationcodemovesa copy of characters
sitartingfrom the rightmostpositionof Factor2 into the
r i g h t m o s pt o s i t i o n os f t h e R e s u l tF i e l d . A s a r e s u l to f t h e
r n o v et,h e c o n t e n t so f t h e R e s u l tF i e l da r ec h a n g e db, u t t h e
c o n t e n t so f F a c t o r2 r e m a i nt h e s a m e .F i g u r e5 - 3 0i l l u s t r a t e st h e M O V Eo p e r a t i o n .

l f t h e R e s u l t F i e l d i s t h e s a m el e n g t ha s F a c t o r 2 , a l l c h a r acters in Factor 2 are transferred. However, if the Result
F i e l d i s s h o r t e rt h a n F a c t o r 2 , o n l y t h e n u m b e r o f c h a r a c t e r s n e e d e dt o f i l l t h e R e s u l t F i e l d a r e t r a n s f e r r e d .O n t h e
o t h e r h a n d , i f t h e R e s u l t F i e l d i s l o n g e rt h a n F a c t o r 2 , a l l
charactersin Factor 2 are moved to the rightmost positions
o f t h e R e s u l t F i e l d . T h e e x c e s sl e f t m o s t c h a r a c t e r so f t h e
ResultField remainunchanqed.
T h e M O V E L o p e r a t i o n i s j u s t t h e r e v e r s eo f t h e M O V E
operation; it moves a copy of the charactersstarting from
the leftmost position of Factor 2 into the leftmost posit i o n s o f t h e R e s u l t F i e l d . F i g u r e 5 - 3 1 i l l u s t r a t e st h e M O V E L
operation.

The MOVE operation code
moves a copy of characters
starting with the rightmost
position of Factor 2 into the
rightmost positions of the
Result F ield.

he MOVE L ooeration code
a copy of characters start
with the leftmost position of
Factor 2 into the leftmost
p o s i t i o n so f t h e R e s u l t F i e l d .

Factor 2
Factor 2

1234567

12345

When Factor 2 and the
R e s u l t F i e l d a r e t h e s a m el e n g t h
all characters in Factor 2
can be moved. Movement starts
with the rightmost character of
Factor 2.

When Factor 2 and the
R e s u l t F i e l d a r e t h e s a m el e n g t h
all characters in Factor 2
can be moved, Movement starts
with rightmost character of
Factor 2
Result Field

Result Field

Factor 2

1234567

When Factor 2 is longerthan the
Result Field, only the exact number of characters needed to fill
the Result Field are moved from
the rightmost positions of Factor 2
into the Result Field

Result Field

When Factor 2 is longer than the
Result Field, only the exrct number of characters needed to fill
the Result Field are moved from
the leftmost positions of Factor 2
into the Result Field.

Result Field

Result Field

Factor 2

Factor 2

When Factor 2 is shorter than
t h e R e s u l t F i e l d , a l l c h a r a c t e r si n
Factor 2 are moved into the
rightmost positions of the
R e s u l t F i e l d . A l l c h a r a c t e r si n t h e
Result Field to the left of those
moved in from Factor 2 remain
the same as they were
before the move.

f:igure 5-30, MOVE Operation Code

Factor 2

Result Field

When Factor 2 is shorter thgn
t h e R e s u l t F i e l d , a l l c h a r a c t e r si n
Factor 2 are moved into the
leftmost positions of the
R e s u l t F i e l d . A l l c h a r a c t e r si n t h e
Result Field to the right of those
moved in from Factor 2 remain
the same as they were before
the move.

Figure 5-31. MOVEL Operation Code

C o n t r o l l i n g O p e r a t i o n sI n A n R P G l l P r o g r a m

5-29

Account F ield

Reada Record

Movedata into processing
area

INPUT
AREA

INPUT
AREA

ACCT

PROCESSING
AREA

PROCESSING
AREA

I

l-l613r-l

t

t

ACCT

F'par'aF'orn-'
I

f f ; l

t:-:]

Move data into processingarea
IN P U T
AREA

Iffi-l
l

l

ACCT

ACCT

I

I

I

I
PROCESSING
AREA

PROCESSING
AREA

t

l
ACCT

Figure 5-32. Dara in Storag€

5-30

Saving Information From a Field by Move Operations

Recordout of seouence

A n y i n f o r m a t i o n i n f i e l d s s p e c i f i e da s i n p u t f i e l d s i s n o r .
r n a l l y o n l y a v a i l a b l ef o r o n e p r o g r a mc y c l e . E a c h t i m e a
rercordis read, information from the fields on the new reco r d r e p l a c e st h a t w h i c h w a s t h e r e f r o m t h e p r e v i o u sr e c o r d
( s e eF i g u r e 5 - 3 2 ) .
T h e r e a r e t i m e s , h o w e v e r ,w h e n y o u w i s h t o s a v ei n f o r m a t i o n f r o m a r e c o r d s o t h a t y o u c a n h a v e i t a v a i l a b l ei n t h e
n L ' x tp r o g r a mc y c l e . F o r i n s t a n c e y, o u m a y w a n t t o c h e c k
t f r e c o n t e n t so f a f i e l d i n o r d e r t o d e t e r m i n ei f a f i l e i s i n
p r o p e r s e q u e n c eo r i f i t h a s d u p l i c a t ee n t r i e s . I n o r o e r r o
d < lt h i s , y o u m u s t h a v et h e d a t a f r o m t w o f i e l d s ,t h e f i e l d
from the record just read and the field from the recoro
r e a d i n t h e p r e v i o u sc y c l e .
C o n s i d e rt h e p r o b l e m o f c h e c k i n gt h e s e q u e n c eo f , a n d
f i n d i n g d u p l i c a t ee n t r i e sf o r , t h e f i l e s h o w n i n F i g u r e 5 " 3 3 .
S e q u e n c ei s t o b e b a s e do n A C C T ( a c c o u n tn u m b e r ) a n d
m u s t b e a s c e n d i n g .A n y d u p l i c a t eo r o u t - o f - s e q u e n c ree c _
ords are to be flagged.
Figure5-33. Inpur Field Sequence

T h e p r o g r a m m u s t c o m p a r et h e A C C T f i e l d s f r o m t w o
r e c o r d s : t h e r e c o r d c u r r e n t l y b e i n g p r o c e s s e da n d t h e p r e _
v i o u s r e c o r d . T h e c u r r e n t a c c o u n tf i e l d s h o u l d a l w a y s b e
h i , g h e trh a n t h e p r e v i o u sa c c o u n t f i e l d . W o u l d t h e s p e c i fi cations in Figure 5-34 do the iob? They would not, Dec a u s ei n o n e p r o g r a mc y c l e t h e f i e l d n a m e d A C C T a l w a y s
h a s t h e s a m e i n f o r m a t i o n i n i t . T h i s i n f o r m a r r o ni s t a k e n
f r o m t h e r e c o r d j u s t r e a d . J u s t b e c a u s eV o u u s e t h e n a m e
t \ / i c e ,y o u w o n ' t g e t t w o d i f f e r e n t A C C T f i e l d s .

C A L C UL A T I O N S P E CFTI C A T I O N S

- _

-

l;;;

1 2
- ' r

l

r 5 b 7 7 7 8 ,.8n

' * L l

L t::::"
3
l

F i g u r e 5 - 3 4 , S e q u e n c eC h e c k i n g ( l n c o m p l e t e S p e c i f i c a t i o n s )

C o n t r o l l i n gO p e r a t i o n sl n A r r R P G l l P r o g r a m

(@-7

Account field

r*-ll

INPUT
AREA

INPUT
AREA

t-r6t5'-tl
t
l
ACCT
T

/
I
PROCESSING
AREA

,aoarrr,*o /
AREA

ti6tsTl

l

INPUT
AREA

ta

ROCESSING
AREA

tl6.'
t

-l

l

ACCT

Figure 5-35. Moving Data to Save lt
5-32

F6-'--l

l

ACCT

-

move

INPUT
AREA

PROCESSING
AREA

F6.t_l

t

ACCT

l

l

SAVE

l

Threrefore,
eachtime a recordis read,you must savethe infonnration{rornthe ACCT f ield so that it is not destrcyed
w h e na n o t h e r e c o r di s r e a d .T h i sy o u c a nd o b y m o v i n g
A C C T i n t o a n o t h e rf i e l d . ( F i g u r eS - 3 5i l l u s t r a t etsh i s c o n _
ceut.)
Figure5-36showsthe specifications
neededto do the job.
A s s u m et h a t y o u m o v eA C C T i n t o a f i e l dc a l l e dS A V E .
The first srepis to compareACCT with SAVE {whichcontainsthe previousACCT data). The secondstepis to move
A C C T i n t o S A V E . I n t h e f i r s t p r o g r a mc y c l e ,S A V E w i l l
c o n t a i na l l z e r o ss i n c ea l l n u m e r i cf i e l d sa r es e tu p w i t h
zerosbeforethe first recordis read. I n the next cycle,
a n da l l c y c l e st h e r e a f t e rS, A V Ew i l l c o n t a i nt h e A C C T f i e l d
from the previousrecord.

w a n tt o m u l t i p l yt h e w h o l ep a r t n u m b e rf i e l dt i m e sq u a n "
tity just because
the part of the field containsunit price.
Somehow,you must separate
pricefrom the restof the
f ield.
To do this you againusea moveoperation,you cannor
m o v et h e w h o l ef i e l d i n t o a n o t h e rf i e l c a
l sw a sd o n ei n t h e
p r e v i o ue
s x a m p l e .T h i s m e r e l yc r e a t eas s e c o n df i e l di d e n tical to the first. You want only the lastf ivecharacrers.
T h e r e f o r ey,o u m u s tm o v et h e f i e l d i n t o a S - p o s i t i ofni e l d .
T h i sw i l l l i m i t t h e m o v et o f i v ec h a r a c t e r(ss e eF i g u r eS - 3 7 ) .

RPG

CALCULATION SPECIFICATIONS
--'l-

Maybeyou arewonderingwhy you woulcJeverwanr to se_
q u r ) n c ceh e c kb y c a l c u i a t i o ni sn s t e a do f u s i n gt h e R p G l l
a u t o m a t i cs e q u e n cceh e c k i n gf u n c t i o nw h i c hi s d o n em e r e l y
b y s p e c i f y i n ag m a t c hf i e l d . T h e a n s w e irs t h a t ,w i t h R p G
ll arutomatic
sequence
checking,any out-of-sequence
card
w i l l c a u s ea h a l t . l t y o u d o n o t w i s ht o h a l t ,b u t m e r e l y
wishto indicateout-of-sequence
or duplicatecards,then
y o u m u s td o y o u r o w n s e g u e n cceh e c k i n g .y o u c o u l da l s o
usethe look aheadfeature,sinceboth look aheadand the
u s eo f m o v e si n c a l c L r l a t i ognisv ee s s e n t i a l tl yh e s a m er e s u l t s .

,,h,ne

,uao-

|

-i_

r'-T
r

,

]--.-;n"-;;;N,-;a-

i-':-J:;:Ti-i,[1 -a_

P A R TN O

Seprarating
One Field Into Two parts
A companyhasdesignedits part numbersto containtwo
diflerentkindsof infornration.The basicpart numberis
containedin the f irst threecharacters.The remainingf ive
characters
containthe price. For example,in the parr number 65J00498.the basicpart numberis 65J and the priceis
$ 4 . 1 9 8W
. h e np r e p a r i n ign v o i c e si t, i s n e c e s s a tr oy m u l t i p l y
u n i : tp r i c et i m e sq u a n t i t yt o f i n d t h e t o t a l p r i c e . y o u d o n ' t

6 : s : J. O : O : 4 : e . 8

o:o:4:e:8
F i g u r e 5 - 3 7 , S e p a r a t i n gt h e p r i c e f r o m t h e p a r t N u m b e r
(Usins MOVE!

CALCTL
' A T I O N S P E CF
I ICATIONS
IBll'l

""

",.,.

i :rNnM.ch.gcaoo,ono.

**lfr.,

P 'qram t -i*T T_lTl
ide,tl.,!o,il
i

I

I

-t-

fi-lrlhri
F i g u r e 5 - 3 6 . S o q u e n c eC l . , " , ! t i n g { C o r r e c t S p e c i f i c a t i o r " " l

C o n t r o l l i n gO p e r a t i o n sI n A n R P G l l P r o g r a m

5-33

I n t h i s c a s e ,t h e M O V E o p e r a l i o n w a s u s e d . W h y w o u l d n ' t
t h e M O V E L o p e r a t i o nw o r k a s w e l l ? C o u l d n ' t y o u r n o v e
l e f t i n t o a 3 - c h a r a c t e fri e l d t o s e p a r a t et h e p r i c e f r o m t h e
r e s t o f t h e p a r t n u m b e r ? R e n r e n r b e trh a t a r i l o v e l e a v e st h r . i
o r i g i n a lf i e l d a s i t w a s b e f o r e I h e m o v e . M O V I L d o e s n o t
r e m o v e t h e f i r s t t h r e e c h a r a c t r : r fsr o m t h e o r i g i n a l P A R T N O
f i e l d . l t m e r e l y c o p i e st h e m . Y o u s t i l l w o u l d n o t h a v et h e
u n i t c o s t b y i t s e l f. B u t y o u w o u l d h a v et h e f ) a r t n u m b e r b ' 7
i t s e l f ( s e eF i g u r e 5 - 3 8 ) .

C h a n g i n gF i e l d T y p e ( A l p h a m e r i co r N u m e r r c i
T h e p a r t r t u r n b e ri i e l r j c r : r q t a i nbs o t i r r : i : r l r l l r . l; r j r ( Ja l l r l i ; r
b e t ; c c h a r a c t e r s( s c eF i g u r e 5 ' 3 l i ) . i t \ , o u \ r y a r l iti i e l ) r ' ( ! g r a m t o w o r k r , r y i t thl r e z o n e p o i ' t i r r [ r r l ; r . . - i i : i r l r : t r {: it i sr ' i
m u s t t o g e t t h e I e i t e r J ) , y o l i f r a v et o r i c l r r r et . h r i;i r : l d a s
a l p h a m e r i c( b l a r r ki r r c r i r l L i r n5n2 o f t h e I n ; r t r tr i , r ) r l i " i i c i ' v
e v e r ,y o u c a n n o tu s ea i r a i p h a n - r e rl ri tc, i Cr i ! i r 'r t . l i r ) r a : ji .( j.l .
r : u l a t i o n s .l " o f i r r c ti o t ; r l c o s t . y, o i r | - r r r . ri .r';tLt r i ; i r ; l ry] : r , i l : ; i ' :
b y q u a n t i t y . T ' h i si s a n a r i l i r r . r r e t iocp c r i l . r r n , i . rf u i t h c r r . r l { i
H t u s tb e n u r n e r i c .

RPG CALCULATION
SPECIFICATTONS

,:...";li;;:.']-

-"

i i i l.;',,i*;il;

lr* ji4 il- i i -l-i-i 1

I

l

W h a t d o y o u d o r f y o r . rn e e r Jo r ' e f i e ! d t n l i r C e f i : r , ; r;.1j 1l -, , , : t l r
a l p h a r r : e r iacn c lr u r n e r i c ? \ ' o u c o r . r i ,i l, i , ' : , , ,!ri , , ' ' i e l f l : , : ' : ; , '
o n i ; ea s r r u r r r e r i a
c n d o i r c c . r t a l ; - l n a n : i , r r ci ,. I i l r r i r r \ c ,y v t r
w o u l d f r a l ' ei o u s e i ' . J vnoa t n e l f o r t t r ( ': r 3 . i r r{ r e l r j. , r : i ' . ' r ' }
l i e l d d e f i n e d J ' o rc n e t y p , eo f i e r ; l t - dn r L r s itt 6 r v cd r , ' r , q u a
narne.
Y o u m a y a l s o u s e a I n o v e o p e r a i i < - ;tror c h ; i i r g ea ; r , r i ' r r r, c. r
f i e l d i n t n a n a l p h a r n e r i c{ i e l d o r v i c e , l u ; s a . \ ' i } r . . : i r f r l r . i r ) ' - l €
f i t r l d sb y :
M o v i n g a n a l p h a m e r i c{ i e i r . r. rj a n i e di n F a c l i i ' 2 i n t o a
n u m e r i cR e s u l tF i t : l d .

PART NO

J : OO 4 9 : 8

PART

F i g u r e 5 - 3 8 . S e p a r a t i n gt h e P a r t f r o m t h e P a r t N u m b e r ( U s i n g M O V E L )

5-34

M o v i n g a r r u m e r i cf i e l , . rl t ; r r t e r .r ln F a c l o r 2 i r t t - ci L
, rr
a l p h a r n e r rR
c e s u l tF i s l r l
F i q u r e s5 - 3 9 a n s 5 - 4 0 Q i v et h e r u l e s l ' i i t a n d r r t a r n p i e 'ii. ) t
t h e v a r i o u st y p e s o f r n o v e sy o u i ; a r rn i a k e t c ,c l t a n g r a: t l . : l d
t y p e . F i g u r e5 - 3 9 i l l u s t r a t e :t h e M O V I o p s r a t i i - - ]ari-r!d f : i t l r r r e 5 - 4 0 t h e M O V E L o p r . r r a t i o n .l f y o u d o n o r ,u r ; d e r s t a i i d
r e s u l t so b t a i n e d i n t h e l o w o r , - J cpr o s i t i r : n r ,s e . ii h € c h d p t e r
entitled Working LUith Data Structures.,

Factor 2 samelength as Result Field

Factor 2 samelength as Result Fielcl
Factor 2
When moving an alphameric
f i e l c ii n t o a n u m e r i c f i e l d ,
the digit r)ortion of all characters
is moved. The zone portiori of
t h e r i g h t m o s t c h . r r a c t e ri s a l s o
m o v e d a n d u s e da s t h e s i g i i .

Factor 2
A B C M N O

r i g h t m o s t c h a r a c t e ri s a l s o m o v e d
a n d r r s e da s t h e s i g n .

'1
234:j5

Result F ielcl

W h e n r n o v i n ga n a l p h a m e r i c
f i e l d i n t o a r , u m e r i cf i e l d ,t h e
d ; g i 1f r o r t i o n o f a l l c h a r a c t e r si s
nroved. Tlre zone portion of thn

F actor 2
! { l r e n n r o v i n ga n u m e r i c f i e l c l
i n t o a n a l p h a r n e r i fci e l d a l i
d i g i t s a r e 1 1 3 6 5 f , ; r r n dT
. ha sign
tzone portion) of the riqhtrn{}st
c h a r a c t e ri s a l s o m o v e d .

i*rrr-i_;l
4"_*/
74r-rr-r;(

w * l i ' : r r n * u i n g a i r L r n r e r i fci e l d i n t o
a n a l p h a r n e r i cf i e i i , a l l d i g i t s a r e
moveci. i i:e zone portion of the
r i g h t m o s t c l r a r a c t e ri s a l s o m o v e d .

L1'i;',:J

R e s u l tF i e l d

R e s u l tF i e l r J

F a c t o r 2 l o n g e rt h a n R e s u l tF i e l d
F aclor 2 ionger than Result F ield
Factor 2

A B C D E F

R e s u l tF i e l d

When moving an alphameric
field into a numeric field, the
digit portions r:f only the number
o f c h a r a c t e r sn e e d e dt t : f i l l r n e
Result Field are nioved. The zone
p o r t i o n o f t h e r i g h t r n o s tc h a r a c t e r
i s o l s o r n o v e d a n d u s e r Ja s t h e s i q r r .

'

Factor 2
W h e n r n o v i n ga n u r n e r i c f i e l d
i n t o a n a l p h a r n e r i cf i e l d ,o n l V t h e
n u m b e r o f d i g i t s n e e d e dt o f i l l
the Result Field is moved. The
signof the rightmost character
is also moved.

F l e s u l tF i e l d

W l i e n m o v i n g a n a l p h a m e r i cf i e l d
i n t o a n u m e r i cf i e l d , t h c d i g i t
p o r t i o n s o f o n l y t h e n u m L r e ro f
c h a r a c t e r sn e e d e dt o f i l l t h e R e s u l t
Field are moved. The zone por

{ z o n eo f 0
beconres sigrt
o f t h e r i g h t r n o s tc h a r a c t e ri s a l s o
o f R e s u l tF i e l d ) r n o v e d a n d u s e d a s t h e s i g n .

Factor 2

(zone o{ 0
b e c o n l e ss i g n
o i H e s u l tr r e l d ,

R e s u l tF i e l d

W h e n n r o v i n ga n u m e r i c f i e l d
i n t o a n a l p h a m e r i cf i e l d , o n l y t h e
n u n r b e r o f d i g i t s n e e d e dt o f i l l
the Result Field is moved. The
signof the rightmost character
is alsomoved.

R e s ul t F i e l c l
Factor 2 shorterthan Result Field
Factor 2 shorter than Result Field
Factor 2
I

A B C D E F
I

R e s u l tF i e l d
Factor 2

When moving an alphameric
field into a numeric field, tne
digit portion of ail characters
is moved. The zone portion of
t h e r i g h t m o s t c h a r a c t e ri s a l s o
moved and usedas the sign.
A l l c h a r a c t e r si n t h e R e s u l t F i e l d
to the left of thosejust moved
i n r e m a i n t h e s a m ea s t h e y w e r e
before the move.

R e s u l tF i e l d
Factor 2
I

873219
When moving a numeric field into
a n a l p h a m e r i cf i e l d , a l l d i g i t s a r e
moved. The sign (zone)of the
r i g h t m o s t c h a r a c t e ri s a l s o m o v e d .
A l l c h a r a c t e r si n t h e R e s u l t F i e l d
to the left of those moved in
r e m a i n t h e s a m ea s b e f o r e t h e n r o v e .
F i g u r e 5 . 3 9 . M O V E O p e r a t i o n sI n v o l v i n g F i e l d s o f V a r i o u s
L e n g t h sa n d T y P e s

Pt

|

|

|

t-r,i

8 7 3 2 ' , t6 7
l

i

r

l

l

l

When moving an alphanreric
field into a numeric f ield, the
c ! i g i tp o r t i o n o f a l l c h a r a c t e r s
i s m o v e d . A i l c h a r a c t e r si n
the Result Field to the right
of thosejust moved in remain
the sanreas they were before
the move. Thus the signof
field does not change.
W h e n m o v i n ga n u m e r i c t i e l d
l n t o a n a l p h a m e f i cf i e l d ,a l l d i g i t s
a r e m o v e d . A l l c h a r a c t e r si n
t h e l - l e s u l tF i e l d t o t h e r a g h to f
t h o s el u s t r n o v e di n r e m a i n a s t h e Y
were before the move.

R e s ul t F i e l d

F i g u r e 5 - 4 0 . M O V E L O p e r a t i o n sI n v o l v i n g F i e l d s o f V a r i o u s
L e t t g t h sa n d T Y P e s
C o n l o l l i n g O p e r a t i o n Isn A n R P G l l P r o g r a n r

5.35

In orderfor the letter in the part numbereverto
be read,
c o m p a r e do, r p r i n t e d ,t h e f i e i d, , t u s tb e d e fi n e d
a sa l p h a _
m e r i c .W h e ni t i s t i m e t o m u l t i p l yp r i c et i m e sq u a n t i t y ,
the
priceportion of the f ielclmust be numeric.
Therefore,when
u s i n gt h e M O V E o p e r a t t o n
t o s r s p a r atthee u n i t c o s tf r o m
the restof the part number,you should,at the
sametime,
c h a n g et h e a l p h a m e r iucn i t p r i c ei n t o a n u m e r i cu n i t p r i c e
b y m o v i n gi t i n t o a n u m e r i cf i e l d . T o d e f i n ea n u m e r i c
f i e l d .y o u m u s ts p e c i f yd e c i m apl o s i t i o na l o n g
with field
l e n g t h{ s e eF i g u r e5 - 4 1 ) .
lf the S-character
unir cost had precededthe part number
( f o r e x a m p l e0, 0 4 9 8 6 S J )y,o u v v o u l d
t h e nu s et h e M O V E I _
operationto get the unit costalone" Remember,however,
that the zoneof the rightmostcharacteris usedfor
the sign
o f t h e f i e l d ( s e eF i g u r eS - 4 0 ) .T h e z o n eo f t h e c h a r a c t e r
J
i s a m i n u ss i g n .T h e p r i c ew i l l a p p e aar sn e g a t i v e .
T h i sv o u
would not want.

TIONS

,.,"[]:],
The part number field
is defined as alphameric
since no entry has been
made in column 52.

W h e n u s i n gm o v e o p e r a t i o n st o c h a n g ea n a l p h a m e r i c
to a
n u m e r i cf i e l d , k e e p i n m i n d t h e k i n d o f s i g n ( p l u s
or rninus)
e a c hc h a r a c t e rw i l l g i v e y o u : a _ ( m i n u s s i g n ) ,o r J
through
R g i v e sa m i n u s s i g n ;t h e r e s t g i v e a p o s i t i v es i g n . l f y o u
are
a w a r e o f t h i s , y o u w i l l n o t g e t u n e x p e c t e dr e s u l t s . S i n c e n o
s i g n i s i n v o i v e c il n a n a l p h a m e r i cf i e l d , y o u d o n , t n e e d t o
w o r r y a b o u t t h e s i g n w h e n c f r a n g i n ga n u t n e r i ct o a n
alDha_
mericfield.

BRANCHING IN CALCULATIONS
T h e d e t a i l a n d t o t a l o p e r a t i o r r sw r i t t e n o n t h e C a l c u i a t ! o n
s h e e ta r e n o r m a l l y e x e c u t e di n t h e s a m eo r . c l ear s t h e y a r e
written. For each record selectedfor processing,the detail
o p e r a t i o n sa r e p e r f o r m e d s e q u e n t i a l l yf r o m b e g i n n i n gt o
end. lf the record selectedfor processingcausesa cf)ntrol
trreak,the total operations are performed, in the order
specified, before detail operations.
There are many times, however, when it is necessaryrnat
o p e r a t i o n sn o t b e p e r f o r m e d s e q u e n t i a l l y . F o r e x a m p l e .i n
o n e c y c l e y o u m a y w i s h t o s k i p s o m e c a l c u l a t i o n so r t o c t o
o t h e r s s e v e r atl i m e s . I n t h i s s e c t i o ny o u w i l l l e a r nt o a l t e r
the sequentiap
l r o c e s s i n go f c a l c u l a t i o n su s i n gt h e m o s t
efficientcoding.

BypassingCalculations
So far you have been bypassingoperations by the use of
i n d i c a t o r s . F o r e a c h c a l c u l a t i o nc o n d i t i o n e d b y i n d i c a t o r s ,
a check is made to see if the condition set by the indicators
is satisifed. (When severalsequential operations are condi-

: i P G C A L C U L A T I o Ns p E C l F l c A T l
oNs

r T h ep r i c es e c t i o n
of the part number

numeric field. Two
decimal places were
specified to show
the cents portion
of the field.

t i o n e d b y t h e s a m e i n d i c a t o r ( s ) ,t h e t e s t i s o n l y n r a d eo n t h e
f i r s t o p e r a t i o n . ) i f t h e c o n d i t i o n i s s a t i s fi e d , t h e o p e r a t i o n
is performed. Calculationsare bypassedor omitted when
c o n d i t i o n sa r e n o t s a t i s f i e d . W h e n b y p a s s i n gc a l c u l a t i n n s
i n t h i s w a y , t h e p r o g r a m h a s t o c h e c k t h e c o n d i t i o n ss e t f o r
the operations to determine whether or not to do them.
T h i s r e q u i r e st i m e a n d s t o r a g es p a c ei n s i d et h e c o m p u t e r .
A n o t h e r w a y t o b y p a s sc a l c u l a t i o n si s t o b r a n c h a r o u n o
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).

Frigure541.

Changing a Field by ths MOVE Operation

Two operation codes are used for branching: GOTO and
TAG. GOTO is the code which causesa branch to another
spot in the calculations. The TAG operation givesthe name
and location of the spot to which the GOTO operation
branches. GOTO causesa branch; the TAG code does
nothing but act as a nametag.

5.36

N E X T i s f o u n d . N E X T i s t h e n a m eo f t h e T A G s t a t e m e n t .
Any operationsbetweenthe GOTO statementand the TAG
statement(thosespecifiedin lines03-05)areskipped.TAG
doesnothing,so the next operationperformedis the SUB
i n l i n e0 7 .
instruction

Figure5-42,insertB, showshow GOTO arrdTAG arespecifierd.GOTO signalsa branchto the spot namedin Factor2.
This namemustalsoappearin the TAG statement,where
it is enteredin Factor1. The rulesfor forminga namefor
GOTO and TAG arethe sameasthosefor formingany field
name.

lf branchingwerenot done,the threeoperationsskipped
by the branchwould haveto be conditionedby NO1 so
t h a t t h e y w o u l dn o t b e d o n ew h e n0 1 t u r n e do n . A n d , o f
course,a checkwould haveto be madein eachprogram
cycleto determineif the operationsshouldbe doneor not.

A GOTO statementcan be conditionedby an indicator,but
a T A G c a n n o t .W h e na G O T Oi s n o t c o n d i t i o n e da, b r a n c h
occursin everyprogramcycle.
I n t h e e x a m p l es h o w ni n F i g u r e5 - 4 2 ,t h e G O T Oo p e r a t i o n
i s d o n eo n l y w h e n0 1 i s o n . l f t h e c o n d i t i o ni s s a t i s f i e da,
branchis takento that point in the programwherethe same

g i l l h e l py o u
T h e r ea r em a n ys i t u a t i o nisn w h i c hb r a n c h i n w
programs.
following
The
effective
write more efficientand
a n dT A G .
u
s
e
o
f
G
O
T
O
f
u
l
l
y
t
h
e
m
o
r
e
s e c t i o nw
s ill explain

tnese
) slin
) operationsif
! o t i so n .

RPG

CALCULATION SPECIFICATIONS
!

l

P

P"eLLjo'_

c

-l

:o
9 A

Factor l

Operation

F ac\ot

d

r

"

m

l

l

l

l

I I I I I I

Comments

2
Name

Length

21 < 211
a

z
t2

6

.";r*..-L

Result Field

Indtcal0rs

b e
t ;
clf z
9

'

a192A21222324752621

t9 50 51

t a a 3 0 3 13 :

-

H,sh Low
I
ltqua

65 66

67 6a 69

7C

thlr
lrulrFl I I I
-i-l-fTTl-rTT
o
0

;f

tT

I-arTrlmr
t-f i-l-Tl-tt

r1

I

L
I

l

f

FI
Figure 542.

Bypassing Calculations by Branching Around Them

C o n t r o l l i n g O p e r a t i o n sI n A n R P G l l P r o g r a m

5-37

Branching When Different Rec(rrd Types Require
Different
Operations
W h e n d o i n g d i f f e r e n t o p e r a t i o n sf o r d i f f e r e n t r e c o r o
types,
y o u u s et h e r e c o r d i d e n t i f y i n g i n d i c a t o r s
to show what opera_
tions shr:uld be done for each rr-.cordtype read (see
Figure
5 - 4 3 ) . W h e n y o u h a v e s e v e r arl e c o r d t y p e s a n d
e a c ht y p e
r e q u i r e ss e v e r aol p e r a t i o n s ,y o u c a n s e et h a t
many conditioni n g i n d i c a t o r sa r e n e c e s s a r v .
F o r s i t u a t i o n sl i k e t h i s , y o u c a n b r a n c h d i r e c t l y
to tne set
o f c a l c u l a t i o n sw h i c h s h o u l d b e d o n e f o r t h e r e c o r d
type
j u s t r e a d . W h e n t h o s ec a l c u l a t i o n s
aredone,you can then
b r a n c h t o t h e e n d o f a l l c a l c u l a t i o n s .T h i s e l i m i n a t e s
checki n g o p e r a t i o n st o s e e i f a s e t o f t ; a l c u l a t i o n s h o u l d
be done
for the record type being processed. In fact, record
identify_
i n g i n d i c a t o r sd o n o t n e e d t o b e s p e c i f i e df o r t h e
individual
o p e r a t i o n s . F i g u r e S - 4 4 s h o w st h e r e c o m m e n d e d
branching
structure used for different recorcltypes which require
diff e r e n t o p e r a t i o n s . U s i n g t h i s s t r u c t u r en o t o n l y
m a k e sy o u r
programs more eff icient but also makes
them easierto understand and document.

RPG

Considerthe useof sucha branchingstructurein a sates
analysisprogram. Eachday the managerof a retailstore
wishesto know total cashsales,total chargesales,and total
refunds.The input file, arrangedin ascending
order by ac_
count number,containsfour differentrecordtypes:
1.

Chargerecordsrecordtotal charges
and refunds(if
a n y )f o r a p a r t i c u l aar c c o u n t .

2.

Paymentrecordsrecordany paymentsreceived.They
a r ei n c l u d e di n t h e f i l e . b u t a r en o t n e e d e di n t h i sj o b .

3.

Refundrecordsrecordany refundsmadefor an account. No cashand chargesalesweremadeby this
customer.

4.

Cashsalesrecordsrecordtotal cashsalesand cashre_
f u n d s( i f a n y ) f o r a p a r t i c u l aar c c o u n t .

CALCULATION SPECIFICATIONS

la

Card Electo

Numhr

o.*fl "_ ";::;ii",f-T-f-fl-fl
""

63 64 65 66 67 6A 69 10 71 72 13 74

These operations are
on record type 01.

on record type 02.
This operation is done
on record type 03.
These operations are
on record type 04.
This operation is
on record type 05.
These operations are
done on record type O6.

Frigure543.

Operations performed for Different Record
Types

RPG CALCULA''O

rnffir

Figure 544.

Recommended Branching Structure

C o n t r o l l i n g O p e r a t i o n sl n A n R P G l l P r o g r a m

5-39

RPG INPUTSPECIFICATIONS
IBIIL",.,..,,".,,
"",,6.!

M$ nec.rb.a,on

RPG CALCULATION
SPECIFICATIONS
IBIL^,.,"",,.^.,
".,,^.!

Md,h€ co,F...o^
Grd

Figure 5-45. SalesAnatysis Job

Electro

N!mb'

nTl_fr-r

F i g u r e5 - 4 5 .i n s e r tA , s h o w st h e i n p u t s p e c i f i c a t i o n
f osr a l l
necordtypes. Noticethe recordidentifyingindicatorsassignedto eachrecordtype.

RPG

CALCL'LATIO

-t
-t, l

I n t h e c a l c u l a t i o nas l,l c h a r g e sc,a s hs a l e sa, n d r e f u n d sa r e
t o t a l e d . l f a r e f u n di s g i v e na l o n gw i t h t h e c a s ho r c h a r g e
:sales
for an account,the amountof the refundis subtracted
from the amountof the cashor chargebeforethe cashor
,charge
is addedto the total. Figure5-45,insertB, shows
t h e c a l c u l a t i osnp e c i fc a t i o n sf o r t h e j o b . A s y o u s e e t, h e
r e c o m m e n d ebdr a n c h i n sgt r u c t u r ew a su s e d .l f a c h a r g e
r e c o r d( t y p e0 1) i s r e a d ,a b r a n c hi s t a k e nt o R O U T 0 1. C a l . h e na
c u l a t i o n s p e c i f i e idn l i n e s0 6 - 0 8a r ep e r f o r m e d T
b r a n c hi s t a k e nt o E N D ,f o r t h e r ea r en o m o r eo p e r a t i o ntso
do for that record. Branchingfor recordtypes03 and 04 is
h a n d l e di n t h e s a m ew a y a sf o r r e c o r d0 ' l. H o w e v e rw, h e na
p a y m e n rt e c o r di s r e a d( 0 2 t u r n so n ) n o c a l c u l a t i o nasr ep e r f o r m e db e c a u steh i sj o b i s n o t c o n c e r n ew
d ith payments.
T h e r e f o r ea, b r a n c hi s t a k e nt o E N D , I n t h i s w a y a l l c a l c u l a tionsare bypassed.They are not evencheckedto seeif cond i t i o n se s t a b l i s h ebdy i n d i c a t o rasr es a t i s f i e d .

ti
r i

ll

+i

rf

1.1
Figure 5-47. Branching in a Matching Records Job

Eranching in a Matching RecordsJob
Supposethat you aredoinga matchingrecordjob which req u i r e st h a t a l l c a l c u l a t i o nbse d o n ew h e nr e c o r d sm a t c h "
ca
b y M R ( s e eF i g u r e
All specification
s nb e c o n d i t i o n e d
5 - 4 6 ) ,o r G O T Oa n dT A G c a n b e u s e dt o b r a n c ha r o u n da l l
c a l c u l a t i o nwsh e nr e c o r d sd o n o t m a t c h( s e eF i g u r e5 - 4 7 ) .
I n t h i s e x a m p l eG
, O T Oi s c o n d i t i o n e d
b y N M R . W h e nr e c o r d sd o n o t m a t c h ,a l l c a l c u l a t i o nasr es k i p p e da n da b r a n c h
t o E N Do c c u r s .
RPG

CALCULATION

Branching WhenAn Errar Condition Occurs
s l l c a l c u l a t i o nwsh i c h
B r a n c h i nigs a n e a s yw a y t o b y p a s a
shouldnot be performedwhenan error occurs. Figure5'48
s h o w sa n e x a m p l eo f t h i s .

RPG

CALCULATIO

#i-

i

F i g u r e 5 - 4 8 . B r a n c h i n gW h e n a n E r r o r O c c u r s
Figure 5-46. Conditioning all Specifications by MR

C o n t r o l l i n gO p e r a t i o n sI n A n F I P Gl l P r o g r a m

541

Branching at Different

points in the progrant

W i t h i n o n e p r o g r a my o u m a y u s ea n y n u m b e r
of GOTO
and TAG operation codes. One or more GOTO
statements
m a y h a v et h e s a m en a m e ( F i g u r e5 _ 4 5 ,i n s e r t
B, lines 02,0g,
and 12l,. However, each TAG must have a different
name.
l f t w o T A G s h a d t h e s a m en a m e , y o u r p r o g r a m
would not
k n o w w h e r et o b r a n c h .

Branching at Detail and Total Ti.me
Y o u m a y b r a n c hf r o m o n e d e t a i l c a l c r , r l p t i o n
t o a n o t h e rd e _
t a i l c a l c u l a t i o no r f r o m o n e t o t a l c a l c u l a t i o nt o a n o t n e r
l l o t a l c a l c u l a t i o n . H o w e v e r ,y o u c a n n o t b r a n c h
from a det r a i lt o a t o t a l c a l c u l a t i o no r v i c e v e r s a .

lSranchingBackward
l i o f a r , y o u h a v e l e a r n e do n l y a b o u t b r a n c h i n gf o r w a r d
in
o r d e r t o s k i p s t a t e m e n t st h a t y o L rd o n o t w i s h t o p e r f o r m .
T h e G O T O s t a t e m e n tc a n a l s o b r a n c h b a c k w a r d .
In this
vvay you can go back to statementsthat were
already done
in order to do them again.
D o i n g t h e s a m es t a t e m e n t so v e r a n d o v e r a g a i ni n
one program cycle is called looping. The statements
done several
t i m e s i n o n e c y c l e , p l u s t h e b r a n c h i n gs t a t e m e n r ,
m a K eu p
the loop. Figure 5-49 shows the b,asicstructure of
a loop.
V / h e nw o u l d y o u w a n t t o b r a n c h b a c k w a r d ? S u p p o s ey o u
\ / a n t t o p r i n t o u t s e v e r am
l a i l i n g l a b e l sf o r e a c h c u s t o m e r
by using the EXCPT operation code (seeRepetitive
Output
(t=XCPT Operation) in the chapter, prr,tgrammed
Control of
Irtput and Output for an explanation of the EXCpT opera_
t i o n ) . E X C P T i s u s e dt o w r i t e s e v e r a ol u t p u t r e c o r d s
in one
p r o g r a mc y c l e . l f y o u w a n t t o p u t o u t
2 5 m a i l i n g l a b e l sf o r
Joe Aaron. you would have to write the EXCPT operation
2 1 5t i m e s - o n e t i m e f o r e a c h r e c o r d . H o w e v e r ,i n s t e a d
of
w r i t i n g E X C P T 2 5 t i m e s , y o u c o u l d u s ea l o o p . O n e E X C p T
code is specified. lt is performed and then a bacKward
branchis taken so that EXCPT will be done aqain.

L o o k a t F i g u r e 5 - 5 0 . T h e l o o p j u s t d e s c r i b e di s c o d e d h e r e .
B u t l o o k a t w h a t w i l l h a p p e n : A n E X C p T r e c o r dw i l l b e
p r i n t e d ;a b a c k w a r d b r a n c h w i l l c a u s et h e E X C p T
to be done
a g a i n ;t h e n a n o t h e r b r a n c h ,a n d a n o t h e r E X C p T . W h e n
w o u l d e x e c u t i o n o f t h e s t a t e m e n t si n t h e l o o p e n d ?
As
c o d e d h e r e ,e x e c u t i o n o f t h e s es t a t e m e n t sw o u l d g o o n
in_
d e fi n i t e l y .
Y o u w a n t t o s t o p p r i n t i n g m a i l i n g l a b e l sf o r J o e A a r o n
after
25 have been made. Therefore, you have to keep track
of
t h e n u m b e r p r i n t e d . T h i s i s d o n e t h r o u g h t h e u s eo f a
soec i a l c o u n t f i e l d w h i c h i s c o n s t a n t l y u p d a t e d t o r e fl e c t t h e
n u m b e r o f t i m e s l o o p i n g h a s o c c u r r e d . F i g u r e5 _ 5 1
shows
t h e w a y t h i s i s d o n e . A t t h e b e g i n n i n go f e a c h c y c l e ,
C O U N T , t h e f i e l d u s e dt o k e e p t r a c k o f t h e n u m b e r o f r e c _
o r d s p r i n t e d , m u s t b e z e r o . E a c ht i m e a r e c o r d i s p u t o u t ,
1 i s a d d e d t o C O U N T . C O U N T i s t h e n c o m p a r e dt o 2 5 , t h e
n u m b e r o f m a i l i n g l a b e l sd e s i r e d . W h e n C O U N T e q u a l s
2b,
c a l c u l a t i o n sw i l l b e c o m p l e t ef o r t h a t p r o g r a mc y c l e , a n d
l o o p i n g w i l l s t o p . W h e n C O U N T i s l e s st h a n 2 5 ( i n d i c a t o r
1 0 i s o n ) . a b r a n c h i s t a k e n b a c k t o t h e b e g i n n i n go f t h e c a l c u l a t i o n ss o t h a t t h e y c a n b e d o n e a q a i n .
I n t h i s e x a m p l e , 2 5 m a i l i n g l a b e l sa r e c r e a t e de a c h c y c l e ( f o r
each re;ord read). lf a different number of records are re_
q u i r e Ct o b e p r i n t e d o r p u n c h e df o r e a c h c y c l e , y o u
h a v et o
comDarethe COUNT f ield to another f ield which contains
t h e n u m b e r o f r e c o r d st o b e p u t o u t i n t h a t c y c l e
{ s e eF i g u r e

5.r2t.

RPG

Figure5-50. An Uncontrolled Loop

01

Figure 549.

5'42

Structure of a Loop

CALCULATION SPECIFIC

C A L C UL A T I O NS P E CFI I C A T I O N S
Clrd E!ecto Numb,

I o."

c

Indicatora

FesultField

:6
a z

Factor 1

Operation

t ;
d : z
7 A

glljl::Lzeie

Factor2

i <

Name

Lengtn

Comments

>211<211=2

E
z

2

r

HishlLowlEqua

7

Figure 5-51, A Controlled Loop

RPG CALCULATIONSPECI
FICATIONS
C.rd Electo Numbr

Proo'amm.,

I o."

76 11 18 79 80

t5

Pros,am ff-fft-fl
rdennf'canonl

|

|

I

|

|

l

Figure 5-52. Printing a Various Number of Records in Each Cycle

C o n t r o l l i n g O p e r a t i o n sI n A n R P G l l P r o g r a m

5-43

You can haveas many loopsin your programas you need.
Y o u c a ne v e nh a v eo n e l o o p w i t : h i na n o t h e rl o o p ( s e eF i g _
u r e 5 - 5 3 ,i n s e r A
t ).
K e e pi n m i n d ,h o w e v e rt,h a t a n u n c o n t r o l l e ldo o p i s a n e n d _
lessloop. Eachloop you createmust be controlledso that
it will beperformed
only a limirted
n u m b e ro f t i m e s ,A l w a y s
s e tu p a c o n d i t i o nw h i c hw h e nt i a t i s f i ew
d i l l c a u s el o o p i n g
t o s t o p ( s e eF i g u r e5 - 5 3 ,i n s e r tl l ) .

cycle). A subroutineis a routinethat is part of another
r o u t i n e .T h a t i s ,a s u b r o u t i n e
i s a g r o u po f o p e r a t i o ntsh a t
c a nb e u s e db y t h e m a i nr o u t i n es e v e r at il m e si n t h e s a m e
programcycle. A subroutinecanalsobe a sequence
of
operationsthat is codedonceand includedin severaldif_
ferentprograms.
Subroutines
can be usedto:
.

U S I N GS U B R O U T I N EISN C A L C U L A T I O N S
A r o u t i n ei s s o m e t h i n dg o n eo v e rar n d o v e ra g a i n "T h e c a l _
c u l a t i o n si n y o u r p r o g r a mc a n b e c a l l e da r o u t i n eb e c a u s e
t h e o p e r a t i o nasr ed o n ea g a i na r d a g a i n( o n e a c hp r o g r a m

E l i m i n a t ed u p l i c a t ec o d i n gb y p e r f o r m i n tgh e s a m ec a t _
c u l a t i o n s e v e r at il m e si n t h e s a m ep r o g r a mc y c l eo r i n
severaldifferentprograms.

o R e d u c et h e s t o r a g er e q u i r e m e n ot sf R p G l l p r o g r a m s
(seeControlling Overlay by UsingSubroutines in this
chapter).

RPG CALCULATION
SPE

F:igure5-53. A Loop Within a Loop

544

The backward branches
will be done only when
c o n d i t i o n s a r e s a t i s fi e d .

tJsingSubroutines to do the Same CalculationsSeveral
.llimes
in One Cycle

T h e a r e ai n w h i c h a l l s a l e s m e w
n o r k i s d i v i d e di n t o t h r e e
d i s t r i c t s :A , B , a n d C . S o m e s a l e s m e w
n ork in only one
d i s t r i c t . O t h e r s m a y w o r k i n p a r t so f t w o o r m o r e d i s t r i c t s .

I n m a n y o f y o u r p r o g r a m s ,t h e s a m eo p e r a t i o n ( s )m a y b e
r e q u i r e ds e v e r a tl i m e s i n o n e c y c l e : W h e n c o d i n g t h e j o b ,

F o r e a c hs a l e s m a nt ,h e i n p u t f i l e c o n t a i n sa r e c o r df o r m a t t e d a s s h o w n i n F i g u r e5 - 5 5 . T h e a m o u n t s i n t h e d i s t r i c t
f i e l d ss h o w t o t a l w e e k l y s a l e sm a d e b y t h a t s a l e s m a ni n

\ / o u c a n s p e c i f y t h e o p e r a t i o n sa s m a n y t i m e s a s n e e d e d .
T h i s o f t e n i n v o l v e sl a r g ea m o u n t s o f c o d i n g , h o w e v e r . l f
t h e s a m eo p e r a t i o n sa r e t o b e d o n e s e v e r atl i m e s i n s u c c e s .
s i o n , y o u c a n o f t e n u s e l o o p i n g t o r e d u c et h e a m o u n t o f

e a c h d i s t r i c t . l f t h e s a l e s m a nd i d n o t w o r k a d i s t r i c t o r
m a d e n o s a l e si n t h a t d i s t r i c t . t h e f i e l d c o n t a i n sa z e t o .

c o d i n g . T h i s w a s e x p l a i n e di n t h e p r e v i o u ss e c t i o n .
T h e r e p o r t m u s t c o n t a i n t h e c o m m i s s i o ne a r n e di n e a c h d i s t r i c t b y e a c hs a l e s m a n .I n a d d i t i o n ,t o t a l c o m m i s s i o nm u s t

l V h a t i f t h e s a m eo p e r a t i o n sa r e n o t d o n e s e v e r a tl i m e s i n
s u c c e s s i o nb, u t a r e p e r f o r m e d ,i n s t e a d ,a t m a n V d i f f e r e n t
p o i n t s i n y o u r p r o g r a m ? C r e a t i n ga l o o p c o u l d n ' t w o r k i n
t h i s c a s e . A s a n e x a m p l e ,c o n s i d e rt h e j o b w h i c h c r e a t e sa

b e a c c u m u l a t e df o r e a c h s a l e s m a na n d f o r e a c h d i s t r i c t . T h e
p e r c e n t a g eo f c o m m i s s i o ni s :

w e e k l y s a l e sc o m m i s s i o nr e p o r t . T h e r e p o r t d e s i r e d( F i g u r e 5 - 5 4 ) s h o w st w o t h i n g s :
1.

.

3 p e r c e n to f t h e g r o s ss a l e s. 0 1 t o 10 0 0 . 0 0 d o l l a r s .

o P l u s2 p e r c e n ot f t h e g r o s ss a l e s1 0 0 0 . 0 1t o 5 0 0 0 . 0 0
dollars.

T o t a l c o m m i s s i o ne a r n e db v e a c h s a l e s m a n .

2 1 . . T o t a l c o m m i s s i o n sp a i d i n e a c h d i s t r i c t

o P l u s 1 p e r c e n to f t h e q r o s so v e r 5 0 0 0 . 0 0 d o l l a r s .

C O M M I S S I O NR E P O R T

Salesman

Dist A

Joe Arness

41.93

Dist B

Bob Brown
C h a r l e sB u t l e r

26,98

Dist C

Total

23.16

9.43

74.52

11 3 1. 6

24.93

138.@

449.16

109.38

585.52

lFigure 5-54. Sales Commission Report

SALESMAN

DIST
A

2 3 4 5 { i 7 A 9 r 0 r 1 r ? 1 l ' 4 r 5 1 6 , t t 1 9 2 t ? 1 2 2 2 1 2 r4 ?1 i 2 8 : ! : 0 3 t i

DIST
B
I li

l : - 1 6- l i l 3 l

DIST
ll414?.3414i4

\
) 4 84 35 C5 r 5 : 5 i 5 ! 5 55 6 5 ; 5 3 5 96 1

Figure 5-55. Input Record for SalesCommission Report

C o n t r o l l i n gO p e r a t i o n sI n A n R P G l l P r o g r a m

5-45

F i g u r e 5 - 5 6 s h o w st h e c a l c u l a t i o , nnse t r t J e tdi ; l i i r c j r . l r ej r i f o r mation required for the report. you first compare uie cori_

l J s i n gt h e b r a n c h i n yEo u h a v el e a r n e da b o u ts o f a r , t h e
L r r a i r c h i nt hga t u s e sG O T Oa n d T A G , y o u c o u l de a s i l y
L r r ' a r crho t h e c e l c u l a t i o nnse e d e dt o f i n d c o m m i s s i o nB. u t
sinceyou co,.rldbranchto them from threedifferentplaces,
i t w o u l d b e d i f { i c u l tt o d e t e r m i n et o w h i c hp o i n t i n t h e
c a i c u l a t i o nyso u s h o u l dr e t u r n . Y o u c o u l dr e t u r nt o t h e
point wheretotalsareaccumulated
for districtA, the point
t h u y a r ea c c u m u l a t efdo r d i s t r i c tB , o r t h e p o i n t t h e y a r e
a c c u m u l a t efdo r d i s t r i c tC . l m a g i n et h e n u m b e ro f i n d i c a t o r sa n d S E T O Na n dS E T O Fo p e r a t i o nnse c e s s a troy d o
t h i s . W o u l d n ' ti t b e n i c ei f t h e p r o g r a mw o u l c aJ u t o m a t i c a l l y
go backto the point from which it branched?

t e n t s o f e a c hd i s t r i c t f i e l d t o z e r o t o f i n d o u t i f t h e s a i e s m a n s o l d a n y t h i n g i n t h a t d i s t r - i c ; tl.f i t i s r . r o tz e r o ,
vou caic u l a t e t h e c o m m i s s i o n( C O M M ) e a l n e d . y o u t h e n a c j dc c l n l ,
mission earned to total commission for the salesrnan
(MANTOT) and to total cornmi:rsionpaid
in each district

(TOTALA.TOTALB,
or T0TAt_C).

T h ec a l c u l a t i o nnse e d e dt o f i n d r t o t n m i s s i oena r n e da r et h e
' s a m feo r e a c hd i s t r i c t( F i g u r e
b - 1 1 6i n, s e r t sA , t s ,C , l i n e s
, 3 - 1 6 )W
. h Vc o d et h e s ec a l c u l a t i o nt si r r e et i n r e s ?W h y n o t
codethem onceand branchto therneachtime thev are
n e e d e d ?( S e eF i g u r eF - 5 7 . )

I
I IBM

I r- ---

RPG

R P Gl l c a nd o t h i s t h r o u g ht h e u s eo f a s u b r o u t i n ey. o u r
e n t i r ep r o g r a mi s t h e m a i nr o u t i n e .T h e o p e r a t i o ntso b e
performedseveraltimes in the programcyclemakeup a
s u b r o u t i n e I. n t h l s c a s et,h e m a i np r o g r a mu s e st h e s u b r o u t i n et o f i n d c o m m i s s i oena r n e d .

CALCULATION SPECIFICATIONS

I l P-q -, a m
r r
I 1j1.1"..":

"usne$M6chnecjroo,a,ctr

' - T

|

-

i| u-' " - "f

tpare

r

-;.-r

L

r

I

l

. . ,
n
t

,

I

I

--t'- --

_ r

- f
,
l

I - r

T

i

r - '
'

i

t

|

a z
:i<

i-,c.,".-,.i^*.1

. 1 . - l
,
l
r
.
.

L
L

Result Field

|

I

Factor 2

I
I

5El'6

rlane

I

6l

i
i i lr-

t l -

-]
r1

fl
ll

ti

i

1
J

:tii + l

Figure 5-56 (Part 1 of 2), Calculations for Sales Commission
Frogram

5.46

For6 GX2r 993
Pnnrdrn

","..,,,,.

i l

I
J

I

l
_

l
_

-

/5

l
l

/6

17

P,os,am TffffT_l
""*i-11.,
ldenrinc.(onl

I

us.a

18

|

19

|

80

|

l

t3l
L enqtF

ifl!
l - .t :
t;l:

t-i
Li
I
I t i+
Pr@,am TT
taenrrcatonLl

T T-T-TI
|

|

|

I

I

Calculations
required to find
c o m m i s s i o ne a r n e d .

Figure 5-56 (Part 2 of 2). Calculations for Sales Commisr'.

ot'rgram

C o n t r o l l i n g C J p e r a t i o n Isn A n R P G l l P r o g r a m

5-47

RPG CALCULA-

Not this:

District A

(
,calculate

cornmission
1
Actumulatetotals
District B

(

j cahulate.
cornmtssron
I
Accumulatetotals
District C
calcu late
conrmission
Accumulate totals

But this:

DistrictA
o"".r,',.u*-\",oa",,
=\i\
Di.tri"tB
Accumutaie-i6'ill
/---/
-r'
District
"
.ra-

Figure 5-58. Structure of a Subroutine

Calcu late
Commission

Accumulate totals

Firgure5-57. Branching to Similar Calculations

Sptecificationsfor Coding a Subroutine
s u b r o u t i n eas r es p e c i f i e o
d n t h e c a r c u r a t i osnh e e a
t f t e ra r l
detailand total operations.Everystatementin
the sub_
routinemust be identifiedas part of the subroutine
by the
l e t t e r sS R i n c o l u m n s7 - g . ( S e "F i g u r e5 _ S g . )
In addition,
two operationcodes,BEGSRand ENDSR,are
neededto
e s t a b l i sthh e b e g i n n i nagn d e n do f t h e s u b r o u t i n e .
E v e r ys u b r o u t i n e
u s e di n t h e p r o g r a mm u s th a v ea u n i q u e
n a m e .T h e r u l e sf o r f o r m i n ga s u b r o u t i n n
e a m ea r et h e
sarneasthosefor forminga field name. The name
must
appearin Factor1 on the samelineras the BEGSR
operation code.

548

Calling the Subroutine
WhenusingGOTO and TAG, you usea GOTOoperation
codeto branchto the next operationto be performed.
W h e ny o u d o t h e o p e r a t i o nisn a s u b r o u t i n ey,o u d o n o t
branchto the subroutine;you cal/ it.
W h e ny o u c a l la s u b r o u t i n ey,o u u s et h e e x e c u t es u b r o u t i n e
( E X S R )o p e r a t i o nc o d e . T h i so p e r a t i o nc o d e
c a nb e p l a c e d
a n y w h e r ei n t h e c a l c u l a t i o o
n p e r a t i o n sW
. h e n e v et h
re
E X S Ro p e r a t i o nc o d ei s e n c o u n t e r e a
d l, l o p e r a t i o nisn t h e
subroutinw
e i l l b e p e r f o r m e d .A f t e r t h e s u b r o u t i n e
has
beenexecuted,RPG ll branchesbackto the marnprogram
and continuesexecutionwith the next statementafter the
E X S Rs t a t e m e n(tF i g u r e5 - 5 g ) .
Factor2 must containthe nameof the subroutineto be
executed.This samenamemust appearon a BEGSR
instruction.

Pageof GC21 -7567-2
l s s u e d2 4 M a y 1 9 7 6
By TNL: GN21-5389
Main Program

Subroutine

Fields Used in a Subroutine
T h e s a m ef i e l d s c a n b e u s e d b y b o t h t h e s u b r o u t i n ea n d t h e
m a i n r o u t i n e . Y o u m a y d e fi n e t h e f i e l d i n e i t h e r r o u t i n e .
H o w e v e r ,t h e n a m e a n d c h a r a c t e r i s t i cosf t h e f i e l d m u s t b e
t h e s a m ei n b o t h r o u t i n e s .

EXSR

T h e f i e l d s y o u d e f i n e i n a s u b r o u t i n es h o u l d b e g e n e r a ls o
t h a t t h e y a p p l y t o a l l s i t u a t i o n sf o r w h i c h a s u b r o u t i n ei s
u s e d . F o r e x a m p l e ,i f D I S T A i s u s e d a s t h e f i e l d n a m e i n a
s u b r o u t i n et o c a l c u l a t ed i s t r i c t s a l e s y, o u a l w a y s t a k e i n f o r m a t i o n f r o m t h e D I S T A f i e l d w h e n c a l c u l a t i n gc o m m i s s i o n . H o w e v e r ,y o u w a n t t h e r o u t i n e a l s o t o h a n d l e i n f o r m a t i o n f r o m t h e f i e l d s D I S T B a n d D I S T C . U s i n gs p e c i f i c
f i e l d s l i m i t s t h e c o r r e c t u s e o f a s u b r o u t i n et o o n e s i t u a t i o n .
F i g u r e 5 - 5 9 . E X S R ( O r d e r i n W h i c h C a l c u l a t i o n sa r e P e r f o r m e d )

I n s t e a d ,i f y o u u s e a g e n e r a lf i e l d n a m e s u c h a s S A L E S . t h i s
o n e s u b r o u t i n ec a n b e u s e dt o c a l c u l a t ec o m m i s s i o ni n a l l
t h r e e d i s t r i c t s ( F i g u r e 5 - 6 0 , i n s e r t C ) . H o w e v e r ,b e c a u s e
t h e r e i s n o i n p u t f i e l d c a l l e dS A L E S , y o u s h o u l d u s et h e
Z A D D o p e r a t i o n c o d e t o p l a c ei n f o r m a t i o n i n t h i s f i e l d
( F i g u r e5 - 6 0 , i n s e r t B ) . T h e i n f o r m a t i o n i n t h e a p p r o p r i ate districtfield (DlSTA, DISTB, or DISTC) is moved into
t h e f i e l d c a l l e dS A L E S b e f o r e t h e s u b r o u t i n ei s e x e c u t e d .
W h e n f i n d i n g c o m m i s s i o ne a r n e di n d i s t r i c t A , D I S T A i s
m o v e d i n t o S A L E S ; w h e n f i n d i n g c o m m i s s i o ne a r n e df o r
district B, DISTB is moved into SALES, etc. In this way,
y o u e n s u r et h a t t h e s u b r o u t i n eu s e st h e c o r r e c t i n f o r m a t i o n
e a c ht i m e i t i s c a l l e d .

RPG

INPUTSPECIFICATIONS
1

2

7 5 t 6 1 7 1 8 1 9 a O

P r e L - f ]' I .

P'^.,,r r-rTfI_n
rr
""."'*'-Ll I

r

f ield Localion

6
!
a

-

F i g u r e 5 - 6 0 ( P a r t 1 o f 4 ) . S a l e sC o m m i s s i o n P r o g r a m ( U s i n g a S u b r o u t i n e )

C o n t r o l l i n gO p e r a t i o n sI n A n R P G l l P r o g r a m

5-49

R P G C I \ L C U L A T I O N S P E C FI I C A T I O N S

Figurer5-60 lPart 2 ol 4). Sales Commissio,nprogram (Using
a Subroutine)

Using Subroutines in the Sales Commi:sion
Report Example
N o w t h a t y o u h a v e l e a r n e dh o w s u b r o r _ r t i n e s
a r e u s e d ,d e f i n e d , a n d e x e c u t e d ,s e eh o w t h e y a r e u s e d
i n t h e s a l e sc o m m i s s i o r lr e p o r t p r o g r a m . A l r s p e c i f i c a t i o n s
areshown in Figure
5-60.

T h e s u b r o u t i n ei s c a l l e d b y t h e E X S R o p e r a t i o n
cooe.

4.

T h e c o m m i s s i o ni s c a l c u l a t e db y o p e r a t i o n ss p e c i f i e d
in the subroutine.

5.

T h e s u b r o u t i n ei s f i n i s h e dw h e n E N D S R s t a t e m e n t
is
e x e c u t e d . T h e i n s t r u c t i o nf o l l o w i n g E X S R i s e x e _

F i r s t a r e c o r d i s r e a d . N o w c o m m i s s i o re
r a r n e di n e a c h d i s trict must be calculated
1.

2.

5-50

D I S T A i s c o m p a r e dt o z e r o t o s e r :i f t h e
s a t e s m a ns o l d
anything in that district. lf the field is greater
than
z e r o , c o m m i s s i o nm u s t b e c a l c u l a t e d . l f
the f ield is
z e r o ,a b r a n c hi s t a k e n t o B , w h e r e a n o t h e r
compari_
s , c ni s m a d e .
B e f o r e t h e s u b r o u t i n ec a n b e c a l l e d ,i t m u s t
be sup_
plied with the correctamount of
s a l e s .T h u s , t h e c o n tentsof DISTA aremoved into Sr\LES.

c u t e d . T h e c o m m i s s i o nf o u n d b y t h e s u b r o u t i n ei s
a d d e d t o t h e t o t a l c o m m i s s i o ne a r n e db y t h e s a r e s m a n ( M A N T O T ) a n d t o t h e t o t a l c o m m i s s i o np a i d
in
the district (TOTALA).
o.

N o w D I S T B i s c o m p a r e d t o z e r o t o s e ei f c o m m r s s i o n
e a r n e ds h o u l d b e c a l c u l a t e d . l f s o , i n f o r m a t i o n f r o m
the f ield DISTB is movedto SALES, and the sub_
r o u t i n e i s c a l l e d . T h e n e x t s t e p sa r e b a s i c a l l yt h e
sam_.
a s t h o s e a l r e a d yd e s c r i b e d . F o l l o w t h e r e s t o f t h e p r o _
gram.

RPG

F o r mG x 2 1 - $ 9 3
P r L n l a' dn U . SA

CALCULATION SPECIFICATIONS

**ii"

75 76 77 78 79 80

r-T-r-r--T-l
t
t
t
t
t

l

r

t

t
l

l
l

F i g u r e 5 - 6 O ( P a r t 3 o f 4 ) . S a l e sC o m m i s s i o nP r o g r a m ( U s i n ga S u b r o u t i n e )

C o n t r o l l i n gO p e r a t i o n sI n A n R P G l l P r o g r a m

5-51

RPG
l

t

r'''n"'q

J

r| o , ' "

t

i

|

OUTPUT

*

,nnF,nn

*

^

I
|^

L'rrr'h
-

"

SPECIFICATIONS

ltH+

T r i
|

T
- ft t
r

|

cx?t 9mo u/M oao.
P n n r r d , nu 5 ^

._i,dErf,i, N,rn,rrr
a

_

l

I

I

t 5 1 6 7 i 1 a r c a o

"*[Tl'--r d " . , , i c , , ' ,t. Ll 1 l _ l
Prorram

f-TT-I-fl

O u t D u tI n d i c a t o r s

r";""
Pros siqn
t,r.kl rd,1

:*"
ilp1:t

l

l

-l
]
]

I
I

Figure 5-60 (Parr 4 of 4). Sales Commission program
(Using a Subroutine)

Using Valid Subroutine Operations

3.

A n y o p e r a t i o nc o d et h a t c a nb e u s e di n c a i c u l a t i o n s
c a nb e
u s e di n a s u b r o u t i n e x c e p tB E G S FaI n d E N D S R .
This
m e a n st h a t y o u c a nu s ea l l a r i t h m e t i cc, o m p a r e
a n dt e s t i n g ,
movelook-Llp,EXSR,and branchirrg
operations.
T h r : r ea r ei i r n i t a t i o nosn s o m eo f t h e o p e r a t i o n s :
1.

You may only branchto anotherstatement
in the sub_
routine when usingthe GOTO statement(Figure
b-61,
insei"tA).

2.

You rnay branchto the ENDSiRstatement you put
if
a n a r n ei n F a c t o rI o f t h e E N D S Rs t a t e m e n r "

You may not branch to a statement outside
of the
s u b r o u t i n e( F i g u r e 5 - 6 1 , i n s e r t B ) .
You cannot branchto a TAG within the subroutine
f r o m a G O T O o u t s i d eo f t h e s u b r o u t i n e( F i g u r e
5-61.
i n s e r tC ) .

5.

Y o u c a n n o t h a v ea s u b r o u t i n ec o d e d w i t h i n a n o t n e r
s u b r o u t i n e . H o w e v e r ,o n e s u b r o u t i n ec a n c a l l a n o t h e r
s u b r o u t i n e . T h i s m e a n st h a t w i t h i n o n e s u b r o u t i n e
y o u r n a y h a v ea n E X S R s t a t e m e n t( F i g u r e
5_62). A
subroutine, however, cannot call itself and cannot
call
t h e s u b r o u t i n ew h i c h c a l l e d i t .

NOT THIS:

U s ea G O T L Ts t a t e m e n t

F i g u r e 5 - 6 1 . E l r a n c h i n gW i t h i n a S u b r o u t i r i r

'rooriril,

5 5i

P a q eo f G C 2 1 : 1 5 6 7 - 2
l s s u e d3 0 J u n e 1 9 7 8
By TNL: GN21-5616
RPG

IISM

L1l"l
I| '';";;
"" ''-

,
Lit:

I

lorlolll'"

CALCULAI
: '

f

l t -

L

L

;
a
j

-

Conditioning Subroutine Staternents
A n y i n d i c a t o rw h i c h i s v a l i d i n c o l u m n s9 - 1 7 c a n b e u s e d
t o c o n d i t i o n a n o p e r a t i o nw i t h i n t h e s u b r o u t i n e . T h a t
o p e r a t i o nw i l l t h e n b e p e r f o r m e d o n l y w h e n t h e c o n d i t i o n s
e s t a b l i s h e db y t h e i n d i c a t o r sa r e s a t i s f l e d "T h e B E G S R a n d
E N D S R o p e r a t i o n c o d e , h o w e v e r ,c a n n o t b e c o n d i t i o n e d
by any indicators.

6

T h e E X S R s t a t e m e n tc a n a l s o b e c o n d i t i o n e d b y i n d i c a t o r s .
l n t h i s c a s e ,t h e e n t i r e s u b r o u t i n ew i l l b e p e r f o r m e d o n l y
w h e n c o n d i t i o n sf o r t h e E X S R s t a t e m e n ta r e m e t . F o r e x a m p l e , i n F i g u r e 5 - 6 3 , i n s e r tA , t h e s u b r o u t i n ew i l l b e p e r f o r m e do n l y i f M R i s o n .
C o n t r o l l e v e l i n d i c a t o r sc a n n o t b e u s e dt o c o n d i t i o n s t a t e m e n t sw i t h i n a s u b r o u t i n es i n c eS R m u s t a p p e a ri n c o l u m n s
7 - 8 . T h e i n d i c a t o r su s e do n t h e E X S R s t a t e m e n td e t e r m i n e
w h e t h e r t h e e n t i r e s u b r o u t i n ei s p e r f o r m e da t d e t a i l t i m e
o r a t t o t a l t i m e ( F i g u r e5 - 6 3 , i n s e r tB ) .

Itl

1il
I i -

iir
t]l

RPG II LINKAGE EDITOR
T h e o u t p u t o f t h e R P G l l c o m p i l e rb e c o m e si n p u t t o t h e
l i n k a g ee d i t o r ,w h i c h b u i l d st h e l o a d ( o b j e c t )m o d u l ef o r
l a t e r e x e c u t i o n . T h e m o d u l e c a n b e c a t a l o g e di n t o t h e
l i b r a r y , p u n c h e d i n t o c a r d s ,o r w r i t t e n t o d i s k e t t e .
RPG

CALCULAT

l;";; T

-f

ir-rri l

T h e l i n k a g ee d i t o r c o m b l n e st h e t r a n s l a t e dR P G l l s o u r c e
c o d e w i t h t h e s y s t e m l i b r a r y m o d u l e sn e c e s s a r tyo c o m p l e t e
t h e p r o g r a m . T h e m a p o f t h e l i n k a g ee d i t o r ' s o u t p u t i s
p r i n t e df o l l o w i n gt h e c o m p i l e rd i a g n o s t i cm e s s a g e(si f
p r e s e n t ) . T h e m a p a l s o i n d i c a t e st h e a m o u n t o f i n t e r n a l
s t o r a g eu s e db y p o r t i o n s o f a p r o g r a m .
T h e R P G l l c o m p i l e ru s e do n M o d e l s4 , 6 , 8 , 1 0 , o r 1 2
i n c l u d e si t s o w n l i n k a g ee d i t o r ,c a l l e dt h e R P G l l L i n k a g e
'l
E d i t o r . O n M o d e l 5 , t h e R P G l l c o m p i l e r u s e st h e o v e r l a V
l i n k a g ee d i t o r t h a t i s p a r t o f t h e S C P . T h e f o l l o w i n g r e f e r s
t o t h e R P G l l L i n k a g eE d i t o r ,a l t h o u g hc o n c e p i u a l l yi,t i s
i d e n t i c a lt o t h e o v e r l a y l i n k a g ee d i t o r .

0

c 4
0

5

c

6

0

7

iil

I,rl

o 8 ,
I
0 9

,;l i;

it+i,
fi i
+ 1 +

Figure5-62. Using EXSR Within a Subrr:urine

5-5tl

P a g eo t G C 2 1 - 7 5 6 7 - 2
l s s u e d3 0 J u n e 1 9 7 8
By TN L: cN21-5616
RPG

tr-l.. I

C A L C U L A T I O NS P E C I F I C A T I O N S

;;;,
i;;
r ' , ' , " , , r " ,i ^

L:T-

i

I I

1-

illL-

I

Operatiof

I f m'i;;;u;;1

l

,"'.
ii.,- :r:;r.,
"L-lIl-l-i1

Factot 2

(:
C;

S U B A w i l l b e e x e c u t e da t d e t a i l
time if MR is on.

!:
t

S U B A w i l l b e e x e c u t e da t t o t a l t i m e .
i | 'ir-

F i g u r e 5 - 6 3 , C o n d i t i o n i n g C a l c u l a t i o n sW i t h i n a S u b r o u t i n e

L i n k a g eE d i t o r M a p
F i g u r e5 - 6 3 . 1i l l u s t r a t etsh e i n f o r m a t i o na v a i l a b t o
en tne
R P G l l L i n k a g eE d i t o r m a p .
T h e S t a r t A d d r c o l u m n g l v e st h e p h y s i c a ll o c a t i o n r n
s t o r a g eo f e a c h m o d u l e . F i g u r eb - 6 3 . 1 s h o w st h e m o d u t e s
i n a s c e n d i n gs e q u e n c eb y a d d r e s s( w h i c h m a y r r o t a l w a V sb e
t h e c a s e ) . T h e r o o t s e c t i o n i n d i c a t e st h e b e g i n n i n go f t h e
p r o g r a mj u s t a f t e r t h e s y s t e ms u p e r v i s o r( 0 E 0 0 , i n t h i s
c a s e ) . T h e r o o t s e c t i o ni s 1 , 0 0 0 h e x a d e c i m a b
l y r e sr o n g
( s e eC o d e L e n g t h c o l u m n ) ; t h e r e f o r e ,t h e n e x t a v a i l a b l e
l o c a t i o n i s 1 E 0 0 . N o t e t h a t t h e n e x t h i g h e ra d d r e s si n t h e
e x a m p l ei s 1 E 0 0 i o r t h e i n p u t m a i n l i n es e c t i o n .
Start
Addr

0E00
1E00
1F 0 0
2000
2050
2060
2080
2100
2150
zzcu
z+5u

Name if
Ovarlay

Code
Length

Name

Title

1000
O100
0100
0050
O010
0020
0080
0050
0100
0200
0800

RGROOT
RGMAIN
RGSUBS
RGSUBS
RGSUBS

Roor
InputMaintine
R e c o r dl D
Inpur ctrt rtn
Subses
5 4 4 4 c o n s e ci n o u t
Input fietds
D e t a i tc a t c s
Lokup routine
D e t a i to u t p u t
Constants

$$CSIP
RGMAIN
RGMAIN
$$PGLC
FGMAIN
RGSUBS

T h e C o d e L e n g t h c o l u m n g i v e st h e s t o r a g er e q u i r e m e n t s
i n h e x a d e c i m a l .T h e N a m e c o l u m n g i v e st h e n a m e o f
s y s t e m ( a n d u s e r ) m o d u l e sa n d d e s i g n a t e tsh e c o m p i l e r c r e a t e ds e g m e n t s( w h i c h b e g i nw i t h R G ) . T h e f u n c t i o n s
o f m o d u l e sa r e d e s c r i b e d ,w h e r e p r a c t i c a l .i n t h e t i t l e
column.
T h e r o o t s e c t i o n c o n t a i n s l / O b u f f e r s ,c o n s t a n t s ,a n d
v a r i a b l e rse q u i r e dt o r u n R P G l l p r o g r a m s .S u b s e gi s a
s e c t i o nt h a t h a s f u n c t i o n s t h a t a r e n o t e a s i l yd e s c r i b a b l e
b y t h e c o m p i l e r . F o r e x a m p l e ,a c a l c u l a t i o ns u b r o u t i n e
i s c a l l e da s u b s e g .
T h e R G M A I N s e c t i o n sa r e t h e b a s i cR P G l l f u n c t i o n s ,
s u c h a s i n p u t , d e t a i l c a l c u l a t i o n st,o t a l o u t p u t , a n d s o o n .
R G S U B Sd e s i g n a t efsu n c t i o n sw i t h i n t h e R G M A I N
f u n c t i o n s . T h e m o d u l e sa r e l i s t e d i n f u n c t i o n a l s e a u e n c e :
t h e s u b s e c t i o n sf o l l o w t h e m a i n f u n c t i o n . I n F i g u r e b - 6 3 ,
t h e l o k u p r o u t i n e f o l l o w s t h e d e t a i l c a l c ss e c t i o n o e c a u s e
a table look-up was performedin detail calculatrons.
S i m i l a r l y ,t h e c o n s t a n t ss e c t i o n ,b e c a u s ei t f o l t c w s t h e
d e t a i l o u t p u t s e c t i o n ,w a s d e f i n e d o n t h e o u t p u t
s p e c i f i c a t i o nf so r d e t a i l ( o r h e a d i n g )l i n e s .

F i g u r e5 - 6 3 . 1 . L i n k a g eE d i t o r M a p

C o n t l o l l i n q ( J p e f a l i o n sl r r A r R P G l l i r r o g r a n r

5-55

Paseof GC21-7567-2
lssued30 June1978
ByTNL: cN21-5616

SimpleOverlays
An overlaystructurebeginsif the load (object)module
b u i l t b y t h e l i n k a g ee d i t o ri s l a r g e trh a n t h e a v a i l a b lm
e ain
(the
on
H-card
or
storagein a machine
sizeis specified the
for
used
compilation).
is assuined
to be that of the machine
The linkageeditor beginswith low-usage
modulessuchas
e x e c u t i o nt i m e t a b l ed u m p a n d l o a dr o u t i n e sf.i l e o p e n
a n dc l o s e ,L R c a l c u l a t i o nasn d o u t p u t ,a n ds o o n . l t
allocatesan overlayfetch arealargeenoughto hold the
largestof the selectedroutines{or groupsof routines)and
callsfor an overlayfetch routine,which will load into that
overlayareathe selectedroutinesas they are needed.The
overlayis
overlayfetch routinechecksto seeif a requested
alreadyin the overlayareabeforegoingto the disk library
to load it. This actionsavestime by avoidingunnecessary
loadsfrom disk.
With overlays,the root sectionoccupiesthe lowestposition
in storageas before. lt is followedby the overlayfetch
routin€. The overlayfetch areacomesnext, followed by
the secondaryroot routine,or root 2. Root 2 is madeup
of thoseroutinesthat do not haveto be overlaid.

Code
Length

Name

0E00
1E00

1000
0100

1F 0 0

0700

2600
2700

0100
0100
0200
0040
0600
0020
0010

RGROOT Root
RGSUBS Overlayfetch
routine
RGSUBS Overlayfetch
area
R G M A I N I n p u tm a i n t i n e
R G M A I N I n p u tf i e t d s
RGMAIN
Derailcalcs
RGSUBS Constants
RGMAIN
Total catcs
RGSUBS Constants
RGSUBS Exceotion

Start
Addr

1Foo
2100
1Foo
2500
2s2o

Name if
Overlay

$*#bor
$*#fuor
$*4fu02
$ffioz
$*ttroz

Figure 5-63.2. Storage Map

Overlay
Name

Relative
Start C/T/S

$*4fu0t
$*#ooz
$4#bos
$*tfboa

00
00
00
00

00
01
01
01

Figure5-63,3. Library Map

All the overlaidroutinesaregivennu.., fn the Nametf
Overlaycolumn. The namesare$*#nnnlwhere nnn is
a t h r e e - d i go
i t v e r l a yn u m b e r .
Figure5-63.2showsa storagemap of a programand
Figure5-63.3showsa librarymap of the sameprogram.
Figure5-63.4is a diagramthat illustratesthe mapsshown
s - 6 3 . 1a n d 5 - 6 3 . 2 .T h e l i b r a r ym a p i n d i c a t etsh e
in Figure5
overlaysizein the # Text Sectorscolumn. You canseein
Figure5-63.3that overlay#2l$##A02l, is the largest,
occupyingsevensectors;this is equivalentto 0700 bytesin
(all storagerequirements
hexadecimal
will be statedin four
hexadecimal
digits). The storagemap showsthe overlay
fetch areaof 0700 bytes. lt alsoindicatesthat overlay
and is actuallyonly
#2 containsthe total calculations
0630 byteslong (0600for total calcs,0020for constants,
and 0010 for exceptionoutput). Therefore,averlayffi.
occupiessevensectors:six arefrrll and the seventhhasonly
0030 bytesof code in it. lf the userwantsto reducethe
sizeof the program'soverlayarea,he would f irst try to
reducethe sizeof total calculations.

5-56

Title

16
02
0A
11

#Text
Sectors

Start
Address

03
07
06
04

1F00
1F00
1F00
1F00

P a g eo f G C 2 1 - 7 5 6 7 - 2
lssued
3 0 J u n e1 9 7 8
B y T NL : G N 2 1 - 5 6 1 6

Root

OverlayFetch Routirre

S;:o03

$in002
Overlay
Fe t c h
Area

F i g u r e 5 - 6 3 . 4 . D i a g r a mo l L i n k a g e E d i t o r M a p a n d S r o r a g eM a p

The Relative Start C/T/S column gives relative library
l o c a t i o n si n c y l i n d e r , t r a c k , a n d s e c t o r f o r t h e o v e r l a y s .
T h i s i n f o r m a t i o n d o e s n o t p e r t a i n t o t f r i sd i s c u s s i o n .

Special Open
Sometrmea
s s t o r a g em a p w i l i n o t l i s t a n o v e r l a y# 1 b u t w l l l
h a v e o t h e r o v e r l a y ss t a r t i n gw i t h $ # # 0 0 2 . T h i s i n d i c a t e s
t h a t t h e s p e c i a lo p e n h a s b e e r "i rm p i e m e n t e d . T h e u s e r
c a n n o t d i r e c t l y c a u s et h i s t o h a p p e n . T h e l i n k a g ee d i t o r
p r o v i d e st h i s f e a t u r ew h e n i t r e d u c e sa p r o g r a m ' ss t o r a g e
r e q u i r e m e n t s .S p e c i a lo p e n d o e s n o t a f f e c t t h r o u g h p u t .
W h e n t h e o p e n / c l o s eo v e r l a y i s t h e l a r g e s to n e , s p e c i a l
o p e n i s i m p l e m e n t e d ,r a t h e r t h a n h a v i n gt h a t c o d e i n c r e a s e
t h e s t o r a g er e q u i r e df o r t h e r e s t o f t h e p r o g r a m . S p e c i a l
o p e n c a u s e ss o m e o f t h e u n o v e r l a i dc o d e i n r o o t 2 t o
o v e r l a yt h e o p e n r o u t i n e a f t e r t h e f i l e s h a v e b e e n o p e n e o ;
i t o v e r l a y ss o m e o f r o o t 2 w i t h c l o s ea t e n d - o f- j o b .

Overlay Starting Addresses
A s t h e m a p s i n F i g u r e5 - 6 3 . 5s h o w , t h e r e a r e t w o s t a r t i n g
a d d r e s s efso r o v e r l a y s . T h e m a i n s t a r t i n ga d d r e s sf o r t h e
i l l u s t r a t i o ni s 1 F 0 0 . T h e s t a r t i n ga d d r e s sf o r t h e s u b o v e r l a y
i s a l w a y s h i g h e r ; i n t h i s c a s e ,i t i s 2 3 0 0 .
Storage Map
Start
Addr

Name if
Overlay

Code

1Foo
21oO
22oo
2300

$+4fu02
$lifrooz
gffis2
$##003

0200
0100
0002
0100

$$PGRI

2400
2300

$+Ffr003
$#+tu04

0 10 0
0300

RGSUBS
RGSUBS

Name

Tirle

RGMAIN
RGSUBS
RGSUBS

Detailcalcs
T r a n s f e rv e c t o r
Conranrs
R e s e tR e s u l t i n g
indr
Subseg
Exception

Length

Library Map
Overlay
Name
o+ffiuu I
i+FfrJV

Z

$*4fu04
o+fiuu4

$*fhos
$+qb06

Relativo
Start C/T/S

#rext
Sectors

Start
Address

ol
o4
o2
03
03
o4
o2

1F 0 0
1F 0 0
2300
2300
1F 0 0
2300
2300

F i g u r e 5 - 6 3 . 5 . S t o r a g ea n d L i b r a r y M a p s

C o n t r o l l i n gO p e r a t i o n sI n A n R P G l l P r o g r a m

5-56.1

P a g eo I G C 2 1 - 7 5 6 7 - 2
l s s u e d3 0 J u n e 19 7 8
B v T N L : G N 2 ' l- 5 6 1 6

$ # + f 0 0 2 i s a m a i n o v e r l a y w i t h s u b o v e r l a y s .T h e r e a r e t w o
i n d i c a t i o n so f t h i s : f i r s t , i t i n c l u d e sa m o d u l e R G S U B S
( w h i c h i s t i t l e d t r a n s f e rv e c t o r ) ,a n d s e c o n d ,i t i s f o l l o w e d
o n t h e m a p s b y o v e r l a y sw i t h h i g h e r s t a r t i n ga d d r e s s e s .
T h e s i z eo f t h e o v e r l a yf e t c h a r e a i s t h e l a r g e ro f ( 1 ) t h e
l a r g e s to v e r l a yw i t h s u b o v e r l a y sp l u s t h e l a r g e s ts u b o v e r l a y ,
o r ( 2 ) t h e l a r g e s to v e r l a y w i t h o u t s u b o v e r l a y s .I n F i g u r e
5 - 6 3 . 5 ,t h e s i z e o f t h e o v e r l a y f e t c h a r e a i s e q u a l t o t h e s u m
of the sizesof $##002 and $##006. This is not obvious
f r o r n t h e m a p s , b u t t h e b l o c k d i a g r a m( F i g u r e 5 - 6 3 . 6 )
drarrun
f r o m t h e m a p s m a k e st h i s c l e a r . O v e r l a y 2 i s t h e
l a r g e s tm a i n o v e r l a yw i t h s u b o v e r l a y ss, o i t d e t e r m i n e st h e
s t a r t i n ga d d r e s sf o r a l l s u b o v e r l a y s .O v e r l a y 6 i s t h e l a r g e s t
sub,cverlayT
. o g e t h e r ,o v e r l a y s2 a n d 6 r e q u i r e8 s e c t o r so r
0 8 0 0 b y t e s , w h i c h i s g r e a t e rt h a n t h e 7 s e c t o r s( o r 0 7 0 0
b y t r . ' s f)o r o v e r l a y 1 .
l f a u s e r w a n t s t o r e d u c et h e s i z eo f t h e o v e r l a yf e t c h a r e a ,
h e c o u l d r e d u c et h e s i z eo f e i t h e r $ # # 0 O Z o r $ # # 0 0 6 .
O n e s e c t o r ,h o w e v e r ,i s a l l t h e u s e rc a n e x p e c t t o s a v e
b e c i a u s$e# # 0 0 1 i s j u s t o n e s e c t o rs m a l l e rt h a n t h e o v e r l a y
fetch area.

Ro o t

O v e r l a yF e t c h R o u t i n e

T'
I
I

s+#002

$##001

rJvertayI
Fetch -l
,Area
i

II

$+#004

$jf#003

I
Root 2
F i g u r e 5 - 6 3 . 6 . D i a g r a m o f S t o r a g ea n d L i b r a r y M a p s

c-50.2

s##005

$##oo6

$##007

P a S eo t G C 2 i - 7 5 6 7 , 2
l s s u e d3 0 J u n e 19 7 8
By TNL: cN21-5616

F itting Available Storage

RPG ll Logic and Function Shifting

T h e l i n k a g ee d i t o r r e m o v e sm o d u l e sf r o m r o o t 2 , p l a c i n g
t h e m i n t o t h e o v e r l a y s t r u c t u r eu n t i l t h e p r o g r a m f i t s i n t o
a v a i l a b l es t o r a g e( o r u n t i l t h e r e a r e n o m o r e m o d u l e st o

T h e b a s i cf u n c t i o n a la r e a so f R P G l l l o g i ca r e s u m m a r i z e d
i n t h e f o l l o r v i n gs e q u e n c e :

o v e r l a y ,w h i c h m e a n st h e p r o g r a m i s t o o l a r g et o f i t ) .
A f t e r a f i t i s o b t a i n e d ,t h e r e m a y b e u n u s e ds p a c et n
storage. lf there is,an attempt is madeto find small
m o d u l e st h a t c a n b e r e m o v e df r o m t h e o v e r l a ys t r u c t u r e
a n d p l a c e db a c k i n t o t h a t f r e e s p a c e .

1.

D e t a i l O u t p u t - D e t a i l a n d h e a d i n go u t p u t ( e x c e p tf o r
o v e r fl o w l i n e s )a r e p e r f o r m e d .

2.

P h y s i c a lI n p u t - R e c o r d s a r e r e a d f r o m p r i m a r y a n o
s e c o n d a r yf i l e s ,a s n e c e s s a r ya, n d t h e l D i n d i c a t o r
is set.

3.

T o t a l C a l c u l a t i o n sA l l c a l c u l a t i o nw
s ith L anda
n u m b e r i n c o l u m n s7 a n d 8 a r e p e r f o r m e d .T h i s
i n c l u d e sa l l e x c e p t i o no u t p u t s p e c i ifc a t i o n si f E X C P T
i s p e r fo r m e d , o r a l l r e q u i r e di n p u t s p e c i ifc a t r o n s
f o r R E A D so r C H A I N s p e r f o r m e do
, r any user
s u b r o u t i n e sc a l l e dw i t h E X S R .

4.

T o t a l O u t p u t - T o t a l o u t p u t ( e x c e p tf o r o v e r f l o w
l i n e s )i s p e r f o r m e d . Y o u s h o u l d n o t e t h a t t o t a l
c a l c u l i a t i o n as n d o u t p u t a r e a t t e m p t e d o n e v e r y
cycre.

T h i s p r o c e s so f m o v i n go v e r l a i dm o d u l e sb a c k i n t o m a r n
storagemight give you a missing overlay, that is, a
s u b o v e r l a yw i t h o u t a m a i n o v e r l a y . I n t h e s t o r a g em a p ,
y o u c a n s o m e t i m e sn o t i c e u n o v e r l a i dm o d u l e sa r n o n g
t h e o v e r l a y s .T h i s i s a r e s u l to f m o v i n gm o d u l e sf r o m m a i n
s t o r a g et o a n o v e r l a ya n d b a c k a g a i n .
T h e l i n k a g ee d i t o r m o v e sc o d e r a t h e r t l r a n a l l o w r r r g
a v a i l a b l es t o r a g eg o u n u s e d . H a v i n gc o d e m o v e d b a c k t o
m a i n s t o r a g ec a n i m p r o v e s p e e do f e x e c u t i o n .b u t i s n o t
u n d e r t h e c o n t r o l o f t h e u s e r . T h e l i n k a g ee d i t o r m o v e st h e
code when it can.

O v e r fl o w O u t p u t - A l l o u t p u t l i n e sw i t h o v e r fl o w
i n d i c a t o r sc o n d i t i o n i n gt h e m a r e p e r f o r m e d .

6.

Logicallnput-Data readin Step 2 is movedto the
f i e l d s n a m e d o n t h e i n p u t s h e e t ,a n d t h e
c o r r e s p o n d i n gf i e l d i n d i c a t o r sa r e s e t .
D e t a i lC a l c u l a t i o n s - A l cl a l c u l a t i o nw
s ithout L and
a n u m b e r i n c o l u m n s7 a n d 8 a r e p e r f o r m e d .S e e
Step 3 for more information.

T h e s ef u n c t i o n a l a r e a sc a n b e i d e n t i f i e d b y t h e t i t l e s o J
r o u t i n e si n t h e s t o r a g em a p . A u s e rc a n r e d u c et h e s i z e
o f a n y o f t h e s ea r e a sb y o n e o f t h r e e m e t h o d s :
a

R e m o v i n qf u n c t i o n f r o m t h e p r o g ! ' a m
U s i n gm o r e e f f i c i e n tc o d i n g
S h i f t i n g f u n c t i o n f r o m o n e g e n e r a la r e at o a n o t h e r

T h e r e m o v a lo f f u n c t i o n f r o m a p r o g r a mo f t e n r e s u l t si n
a s e c o n dp r o g r a m b e i n g w r i t t e n t o p e r f o r m t h o s e f u n c t i o n s .
S o m e s y s t e md e s i g n si n c l u d e l u x u r i e st h a t a r e n o t e s s e n t i q l
t o t h e j o b . T h e s ef u n c t i o n s m a y b e r e m o v e df r o m t h e
program.
F u n c t i o n st h a t c a n n o t b e r e m o v e dc a n o f t e n b e m o v e d t o
a n o t h e r a r e a . S o m e t o t a l c a l c u l a t i o n sc a n b e m o v e d e a s i l v
t o d e t a iI c a l c u l a t i o n s .

C o n t r o l l i n gO p e r a t i o n sI n A n R P G l l P r o g r a m

5-56.3

P a g eo f G C 2 1 - 7 5 6 7 - 2
l s s u e r3i0 J u n eI 9 7 8
B y T I { L : G N 2 1. 5 6 1 6
1 - h ef o l l o w i n g r n u l t i p l y s t a t e m e n tc o u l d b e m o v e d t o d e t a i l
c a i c L t l a t i o nbsy c o n d i t i o n i n gi t w i t h t h e 0 1 i n d i c a t o r j, u s t
l i k e t : h ea d d , a n d d e l e t i n gt h e L 1 i n d i c a t o ro n t h e M U L T
s t a t e m e n t .T h e r e s u l t sw i l l b e i d e n t i r : a l S
. i m i l a r l y ,s o m e
c a l c L r l a t i o ncsa n b e r n o v e dt r o m d e t a i l t o t o t a i ; h o w e v e r .
a n e \ v r e c o r d l D i n d i c a t o rw i l l b e o n s o t h e u s e rm a y h a v e
t o u s ea n e x t r a i n d i c a t o r .
c
0
CL1

1

AMT
TO'I'A L

ADD
fulULT

TOTA L
RATE

TOTA L
DISCNT

P r i m a r ya n d s e c o n c i a riyn p u t a r e d o n e a t i n p u t t t m e .
R E A D a n d C l l A l N a r e p e r f o r m e dd u r i n gc a l c u l a t i o n s l. f
c a l c u l a t i o nas r e t o o b i g , a f i l e p r o c e s s ; ewdi t h t h e C H A I N
o p e r a t i o nc o d e m i g h t b e f i r s t s o r t e d a n d t h e n m a t c h e da s
a s e c o n d a r yf i l e a g a i i r stth e p r i m a r y . l f i n p u t i s t o o b i g , a
s e c o n d a r yf i l e c o u l d b e m a d e a d e m a n d f i l e a n d p r o c e s s e d
w i t h t h e R E A D o p e r a t i o nc o d e d u r i n gc a l c u l a t i o r r s .
O u t p u t , l i k e c a l c u l a t i o r t sc, a n b e s h i f r l e db e t w e e nd e t a i l a n r _ l
t o t a l c a l c u l a t i o n s .E v e n o v e r fl o w o u i i p u t c a n b e m o v e d
t o t h e { o l l o w i l g d e t a i lo r t o t a l c a l c u l a t i o n bs y u s i n ga
n u m t : r i ci n d i c a t o r w
, h i c h i s S E T O N c o n d i t i o n e db y t h e
o v e r i l o v ' ri r r d i c a t o r . E X C P T i s o t - r t p u tp e r f o r m e d c j u r i r - . , g
c a l c u l a t i o r r s .S o m e o u t p u t f u n c t i o n s m a v b e m o v e c lf r o m
o u t p u t t o c a l c u l a t i o n (se i t h e rd e t a i lc ) rt o t a l ) .
A n y c a l c u l a t i o no v e r l a y o r s u b o v e r l a ,tyh' a t d o e sa n E X C P T
w i l l c : o n t a i na l l E o u t p u t s p e c i f i c a t i o n sl.f a s u b o v e r l a yh a s
E X C P T i n i t a n d i s t o o l a r g e t, h a t o p e r a t i o nc a n u s u a l l yb e
m o v r ) dt o a n o t h e rs u b r o u t i n e . l f t h e s u b r o u t r n eas r e l a r g e ,
t h e y c a n u s u a l l yb e d i v i d e di n t o s e v ear l s m a l l e rs u b r c l u t i n e s .
C a l c u l a t i o ns e c l i o n sc a n n o t b e d i v i d e db y t h e l i n k a g ee d i t o r
to be separate
o v e r l a y s ; s u L r r o u t i nceasn . T h e y w i l l b e c o m e
s u b o u e r l a ytso t h e m a i n d e t a i io r t o t a l c a l c u l a t i o nos v e r l a y .
l f o n e s u b r o u t r n ec a l l sa n o t h e rs u b r o l t i n e ,b o t h w i l l a p p e a r
I n t h e s a m es u b o v e r l a y T
. o d i v i d et h e n t u p , t h e f i r s t
s u b r o u t i n em u s t r e t u r n t o r e g u l a rc a l r : u l a t i o nf sr o m w h i c h
t h e s r : c o n ds u b r o u t i n ec a n b e c a l l e d .
U s i n qs h a r e dl i 0 f o r d i s k f i l e s c a n s a ! , ea g r e a t d e a l o f s p a c e
r r ' rs o r r e p r o g r , t m s .W i t h t h e r e s u l t i n gs m a i l e ro v e r l a y
s t r L r c t u r ep, e r t o r n r a n c em a y b e i m p r c ' v e d .A l t e r n a t i v e l y ,
l a r g e d i s k f r l e b u f f e r s a n d d o u b l e b u f f e r i n gc o u l t Jb e
s p e c i f i e d . T h e s r :t w o t e c h n i q u e su s e e x t r a s t o r a g e
( r e s u l t i n gi n r n o r eo v e r l a y s b
) u t m a y s t i l l p e r f o r mf a s t e r
b e c a u s eo f t h e s p e e di m p r o v e m e n ti n d i s k o p e r a t i o n st h e y
p r o v i d e . S e l e c t i o nb e t w e e n l a r g e rd i s k l / O b u f f e r s o r s h a r e d
b u f f e , r sm u s t b e m a d e b y t r i a l f o r e a c h p r o g r a m .
I n f o r m a t i o na b o u t t h e o v e r l a yl i n k a g ee d j t o r c a n b e f o u n d
in the IBM System/3 Overlay Linkaget Editor Reference
Manual.GC21 7561.

5-56.21

S P E C I A L U S E SO F C O N T R O L L E V E L I N D I C A T O R S
A t t h i s t i m e , y o u s h o u l db e f a n r i l i a w
r i t h t h e n o r m a lu s e o f
c o n t r o l l e v e l i n d i c a t o r s ,L 1 - L 9 . Y o u k n o w t h a t b y a s s i q n ,
i n g t h e m o n t h e I n p u t s h e e ta n d u s i n gt h e m o n t h e C a l c u l a t i o n a n d O u t p u t S p e c i f i c a t i o n ss h e e t sy o u c a n d o t o t a l
o p e r a t ro n s .
I n t h i s s e c t i o n y, o u w i l l l e a r nt o w o r k w i t h a s p e c i a il n t e r n a !
c o n t r o l l e v e li n d i c a t o rL 0 . Y o u w i l l a l s ol e a r nt o u s e L 1 - L _ 9
i n d i c a t o r st o c o n d i t i o n c a l c u l a t i o n sa r - r dt o p e r { o r m g r o u p
p n f rt r n g .

I n t e r n a lC o n t r o l L e v e l I n d i c a t o r L 0
L 0 i s a u n i q u ec o n t r o l l e v e li n d i c a t o rw h i c h i s a l w a y so n .
Y o u c a n n o ta s s i g ni t t o a { i e l c Ja, s y o u d o L 1 - L 9 , b y e n t e r i n g i t i n c o l u m n s 5 9 - 6 0 o f t h e I n p u t s h e e t . B r , r t y, o u c a i r
u s e i t t o c o n d i t i o na c a l c u i a t i o no l o u t p u t o p e r a t i o r r .T h e
o p e r a t i o ns o c o n d i t i o n e dw i l l b e d o n e a t t o t a l t i r n e f o r
e v e r yp r o g r a mc y c l e ,s i n c eL 0 i s a l w a y so n .
'Ihe

m a i n p u r p o s eo i t h e L 0 i n d i c a t o ri s t o a l l o w V o u t o
s p e c i f yt o t a l o p e r a t i o n sw h e n i n d i c a t o r sL ' l - L 9 a r e n o t
available
o r w h e n t h e y c a n n o ta c c o m p l i s ht h e i o b .

S u p p r o s yeo u w a n t t o p r i n t t h e r e p o r t s h o w n i n F i g u r e b - 6 4 .
T h e r e p o r t i s a l i s t i n qo f i t e r n sa c o m L l a n yh a s s o i d i n e a c h
o f r t s t w o d i s t n c t s . T h e r e p n r t i n c l u d e st o t a l s a l e sf o r e a c l r
d i s t r i c t( D I S T O T )a n d a g r a n dt o t a i o f s a l e si n b o t h d i s t r i c t s
"f
h e i n p u t r e c o r d sa r e g r o u p e db y d i s r r i c t w i t h
{GD fOT}.
D i s t r i c t i r e c o r d sp r e c e d i n gD i s t r i c t 2 . E a c h r e c o r d c o n ,
t a i n sa n i t e m n u r r i b e rf i e l d ( t T E M ) , a r r i t e n rc l e s c r i p t r o n
( D b : S ; C Ra) ,n d a n i t e m c o s t f i e i d { C f l l l T ) ,a s s h o w n i n F i g u r e
565
A i - e r : o r di d e n t i fi c a t i o n c o d e i n L l o s i t i o n. l i r r d i c a t e si n w h i c h
d i s t r i r ; ti h r , ' i t c n w
r a s s o l c l .l l o r m a i l y , t h e f i e i d c o n t a i n i n g
t h c r : c o r d i d e r r t i f i c a t i o nc o t l e c o u i d b e u s e c a
l sa control
t i e l t . :i in t h e p r i n t i n g o f d i s t r i c t t o t a l s . H o r n i e v e re,a c h d i s ,
t r i c L l - r a sm o r e t h a n o n e r e c o r d i d e n t i f i c a t i o nc o d e . D i s t r i c t

34J 26 |
46F 419
2 1P 0 0 6

'l

u s e se i t h e r a 1 o r a n M a s a n i d e n t i f i e r a n d D i s t r i c t 2 u s e s
e i t h e r a 2 o r a i r N . S i n c e t h e c o n t e n t so f t h e r e c o r d i d e n t i f i
c a t i o n f i e l c lc a n c h a n q ew i t h c i u t a c t u a l l y h a v i n ga c h a n g ei n
d i s t r i c t ,t h i s f i e l d c a n n o t b e u s e da s a c o n t r o l f i e l d . N e i t h e r ,
o f c o u r s e c, a n t h e I T E M , D E S C R ,o r C O S T f i e l d sb e u s e da s
control fielcls.

Artific ial Contro I B reaks
W h t : n i t i s n e c e s s a r yt o d c t o t a l o p e f a t j o n sb u t n o c o n t r c l
f i e l d sa r e a v a i l a b l et c , c a l t s ea c o n t r o l b r e a k ,y o u c a n u s e L 0
t o c a L r saen a r t i fi c i a lc o n t r o l b r e a k . F i g u r e5 - 6 6 , i n s e r tB ,
s h o w s t h e u s e o f L 0 t o p e r mi t t o t a l c a l c u i a t i o nc r p e r a t r o n s "

P O S T A I - ] L EC O M P R E S S O R
POIITABi,.E
G E N ER A I O R , 3 O K W
H Y D R A T J I - . IJCA C K

623.21
14
, 59.95

260.00
t
?

II
DISTRICI TOTAt.

34_t261
164300
8 0 D 6 10

ilems

B J ,3 4 7 . 1 6 '

P O R T A t s L EC O M P R E S S O B
P O R T A B L ES P R A Y E R
P O R T A B L . EG E N E R A T O R .s O K W

a1
r123.
930.oo
3 ,0 16 .50

tt

I

'1
. 2 1 9 .0 4 .

D I S T R I C TT O T A L

A.ridilonal
items

2 18,566.20" '

G R A ND T O T A L

Figure 5-64.

Addilional

Format of District Sates Listino

Record
l.D. Code

ITEM
r

r . , .

Figure 5-65.

DESCR
r , l

, r r I j : ] l

r t

1 6

t i : , . t ; ' , : : . 1 1 : . , .

COST
. j : _ q t i l . t l t ; .

r i ; l : l t g t t

Format of Sales Becord

C o n t r o l l i n gO p e r a t i o n sI n A n R P G l l P r o g r a m

5-56.5

T h i s p a g ei s i n t e n t i o n a l l yl e f t b l a n k

G X 2 1 . S 4 U I M0 5 0 '
p,,nr.dn us A

RPG INPUTSPECIFICATIONS
:lBll

.,".",

Ma.h ne corpo,aho.

,..

1

"."nei
l

7 5 7 6 7 7 7 8 7 9 8 0

2
l

l

P

r

@

r

s

n

l

l

l

P " s L 1j . I _ , d " ; , , , " " , l, l.l "l 1

r1
RPG

l

l

l

l

ll

F o r n G x 2 1S 9 3
P. nr.d i! U.S A

C A L C U L A T T O NS P E C I F I C A T I O N S

**f-f]"_ Prqram

18 79 AO

15 76 1l

[T_fflflI

ld.ntircationl

I

|

|

|

I

l n d i c a t o r 2 1 i s u s e dt o s i g n a l
a c h a n g ei n r e c o r d t Y P e . T h i s
t e c h n i q u eo n l Y w o r k s f o r t w o
recorcl types.

F i g u r e 5 - 6 6 ( P a r t 1 o f 2 ) . C a l c u l a t i o n sU s i n g a n A r t i f i c i a l C o n t r o l B r e a k ( L O I n d i c a t o r l

C o : r L r , rilr r gO p e r a t i o n sI n A n R P G l l P r o g r a m

5-57

RPG
IBlt

T;-

OUTPUT
I

I

SPECIFICATIONS

",.."",.,. "",esMd,n. (:..F.a,.n

ftqamms

I o"*

I

I

I

I

I

! _

. ; -I l fL l l - Il tt l I ll l
. l

Figure 5€6 lPart 2 ol 2). Calculations Using
an Artificiat Conrrol Break (l_0 Indicarorl

Assumethat the followingf ive recordsare read:

Id e n t i f y i n g

5-513

(;\2rl&

u/M05o'

,

I

% " l1l d

I ' L r ' -

:r r: c*n :t rr th Td 'T' " I1 -- lt l l1-l ll - l

T h e o p e r a t i o n sp e r f o r n t e do n t h e s ef i v e r e c o r d sa r e a s f o l lows:

RecorC
{1)

QI

(3)

(4)

(5)

lndicators On Aperations Performed
LO

LO,21

LO,21

LO

LR

0 1 t u r n so n .
N o t o t a l o p e r a t i o nasr ep e r f o r m e db e c a u sceo n d i t i o n s
i n l i n e s5 - 6 ( C a l c u l a t i o n s
sheet)are not met.
( R e m e m b et rh a t o p e r a t i o n s
conditioned
b y c o n t r o ll e v e l
i n d i c a t o r isn c o l u m n s7 - 8a r e
performedfirst, but are byp a s s eo
d n t h e f i r s t R P Gl l
c y c l e).
C O S Ti s a d d e dt o D I S T O T .
2 1 i s s e to n .
I T E M ,D E S C Ra, n dC O S T
a r ep r i n t e do u t .
0 1 i s t u r n e do f f .
2 1 r e m a i nos n ^
0 1 i s t u r n e do n .
N o t o t a l o p e r a t i o nasr ep e r formed.
C O S Ti s a d d e dt o D I S T O T .
I T E M ,D E S C Ra, n dC O S T
a r ep r i n t e do u t .
0 1 i s t u r n e do f f .
2 1 r e m a i nos n .
0 2 t u r n so n .
D I S T O Ti s a d d e dt o G D T O T .
(Conditionsfor the total
o p e r a t i o ni n l i n e5 h a v eb e e n
met.)
D I S T O Ti s p r i n t e do u t .
COSTiSAddcdtO DISTOT.
21 is set off.
I T E M ,D E S C Ra, n dC O S T
a r ep r i n t e do u t .
02 is turned off.
0 2 i s t u r n e do n .
No total operationsare Performed.
coST addedto DlsToT.
I T E M . D E S C Ra, n dC O S T
areprintedout.
02 is turned off .
DISTOTaddedto GDTOT
( L R i n d i c a t oirs o n ) .
DISTOTand GDTOT printed
out.

Using Control Level lndicators as Calculation Conditioning
lndicators
C o n t r o l l e v e l i n d i c a t o r sa r e n o r m a l l y e n t e r e di n c o l u m n s 7 - 8
o f t h e C a l c u l a t i o ns h e e tw h e r e t h e y s p e c i f yw h i c h c a l c u l a t i o n s a r e t o b e d o n e a t t o t a l t i m e . T h e y m a y , h o w e v e r ,b e
u s e d i n c o l u m n s 9 - 1 7 a l s o w h e r e t h e y i n d i c a t ew h i c h d e t a i l
o p e r a t i o n sa r e t o b e d o n e o n t h e f i r s t r e c o r d o f a c o n t r o l
group.
C o n t r o l l e v e l i n d i c a t o r sa r e t u r n e d o n n e a r t h e b e g i n n i n go f
the program cycle if the contents of the control field on the
record just read are different from the contents of the pre'
v i o u s c o n t r o l f i e l d . S i n c et h e i n d i c a t o r i s n o t t u r n e d o f f u n t i l t h e e n d o f t h e c Y c l e ,i t i s o n d u r i n g t o t a l a n d d e t a i l t i m e .
T h u s , i t i s a v a i l a b l et o u s e a s a c o n d i t i o n i n g i n d i c a t o r d u r i n g
d e t a i lt i m e a s w e l l a st o t a l t i m e .
W h e n a n o p e r a t i o n i s n o t c o n d i t i o n e d b y c o n t r o l l e v e li n d i c a t o r ss p e c i fi e d i n c o l u m n s 7 - 8 o f t h e C a l c u l a t i o ns h e e t ,t h e
o o e r a t i o n i s d o n e a t d e t a i l t i m e . l f t h e o p e r a t i o ni s c o n d i t i o n e d b y a c o n t r o l l e v e l i n d i c a t o r s p e c i f i e di n c o l u m n s 9 ' 1 7 ,
a n d n o t i n 7 " 8 t h e o p e r a t i o ni s s t i l l d o n e a t d e t a i l t i m e , b u t
o n l y w h e n t h e c o n t r o l l e v e li n d i c a t o ri s o n . A n d w h e n i s
t h e c o n t r o l l e v e li n d i c a t o r o n ? O n l y d u r i n g t h e p r o c e s s i n g
of the first recordin a control group asonly the first record
i n a n e w g r o u p c a u s e sa c o n t r o l b r e a k .

Group Printing
I n g r o u p p r i n t i n g , d a t a f r o m g r o u p so f i n p u t r e c o r d si s
s u m m a r i z e da n d p r i n t e d a s t o t a l s o n a r e p o r t . S o m e t i m e s ,
a f i e l d o n e a c h r e c o r d i n a n i n p u t f i l e i s a c c u m u l a t e da n d
o n l y t h e f i n a l t o t a l i s p r i n t e d . A t o t h e r t i m e s , s u b t o t a l sa r e
created by adding the contents of a field from a certain
g r o u p o f r e c o r d sa n d p r i n t i n g t h e r e s u l t .

Printing Only the Final Totals
I t i s p o s s i b l et o a d d t h e c o n t e n t so f a f i e l d f r o m a l l d a t a
r e c o r d s ,a n d p r i n t o n l y t h e t o t a l a c c u m u l a t e d . Y o u m a y
w a n t t o d o t h i s w h e n y o u a r e n o t i n t e r e s t e di n a n y o f t h e
d e t a i l i n f o r m a t i o n , b u t y o u d o n e e da s u m m a t i o no f t h a t
information.
Figure 5-67 shows the coding for a program that finds the
t o t a l s f o r t w o f i e l d so f i n f o r m a t i o n a n d p r i n t s o n l y t h o s e
t o t a l s . N o t i c e , w h e n p r i n t i n g o n l y t o t a l s ,t h e I n p u t s h e e t
n e e d o n l y c o n t a i n t h o s e f i e l d s t h a t w i l l b e u s e di n t h e c a l c u '
l a t i o n so r i n t h e p r i n t i n g . T h e O u t p u t - F o r m a t s h e e ts h o w s
only a total line (T in column 15). That line is not printed
u n t i l t h e l a s t r e c o r d h a s b e e n p r o c e s s e d( L R i n c o l u m n s
24-251. Then, one line is printed, containing the total
quantity, total cost, and a constant (see insert on OutputFormat sheet).
C o n t r o l l i n gO p e r a t i o n sI n A n R P G l l P r o g r a m

5-59

F i l e D e s c r i p t i o n S p e c i fi c a t i o n
F l€ Addrr
Lenqth

oi Key

ol Secord

onlUno.dered

F'e1d or

Addre$

F e d

liii l
RPG INPUTSPECIFICATIONS

cx2t w

,"nwd,*

75 76 7/

P,q'anr

u/Mo5o,

18 l9

80

[TTTT-T_]

t d m " ( a i , o n Ll ,l ll l l

Record lcJenlrf rctron

Codes
F ield Location

l 1 l
+ l t

rlitll+

RPG CALCULATION
SPECIFTCATIONS
IBM,",.,^",,,,,,,

.o'm Gx?1 $93
P r i ^ r . dn u s A

M . c h , n .c o , r , . i i o ^
"",..n
C!rd

I

Proe.a.nme.

El.cro

N!hhr

I o.tu

75

output I ndicators

L i;- l_-le

1 . I ; lr4

s,pp,* I

Constantor €dit Word

Ji
o

Figure5-67. Group printing - printing
Only the Finat Totals

5-60

76

'*ldrl"'_ :rlL,."lfTT-[-i]
7t

78

79

80

tSroupPrintingof Subtotals
F i g u r e5 - 6 8s h o w sg r o u pp r i n t i n go f s u b t o t a l sT. h e i n p u t
r e c o r d sf o r t h e p r o g r a mc o n t a i ni t e m ,q u a n t i t y ,a n dc o s t
f i e l d s t; h e y w e r ep r e v i o u s lsyo r t e db y l i k e i t e m s .
F i g u r e5 - 6 9s h o w st h e c o d i n gt o p r o d u c et h e r e p o r t . S i n c e
a subtotalis to be calculatedfor eachdifferenttype of item,
t h e f i e l d I T E M i s d e s i g n a t eadsa c o n t r o lf i e l d o n I n p u t
r ; p e ciicf a t i o n s T
. h e c a l c u l a t i o nssh o wt h a t ,a se a c hi n p u t
r e c o r di s r e a d t, h e v a l u e si n t h e O T Y a n d C O S Ta r e
a c c u m u l a t eidn t o s u b t o t afli e l d s .A t e a c hc o n t r o lb r e a k ,
l i h es u b t o t afl i e l d s S
, U B O T Ya n dS U B C O Sa. r ea c c u m u l a t e d
i n t o f i n a lt o t a l f i e l d s .
-Ihe
O u t p u t - F o r m asth e e ti n F i g u r e5 - 6 9s h o w sc o d i n gf o r
t h r e ed i f f e r e n t y p e so f p r i n t e dl i n e s :
A d e t a i l l i n e , w h i c h i s p r i n t e d f o r e a c hi n p u t r e c o r dr e a d .
N o t e t h e u s eo f a c o n t r o l l e v e l i n d i c a t o ro n t h e I T E M
f i e l d . T h i s c a u s e st h e f i e l d t o b e p r i n t e d o n l y f o r t h e
f i r s t r e c o r d o f e a c h c o n t r o l g r o u p ( s e eF i g u r e 5 - 6 8 ) ,
m a k i n g t h e r e p o r t l e s sc l u t t e r e da n d e a s i e rt o r e a d . T h i s
is known asgroup indication (seeindex entry).
A t o t a l l i n e , c o n d i t i o n e db y L 1 , w h i c h i s p r i n t e d o n l y
a f t e r e a c h c o m p l e t e g r o u p o f l i k e i t e m s w a s r e a d ,t h a t
is, after each control break.
A f i n a l t o t a l l i n e , c o n d i t i o n e db y L R , w h i c h i s p r i n t e d
only once, after all records were processed.
lf you want the subtotals to be the sums of only the
,quantitiesand cost in one section (for instance,only those
,quantitiesand costs under item ABCD), it is necessaryto
set those fields back to zero after they have been printed
iandadded into the f inal totals. This processis indicated
i n c o l u m n 3 9 . T h e B e n t r i e si n d i c a t et h a t t h e t o t a l s , S U B
,OTY and SUBCOS, are to be blanked out, or zeroed out,
, a f t e rt h e y a r e p r i n t e d , w h e n t h e c o n t r o l f i e l d ( I T E M ) c h a n g ,es. They are set back to zero so that they can correctly
accumulatethe quantities and costs for the next item.

C o n t r o l l i n gO p e r a t i o n sI n A n R P G l l P r o g r a m

5-61

ASCD

?5
60
65

IJ

t4NOP

JzU

1,50.00

1,0
2000
50
1 , 80

.20
40.00
1 ,. 0 0
3.60

2240

44.80

4O
49

80.00
98.00

89

1,78.00

S U 3 TO T AL S

3 72 . 8 0

FINAL TOTALS

XY ZZ

al

o

O

25.00
60.00
65.00

SU s T O T A L S

SU s T O TLAS

F i g u r e 5 - 6 8 , G r o u p p r i n t i n g - R € p o f . tS h o w i n g
Subtotats

File Description Specif ication

LengthofKeyFedor
of

Secofd

Address

Fietd

E x t e n tE x i t
lor DAIV

F

IB}l

RPG INPUTSPECIFICATIONS

-

GX2r994

UM05O.

,,,", ., ."" aus N$ Ma.hn,uc:o Dora,on

F*--F * -

'.*FEl"_
€ i
eI - |

ffiffi

Recordldentification
Codes
1

j

z

|

9

f

il

1 i

O

Figure5-69 {Part 1 of 2}. Group printing _ printing
Subtotals

5-62

Fo.m Cx21.m3
P . i n r . d' n U . S , A

CALC'I.J
LATION SPECI
FICATIONS
Ca.d El€cto Nrmbr

Gr.phic

P'q,.h

ldenr,ticdtionl

I o.,.

c

Factor 1

J1

T

Oparstion

I

Faclor 2

5t I
2l I

2 h3l!.

I

|

|

|

I

Comments

Length

Name

rl I

I

ResultField

Indicator!

E c

75 76 77 18 79 gO

[-T-T_ffT-l

;ffzTlH

c

5l I

E

l

x

HiehI LowlEcur

T tt-f I-t-f$t-ilTfT

io 61 62 63 il 65 S 6? A @ 70 11 12 13 1'

SPECIFICATIONS
:181f,

""-.,-,

"",.*Mddcor*..n@
Card Elecro

Bryrmmr

ldenrricsr,onl I.

o

Outpul Indicators

*ip

Field Name

'??:.;T* ru.s'r cn
|
I

ffi
trr------r

d

I

a

z

z

.AUTO

lrl

Porron I

;lil

R6qd I

s3 l -lla lo"u t p u 'II

0

6

l | | t l

l

o
0
0

I

| | l l l

m-TTtTft-TtT-n-ll-

l1-t'TT-n-

E

i

.l;;
I

I

I

Field Edit
a = Z e r c

I
Ir

l i i i

#il
tr
I l1
J

a

l+Illl
^T:t^].t

I
O

|

fLf

I
I

tmlTff

|

il tlf tl l

l_

l | l I l l
5

|

1l 1? '3 1,

T
I
0

I

Constantor Edit Word

" t ' t l

a

I

Plui Sign

lil;

s l1 , " . I

Filename

o

P,qram r-I-rT_TT-]

Numhi

I O.l.

I

Figure 569 (Part 2 ol 21, Group Printing - Printing Subtotals

C o n t r o l l i n g O p e r a t i o n sI n A n R P G l l P r o g r a m

563

Group Printing with Two Control Level lndicators
Certainprogramsrequiretwo or more control levels.Nine
l e v e l s( L 1 - L 9 )a r ep o s s i b l eT. h i s p r o g r a mu s e st w o o f t h e s e ,
Ll and L2. to producethe reportshownin Figure5-70.
Eachrecordin the input file containsthe part numberof
an item,the quantity of itemssold,and a numberto identi_
fy the salesman
who soldthoseitems. The file hasbeen
previouslyarrangedby salesman
number. That is, all records
for salesman
number12 aretogether,all recordsfor salesman number13 aretogether,and so forth. Recordsare
alsogroupedby item numberwithin eachsalesman
group.
On the printedreport,the salesman
numberis to be printed
once;part numbersare in the next columnwith the sums
of quantitiesfor eachpart numberin the rightmostcolumn.
Subtotalsareprintedfor eachsalesman
and a final total
is printedat the end of the report.
Figure5-71showsthe codingto producethe report. Since
the PARTNOfield changes
most frequently(thereare
severalpart numbersfor eachsalesman)
that field is the
lowestlevelcontrol field and is assigned
indicatorL1 on the

I n p u t s h e e t .T h e n e x t h i g h e rl e v e cl o n t r o lf i e l d .w h i c hd o e s
n o t c h a n g ea sf r e q u e n t l yi,s S L S N U M t; h e r e f o r eS. L S N U M
i s a s s i g n eidn d i c a t o rL 2 . T h e c a l c u l a t i o on n t h e f i r s t l i n e
(01 indicatorspecified)occursfor everyrecordthat is read.
Q T Y i s a d d e dt o a t o t a l ,O T Y S U M . L i n e2 o c c u r so n l y
w h e nt h e c o n t r o lf i e l d ,P A R T N O ,c h a n g e sb,e c a u sLe1
( c o l u m n s7 a n d 8 ) c o n t r o l st h i sc a l c u l a t i o nS. o .w h e n L 1
i s o n . O T Y S U Mi s a d d e dt o a n o t h e rt o t a l ,S U B T O T .T h e
t h i r d l i n ed e s c r i b et sh e c a l c u l a t i oonf a f i n a lt o t a l , F I N O T .
T h i sc a l c u l a t i o on c c u r sw h e n L 2 i s o n ( w h e nt h e c o n t r o t
f i e l d ,S L S N U M c, h a n g e s ) .
W h e nt h e h i g h e rl e v e cl o n t r o ll e v e li n d i c a t o r( L 2 ) i s o n , t h e
l o w e rl e v e li n d i c a t o r( L 1 ) i s a l s oo n . A s s h o w no n t h e O u t p u t - F o r m ast h e e tw
, h e n L 1 i s o n , P A R T N Oa n d O T y S U M
a r ep r i n t e d( l i n e s0 3 a n d 0 4 ) . H o w e v e rt,h e f i e l dS L S N U M
isconditioneb
d V L 2 , s o i t i s p r i n t e do n l y f o r t h e f i r s t r e c o r d
o f e a c hL 2 c o n t r o lg r o u p . W h e nL 2 i s o n , S U B T O Ta n d
t h e c o n s t a nS
t U B T O T A La r ep r i n t e d( l i n e s0 5 - 0 7 ) .W h e n
L R i s o n , F I N T O Ta n d t h e c o n s t a n F
t I N A L a r ep r i n t e d .
The two subtotals,OTYSUMand SUBTOT,are zeroed
a f t e rp r i n t i n gb y e n t e r i n ga B i n c o l u m n3 9 ( l i n e s0 4 a n d
06). Detaillinesneedneverbe blankedafter,nor doesa
final total (regulatedby the LR indicator).

P a g eo I G C 2 1 - 7 5 6 7 - 2
lssued21 December 1979
By TNL: GN21-5709
S I \ L . E S M A NN U M B E R
PART NUMBER

a')
LJ

L2
1,2
7,2

4235
DTZ+
LJ+U

r)
U

375
100
200
a-7 q

L)
!J

4235
cr,40

SU3 TOTAL

qn

400
450

)A
14
1A
M

8L24
!5>6

E091,

SUsTOTAL

600
325
t 1,0
370
1,405

SUBTOTAL

z) 5u

FINAL

Figure5-70. Group Printing - Report produced using Two control Level Indicators

File Description Specif ication

Lenq$
ol

R4ord

of

Key

Field

Address

q
Field

tor Cylnder

RPG INPUTSPECIFICATIONS

G X 2 l 9 0 9 4 U / M0 5 0 '

'"*FE"P,q'dn
_

Record

Ov€rflow

15 76 1/

18 79 80

fT_fT-tTl

rdrn,,r(a'u,,L--fl

I

i

I

l

ldentif ication Codes

Figure5-71 (Part 1 of 2), Group Printing with Two Control Level Indicators

C o n t r o l l i n g O p e r a t i o n sl n A n R P G l l P r o g r a m

5-65

P a g eo f G C 2 1 , 7 5 6 7 - 2
l s s u e d2 1 D e c e m b e r 1 9 7 9
By TNL: GN21-5709

RPG CALCULATIONSPECIFICATIONS
, IBM,

..,.,," Buni,nMach,npc.po,a,on

-l-r:-l
ndicarofs

I

OUTPUT

SPECIFICATIONS

Figure5-71 lPart 2 ol 2). Group printing with rwo contror
Leverlndicators

5-66

Pageof GC21 -7561-2
l s s u e d2 4 M a y 1 9 7 6
Bv TNL: GN21-5389

B I N A R Y F I E L DO P E R A T I O N (SC O ] [ T R O L L I N G
SWITCHES}

BITON Operation Code
F i g u r e 5 - 7 2 s h o w s a C a l c u l a t i o ns h e e tc o n t a i n i n gt h e B I T O N
o p e r a t i o n c o d e . T h i s o p e r a t i o n c o d e c a u s e ss p e c i f i e db i t s i n
F a c t o r 2 t o t u r n o n ( s e tt o 1 ) i n t h e f i e l d n a m e d i n t h e R e s u l t F i e l d . T h e f i e l d n a m e d i n t h e R e s u l tF i e l d m u s t o e a
o n e - p o s i t i o na l p h a m e r i cf i e l d . S i n c e i t i s o n e p o s i t i o n i n
l e n g t h ,a 1 m u s t b e e n t e r e di n c o l u m n 5 1 o f F i e l d L e n g t h .
One or more of the eight bits can be turned on. To turn on
t h e f i r s t b i t i n a f i e l d , e n t e r 0 i n F a c t o r 2 . T h e s eb i t n u m bers must be enclosed by apostrophes.

/ y ' o f e . 'T h i s t o p i c i s i n t e n d e d f o r I B M S y s t e m / 3 M o d e l 6 ,
Model 10, Model 12, and Model 15 programmers.
R P G l l p r o v i d e sc e r t a i no p e r a t i o n c o d e sw h i c h s e r a n d t e s t
i n d i v i d u a lb i t s i n s t o r a g e . T h e s e i n d i v i d u a l b i t s c a n b e s e t
a n d t e s t e dt o a l l o w y o u f u r t h e r c o n t r o l o v e r p r o c e s s i n g .
W h e n t h i s i s d o n e , t h e b i t s a r e c a l l e ds , w i t c h e as n d t h e i r
f u n c t i o n s a r e s i m i l a rt o t h a t o f R p G l l i n d i c a t o r s . T h e
o p e r a t i o n c o d e sw h i c h s e t a n d t e s t t h e b i t s a r e k n o w n a s
binary field operations. A binary f ielcl is a one-byte field
c o n t a i n i n g8 b i t s i d e n t i f i e d l e f t t o r i g h t b y t h e d i g i t s 0 - 7 .
The bits can be set on, set oi'f, and tested. Since each bit
c a n b e u t i l i z e d ,t h e r e a r e e i g h t i n d i c a t o r si n e v e r y b y t e .

Y o u c a n c o n d i t i o n t h e o p e r a t i o n w i t h i n d i c a t o r si n c o l u m n s
7 - 1 7 . Y o u m a y a l s ot u r n o n a b i t i n a n a r r a ye l e m e n t ,b u t
t h a t a r r a y e l e m e n tm u s t b e o n e p o s i t i o n i n l e n g t h .
ln Figure5-72,bits 0, 1. and 7 are setto 1 in the binarv
f i e l d l a b e l e dC O D E .

W h e n u s i n g b i n a r y f i e l d o p e r a t i o n s ,r e l n e m b e rh o w d a t a
f i e l d sa r e i n i t i a l j z e db y t h e s y s t e m :
o A l p h a m e r i c f i e l d sa r e i n i t i a l i z e dt o H e x a d e c i ma l ' 4 O .'

BITOF Operation Code

N u m e r i c f i e l d sa r e i n i t i a l i z e dt o H e ; < a d e c i m a, F
l 0,.

o

F i g u r e 5 - 7 3 i s a s a m p l eC a l c u l a t i o ns h e e tc o n t a i n i n gt h e
B I T O F o p e r a t i o n c o d e . T h i s o p e r a t i o n c o d e c a u s e ss p e c r f i e d b i t s i d e n t i f i e d i n F a c r o r 2 r o t u r n o f f ( s e tt o 0 ) i n a
f i e l d n a m e di n t h e R e s u l tF i e l d . I n F i g u r e5 - 7 3 , b i t s 0 , 3 ,
a n d 4 a r e t u r n e d o f f ( s e tt o 0 ) i n t h e b i n a r v f i e l d l a b e l e d

Y o u s h o u l d i n i t i a l i z et h e b i n a r y f i e l d c o n t a i n i n gt h e b i t s t o
b e s e t a n d t e s t e d t o b i n a r y z e r o ( H e x a r J e c i m a, 0i 0 , ) a t t h e
b e g i n n i n go f t h e p r o g r a m .

CODE.
A l l o t h e r s p e c i fi c a t i o n sa r e t h e s a m ea s t h o s e s p e c i fi e d u n d e r
BITON Operation Code.

r

RPG

..

C A L C I . J L A T I O NS P E C I F I C A T I O N S

l',"; l;;l
:

Inrrr,-.ron

L_

I

_r-*

,
I

i

I |

--i

l l ilrmlmu
I

_1 I I

L

F o r mC X 2 19 0 9 :
P , r r e di l J s a

l

,","iri.,

15 76 71 1A 19 8A
P , o q , a m t - I i T i - I - l

I

_

r o " " r r . . t " " f l lI 1 l

ResultF eld

Facrof 2

-l

?f1
9 i :t
olt

Figure5-72. The BITON Operarion Code

C o n t r o l l i n gO p e r a t i o n sI n A n R P G l l P r o g r a m

5-67

TEISTBOperation Code
F i g u r e 5 - 7 4 i s a s a m p l eC a l c u l a t i o n
s h e e tw i t h t h e T E S T B
o p e r r a t i o rc.or d e . T h i s o p e r a t i o nc o d e c a u s e s
s p e c i fi e d b i t s
i d e r r t i fi e d i n F a c t o r 2 t o b e t e s t e df o r
an off or on condi_
t i o n . R e s u l t i n gi n d i c a t o r si n c o l u m n s
54-59are set depend_
i n g u p o n t h e c o n d i t i o n s . A t l e a s to n e r e s u
lting indicator
m u s t b e u s e dw i t h t h e T E S T B o p e r a t i o n ,
and as many as
t h r e e c a n b e r - r a m e fdo r o n e o p e r a t i c l n .
T w o i n d i c a t o r sm a y
b e t h e s a m ef o r o n e T E S T B o p e r a t i o n .b u t
not three. Res u l t i n g i n d i c a t o r si n t h e s ec o l u m n s h a v e
the followrngmean
inqs:

I n F i g u r e5 - 7 4 , b i t s 4 , 8 , a n d 6 i n t h e b i n a r y f i e l d n a m e d
C O D E a r e t e s t e d . R e s u l t i n gi n d i c a t o r 6 6 i s t u r n e d
on if
b i t s 4 , 5 , a n d 6 a r e o f f . l f s o m e a r e o n a n d o t h e r so f f ,
res u l t i n gi n d i c a t o r7 7 i s t u r n e d o n . l f t h e y a r e a l l o n .
resulti n g i n d i c a t o r8 8 i s t u r n e d o n .
A l l o t h e r s p e c i fi c a t i o n sa r e t h e s a m ea s t h o s e s p e c i fi e d
under BITON Operation Code. However, you need not
d e f i n et h e R e s u l tF i e l d a s o n e p o s i t i o n i n l e n g t h ,
s i n c et h i s
is done when the field is usedin a BITON or
BITOF opera
tion code.

C o l u m n s 5 4 - 5 5 : A n i n d i c a t o r i n t h e s ec o l u m n s
is turned
c , ni f a l l t h e b i t s i n F a c t o r 2 a r e o t | ( s e t
to 0).
C l o l u m n s5 6 - 5 7 : A n i n d i c a t o r i n t h e s ec o l u m n s
is turned
o n i f t w o o r m o r e b i t s w e r e t e s t e da n d f o u n d
to be of
n r i x e d s t a t u s ,s o m e b i t s o n a n d o t h e r b i t s
off .
C o l u m n s 5 8 - 5 9 : A n i n d i c a t o r i n t h e s ec o l u m n s
is turned
o n i f a l l t h e b i t s i n F a c t o r 2 a r eo n ( s e t t o
1).

C A L C UL A T I O N S P E C F
I ICATIONS

F ac\or 2

Note: The shaded colurrtns
a r e n o t u s € d . L e a v et h e m
blank.

F i g u r r :5 - 7 3 . T h e B I T O F O p e r a t i o n
Code

I B M I. " .

RPG

C A L C U L A TI O N S P E C I F I C A T I O N S
75 76 77 /8 79 80

Proqam [TT-fr-r-t
"*ff l'__
rde,r,icaronl

FigureS-74. The TFSTB Operation Code

5-68

I

|

|

|

jLJ

Example
Fieldsaresometimespresentin customerm,aster
filesto indi,cateparticulartypesof customers.Whensucha masrer
f i l e i s c r e a t e de, a c ho f t h e c o n d i t i o n si n d i c a t i n g
a particular
customertype is represented
in a recordby a one-position
field. Sinceeachpositionoccupiesone byt(!of storage,four
p o s i t i o n si n d i c a t i n cg u s t o m etry p e sw i l l b e s t o r e di n f o u r
b),tesof storage.You can usebinaryfield operationsto
converteachone-byterecordpositionto one bit of informa_
tion on disk. Therefore.four bvtesof inforrnationcan be
re,Cuced
to four bits of informationon disk.
F o r e x a m p l ea, s s u m ye o u h a v ea c u s t o m enr r a s t efri l e o n
c a r d s .Y o u h a v ef o u r c o l u m n sc o n t a i n i n tgl - r ef o l l o w i n gi n formation:
o W h e t h e trh e c u s t o m e irs a w h o l e s a l eorr r e t a i l e r .
o l f t h e c u s t o m e irs e n t i t l e dt o a d i s c o u n t .
o l f o r d e r ss h o u l db e c h e c k e db y t h e c r e d i td e p a r t m e n t .
r

l f d u et o a b a dp a y m e n th i s t o r y t, h e s h i p m e nst h o u l db e
s e n tc a s ho n d e l i v e r y .

N o w y o u w a n t t o p l a c et h e c a r df i l e o n d i s k ,a n d t h e i n f o r m a t i o nf r o m t h e f o u r c o l u m n si n f o u r b i t si n a b i n a r y
f i e l d l a b e l e dC H E C K . T h e f o u r c o l u m n sw i l l b e l a b e l e d
W H L S E ,D S C T ,C R E D I T ,a n d C O D r e s p e c t i v e l yT.h e f o l ow'ingoperationsshouldbe performed:
1.

l f W HL S E i s e q u a lt o 1 , t u r n o n b i t 0 i n C HE C K .

2.

l f D S C Ti s e q u atlo 1 , t u r n o n b i t 1 i n C H E C K .

3.

l f C R E D I Ti s e q u a tl o 1 , t u r n o n b i t 2 i n C H E C K .

4.

l f C O D i s e q u a lt o 1 , t u r n o n b i t 3 i n C H E C K .

INCREASING
T H E S P E E DO F O P E R A T I O N (SD U A L
I/OAREAS)
D u r i n gt h e n o r m a lR P Gl l c y c l e ,a r e c o r di s r e a d ,c a l c u l a . h e c y c l ei s
t i o n sa r ep e r f o r m e da, n d o u t p u t i s p r o d u c e d T
repeatedfor eachrecord.
T h e s p e e da t w h i c ht h e c y c l ei s d o n ed e p e n d u
s p o nt h e
. al.
s p e e da t w h i c h r e c o r d sa r er e a da n d o u t p u t p r o d u c e d C
, r i t i n gt o
c u l a t i o n tsa k el e s st i m e t h a n r e a d i n gp, r i n t i n gw
d i s k ,o r p u n c h i n g .T h e s p e e do f d o i n go u t p u t c a nb e i n creasedby usingdual input/outputareas.

Dual Input Areas
W h e nd u a l i n p u ta r e a sa r eu s e d t, h e p r o g r a mc y c l ei s
changedF
. i r s ta r e c o r di s r e a d . A t t h e s a m et i m e ,c a l c u l a tions are beingperformedon this record,anotherrecordis
beingread. Thus,the contentsof two recordsare in the
computerat the sametime. Figure5-76showshow the
recordsare processed
when two input areasareused.
D u a li n p u ta r e a sc a n b e s p e c i f i e fdo r s e q u e n t i adli s kf i l e so r
d i r e c td i s kf i l e sp r o c e s s esde q u e n t i a l l fyo, r c a r df i l e sd e s i g n a t e da s i n p u tf i l e s .o r f o r t a p ei n p u t f i l e s . N o s t a c k e r
selectioncan be specifiedfor cardfiles. Dual input area:
cannotbe specifiedfor combinedor updatefiles,table,or
d e m a n df i l e s . W h e ns h a r e di n p u t / o u t p u it s s p e c i f i e idn t h e
headercard,all deviceswhich can usesharedinput/output
a r ea u t o m a t i c a l leyx c l u d e df r o m u s eo f d u a li n p u ta r e a s .
(Note to Model 6 Programmers.'Dual input areascan be
u s e df o r d a t ar e c o r d eirn p u t f i l e s . D u a li n p u ta r e a sc a n n o t
to disk, data recorder,or ledgercarddevicefiles
oe assigned
u s i n ga s h a r e di n p u t / o u t p u a
t r e a s, p e c i f i e idn c o l u m n4 8
o f t h e C o n t r o ls h e e t . )

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
b y t h e B I T O F i n s t r u c t i o n ( L i n e 1 . F i g u r e5 - , 7 5 ) .

C o n t r o l l i n gO p e r a t i o n sI n A n R P G l l P r o g r a m

5-69

C A L C UL A T I O N S P E C F
I ICATIONS

Figure 5-75. Example of Binary Field Operations

Input area 1

Records A and B
initially readinto
srorage.

Input area2

Record B

Input area 1

Record C

After Record A is
processed,Record C
is read while Record
B is processed,

Input area2

Input area 1

Input area2

t

;J'C,""i'1

After Record B is
processed,Record D
is read while Record
C is processed.

Record D

/Vofe.' The shaded areas represent records being processed,

Frigure5-76. Dual lnput Areas

5i-70

Dual input areasrequiremore computerstoragespacethan
one input area,because
two recordsare in storageduring
e a c hc y c l e . l f y o u h a v ea l a r g ep r o g r a my, o u m i g h tn o t
haveenoughstoragespaceto accommodate
two input areas.
The effectof dual input areascan be determinedonly if you
haveknowledgeof a program'sprocessing
requirements
and
e x p e r i e n cien R P Gl l p r o g r a m m i n gI.n s o m ec a s e sy,o u c a n
o n l y m a k ea f i n a ld e t e r m i n a t i obny a c t u a e
l xperimentation.
(Note to Disk Programmers: ll your programplus two input
a r e a sr e q u i r em o r es p a c et h a n i s a v a i l a b l ec,e r t a i nR P Gl l
o b j e c tc y c l er o u t i n e sr e m a i no n d i s kd u r i n ge x e c u t i o na n d
arecalledinto storageas needed.lf too many routinesremain on disk,the performance
of your programmay be decreasedby the useof dual input areasratherthan increased.)

Specifications
One entry on the File Descriptionsheetis requiredto specif y d u a l i n p u ta r e a s :a n y d i g i t ( 1 - 9 )i n c o l u m n3 2 a s s i g ndsu a l
i n p u ta r e a sf o r t h e s p e c i fe df i l e . F i g u r e5 - 7 7s h o w st h e f i l e
M A S T E Rh a sb e e na s s i g n eddu a l i n p u t a r e a s .

File Description Specif ication
Fn. Addi! onlurDr&red
LsgS
ot

Rhrd

ol

Key

Field

4&16r

d
tield

tor Cvl,n&r O,edlow

S p e c i f i c a t i o no f d u a l i n p u t a r e a s
for card f iles is alsodone with
a digit in column 32.

Figure 5-77. Specifying a Dual Input Area

Dual Output Areas
W h e n d u a l o u t p u t a r e a sa r e u s e d ,t h e p r o g r a mc y c l e i s
c h a n g e d . A r e c o r d i s w r i t t e n o r p u n c h e do u t a t t h e s a m e
t i m e c a l c u l a t i o na n d o u t p u t o p e r a t i o n sa r e b e i n g d o n e i n t e r n a l l y t o p r o d u c e t h e n e x t r e c o r d . ( C a l c u l a t i o no p e r a t i o n s a r e n o t d o n e a t t h e s a m et i m e a s w r i t i n g o r p u n c h i n g
w h e n o n l y o n e o u t p u t a r e a i s u s e d . ) F i g u r r -5' - 7 8 s h o w s
l]ow output records are produced using dual output areas.
D u a l o u t p u t a r e a s ,l i k e d u a l i n p u t a r e a s ,r e r l u i r em o r e c o m p u t e r s t o r a g e . C o n s e q u e n t l y t, h e s a m es p a c ec o n s i d e r a t i o n s
t h a t a p p l y t o d u a l i n p u t a r e a sa l s o a p p l y t c , d u a l o u t p u t
a r e a s . D u a l o u t p u t a r e a sc a n b e u s e d f o r s e r q u e n t i aaln d
c l i r e c td i s k o u t p u t f i l e s , M o d e l 1 0 p r i n t e r f l e s ( 5 2 0 3 p r i n t e r ) ,
t a p e f i l e s , a n d c a r d o u t p u t f i l e s . D u a l o u t t r u t a r e a sc a n n o t
t r e s p e c i f i e df o r c o m b i n e d o r u p d a t e f i l e s . A l s o , d u a l o u t p u t a r e a sc a n n o t b e a s s i g n e dt o M o d e l 6 d a t a r e c o r d e r ,d i s k
o r l e d g e rc a r d d e v i c ef i l e s a n d M o d e l 1 0 o r M o d e l 1 5 d i s k
f i l e s t h a t u s e a s h a r e di n p u t / o u t p u t a r e a .

Sipecifications
O n e e n t r y i s r e q u i r e do n t h e F i l e D e s c r i p t i , c ns h e e tt o s p e c i f y d u a l o u t p u t a r e a s : a n y d i g i t ( l - 9 ) c a n b e e n t e r e di n c o l u m n 3 2 f o r a n o u t p u t f i l e . F i g u r e 5 - 7 9 s h o w st h e f i l e
t t R l N T h a s b e e n a s s i g n e dd u a l o u t p u t a r e a r ; .

C o n t r o l l i n gO p e r a t i o n sI n A n R P G l l P r o g r a m

5'71

outputarea1 [ffit--'m

[.::::::i::ir:::::::::::::ii

\ lecord

A is in outputareaL

I Whtte record A is being written

or punchedcalculations
are
performedon recordB, and it
is mored to output area2.

Output area2

| ..""-rI

Output area1

t *"""..
I

WhenrecordA is finished.record
B is readyto be written or punched.
WhilerecordB is beingwrittenor
punchedfrom area2, recordC is
calculated
and movedinto area1.

\

OutputArea2

ffiffi.,qffi1

Output area1

Fffi*lffifi|

Output area2

r#."l I

R e c o r d D i s c a l c u l a t e da n d
m o v e d i n t o a r e a2 , w h i l e
recordC is beingwritten or
punched.

Note: the shaded blocks represent records being written,
p u n c h e d ,o r p r i n t e d .

Figure 5-78. Dual Output Areas

Description Specification

F

Exlent Exit
lor DAM
Filename

D*ice

Symbolic
Odice

Name of
Label Exir
Core I ndet

"lll

ul-l'lF
F

oa

€

Bl@k
ung6

optaon

Entry

I

crt

*

Figure 5-79. Specifying Dual Output Areas

5-72

l:11

6

oa 6l at tt

9l

ilI lil

Review5

Additional Usesof Indicators
'l

.

What effect do halt indicators have on System/3 operations? How can you use halt
indicators to handle error situations?

2.

D e s c r i bae m e t h o dt o e l i m i n a t ea n o u t p u t f i l e f o r o n e p r o g r a mr u n w i t h o u t h a v i n g r t o
rewritespecifications
and recompilethe program.

3.

W h e nc o n d i t i o n i n a
g c a l c u l a t i osnp e c i f i c a t i owni t h a n i n d i c a t o rw
, h a t h a p p e nw
s hen
the indicatoris on? What happenswhen it is off?

4.

Describewhat the TESTZ operationdoes.

5.

Usingthis TESTZ specification,
tell what the statusof indicators93, 94, and 95 will be
w h e nt h e f i e l d T E S Tc o n t a i n s :
a. ABC
b. &/*
c. JOH
d. 789
6.

Review 5

5-73

U s i n gt d " r C
i sO M Ps p e c i f i c a t i o tne, l l w h a t t h e s t a t u so f i n d i c a t o r 9
s 6 ,9 7 , a n d9 8 w i l l
b e w h e ntrh e f i e l d sF I R S Ta n dS E C O N Dc o n t a i n :

a.
b.
c.
d.

First
16942
16000
19645
18921

Second
17942
15000
19645
18931

ControllingOperationson the Basisof the Next Recordin a File
7.

B a s i c a l l yw, h a t d o e st h e l o o k a h e a df a c i l i t ya l l o wy o u t o d o ? W h a tl i m i t a t i o n a
spply
to its u$e?

8'

T o t h e i n p u t s p e c i f i c a t i o ng si v e na d dt h o s ew h i c hw i l l a l l o wy o u t o l o o k a h e a di n
o r d e rt o r e a dt h e n e x t p a r t n u m b e r( p A R T N o ) a n d n e x t c o d ei n c o l u m n9 6 .

RPG INPUTSPECIFICATIONS

**ffl"

1+1"f+
II
T'-- Ii

r 1
f ' 1 1

Ii
] - - l

' f i I l r

r

75 76 77 78 79 80

Prderam aT_rT-fl_l
!en,ica,,onl

l

Moving Data
9.

With MOVE, which positionof Factor2 is movedf irst and whereis it positionedin
t h e R e s u l tF i e l d ?

1 0 . w h a t h a p p e n isn a M O V Eo p e r a t i o ni f F a c t o r2 i s l a r g e trh a n t h e R e s u l tF i e l d ?
W h a th a p p e n isf i t i s s m a l l e r ?
1 1 . with MOVEL, which positionof Factor2 is movedfirst and whereis it positioned
i n t h e R e s u l tF i e l d ?

12. Whatsigndoesa numericResultFieldhaveafter a MOVEL operation?

I

I

I

I

I

I

P a g eo f G C 2 1 - 7 5 6 7 - 2
l s s u e d2 1 D e c e m b e r 1 9 7 9
By TN L: GN21-5709

13.

t;;

FlELDl, a 4-position
p o s i t i v en u m e r i cf i e l d ,c o n t a i n s3 4 5 6 ; F | E L D 2 , a ng - p o s i t i o n
n e g a t i vneu m e r i cf i e l d ,c o n t a i n s8 7 6 5 4 3 2 1 .W h a tw i l l t h e c o n t e n t so f t h e R e s u l tF i e l d
b e a f t e re a c ho f t h e f o l l o w i n gi n s t r u c t i o niss e x e c u t e di ,f F I E L D l a n d F I E L D 2c o n t a i n
the abovevaluesbeforeeachinstructionis executed?

RPG

CALCULATION SPECIFICATIONS
75 76 7? 78 79 80

""*fll "- iffiil.,".[ll[f]
Renrlr Field

Branching in Calculations

1 4 . W h a t i s t h e p u r p o s eo f b r a n c h i n q ?
1 5 . H o w i s b r a n c h i n gs p e c i f i e di n R p G l l ?
1 6 . By using branching, how can you structure a program, which has severalrecord
t y p e s e a c h o f w h i c h r e q u i r e sd i f f e r e n t c a l c u l a t i o no p e r a t i o n s ,s o t h a t i t i s e a s yr o
write and efficientto run?

1 7 . w h a t m u s t y o u a l w a y si n c l u d e i n a p r o g r a mt h a t h a s a l o o p ? w h a t w i l l h a p p e n i l
y o u d o n o t i n c l u d et h i s ?

UsingSubroutinesin Calculations
1 8 . W h e n s h o u l d a s u b r o u t i n eb e u s e d ?
1 9 . what are the operations used to def ine and execute a subroutine? what enrry musr
b e m a d e i n e a c h c a l c u l a t i o nl i n e o f a s u b r o u t i n et h a t i s d i f f e r e n t f r o m a l l o t h e r
c a l c ul a t i o n s ?

2 Q . w h a t l i r n i t a t i o nisn t h e u s eo f G o r o a n d r A G a p p l yt o s u b r o u t i n e s ?
2 1.

W h e r em u s ts u b r o u t i n ebse c o d e d ?

Review 5

5-75

SpecialUsesof Control LevelIndicators
22.

W h e nw o u l dy o u u s et h e L 0 i n d i c a t o r ?

23'

How canyou specifycalculations
to be performedonly on the f irst cardof a qrouo?

24.

W h e ns h o u l dy o u s p e c i f yb l a n ka f t e r ( g i n c o l u m n3 9 o f t h e O u t p u t - F o r m a t
sheet)
f o r a n o u t p u tf i e l d ?

BinaryFieldOperations
25.

Whatare bit switchesusedfor?

26.

Codethe calculationspecificationto:
a . S e to n b i t s4 a n d 7 i n a f i e l d c a l l e dT E S T E R .
b. Set off bits 'l, 2, and 3 in TESTER.
c . T e s tt o s e ew h e t h e rb i t s 1 , 2 , a n c l 3i n T E S T E Ra r ea l l o n o r a l l o f f .
S e to n i n d i c a t o r0 1 i f t h e y a r ea l l o n a n ds e to n i n d i c a t oor 2 i f t h e v a r ea l ro t f .

Dual Input/OutputAreas
27'

5-76

F o r w h i c hd e v i c ea n d f i r et y p e sc a n y o u s p e c i f yd u a ri n p u t / o u t p u t
a r e a so n v o u r
system?

P a g eo f G C 2 1 - 7 5 6 7 - 2
l s s u e d3 0 J u n e 1 9 7 8
By TNL: GN21-5616

AnswersTo Review5

H a l t i n d i c a t o r sm a y b e t u r n e d o n a s r e c o r d i d e n t i f y i n g i n d i c a t o r s ,a s a r e s r . r lot f
a
t e s t o n a f i e l d , o r a s a r e s u l to f c a l c u l a t i o n s .w h e n t h e y a r e o n , t h e y c a u s et h e
s y s t e mt o h a l t a f t e r a l l c a l c u l a t i o n sa n d o u t p u t o p e r a t i o n sh a v e b e e n p e r f o r m e d f o r
t h a t p r o g r a mc y c l e .
B e c a u s ea p r o g r a m c y c l e i s c o m p l e t e d b e f o r e t h e s y s t e m h a l t s ,o p e r a t i o n sm a y b e
p e r f o r m e d o n e r r o n e o u sd a t a . H a l t i n d i c a t o r s ,w h e n u s e d a s c o n d i t i o n i n g
indicators,
a l l o \ / /y o u t o b y p a s sc a l c u l a t i o n sa n d o u t p u t o p e r a t i o n sw h i c h w o u l d u s u a l l y b e d o n e .
T h e y ' a l s oa l l o w y o u t o p r i n t e r r o r m e s s a g easn d s t a c k e rs e l e c ta n y c a r d sw i t h e r r o n e ous information.

2.

U s e i e ne x t e r n a l i n d i c a t o r ( U l - U 8 ) t o c o n d i t i o n t h e o u t p u t f i l e a n d o p e r a t i o n ss p e c i f i e d f o r t h a t f i l e . w h e n t h e i n d i c a t o ri s o n t h e f i l e i s u s e d ; w h e ni t i s o f f , t h e f i l e i s
n o t u s e d . T h e f i l e i s c o n d i t i o n e d b y a n e x t e r n a l i n d i c a t o r s p e c i f i e di n c o l u m n s 7 1 - 7 2
o f t h e F i l e D e s c r i p t i o r sr h e e t . T h e o u t p u t s p e c i f i c a t i o n s h o u l d b e c o n d i t i o n e d b y t h a t
s a m €e x t e r n a l i n d i c a t o r e n t e r e di n c o l u m n s 2 3 - 3 1 o f t h e O u t o u t S o e c i f i c a t i o n sS h e e t .
l f t h , ei n d i c a t o r i s o n , t h e s t e p w i l l b e e x e c u t e d . l f t h e i n d i c a t o r i s o f f , t h e s t e p w i l l
not be executed.

4.

T E S - I - Ze x a m i n e st h e z o n e p o r t i o n o f t h e l e f t m o s t c h a r a c t e ri n a n a l p h a m e r i cf i e l d .
l f t h i a tp o s i t i o nc o n t a i n s& o r A - 1 ,t h e p l u s i n d i c a t o rw i l l t u r n o n . l f t h a t p o s i t i o n
I
c o n t ; l i n s- ,
J - R , t h e m i n u s i n d i c a t o rt u r n s o n . F o r a l l o t h e r c h a r a c t e r st h
,e
i ,or
z e r o I n d t c a t o rt u r n s o n .

tr

o'>
a. orl
D. On
c. off
d. ojf

6.
a.

9C;
off

D . orl

off
d . off

94
off
off
on
off
97
on
ofi
off
on

95
off
off
off
on
98
off
off
on
off

L o o k a h e a da l l o w s y o u t o u s e d a t a o n t h e n e x t r e c o r d t o b e p r o c e s s e d .N o r m a l l v
o n l y t h e d a t a o n t h e r e c o r d c u r r e n t l y b e i n g p r o c e s s e di s a v a i l a b l et o t h e R p G l l p r o g r a m . L o o k a h e a di s m o s t o f t e n u s e dw i t h i n p u t f i l e s . l f i t i s u s e dw i t h c o m b i n e d
o r u p d a t e f i l e s , i n f o r m a t i o n i n t h e l o o k a h e a df i e l d w h i l e t h e c o m b i n e d o r u p o a r e
f i l e i s b e i n g p r o c e s s e dw i l l b e f r o m t h e r e c o r d c u r r e n t l y b e i n g p r o c e s s e dn, o t f r o m
the next recordin the file.
tt.

**

m u s t b e s p e c i f i e di n c o l u m n s 1 9 - 2 0 t o i n d i c a t et h a t t h e f i e l d s l i s t e d a r e t o b e
l o o k e r da t i n t h e n e x t c a r d a v a i l a b l ef o r p r o c e s s i n g .L o o k a h e a df i e l d s m u s t b e g i v e n
d i f f e r e n t f i e l d n a m e st h a n t h o s e u s e dw h e n d e s c r i b i n gt h e f i l e . A n y a l p h a b e t i c
c h a r a c t e r sm a y b e u s e d i n c o l u m n s 1 5 , i 6 .

A n s w e r sT o R e v i e w 5

5--17

I

RPG

IBM
l,r ,

r

i

INPUT SPECF
I ICATIONS

,

I
.

L , r r t I

i j t . , l L l r j L

l

i , r f

l , r

; . 1
i
!i

l

l
i

, r
, .

, f_
_1I
o]iennz,ul

',1) 32+ sc
lDr
331 3
I

?ffrroHI
I

rl
6i lNExr Nq
9,6i 9 bl lNxIcD I

9.

T h c r i g h t h a n d ,l o w o r c l e rp o s i t i o r ro f F a c t c r 2 i s m o v e d f i r s t , t o t h e r i q h t h a n t l ,l c - . r i
o r d e r p o s i t i o no f t h r : R e s u l tF i e l d .

x0.

l f F a c t o r 2 i s l a r g e r ,t h e n u n r b e r o f p o - s i t i o n sn t o v e dw i l l l t e e r l u a lt o t h e s i z i :o f t i r e
R e s u l ti r i e l d . l f F a c t o r2 i s s m a l l e r t, h c w h o l e f i e i d w i l l L r er r o v e d a n d t h e l e f t h a r r r i
p o s i t i o r r so f t h e R e s u l t F i e l d w i l l b e u n c h a n g e c l .

11

W i t h M l ) V E L , t h e l e f t m o s tp o s i t i o no f F a c t o r2 i s m o v e c tJi r s t t o r h e l e f t n r o s ip o : r
t i o n ( ' f t h e R c s u l tF r e l d .

12

T h e s i g no f t h r . ,R e s u l t F i e l d a t t e r a M O V E L o l r e r a t i o ni s l r e r fo i r n e d w i i l b c t h e s a i r r t :
a s t h a t r t f t h e i o w ' o r d e rc h a r a c t e or f F a c t o r2 L r n l e sFsa c t o r 2 i s s r n a l l etrh a n t h e R c
s u i t F i c l d i n w h i c h c a s et h e s i - c 1i snu r i c h a n g e r l .
i

I J

3 /u

a.876ii3456
b. B76a;
c. 4321
d.3456432i

14.

B r a n c h i n ga l t e r st h e s e c l u € l n ci rer w h r c h c a l c u i a t i o r rasr e e x e c u t e d . l t a l l o w sV O ut o
a. SkiI cirlculation
ol)erati()n\.
b . E x e c u t eo p e r a t i o n si n a n o r d e r o t h e r t h a n t h e r - r o r m asi c q L l e r t i aot r d € r ' c . P e r f o r mt h e s a m ec a l c u l a t i o nsse v e r atli m e s i n o n e c v c l e .

15.

B r a n c h i n gi n R P G l l i s s p e c i f i e db y t h e o p r e r a t i o nGsO T O a n d T A G . G O T O t e l l st h c .
-tAC
c o m p u t e r t o b r a n c h t o a l o c a t i c l ni n d i c a t e di n F a c t o r 2 o f t h e i r r s t r u c t i o r r .T h e
s t a t e m e n ti s p l a c e da t t h e p o i n t i n y o u r p r o g r a mt o \ , v h i c hy o u w a n t t o b r a n c f r . T h e
n a m e i r r F a c t o r ' i o f t h e T A G s t a t e r n e nits t i r e s a m ca s t h e n a m e i n F a c t o r2 o f t h e
a p p r o p r i a t eG O T O . E v , e r yG O T O r e c l u i r eas T A G o r t h e p r o o r a mw i l l n o t k n o w
w h e r e t o b r a n c h t r . ) . S e v e r a lG O T O s t a t e m e n t sm a y b r a n c h t o t h e s a m . rT A G , b u t t l - i e
n a f f r eo n e a c h T A G s t a t e m e n tm u s t b e U n t u u e .

1 6 . condition severarGoro

statementswith the various record type indicators. write
t h e s e t o f s p e c i f i c a t i o n sf o r e a c h r e c o r d t y p e
s e p a r a t e l ya n d i n c r u d et h e m i n t h e p r o _
g r a r n . T h e s e t o f s p e c i fi c a t i o n sf o r e a c h
r e c o r d t y p e w i l l b e g i nw i t h a T A G s t a t e m e n t
a n d e n d w i t h a G O T O s t a t e m e n tw h i c h b r a n c h e s
t o t h e e n d o f a l l c a l c u l a t i o n s .T h e
program will test the record type and
branch to the correct set of specifications. At
t h e e n d o f t h e s e t o f s p e c i f i c a t i o n si,t w i l l b r a n c h
a r o u n d a l l o t h e r s p e c i f i c a t i o n tso
t h e e n d o f t h e c a l c u l a t i o ns e c t i o n .

1 7 . l f a p r o g r a m h a sa r o o p , t h e r e m u s t b e s o m e w a y
to stop the rooping. The branch

back instruction must be conditioned so that when
certain conditions have oeen met,
t h e s t a t e m e n tw i i l n o t b e e x e c u t e d . r f t h i s c o n d i t i o n
i s n o t s p e c i fi e d o r c a n n o t b e
m e t , t h e p r o g r a mw i l l g o i n t o a n e n d l e s sl o o p .

t at_

A s u b r o u t i n ec a n b e u s e d w h e n e v e rt h e s a m ec a l c u l a t i o n s
m u s t b e e x e c u t e da t s e v e r a l
d i f f e l r e n tp l a c e si n a p r o g r a m .

1 9 . T h e f i r s t l i n e o f a s u b r o u t i n em u s t h a v et h e B E G S R
o p e r a t i o n c o d e i n c o r u m n s2 9 _ 3 2
w i t h t h e s u b r o u t i n en a m e i n F a c t o r 1 . T h e r a s tr i n e
i n a s u b r o u t i n em u s t h a v e
E N D S R o p e r a t i o nc o d e i n c o l u m n s 2 g - 3 2 . T h i s
l i n e c a n h a v ea n a m e i n F a c t o r 1 , a n d
t h i s n a m e c a n t h e n b e r e f e r e n c e db y a G o r o s t a t e m e n t .
E v e r y s u b r o u t i n er i n e m u s t
h a v eS R i n c o l u m n s 7 - 8 .

20.

N o b r a n c h e sc a n b e m a d e f r o m a G o r o s t a t e m e n t
w i t h i n a s u b r o u t i n et o a T A G
s t a t e m e n to u t s i d et h a t s u b r o u t i n e . N o b r a n c h e sc a n
b e m a d e f r o m o u t s i d et h e s u b _
r o u t i n e t o a T A G s t a t e m e n tw i t h i n t h e s u b r o u t i n e .

21.

A l l s u b r o u t i n e sm u s t a p p e a ro n t h e c a r c u r a t i o ns h e e t
a f t e r a i l d e t a i ra n d t o t a l
c al c ul a t i o n s .

22.

L 0 w o u l d b e u s e di f y o u n e e dt o p e r f o r m s o m e c a l c u l a t i o n
s t e p sa t t o t a l c a l c u l a t i o n
t i m e a n d t h e r e i s n o n o r m a l c o n t r o l l e v e li n d i c a t o r ( L 1 - L 9 )
a v a i l a b l e .A c o m m o n u s e
o f t h i s i s t o s e t o n t h e o t h e r c o n t r o r r e v e ri n d i c a t o r sw h e n
c o n t r o r f i e r d sa r e n o t
a v ai l a b l e .

23'

D e t a i l c a l c u l a t i o n sa r e d i s t i n g u i s h e df r o m t o t a l c a l c u l a t i o n s
by the fact that columns
7 - 8 o f t h e C a l c u l a t i o ns h e e ta r e l e f t b l a n k f o r d e t a i l c a l c u l a t i o n s .
S i n c et h e c o n t r o l
l e v e l i n d i c a t o r s t a y so n t h r o u g h d e t a i l c a l c u l a t i o n s
i t c a n b e u s e dl i k e a n y o t h e r i n d i c a t o r i n c o l u m n s 9 - 1 7 t o c o n t r o l d e t a i l c a l c u l a t i o n s .T h e
c o n t r o l l e v e l i n d i c a t o rw i l l
be on for only the first card of a new control group.

24.

B l a n k a f t e r s h o u l d b e u s e dt o r e s e ta f i e r d t o z e r o t h a t i s
u s e dt o a c c u m u r a t ea n d
p r i n t a t o t a l f o r e a c hc o n t r o r g r o u p . T h i s
a i l o w st h e f i e r d t o s t a r t w i t h a z e r o
v a l u ef o r t h e n e w c o n t r o t g r o u p .

25'

B i t s w i t c h e sa r e u s e dt o c o d e a n d t e s t f o r s p e c i f i e ds i t u a t i o n s .
W i t h S y s t e m / 3M o d e l
1 0 D i s k S y s t e ma n d M o d e l 6 , t h e y a r e s t o r e d i n o n e - b y t e
a l p h a m e r i cf i e l d s i n s t o r a g e
a n d o n d i s k . O n e e x a m p l ei s c r e d i t i n f o r m a t i o n i n a n
a c c o u n t sr e c e i v a b l ef i l e . T h e
f i r s t b i t m i g h t m e a na C O D o n l y ; t h e s e c o n d ,p a y m e n t
due in 30 days;thethird,
c r e d i t l i m i t $ 1 0 0 0 ; e t c . w h e n t h e s ec o n d i t i o n sa r e c o d e d
a s b i t s w i t c h e st h e y t a k e
u p l e s sd i s k s p a c et h a n s i n g l ec h a r a c t e rc o d e st h a t m i g h t
b e u s e d i n t n e s a m ew a y .

26.

S e ec o d i n g s h e e t .

A n s w e r sT o R e v i e w 5

5-79

P a ; e o f G C 2 1- 7 5 6 7 - 2
l s s u e d2 4 M a y 1 9 7 6
By TNL: GN21-5389

1illi

T

t , l li

27.

Model l0 Citrd System.
o

M F C U i n p u t f i l e s ( n o s t a c k e rs e l e c t ;n o t a b l e o r d e m a n d f i l e s )

.

M F C U o u t p u t f i l e s ( n o s t a c k e rs e l e c t )

o

PRINTEIl ourput files

o P R l N T R i 2o u t p u t f i l e s
.

TAPE input file

.

TAPE output file

Model l0 Disk System and Model l2:
r

M F C U o r 1 4 4 2 i n p u t f i r e s ( n o s t a c k e rs e r e c t ;n o t a b r e o r d e m a n d f i r e s )

.

M F C U o r 1 4 4 2 o u t p u t f i l e s ( n o s t a c k e rs e l e c t )

o

P R I N T E F to u t p u t f i l e s

o

P R I N T R 2 Io u t p u t f i l e s

o

D I S K i n p u t f i l e s( s e q u e n t i aal n d d i r e c t o n l y )

.

D I S K o u t p u t f i l e s ( s e q u e n t i aal n d d i r e c t o n l y )

o TAPE input files
o TAPE output f iles

tilI

T I I-T

1r+1

Model 6:
.

D I S K i r r p u tf i l e s( s e q u e n t i a ln d d i r e c to r r l y ;n o s h a r e dl / O )

o D I S Ko u t p u tf i l e s( s e q u e n t iaanl dd i r e c to n l y ;n o s h a r e dl / O )
o D A T A 9 6 i n p u tf i l e s
M o d e l 1 5 : S a m ea sM o d e l1 0 D i s kS y s t e mp, l u s
.

2 5 0 1i n p u t f i l e s

o M F C M i n p u t f i l e s( n o s t a c k esr e l e c tn; o t a b l eo r d e m a n df i l e s )
o M F C Mo u t p u t f i l e s( n o s t a c k e sr e l e c t )

A n s w e r sT o R e v i e w 5

5-81

Chapter6. Match Fieldsand Multif ile Processing

C H A P T E R6 D E S C R I B E S :
H o w t o a s s i g nm a t c h f i e l d st r r o n e o r r n o r e f i l e s .
U s e o f n r a t c h f i e l d s t o s e q L r e n cceh e c k r e c o r d si n a f i l q .
U s i n gn r a l . c h i n gr e c o r d st o c o n t r o l t h e .p r o c e s s i n go f m u l t i p l e i n p u t f i l e s .

B E F O R E R E I \ D I N G T H I S C I . I A P T E RY O U S H O U L D B E A B L E T O D E S C R I B E :
H o v vt-o i d e r r t i f yi r r p u t r e c o r d t y p e s o n t h e l n p u t s h e e t .
H o w t o u s e f i e l d - r e c o r dr e l a t i o n "
H o w t o s p e c i f y s t a c k e rs e l e c t i o no n t h e M F C U .
R P G l l o b l e c t J : r o g r a mc y c l e "

AFTER READING THIS CHAPTERYOU SHOULD BE ABLE TO DESCRIBE:
C h e c k i n gt h e s e q u e n c eo f r e c o r d sw i t h i n a f i l e u s i n g m a t c h f i e l d s .
U s i n g m a t c h f i e l d s w i t h f i e l d - r e c o r dr e l a t i o n f o r m o r e t h a n o n e r e c o r d t y p e i n a f i l e .
M a t c h i n gr e c o r d sw f r e n t h e r e i s o n l y c . r n e
r e c o r dt y p e i n a f i l e .
R P G | | o g i c f o r p r o c e s s i n gf i l e s b y n r a t c h i n gr e c o r d s .
M a t c h i n gr e c o r d sw h e n t h e r e a r e m o r e t h a n o n e r e c o r d t y p e i n a f i l e .
M a t c h i n gr e c o r d sw h e n a i l c f t h e r e c o r d si n o n e o f t h e f l l e s h a v e b e e n p r o c e s s e d .
U s i n gm a t c h f i e l d s a n d c o n t r o l f i e l d s i n t h e s a m ef i l e .
H o w t o d e t e r m i n ew h e t h e r a f i l e s h o u l d b e p r i m a r y o r s e c o r r d a r y .
y'y'ote.'\/ou can use the review questions contained in Review 6 at the end of this
c h a p t e rt o t e s t y o u r c o m p r e h e n s i o no f t h e t o p i c s i n t h e c h a p t e r . A n s w e r sf o l l o w
the review questions.

M a t c h F i e l d sA n d M u l t i f i l e P r o c e s s i n g 6 - 1

INTRODUCTION
Match f ields are data fields on
separaterecords that are
c o m p a r e dt o e s t a b l i s l ai r e l a t i o n s h i p
b e t w e e nt h e r e c o r d s .
M a t c h f i e l d sh a v et w o f u n c t i o n s ,
O e p e n O i no
gn w h e t h e r t h e
r e t a t e dr e c o r d sa r e t h e s a m ei n p u t
type file or in separate
i n p u t t y p r ef i l e s . ( A n i n p . t t t y p e
file can be an input, update,
o r c r : m b i n e df i l e . i
Within a f ile, match f ielrJr;are used
to check the sequence
of records on which tirey 3ppg6p.
The sequencechecking is
a c c o m p l r s h e db y c o m p a r i n gm a t c h
f i e l d si n o n e r e c o r d w i t h
the match fielclsin thc next record
of the same file. When
t w o o r r n o r ei n p u t t y p e f i l e sa f e
u s e c ib y a p r o g r a m .t h e s e q u e n c eo f e a c h f i l e c a n
b e c h e c k e dj u s t a s s e q u e n c ew a s
c h e c k e df o r a s i n g l ef i l e . , A l l f i l e s
t h a t a r e s e q u e n c ec h e c k e d
by match fieldsmust be in the
s a m es e q u e n c ee, t t h e r a s .
c e r r d i r i go r C e s c e n d i n g .
I n a d d i t i o n t o s e q u e n c ec f r e c k i n g
r e c o r t j sw i t h i n a f i r e , m a t c h
f i e l d sc a n a l s o b e u s e d t o e r s t a b l i s h
a r e l a t i o n s h i pb e t w e e n
r e c o r d st h a t a r e i n s e p a r a t rf:i r e s .
T h a t i s , m a t c h f i e r d sc a n
be used to match records l,rarn
two ar more inpLtt type tiles
t o d e t e r r n i n ew h i c h r e c o r d i s t o
b e p r o c e s s e do n t n e c u r r e n t
c y c l e . l f t w o f i l e sa r e u s e c i n t h e
s a m ej o b a n o y o u d o n o t
s p e c i f y t h e o r d e r o f p r o c e s s i n gt,h e p r i m a r y
f ile is completely processedfirst. Only then are
records from secondary
files processed. By specifying
that the order of processing
ir; to be determined by conrparing
the contents ot match
fields, however, you can causerecorcls
from secondary files
tlhat are related to a record in the primary
file to be proc_
e s s e db e f o r e t h e n e x t p r i m a r y r e c o r d .
T h e p r o c e s s i n go f m o r e t h a r r o n e i n p u t
type f ile,with or
without match fields, is terrred multifile
processmg. Selection of records from more than one
file basedon the cont e r n t so f m a t c h f i e l d s i s k n o , w na s m u l t i f i l e
p r o c e s s i n gb y
m'atching rccords.
M u l t i f i l e p r o c e s s i n gi s c o m n r o n l y u s e d
i n a p p l i c a t i o n sw h e r e
d a t a f i l e s a r e s e t L l pt o c o n t a i n o n l y
a c e r t a i nt y p e o f i n f o r m a t i o n . F o r e x a m p l e ,a m a s t e rp a y r o l l
file might contain
dertawhich dces not change often,
such as an #ployee,s
pay rate. Another payroil fiire,
which wourd consist of new
rercordsevery week, might contain
data suctras tne number
of hours an employee workerd in
the week" To produce a
paycheck or other report, information
from both files
must be used. Furthermore, the records
from the two f iles
mList be processedin a partir:ularorder.
Matching records
can be used both to determine which
record to processon
eacn program cycle and to sequence
check the records with_
i n e a c hf i l e .

o-2

Note to Disk programnters; For ease
of depicting input reco r d s a n d f i l e s .c a r d - l i k er e c o r d sa r e
shown in illustrations
throughoutthis chapter. This does
not imply that the proce s s i n gr n u s t b e d o n e u s i n gc a r c if i l e s .
The filescan be reacl
f r o m a n y S y s t e m / 3 d e v i c et h a t c a n
b e u s e ca
Jsan rnput de,
vice. Also, throuqhoutthe chapter.
t w o i n p u t - t y p ef i l e s
a r e u s e d i n e x a m p l e st o i l i u s t r a t eR p G
ll logictor matching
r e c o r d s . R P G i l r o g i ca n d t h e r u r e sf o r
r e c o r d s e r e c t i o nr j o
n o t c h a n g ew h e n m o r e t h a r r t w o f i l e s
a r e u s e d . S e et h e
R P G l l r e f e r e n c em a n u a i f o r y o u r s y s t e r n
for examples
u s i n gm o r e t h a n t w o f i l e s .

C H E C K I N G S E O U E N C EO F R E C f } ! ? D $
WITHIN A FILE

File Containing Onty One Record Type
As you know, an A or D entrv madein
colurnn 1g of a file
d e s c r i p t i o ns p e c i f i c a t i o ni n d i c a t e st h a t
t h e r e c o r d si n t h e
file cjescribed
a r e t o b e i n s e q u e n c e .l f y o u s p e c i t y
that the
f i l e E M P L O Y E E i s r o b e i n a s c e n d i n g( A )
s e q u e n c ew
, hich
e m p t o y e er e c o r d si n F i g u r e 6 _ 1a r e i n
the correctorc.ler?
Actually all threearrangementshow the
f ile in ascending
o r d e r : t h e f i r s t i s s e q u e n c e db y d e p a r t m e n t
number,the
s e c o n db y n a m e , a n d t h e t h i r d g r o u p b y
e m p l o y e en u m b e r .
As you can see then, before the program
can check the se_
q u e n c eo f r e c o r d si n a f i l e , y o u
m u s t s p e c i f yt h e f i e l d o r
l i e l d s w h i c h a r e t o d e t e r m i n et h e
order. The fieldson which
t h e s e q u e n c ei s t o b e c h e c k e d ( c a l l e dm a t c h
f i e l d s )a r e i d e n _
t i f i e d o n t h e I n p u t s h e e tb y c o d i n g o n e
o f t h e e n t r i e sM 1 M 9 i n c o l u r n n s6 1 - 6 2 ( s e eF i g u r e 6 _ 2 ) .
R e c o r d sw i t h i n a f i l e m a y b e s e q u e n c e d
o n t h e b a s i so f o n e
or more dataf ields. Up to nine fieldsmay
b e u s e db y a s s i g n i n g o n e o f t h e e n t r i e sM l - M g t o e a c h m a t c h
field. Entering
M 1 o n t h e s a m e l i n e a s y o u d e s c r i b et h e
DEpT field (Figure
6-2) causesthe records to be sequence
checked according to
o e p a r t m e n tn u m b e r . T h u s , t h i s f i l e s h o u l d
be in ascending
orderasshown in the f irst group of Figure
6_1.
When you specify more than one match field
to check se_
q u e n c e ,t h e p t o g r a m c o n s i d e r s
ali the match fieldsto be one
c o n t i n u o u sf i e l d , e v e n t h o u g h t h e f i e l d s m a y
not be adjacent
i n a r e c o r d . F o r t h i s r e a s o n ,a l l m a t c h f i e l d s
a s s i g n e dt o a
particular record type are considered
to have the same type
o f d a t a ( a l p h a m e r i co r n u m e r i c ) . T h e i n d i v i d u a l
f i e l d sa r e
c h e c k e di n o r d e r a c c o r d i n gt o t h e l e v e lo f
the match f ield
e n t r y a s s i g n e dt o t h e f i e l d . M 1 i s t h e l o w e s t
l e v e l ;M 9 i s
c o n s i d e r e dt h e m o s t i m p o r t a n t .

425 i

AKRE JA

372

THOMASSE

372 /
361 /

THOMASSE

2043

03

037

218 !
t

DAHM PA

361 |

2043

03

037

//',

/',
NELSONKR /
l
DAHM PA

t

4061
3672

03
02

051
O17

NELSON KR

DEPARTMENT
N U M B ER

EMPLOYEE
NAME

425

AKRE JA

I

3186 r'

l

372

THOMASSE

I

05

029

1

ZOCS

EMPLOYEE
NUMBER

F i g u r e 6 - 1 . S e q u e n c e dF i l e s

M a t c h F i e l d sA n d M u l t i f i l e P r o c e s s i n q

RPG INPUTSPECIFICATIONS
C,"pr," I

GX21S4

Ca.d Elecro Num&.

;__;

""pi I lu

U/M O5o'

15 76 77 78 79 W

P'q'ism l--T*l-T-fT-t
ro*tiroro"t
I

I

I

J

I

I

Field Location

!

:

!

+

r

I

+

1
I

I
l Ll

1

Figure 6-2. Assigning a Matr:h Field
for Sequence Checking

T h e i n p u ts p e c i f i c a t i o ns sh o w ni n F i g u r e
6 - 3 s h o wt h a t
t h r e ef i e l d so n a n E M p L O y E Er e c o r d
a r et o b e u s e df o r
sequence
checking.Sinc,sall recordsin a particutar
region
a r et o b e t o g e t h e rt,h e R i E G I O N
f i e l d i s a s s i g n etdh e h i g h est (M3) matchfield entry and,thus,
is checkedfirst.
D S T R C Ti s t h e n e x t m a t , c h
f i e l d ( M 2 ) ,a n OD E p T i s t h e
l a s t( M 1 ) .

Figure6-4 showsthreerecordsfrom the
EMpLOyEEf ile.
The threematchf ieldsshownwould be
considered
one
field. lf the file is specified to be in ascending
order (on
the File Descriptionsheet),the recordsare
in ordersince
03037372is lower than 0305121g,which is
lowerthan
05029425. However.if the file is to be in
descending
sequence,record1 and record3 must
be switched.

RPG INPUTSPECI
FICATIONS

I

T

tl

l1

ti+

I f r

lfl

Figure 6-3. Assigning More than
One Match Field for Sequence
Checking

u/M o5o.

,.*ri'r.,:;ffiil,,..liffffi

l{ |ffi

rf
I !i

GX2t m!

+

I

l
1

425

AKRE JA

3186

05

029

M3

+

M2

M1

Record3 +

Fl--rl;l
Record 1 +

REGION
DSTRCT
DEPT
(M1)

Figure 64.

Region
(M3)

DSTRCT
(M2)

Match Fields Checked According to Level Assigned

Processinghalts when the first record out of sequenceis
read. You can then correct the order of the records to cont i n u e p r o c e s s i n g .N o t e , h o w e v e r ,t h a t o n l y a n e r r o r i n t h e
direction of the sequenceis det{rcted. When sequencechecki n g a f i l e w i t h m a t c h f i e l d s , R P G l l d o e s n o t c a u s et h e p r o c e s s i n gt o s t o p w h e n a d u p l i c a t em a t c h f i e l d i s r e a d . T h i s

I n t h e l a s t e x a m p l e ,a l l r e c o r d si n t h e E M P L O Y E E f i l e w e r e
t h e s a m er e c o r d t y p e ; t h a t i s , t h e y c o n t a i n e dt h e s a m et y p e
o f i n f o r m a t i o n i n t h e s a m el o c a t i o n o n e a c h r e c o r d . T h e r e f o r e , a p a r t i c u l a rm a t c h f i e l d c o u l d a l w a y s b e f o u n d i n c e r t a i n p o s i t i o n sf o r e v e r y r e c o r d i n t h e f i l e .

can be accomplished,however, by coding the sequencecheck
u s i n gc a l c u l a t i o ns p e c i fi c a t i o n s .

M a t c h F i e l d sA n d M u l t i f i l e P r o c e s s i n g 6 - 5

File ContainingMorethan One RecordType

the other employeerecords.Two differentrecorq
types
are necessary
because
salesmen
receivea percentcommis_
sionon sales,while other employeesreceivea set weekly
s a l a r y .A l t h o u g hc o m m i s s i oann d s a l a r yf i e l d sa p p e a r
on
o n l y c e r t a i nr e c o r d sa. l l E M p L O y E Er e c o r d sc o n t a i n
an
employeenumber,department,and district,as
shownin
Figure6-5. However,thesecommonfieldsappear
in differentlocationson differentrecordtypes.

rfVhen
sonreor all of the fieldson a recordare in
different
p o s i t i o n tsh a nt h e f i e l d so n o t h e rr e c o r d s
i n t h e s a m ef i l e ,
\/ou havedifferentrecord;types,
Supposeyour EMpLOyEE
f ile is madeup of two diffr:rentrecord
types,one type for
sralesmen
and one type for all other employees.An
S in
p o s i t i o n9 6 i d e n t i f i e rse c o r d so f
salesmen
a ;n O i d e n t i if e s

RPG INPUTSPECI
FICATIONS
-

l I
T
I e u n . n , n e/ c ' " d ( I

l

|
|
I '^"-'- F."* | r-r-il
'

-r

I

|

-J

|
I

-1| -tI -tl o , o r - , . " u - * l
I

L

I

_

o
R e c o r df o r O t h e r E m p l o y e e

Recordfor Salesman
Figure 6-5, File Containing Two Record Types

o-o

(ir2l 1&

I

l

**il"-

15 16 1/

!/M 60,

7A 79 aO

P'q'dm [-T_TT-T-T--]
to-',r-r,-l
t_L I | |

I

[ : o r t h i sp a r t i c u l apr r o g r a my, o u w a n ta l i s to f a l l e m p l o y _
eres,
in ascending
sequence
accoroingto district. Further_
rnore,the recordswithin a districtareto be in sequence
accordingto departmentand employeenumbers.To ensure
the sequence
of the file, threefieldson eachrecordmust be
c h e c k e da, ss h o w ni n F i g u r e6 - 6 . D I S T R C Ti s t h e m o s ti m portantcategoryand,therefore,is assigned
the highest
nnatchfield entry.
M3

M2

DSTiICT

Sincetherearetwo differentrecordtypes,a particular
m a t c hf i e l d m a y n o t a l w a y sb e i n t h e s a m er e c o r dp o s i t i o n s .
F o r i n s t a n c eD, S T R C Ti s i n p o s i t i o n s1 5 - 1 6o n s a l e s m e n
records,and in positions2Q-21on recordsfor otner emp l o y e e sY
. o u m u s tt e l l t h e p r o g r a mw h e r et o l o c a t et h e
match fields for eachrecord type (Figure6-7). Oncethe
programdetermines
the recordtype by checkingthe code
i n p o s i t i o n9 6 , i t t h e n l o o k sa t t h e a p p r o p r i a tm
e a t c hf i e l d
positionsfor that recordtype.

M1

DEPT EMPNUM
RecordType "O" for Other Employee

t;

3

L '

M3

Record Type "S" for Salesman

425

07

Figune6-6. Match Fields in Different Locations on Two Records

RPG INPUTSPECIFICATIONS

,,*! 1.,-l;fi;r.,.
i-iliill
Fickl
I ndicators

!
.9

!
6

!€
,,tr
g E
!

5 -

Fiigure6-7, Assigning Match Fields to Different Record Ttrrpes

M a t c h F i c l d sA n d M u l t i f i l e P r o c e s s i n g 6 - 1

F i e l d sf r o m d i f f e r e n t r e c o r d t y p e s w h i c h h a v e r r e e n
assigned
t h e s a m em a t c h v a l u e m a y h a v et h e s a m en a m e .
As shown
i n F i g u r e 6 . 7, M 2 h a s b e e r ra s s i g r . r ebdo t h t o t h e
DEp-f f ield
o n s a l e s m a nr e c o r d sa n d t o t h e D E p T f i e l d o n o t h e r
em_
ployee records.
l f m a t c h f i e l d s a r e a s s i g n e dt o m o r e t h a n o n e r e c o r c l
type in
a p r o g r a m ,a l l o f t h e r e c o r d s( w i t h m a t c h f i e l d s ) r n u s t
be
a s s i g n e dt h e s a m en u m b e r o f m a t c h f i e l d s . F u r t h e r r n o r e ,
all
m a t c h f i e l d s ( o n d i f f e r e n t r e c o r dt y p e s )w h i c h
a r e g i v e nt h e
s a m ev a l u e( M 1 M 9 ) m u s t b e t h e s a m el e n g t h . T h u s ,
all M1
f i e l d s m u s t b e t h e s a m el e r r g t h ,a l l M 2 f i e l d s r n , - l s r
trethe same
l e n g t h ,a n d s o o n . T h i s , o f c o u r s e ,m e a r r st h a t t n e
rotal
l e n g t h o f t h e m a t c h f i e l d s m u s t l l e t h e s a r n ef o r e a c h
of the
recoros.
I n t h i s e x a m p l e ,t h e E M p LO y E E :f i l e c o n t a i n so n l y
two
t y p e s o f r e c o r d sa n d b o t h a r e a s s i g n e dm a t c h f i e l d e n t r i e s .
l l o w e v e r , m a t c h f i e l d sn e e d n o t l t e s p e c i f i e cflo r
all recorc.l
t y p e s i n a f i l e . R e c o r d t y p ' s 5w h i c h d o n o t c o n t a g r
matci.l
l ' i e l d sa r e p r o c e s s e di n t h e , c r d e rt h e y a r e r e a c l .
The sequence
c h e c k , t h e n a p p l i e so n l y t o t h e r r : c o r dr V p e st o w h i c h
r n a t c hf i e l d e n t r i e sh a v e b e e na s s i q n e d .

T J S I N GM A T C H F I E L D S W I T H F I E L D . R E C O R D
I I E L A T I O N F O R M O R E ' I ' H A N O N E R E C O R DT Y P E
IN A FILE
I n t h e l a s t e x a m p l e ,e a c h o f t h e r e c o r d t y p e s i n t h e E l V l ,
P L O Y E E f i l e i s d e s c r i b e dr n r i t ha s e p a r a t es e t o f i n p u t
specif i c a t i o n s . S i n c ea l l o f t h e f i e l d st o b e u s e df o r m a t c h t n g
are
i n d i f f e r e n t c o l u n r n so n t h e d i f f e r e n t r e c o r d t y p e s , t h e s a m e
m a t c h f i e l d e n t r i e sa r e a s s i g n e do n c e f o r e a c h r e c o r d t v o e .

DEPT
(1-3)

DSTRCT
(8-9)

COIVIM
(14_t5l

EMPNUM
125-27]'

M a t c h F i e l d st h e S a m e f o r A l l R e c o r d T y p e s
O f t e n , h o w e v e r ,y o u m a y f i n d r . h a ta l t h o u g h t l r e r ea r e d i f ,
f e r e n t r e c o r d t y p e s i n a { i l e , r n a n y o f t h e f i e l d sa r e t h e
same
o n a l l r e c o r d t y p e s . T h a t i s , r n a n y f i e l c l sh a v et h e s a m e
n a m e ,c o n t a ! nt h e s a m et y p e o f d a t a ,a n d a r e a l w a y sf o u n d
i n p a r t i c u l a rp o s i t i o n so f a n y r e c o r dt y p e i n t h e f i l e . F o r
e x a m p l e ,s a l e s m e nr e c o r d sa n d o t h e r e m p l o y e er e c o r o s
r n i g h t b e o r g a n i z e da s s h o w n i r r F i g u r e 6 _ g . F o r r , o t h
rec_
o r d t y p e s ,a l l f i e l d sa r e t h e s a m ee x c e p tt h e C O M M a n d
S A L A R Y f i e l d sa n d t h e r e c o r di d e n t i f y i n gc c d e i n p o s i t i o n
96.
W h e n o n l y a f e r , nf iye l d s d i f f e r , r e c , . . r rtdV p e sc a n b e d e s c r i b e d
o n t h e I n p u t s h e e ti n a n O R r e l a t i o n s h i p l. n s t e a col f u s i n g
s e p a r a t es e t so f i r r p u t s p e c i f i c a t i o n sc, o m m o n f i e l d s n e e d
t o b e c J e s c r i b eodn l y o n c r : . A s s h o w r ri r r F i g u r e6 _ 9 ,e n t r i e s
u n d e r F i e l d R e c o r c lR e l a t i o n ( c o l u m n s6 3 _ 6 4 )c a n t h e n
i d e n t i f y t h e f i e l d sw h i c h a r e u n i q u e t o a p a r t i c u t a rr e c o r d
t y p e . N o t i c et h a l f i e l d sw h i c h a r e t h e s a n r ef o r a l l r e c o r d
t y p e s a r e d e s c r i b e df i r s t . A l l f i e l d sr e l a t e dt o a p a r t i c u l a r
r e c o r d t y p e a r e t h e n d e s c r i b e db e t o r e s p e c i f , r , i ntgh e f i e l d s
r e l a t e dt o o n e o { t h e o t l r e r r e c o r d t y p e s .
D S T R C T ,D E P T , a n d E M P N [ J Ma r e t h e t h r e e m a t c h f i e l d s
t o b e u s e di n s e q u e n c e
c h e c k i n qt h e E M p L O y E E f i l e .
S i n c et h e y a r e r l e s c r i b e od n l y o n c e o n t h e I n p u t s h e e tw i t h _
o u t a n y f i e l c lr e c o r d r e l a t i o ne n t r i e s ,t h e m a t c i r f i e l d e n t r i e s
a i s o n e e d b e a s s i g n e do n l y o n c e ( F i g u r e 6 - g ) . W h e n r e c o r d
t y p e s a r e d e s c r i b e di n a n O R r e l a t i o n s h i pa n c la m a t c h f i e l d
e n t r y i s a s s i g n e dt o a f i e i d w i t h o u t a n y f i e l d r . e c o r dr e l a t i o n
e n t r y , t h e m a t c h f i e l d w i l l b e u s e df o r a l l r e c o r d r y p e s .

S a l e s m a nR e c o r d

S

DEPT
(1-3)

DSTRCT
(8-9)

SALARY
(13-17)
Other Employee Record

F i g u r e 6 - 8 . S a m eM a t c h F i e l d sf o r B o t h R e c o r d T y p e s

o"6

P a g eo f G N 2 1 - 7 5 6 7 - 2
l s s u e d2 4 l M a y1 9 7 6
By TNL: GN21-5389

RPG INPUTSPECTFICATTONS

iiirl

++l1r
iil

**iil",-

la

! 0 9 4 7 1 rv l r o

tti I t

)B l\J 8A

P"arJ" I l l ll
l t
r d e , ' , r , , " . , , l _ L lj L I I

6
!
9

9

:

-i;

a

q:'

a

!,E

I

I

i l

I

iil

I

f

I

I'
t,

I

i ' ,
i ' l

l-

Ir
t-

F i g u r e 6 - 9 . A s s i g n i n gM a t c h F i e l d s O n c e f o r
Two Record Types

Match Fields Differ Between Record Types
I n t h e l a s t e x a m p l e ,a l t h o u g h s o m e f i e l d sd i f f e r e o
between
r e c o r d t y p e s ,a l l t h e f i e l d s t o b e u s e d i n m a t c h i n g
were tne
s a m e ( s a m en a m e , f o r m a t , a n r j r e c o r d p o s i t i o n s ) .
Suppose,
n o w e v e r ,t h a t o n e o f t h e m a t t ; hf i e l d s ,
DEpT, is in different
r e c o r d p o s i t i o n sf o r e a c h r e c o r d t y p e .
T h e t w o r e c o r c lt y p e s
n t h e E M P L O Y E Ef i l e a r e s h o w n i n F i g u r e
6-10.

S A L E S M A NR E C O R D
( R e c o r dl d e n t i f y i n g I n d i c a r o r0 1
turns on when this record type is read.)

EMPNUM
(1 - 3 )
utrr |

(5-7)
387

SALARY
(10-14)
I

|

I

O T H E R E M P L O Y E ER E C O R D
D:iTRCT

Qo_211

+-l--_-l__
293 07564

( R e c o r dl d e n t i f y i n g I n c l i c a t o 0r 2
turns on when this record type is read.)

o

Figure6-10. Match FieldsDiffer Between
Record Types

Match Fields And Multifile processirr,l

6-9

A c c o r d i n g t o w h a t y o u h a v e l e a r n e ds o f a r , y o u m i g h t
as_
s i g n m a t c h f i e l d e n t r i e sa s s h o w n i r r F i g u r e 6 - 1 1 .
H o ' w e v e rt,h e s p e c i f i c a t i o n s h o w n i n F i g u r e 6 _ 11 w i l l
not
w o r k . T h e r e i s a n a d d i t i o n a lr u l e t o r e m e m b e r
tn assrgning
m a t c h f i e l d e n t r i e sw h e n f i e l d _ r e c o r dr e l a t i o n i s u s e d
and
t h e rm a t c h f i e l d sd i f f e r b e t w e e nr e c o r d t y p e s . l f o n e ( o r
m o r e ) o f t h e m a t c h f i e l d s i n e i t h e r f i l e i s a s s i g n e dw i t h o u t
a f i e l d - r e c o r dr e l a t i o n ,t h e r e s t o f t h e m a t c h f i e l d s
must be
a s s i g n e di n t h e s a m ew a y , w i ; t h o u te n t r i e si n c o l u m n s
63-64.
O f c o u r s e ,t h e s p e c i fi c a t i o n sw h i c h a s s i g ns o m e o t
these
m a t c h f i e l d s w i t h f i e l d - r e c o r crle l a t i o na r e s t i l l n e c e s s a r y .
N o t i c ei n F i g u r e6 - 1 1 t h a r t n , o o f t h e m a t c h f i e t d s( M 1
and
M 3 ) a r e a s s o c i a t e dw i t h a l l r e c o r d t y p e s ( w i t h o u t f
ield_
r e c , o r dr e l a t i o ne n t r i e s ) . T h e r e f o r e ,a n a d d i t i o n a le n t r y
( d u m m y e n t r y ) s h o u l db e m a d e ( s e e
l i n e 0 5 o f F i g u r e6 _ 1 2 )
t o a s s i g nt h e M 2 m a t c h f i e l d ( D E p T ) t o a l l r e c o r d t y p e s
atso
A c t u a l l y t h e M 2 m a t c h f i e l d i s n , t t h e s a m ef o r a t i r e c o r d
t y p e s , s i n c e t h e l o c a t i o n o f t h e f i e l d v a r i e s . T h e r e f o r e ,h o w
d o ' y o u k n o w w h i c h e n t r i e st o m a k e i n t h e F i e l c tL o c a t i o n
c o l u m n so f t h i s d u m m y m a t c h f i e l d e n t r y ? y o u k n o w
that
a n y o n e m a t c h f i e l d i s a l w a y st h e s a m e l e n g t h , r e g a r d l e s s
of
r e c o r d t y p e o r l o c a t i o n i n t h e r e c o r t J .I n t h i s c a s e ,
DEpT is
t h r e e p o s i t i o n sl o n g . A n y n u m b e r sw h i c h g i v e t h e c o r r e c t
l e n g t h o f t h e m a t c h f i e l d c a n b e s p e c i f i e da s F i e l d
Location.
A s s h o w n i n F i g u r e6 - 1 2 , p o s i t i o ns 1 2 - 1 4a r e s p e c i fi e d f o r
t h e d u m m y m a t c h f i e l d . W h e n t h i s s p e c i fi c a t i o n t i n e i s
oer_
f o r r n e d ,t h e p r o g r a m l o o k s a t t h e t h r e e p o s i t i o n so t d a t a

( p o s i t i o n s1 2 - 1 4 ] o
r n w h i c h e v e rr e c o r d t y p e w a s r e a d . O f
c o u r s e ,t h e M 2 m a t c h f i e l d i s n o t i n p o s i t i o n s 1 2 _ 1 4o n
e i t h e r r e c o r d t y p e s o y o u d o n , t w a n t t h i s i n c o r r e c td a t a t o
b e u s e d i n s e q u e n c ec h e c k i n g . l t w o n , t b e , b e c a u s e
all of
the match field entries are checked before the sequence
checking is performed. lf the record read is record type 01,
l i n e 0 7 i s p e r f o r m e d . T h i s e n t r y t e l l s t h e p r o g r a mt h a t t h e
d a t a i n p o s i t i o n s1 0 - 1 2s h o u l db e u s e df o r t h e M 2 f i e l d . O n
t h e o t h e r h a n d , i f r e c o r d t y p e 0 2 i s r e a d .l i n e 0 g i s p e r f o r m e d a n d t h e d a t a i n p o s i t i o n s5 - 7 i s u s e d i n s t e a do f
that
i n p o s i t i o n s1 2 - 1 4 . A c t u a l l y , t h e n , w h e n e i t h e r o f t h e s p e c i f i c a t i o n si n l i n e s0 7 o r 0 8 i s p e r f o r m e d ( d e p e n d i n go n r e c _
o r d t y p e ) , t h e d a t a u s e da s t h e m a t c h f i e l d i s c h a n g e d ,a s i f
t h e d u m m y e n t r y h a d n e v e r b e e n s p e c i fi e d .
A l t h o u g h t h e s p e c i fi c a t i o n si n F i g u r e 6 - 12 w i l l c a u s et h e
E M P L O Y E E f i l e t o b e s e q u e n c ec h e c k e dc o r r e c t l y ,t h e r e i s
a w a y t o r e d u c et h e n u m b e r o f s p e c i f i c a t i o n sr e q u i r e d . A s
m e n t i o n e d ,f o r a d u m m y e n t r y y o u c a r rs p e c i f ya n y r e c o r d
p o s i t i o n sw h i c h g i v e t h e c o r r e c t l e n g t h f o r t h e m a t c h f
ield.
H o w e v e r .i f y o u s p e c i f y t h e a c t u a l p o s i t i o n sa s s o c i a t e dw i t h
t h a t m a t c h f i e l d o n o n e o f t h e r e c o r dt y p e s , t h e r e r s n o
n e e d f o r t h e s p e c i fi c a t i o n w h i c h r e l a t e st h o s e p o s i t i o n st o
t h e m a t c h f i e l d f o r t h a t r e c d r d t y p e ( F i g u r e6 _ 1 3 ) . T h u s ,
b y e n t e r i n g1 0 t o i 2 ( l i n e 0 5 , F i g u r e6 - 1 3 ) a s t h e p o s i t i o n s
f o r t h e M 2 f i e l d , y o u c a n e l i m i n a t et h e m a t c h f i e l d e n t r y
( l i n e 0 7 ) i n w h i c h t h e M 2 f i e l d i s d e s c r i b e df o r r e c o r d
tvoe

01.

;;, ,;;;l

RPG INPUTSPECIFICATIONS

l

1

2

tl--r

PaiEL

|-],,'

llccor(l ldeft,l i.aliorr Co(ks

:

' , ,

l+:J

;1,i li

;FI T;

.f.i fi
0 5l lr

;I;I Ti

;r,l l;

F i g u r r - ' 6 - 1 1 . I n c o r r e c t M a t c h F i e l d E n t r i e sf o r R e c o r d s
D e s c r i b e dw i t h F i e l d R e c o r d R e l a t i o n

6 - 10

75 t6 t7

i8

I

7! 80

Pro!,r,n f lT
fl.l-.]
r d e n , , c d , i, Lo Ii L
l l

I

RPG INPUTSPECIFIC/{TiI)NS
IEll

,.,",,,,,"..,

Mdchn? co,Dora,on
",,,nes

Fleld Na'ne

|

-

t :

1f+:i

Dummy entry so that
a l l m a t c h f i e l d sa r e
a s s i g n e dw i t h o u t
f i e l d - r e c o r dr e l a t i o n .

P e r f o r m i n ge i t h e r o f t h e s e
s p e c i fi c a t i o n s a c t u a l l y v o i d s
what hasbeen done as a result
of performing the dummy entry.

F i g u r e 6 ' 1 2 . A s s i g n i n gM a t c h F i e l d s f o r R e c o r d s D e s c r i b e d
with Fierd Record Reration

RPG lNPUTSPECIFICATIONS
IBlf,

,.,.,^",,."",

Md,n.

(ix21 !B
u/M050.
h,nr&l,n U S A

corcora,on

","n.s
1

2

/ 5 7 6 1 7 J 8 J 9 8 O

r l
'- u *l L L
l o ' _ - , .t l q' ;, a'm, , . , ' ,l " . l1 l T - f - T | | I i I I

Record ldentif i@tion Codes

Fieki
Indicators

This entry eliminated
s i n c et h e d u m m y e n t r y
specifies the match field
i s i n p o s i t i o n s1 0 - 1 2 .

Figure 6-13. Eliminating Specificatiorrs in Assigning Match Field Entries

Dummy entry so that all match
f i e l d s a r e a s s i g n e dw i t h o u t f i e l d record relation.

M a t c h F i e l d sA n d M u l t i f i l e P r o c e s s i n g 6 - 1 1

A f t e r p e r f o r m i n gt h e d u m m y e n t r y ( l i n e
0b), tne program
knows the M2 match field is to be found
i n p o s r t i o n s1 0 - i 2
l f r e c o r d t y p e 0 1 i s r e a d ,t,h e M 2 f i e l d
actuallyis in posit i o n s 1 0 - 1 2 . T h u s , l i n e 0 7 d o e s n , th a v e
to be pertormed,
s i n c ei t d o e s n o t c h a n g e , a n y t h i n g .O f
c o u r s e ,i f r e c o r d t y p e
0 2 i s r e a d ,t h e s p e c i f i c a t i o ni n l i n e 0 g i s p e r f o r m e d .
This
s a y s ,f o r r e c o r d t y p e 0 2 , u s e p o s i t i o n s
5-7 tor the M2 field
instead of positions .l0_1 2.
T h e f i e l d n a m e s p e c i f i e df o r t h e d u m m y e n t r y
can be any
n a m e , s i n c ef i e l d n a m e sa r e i g n o r e d
i n s e l e c t i n gm a t c h
f i e l d s . I n t h i s c a s e ,D E p l - w a s s p e c i f
i e c ls i n c e i i h a p p e n s
that the M2 fieldson both recordtypes
h a v et h e s a m e
n a m e . l f t h e n a m e st o b € , u s e dd i f f e r ,
it is stilla goodpract i c e t o u s ea n a m e g i v e n t o t h e m a t c h f i e l d
on one ot the
record types.

MATCHING RECORDS: ONE RECORD
TypE tN EACH
F IL E
One of the most common forms of multif
i l e p r o c e s s i r . irng_
v o t v e su s i n go n e f i l e t o o b t a i n d a t a f r o m
a n o t h e rf i l e . F i g u r e 6 - 1 4 s h o w sa w e e k l y s a t e sr e p o r t t o
be printed which is
u s e dt o d e t e r m i n ew h i c h i t e m s a r e s e l l i n g
b e s ta t w h i c h
l o c a t i o n . A S A L E S f i l e c o n t a i n sr e c o r c J s
o f i n d i v i d u a li t e m s
s o l d ,g i v i n g t h e q u a n t i t y a n d l o c a t i o n . T h e
d e s c r i p t i o no f
r - ' a c hi t e m , h o w e v e r ,m u s t b e o b t a i n e d
from an ITEM mast e r f i l e . T h e I T E M m a s t e rf i l e c o n s i s t so f
one ITEM record
1 [ o re a c h i t e m i n s t o c k .

F o r t h i s p r o g r a m ,l e t , sa s s u m et h a t e a c h f
i l e c o n t a i n so n l y
o n e r e c o r d t y p e . A l l I T E M r e c o r d sa r e i n o n e f o r m a t
and are
i d e n t i f i e d b y t h e c h a r a c t e rI i n p o s i t i o n 1 .
A l l r e c o r d si n
t h e S A L E S f i l e a r e i d e n t i f i e db y a n S i n p o s i t r o n
1 and are
a l s o i n o n e f o r m a t ( c e r t a i nt y p e o f i n f o r m a t i o n
in same
l o c a t i o no n e v e r y r e c o r d ) . T h e S A L E S r e c o r d s
for a partic_
u l a r i t e m c a n b e a s s o c i a t e dw i t h t h e r e l a t e d
ITEM master
recordby a common match field containing
the item num_
b e r ( s e eF i g u r e 6 - 1 4 ) .

ProcessingOrder: More Than One Matching
Record in a
Secondary File
I n t h e I T E M m a s t e rf i l e , t h e r e i s o n l y o n e r e c o r d
for each
rtem,but in a programrun theremay be several
SALES reco r d s f o r t h a t p a r t i c u l a ri t e m . L e t u s s u p p o s et h e r e
isalways
a t l e a s to n e S A L E S r e c o r d f o r e a c h I T E M r e c o r d .
There_
f o r e , t h e r e s h o u l d b e n o r e c o r d si n e i t h e r f i l e
which do not
h a v ea m a t c h i n g r e c o r d i n t h e o t h e r f i r e .
B o t h f i r e sa r e s o e c i f i e d w i t h m a t c h f i e l d s i n a s c e n d i n gs e q u e n c e .
T o p r o d u c e t h e r e p o r t i n F i g u r e6 - 1 4 , i n w h a t
order should
r e c o r d sf r o m t h e t w o f i l e s b e p r o c e s s e d ?F i r s t
an ITEM
m a s t e rr e c o r d s h o u l d b e p r o c e s s e dt;h a t i s , t h e
item number
a n d d e s c r i p t i o np r i n t e d . T h e n , a l l t h e S A L E S r e c o r d s
which
a r e f o r t h e s a m e i t e m ( m a t c h f i e l d st h e s a m e )
shouldbe
p r o c e s s e d .T h e q u a n t i t y a n d l o c a t i o n
o f e a c h s a l es h o u l d
b e p r i n t e d u n d e r d e s c r i p t i o n . T h u s ,a f t e r e v e r y
ITEM rec_
o r d p r o c e s s e do, n e o r m o r e S A L E S r e c o r d sm u s t
Deproc_
e s s e db e f o r e t h e n e x t r e c o r d f r o m t h e I T E M m a s t e r
file is
processed.
How does RPG ll know when to stop printing
SALES reco r d s a n d t o p r o c e s st h e n e x t I T E M ? A s w e s a i d ,
the SALES
r e c o r d sf o r a p a r t i c u l a ri t e m a r e r e a d o n e a t a
time and
printed, Whenthe match field on a
SALES recordis for a
different item, that SALES recordis not processed
immedi_
a t e l y . l n s t e a d ,t h e n e x t I T E M m a s t e rr e c o r d i s p r o c e s s e d
to
p r i n t t h e d e s c r i p t i o nf o r t h e n e w i t e m .
Then the SALES
r e c o r d sf o r t h a t i t e m a r e p r i n t e d . A s y o u c a n
s e e ,t o d e t e r m i n e t h e c o r r e c t o r d e r o f p r o c e s s i n gb, o t h f i l e sm u s t
be in
t h e s a m es e q u e n c ea c c o r d i n gt o t h e m a t c h f i e l d ;
in this case,
r n a s c e n d i n gs e q u e n c eb y i t e m n u m b e r .

o-lz

SALES File

lTElt/l File

s [ 11-rl 038

o4e

slTfl
sFot I

rIzgel

rm

NUM

s[rorl

ITNUM

D E S C R P\ P R I C E

157
062

OTY

LOCATT{

S E C O N D A R YF I L E

P R I M A R YF I L E
Match Field Containing
Item Number

SALES REPORT

ITEM
101

DESCRIPTION

OUANTITY

LCCATION

F
4S

62
t5I

49
38
67

MN
SD
SD
MN
WS
MN

-\-/-=./---\--

----7-=----

Data From
ITEM Records

Data From
SALES Records

Figure6-14. Matchings,ALEsRecordswithRelatedlTEMRecordstoProduceaPrintedReporl

6'13
M a t c h F i e l d sA n d M u l t i t i l e P r o c e s s i n g

How RpG lt Logic Detemines
a Record

From Which File to process

U s i n gt h e s a m ee x a m p l e ,l e t , s
s e eh o w t h e R p G l l l o g i c d e _
t e r m i n e sf r o m w h i c h f i l e
a recordis to be processed.
The
I T E M m a s t e rr e c o r d sa r e
t h e p r i m a r y f i f. , " 0 t h e
SALES
r e c o r d sa r e t h e s e c o n d a r yf i l e .
W h e n t w o i n p u t f i l e sa r e
u s e d i n a p r o g r a m ,t h e p r o g r a m
c y c l e i s s t i g f , t t yd i f f e r e n t f o r
t h e f i r s t r e c o r d r e a d .y o u
can follow the lJgic flow shown
in
F i g u r e6 - 1 5 a s w e d i s c u s s
t h e f i r s t p r o g r a mc y c l e a n d
s
u
b
s e q u e n tc y c r e sf o r t h i s j o b . p a y
s p e c i a ra t t e n r t o nt o w h e n
the recordidentifying
i n d i c a t o ri s o n . i d e n t i t y i n g
the rec_
o r d t o b e p r o c e s s e da, n d w h e n
t h e M R i n d i c a r o rt s t u r n e d
on and off.
, A t t h e b e g i n n i n go f t h e f i r s t p r o g r a m
c y c l e ( F i g u r e6 - j 5 ,
part A), a recordis read
f r o m e a c hf i l e . T h e t i r s t
stepis to
d e t e r m i n ew h i c h r e c c

)jle
rninesif mut"r,riera, ll,iJl"_T';"1
[ i#:::l tH;.
I n t h i s c a s e ,b o t h t h e I T E N 4
r e c o r da n d

the SRLES record
containan M1 field. The rnatch
f i e l d sf r o m e a c hf i l e a r e
t h e n c o m p a r e dt o s e ew h i c h
i s l o w e r i n s e q u e n c e .( l f
the
file had been in descending
sequence,tro Jiogrurn *ouro
c h e c k f o r t h e h i g h e s tm a t c h f i e l d . )
I n t h i s c a s e ,n e t t h e r
f ieldis lower asthe match
f i e l d so n t h e p r i m a r y a n d
seco n d a r y r e c o r d sa r e b o t h 1 0 1 .
W h e n m a i c f , t i e t O sf r o m t h e
t r v o f i l e s a r e t h e s a m e ,t h e r e c o r d
from the primary file is
a l w a y ss e l e c t e df o r p r o c e s s i n g
N o w t h e a p p r o p r i a t er e c o r o l
i d e n t i f y i n g i n d i c a t o ri s t u r n e d
on to identify the type of record
selectedfor processing.
-ftus,01
would be turned on for the ITEM
r e c o r c lf r o m t h e
primary file.
Orrcea record is selectedfor processing
and the record
i c r - ' n t i f y i n gi n d i c a t o r i s t u r n e d
o n , t h e p r o g r a md e t e r m i n e s
v y h e t h e rt h e M R i n d i c a

orthe
record.
since
;:T:iff i.,ff,T..il;:ilffi,ili,,

a r n a t c h i n gr e c o r d c o n d i t i o n e x i s t s .
T h e M R i n d i c a t o ri s
not turned on yet, however,
becausethe selecteorecord
is
not ready to be processedyet.

F i r s t , t h e p r o g r a mc h e c k st o
s e ei f a n y t o t a r o p e r a t i o n sa r e
t. be performed for previousry processed
records. Total
c a l c u l a t i o n sa n d t o t a l o u t p u t
a r e p e r f o r m e do n l y i f c o n t r o l
fi,:lds change or if the last rec;ord
in the file has already been
p r o c e s s e d( L R o n ) . S i n c e
t h e r r ea r e n o c o n t r o l f i e l d s i n
e i t h e r f i l e , c o n t r o l l e v e li n d i c a t o r s
w i l l n e v e rb e t u r n e d o n
during this program. Furthermore,
t h i s i s n o t t h e t a s tr e c o r d .
N e i t h e rc o n d i t i o n h a s o c c u r r e r d ;
t h e r e f o r e ,t o t a l _ t i m eo p e r a _
tions are bypassed.

6-14

At this point, the MR indicator
i s t u r n e d o n t o i n c i i c a t et h a t
t h e m a t c h i n gr e c o r d c o n c l i t o n
e x i s t s . N o w t h e p r o g r a mi s
reaoyto perforrniite detail
o p e r a t i o n sf o r t h e r e c o r d w h i c h
w a s s e i e c t e df o r p r o c e s s i n g .
Thus,the item number and
d e s c r i p t i o nf r o m t h e p r i m a r y f
i l e r e c o r da r e p n n t e d . T h e
program knows which
operations are to be performed
be_
c a u s et h e o p e r a t i o n sa r e e i t h e r
c o n d i t i o n e dt o b e p e r f o r m e d
only when recordidentifying
i n d i c a t o r0 1 a n d t h e M R i n _
dicatorareon or they are not
c o n d i t i o n e db y i n d i c a t o r s .
O n c e t h e p r o c e s s i n go f t h i s r e c o r d
i s c o m p l e t e d ,t h e r e c o r d
i d e n t i f y i n gi n d i c a t o r i s t u r n e d
o f f ( Q . lo t t j . f f r i s c o m p l e t e s
t h e f i r s t p r o g r a m c y c r e ;t h a t
i s , o n e r e c o r d h a so e e np r o c _
essed.
F o r t h e p r o c e s s i n go f a i l s u b s e q u e n t
r e c o r d s ,r o o k a t t h e
p r o g r a mc y c l e i n F i g u r e
6-15, part B. The entirecycle will
be repeatedfor each record processed.
A t t h e b e g i n n i n go f t h e f i r s t c y c l e .
a r e c o r dw a s r e a df r o m
both the primary f ile and the
5 e 6 e n d 6 ; yf i l e . H o w e v e r ,
s i n c eo n l y o n e r e c o r d i s s e l e c t e d
f o r p r o c e s s i n ga t a t i m e ,
o n e r e c o r d ( i n t h i s c a s e ,a S A L E S
r e c o r d ) s t i l t r e m a i n si n
t h e i n p u t r e a da r e a . T h e r e f o r e ,
a r e c o r dt - ,
onrVone file
i s r e a d a t t h e b e g i n n i n go f t h e
s e c o n dc y c r e a n d f o r a i l f o r _
l o w i n g p r o g r a mc y c l e s . T h e
r e c o r dr e a d w i l l b e f r o m t h e
s a m ef i l e a s t h e l a s t r e c o r d p r o c e s s e d .
Thus,for the second
c y c l e , t h e s e c o n dr e c o r d f r o m
the ITEM file would be read
i n t o t h e p r i m a r y f i l e r e a da r e a .
N o w t h a t a r e c o r d f r o m e a c hf i l e
i s i n t h e r e a o a r e aa g a i n ,
tne second record can be selected
for processing. Once
a g a i nt h e f i r s t s t e p i n t h e r o g i c
i s t o d e t e r m i n ei f m a t c h
f i e l d s a r e s p e c i f i e df o r t h e r e c o r d s
from both files. In this
p r o g r a m ,t h e r e i s o n l y
one recordtype per file and both
are
a s s i g n e dm a t c h f i e l d s . T h e r e f o r e ,
t h e a n s w e rt o t h i s q u e s tion is yes for every program cycle
of this program.
T h e m a t c h f i e l d sf r o m b o t h r e c o r d s
arethen compared. In
t h i s c a s e ,t h e s e c o n d a r yf i r e s A L E s
record isfor the first
i t e m n u m b e r ( i 0 1 ) . S i n c et h e
I T E M r e c o r df o r t h e f i r s t
i t e m ( 1 0 1) h a s a l r e a d y b e e n p r o c e s s e d ,
the primary file rec_
o r d i n t h e r e a da r e a i s f o r t h e s e c o n d
i t e m n u m b e r ( . 11 7 ) .
The match field on the SALES
recordis lower in sequence
than the match field on the ITEM
r e c o r d ;t h e r e f o r e ,t h e
SALES record is selectedto be processed.
Oncu again, a
recordidentifying indicator (02
f or a SALES record)is
turned on to identify the type
of record selecteo.
At this point, the MR indicator
i s s t i l l o n b e c a u s er n e o r e _
v i o u s c o m p a r i s o n( i t e m . l0 1 ) d i d g i v e
a match. The setting
o f M R h a sn o t h i n g t o d o w i t h t h e
r e c o r dw h i c h w a s j u s t
selectedfor processing. The indicator
will not be set to reflect the current condition until just
b e f o r et h e r e c o r d
s e t e c t e df o r p r o c e s s i n S( S A L E S r e c o r d
for item 101) is
processed.

S e c o n d a r yf i l e

P r i m a r yf i l e

H
F
''*
L yl'ii''_l/
o

o

o
a

a
\

o
Turn off record
i d t r n t i fy i n g i n d i c a t o r

t----1
7----1
1101 | llol
I
I rrsv I I snlps I
L___l
L---l

o

Read record
from each
file. Turn
LR if last
r e c o r d ;i f L R ,
go to Perform
total calculations.

Input Read Area
A r e m a t c h f i e l d s s p e c i fi e d
for both?
Yes, so compare match
t o s e l e c tr e c o r d
Turn on record identifying
indicator

P e r f o r mh e a d i n go u t p u t
and detail output for
s e l e c t e dr e c o r d

o

START

a
D e t e r m i n ew h e t h e r M R w i l l
be set on or off

a

o

Perform detail
calcu lat ions fo r
selected recor(l

C h a n g ei n c o n t r o l f i e l d ?
Yes,turn on control a
l e v e li n d i c a t o r

Tuln MR on or off
for selected record

O
Perform total
c a l c ul a t i o n s
Perform
total output

a

o
o

@

RPGll Logicfor FirstProgramCvcle

F i g u r e6 - 1 5 ( P a r t 1 o f 2 ) . L o g i c o f M a t c h i n g R e c o r d s

6-15
M a t c h F i e l d sA n d M u l t i f i l e P r o c e s s i n g

Primary f ile

START

I

o

S e c o n d a r yf i l e

ffiffi

o

I

a

\

o

Read record
from one of
files. Turn on

Turn off record
identifyingindicator

a

Are match fields
specified for both?
Yes, so compare match
fields to select record

P e r f o r m h e a d i n go u t p u t
and detail output for
selected recclrd

Tur.n on record identifying O
Inotcator

D e t e r m i n ew h e t h e r M R w i l l
oe set on or off

O

Perform detail
c a l c u l a l i o n sf o r
selecteclrecord

C h s n g ei n c o n t r o l f i e l d ?

I..::rr.l
revet

on controt1

Incticator

o

Turn MR on or off
for selectedrecord

o

Perform
total output

o
t

RPGll Logicfor Subsequentprogram
Cvcles
Figure 6-15 lpart 2 of
2 1 . Logic of Matching
Records

6 - 16

o

Sirrcethe next record to be prooessedhas been selected,the
R P G l l p r o g r a n rn o w d e t e r m i n e :h; o w t h e M R i n d i c a t o r i s
to be set for processingthis carcl. ls there a matching record condition? You are probablythinking that there is not,
b e c a u s et h e m a t c h f i e l d s a r e n o t t h e s a m e ( s e c o n d a r yf i l e ,
1 0 1; p r i m a r y f i l e , 1 1 7 ) . H o w e v , : r ,w h e n t h e m a t c h f i e l d s

For the restof the SALESrecordsrelatedto the first item
n u m b e r( 1 0 1 ) ,t h e c o m p a r i s oonf m a t c hf i e l d sw o u l di n d i catethat tlre secondaryfile recordsare lower in sequence
t h a nt h e i t e m n u m b e r( 1 1 7 )o n t h e I T E M r e c o r do f t h e p r i m a r yf i l e . T h u s ,a l l s a l e sr e c o r d sf o r i t e m 1 0 1 a r ep r o c e s s e d .
F u r t h e r m o r et h. e M R i n d i c a t o w
r i l l b e o n d u r i n gp r o c e s s i n g
o f a l l t h e r e c o r d ss, i n c et h e m a t c hf i e l d s( 1 0 1 )w i l l a l w a y s
be the sameasthe matchfield on the lastprimaryrecord
processed.

are not equal and a secondary file record has been selected,
t h e m a t c h f i e l d o n t h e s e c o n d a r yf i l e r e c o r d ( S A L E S ) i s t h e n
compared with the match field of the last primary file record processed.The last ITEM record processedhas a match

At the beginningof the next programcycle.a SALESreco r d f o r t h e n e x t i t e m n u m b e r{ 1 1 7 )w o u l d b e r e a d . O n
comparingthe SALES recordmatchf ield with the match
field on the ITEM recordin the readarea,thereis a match
a g a i n .T h e I T E M f o r i t e m 1 1 7W o u l dt h e n b e p r o c e s s ebde f o r et h e S A L E Sr e c o r d sf o r t h a t s a m ei t e m .

f i e l d o f 1 0 1 , t h e s a m ea s t h e m a t c h f i e l d o f t h e S A L E S r e c ord to be processed.Therefore, there is another matching
r e c o r dc o n d i t i o n .
T h e M R i n d i c a t o r i s n o t s e t a g a i na n d t h e r e c o r d s e l e c t e d
( S A L E S 1 0 1 ) i s n o t p r o c e s s e d( d e t a i lo p e r a t i o n sn o r p e r formed) until after any total oprlrationsto be done for previous records are completed. Sirrcethere are no control
f i e l d s a n d t h i s i s n o t t h e l a s t r e c , f , r di n t h e f i l e , t o t a l o p e r a t i o n s c a n b e s k i p p e d i n t h i s p r o l l r a mc y c l e .

Specifications for a Matching Records Program
F i g u r e6 - 1 6s h o w st h e t h r e es p e c i f i c a t i osnh e e t -s F i l e D e s c r i p t i o nI,n p u t ,a n d O u t p u t- t o b e u s e df o r t h i s p r o g r a m .
S i n c et h e d a t af r o m t h e t w o i n p u tf i l e si s o n l y t o b e p r i n t e d ,
c a l c u l a t i osnp e c i f i c a t i o nasr en o t n e c e s s a r y .

At this point, immediately beforreprocessingthe selected
record, the MR indicator is set. Although MR is alreadyon
for the previous record processed,it is set on again for the
p r o c e s s i n go f t h i s r e c o r d ( S A L E S r e c o r d f o r i t e m 1 0 1 ) . A l l
d e t a i l o p e r a t i o n sc o n d i t i o n e df o r r e c o r d t y p e 0 2 ( o r f o r b o t h
0 2 a n d M R i n d i c a t o r so n ) a r e t h e n p e r f o r m e d . T h u s . t h e
q u a n t i t y a n d l o c a t i o nf i e l d s o n t h e S A L E S r e c o r d a r e p r i n t e d .

T h e F i l e D e s c r i p t i o snh e e d
t e fi n e st h e t w o i n p u tf i l e st o b e
u s e di n m a t c h i n ga, sw e l l a st h e p r i n t e rf i l e ,o n w h i c ht h e
reportis to be printed. Noticethat the two input files must
b o t hb es p e c i f i ea
d s b e i n gi n t h e s a m es e q u e n c(eA i n c o l u m n 1 8 ) . T h e P a n dS e n t r i e si n c o l u m n1 6 i n d i c a t et o t h e
systemwhetheran input type f ile is to be considered
asa
p r i m a r yo r s e c o n d a rfyi l e "

A f t e r p r i n t i n g t h e S A L E S r e c o r r l ,p r c l c e s s i nfgo r t h i s r e c o r d
i s c o m p l e t ea n d r e c o r d i d e n t i f y i n g i n d i c a t o r 0 2 i s t u r n e d o f f .
I n t h e n e x t p r o g r a mc y c l e , a n o t h e r S A L E S r e c o r d i s r e a d
from the secondary file to repla,cethe SALES record just
processed.

F i l e D e s c r i p t i o n S p e c i fi c a t i o n
11'ro
ecorl

Address

F'crd

lecord

Adfress

Type

E x t e n tE x i t
for DAM
Device

t

Brock
Lengrh

I
I

Addlt

ofdl

L3be Exil

Device

i+#-

Core I ndex

AreJ

: t.,."t...

E.iry

irl
tii

)E

llt

I

-

'

i

i

i

i

r + +
l - 1 1

conditLor

I "',r:t l
I

!

Becdd
ie.qrh

'or Cyl nder Ovedlow

Name of

Symboli(

t
r-tll
. , L , l l

i il , r:

' I

I
l

I

I

T

F l g u r e 6 - 1 6 ( P a r t 1 o f 2 ) . S p e c i f i c a t i o n sf o r M a t c h i n g R e c o r d sp r o g r a m
M a t c h F i e l d sA n d M u l t i f i l e P r o c e s s i n g 6 - 1 7

GX2l m4

U/M O5o.

.9
3

!
.9

Onerecordtyp.;n GiE?E
in eachfile
c o n t a i ni n g
item number.

RPG

i

OUTPUT

Figure 6-16 (part Z ol 2}. Specifiications
for Matching Records program

6-18

SPECIFICATIONS

F i l ed e s c r i p t i osnp e c iifc a t i o n sal s oa s s o c i a teea c hi n p u t f i l e
w i t h a p a r t i c u l adr e v i c e .O n t h e M F C U ,t h e p r i m a r yf i l e i s
u s u a l l ye n t e r e dt h r o u g ht h e p r i m a r yh o p p e r( d e v i c e n t r y
M F C U l) ; t h e s e c o n d a rfyi l e i s u s u a l l yr e a df r o m t h e s e c o n d a r yh o p p e r( d e v i c e n t r y M F C U 2 ) . H o w e v e ri,n m u l t i f i l e p r o c e s s i nugs i n gt h e M F C U ,e i t h e rf i l e m a y b e a s s o c i atedwith eitherof the two hoppers.

A s y o u r e c a l il n t h e d i s c u s s i oonf m a t c h i n gr e c o r dl o g i c ,t h e
0 1 r e c o r di d e n t i f y i n gi n d i c a t o ri s o n w h e n e v ear n I T E M r e c , E M r e c o r d sa r e
o r d i s b e i n gp r o c e s s e dF. u r t h e r m o r eI T
p r o c e s s eodn l y i f a m a t c h i n gr e c o r dc o n d i t i o ne x i s t s( M R
o n ) . T h e r e f o r ec.o n d i t i o n i n tgh e p r i n t i n go f t h e i t e m n u m b e ra n dd e s c r i p t i o bn y M R a n d0 i e n s u r etsh a t t h e i n f o r m a '
t i o n i s c o m i n gf r o m t h e I T E M r e c o r d .

T h e c o n t e n t so f t h e t w o i n p u t f i l e sa r ed e s c r i b eodn t h e
I n p u t s h e e tw
, i t h a s e p a r a tsee to f s p e c i f i c a t i o n
f osr e a c h
f i l e . E n t r i e si n c o l u m n sl 9 - 2 7 i d e n t i f yt h e t w o r e c o r dt y p e s
R e c o r di d e n t i f y i n gi n d i c a t o 0
r 1 will turn on if an ITEMrecord is selectedfor processing;
irrdicator02 will turn on if a
S A L E Sr e c o r di s s e l e c t e dT. h e s i n g l em a t c hf i e l d i n e a c h
f i l e i ss p e c i f i eb
d y a s s i g n i nt g
h e M 1 e n t r y i n c o l u m n s6 1 - 6 2 .
previously.
a sy o u l e a r n e d

T h e q u a n t i t ya n d l o c a t i o na r et o b e p r i n t e do n l y w h e na
d .e c a u steh e M R i n d i c a S A L E Sr e c o r di s b e i n gp r o c e s s e B
t o r i s o n d u r i n gt h e p r o c e s s i nogf b o t h I T E M r e c o r d sa n d
S A L E Sr e c o r d si.t i s n ' ts u f f i c i e ntto c o n d i t i o nt h i so u t p u t
l i n eo n l y o n t h e b a s i so f M R . T h e r e f o r et ,h e p r i n t i n go f
q u a n t i t ya n d l o c a t i o ni s c o n d i t i o n e d
b y b o t ht h e M R i n d i c a t o ra n d t h e 0 2 r e c o r di d e n t i f y i n gi n d i c a t o r .

L i n e s0 1 - 0 4o f t h e O u t p u ts h e e st p e c i f yt h a t h e a d i n gasr e
to be printedat the top of everypageof the report.

I n t h i s c a s ec, a l c u l a t i o snp e c i f i c a t i o na sr en o t r e q u i r e d .
H o w e v e ri,f c a l c u l a t i o nasr er e q u i r e da n da r et o b e p e r f o r m e do n l y i f a m a t c h i n g( o r n o t m a t c h i n gr)e c o r dc o n by the
d i t i o ne x i s t sc, a l c u l a t i o nm
s u s ta l s ob e c o n d i t i o n e d
M R ( o r N M R )i n d i c a t o r .

M a t c h F i e l d sA n d M u l t i f i l e P r o c e s s i n g 6 - 1 9

Processing
Order: More Than One Matching
Recordin the
PrimaryFile
For the examplejust prersented,
therewasmorethan one
recordin the secondaryf irewith
the samematchfierd.
That is, a singleITEM recordwas
relatedto'a numoerof
SALESrecords.In sucha case,the
orOerof pro"essing
was
the first primaryfile record,followed
by its relatedsecondaryfile records,then the next primary
file record,fol_
lowedby its relatedsecondaryfile
records,anctso on.
Let'stake a look at anotherset
of files,in which eachrecord hasa matchingrecordin the
other file. Figure6_17,
part A, showsthat therenrtay
be more than one primaryfile
recordwhich matchesthe same
secondaryrecords.In what
o r d e rd o y o u t h i n k t h i

rirst primaryrir.,..o,T'p
jT:::::fi
l:HX,:H.,lrT

Ji:

folrowedby its reratedsecondary
tite recoros.Instead,arl
p r i m a r yf i l e r e c o r d sw i t h t h e
s a m em a t c hf i e t Oq R w o u t O
oe processed;
then all secondary
file recordsfor AA (see
l F i g u r 6e - 1 7 ,p a r t B ) .

r \ c t u a l l y t, h e R p G l l l o g i cu s e dt o
d e t e r m i n et h e o r d e ri n
lvhichsuchfilesare processed
is the sameas that discussed
5rreviously.Rememberthat wheneverthe match
fieldson
the two recordsin the readareaare
tne samu,ine primary
file recordis alwaysselectedfor processing.
Thus,during
the f irst programcycle,the first primary
file record(AA)
ir;comparedto the first secondaryfile
record(AA). The
matchfieldsarethe same.so the f irst primary
file recordis
processed.
Then the secondprimaryfile record(again
AA)
is readand comparedto therfirst
secondary
file record(AA),
still in the readarea. Sincethereis
a matchagain,this sec_
ond primaryfile recordis processed.
Frcrboth of the lasttwo examplespresented.
everyrecord
in the secondary
file had at leastone or more related
rec_
ordsin the primaryfire. sirrcea matching
recordcondition
al'rvays
exists,the MR indicatorwason during
the process_
inrgof everyrecordin both liles.

6-2(l

MatchingRecords:RecordsWhich
HaveNo Matchin the
Other File
ln the multifile programspresented,
therewasat leastone
SALESrecordfor everyITEM master
record. Therefore.all
recordshad a relatedrecordin the
other file. Of course,in
m u l t i f i l ep r o c e s s i n igt .i s p o s s i b lteo
h a v ep r i m a r yf i l e r e c ordswith no relatedrecordsin the
secondaryfile, aswell as
secondaryf ile recordswith no relatedprimary
f ile records.
In eithercase,the recordwith no related
recordin the other
file is calledan unmatchedrecord.
For instance,if only
c e r t a i ni t e m sa r es o l d ,t h e r ew o u l d
b ea n I T E M m a s t er e c ord for everyitem and SALESrecords
for only someof
thoseitems. The ITEM recordsfor which
no sateswere
maclewould be unmatchedrecords.
U n m a t c h e rde c o r d sc a n b e i n e i t h e r
o r b o t h f i l e s ,b u t t h e y
a r eu s u a l l yf o u n d i n t h e p r i m a r yf i l e .
I n t h i se x a m p l ei,t i s
q u i t ep r o b a b l et h a t f o r a n y o n e
i t e m .n o s a l e sh a v et a k e n
p l a c e .H o w e v e ri,t i s n o t a s l i k e l y
t h a t s a l e sh a v eo c c u r r e d
f o r a n i t e m f o r w h i c h t h e r ei s n o r e c o r d
i n t h e I T E Mm a s t e r
rt l e .

More than one
primary file
record with
same match field

/

'-

S e c o n d a r yF i l e

P r i m a r yF i l e

F I L E S B E F O R EP R O C E S S I N G

S e c o n d a r yr e c o r d sw i t h m a t c h f i e l d A A

P r i m a r y r e c o r d sw i t h s a m e m a t c h f i e l d s
processedbefore the secondary records
with same match field

THE FILES
ORDER OF PROCESSING

Figure6-17, More than One Primary File Record with Same Match Field
M a t c h F i e l d sA n d M u l t i f i l e P r o c e s s i n g 6 - 2 1

ProcessingOrder: lJnmarched
Records

I n t s p r o g r a m c y c l e s h o w st h a t
e v e ni f t h e r e i s n o m a t c h i n g
r e c o r dc o n d i t i o n , t h e p r i m a r y
f i l e m a y b e s e l e c t e df o r p r o c _
e s s i n g .T h i s i s b e c a u s eR p G
ll logiclooks for the record
with the lowestmatch f ield, regardless
o f w h e t h e rt h e
r e c o r di s f r o m t h e p r i m a r y f i l e
o r t h e s e c o n d a r vf i l e .

L e t ' sa s s u m teh a t t h e

thereco
rds,n
o*n,
n'J[l],:;:,?jJ:J:
[Ti:il;:

lTffT'

f i l e c o n t a i n i n gt w o u n m a t c h e d
r e c o r d s .T h e R p G l l l o g i c
related to rnatching records would
determine tfre order in
w h i c h t o p r o c e s st h e

pIained
eartier,r,,.r,
J:'ff:'r(:llH ?.'.?,:1'i,il;
f ;;;,,

Now the next primary file ITEM
record (239) is read. Since
i t m a t c h e st h e S A L E S r e c o r d
i n t h e r e a d a r e a ,t h e p r i m a r y
file recordis automatically
s e l e c t e df o r p r o c e s s i n g .A l t h o u g h
a m a t c h i n gr e c o r d c o n d i t i o n
e x i s t sf o r t h e I T E M r e c o r d
s e l e c t e da, t t h i s p o i n t t h e M R
indicatorisstill off because
of
t h e l a s t r e c o r d p r o c e s s e d( u n m a t c h e d
ITEM recordtor 124).
T h e s t a t u so f M R i s n o t c h a n g e d
u n t i l r i g h t b e f o r ed e t a i l
o p e r a t i o n sf o r t h e s e l e c t e dr e c o r d
are performed.

p r o c e s s e df,o l l o w e d b y

a i l S A L E S r e c o r d sf o r i t e m
101. Re_
m e m b e r ,i f a r e c o r d i s s e l r : c t e d ,
f o r p r o c e s s i n gd u r i n g a p r o gram cycle, the next record
from that same f-iteis read
at
t h e b e g i n n i n go f t h e n e x t c y c l e .
T h e r e f o r e ,w n e n t h e f i r s t
S A L E S r e c o r df o r i t e m 1 l 7 i s
r e a d ,a n o t h e r m a t c h i n g r e c ord conditionexists. Thus,
the primary file record (ITEM
r e c o r df o r i t e m 1 1 7 ) i s p r o c e s s e c l
f irst. The nexr pnmary
f i l e r e c o r df o r i t e m 1 2 4 i s
t h e n r e a d t o r . u p t u . ut h e I T E M
r e c o r d p r o c e s s e d .S i n c eS , A L E S
r e c o r d sw i t h m a t c h f i e l d s
of 117 are lower in sequence
t h a n 1 2 4 ,t h e t w o S A L E S
r e c o r d sf o r i t e m 1 1 7 a r ep , r o c e s s e d .
F u r t h e r m o r e ,a l t h o u g h
L h em a t c h f i e l d s( 1 1 7 ) o n t h e
S A L E S r e c o r d sa r e n o t t h e
same
€ l st h a t o f t h e I T E M r e c o r d i n
t h e r e a da r e a ( 1 2 4 1 ,t h e y a r e
t h e s a m ea s t h e m a t c h f i e l c lo f
the last ITEM recoroproce s s e d .T h e r e f o r e ,t h e M R
i n d i c a t o r i s o n w h e n e a c hS A L E S
r e c o r df o r 11 7 i s p r o c e s s e d .
v/hen the next sALEs record(item
239) is re
a d .t h e r e s t i r l
-rn.
isin'ta match with the lTEt\l record
f or 124.
rnu,.n
field on the ITEM recordis
lower than that on the SALES
r e c o r d ;t h e r e f o r e ,t h e p r i m a r y
f i l e r e c o r df o r i t e m 1 2 4 ,
an
u n m a t c h e dr e c o r d , i s p r o c e : ; s e d
f i r s t ( F i g u r e6 _ 1 g ,p a r t B ) .
S i n c et h e f i l e s a r e i n a s c e n d i n g
r u q r " n " u l t h i s m e a n st h a t
t f r e r ei s n o r e c o r d i n t h e s e c o n d a r y
file with a match field
o 1 ' 1 2 4 . T l r e r e f o r e ,M R w i l l b e
t u r n e d o f f j u s t b e f o r et h e
ll"EM record for 124 is pror:essed.

o-zl

Followingthe ITEM recordfor
2 3 9 , t h e S A L E S r e c o r df o r
i t e m 2 3 9 i s p r o c e s s e d .T h e n ,
a s b e f o r e ,t h e u n m a t c h e d
I T E M r e c o r df o r i t e m 2 g 6 i s p r o c e s r . O ,
rinc" lt is lower in
s e q u e n c et h a n i t e m 3 2 . 1o n t h e
next SALES record. To
c o m p r e t et h e p r o c e s s i n gt,h e p r i m a r y
f i r e r r E M r e c o r df o r
i t e m 3 2 1 i s p r o c e s s e df,o l l o w e d
b y t h e t w o s a l e sr e c o r d sf o r
item321.
I n s u m m a r y ,t h e n , R p G l l s e t s
t h e M R i n d i c a t o rt o o f f i m m e d i a t e l yb e f o r e p r o c e s s i n ga n y
u n m a t c h e dr e c o r d s . M R i s
t u r n e d o n b e fo r e p r o c e s s i n ga
r e c o r d t h a t h a sa m a t c h i n g
recordin the other file. After
a r e c o r d h a sb e e np r o c e s s e d ,
t h e i n d i c a t o r r e m a i n sa s i t w a s
u n t i l i t i s s e t a g a i ni m m e d i _
a t e l y b e f o r et h e n e x t r e c o r d i s p r o c e s s e d .
R e g a r d l e sosf t h e r e c o r d si n a f i l e ,
t h e r e i s a n e a s yw a y t o
d e t e r m i n ei f a m a t c h i n g r e c o r < i
c o n d i t i o n e x i s t sa n d i f t h e
M R i n d i c a t o rw i l l b e t u r n e d o n :
1.

W h e na p r i m a r y f i l e r e c o r di s s e l e c t e d
for processing,
MR will be turned on if there is
a s e c o n d a r yf i l e r e c _
o r d i n t h e r e a d a r e aw i t h t h e s a m e
match f ield.

2.

W h e n a s e c o n d a r yf i l e r e c o r d i s
s e l e c t e df o r p r o c e s s _
ing, MR will be turned on if the lastprimary
file reco r o p r o c e s s e dh a d t h e s a m em a t c h
f ield.

1321

P

t286
lt

239

P
P
PJ

117

[r io1
\

101

I

I
I

\
\

I

Item
Number

Item
Number

I T E M M a s t e rF i l e

SALES File

( P r i m a r yF i l e )

( S e c o n d a r yF i l e )

@

@

F r L E sB E F . R EP R . . E S S T N G

PRocESSTNG
oRDER oF FTLES

F i g u r e 6 - 1 8 . P r o c e s s i n gF i l e s w i t h U n m a t c h e d R e c o r d s
M a t c h F i e l d sA n d M u l t i f i l e P r o c e s s i n g 6 - 2 3

I Stacker Selection of lJnnatched Card Recorrls
W h e n r e c o r d sf r o m t w o f i l e s
a r e a s s i g n e dm a t c h f i e l d s ,
a
record from one fire may
be prccessed,then a record from
t h e o t h e r f i l e , a n d t h e n e rr e c o r d
from the first tile again.
However, regardlessof the
order in which tho-ru.orO,
ur.
p r o c e s s e da, l l c a r d sw h i c h
enterthrough the prrmary
h
op_
per of the MFCU or MFCM
a r e a u t o m - a t i c a l l sf t a c k e di n
s t a c k e r1 . A l l c a r d se n t e r i n g
t h r o u g h t h e s e c o n d a r yh o p p e r
e n d u p i n s t a c k e r4 ( s t a c k e r
5 o n t n e M F C l W M o o e tA l
).
lf thereare unmatched.rercords
in either file, you can separate such cards from the others
in that file by stacker
selectingthe unmatched r:ards
into a different ,,..*"r. R,
you learned in the chapter
Card Output Operations, cards
from an input file can be
s e l e c t e di n t o a d i f f e r e n t s t a c k e r
b y e n t e r i n gt h e n u m b e r o f
t h e s t a c k e ro n t h e I n p u r s n e e t .
H o w e v e r ,t h i s c a n b e d o n e o n l y
w h e n i n p u t c a r d sa r e t o b e
stacker selectedon the basisof
record type.
iStackerselection of a caro
becauseit has no matching rec_
r ) r d i n t h e r e l a t e df i l e r n u s t
b e s p e c i f i e di n c o l u m n l 6 o f
the
( J u t p u t s h e e t( F i g u r e
6 - 1 9 , p a r t A ) " H o w u u e r ,a n i n p u t
file
cannot be specifieclon the Output
sheet. Therefore, the
i n p u t f i l e c o n t a i n i n gt h e c a r d
t o b e s t a c k e rs e l e c t e d( t h e
c a r d w i t h n o r e l a t e dr e c o r r l )m u s t
b e d e f i n e da s a c o m b i n e d
f ile on the File Descriptiorr
s h e e r( F i g u r e O _ i n , ' 0 . * B ) .
The
combinedfile name can th,en
b e u s e do n t h e O u t p u t s h e e t
for stacker selection.
A l o t i c eo n t h e O u t p u t s h e e tt h a t
s t a c k e rs e l e c t i o ni s s p e c i _
f i e d f o r t h e c o m b i n e df i l e I T E M ( l i n e
1 1 ) ,, i n " . o n l y t h e
l ' l - E M f i l e c o n t a i n su n m a t c l r e d
r e c o r d s . T h e f i l e n a m ei n c j i _
c a t e sf r o m w h i c h f i l e t h e c a r r d s
w i l l b e o u t p u t . S i n c ea
m a t c h i n gr e c o r dc o n d i t i o n
c a n n o t p o s s i b l ye x i s t f o r a n y
unrnatched records. MR must be
off. Therefore, the stacker
s e l e c t i o no f r e c o r d si s c o n d i t i o n e d
by NMR (off).

;24

A n y r e c o r d ,c o n d i t i o n e d f o r s t a c k e r
s e l e c t i o nb y t h e M R
i n d i c a t o r ,s h o u l d b e s p e c i f i e d
a s a d e t a i l _ t i m er e c o r d ( s e e
F i g u r e6 - 1 9 , p a r t A , c o l u m n 1 5 ) .
O t h e r w i s e ,r n e n e x t r e c ord to be processedwould be
stacker selectedinstead of the
recordyou want" This is because
t h e d e t a i l _ t i m ep r o c e s s i n g
of a card is done within one program
cycleand the proc_
esselF

9V

ilel

Extent Exit
for DAM

TyF
Dwice

Symbolic
Owics

Core Index

I

r::--:I Sodins
L6tid
I

UI U8

_t_-

i

Option

l"."roruourd
not
be processed

Frigure6'25. specifyingwhen Processing
is to stop in a MatchingRecordsprogram

I

l<

II

6.32

Label Exir

&..

t T E Mf i t e

rq Cylanftr 6dtow

Name oI

SALES file

t-I

p a q eo f G C 2 1 - 7 5 6 7 - 2
lssued
2 1 D e c e m b e1r 9 7 9
By TNL: cN2.l_S709
A s s u m et h e s e c o n d a r yS A L E S if i l e c o n t a i n s
the records
s h o w n i n F i g u r e6 - 2 6 . F o l l o w i n g e a c h g r o u p
o f s a t e sr e c _
o r d s f o r a p a r t i c u l a ri t e m i s a r e c o r d w h i c h g i v e s
the total
salesfor that item. The total records do
not have match
t i e l d s a n d t h u s a r e s e l e c t e df o r p r o c e s s i n g
assoon asthev
are readA n e n d o f f i l e e n t r y i s a s s i g n e ct ol t h e p r i m a r y
ITEM file.
S i n c e b o t h f i l e s a r e i n t h e s a m es e q u e n c e ,
onceall ITEM
master records are processed,ernysalesrecords
which still
remalnin the SALES file must be either
r e c o r d sw h i c h
match the rast primary record processed.
records for which
t h e r e i s n o v a l i d i t e m n u m b e r ,o r t o t a l r e c o r d s
which are not
to be r-rratched.

W h e n t h e / * r e c o r d i n t h e p r i m a r y f i l e i s r e a d ,t h e p r o g r a m
c h e c k st h e o t h e r f i l e . T h e t w o S A L E S r e c o r d sf o r i t e m
321
match the lastprimary file ITEM recordprocessed.
Thus,
t n e y a r e a u t o m a t i c a l l yp r o c e s s e d .T h e n e x t r e c o r d i n
the
S A L E S f i l e , a t o t a l r e c o r d w i t h o u t m a t c h f i e l d s .w i l l
cause
t h e L R i n d i c a t o r t o b e t u r n e d o n , a n d t h e p r o g r a mw i l l
e n d . H o w e v e r ,i f a n e n d o f f i l e e n t r y w a s n o t a s s i g n e d
to
the primary ITEM file, or if the end of file entry was
assigned
t o t h e s e c o n d a r yS A L E S f i l e , a l l r e c o r d si n t h e S A L E S
file will be readand processeo.

TOTAL
Not
Processed

TOTAL

+
Becords Processed
After End-of-File
R e a c h e di n I T E M
File

TOTAL

ITEM Fite

F i g u r e 6 - 2 6 . P r o c e s s i n ga M a t c h i n g R e c o r d s
Job After End of Fire

Match Fields And Multif ile Processinq

6-33

I J S EO F M A T C H F I E L D S A N D C O N T R O L F I E L D S
IN
.]THE
SAME FILE
I n t h e p r e v i o u se x a m p l e ,t h e I T E M a n d S A L E S f
i l e sw e r e
r n a t c h e da c c o r d i n gt o a n i t e m n u m b e r f i e l d s o
that individu a l s a l e sc o u l d b e p r i n t e d u n d e r t h e i t e m d e s c r i p t i o n .
Suop r o s ey o u a l s ow i s h t o h a v et h e s a l e sf o r
e a c hi t e m t o t a l e d
a n d p r i n t e d , a s s h o w n i n F i g u r e6 _ 2 7 .

ITEM

DESCRIPTION

OUANTITY

43
62
157

T'o perforrn total operations on a group of records.
it is
n e c e s s a r tyh a t c o n t r o l f i e l d s b e a s s i g n e dt o d i s t i n g u i s h
one
group f rom the next. For this program,
t h e s a m ei t e m n u m _
b e r f i e l d u s e df o r m a t c h i n gt h e r e c o r d sw o u l d b e s p e c i f
ied as
a c o n t r o l f i e l d o n t h e I n p u t s h e e t( F i g u r e6 _ 2 g ) .
Although
y o u r f i l e sm a y c o n t a i n b o t h m a t c h f i e r d s
a n c rc o n t r o r f i e r d s ,
t h e r e i s n o r e l a t i o n s h i pb e t r v e e nt h e t w o f u n c t i o n s p e r _
f o r m e d . E v e n i f t h e s a m e{ i e l d so n a r e c o r d a r e
u s e da s b o t h
m a t c h a n d c o n t r o l f i e l d s ,t t r e o n l y s i m i l a r i t y i s t h a t
the same
d , a t aw i l l b e u s e di n p e r f o r n t i n ge a c h f u n c t i o n .
M a t c h f i e l d sa r e c h e c k e df i r s t t o d e t e r m i n ef r o m w h i c h
f ile
t h e n e x t r e c o r d i s t o b e p r o c e s s e d( s e eF i g u r e6 - 2 9 ) . I n
eff e ' c t ,t h e m a t c h i n g r e c o r d f u n c t i o n i s c r e a t i n go n e f
ile for
processingby merging the data from two f
iles. (Of course,
a { t e r p r o c e s s i n gt,h e t w o f i l , e sa r e a u t o m a t i c a l l ys e p a r a t e d
a l l a i n i n t o t h e a p p r o p r i a t es t a c k e r s . )

LOCATION

262 TOTAL

49
38
67
154 TOTAL

Figwe 6-27, Printing Totals for Matching Records

I n a d d i t i o n , c o m p a r i s o no f t h e m a t c h f i e l d sd e t e r m i n e s
w h e t h e r t h e M R i n d i c a t o rv r r i l lb e t u r n e d o n o r o f f f o r p r o c e s s i n go f t f r e s e l e c t e dr e c o r d . A s d i s c u s s e dp r e v i o u s l y ,
the
MR indicatoris to be on for processing
of a primarv file

RPG

INPUTSPECIFICATIONS

,l

f

|

2

/ 5 / 6 / t

J 8 7 g 8 O

l
'- . r " tl i l ' L
l t i r L _l ,

_,-

I
!

I
t.
I ie d N.rnre
!

u . i

6

a =

7 z

a
!

> -

_

r 5{ 55 !a i7 !31!9 br

I
I

Itern number
f i e l d s u s e da s
froth match
f i e l d sa n d
control fields.

I
I
I
I
I
I

nti

d,a

fllr-rc,). , :
. lI
, l r . ,

1 r I

r l i
t , i
. l I

F i l r u r e6 - 2 8 . A s s i g n i n gt h e s a m e F i e r d a s a M a t c h F i e r d
and as a contror Fierd
6-34

I

START

I
Y
a

a
o

o

Select record to
p r o c e s si n t h i s c y c l e

Turn off record
identifying indicator
and control level
indicators

O

o
R e a da n o t h e r
record

M a t c hi n g
Record
Function

and turn on record
identifying indicator
Determineif MR
s h o u l d b e s e t o n o r off
for selected record

a
Detailoutput for
selected record

o
Detail calculations
for selected rerord

Detail-Time
Operations
Performed

l s C o n t r o l F i e l do n
selected record different?
lf same, go to process
selected record
lf different, turn on
control lsr'el indicator
Control
Level
Function

o
MR set on or off
for $elected record
lf control levelindicator on,
d o t o t a l c a l c u l a t i o n sa n d
output for prarious control
grou p

o
o
o
o

Total-Time Operations
P e r fo r m e d

Figure6-29. RPGlt Logicof Obtainirrg
Totalsfor MatchingRecords
r e c o r d o n l y i f t h e r e i s a m a t c h i n gr e c o r d i n t h e s e c o n o a r y
f i l e . L i k e w i s e ,i f a s e c o n d a r yf i l e r e c o r d i s s e l e c t e d M
, R is
t,c be on for its processingonly if a matching record from
t h e p r i m a r y f i l e h a sa l r e a d y b e e n p r o c e s s e dl.f a n u n m a t c h e d
rL"cordis selected,MR is set off, of course. At this point.
however, the matching record function onlV determines how
t h e M R i n d i c a t o r i s t o b e s e t ; t h e s t a t u so f M R i s n o t a c t u a t l v c h a n g e dy e t .

O n c e t h e m a t c h i n g r e c o r d f u n c t i o n h a s s e l e c t e dt h e n e x t
r e c o r d t o b e p r o c e s s e dt,h e c o n t r o l l e v e lf u n c t i o n t h e n c o n s i d e r st h e r e c o r d sa s o n e f i l e i n d e t e r m i n i n gi f a c o n t r o l
break has occurred. This check is made before the selected
r e c o r d i s p r o c e s s e da n d , t h u s , b e f o r e t h e M R i n d i c a t o r i s
s e t f o r t h e r e c o r d j u s t s e l e c t e d( s e eF i g u r e6 - 2 9 ) . T h e c o n t r o l f i e l d ( i t e m n u m b e r ) o n t h e s e l e c t e dr e c o r d i s c h e c k e d
t o s e e i f i t i s d i f f e r e n t f r o m t h a t o n t h e p r e v i o u s l yp r o c e s s e dr e c o r d . l f i t i s t h e s a m e ,n o t o t a l s a r e t o b e p r i n t e d ;

M a t c h F i e l d sA n d M u l t i f i l e P r o c e s s i n q 6 - 3 5

s J t h e M R i n d i c a t o r i s s e r tt,h e O T y a c c u m u l a t e di n t o
T O T A L , a n d t h e i n d i v i d u a lr e c o r d i s p r i n t e d . H o w e v e r ,
if
the item number is differentfrom that on the previously
p r o c e s s e dr e c o r d ,t h i s m e a n st h a t a l l i n d i v i d u a l
s a l e sf o r
t h e l a s t i t e m n u m b e r h a r r eb e e n p r i n t e d . T h e c h a n g e
in the
c o n t r o l f i e l d c a u s e sa c o n t r o l l e v e l i n d i c a t o r ( L 1 w a s
as_
s i g n e d )t o b e t u r n e d o n . A n y t o t a l c a l c u l a t i o n sa n d
total
o u t p u t ( o p e r a t i o n sc o n d i t i o n e c lb y t h e c o n t r o l l e v e l
indica_
t o r ) a r e t h e n p e r f o r m e d f o r t h e p r e v i o u sc o n t r o l g r o u p .
In
t h i s c a s e ,t h e t o t a l o f a l l s a l e sf o r t h e p r e v i o u si t e m
are
p r in t e d .
W h e n t o t a l o p e r a t i o n sa r e p e r fo r m e d , t h e s e l e c t e dr e c o r d
h a s n o t b e e n p r o c e s s e dy e t . T h e r e f o r e ,d u r i n g t o t a l
time,
M R i s s t i l l s e t f o r t h e p r e v i o u s l yp r o c e s s e dr e c o r d .
Once
t o t a l o p e r a t i o n sa r e c o m p l e t e d ,M R i s t h e n s e t f o r
tne
selectedrecord (the first record in the next control group)
so it can be processed.

6-36

W h e n e v e ra c o n t r o l f i e l d c h a n g e s( c o n t r o l b r e a k ) .a c o n t r o l
l e v e li n d i c a t o r i s a u t o m a t i c a l l yt u r n e d o n . F u r t n e r m o r e ,
w n e n e v e ra c o n t r o l l e v e l i n d i c a t o r i s o n , t o t a l o p e r a t i o n s
w i l l b e p e r f o r m e d . I n a m a t c h i n g r e c o r d sp r o g r a m ,h o w e v e r ,
t h e r e m a y b e t i m e s w h e n a c o n t r o l b r e a k o c c u r sa n d y o u
d o n ' t w a n t t o t a l o p e r a t i o n st o b e d o n e . T h u s , y o u m u s t
s p e c i f yt h a t t o t a l o p e r a t i o n sa r e t o b e p e r f o r m e do n l v u n d e r
c e r t a i nc o n d i t i o n s .
F o r t h i s p r o g r a m ,s a l e sa r e t o b e a d d e d a n d t h e t o t a l p r i n t e d
o n l y i ' f t h e r e i s a n I T E M m a s t e rr e c o r d w i t h m a t c h i n gS A L E S
r e c o r d sf o r t h a t i t e m . I n s u c h a c a s e ,M R w o u l d h a v e b e e n
s e t o n f o r t h e l a s tS A L E S r e c o r do f t h e g r o u p . M R w o u l d
s t i l l b e o n , t h e n . w h e n t h e c o n t r o l b r e a k o c c u r s .T h u s , d e t a i l
o p e r a t i o n st o a c c u m u l a t es a l e ss h o u l d b e p e r f o r m e d w h e n _
e v e r M R i s o n a n d t h e t o t a l o p e r a t i o n st o p r i n t t h e T O T A L
s h o u l d b e c o n d i t i o n e dt o b e p e r f o r m e do n l y w i t h L l a n d
M R o n ( F i g u r e6 - 3 0 ) .

Paseof cC21-7567-2
lssued21 Decemberlg79
By TNL: GN2t-5709
RPG CALCULATION
SPECIFICATIONS

F o r mC x ? i S 9 3
priEdilUSA
1

2

7 5 7 6 7 7 1 8 7 9 8 0

""Ll l"- linil,,..LlT-[Il]
Resull Field

Factor 2

RPG

OUTPUT

SPECIFICATIONS

cx2r so

""'f-fl'-

P,^rar
rde"r,r.r,nit

u/M o50.

15 t6 1/

lTl

78 19 80

l-[T_l
|

|

I

I

I

I

Figure 6-3o. controiling performance of rotar
operations in a Matching Records program

M a t c h F i e l d sA n d M u l t i f i l e P r o c e s s i n q 6 - 3 7

l j i n c e t h e r e c a n b e u n m a t c h e dr e c o r d si n e i t h e r f i l e ,
Vou can
h a v ea n I T E M r e c o r d w i t h n o m a t c h i n gS A T E S
r e c o r d so r
i n v a l i d S A L E S r e c o r d sf o r w h i c h t h e r e a r e n o
matchingITEM
m a s t e r ( s e eF i g u r e6 - 3 1 ) . , A l t h o u g ha c o n t r o l
b r e a kw o u l d
o c c u r f o l l o w i n g t h e p r o c e s s i n go f t h e u n m a t c h e d
records,
y o u d o n ' t w a n t t o t a l o p e r a t i o n st o b e p e r f o r m e d .
The MR
i n d i c a t o r w o u l d b e o f f f o r t h e u n m a t c h e dr e c o r d s .
There_
fore, if you condition total time output
s p e c i fi c a t r o n sw i t h
L-"1
and MR on, total time rryouldbe bypassedfor such
cases.

D E T E R M I N I N GW H E T H E R F I L E S S H O U L D
BE
PRIMARY OR SECONDARY
h b a s i cq u e s t i o na r i s e si n a r r y m u l t i f i l e p r o c e s s i n g
application:
V / h i c h f i l e s h o u l d b e d e s i g n a t e dt h e p r i m a r y f i l e
and which
r s t o b e t h e s e c o n d a r yf i l e ? S i n c ea l m o s t a l l m u l t i f i l e p r o g r a m si n v o l v et h e u s e o f m a t c h f i e l d s t o d e t e r m i n ep r o c e s s i n g
o r d e r , a n u n d e r s t a n d i n go f m a t c h i n g r e c o r d l o g i c g e n e r a l l y
is
e s s e n t i aflo r d e t e r m i n i n gw l r i c h f i l e s h o u l d b e t h e p r i m a r y
fi l e .
S i n c ef i l e sv a r y a m o n g a p p l i c a t i o n sw
, e c a n , t s t a t ea b s o l u t e l y
t h a t a c e r t a i nf i l e i s a l w a y s t o b e p r i m a r y o r s e c o n d a r y .
H o w e v e r ,n o w t h a t y o u u n c l e r s t a n d
t h e b a s i cm a t c h i n g r e c o r d s c o n c e p t s ,t h e f o l l o w i n , l p o i n t s m a y h e l p y o u t o
make
t h e b e s tf i l e d e s i g n a t i o n .
l f t h e m a t c h f i e l d s o n r e c o r , Cfsr o m t w o o r m o r e f i l e s
are
c c l m p a r e da n d f o u n d t o b e r : h es a m e ,t h e p r i m a r y f i l e
rec_
o r d i s a l w a y s s e l e c t e d . F u r t h e r m o r e ,t h e p r i m a r y f i l e w o u l d
b e g i v e n p r i o r i t y i f n o n e o f t h e a v a i l a b l er e c o r d sc o n t a i n e d
m a t c h f i e l d s . I n g e n e r a l t, h e n , i f a l l m a t c h c o n d i t i o n s
are
t h e s a m e ,t h e p r i m a r y f i l e r e r c o r di s t h e f i r s t p r o c e s s e d .
With this ideain mind, we can saythat if datafrom file A
m u s t b e a v a i l a b l et o t h e p r o g r a m b e f o r e f i l e B c a n b e p r o c _
e s s e d t, h e f i l e c o n t a i n i n gt h e n e c e s s a r d
y ata (A) shouldbe
d e s i g n a t e da s t h e p r i m a r y f i l e . F o r e x a m p l e ,s a y y o u h a v e
t l r r r of i l e s t o p r o c e s st o d o a c u s t o m e rb i l l i n g a p p l r c a t i o n .
The
c u s t o m e r s 'n a m e sa n d a d d r e s s easr e r e c o r d e di n o n e f i l e w h i l e

6-38

t h e c u s t o m e r s ' t r a n s a c t i o an rse i n a n o t h e rf i l e . A n a m e
and
a c l d r e s iss t o b e p r i n t e d o n a b i l l b e f o r e a c u s t o m e r , sc h a r g e s
a n d c r e d i t s . T h e n a m e a n d a d d r e s sr e c o r d m u s t b e a v a i i a b l e
f o r o u t p u t a n d , t h u s , m u s t b e p r o c e s s e db e f o r e t h e r e l a t e d
t r a n s a c t i o nc a r d s . I n t h i s c a s e ,t h e n a m e a n d a d d r e s sf i l e
s h o u l d b e s p e c i fi e d a s t h e p r i m a r y f i l e .
L e t ' s c o n s i d e ra n o t h e r c a s ei n w h i c h o n e f i l e i s t o b e u s e c l
o n l y a s i n p u t w h i l e t h e o t h e r f i l e i s t o b e u s e df o r b o t h i n put and output. In other words,the program
r e q u i r e so n e
i n p u t f i l e t o b e r e a da n d o n e c o m b i n e d o r u p d a t e f i l e t o
be
b o t h r e a d a n d w r i t t e n o r p u n c h e d . U s u a l l y ,i n f o r m a t j o n
f r o m t h e i n p u t f i l e w o u l d b e n e c e s s a r tyo c a l c u l a t e
the data
to be output to the combinedor updatef ile. Or, perhaps
t h e a c t u a li n p u t f i l e d a t a i s t o b e o u t p u t t o t h e c o m b i n e do r
u p d a t e f i l e . E i t h e r w a y , t h e c o m b i n e c lo r u p c l a t ef i l e s h o u l d
b e s p e c i f i e da s t h e s e c o n d a r yf i l e , s o t h e d a t a f r o m t h e p r i _
m a r y i n p u t f i l e i s a v a i l a b l eb e f o r et h e o u t p u t i s o o n e .
I n g e n e r a l t, h e t y p e o f d a t a w h i c h m u s t b e a v a i l a b l eb e f o r e
processing
a n o t h e r f i l e i s p e r m a n e n tr e c o r d i n f o r r n a t i o n ,
s u c h a s w o u l d b e f o u n d i n a m a s t e rf i l e . F o r i n s r a n c e a, n
e m p l o y e e ' sh o u r l y w a g e f r o m a m a s t e rf i l e i s n e c e s s a r yo e f o r e t h e c o m p u t e r c a n u s et h e n u m b e r o f h o u r s w o r k e d
f r o m a n e m p l o y e ed e t a i l f i l e t o c a l c u l a t en e t p a y . T h e r e .
f o r e , a m a s t e rf i l e i s o f t e n t h e p r i m a r y f i l e , w h i l e a d e t a i l
o r t r a n s a c t i o nf i l e i s t h e s e c o n d a r yf i l e O f c o u r s e ,t h i s i s
o n l y a g u i d e l i n ea n d s h o u l dn o t b e c o n s i d e r e d
the rulefor
all situations.
A s a f i n a l p o i n t , i f t h e f i r s t r e c o r d i n o n e o f t h e f i l e sm u s t
b e t h e f i r s t r e c o r d p r o c e s s e di n t h e p r o g r a m ,y o u m u s t m a k e
s u r e t h a t t h i s r e c o r d w o u l d b e s e l e c t e d .T o d o t h i s , f i r s t
d e c i d ew h i c h f i l e y o u t h i n k s h o u l db e p r i m a r ya n d w h i c h
secondarya
, c c o r d i n gt o t h e s u g g e s t i o n ps r e s e n t e d .T h e n ,
d e t e r m i n ew h i c h r e c o r d w o u l d b e s e l e c t e cf Ji r s t r n t h e p r o _
g r a m b y t h e R P G l l l o g i c o f m a t c h i n gr e c o r d s . l f t h e r e c o r d
w h i c h w o u l d b e s e l e c t e di s n o t t h e r e c o r d w h i c h m u s t b e
p r o c e s s e df i r s t , t h e p r i m a r y a n d s e c o n d a r yf i l e d e s r g r r a t r o n
shouldbe switched.

L R t u r n e d o n " M R o n f r o m p r e v i o u sr e c o r d
s o t o t a l o p e r a t i o n sd o n e f o r p r e v i o u sc o n t r o l g r o u p .
(SALES for 156 totaled and printed) Job is then
ended.

Ll turned on. MR off from previous
r e c o r d s o t o t a l o p e r a t i o n ss k i p p e d "
MR then turnedon for this matching
recoro"
Ll turned t-rn.MR on tronr previous
r e c o r d s o S A L E S f o r 12 4 a r e t o t a l e d
and printed. MR then set off for
this unmatchedrecord,

UNMATCHED

L1 turned on, MR off from prevtous
r e c o r d s o t o t a l o p e r a t i o n ss k i p p e d . T h e n
MR turned on for this matchingrecord.
Ll turnedon, MR still on for
p r e v i o u sr e c o r d s o S A L E S f o r 1 0 1

UNMATCHED

|

101

are totaled and printed. MR then
set off for this unmatchedrecoro.

Ll turned on automatically for
first record, Total operations are
skipped in first programcycre,
however. MR then set on for
this matching record,

SALES File
( S e c o n d a r yF i t e )
ITEM Fite
(Primary File)

Figure 6-31. Useof tltR Indicator to DetermineWhether Total
O p e r a t i o n sa r e t o b e p e r f o r m e d

M a t c h F i e l c i sA n d M u l t i f i l e P r o c e s s i n g 6-39

640

Review6

1.

What are match fields used for when assignedto a single file?

2.

lf a record type has two match fields, which match field is assignedM1 and which is
assignedM2?

3.

Referring to the following Input sheet, indicate the errors in assigningmatch fields
and the reasonsthe specificationsare in error.

RPG
IBil

.,"

"

,"".

INPUTSPECIFICATIONS

G X 2 19 0 9 4 U / M 0 5 0 '

Bu!,esMach..co.oom,o.
Card E ecrro

__i

I

Record

ldentification

Codes

a

rc
T

f;
t

,",,

r, ,al;

F ieid Name

o
E !

=

a

To
I
i

"T"

13

.MPL AWE A

'-f ;

E

)I
t

[;

!
a
3

:-

lil-

)tlM

=

llt:Zl ddf
I LIO {flsnjr
TI
idr r r

T
T

/l

i

!J

r i

I

I

! n

6

Jc tr l^

tl /r" t

) t k l

1*I

i

d
!

Blanr

l

lTa

I

i8
0 9

I

,1 6i

I

tlr

:i

3
a

l:

tr

tf
-f - f i

I

Field
Indicators

Filename

o 1
tr+

Jenriicdronl

F ield Location

:

t5 16 J7 18 19 80

Proedm lT-ffTr_l

I

2

;

:f

,","ii'_

N!mbe,

f'17
z

I tljl

ltr/|

-r I
AI

4i

I

ta

h

tf,t

1lr
-f

) t

I

I

I
I

-ri

T

-

f

4.

Must matchfieldsbe assigned
to all recordtypesin.afile?

5.

G i v e nt h e f o l l o w i n gd a t aa b o u ta f i l e n a m e dE M p L o y E E ,c o d et h e i n p u ts p e c i f i c a tionswhich describethe recordtypesin an OR relationship:

-r

f
I

Recordt,ype01 identifiedby the characterA in positiong6.
Recordt'ype02 identifiedby the characterB in position96.
Field t\ame
NAMT:
DEPT
CODE
ADDFIES
E M P N U M( m a t c hf i e t d )

6.

Record Positions
5 - 15
1-4
8-9
16-30
42-45

Record Type
recordtype 02 only
both recordtypes
recordtype 01 only
recordtype 02 only
both recordtypes

Whatare matchfieldsusedfor when assigned
to multipleinput, update,or combined
files?

Review 6

6-41

Referto the followingprogramcyclesto answerquestions
7 and g:

'
a

"/*l'

o

DetailCalculations
and Output

' .

/,.+l

Detail Calculations
and Output

Record 1 selected

Record 2 selected

a

a

I

I
t

I

t

o

a

J

Total Calculations
and Output
a

Total Calculations
and Output

a

PROGRAM
C Y C L E1

a

a

PROGRAM CYCLE 2

7.

when is the MR indicatorseton and off for the first
recordselectedfor processing?

8.

when is the recordidentifyingindicatorfor record1
seton and off?

L

Definean unmatchedrecord.

1 0 . lf a primaryfile recordis serected
for processing,
what conditionmust be met for the
Ml? indicatorto be seton for that record?

1 1 . lf a secondaryfile recordis serected
for processing,
what conditionmust be met for
thr"'MR indicatorto be seton for that record?

12. Assumean lrEM f irereadfrom the MFCU or MFCM
containstwo recordtypes. which
spercification
line on the followingoutput sheetis correctin order
to stackerselect
unmatchedrecordsof recordtype 01 into stacker3? What
arethe other two stacker
sel,ection
specificationsi ncorrect?

cv2r.@0

**ffi"r

r

q

.

3

u/M o5o.

75 76 71 7A 79 aO
m t t t l l t l

, d " " , r , . " , , " t"_1_ l _ l l _ | |

End

Constanror Edil \for d

?

0 3

o

014

o

;li

o

o l6l

o

i+

6.42

I
-t-

TI
L

I

L.i

I

I

rl

+jj
Tlr

fl

13'

An item numberfield is assigned
asa matchfield for processing
the two filesshown.
ldentify th,ernr,"n'nn records(recordsforwhichMR is on),
the unmatchedrecords,
and the recordswith no matchfield assigned.

*D/\TE

HAUS

DOE

JA

ST

051309

050669

105 |
101|
I
I
Item
Number

I
I
I

Primary File

14.

Secondary File

R e f e r r i n tgo t h e f i l e ss h o w ni n question13, specifythe order in which
the records
would be processed.

1 5 . what doesan E in column 17 of the FireDescriptionsheetindicate?what does
an
A o r D i n c o l u m n1 8 i n d i c a t e ?

1 6 . Whatdo the followinginput specifications
causeto happen?

RPG INPUTSPECIFICATIONS

**ffl"- ff:;L",..fiii:rt*

Review 6

6-43

Review Problem
The data processingdepartment is to prepare a weekly labor
distribution report showing
t h e t o t a l n u m b e r o f h o u r s w o r k e d b y e a c h e m p l o y e e ,a s w e l l
asthe total numberof hours
w o r k e r db y a l l e m p r o y e e sw i t h i n a d e p a r t m e n t . T h e r e f o r e ,
the report must be organized
b y d e p a r t m e n tn u m b e r a n d b y m a n n u m b e r w i t h i n a d e p a r t m e n t .
Two input files are necessaryto provide data for the report:
a . P M S T E R i s a m a s t e rp a y r o l l f i l e c o n t a i n i n gt h r e e t y p e s o f
records:
D a t e r e c o r d- f i r s t r e c o r d i n f i l e .
lDepartmentname records.
l [ m p l o y e e m a s t e rr e c o r d s .
Theremployee records are in ascendingsequenceby department number and
by man
n u r n b e rw i t h i n a d e p a r t m e n t . A d e p a r t m e n t n a m e r e c o r d a p p e a r sw i t h i n
the file immedi.
ately before the group of employee records for that particular departmenr.
b ' L A B O R i s a f i l e o f d a i l y r e c o r d sc o n t a i n i n gt h e n u m b e r o f h o u r s a n e m p l o y e e
worked.
Sinr:eeach employee's daily hours are recorded on a separaterecord, there will
be more
t h a n o n e L A B O R r e c o r d f o r e a c he m p l o y e e .
T h e L A B O R f i l e i s a l s o i n a s c e n d i n gs e q u e n c eb y d e p a r t m e n t n u m b e r a n d
by man number within a department.

PMSTER File - 3 Record Types
Date Record Layout

DI DATE
'1"r."

urlr.r!..2,2.rr_lrzns.rr

DepartmentName Record Layour
FIRSTI SECNDI

Employee MasterRecord Layout
I.D.

DEPT MANNo

CODE

Yl

NAME

RATE

e l u r r t . r t n r r a r t

Man
Number

Employee Name

a t t r t o a r a t . r

Hourly
Rate (2 decimal
positions)

644

LABOR FiIe- 1 RecordType
DEIPT

MANNO H

Hours
Worked

g e t w o f i l e s ,t h e r es h o u l d
I n p r o c e s s i nt h
b e a n e m p l o y e em a s t e r e c o r dr e l a t e dt o a l l L A B o R
records' In fact, morethan one LABoR record
will matchthe sameemproyeemasterrecord
f r o m t h e P M S T E Rf i l e . H o w e v e ri,t i s p o s s i b l e
t h a t t h e L A B o R f i l e c o n t a i n st h e f o l l o w i n g
unmatchedrecords:
Recordswith errorsin matchfields.
Recordsfor new emproyees
for whom emproyeemasterrecordshavenot yet been
created.
l f y o u r e a dt h e L A B o R f i r ef r o m t h e M F c u
o r M F C M ,u n m a t c h e dL A B O R r e c o r d s h o u r d
be stackerselectedinto stacker3. Processing
shouldend when the lastrecordfrom the
LABOR file hasbeenprocessed.
F o r t h i s p r o g r a r ns.e ei f y o u c a nc o d et h e f o l l o w i n g :
1'

F i l ed e s c r i i p t i osnp e c i f i c a t i o n( rse a dt h e f i r e sf r o m

2.

I n p u t s p e c i fc a t i o n s .

M F C U .M F c M . o r D r s K ) .

output'format specifications
necessary
to stackerselectunmatchedLABoR cards
u s i n gt h e l / I F C Uo r M F C M .

Review 6

6-45

AnswersTo Review 6

1.

M a t c h f i e l d s a r e u s e dt o s e q u e n c ec h e c k c a r d sw i t h i n a f i l e .

2.

T h e h i g h e re n t r y , M 2 , i s a s s i g n e dt o t h e m o r e i m p o r t a n t f i e l d .

3.

R e a s o n sf o r s p e c i f i c a t i o ne r r o r s :
Line 07 -

M a t c h f i e l d s o f t h e s a m e l e v e lm u s t b e t h e s a m e l e n g t h . A l s o , f i e l d s
h a v i n gt h e s a m e n a m e m u s t b e t h e s a m e l e n g t h , r e g a r d l e sisf t h e y a r e

a s s i g n e da s m a t c h f i e l d so r n o t .
L i n e 0 8 - - M a t c h f i e l d s o f t h e s a m e l e v e lm u s t b e i n t h e s a m ef o r m a t ( a l p h a m e r i c
or numeric) if the fields have the same name. Also. f ields with the
s a m en a m e m u s t b e i n t h e s a m ef o r m a t ( a l p h a m e r i co r n u m e r i c ) , r e g a r d l e s si f t h e y a r e a s s i g n e da s m a t c h f i e l d so r n o t .
L i n e 1 0 - E v e r y r e c o r d t y p e a s s i g n e dm a t c h f i e l d s m u s t c o n t a i n t h e s a m en u m b e r
of match f ields.

4.

No. Bemember that record types without match f ields are selectedbefore record
typeswith match f ields.

q

A l l f i e l d s w h i c h a r e c o m m o n t o a l l r e c o r d t y p e s m u s t b e d e s c r i b e df i r s t . A l l f i e l d s r e l a t e d t o a p a r t i c u l a rr e c o r d t y p e a r e t h e n d e s c r i b e dt o g e t h e ra s a g r o u p . F o l l o w i n g
t h e c o m m o n f i e l d s ,f i e l d s r e l a t e dt o e i t h e r r e c o r d t y p e 0 ' l o r t h o s e r e l a t e dt o r e c o r d
t y p e 0 2 m a y b e d e s c r i b e dn e x t , a s f o l l o w s :

RPG INPUTSPECIFICATIONS
.,;" r

j-;Iii,l

0

8

6-46

i-

t

al

Tkil;;Na;-

i-=]

i

Pageo( GC21_7567-2
tssued21 December
1g7g
B y T NL : c N 2 1 - 5 7 0 9
M a t c h f i e l d s a r e u s e df o r r w o p u r p o s e s :
a . S e q u e n c ec h e c k i n gt h e c a r d si n e a c h f i l e
b . M a t . c h i n gr e c o r d sb e t w e e nt h e t w o f i l e s t o d e t e r m i n et h e
order of processing

7.

MR se;fon between totar time and detair time operationsduring program
cycte r.
MR ser:off between totar time and detair time operationsduring program
cycre 2.
B e c o r d i d e n t i f y i n g i n d i c a t o rs e t o n i m m e d i a t e r ya f t e r
r e c o r d i s s e r e c t e dd u r i n g p r o gramcycle 1.
R e c o r c li d e n t i f y i n g i n d i c a t o r s e t o f f f o i l o w i n g d e t a i rt i m e
o p e r a t i o n sd u r n g p r o g r a m

cycle1.

9.

A n u n r n a t c h e dr e c o r d i s a r e c o r c li n e i t h e r i n p u t f i l e w h i c h
d o e s n o t h a v ea m a t c h i n o
r e c o r d ( s a m em a t c h f i e l d ) i n t h e o t h e r i n p u t f i l e .

10.

T h e r e r n u s t b e a r e c o r d i n t h e s e c o n d a r yf i r e w i t h t h e
s a m e m a t c h f i e l d ( s )a s t h e
r e c o r di n t h e p r i m a r y f i r e .

1 1 . T h e m e r t c hf i e l d ( s )o n t h e s e c o n d a r yf i l e r e c o r d m u s t
b e t h e s a m ea s t h e m a t c h f i e l d ( s )
o r r t h e l a s tp r i m a r y f i l e r e c o r d p r o c e s s e d .

12

L i n e 0 3 i i s a c o r r e c t s p e c i f i c a t i o nf o r s t a c k e rs e r e c t i o n
o f u n m a t c h e dr e c o r o s .
L i n e 0 1 i s i n c o r r e c tb e c a u s et h e r e i s n o r e c o r d i d e n t i f y i n g
i n d i c a t o r s p e c i t y i n gt h e
t y p e o f r e c o r d t o b e s t a c k e rs e l e c t e d .
L i n e 0 5 i s i n c o r r e c tb e c a u s es t a c k e rs e l e c t i o no f a r e c o r d
o n t h e b a s i so f a m a t c h i n g
o r n o t r n a t c h i n qr e c o r d c o n d i t i o n s h o u l d b e d o n e a t d e t a i l
time, not at total time.

tJ.

M a t c h i n g r e c o r d sa r e r e c o r d sf r o m b o t h f i r e sc o n t a i n i n g
i t e m n u m b e r s1 0 1 , 1 0 7 ,
212, and 298.
T h e t h r , : eu n m a t c h e dr e c o r d sf r o m t h e p r i m a r y f i l e c o n t a i n
i t e m n u m b e r s1 0 5 , 1 0 5 ,
a n d 2 6 1 ' ' T h e o n e u n m a t c h e dr e c o r d i n t h e s e c o n d a r yf i l e
c o n t a i n si t e m n u m b e r 1 g 7 .
*D,ATE
The
r e c o r d f r o m t h e p r i m a r y f i l e a n d t h e t w o n a m e r e c o r d sf r o m
tne secondary
f i l e a r e r e c o r d sw i t h n o m a t c h f i e l d sa s s i q n e d .

1 4 . T h e r e c o r d sw o u l d b e p r o c e s s e di n t h e f o l l o w i n q o r d e r :

P r i m a r yF i l e

S e c o n d a r yF i l e

A n s w e r sT o R e v i e w 6

647

P a g eo f G C 2 1 - 7 5 6 1 - 2
l s s u e d2 1 D e c e m b e r. 1 9 7 9
By TNL: cN21-5709

1 5 . A n E m e a n st h e p r o g r a ms h o u r dc h e c k
that fire for end of fire. rf end of f ireis

r e a c h e d( a l * r e c o r d r e a d ) ,u s u a l l y p r o c e s s i n g
o f r e c o r d si s s t o p p e d . H o w e v e r ,i t
e n d o f l i l e i s r e a c h e di n a m a t c h i n gr e c o r d sp r o g r a m ,
t h e m a t c h i n g r e c o r d sa n d
r e c o r d sw i t h n o m a t c h f i e r d sf r o m t h e
o t h e r f i r e a r e p r o c e s s e db e f o r e t h e p r o ,
gram is ended.

A n A o r D e n t r y i n d i c a t e st h a t a n i n p u t f i r e
i s i n a s c e n d i n go r d e s c e n d i n gs e q u e n c e
a c c o r d i n gt o t h e m a t c h f i e l d ( s )o n t h e r e c o r d s .

1 6 . F i r s t , t h e R E G I o N m a t c h f i e r d sa r e c o m p a r e d
t o d e r e r m i n ei f t h e r e i s a m a t c h i n g
r e c o r dc o n d i t i o n a n d , t h u s , w h i c h r e c o r d p r o c e s s .
to
N e x t , t h e c o n t e n t so t t h e
R E G I o N f i e l d a r e c h e c k e do n t h e r e c o r d
s e r e c t e dt o d e t e r m i n e i f a c o n t r o r b r e a k
h a s o c c u r r e da n d , t h u s , i f L 1 s h o u l d
be seton.

6-48

Solution to the Revielv prr.rblern
F i l e D e r s c r i p t i oS
n p e r c i cf a t i o n s
a, MFCUcr MFCMfiles:

File fJeseription Specification

'T

rI

I
I
I

I

I

I

i

-

o

Devirre

Lb!tstwttatrrag6.

b . D i s k f i l e s ( s e q u e n t i a l:)

File Description Specif ication
FileAddinon/Unor&red

Extenr Fxit
ior Cylio&r Oedlow
Lahl

G 6r D lr

9, s"r

t'

zr L

o, tr

6

Exrt

r!

AnswersloReview6

6-49

I r"rputSpecifications
R P G I N P U TS P E CFI I C A T I O N S

IBM,."..
f';;;-

---T;";;

_--

1""'s1ll:,

P*r,

'

'',

75 /6 1/ 1a 1g 80
r.:
-l
f [-f
L_l _l_l
:
, _l

P'oq
"1

J

Record ldentif ication Codes
Fiefti
In d i c a t o r s

.lrl
fir

ril
i+l

-iF
lr

+fi

..-f +

I f *

rii

Ij rf

rli

]rr
.- l--r-

rt
, t

lrl

' l
i

l

tf

f

i

t t

rll r

l

ilr

L.

Output Specifications

OUTPUT

SPECIFICATIONS

G X 2 1S C

U 1 M0 5 0 .

Card Elecro Nuhrpr

,.

-.

Dale

1

i

Z - h ! .

46t4r

ttl
lrl
&50

I
T
t-

lt

I
i

I
I

I

ii

48r49r50,51

52r53r5ar55,56

ti

ll

57 5a 59 60 L;1 62 63 64

65 66 67 S

1i.

itrill

fjg

I 1r i1 f r
I 1 l il+

Tl 1 - i t t
I

r fl

Chapter7. ProgrammedControl of Input and Output

C H A P T E R7 D E S C R I B E S :
H o w t o a l t e r t h e o r d e r o f p r o c e s s i n gi n p u t f i l e s u s i n g F O R C E .
H o w t o r e a d o n e o r m o r e r e c o r d sp e r c y c l e f r o m a d e m a n d f i l e .
H o w t o d o r e p e t i t i v eo r e x c e p t i o no u t p u t d u r i n g c a l c u l a t i o n s .

B E F O R E R E A D I N G T H I S C H A P T E RY O U S H O U L D B E A B L E T O D E S C R I B E :
Multifile processing.
Lool:-ahead.
E n d - o f - f li e c o n d i t i o n .
*PLI\CE.

R P G l l p r o g r a ml o g i c( C h a p t e r1 ) .

AFTER READING THIS CHAPTERYOU SHOULD BE ABLE TO DESCRIBE:
R P G l l F O R C E o p e r a t i o nc o d e .
U s i n g F O R C E w i t h t h e l o o k - a h e a df e a t u r e .
U s i n , 3t h e R P G l l R E A D o p e r a t i o nc o d e t o p r o c e s sd e m a n d f i l e s .
R P G l l E X C P T o p e r a t i o nc o d e .
Note: You can use the review questionscontained in Review 7 at.the er.rdof this
c h a p t e rt o t e s t y o u r c o m p r e h e n s i o no f e a c h t o p i c i n t h e c h a p t e r . O u e s t i o n sa r e
g r o u , p e da c c o r d i n gt o t h e t o p i c t o w h i c h t h e y a p p l y . A n s w e r sf o l l o w t h e r e v i e w
q u e s t oi n s .

P r o g r a m m e dC o n t r o l o f I n p u t a n d O u t p u t

1-1

INTRODIJCTION
N o r m a i l y , r e c o r d sa r e r e a d , i d e n t i f i e d ,s e l e c t e df o r p r o c e s s _
r n g ,a n d o u t p u t a c c o r d i n gt o t h e f i x e d l o g i co f t h e R p G l l
o b j e c t p r o g r a r n . S o m e t i m e s ,h o w e v e r ,y o u n e e c tl o h a v e
d i r e c t c o n t r o i o v e r t h e i n p u t a r r do u t p u t o f y o u r p r o g r a m .
R P G i l p r o v i d e ss e v e r aoi p e r a t i o r rc o d e sw h i c h g i v e y o u t h i s
i : o n t r o l . B y u s i r r gt l r e F O R C E o p e r a t i o nc o d e i n y o u r
own
, : a l c u l a t i or o
r u t i n e ,V O uc a n o v e r r i d en o r m a l R p G l l m u l t i _
f i l e l o g i c f o r s e i e c t i n gi n p u t r e c o r . c lfso r p r o c e s s i n g .y o u
r : a na l s ; oc l o c e r t a i nl < i n d so f i n p u t a n d o u t p u t d u r i n g c a l c u a t i o n t i n r e b v u s ! r r gt h e R E A D a r . r dE X C I T To p e r a t i o nc o d e s .
l V a t e : f h e C F i A I N o p e r a t i o nc o c . i e
a l s oa l l o w sp r o g r a m n r e d
r : o n t r o lo f i n p u t a n i l o u t p u t o p e r a t i o n s . T h e C F I A I N o p e r a 1:ionis explained in iBM System/3 RpG il Disk File pro_
ctessi
ng' Pragrasnrner "s Gu i de, GC2it -7 566.

t\LTERING THE ORDER OF PROCESSTNG
Fil-ES
I F O R C E , 0 P ER A T T O Nl
l l P G l l u s e st w o r n e t h o d st o d e t e r m i n et h e o r d e r i n w h i c h
r e c o r d sa r e p r o c e s s e ci ni a n r u i t i f i l e p r o g r a r n .
. r l f r n a t c hf i e i c j sa r e n o t s p e c i f i e ctii t r e i t h e r f i l e , a l l r e c o r d s
a nt l ' l e ! t r r i m a r yf i l e a r e p r o c e s s e df,o l i o w e d b y t h o s e i n
t h e s e c o n d a r i /f i i e s i n t h * "o r r . l e d
r e f i n e c Jo n t h e F i l e D e ,
s c r i p t i o ns h e e t s .
o W h e n r n a t c hf i e l c l sa r e a s s i g n e ctih, e R p G l l l o g i c o f
m a t c h i n q r e c o r d sd e t e r m i n e sf r o n r i r y h i c hf i l e t h e n e x t
recordis to be processed.
l - h e o r r l e r o f p r o c e s s ; r rdr g
e t e r n r i n e db y R p G l l l o g i c i s a p _
p r r o p r i a t ef o r m o s t o f y o u r m u l t i { i l e p r o g r a m s . H o w e v e r ,
f o r c e r t a i r rp r o g r a n l s "i t m a y b e n e c e s s a r yt o h a v e s o m e o f
t h e r e c o r d si r ) t h e t u / o f i l e s p r o c e s s e di n a n o r d e r o t h e r t h a n
t h a t i n w h r c h R P G i N l o g i c w o u l d s e l e c tt h e r e c o r c i s .
I t r e c o r d c i a nb e p r o c e s s e coju t o f o r d e r o n l y i f y o u i n d i c a t e
t , r t h e p r o g r a r nt h a t t h e f i i e c o n t a i n i n gt h a t r e c o r c li s t o b e
f r f , r c e c jT. c , d o t h i s , y o u m u s t c o d e a d c l i t i o n a sl p e c i f i c a t i o n s
t , ) o v e r r i d en o r n r a l R P G i i r n u l t i fi l e l o g i c .

7-2

R e g a r d l e sosf h o w y o u r f i l e sa r e o r g a n i z e d t, h e f o l l o w i n g
s i t u a t i o n sr e q u i r et h a t y o u a l t e r t h e o r d e r o f p r o c e s s i n g :
1.

M a t c h f i e l d sc a n n o tb e a s s i g n e tdo t h e f i l e sa n d y o u
w r s ht o :
a . A l t e r n a t e p r o c e s s i n gb e t w e e nt w o f i l e s .
b . P r o c e s sa p r i m a r y f i l e r e c o r d f o l l o w e d b y a p a r t i c u l a r n u m b e r o f s e c o n d a r vf i l e r e c o r d s .
c . P r o c e s sa s e c o n d a r yf i l e r e c o r d o n l y w h e n i t
m a t c h e sa p r i m a r y f i l e r e c o r d .

2.

M a t c h f i e l d sa r e a s s i g n e dt o b o t h i n p u t f i l e s . y o u
w i s h t o p r o c e s so n e p r i m a r y f i l e r e c o r d ,f o l l o w e d b y
m a t c h i n gs e c o n d a r yf i l e r e c o r d s ,t h e n t h e r e s t o f t h e
m a t c h i n gp r i m a r y r e c o r d s .

T o a l t e r t h e o r d e r o f p r o c e s s i n gy, o u m u s t f i r s t d e t e r m i n e
w h i c h f i l e i s t o b e p r o c e s s e d - w h e na n d u n d e r w h i c h c o n d i t i o n s . O n c e y o u k n o w t h e o r d e r ,t h e n e x t s t e p i s t o d e t e r r n i n e ,f o r a p a r t i c u l a rp r o g r a m m i n gc y c l e , w h e t h e r t h e R p G
l l l o g i c w i l l s e l e c tt h e a p p r o p r i a t er e c o r d o r i f y o u m u s t
f o r c e t h e p r o c e s s i n go f t h a t r e c o r d .
T h e f i r s t r e c o r d t o b e p r o c e s s e di n a n y p r o g r a mc a n o n l y b e
s e l e c t e db y R P G l l l o g i c i n t h e u s u a lw a y . T h e r e a f t e r ,t o
a l t e r t h e o r d e r o f p r o c e s s i n gy, o u t e l l t h e p r o g r a mt o f o r c e
a r e c o r df r o m a f i l e w h i c h w o u l d n o t o r d i n a r i l y b e p r o c e s s e d
n e x t . O n c e t h e f o r c e d r e c o r d i s p r o c e s s e da, n d p r o v i d i n ga n o t h e r r e c o r d i s n o t f o r c e d , t h e R P G I I l o g i c s e l e c t st h e n e x t
r e c o r d i n t h e u s u a lw a y . T h i s i s t h e r e c o r dw h i c h w o u l d
h a v eo r d i n a r i l y b e e n p r o c e s s e di f t h e o t h e r f i l e h a d n o t b e e n
forced.

Specifying the Next File to Process
T o p r o c e s sa r e c o r d o u t o f i t s n o r m a l s e q u e n c ey, o u s p e c i f y
o n t h e C a l c u l a t i o ns h e e tt h e F O R C E o p e r a t i o nc o d e a n d
the nameof the file which is to be forced in the nexf orog r a mc y c l e ( F i g u r e7 - 1 ) .

A,ssuminga record type 01 from the primary f ile is being
p r o c e s s e dt .h e c a l c u l a t i o no n l i n e 0 1 i s p e r f o r m e d . T h e n e x t
d e t a i l - t i m ec a l c u l a t i o ns p e c i f i c a t i o nf o r r e c o r d t y p e 0 1 i n d i ciatesthat the secondaryfihl (SECOND) is to be forced. The
F O R C E d o e s n o t o c c u r i m r n e d i a t e l y ,h o w e v e r . T h i s s p e c i f i c a t i o n o n l y t e l l s t h e p r o g r a mt o r e m e m b e rt h a t a r e c o r d
f r o m t h e f i l e S E C O N D i s t c r b e p r o c e s s e dn e x t . A n y a d d i t i o n a l c a l c u l a t i o n sa n d / o r o u t p u t f o r t h e r e c o r d b e i n g p r o c essedare performed first to complete the present program
cycle.
l r t t h e b e g i n n i n go f a n o r m a l p r o g r a mc y c l e , R P G l l l o g i c
looks at the two records av.ailablein order to select the one
to processduring that cycler. However, if the record from
t h e f i l e w h i c h w o u l d n o t n o r m a l l y b e s e l e c t e di s t o b e p r o c essed,this must be indicated to the program before the beg i n n i n go f t h e c y c l e . l f a f i l e i s t o b e f o r c e d , t h e r e i s n o
n e e d f o r R P G l l l o g i c t o c o m p a r et h e r e c o r d sa n d m a k e a
s e l e c t i o n . T h i s i s t h e r e a s o r trh a t , i f a f i l e i s t o b e f o r c e d ,
t l r e F O R C E m u s t b e i n d i c a t e dd u r i n g t h e p r o g r a m c y c l e
i m m e d i a t e l yb e f o r e t h e c y c l e i n w h i c h t h e F O R C E i s t o
occur.

RPG

D e p e n d i n go n y o u r p r o g r a m ,y o u m a y n o t h a v et o f o r c e a
r e c o r d i n e v e r y p r o g r a m c y c l e . F o r s u c h s i t u a t i o n s ,y o u
m u s t i n d i c a t ew h e n t h e F O R C E i s t o b e d o n e b y s p e c i f y i n g c o n d i t i o n i n g i n d i c a t o r si n c o l u m n s9 - 1 7 o f t h e C a l c u l a t i o n s h e e t ( F i g u r e 7 - 1 ) . W h e t h e rt h e F O R C E i s t o b e p e r formed in the next cycle or not may depend on any of several conditions:
o The type of file or record type being processedat the
time.
r

The number of recordswhich have been processed.

o The result of a calculation performed.
o The contents of a field on the record being processed.
o The contents of a f ield on a record which has not been
processedyet.
W i t h t h e s ep o i n t s i n m i n d , l e t ' s d i s c u s sa j o b i n w h i c h y o u
can determine if the order of processingmust be altered on
the basisof the type of record being processed.

CALCULATION SPECIFICATIONS
15 76 11 18 7g AO
G,aphic

--t

I

Ca,d

Electo

N!mEr

l

l

l

tu€Ll ld

P

'

t

u

'

.

m

l

l

l

l

l

l

r".,n"'."| I | | I | |

Additional calculations.

lFigure7-1. Specifying the Fil,eto be Processedin the Next Program Cycle

Programmed Control of Input and Output

7'3

ArlternatingProcessingBetween Two Files
T h e t w , r f i i e s i n F i g u r e 7 - 2 e a c hc o n t a i n o n e r e c o r d f o r e v e r y
s a l e s m a ni n a c o m p a n y . T h e M A S T E R r e c o r d sa r e a r r a n g e d
i n a l p h a b e t i c aolr d e r b y s a l e s m a n a m e ;t h e M O N T H f i l e i s
a r r a n g e di n a s c e n d i n gs e q u e n c eb y s a l e s m a nn u m b e r . A l _
t h o u g h t h e r e i s n o c o m m o n m a t c h f i e l d , t h e r e c o r d si n t h e

T h e t w o f i l e s a r e t r c b e p r o c e s s e dt o d e t e r m i n et h e a m o u n r
o f c o m m i s s i o ne a r r r e db y e a c h s a l e s m a n .T o d o t h i s , a s a l e s m a n ' s c o m m i s s i o nr a t e f r o m h i s M A S T E R r e c o r d m u s t b e
m u l t i p l i e db y t h e a m o u n t o f h i s s a l e sc o n t a i n e do n h i s
M O N T H r e c o r d ( F i g u r e T - 2 ) .T h e c a l c u l a t e d
c o m m i s s i o ni s
t h e n r e c o r d e di n t h e s a l e s m a n ' M
s ONTH record.

t r v o f i l e s a r e , n e v e r t h e l e s si n, a o n e , t o . o n ec o r r e s p o n d e n c e .
S a l e s m e nn u m b e r sh a v eb e e n a s s i g n e ds u c h t h a t t h e y c o r r e s _
p l n d t o t h e o r d e r o f t h e s a l e s m e nn a m e s . T h u s , t h e f i r s t
r t : c o r di n e a c h f i l e i s f o r B a k e r ( s a l e s m a n# 1 0 ) ; t n e s e c o n d
r e r c o r di n e a c h f i l e i s f o r C o s t e l l o( s a l e s m a n# 2 0 ) , a n d s o o n .

RIME .RO85ffT

25

NELSOI\C KEIf
HABT.I{ESS DAVE
HAGUE

41

0568

, :35':

159085

COST€LLO .TOM

tt

27684a
23

tt

.;,;,$91g$05h,. ,,
Elranch
, ', , , , , , N b i a e
. ,,,,, , ,i , ,:,,,,, :: ', ,, : , :

30 -

tl

Commission
Rate

MASTER File
Figure 7-2, Files to be Alternately processed

74

367560
089760

JOHN

BAKER FRANK

137896

,,,!|e::r

0566
41

'5o

0568

.,lO.iilii..i.

fl

t
tt

sa$ryan
NUrnbdi

MONTH File

34s6e5

tl

l
l
l

sates

The two files are defined and the records describedwith
t l r e s p e c i f i c a t i o n s h o w n i n F i g u r e7 - 3 . M A S T E R , t h e p r i n t a r y f i i e , i s a s s i g n e dr e c o r c li d e n t i f y i n g i n d i c a t o r 0 1 . l n d i c a t o r 0 2 i s a s s i g n e dt o t h e s e c o n d a r yf i l e , M O N T H . S i n c e
I I I O N T H i s a c a r d f i l e t o b e u s e df o r b o t h i n p u t a n d o u t p u t ,
i l .i s d e f i n e da s a c o m b i n e df i l e . ( M O N T H c o u l d a l s ob e d e f i n e d a s a n u p d a t ef i l e . o n a n o t h e r d e v i c e . )

T h i s p r o g r a m m u s t p r o c e s st h e t w o f i l e sa l t e r n a t e l y ;t h a t i s ,
every primary file record processedmust be followed by a
s e c o n d a r yf i l e r e c o r d . L i k e w i s e ,e v e r y s e c o n d a r yf i l e r e c o r d
processedmust be followed by anotlrer primary f ile record.
In this case,the MASTER record for a salesrnanis read to
m a k e t h e c o m m i s s i o nr a t e a v a i l a b l e .H i s M O N T H r e c o r d i s
then processed,to caiculate the commission and record the
a m o u n t i n t h e M O N I - F Ir e c o r d . T h e n , t h e n e x t M A S T E R
and the next MON-N-Hrecord are processedIn the same way
for the second salesrnan

File Description Specif ication

Leng$
ot

of

REo.d

Key

Field

tud.est

q
Field

lor Cylindc.

SVmbolic
Deviee

Ove.llow

Label Exil

O t h e r d e v i c e sc a n
b e u s e d ,d e p e n d i n g
on the systemand
c c l n f i g ur a t i on

RPG INPUTSPECIFICATIONS

G X 7 19 0 9 4 U r M 0 5 0 -

7a t6

7/

1A t9

AO

'.,"
Lll",_l;::n.,""l=f-Tlll

6 1 ,

Figure 7-3. Specifications to Define and Describe Files to be ProcessedAlternately

F r o g r a n l r n e cCl o n t r o l o f I n p u t a n d O u t p u t

7'5

l i i n c e n o m a t c h f i e l d s a r e a s s i g n e dR
, p G l l l o g i cw o u l d n o r _
r n a l l y p r o c e s sa l l r e c o r d si n t h e p r i m a r y M A S T E R f i l e b e f o r e

During processingof the forced record (02 on), the comm i s s i o ni s c a l c u l a t e da n d r e c o r d e di n t h e M O N T H r e c o r d
( F i g u r e7 - 4 ) . O n l v t h e s p e c i f i c a t i o n sf o r r e c o r d t y p e 0 2 a r e
d o n e . T h e r e f o r e ,t h e F O R C E o p e r a t i o n i s n o t p e r f o r m e d .

a n y o f t h e s e c o n d a r yM O N T H r e c o r d s . T o a l t e r n a t et h e f i l e s .
)/ou must tell the program to force a secondary file record
e v e r y t i m e a p r i m a r y f i l e r e c o r d i s b e i n g p r o c e s s e d .W h e n a
I/IASTER record is being processed.record iclentifying in_

S i n c en o F O R C E w a s i n d i c a t e di n t h i s c y c l e ( 0 2 o n ) , R p G l l
l o g i c a g a i nt a k e so v e r t o s e l e c ta r e c o r d ,a t t h e b e g i n n i n go f

c l i c a t o r0 1 i s o n . T h u s , y o u s h o u l d c o n d i t i o n t h e F O R C E
c l p e r a t i o nt o b e p e r f o r m e do n l y i t 0 1 i s o n { C a l c u l a t i o n
s h e e ti n F i g u r e7 - 4 ) .

t h e n e x t c y c l e . T h u s , t h e s e c o n dp r i m a r y f i l e M A S T E R r e c o r d i s p r o c e s s e d( 0 1 o n ) . P r o c e s s i n o
gf the filescontinues
w i t h t h e n e x t M O N I - H r e c o r d b e i n gf o r c e d a n d t h e n a n o t h e r
M A S T E R r e c o r d b e i n Es e l e c t e db y R P G l l l o g i c u n t i l a l l r e c ords have been processec.

l \ t t h e b e g i n n i n go f t h e p r o g r a m , R p G l l l o g i c a u t o m a t i _
c a l l y s e l e c t st h e f i r s t r e c o r d ,w h i c h i s a p r i m a r y f i l e r e c o r d .
S i i n c e0 1 i s o n , t h e F O R C E o p e r a t i o n i s p e r f o r " m e dt;h a t i s .
the program notes that a MONTH recorclis to be forced at
t h e b e g i n n i n go f t h e n e x t c y c l e .

RPG

CAL.CULATION
SPECIFICATIONS

I

it

l'-l-;i';iJril;;l

iiilli-i

l "*l 1_1.'

T

tl
OUTPUT

ll

Ij
rit
I

lii

+

SPECIFICATIONS

I

i 1 fc.,,,ri.-",r,,,,.',,,':

l l i _ ] 1

t

t

T

Frigure7-4, Conditioning Operations on Basis of Record Type

7-6

T

P a g eo t G C 2 1 - 7 5 6 7 - 2
l s s u e d2 1 D e c e m b e r 1 9 7 9
By TNL: GN21-5709

Forcing a Number of Recordsfrom a File
I n t h e l a s t e x a m p l e .t h e F t f R C E o p e r a t i o nw a s p e r f o r m e d
o n l y i f a p a r t i c u l a rr e c o r d i d e n t i f y i n g i n d i c a t o rw a s o n .
N o w l e t ' s c o n s i d e ra c a s ei n w h i c h y o u c o n d i t i o n t h e
F O R C E o p e r a t i o no n t h e b a s i so f w h e t h e r a r e s u l t i n gi n dicatoris on or off .
S u p p o s ey o u h a v ea n u m b e r o f c u s t o m e r sw h o p e r i o d i c a l l y
o r d e r i t e m s t o b e d e l i v e r e df r o m a c e n t r a lw a r e h o u s e .O n e
r e c o r d i s k e p t f o r e a c h u n i t i n s t o c k i n t h e w a r e h o u s e a, n d
another record for each cLrstomer'sorder of a particular
u nr t .

F o r t h i s r u n , t h e O R D E R f i l e ( F i g u r e7 - 5 . i n s e r t A ) c o n t a i n s
t h e w e e k ' s o r d e r r e c o r d sf o r t e l e v i s i o ns e t s ,u n i t n u m b e r
4607. The records show which customer placed the order,
and the quantity of television setswanted. The STOCK file
consistsof a separaterecord for each television set (unit
4 6 0 7 ) i n s t o c k ( F i g u r e7 - 5 , i n s e r t B ) . E a c h r e c o r d p r o v i d e s
t h e u n i t n u m b e r , l i s t p r i c e ,a n d s e r i a ln u m b e r o f t h e i t e m .
There are two purposesfor processingthe f iles. First. you
w a n t a n i n d i c a t i o n o f w h i c h o r d e r sc a n b e f i l l e d a n d w h i c h
o r d e r sc a n n o t b e f i l l e d . S e c o n d l y ,t h e S T O C K f i l e i s t o b e
kept up-to-date so it only contains as many records as there
a r e t e l e v i s i o ns e t sa v a i l a b l e .

Orders are processedaccording to the type of unit ordered.
T h e r e f o r ef,o r a p a r t i c u l a r u n , t h e p r i m a r y f i l e ( O R D E R )
, ; o n t a i n sa l l o r d e r r e c o r d sf o r o n l y o n e t y p e o f u n i t , a n d t h e
: s e c o n d a r fyi l e ( S T O C K ) c o n t a i n sa l l i n - s t o c kr e c o r d sf o r
that type of unit.
4607

4628

460-1

35905

WS6177O

12

Kl24110

2637

2012

1938

4607

4607
4607

@

05

09

4607

4607

35905

35905

4224320

D21Ax32

4607

35905

126AJ41

tt

t
t

l

U ni t
Number

List
Price

t
t

ORDER file

r
t

l
l

l

Serial
Number

STOCK file

rVote.' System/3 will allocate two decimal placesin the list
price, although a decimal does rrot appear in the f ield.
The list price in the stock file is logically representedas

$359.05.
lFigure7-5. Files for ProcessingCustomer Orders
P r o g r a m m e dC o n t r o l o f I n p u t a n d O u t p u t

7'7

T h e p r o g r a ms h o u l d p r o d u c ea p r i n t e d r e p o r t s h o w i n gw h i c h
o r d e r sc a n b e f i l l e d , a n d t h e a m o u n t e a c h c u s t o m e ro w e s
( F i g u r e7 " 6 ) . T h u s ,y o u m u s t d e t e r m i n et h e a m o u n t d u e
for each itern and the total amount for each orcier. A reco r < lf r o m e a c h f i l e m u s t b e a v a i l a b l eb e f o r e V o u c a n c a l c u l a t r :t h e i n f o r m a t i o n .

Controlling the Number of Times FORCE is performed
A f t e r R P G l l s e l e c t sa n d p r o c e s s easn O R D E R r e c o r d , y o u
m u s t F O R C E t h e p r o c e s s i n go f a n u m b e r o f S T O C K r e c ords. The quanrity ordered(QTY) from the ORDER rec-

S T O C K r e c o r d sf o r a n o r d e r h a v eb e e n p r o c e s s e dt,h e n e x t
O F i D E R r e c o r d i s s e l e c t e dt o r e p e a tt h e p r o c e s s ,

o r d i s u s e dt o c o n t r o l t h e n u m b e r o f t i m e s y o u f o r c e s e c o n d .
ary file records. The quantity is storedin a field, called
C O U N T , t o k e e p t r a c k o f h o w m a n y r e c o r d sa r e l e f t t o b e
forced for an order. Each time a STOCK record is forced,
t h e n u m b e r i n C O U N T i s r e d u c e db y o n e . W h e n C O U N T
reacheszero, enough STOCK records have been processed
f o r t h a t p a r t i c u l a ro r d e r . T h e n R P G | | l o g i c c a n a g a i nt a k e
o v e r t o p r o c e s st h e n e x t O R D E R r e c o r d ( F i g u r e 7 - 7 ) .

L o , c k i n ga t t h e t w o f i l e s , y o u c a n s e et h a t e v e r y r e c o r d h a s
a c , o m m o nf i e l d c o n t a i n i n gt h e u n i t n u m b e r . l t d o e s n o
g o o d t o a s s i g na m a t c h f i e l d t o c o n t r o l p r o c e s s i n go r o e r ,

T h e c a l c u l a t i o ns p e c i f i c a t i o n s h o w n f o r t h i s p r o g r a m ( F i g u r e 7 - 8 ) o n l y d e t e r m i n ei f a r e c o r d i s t o b e f o r c e d i n t h e
next cvcle.

F i l e sf o r t h i s p r o g r a mm u s t b e p r o c e s s e di n a s p e c i f i co r d e r .
T h e q u a n t i t y o r d e r e d( O T Y ) f r o m a n O R D E R r e c o r o m u s t
b e a v a i l a b l ef i r s t . T h i s q u a n t i t y i s u s e dt o d e t e r m i n eh o w
m a n y S T O C K r e c o r d sa r e t o b e p r o c e s s e d .W h e n e n o u g h

b e c r a u steh e u n i t n u m b e r i s a l w a y st h e s a m ef o r e v e r y r e c o r c . A l l r e c o r d si n t h e p r i m a r y f i l e w o u l d b e p r o c e s s e d
b e f o r e a n y s e c o n d a r yf i l e r e c o r d s .
R e m e m b e r ,t h e r e i s n o w a y y o u c a n c o n t r o l s e l e c t i o no f
t h e f i r s t r e c o r d t o b e p r o c e s s e di n a p r o g r a m . R p G l l l o g i c
a l w a y ss e l e c t sa p r i m a r y f i l e r e c o r d f i r s t w h e n m a t c h f i e l d s
a r e n o t s p e c i f i e d . S i n c ea n O R D E R r e c o r d m u s t b e a v a i l _
a b l r ,f.i r s t f o r t h i s p r o g r a m ,t h e O R D E R f i l e s h o u l d b e d e s i g n , a t e da s t h e p r i m a r y f i l e .

CUSTOMER
1938

2012

2637

ITEM
4607

4607

4607

OTY

A s s u m et h e f i r s t O R D E R r e c o r d ( r e c o r dt y p e 0 1 ) h a s b e e n
s e l e c t e dm
, a k i n g t h e q u a n t i t y o r d e r e d ( O T Y ) a v a i l a b l e .T h e
f i r s t c a l c u l a t i o ns p e c i fi c a t i o n ( l i n e 0 1 ) f o r t h i s r e c o r d t y p e
s t o r e st h e q u a n t i t y i n t h e C O U N T f i e l d . T h e n t h e p r o g r a m
d e t e r m i n e si f a n y S T O C K r e c o r d sa r e t o b e p r o c e s s e df o r
t h i s o r d e r ( l i n e 0 b ) . l f C O U N T i s g r e a t e rt h a n z e r o , i n d i c a t o r 2 7 t u r n s o n . W i t h 2 7 o n , l i n e 0 6 i s p e r f o r m e d ,i n d i c a ting a STOCK record must be forced in the next program
cvcle.

SERIALNO

COST

TOTAL

126AJ41
DZ1AX32
4324320
s15206H
K124110
436rG11
M32OCEW
TS91870
ws61770

359.05
359.05
359.05
359.05
359.05
359.05
359.O5
359.05
359.05

359.05
718.10
1077.15
1436.2A
1795.25
21U.30
2 5 r3 . 3 5
2872.40
3231.45

359.05
359.05
359.05
359.05
359.05

359.05
718.10
1077.15
1436.20
1795.25

o9

05

04
?oa o6

398.95
398.95
398"95
3425

4607

7()7 0n

'I196.85
1595.80

07
JO / .UJ

367.03
367.03
367.03

Figure 7-6. Printed Report Showing Customer Orders processed

1-8

398.95

367.03
734.06
11 0 1 . 0 9
1468.12

/ q t t h e b e g i n n i nogf t h e s e c o n dc y c l et h e n ,t h e f i r s t S T O C K
record(recordtype 02) is selected(by beingforced). Line
03 is performedto reducethe COUNTby one for this record beingprocessed.
The COUNT is then comparect
to zero
a g a i n( l i n e0 5 ) t o d e t e r m i n ei f a n y r n o r eS T O C Kr e c o r d a
s re
t o b e p r o c e s s ef d
o r t h i s o r d e r . l f C O U N Ti s s t i l l g r e a t etrh a n
t e r o ( 2 7 s e to n a g a i n )l,i n e0 6 i s p e r f o r m e d
a g a i n i,n d i c a t i n g
a n o t h e rS T O C Kr e c o r di s t o b e f o r c e da t t h e b e g i n n i n o
gf
t h e n e x tc y c i e .

START
RPG llselects
ORDER record

D u r i n gp r o c e s s i nogf t h e s e c o n dS T O C Kr e c o r d C
, O U N Ti s
a g a i nr e d u c e d
b y o n e ( l i n e0 3 ) . A s s u m i n g
C O U N Ti s n o w
a t z e r o ,t h e C O M P A R Eo p e r a t i o no n l i n e0 S s e t si n d i c a t o r
1 1 7o f f" W i t h 2 7 o f f . t h e F O R C Eo p e r a t i o no n l i n e0 6 i s n o t
p e r f o r m e d u r i n gt h i sc y c l e . A t t h e b e g i n n i n og f t h e n e x t
p r o g r a mc y c l et h e n ,R P G| | s e l e c ttsh e n e x t O R D E Rr e c o r d
f r o m t h e p r i m a r yf i l e i n t h e u s u aw
l ay.

records been
processedfor
th is
order?

F O R C Ea
STOCK record

Subtract I
from quantity

Figure 7-7. Determining When Stock Records Must be Forced to
Fill an Order

RPG

C A L C U L A T I O NS P E C I F I C A T I O N S

,,,"
LTi',-:;:ilil",."
L-Iffil

L""1

l

I

I

Figure7€.

I
l

t1

ii

-

1i

I
t

ll

l
T

T

lr

Controlling the Number of Times a File is Forced

P r o g r a m m e dC o n t r o l o f I n p u t a n d O u t p u t

-l'9

P a r l eo f G C 2 1 - 7 5 6 7 - 2
l s s u e d2 1 D e c e m b e r 1 9 7 9
By TNL: GN21-5709
A t t h i s p o i n t , a d d t h e s p e c i fi c a t i o n s f o r c a l c u l a t i n g t h e

a r n o u nd
t u e a n df o r p r i n t i n gt h e r e p o r t( F i g u r e7 - 9 ) . A n
O R D E Rr e c o r di s s e l e c t efdi r s t ,m a k i n gt h e O T y a v a i l a b l e .
C a l c u l a t i olni n e s0 1, 0 2 , a n d0 6 i n F i g u r e7 - g a r ep e r f o r m e d
f o r t h i s r e c o r d( r e c o r dt y p e 0 1 ) . F i r s t ,a T O T A L f i e l d ,t o
b e p r i n t e df o r e a c hg r o u po f c u s t o m e r si s. s e tt o z e r o( l i n e
0 1) . N e x t ,t h e q u a n t i t yo r d e r e di s m o v e di n t o t h e C O U N T

f i e l d ( l i n e0 2 ) . l f C O U N Ti s g r e a t etrh a nz e r o .i n d i c a t o 2
r7
i s t u r n e do n ( l i n e0 6 ) . a n d l i n e0 7 i s p e r f o r m e dt ;h e p r o gramis instructedto forcea STOCKrecordat the beginning
of the next cycle. Beforeforcing,however,the output speci
f i c a t i o n s( F i g u r e7 - 9 ,l i n e s0 8 - 11 ) a r ep e r f o r m e d
to print
d a t af r o m t h e O R D E Rr e c o r d .

--++_

RPG

CALCULATION SPECIFICATIONS

."..iI1",Factor 2

ilfirl
lillhi
RPG

OUTPUT

GX?r 9@O U/M 0S'

SPECIFICATIONS

,.,.ffi,,,_

15 16 77 18 19 80

Proe,am -T-TTIT_l
n . , ' , r , - ' . . f l l l i l l

D

]

)

2

l

3

'

l

)

'

6

8
9

1

0
l

|

i- 1l , t' l :r '

r
l

I

ii-i+ir
Fillure 7.9, Specifications to ProcessCustomer Orders

7-10

.

i

I

i

1

J

I

1

'

I
tTnrnt
I iur.nJ-, I

1 i

t

t

5E.RIh]LNO'

l i
5
-++

l

-

l

t

_

l

I.IIE|'| ' ' CfrLr

r

l

l i
l l
TI-

i l . i 1

D,^.,itl

t #1-r1
l{

I

.

.

Fo'llowingoutput. the next cyclebeginswith a forced
STOCKrecord(recordtype 02) beingprocessed.The cost
i s a d d e dt o a T O T A L -f i e l d ( l i n e0 3 ) t o a c c u m u l a tteh e t o t a l
a m o u n td u eo n t h e o r d e r .
Tl'ren,COUNT is reducedby one for the recordbeingproca g a i nC O U N Ti s c o m p a r e dt o z e r o
e s s e d( l i n e0 4 ) . O n c , e
( l i n e0 6 ) t o d e t e r m i n ei f l i n e0 7 s h o u l db e p e r f o r m e dt;h a t
is,to determineif anotherSTOCKrecordis to be forced
for the next cycle. lihe COSTand TOTAL calculatedfor
th,eSTOCKrecordarethen printed,by performingthe outp u t s p e c i f i c a t i o no sn l i n e s1 2 - 1 5 .
Tlre recordselectedrlt the beginningof the next program
cycledependson wfrethera FORCEoperationwas indicated
i n t h e p r e v i o u cs y c l e . l f c a l c u l a t i o lni n e0 7 h a db e e np e r (by beformed,anotherSTOCKrecordwould be processed
i n , gf o r c e d ) . l f n o t , R P Gl l w o u l ds e l e ct h e n e x t O R D E R
r e c o r df r o m t h e p r i n r a r yf i l e .

Controlling ProcessingAfter ReachingEnd of File
I n a m u l t i f i l ep r o g r a me, n d o f f i l e e n t r i e sc a n b e s p e c i f i e d
f o r a n y ,a l l , o r n o n eo f t h e i n p u tf i l e s . l f a n e n d o f f i l e e n t r y
stopsafter all
is specified for only one file, processing
recordsfrom that file havebeenprocessed.(Remember,
to the files,the prohowever,if matchfieldsareassigned
gramcontinuesto processthe recordswhich matchthe last
or which haveno matchfields.) lf end of
recordprocessed
f i l e e n t r i e sa r es p e c i f i e fdo r a l l o r f o r n o n eo f t h e i n p u tf i l e s ,
p r o c e s s i ncgo n t i n u e ,uCn t i l a l l r e c o r d si n a l l f i l e sh a v eb e e n
processed.

F o r t h i s p r o g r a m ,s u p p o s eO R D E R a n d S T O C K a r e c a r d
f i l e s ,a n c lp r o c e s s i n gn l u s t c o n t i n u e u n t i l b o t h r e a c he n d o f
f i l e . F l o w e v e r ,i f o n e f i l e r t r n so u t b e f o r e t h e o t h e r , y o u
don't want to perform the usual calculations apd output for
t h e r e m a i n i n gf i l e . T h e r e m a i n i n gc a r d sm u s t b e p r o c e s s e d
i n a n o t h e rw a y ; t h a t i s , b y s e l e c t i n gt h e m t o a s p e c i a ls t a c k e r . l f a l l o r d e r s a r e f i l l e d , a n y r e m a i n i n gS T O C K c a r d s
s h o u l d b e s e l e c t e dt o s t a c k e r3 . l f t h e r e a r e n ' t e n o u g h i t e m s
i n s t o c k t o f i l l a l l o r d e r s .a n y r e m a i n i n gO R D E R c a r d s
should be selectedto stacker 2.
T o c o n t i n u e t h e p r o g r a mu n t i l b o t h f i l e s h a v eb e e nc o m p l e t e l y p r o c e s s e ds, p e c i f y e n d o f f i l e e n t r i e so n t h e F i l e D e s '
c r i p t i o n s h e e t ,e i t h e r f o r b o t h o f o r f o r n e i t h e r o f t h e t w o
i n p u t f i l e s ( F i g u r e7 - 1 0 ) . B y d o i n g t h i s ,t h e L R i n d i c a t o r
won't be set on to end the program until the last record of
t h e l a s t f i l e h a sb e e n P r o c e s s e d .
W i t h e n d o f f i l e s p e c i f i e df o r b o t h f i l e s , l e t ' s c o n s i d e rw h a t
w i l l h a p p e nw h e n o n l y o n e o f t h e f i l e s r e a c h e se n d o f f i l e
( s e eF i g u r e7 - 9 ) . F i r s t , s u p p o s et h e S T O C K f i l e r e a c h e se n d
o f f i l e b e f o r e a l l O R D E R c a r d sa r e p r o c e s s e d .S i n c e b o t h
f i l e s a r e n o t a t e n d o f f i l e , p r o c e s s i n gw i l l n o t s t o p ' I n s t e a d ,
a f t e r p r o c e s s i n gt h e n e x t O R D E R c a r d , t h e p r o g r a mw i l l t r y
t o f o r c e t h e a p p r o p r i a t en u m b e r o f r e c o r d sf r o m t h e S T O C K
f i l e . W i t h n o m o r e S T O C K c a r d st o f o r c e , a n o t h e r O R D E R
recorcw
l i l l b e s e l e c t e d .O n c e a g a i n ,t h e p r o g r a mw i l l t r y t o
force STOCK records for that order' The processcontinues
u n t i l a l l p r i m a r y f i l e O R D E R r e c o r d sh a v e b e e n p r o c e s s e d .
F u r t h e r m o r e ,e v e r y t i m e a n e w O R D E R r e c o r d i s p r o c e s s e d ,
i t i s p r i n t e d o n t h e r e p o r t a n d t h e c a r d g o e si n t o s t a c k e r 1 '
a s i f t h e o r d e r w e r e b e i n gf i l l e d .
A s i m i l a r p r o b l e m a r i s e si f t h e O R D E R f i l e r e a c h e se n d o f
f i l e f i r s t . S u p p o s et h e l a s t o r d e r h a s j u s t b e e n f i l l e d .

File Description Specif ication

O t h e r d e v i c e sc a n
b e u s e d ,d e p e n d i n g
on the system and
configuration

Figure 7-10. Continuing ProcessingUntil Both Files Reach End-of'File

P r o g r a m m e dC o n t r o l o J I n p u t a n d O u t p u t

7-11

After processing
the lastSTOCKcardfor that order,no
m o r eS T O C Kc a r d sa r et o b e f o r c e d .s o R p G l l l o g i c
tries
I
t o s e l e ctth e n e x t p r i m a r yf i l e O R D E Rr e c o r d . I n d o i n g
so,
t h e / * c a r df r o m t h e O R D E Rf i l e i s r e a d .S i n c et h e p r o g r a m
i s t o c o n t i n u eu n t i l b o t h f i l e sa r ep r o c e s s e R
d .p G l l l o g i c
automaticallyprocesses
the remainingrecordsin the other
file (STOCK). As eachremainingSTOCKrecord processed,
is
the calculations
and output for that recordtype are performedand the cardgoesinto stacker4, as if the
record
w e r eb e i n gu s e dt o f i l l a n o r d e r .
A l t h o u g hp r o c e s s i ni sgt o c o n t i n u eu n t i l b o t h f i t e s
reach
e n d o f f i l e , y o u m u s th a v ea w a y o f d e t e r m i n i nw
g h e nt h e
f i r s t f i l e r u n so u t a n dw h i c h f i l e i t i s . T h i s i s n e c e s s a r y
so
t h a t n o r m a lc a l c u l a t i o nasn d o u t p u tf o r t h e r e m a i n i n g
cards
can be bypassed
and stackerselectionspecificatrons
per_

f o r m e d i n s t e a d . R e a d i n ga l * c a r df r o m a f i l e w i l l n o t
necess a r i l y i n d i c a t et h a t e n d o f f i l e h a s b e e n r e a c h e di n a l l f i l e s .
The LR indicatoris turned on only when the /* cardof
the
l a s t f i l e h a s b e e n r e a d . T h e r e f o r e ,a t r a i l e r c a r d s h o u l d
be
p l a c e da t t h e e n d o f e a c h f i l e ( F i g u r e 7 - 11 b e f o r e
),
the /*
c a r d , t o i n d i c a t ew h e n a l l c a r d so f t h e f i l e h a v e b e e n p r o c e s s e d .W h e n a t r a i l e r c a r d i s r e a d ,t h e r e c o r d i d e n t i f y i n g
ind i c a t o r a s s o c i a t e dw i t h t h a t c a r d t u r n s o n t o i n d i c a t e
which
file has been completely processed. For this program.
tne
t r a i l e r c a r d i n t h e O R D E R f i l e w i l l t u r n o n i n d i c a t o r0 3 ,
while the trailercard in the STOCK file will turn on indicator 04.
L e t ' s l o o k a t t h e c o m p l e t e d c a l c u l a t i o na n d o u t p u t s p e c i f i c a t i o n sf o r t h i s p r o g r a m ( F i g u r e 7 - 1 2 } t o u n d e r s t a n dh o w
the trailer cards are used to control processing.

t/ . - -

l-'

g'

Trailer card
record type 03

ORDE R cards
record type 01

caro
type 04

STOCK cards
record type 02

.J'

ORDER fite
frigure 7-11. Use of Trailer Cards to Control
End-of-File processing

7'-12

STOCK fite

A s s u m et h e t r a i l e r c a r d f r o r r rt h e O R D E R f i l e ( r e c o r dt y p e
0 3 i ) i s r e a d , i n d i c a t i n ga l l O R D E R c a r d sh a v eb e e n p r o c e s s e d .
W h e n r e c o r c li d e n t i f y i n g i n d i c a t o r 0 3 i s s e t o n , y o u k n o w
that any remairringSTOCK cards are to be selectedto
s t a c k e r3 . H o w e v e r ,i n d i c a t o r 0 3 c a n n o t b e u s e dt o c o n d i '
t i c l n t h e s t a c k e rs e l e c t i o n . h s s o o n a s t h e t r a i l e r c a r d h a s
b e e n p r o c e s s e da n d t h e f i r s t o f t h e r e m a i n i n gS T O C K c a r d s
r e , a d i,n d i c a t o r 0 3 i s s e t o f f a n d r e c o r d i d e n t i f y i n g i n d i c a t o r
0 2 1( f o r t h e S T O C K c a r d ) i s s e t o n . T h e r e f o r e ,w h i l e t h e
t r a i l e r c a r d i s s t i l l b e i n g p r o t ; e s s e dy,o u m u s t s e t o n a n i n d i catorwhich will stay on until the lastSTOCK card hasbeen

c a l c u l a t i o n sw h e n 3 3 i s o n , m e r e l y b y b r a n c h i r r gt o t h e e n d
o f c a l c u l a t i o n s .N o r m a l o u t p u t f o r S T O C K r e c o r d si s t h e n
c o n d i t i o n e ds o i t i s n ' t p e r f o r m e d i f i n d i c a t o r 3 3 i s o n ( o u t p u t l i n e s 1 0 - 1 3 ) . O u t p u t l i n e 1 9 t h e n I n s t r u c t st h e p r o g r a m
t o s t a c k e rs e l e c tt h e S T O C K c a r d i f 3 3 i s o n .

s t i l c k e rs e l e c t e d .A s c a l c u l a t i o nl i n e 0 1 s h o w s ,r e c o r d i d e n t i f y i n g i n d i c a t o r 0 3 i s u s e dt o S E T O N i n d i c a t o r 3 3 . ( T h e
u s e o f N 3 4 o n l i n e 0 1 w i l l b e c o m ec l e a r a s t h e p r o g r a m i s

N o w , l e t ' s a s s u m et h e S T O C K f i l e r u n s o u t b e f o r e t h e
ORDER file. When the trailercardfrom the STOCK file
( r e c o r d t y p e 0 4 ) i s r e a d ,y o u k n o w t h a t t h e r e m a i n i n g
O R D E R c a r d sm u s t b e s e l e c t e dt o s t a c k e r2 . F o r t h e s a m e
r e a s o na s p r e v i o u s l ye x p l a i n e d ,t h e r e c o r d i d e n t i f y i n g i n d i cator of the trailer card cannot be used to condition the
s t a c k e rs e l e c t i o n . T h e r e f o r e ,r e c o r d i d e n t i f y i n g i n d i c a t o r
0 4 i s u s e dt o S E T O N i n d i c a t o r 3 4 ( F i g u r e7 - ' l2 , c a l c u l a t i o n

e>,rplained.)

l i n e0 4 ) .

Now when a STOCK card is selectedfor processing,the prog r a m m u s t d e t e r m i n ei f n o r n n a lc a l c u l a t i o n sa n d o u t p u t
s l ^ r o u lb
d e p e r f o r m e df o r t h e r e c o r d ( r e c o r dt y p e 0 2 ) . S i n c e
i n d i c a t o r 3 3 i s o n , n o r m a l c a l c u l a t i o n sa n d o u t p u t s h o u l d
be bypassedand the STOC!( record stacker selectedinstead.
T o d o t h i s , a l l o f t h e s p e c i f i c a t i o n fso r r e c o r d t y p e 0 2 c o u l d
b r - ' c o n d i t i o n e dt o b e p e r f o r m e do n l y i f i n d i c a t o r 3 3 i s o f f
( l r l 3 3 ) . H o w e v e r ,t o e l i m i n a t et h e e x t r a c o d i n g a n d i n d i c a t o r
t e s t i n g ,c a l c u l a t i o nl i n e 0 2 i n s t r u c t st h e p r o g r a mt o s k i p t h e

I n a d d i t i o n , w h i l e t h e t r a i l e r c a r d i s b e i n g p r o c e s s e dy, o u
m u s t d e t e r m i n ei f t h e l a s t o r d e r w a s c o m p l e t e l t 'f i l l e d l f
t h e r e h a d b e e ne n o u g h S T O C K r e c o r d st o f i l l t h e o r d e r , t h e
q u a n t i t y i n t h e C O U N T f i e l d w o u l d h a v eb e e n r e d u c e dt o
z e r o . T h e r e f o r e ,w h e n r e c o r d i d e n t i f y i n g i n d i c a t o r 0 4 i s o n ,
C O U N T f i e l d s h o u l d b e c h e c k e d( c a l c u l a t i o nl i n e 0 5 ) ' l f

RPG

CALCULATION SPECIFICATIONS

'*"fll"-

[;;
El'rav

c

C O U N T i s g r e a t e rt h a n z e r o , i n d i c a t o r 3 6 i s s e t o n . W r i t h3 6
w i l l b e p r i n t e d i n d i c a t i n gh o w m i a n yi t e m s o f
on, a message
c
t h e l a s to r d e r o u l d n o t b e f i l l e d ( o u t p u t l i n e s l 4 - 1 7 ) '

la

p,oqran
lr d p n , n d r o

7e ,-1 78 a9 80

r

llll

L l _ L i l

:] ()
6

8

T

T I
l .i

9Li

.:

I

0 6
I

H]

I
T

I

i1

tl

II
fi

il

I
_l

il

i
L

F i g u r e T - 1 2 ( P a r t 1 o f 2 1 . C o n t r o l l i n g O p e r a t i o n sa t E n d - o f " F i l e

P r o g r a m m e dC o n t r o l o f I n p u t a n d O u t p u t

7-13

A t t h i s p o i n t ,t h e f i r s t o f t h e r e m a i n i n O
g R D E Rc a r d si s
r e a d . S i n c ei n d i c a t o 3
r 4 i s s t i l lo n , a l l c a l c u l a t i o nf so r t h e
O R D E Rc a r da r eb y p a s s e(ds e ec a l c u l a t i o lni n e0 6 ) . T h e
n o r m a lo u t p u tf o r t h e O R D E Rr e c o r di s t o b e p e r f o r m e d
o n l y i f i n d i c a t o 3r 4 i s o f f . T h u s ,t h e p r i n t e ro u t p u tf o r
reco r d t y p e 0 1 ( o u t p u tl i n e s0 6 - 0 g )i s s k i p p e da n d t h e r e c o r d
i s s e l e c t e idn t o s t a c k e2r i n s t e a d( o u t p u tl i n e2 0 ) .
,Asyou haveseen,the trailercardsfrom eachfile
are used
t o s e to n p a r t i c u l airn d i c a t o r sW
. h e nt h e O R D E Rf i l e
t r a i l e rc a r d( r e c o r dt y p e 0 3 ) i s r e a d ,i n d i c a t o 3
r 3 i s s e to n .
L i k e w i s ei n
. d i c a t o3
r 4 i s s e to n w h e nt h e S T O C Kf i l e t r a i l e r
r:ard(recordtype 04) is read. The indicatorwhich
is seton
133 or 34) is usedto preventcertainoperationsfrom being
performed
a n dt o c a u s er e m a i n i n rge c o r d si n t h e o t h e rf i l e
to be stackerselected.
(Jf course,readinga trailercard
doesnot meantnereare
a l w a y sc a r d sr e m a i n i n ign t h e o t h e rf i l e . F o r i n s r a n c e ,
ass u m ea l l O R D E Rc a r d sh a v eb e e np r o c e s s e bd u. t n o t
all
{ ] T O C Kc a r d s .W h e nt h e O R D E Rf i l e t r a i l e rc a r di s r e a d .
it

OUTPUT
G,aph,c

I

FieureT-12 (Part 2 of 21. Controlling Operations
at End_of-File

7:14

s i g n a ltsh a t t h e r e m a i n i n S
g T O C Kc a r d ss h o u l db e s t a c k e r
selected.As the STOCKcardsarestackerselected,
one-byo n e ,e v e n t u a l ly o u r e a c ht h e e n d o f S T O C Kb y r e a d i n g
t h e t r a i l e rc a r df r o m t h e S T O C Kf i l e . A t t h i s p o i n t ,b o t h
f i l e sh a v er e a c h e e
d n d o f f i l e .t h e L R i n d i c a t o irs a u t o m a t i c a l l ys e to n , a n d t h e p r o g r a mi s e n d e d .
W h e nt h e O R D E Rf i l e t r a i l e rc a r di s r e a d( 0 3 s e to n ) , t h e n
y o u w a n t t o k n o w i f t h e S T O C Kf i l e h a sb e e nc o m p l e t e l y
processed.lf it has.the STOCKf ile trailercard (record
t y p e 0 4 ) h a sa l r e a d yb e e nr e a d ,a n dt h e i n d i c a t o sr e to n b y
0 4 ( i n d i c a t o3r 4 ) w o u l ds t i l lb e o n . W i t h 3 4 o n , t h e r e , sn o
point in havingrecordtype 03 seton indicator33. Likew i s e .i f i n d i c a t o 3
r 3 i s o n ( O R D E Ra t e n d o f f i l e ) w h e nt h e
STOCKfile trailercard (recordtype 04) is read,there,sno
point in havingrecordtype 04 seton indicator34. For
this
r e a s o nt ,h e c a l c u l a t i o nosn l i n e s0 1 a n d 0 4 o I F i g u r e7 - 1 2
havebeenconditionedby N34 and N33. respectively.
As you know, the settingof an assigned
indicatorcande_
t e r m i n ew h e t h e ra F O R C Ei s t o b e p e r f o r m e do r n o t i n t h e

SPECIFICATIONS
Caid

Electio

Numbr

GX2t 9@O U/M 050.

1

2

? 5 7 6 7 7 7 8 ? 9 8 0

"*l I l"_ il::til",""fTTTTT-l

f o l l o w i n g p r o g r a mc y c l e . E i t h e r a r e c o r d t y p e , d a t a o n a
r e c o r d ,o r t h e r e s u l to f c a l c u l a t i o n sp e r f o r m e d d u r i n g p r o c e s s i n go f a r e c o r d c a n s e t t h e p a r t i c u l a rc o n d i t i o n i n g i n d i cator on or off.

s i b l e ,v o u s h o u l d o r g a n i z ey o u r f i l e s i n s u c h a w a y t h a t t h e
n o r m a l R P G l l l o g i c c a n d e t e r m i n et h e a p p r o p r i a t eo r d e r o f
f i l e p r o c e s s i n g .I n t h r s w a y , y o u d o n o t h a v et o c o d e a d d i '
t i o n a l s p e c i f i c a t i o n st o c o n t r o l t h e o r d e r . O f c o u r s e ,f r o m
t i m e t o t i m e y o u m a y h a v ei o b s i n w h i c h y o u m u s t u s e

I n t h e e x a m p l e sp r e s e n t e dt h u s f a r , s o m e t h i n ga b o u t a r e c o n d w h i c h w a s c u r r e n t l y b e i n g p r o c e s s e d e t e r m i n e dw h e t h e r
t h e c o n d i t i o n i n g i n d i c a t o r w a s s e t o n a n d u r h e t h e ra n u n processedrecord was forced. In the last example, the OTY
f i e l d o n t h e O R D E R c a r d d e t e r m i n e dh o w m a n y S T O C K
recordswere to be forced.

F O R C Ea n d l o o k - a h e a d .

Doing Matching Records Without Match Fields
l f t w o f i l e s a r e o r g a n i z e ds u c h t h a t t h e s a m em a t c h f i e l d s
c a n n o t b e a s s i g n e dt o t h e t w o f i l e s , y o u c a n s t i l l p r o c e s st h e
m a t c h i n g r e c o r d st o g e t h e r b y u s i n g l o o k - a h e a df i e l d s a n d
t h e F O R C E o p e r a t i o n . ( T h i s c a n n o t b e d o n e , h o w e v e r ,i f
t h e l o o k - a h e a df i l e i s d e f i n e d a s a c o m b i n e d o r u p d a t e f i l e ' )
L o o k - a h e a dc a n b e u s e dt o d e t e r m i n ei f c e r t a i n f i e l d s ( n o t

L,ook-Aheadto Determine Whether a File is to be Forced
F o r s o m e p r o g r a m s ,y o u c a n n o t d e t e r m i n ew h e t h e r a r e c o r d
i : ;t o b e f o r c e d i n t h e n e x t c y c l e u n t i l y o u k n o w s o m e t h i n g
about the recordswhich have not been processedyet. Thus,
y o u m u s t l o o k a h e a di n o n e o r b o t h f i l e s a t t h e n e x t r e c o r d
v r h i c h i s n o t y e t a v a i l a b l ef o r p r o c e s s i r r g I. n l o o k i n g a h e a d ,
y ' o u m a y b e c h e c k i n gt o d e t e r m i n ew h a t r e c o r d t y p e i s n e x t ,
t o s e ew h a t d a t a i s o n t h e n e x t r e c o r d ,o r t o d e t e r m i n ei f
the next record has the same match field as the record be-

recordmatch
a s s i g n e da s m a t c h f i e l d s ) o n a n u n p r o c e s s e d
t h o s e o n t h e r e c o r d b e i n g p r o c e s s e d 'l f t h e y m a t c h , F O R C E
is performed to causethe matching unprocessedrecord to
b e s e l e c t e dn e x t .
A s a n e x a m p l e ,a s s u m ea r e p o r t i s t o b e p r e p a r e ds h o w i n g
t h e a m o u n t o f e a c h s a l e s m a n ' s a l e sa n d h i s q u o t a ' T h e r e p o r t s h o u l d a l s o c o m p a r et h e t o t a l o f d i s t r i c t s a l e sw i t h t h e
districtquota.

i r n gp r o c e s s e d .W h a t y o u f i n d i n l o o k i n g a h e a dc a n d e t e r r n i n ew h i c h f i l e i s t o b e p r o c e s s e dn e x t a n d , a l s o ,w h e t h e r
the file must be forced or not.

T h e t w o f i l e s a v a i l a b l ef o r t h i s p r o g r a ma r e d e s c r i b e di n
F i g u r e7 - 1 3 . T h e p r i m a r y f i l e ( M A S T E R ) c o n t a i n sa d i s t r i c t
s ASTER
r e c o r d ( r e c o r dt y p e 0 1 ) , f o l l o w e d b y a l l s a l e s m e n ' M

t l e f o r e c o n s i d e r i n gt h e u s eo f F O R C E w i t h l c l o k - a h e a dh, o w e v e r ,y o u s h o u l d e v a l u a t ey o u r s y s t e md e s i g n . l f a t a l l p o s -

RPG

INPUTSPECIFICATIONS

IBIt

R.cord

ldentlf icalion C(r(les

-T---;-

ffi:

i
I

I

,

'il4.lr 1414 '

l:l
l : I F e r (Nr a m e

dr

Fl4i,

lf,liliilli
lll
l

t

l

fli
ili

*"i
1

3i
6l

l ll ll :. I r E

iiii"l

Figure 7-13. Describing Files to be Matched Without Match Fields

P r o g r a m m e dC o n t r o l o f l n p u t a n d O u t p u t

7-15

r e c o r d s( t y p e 0 2 ) a s s o c i a t e d
w i t h t h e d i s t r i c t . T h e s ea r e i n
turn followed by the next district record (01)
and rts reiated
r ; a l e s m e inv ] A S T E Rr e c o r d s( 0 2 ) a n d s o o n .
Although the
f e c o r o sa r e g r o u p e db y d t s t r i c t ,a l l s a l e s m a nM A S T E R
rec_
o r d s i n t h e f i l e a r e s t i l l i r r a s c e n o t n gs e q u e n c el : V
salesman
-[he
number.
s e c o n C a r yf i l e ( S A t - E S )c o n t a i r i so n l y o n e r e c ord type (03), 3 p6sor.6
f o r .e a c h i n d i v i d u a ls a l e . T h e S A I _ F S
l i l e i s a l s oi n a s c e n d i n sge q u e n c e
by salesmanumber. While
t h e M l \ S T E R f i l e c o n t a i n sa r e c o r d f o r e v e r y
s a l e s m a n( a s s u m e t h e r e a r e n c [ \ l A S T E i i r e c o r d sr r . r i s s i n gt)h, e
SALES
f i l e m a y c o r r t a l no n l y o n e , s e v e r a l o, r e v e n n o r e c o r d s
for a
6 r a r t i c u l asra l e s m a n .

RPG ll selects
record from
primary f ile

ls
i t a s a l e sm a n
m a s t e rr e c o r d ?

1 ' o p r o d u c e t h e r e p o r t , t h e r e c o r d ss h o u l d b e p r o c e s s e d
in
t h e f o i l o w i n go r d e r ;
I"

D i s t r i c t r e c o r c i( r e c o r dt y p e t l 1 ) .

2.

S a l e s m a nM A S T E R r e c o r d ( r e c o r d t y p e 0 2 ) .

J

A l l S A L E S r e c o r d sf o r t h a t s a l e s m a r{rr e c o r dt y p e
03).

Look-Ahead
ls man number on

S A L E S r e c o r d s a m ea s
that on salesman

N e x t s a l e s m a nM A S T E R r e c o r d .
6

(lt isa district
r e c o r d s o s e le c
next primary
fi I e record)

( s e t e c tn e x t
primary fiie
record)

S A L E S r e c o r d sf o r t h a t s a i e s m a n .
N e x t d i s t r i c t r e c o r c l( a f t e r a l l s a l e s m a nM A S T E R r e c ordsassociated
w i t h t h e f i r s t d i s t r i c t h a v e br e e n p r o c _
e s s e d) .

T h e r e i s n o c o m m o n f i e l d o n a l l t h r e e r e c o r dt y , p e s
which
c a n b e a s s i g n e da s a m a t c h f i e l d t o c a u s et h e r e c o r d s
to be
p r o c e s s e ri Jn t h i s o r d e r T o t a l s a r e t o b e
a c c u m u l a t e db y
s a l e s m a n u m b e r ;b u t t h e M A N N U M f i e l d i s c o n t a r n e d
onlV
o n t h e s a l e : i m a nM A S T E R a n d S A L E S r e c o r d s . T h e
district
r e c o r d sd o r r o t c o n t a i nt h i s i n f o r r n a t i o n .

F O R C Er h e
SALESrecord
to be processed

l s m a n n u m b e ro n n e x l
S A L E S r e c o r d s a m ea s t h a t
S A L E S r e c o r db e i n g

( s e l e c tn e x t
p r i m a r yf i l e
record)

l f t h e M A I ' I N U M f i e l d sa r e a s s r g n e a
d s M 1 n r a t c ht i e l d s f o r
o r r l y t w o o f t h e r e c o r d t y p e s , t h e r e c o r d sw i l l b e p r o c e s s e d
I n a n I n c o r n l c to r d e r . F o i l o w i n gt h e l a s ts a l e s m a n
MASTER
r e r : o r d( 0 2 r e c o r d t y p e ) f o r a p a r t i c u l a rd i s t r i c t , t h e n e x t
r e r : o r di n t h e s a m ef i l e i s a n o t h e r c l i s t r i c tc a r d . S i n c e
dist n c t r e c o r C sh a v en o l M1 r n a t c hf i e l d e n t r y a s s i g n e d( n o
M / \ N N U M f i e l d ) , t h e d i s t r i c t r e c o r d i s p r o c e s s e ci nt r m e d i a t t : l y b e f o r e t h e S A L E S r e c o r d sf o r t h e l a s t s a l e s m a n .
A l t h o u g h t h i s p r o g r a n rc a n n o t b e d o n e u s i n gm a t c h
fields,
y o u c a n m a t c h t h e r e c o r d sy o u r s e l f b y u s i n g
the look_ahead
c a l r a b i l i t yt o c o m p a r e f i e l d s ( F i g u r el _ 1 4 }. T h e o b j e c t
is to
m e t c h a s a l e s m a n 'S
s A L E S r e c o r dw i t h t h i s s a l e s r n a n
M l \ S - f E R r e c o r c J .T h u s , t h e M A N N U M f i e l d o n
a SALES
r e c o r d i s d e f i n e d a s a l o o k - a h e a df i e l d . W h i l e p r o c e s s r n g
a
s a l i r 5 l - 1 1M3AnS T E R r e c o r d ,y o u t h e n l o o k a h e a d ( i n
calcul a t r o n s )e r tt h e u n p r o c c s s e dS A L E S r e c o r d t t l d e t e i . m i r r e
if

FigureT-14.UsingLook Aheadto Determineif RecordsMatch

t h e s a l e s m a nn u m b e r i s t h e s a m ea s o n t h e r e c o r d b e i n g p r o c .
e s s e d . l f t h e y m a t c h , t h e F O R C E o p e r a t i o n c o d e i s u s e dt o
p r o c e s st h e S A L E S r e c o r d a s i f R p G l l l o g i c w e r e p e r f o r m i n g a m a t c h i n gr e c o r d sj o b . y o u t h e n c o n t i n u e t o f o r c e t h e
r e s t o f t h e S A L E S r e c o r d sw h i c h c o n t a i n t h e s a m es a l e s m a n
number. For each record, look-aheadis used to check the
M A N N U M f i e l d t o d e t e r m i n ei f t h e S A L E S r e c o r d s h o u l d
b e f o r c e d . W h e n l o o k - a h e a di n d i c a t e st h a t t h e n e x t S A L E S
r e c o r d i s f o r a d i f f e r e n t s a l e s m a nn u m b e r , t h e S A L E S r e c o r d i s n o t f o r c e d . I n s t e a d ,R p G l l t a k e s o v e r t o s e l e c tt h e
n e x t p r i m a r y f i l e r e c o r d w h i c h r s e i t h e r a r r o t h e rs a l e s m a n
M A S T E R r e c o r do r t h e n e x t d i s t r i c t r e c o r d .

/- | o

Nlow that you understand the steps involved in this program,
l o o k a t t h e s p e c i f i c a t i o n si n F i g u r e7 - 1 5 . T h e I n p u t s h e e t
describesthe records in each file and defines the look-ahead
f i e l d f o r t h e S A L E S r e c o r d s ' O n l y t h e c a l c u l a t i o n sn e c e s sarv to determine which record is to be processednext are

file
s h o w n . T o a c t u a l l y p r e p a r et h e r e p o r t , y o u w o u l d n e e d
a
d
d
i
t
i
o
n
al
f
i
l
e
s
a
n
d
t
h
e
d e s c r i p t i o ns p e c i f i c a t i o n st o d e f i n e
t
o
t
a
l
s
t
o
a
c
c
u
m
u
l
a
t
e
c a l c u l a t i o na n d o u t p u t s p e c i if c a t i o n s
and print the data.

RPG INPUTSPECTFICATIONS

;.tu;N*l
Record

ldentif icarion Codes

lri
i t T

L ,
i i

I
I
Iti

RPG

CALCULATION SPECIFICATIONS
75 16 71 1A 19 AO

"*fI]"-

Proerad fT-fTTTl
rdennt.ar..I

I

I_L_l--Ll

ResultField

Factor 2

l f s a l e s m a nn u m b e r s a r e t h e s a m e ( 2 3 o n ) '
f o r c e t h e n e x t S A L . E Sr e c o r d '

l f s a l e s m a nm a s t e rr e c o r d ( 0 2 ) o r S A L E S
record (03) being processed,check salesman
number on the next SALES record

Figure 7-15. Using Look Ahead to Match Records

Output
P r o g r a m m e dC o n t r o l o f I n p u t a n d

7-17

l,rocessing a Primary. Then Matching
Secondary Records
tlefore Matching primary Records
l \ n o t h e r r e a s o nf o r l o o k i n g a h e a dt o
d e t e r m i n ew h i c h r e c _
o r o t o p r o c e s sn e x t i s w h e n y o u w a n t
t o p r o c e s st h e f i l e s i n
a n o r d e r o t h e r t h a n t h e u s u a lo r d e r o f
m a t c h i n gr e c o r o
l o g i c . I n s u c h c a s e sa, l l f i l e s m u s t h a v e
match f ields. The
n r a t c h f i e l d so n t h e n e x t r e c o r d s
a v a i l a b l ef o r p r o c e s s r n g
a r e l o o k e d a t t o d e t e r m i n ew h i c h r e c o r d
will ordinarilybe
s e l e c t e da n d , t h u s , i f i t i s n e c e s s a r y f o r c e
to
a recordinstead.
T o i l l u s t r a t ea l t e r i n gt h e o r d e r o f m a t c h i n g
recordlogic,
l e t ' s c o n s i d e ra s a m p l eb i l l i n g p r o g r a m
in which the records
a r e t o b e p r o c e s s e di n a p a r t i c u l a ro r d e r .
H o w e v e r ,n o t e t h a t
t h e e x a m p l e i s p r e s e n t e do n l y t o s h o w y o u
why and how
l o o k - a h e a df i e l d sa r e u s e dt o d e t e r m i n e
whethera parttcutar
f i l e s h o u l d b e p r o c e s s e d .A c t u a i l y ,
t h e d e s i r e dr e s u r t sc o u r d
a l : ; ob e o b t a i n e d b y p r o c e s s i n gt h e r e c o r d s
in a different

c 735
N

4C

o r d e r u s i n gt h e n o r m a l R p G l l l o g i c . W e a r e
not necessarily
s u g g e s t i n tgh a t y o u r f i l e s b e o r g a n i z e di n
t h e s a m ew a y f o r
y o u r b i l l i n g p u r p o s e s .l n f a c t , i t i s p o s s i b r e
t h a t t h e f i r e sf o r
t h e s a m p l ep r o g r a m c o u l d b e o r g a n i z e di n a
different way
s u c h t h a t l o o k - a h e a dw i t h F O B C E w o u l d n o t
be necessarv
t o p r o c e s st h e r e c o r d si n t h e d e s i r e do r d e r .

Organizationof the Files: The two files for
the billing ap_
p l i c a t i o n( F i g u r e7 - 1 6 ) c a n e a c hc o n t a i n
t w o r e c o r dt y p e s .
T h e p r i m a r y f i l e ( F I R S T ) c o n t a i n sa n a m e
a n d a d d r e s sr e c o r d f o r e v e r y c u s t o m e r ( r e c o r dt y p e 0 1 ) f o l l o w e d
by the
c u s t o m e r ' sc h a r g er e c o r d ( r e c o r dt y p e 0 2 ) i f
any purchases
w e r e m a d ed u r i n g t h e m o n t h . T h e s e c o n d a r y
f ile (SECOND)
c o n t a i n so n e r e c o r d f o r e v e r y c u s t o m e rs h o w i n g
his previous
b a l a n c e( r e c o r d t y p e 0 3 ) . l f t h e c u s t o m e r i s
entitled to a
d i s c o u n t ,a r e c o r d c o n t a i n i n gh i s d i s c o u n t r a t e
follows the
b a l a n c ec a r d . A s y o u c a n s e e ,b o t h f i l e s a r e i n
a s c e n d i n gs e _
q u e n c ea c c o r d i n gt o a c o m m o n m a t c h f
i e l d c o n t a i n i n qt h e
c u s t o m e rn u m b e r .

01

735 GEST BRUCE 4856
N I N T H S T R E E TM P L S M N

631

5E

02

396

c 631
c 631

3D

01

450

6 3 1 D E A NT H O M A S9 8 6 O A K
G L E ND R I V E S T P A U L M N
N 5 6 3 C A R L S O NV 4 6 F I R S T
AVENUE HOPKINS MN
C 4O2

c

402

48

3A

03

02

N 4 0 2 A K R E J 3 1 1H A W K
I N S D R I V EB R A I N E R M
ON

2g7

B 563
Record Type 02
( C h a r g eR e c o r d )
Record Type Ol
(Nameand Address)

F T R S Tf i t e
F i g u r e 7 - 1 6 . F i t e sW i t h M o r e r h a n O n e M a t c h i n g
Record
7-18

754

RecordType 04
( D i s c o u n tR e c o r d )

B 402

2986

S E C O N Df i t e

Record Type 03
( P r e v i o u sB a l a n c e )

P a s eo f G C 2 1 - 7 5 6 7 - 2
l s s u e d2 1 D e c e m b e r 1 9 7 9
By TNL: cN21-5709

'fhe

s p e c i fi c a t i o n si n F i g u r e 7 - 1 7 d e f i n e t h e f i l e s f o r t h i s a p .
p l i c a t i o n . A s e n t r i e si n c o l u m n 1 8 o f t h e I n p u t s h e e ts h o w ,
record type 02 (charge records) in the primary file ancl reco r d t y p e 0 4 ( d i s c o u n tr e c o r d ) i n t h e s e c o n d a r yf i l e m a y o r
m a y n o t b e p r e s e n tf o r a p a r t i c u l a rc u s t o m e r . T h e u s e o f
t h e l o o k - a h e a df i e l d s d e f i n e d o n l i n e s i 1 - 1 2 a n d 1 g - 2 0 w i l l
b e c o m ec l e a ra s w e e x p l a i n t h e p r o g r a m .
File Description Specif ication

LFgb
ot

BMrd

ot

Key

Field

Addrer

Extenl Exh
{fr DAM

d
F€td

td Cyli*r

&dlow

Other devices can
b e u s e d ,d e p e n d i n g
o n t h e s y s t e ma n d
R P G I N P U T S P E C I F I C A T I O N Sc o n f i g u r a t i o n

,'."|.i].,-",ir;il",,."1

lfigur"T-17.

ForceWithLookAhea o
t1

6i

Review 7

7-33

l\nswers To Review 7

1.

a . M a t c h f i e l d s c a n n o t b e a s s i g n e dt o t h e f i l e s a n d y o u n e e d t o :

Alternateprocessing
betweentwo files.
P r o c e sas p r i m a r yf i l e r e c o r df o l l o w e db y a n u m b e ro f s e c o n d a rfyi l e r e c o r d s .
o P r o c e s sa s e c o n d a r yf i l e r e c o r d o n l y w h e n i t m a t c h e sa p r i m a r y f i l e r e c o r d .
b . M a t c h f i e l d s a r e a s s i g n e dt o b o t h f i l e s a n d y o u n e e d t o a l t e r t h e o r d e r o f m a t c h i n g r e c o r d l o g i c t o p r o c e s sa p r i m a r y f i l e r e c o r d .t h e n m a t c h i n gs e c o n d a r yf i l e
r e c o r d sb e f o r e m a t c h i n g p r i m a r y f i l e r e c o r d s .
a . W h e n e a c h f i l e m u s t b e p r o c e s s e da n d u n d e r w h i c h c o n d i t i o n s .
b . W h e t h e r R P G l l l o g i c w o u l d s e l e c tt h e a p p r o p r i a t er e c o r d o r i f t h e f i l e m u s t b e
forced.

3.

N o a c t i o n o c c u r sa t t h e t i m e t h e s p e c i f i c a t i o ni s p e r f o r m e d . A t t h e b e g i n n i n go f t h e
next program cycle, the next record from the file specified as Factor 2 of the
F O R C E o p e r a t i o n i s s e l e c t e d( b y b e i n g f o r c e d ) f o r p r o c e s s i n g .

4.

a . N o , t h e s p e c i f i c a t i o n sa r e i n c o r r e c t .
b . A M A S T E R r e c o r d w i l l b e p r o c e s s e di n e v e r y p r o g r a mc y c l e u n t i l e n d o f f i l e i s
reached.
c . A C O M M I S r e c o r d w i l l n o t b e p r o c e s s e du n t i l a l l r e c o r d si n t h e M A S T E R f i l e
have been processed.
d . L i n e s0 5 a n d 0 6 s h o u l d n o t b e c o n d i t i o n e d b y r e c o r d i d e n t i f y i n g i n d i c a t o r 0 7 .
The COMP operation should be performed for every record type to determine if
t h e F O R C E i s t o b e p e r f o r m e d . l t m a y b e n e c e s s a r tyo f o r c e a C O M M I S r e c o r d
f o l l o w i n g e i t h e r a M A S T E R r e c o r do r a n o t h e r C O M M I S r e c o r d . F o r t h i s r e a s o n ,
y o u m u s t b e a b l e t o p e r f o r m t h e F O R C E o p e r a t i o nw h i l e p r o c e s s i n ge i t h e r o f
the record types.
e . T h e F O R C E o p e r a t i o n i s n o t n e c e s s a r y .T h e R P G l l l o g i c o f m a t c h i n g r e c o r d s
c a n d e t e r m i n et h e p r o p e r o r d e r o f p r o c e s s i n gi f t h e S L S N B R f i e l d s o n e a c h
r e c o r d t y p e a r e a s s i g n e da s m a t c h f i e l d s o n t h e l n p u t s h e e t .

5.

I n p u ts p e c i f i c a t i o nt os d e f i n el o o k - a h e afdi e l d :

G x 2 1$ 9 4 U / M0 5 0 '
'n u s.a
P,,^rPd

RPG INPUTSPECIFICATIONS
IBll

.,",^,,.",

a u , ^ € s M a c hn ec o , o o , a ,o n

_

t5 76 11 78 /9 80
P,@,am
F-f-TT-tr-l-ldenr'ric.tionl
I
I
|
|
|
|

Field
I ndicalors

I

+
i

l

-tl

Calculationspecifications
to determineorder of file processing:

RPG

Forh Gx?1.S3

CALCULATION SPECIFICATIONS

P.inr.d i. U.S.A

7 5 7 6 7 7 7 8 7 9 W

f-T_l
'"*L_L,lo'_

P'@,!m r--T--r-r--T-l
u.."r*,,-l
| | I |

Answers To Review 7

|

I

7-35

lf matchfield entrieshad beenassigned
to the SLSNBRfieldson the Input sheet,
input specificationlines10 and 11 would not be necessary
to definethe took-ahead
f i e l d ' N o c a l c u l a t i osnp e c i f i c a t i o n
wso u l d b e r e q u i r e dt o d e t e r m i n et h e o r d e ro f
processing.
6.

a . A demandfile is processed
only by the READ operationcodeduringcalculations.

D e m a n df i l e r e c o r d sa r en e v e rs e l e c t e bd y n o r m a lR p G l l m u l t i f i l el o g i c .

o . Matchfieldscannotbe assigned
to a demandfile.
c . Look-ahead
fieldscannotbe definedfor a demandf ile.
d . Readina
g n e n do f f i l e r e c o r d( / * ) f r o m a d e m a n df i l e d o e sn o t

s e tt h e L R
i n d i c a t o or n . I n s t e a da, n e n do f f i l e i n d i c a t o cr a nb e e n t e r e di n c o l u m n s
5g-59
o f t h e R E A D s p e c i f i c a t i ol n
i n e . T h i s i n d i c a t ow
r i l l t u r n o n e a c ht i m e a R E A D
i se x e c u t e d
w h i c he n c o u n t e rasn e n d o f f i l e c o n d i t i o ni n t h e d e m a n df i l e .

7.

lmmediateoutput for specifiedrecordsoccurs. Theserecordsarecoded
asexcept i o n r e c o r d sb y a n F i n c o l u m n1 5 o f t h e O u t p u t . F o r m asth e e t .

8.

SeeSpecification
sheets.

RPG

CALCULATION SPECIFICATIONS

*' [-J-l.,
_

1 7 7 8 7 9 W

r r q r . m I l I I l | |
rd.n'nc.r'onl | | I I I I

SPECIFICATIONS

Z "

Constant or Edit Word

7-36

Ze.o

Chapter8. Tables

C H A P T E R8 D E S C R I B E S :
Usesfor tables.
R P Gl l c o d i n gu s e dt o s e a r c ht a b l e s .
D e s i g n i ntga b l ei n p u tr e c o r d s .
L O K U Po p e r a t i o nc o d e .
U s eo f t a b l ed a t ai n c a l c u l a t i o nasn d o u t p u t o p e r a t i o n s .

B E F O R ER E A D I N GT H I SC H A P T E RY O U S H O U L DB E A B L E T O D E S C R I B E :
R P Gl l o b j e c tc y c l e .
Matchingrecordsprocessing.
Useof indicatorsto conditionoperations.

A F T E R R E A D I N GT H I SC H A P T E RY O U S H O U L DB E A B L E T O :
Stateusesfor tables.
D e f i n ea t a b l eo n t h e E x t e n s i o n
sheet.
C o d ep r o b l e m su s i n ga s i n g l et a b l e .
Codeproblemsusingrelatedtables.
D e fi n ea n d c o d et h e L O K U Po p e r a t i o nc o d ew i t h t a b l e s .
Describedataand storeit in a table.
Note: You can usethe reviewquestionscontainedin Review8 at the end of this
chapterto test your comprehension
of the chapter.Answersfollow the review
questions.

Tables

8-1

IINTRODUCTION

Search Word

l l f y o u w i s h t o m a k e a t e l e p h o n ec a l l t o a p e r s o n ,y o u m u s t
l i i r s td e t e r m i n eh i s t e l e p h o n en u m b e r . l m a g i n et r y i n g t o o b t a i n t h e n u m b e r i f n o t e l e p h o n ed i r e c t o r i e sw e r e a v a i l a b l e !
F o r s u c h r e a s o n ss, i m i l a r i t e m s o f i n f o r m a t i o n a r e g r o u p e d
a n d o r g a n i z e ds o t h e y c a n b e r e f e r e n c e de a s i l ya n d q u i c k l y .

NUMBER Table

A table is a collection of related data organized in such a
way that each item of information can be referencedby its
p o s i t i o n w i t h i n t h e t a b l e . A t e l e p h o n ed i r e c t o r Vc o n s i s t co f
t w o t a b l e so f i n f o r m a t i o n : a n a n ^ el i s t a r r a n g e da l p h a b e t i c a l l y a n d a n u m b e r l i s t a r r a n g e di n n o a p p a r e n to r d e r . E a c h
L e l e p h o n en u m b e r , h o w e v e r ,o c c u p i e sa p o s i t i o n i n t h e n u m b e r l i s t c o r r e s p o n d i n gt o t h e p o s i t i o n o f a p a r t i c u l a rn a m e i n
lhe name list.
liach item within a table is called a table element. Thus.
e r a c hn a m e w o u l d b e a n e l e m e n to f t h e n a m e t a b l e , w h i l e
e r a c hn u m b e r w o u l d b e a n e l e m e n to f t h e t e l e p h o n en u m D e r
table.

ABRAMS JOHN

286-6424

ACKERMAN GAIL

289-2933

ADAMS KEN'.

938-7515

ANDERSON THOMASE .

93s-8381

BABITT ROBERTA

2aa-7547

B A R S N E S SR I C H A R D .

938-3932

I

l f y o u w i s h e dt o d e t e r m i n e K e n A d a m s ' t e l e p h o n en u m b e r ,
you would look through the list of names to locate K6y'U
tlDAMS. This procedure of checking the elements of a
table one at a time to f ind a particular entrv is calledsearchi,nga table. Before looking through the name list, you must
know what information you wish to f ind. the name KEIV
llDAMS.

)

I

ct
I

)v
WIK GAIL

(

v

288-4663

This data is referred to as the search word.

l \ s s h o w n i n F i g u r e8 - 1 , t h e n a m e l i s t i s s e a r c h e dt o f i n d
a n e n t r y w h i c h i s e q u a l t o t h e s e a r c hw o r d . T h e m a t c h i n g
entry, KEN ADAMS, is found in the third element of the
r r a m et a b l e . H i s c o r r e s p o n d i n gt e l e p h o n en u m b e r , t h e n , i s
f o u n d b y s e l e c t i n gt h e t h i r d e l e m e n t i n t h e n u m b e r t a b l e .
W h e n t w o r e l a t e dt a b l e sa r e u s e d ,a s i n a t e l e p h o n ed i r e c t o r y , a c t u a l l y o n l y o n e t a b l e i s s e a r c h e d( n a m e t a b l e ) . W h e n
t h e s e a r c hc o n d i t i o n ( i n t h i s c a s e .a n e q u a l m a t c h ) h a s b e e n
s a t i s ife d , t h e d a t a i n t h e c o r r e s p o n d i n ge l e m e n to f t h e s e c o , n dt a b l e b e c o m e sa v a i l a b l e .T h u s , t h e f i r s t t a b l e i s u s e da s
a meansof locating data in the second table.
A t e l e p h o n ed i r e c t o r y i s a n e x a m p l eo f t a b l e sw h i c h o r g a n i:zeinformation that we must referenceover and over again
i n o u r e v e r y d a y l i v e s . L i k e w i s e ,t a b l e sc a n b e u s e dt o o r g a n i z ed a t a w h i c h m u s t b e r e f e r e n c e dr e p e a t e d l Vi n v o u r
data processingjobs.

Figure8-1. Searching
a Table

L e t ' s a s s u m et h a t c u s t o m e r sh a v e p u r c h a s e dv a r i o u si t e m s
f r o m a c o m p a n y s a l e sc a t a l o g . T h e s a l e sf i l e ( F i g u r e8 - 2 )
w o u l d c o n t a i n r e c o r d ss h o w i n gt h e c u s t o m e r ' sa c c o u n t n u m b e r ( C U S T M R ) ,t h e i t e m o r d e r e d( I T M O R D ) , i d e n t i fi e d b y
a c o d e ,a n d h o w m a n y w e r e o r d e r e db y t h a t c u s t o m e r
(OTYORD).
F u r t h e r m o r e ,t h e c o m p a n y k e e p sa n i n v e n t o r y f i l e ( F i g u r e
8 - 2 ) t o c o n t a i n d a t a a b o u t e a c h i t e m w h i c h i s c a r r i e di n
stock. A separaterecord is kept for each item showing the
i t e m c o d e ( I T E M ) . t h e q u a n t i t y o n h a n d ( O T Y S T K ) ,a n d
the unit cost of eachitem (COST).
B e f o r e y o u c a n s h i p t h e c u s t o m e r ' so r d e r s ,y o u m u s t f i r s t
d e t e r m i n ei f t h e i t e m o r d e r e d i s s t i l l c a r r i e d i n s t o c k . T o d o
t h i s , a c l e r k c o u l d s p e n dt i m e l o o k i n g u p e a c h i t e m o r d e r e d
t o s e e i f t h a t i t e m i s r e c o r d e di n t h e i n v e n t o r y f i l e . H o w e v e r ,t h e s a m ei t e m w i l l p r o b a b l y b e o r d e r e d b y m a n y c u s t o m e r s . T h u s , t h e s a m e i n v e n t o r y f i l e r e c o r d sw o u l d h a v e
t o b e r e f e r e n c e do v e r a n d o v e r a q a i n .

8i-2

SALESFila

INVNTRY File

Rocord
s4567S9A87 15

I

A23
,r:

I

33

..!

'
"

rr40

,.,,,
"

":,,

",

s 3 4 6 7 2 4 C 8 96 3

s569823883 37
'r'

' i ' " ' r " * l ' i "'*' r ' ' ' "' ' ' " ' " ' "

883

46

2109

ITMORD

I 9?.,"q99,",,,,1i9
c72

70 21!50

Figure 8-2. Data for Dctcrmining if Ordrrr Cra br Filbd

Tabler

8-3

Siearclringa Single Table

DesigningTable lnput Records

R P G l l c a n s e a r c hf o r t h e d a t a i n m u c h l e s st i m e b y p e r { o r m i n g a t a b l e l o o k u p f u n c t i o n . A s s h o w n i n F i g u r e8 - 3 ,
a t a b l e ( T A B I T M ) w o u l d b e s e t u p i n s t o r a g et o c o n t a i n a l l

D a t a u s e dt o c r e a t ea t a b l e m u s t b e o b t a i n e d f r o m t a b l e i n p u t r e c o r d s . T h e s er e c o r d sc a n b e t a k e n f r o m t h e k e y b o a r d
o r C R T , p u n c h e d c a r d s ,m a g n e t i ct a p e , o r d i s k . T h e r e c o r d s

crf the items available (seeLoading Tablesin this chapter
f o r m e t h o d s o f l o a d i n gt a b l e d a t a i n t o s t o r a g e ) .

a r e r e a d b y t h e c o m p u t e r a n d e n t r i e sa r e p l a c e ds i d e b y s i d e
i n s t o r a g et o f o r m t h e t a b l e .

'l-he
s e c o n df i e l d o f e a c h s a l e sr e c o r d t e l l s t h e p r o g r a m
vvhich item to look up. For every salesrecord read into the
c o m p u t e r , T A B I T M i s c h e c k e dt o s e e i f t h e s e a r c hw o r d
( i t e m c o d e o n t h e s a l e sr e c o r d ) m a t c h e sa n e n t r y i n t h e
t ab l e .

T h e i n v e n t o r y f i l e f o r t h i s c o r n p a n yi n d i c a t e st h a t 9 8 t y p e s
o f i t e m s a r e c a r r i e d i n s t o c k . T h e r e f o r e ,t h e 9 8 i t e m c o d e s
m u s t b e c o n t a i n e d i n t a b l e i n p u t r e c o r d st o p r o v i d e t h e e n t r i e sf o r T A B I T M .

I n a d d i t i o n t o s e a r c h i n gf o r d a t a q u i c k l y , u s e o f t h e t a b l e
l c o k u p c a n o f t e n r e d u c et h e n u m b e r o f R P G l l s p e c i f i c a t i o n s n e e d e di n a p r c l g r a m .A l l y o u m u s t d o i s s e t u p a n d
d e f i n e t h e t a b l e , a n d s p e c i f yt h a t t h e l o o k u p o p e r a t i o n i s
tc be performed.

Number of Table lnput Records Required for a Table
H o w m a n y r e c o r d sw o u l d b e n e c e s s a r tyo p u n c h t h e 9 8
i t e m c o d e s ? T h a t i s e n t i r e l y u p t o y o u . T h e n u n r b e ro f
r e c o r d sr e q u i r e dt o c o n t a i n t h e t a b l e d a t a d e p e n d so n t h e
n u m b e r o f e n t r i e sv o u w a n t o n e a c h r e c o r d .

TABITM
A23
A87
821
883
c46

c89

i
)

)
Search

Y33

Word

Number of Entries on a Table lnput Record
T a b l e i n p u t r e c o r d sm a y e i t h e r c o n t a i n o n e e n t r y o r a n u m b e r o f e n t r i e s . T h e p o i n t t o r e m e m b e ri s t h a t a l l t a b l e i n p u t
r e c o r d sf o r a s i n g l et a b l e m u s t c o n t a i n t h e s a m en u m b e r o f
e n t r i e s ,e x c e p t f o r t h e l a s t r e c o r d .
T h e u s e o f o n e e n t r y p e r r e c o r d i s v e r y c o n v e n i e n ti f i t i s
n e c e s s a r tyh a t t h e e n t r i e sb e i n a p a r t i c u l a ro r d e r . T h e n t o
a d d o r d e l e t ee n t r i e s ,y o u m e r e l y a d d o r r e m o v ea r e c o r d .
O t h e r w i s e ,V o u w o u l d h a v et o r e c r e a t ea l l o f t h e r e c o r d s
f r o m t h e p o i n t o f c h a n g et o t h e e n d o f t h e t a b l e . H o w e v e r ,
i n t h e T A B l T M t a b l e , i t e m c o d e e n t r i e sn e e d n o t b e i n o r d e r ,
s o i n c l u d i n ga n u m b e r o f e n t r i e si n e a c h r e c o r d r e d u c e st h e
n u m b e r o f r e c o r d sr e q u i r e d .
F o r T A B I T M , 9 8 e n t r i e sm u s t b e r e c o r d e do n t a b l e i n p u t
r e c o r d s . l f 9 6 - c o l u m n c a r d sa r e u s e d ,3 2 e n t r i e sf i t o n e a c h
r e c o r d ,s i n c ee a c h i t e m c o d e i s t h r e e c h a r a c t e r sl o n g . T h e r e f o r e , t o s a v ec a r d s p a c e ,V o u c o u l d p u n c h t h r e e t a b l e i n p u t
r e c o r d sc o n t a i n i n g3 2 e n t r i e se a c h a n d a f o u r t h t a b l e i n p u t
r e c o r d f o r t h e r e m a i n i n gt w o e n t r i e s . ( S e eF i g u r e8 - 4 . ) I n
t h i s w a y , a l l r e c o r d sc o n t a i n t h e s a m e n u m b e r o f e n t r i e s
exceot the last record.

s275631C65

I)USTMH

ITMORD

OTYORD

SALES record
Figure 8-3. Searching a Table for a Particular Data ltem

Et-4

O f c o u r s e ,y o u d o n o t h a v et o f i l l t h e e n t i r e r e c o r d w i t h e n t r i e s ,a s w e h a v ed o n e . F o r i n s t a n c e ,y o u m a y w a n t r h e l a s t
3 6 c o l u m n so f a c a r d t o c o n t a i n n o p u n c h e s . I n t h a t c a s e ,
y o u c o u l d p u n c h 2 0 e n t r i e s( c a r d c o l u m n s 1 - 6 0 ) i n t o e a c h
o f f o u r t a b l e i n p u t r e c o r d s . T h e r e m a i n i n g1 8 e n t r i e sc o u l d
then be punched into a fifth record.

Noticein Figure8-4 that the two entriesin the fourth table
input recordare placedsideby side. Sincethereare unused
cardcolumnson the record,why not spacethe entries?
You cannot,because
all entriesmust be continuouson the
record,with no blankcolumnsbetvven entries. Furthermore,the first entry on eachrecordmust beginin position
one.

Y33lYs8
Rrcord 4
Contains
2 Table
E ntries

Describing
TableInput Recordswith ExtensionSpecifications
Records
1 , 2a n d3
EachContain
32 Table
Entries

Figure 84.

you then
Oncethe tableinput recordshavebeendesigned,
d e s c r i b teh e mt o t h e R P Gl l C o m p i l e rp r o g r a m .O r d i n a r i l y ,
the dataon input recordsis describedby enteringspecifications on the Input sheet. However,you describethe data
specifications
o n t a b l ei n p u t r e c o r d sb y c o d i n ge x t e n s i o n
o n t h e u p p e rh a l f o f t h e E x t e n s i o a
n n d L i n eC o u n t e rs h e e t .
(Hereafter,
we will referto the upperportion of the form
as the Extensionsheetand the lower portion asthe Line
Countersheet.)

A 2 3 l Ag 7 l B 2 1 l B 8 3 l c 4 6 l _

Figure8-5 showsthe extensionspecificationsneededto describethe tablecontainingitem codes.As you can see,a
s i n g l et a b l ec a n b e d e s c r i b euds i n go n l y c o l u m n s2 7 - 4 5 . O f
c o u r s er,e m e m b etrh a t t h e p a g ea n d l i n en u m b e r( c o l u m n s
1 - 5 )a n df o r m t y p e ( E i n c o l u m n6 ) a r ea l s op a r to f t h e e n t i r e s p e c i fc a t i o nl i n e .

Four Table-lnput Records for TABITM Entries

EXTENSIOA
N N D L I N EC O U N T E R
SPECIFICATIONS
&rd Elecro Nuh&,
Prryammer

E

I Oate

Sequence ol rhe Chaininq

File

To Filename

9

Table or
Array Name

From Filename

s

Table or
Array Name

9

Comments
G

E

E
Jt
92021222324252t

t TlI.

:
92
o
:

l
I
l

0
o

5

0

6

;

1

0

I

Figure 86.

t

Describing Table-lnput Records

Tables 8-5

T h e e x t e n s i o ns p e c i f i c a t i o n sp r o v i d e t h e f o l l o w i n g i n f o r m a t i o n a b o u t e a c ht a b l e t o b e u s e d :
1.

N a m e o f e a c h t a b l e ( c o l u m n s2 7 - 3 2 ).

2.

N u m b e r o f t a b l e e n t r i e sp e r t a b l e i n p u t r e c o r d ( c o l u m n s3 3 - 3 5 ) .

l f p o s s i b l e ,i t i s h e l p f u l t o a s s i g nt a b l e n a m e sw h i c h a r e
m e a n i n g f u l .F o r t h i s e x a m p l e ,t h e n a m eT A B I T M h a s
b e e na s s i g n e d .S u c h a n a m e g i v e sa n i n d i c a t i o no f w h a t
k i n d o f d a t a i s c o n t a i n e d i n t h e t a b l e ( i n t h i s c a s e ,i t e m
c o de s) .

3.

N u m b e r o f t a b l e e n t r i e sp e r t a b l e ( c o l u m n s3 6 - 3 9 ) .

4.

L e n g t h o f e a c h e n t r y ( c o l u m n s4 0 - 4 2 \ .

5.

W h e t h e r p a c k e do r b i n a r y d a t a l s c o n t a i n e d i n t h e
t a b l e ( c o l u m n4 3 ) .

W h e n a s i n g l et a b l e i s b e i n g u s e d ,a s i n t h i s c a s e .t h e t a b l e
n a m e i s e n t e r e di n p o s i t i o n s2 7 - 3 2 o f t h e E x t e n s i o ns h e e t
( s e eF i g u r e8 - 5 ) .

Number of Table Entries per Table lnput Record

6.

N u m b e r o f d e c i m a l p o s i t i o n si n e a c h n u m e r i c e n t r y
( c o l u m n4 4 ) .

7.

S e q u e n c eo f t a b l e e n t r i e s ,i f a n y ( c o l u m n 4 5 ) .

E a c h t y p e o f e n t r y w i l l b e d i s c u s s e di n t u r n . F r o m F i l e n a m e ( c o l u m n s1 1 , 1 8 ) ,T o F i l e n a m e( c o l u r n n s1 9 - 2 6 ) ,a n d
t h e e n t r i e si n c o l u r n n s4 6 - 5 7 a r e d e s c r i b e dl a t e r i n t h i s c h a p ter.

Assigning Table Names

T h e n u m b e r o f e n t r i e si n e a c h t a b l e i n p u t r e c o r d i s s p e c i f i e d i n c o l u m n s 3 3 - 3 5 . F i g u r e8 - 5 s h o w s3 2 e n t r i e sp e r r e c o r d f o r T A B I T M . I n t h i s w a y , t h e c o m p i l e r p r o g r a mw i l l
e x p e c t a l l t a b l e i n p u t r e c o r d st o c o n t a i n 3 2 e n t r i e s ,e x c e p t
t h e l a s t r e c o r d w h i c h m a y h a v ef e w e r e n t r i e s . N o t i c e t h a t
t h e n u m b e r e n t e r e di n t h e s ec o l u m n s s h o u l d e n d i n c o l u m n

Number of Table Entries Per Table
T h e n u m b e r o f e n t r i e sw h i c h c a n b e c o n t a i n e di n t h e e n t i r e
t a b l e i s e n t e r e di n c o l u m n s 3 6 - 3 9 o f t h e E x t e n s i o ns h e e t .
A s s h o w n i n F i g u r e8 - 5 , t h e n u m b e r ( 9 8 f o r T A B I T M ) s h o u l d
e n d i n c o l u m n3 9 .

E v e r y t a b l e u s e d i r r a p r o g r a mn r u s t b e a s s i g n e da n a m e
f r o m t h r e e t o s i x c h a r a c t e r sl o n g . T h e t a b l e n a m e m a y c o n t a i n a n y c o m b i n a t i o n o f a l p h a b e t i cc h a r a c t e r sa n d n u m b e r s .
H o w e v e r ,t h e f i r s t t h r e e c h a r a c t e r so f t h e n a m e m u s t b e
TAB.
W i t h t h e s ep o i n t s i n m i n d , w h i c h o f t h e f o l l o w i n g t a b l e
n a m e sa r e n o t a c c e p t a b l ea n d w h y ?

TABA

15ABCD

TAB C

TABSTATE

TB123

*TAB

TAB$2
T A B C a n d * T A B a r en o t a c c e p t a b l a
e s, t a b l en a m e sc a n n o t
c o n t a i nb l a n k so r s p e c i acl h a r a c t e r s u, c ha st h e * . T A B $ 2 ,
o n t h e o t h e rh a n d ,i s a n a c c e p t a b ltea b l en a m e ,s i n c e$ i s
o n e o f t h e t h r e es p e c i acl h a r a c t e rwsh i c hc a n b e c o n s i d e r e d
a n a l p h a b e t icch a r a c t e r(. T h eo t h e rt w o a r e# a n d @ . )
T h e n a m e s1 5 A B C Da n dT B 1 2 3a r e i n v a l i db e c a u steh e y
d o n o t b e g i nw i t h t h e a l p h a b e t icch a r a c t e rTsA B . S i n c e
T A B S T A T Ec o n t a i n sm o r et h a ns i x c h a r a c t e r ist ,c a n n o t
b e a n a c c e p t a b ltea b l en a m e .T A B A a n dT A B $ 2 a r et h e
o n l y t w o v a l i dt a b l en a m e ss h o w n .
8-6

Length of an Entry
T h e l e n g t h o f e a c h t a b l e e n t r y i s i n d i c a t e di n c o l u m n s 4 0 - 4 2 ,
w i t h t h e n u m b e r e n d i n g i n c o l u m n 4 2 . N u m e r i ct a b l e e n t r i e s m a y b e u p t o 1 5 d i g i t s l o n g , w h i l e a l p h a m e r i ce n t r i e s
c a n b e a s l o n g a s t h e m a x i m u m r e c o r d l e n g t hf o r t h e d e v i c e
(256maximum).
F o r T A B I T M , t h e l e n g t h3 h a s b e e n e n t e r e d . l t i s p o s s i b l e
t o s p e c i f y o n l y o n e l e n g t h . T h e r e f o r e ,t h i s n e c e s s a r i l m
y eans
t h a t a l l e n t r i e si n a t a b l e m u s t b e t h e s a m e l e n g t h .
A t t h i s p o i n t , y o u m a y b e w o n d e r i n gw h a t t o d o i f a l l e n t r i e s a r e n o t t h e s a m e l e n g t h . F o r i n s t a n c e ,y o u m i g h t w i s h
t o m a k e a t a b l e c o n t a i n i n gt h e m o n t h s o f t h e y e a r . T h e
s o l u t i o n i s s i m p l e - a l l e n t r i e sa r e m a d e t o b e t h e l e n g t h o f
t h e l o n g e s te n t r y . T h e w o r d S E P T E M B E R c o n t a i n st h e
most characters. Therefore. each entry should be 9 charact e r s l o n g . T o m a k e J U N E a n e n t r y w i t h l e n g t ho f 9 , y o u
w o u l d p l a c e5 b l a n k s a f t e r t h e l e t t e r E ( s e eF i g u r e 8 - 6 ) . l n serting extra blanks to lengthen the data entry is referred to
a s p a d d i n gw i t h b l a n k s . l f y o u r t a b l e e n t r i e sw e r e n u m b e r s ,
instead of letters, you would pad the short entries with
z e r o so r b l a n k s . ( F o r n u m e r i c e n t r i e s ,t h e z e r o so r b l a n k s
w o u l d p r o b a b l y b e p l a c e di n f r o n t o f t h e n u m b e r . )

J

Entries with Decimal Positions

A N U A R Y b b

W h e n t h e e n t r i e so f a t a b l e a r e n u m e r i c , i t i s n e c e s s a r tyo
s p e c i f y i n c o l u m n 4 4 t h e n u m b e r o f d e c i m a l p o s i t i o n s( 0 - 9 )
i n e a c he n t r y . E v e n i f a n u m e r i c e n t r y c o n t a i n sn o d e c i m a l
p o s i t i o n s ,a 0 m u s t s t i l l b e e n t e r e dt o i n d i c a t en u m e r i c d a t a .

F E B R U A R Y b
M A R C H b b b b
A P R I L b b b b

W h e n d e c i m a l p o s i t i o n sa r e n o t s p e c i fi e d ( c o l u m n 4 4 l e f t
b l a n k ,a s i n F i g u r e8 - 5 ) , R P G l l c o n s i d e r tsh e t a b l ee n t r i e s
to be alphameric.

r vA t Y b b b b b b
. JU N E b b b b b
J U L Y b b b b b

Sequence of Table Entries

, C U G U S T b b b
I ] E P T E M B E R+

L o n g e s tT a b l e E n t r y

( ) C T O B E R b b
I ! O V E M B E R b
D E C E M B E R b

F o r T A B I T M , t h e i t e m c o d e sn e e d n o t b e i n a n y p a r t i c u l a r
o r d e r . T h u s . c o l u m n 4 5 i s l e f t b l a n k i n F i g u r e8 - 5 . H o w e v e r ,i f t h e t a b l e e n t r i e sa r e i n a s c e n d i n go r d e s c e n d i n g
o r d e r . a n A o r a D i s e n t e r e du n d e r T a b l e S e q u e n c e( c o l u m n
4 5 ) . N o t e t h a t i f a t a b l e i s t o b e i n s e q u e n c et h e e n t r y i s
m a d e o n t h e E x t e n s i o ns h e e t . F o r i n p u t f i l e s ,o t h e r t h a n
t a b l e f i l e s ,t h e s e q u e n c ee n t r y i s a l w a y s m a d e o n t h e F i l e
Description sheet.

TableOf Months
Coding the Table Lookup Operation (LOKUP)
Figruvs
9-6. MakingTableEntriesthe SameLength

O n c e t h e t a b l e i n p u t r e c o r d sh a v e b e e nd e s c r i b e d V
, ou tell
R P G l l t o s e a r c ht h e t a b l e b y c o d i n g t h e L O K U P o p e r a t i o n
o n t h e C a l c u l a t i o n ss h e e t . T h i s i n v o l v e ss p e c i f y i n g :

Pa
\

(

Single Table
lnput Fite.
'LABITM
Entries for
and
TABCST in Alternatrng
Format.

F i i g u r e8 - 1 2 . A l t e r n a t i n g - F o r m a t T a b l e _ l n p u tF l e c o r d s

412

F o r T A B I T M a n d T A B C S T , e a c h p a i r o f r e l a t e de n t r i e sw i l l
r e q u i r ee i g h t c a r d c o l u m n s . B y p u n c h i n g 1 2 p a i r sc f e n t r i e s
i n a r e c o r d ,a n e n t i r e c a r d c a n b e f i l l e d . T h u s a t a b l e i n p u t
f i l e t o c o n t a i n a l l e n t r i e s( 9 g p a i r s )f r o m b o t h t a b t e sc a n
c o n s i s to f n i n e a l t e r n a t i n gf o r m a t , t a b l e i n p r . r ct a r d s . T h e
f i r s t e i g h t r e c o r d sm i g h t e a c h c o n t a i n j 2 p a i r so f e n t r i e s
a n d t h e i a s t r e c o r d m i q h t c o r r t a i nt w o p a i r so f e n t r i e s .
A s m e n t i o n e d b e f o r e ,e n t r i e sf o r T A B I T M a r e e a c h 3 _ c h a r a c t e r a l p h a m e r i cd a t a . F o r T A B C S T , 5 - d i g i t n u m e r i c e n t r i e s a r e n e e d e d . A l l o f t h e e n t r i e sf o r a s i n g l et a b l e m u s t
b e a l i k e ;t h a t i s , a l l a l p h a m e r i co r a l l n u m e r i c . h o w e v e r ,
t h e e n t r i e sf o r a n a l p h a m e r i ct a b l ea n d t h e e n t r i e sf o r a
n u m e r i c t a b l e c a n b o t h b e o n t h e s a m et a b l e i n p u t r e c o r d
w h e n a n a l t e r n a t i n gf o r m a t i s u s e d _
A l t h o u g h e a c h t a b l e i n p u t r e c o r d c o n t a i n se n t r i e sf r o m b o t h
t a b l e s ,a c t u a l l y t w o s e p a r a t et a b l e sa r e c r e a t e di n s t o r a g e
f r o m t h e s er e c o r d s . T h e R P G l l C o m p i l e r k n o w s t h a t t w o
t a b l e sa r e t o b e s e t u p , r a t h e r t h a n a s i n g l et a b l e , b e c a u s eo f
t h e w a y t h e r e c o r d sa r e d e s c r i b e do n t h e E x t e n s i o ns h e e t .

Last recordcontains
two pairsof entries

DescribingTwo Tableswith ExtensionSpecifications

RPG EXTENSIONAND LINE COUNTERSPECIFICATIOI\

\ffhentwo relatedtablesare usedin a program,you havethe
two tableinput files (onefor eachtable)
choiceof designing
o r o n l y o n et a b l ei n p u tf i l e c o n s i s t i nogf a l t e r n a t i nfgo r m a t
ttableinput records.

Q.d Electo Num&.

Extension Specifications

rlfyou decidedto set up TABITM and TABCSTusingseparatefiles,asdiscusedearlier,the two tableswould be describedasshownin Figure8-13. Sinceeachtable hasits
()wnset of input records,a separate
line of extensionspecificationsis neededfor eachtable.
N o w t a k ea l o o k a t F i g u r e8 - 1 4w h i c hd e s c r i b et sh e s a m e
l i n ei s c o d e d
t w o t a b l e s .N o t i c et h a t o n l y o n e e x t e n s i o n
'whenalternatingformat, table input recordsare used.
lSinceone line is codedfor eachsetof input records,the
secondtableof the alternatingformat recordmust be enteredon the sameextensionline asthe first table.
tablesarecreated.evenif you
Rememberthat two separate
usealternatingformat records.Therefore,both tablesmust
haveuniquenames,which arespecifiedon the Extension
sheet.The tablewhoseentry appearsfirst on a table input
recordis namedin columns27-32. The nameof the alternatingtable (in this case,TABCST)is enteredin columns
46-51of the sameline. The alternatingtable is alwaysthe
tablewhoseentry is the secondone in a pair of relatedentries.
Noticethat Numberof EntriesPer Record(columns33-35)
and Numberof EntriesPerTableor Array (columns36-39)
columnsfor alterspecification
do not havecorresponding
natingtables.Sincethe numberof entriesper recordand

Figure 8-13, Decribing Separate Table'lnput Records

numberof entriesper table must be the samefor eachof
are not needed
specifications
the alternatingtables,separate
for the secondtable.
However,the Lengthof Table Entry (columns52-54)must
be indicatedsinceit may be differentfor the two tables.
f n Figure8-14,a 3 hasbeenenteredin columns4O'42as
t h e t a b l ee n t r y l e n g t hf o r T A B I T M .w h i l ea 5 h a sb e e ne n '
teredin columns52-54specifyingthe lengthof the unit
cost entriesfor TABCST.
The unit cost entriesfor TABCSTare in the form of 12467,
which would represent$124.67. Therefore,a 2 hasbeen
enteredfor the numberof decimalpositions(column56).
indicatesthat the entry is numericand
This specification
containstwo decimalpositions.

RPG EXTENSIONAND LINE COUNTERSPECIFICATIONS
IBItt

.",.","."

".".es

MdilE co,F.a,on
7 5 7 6 1 1 1 8 7 9 n

**fl"_

Prq'.m
[fiT
ro".tr""r'o.l |

|

|

fT-l
| |

|

Extension Specifications

E

Sequence

Nunhr

ol rhe Chaini.g

ol the Charninq

Fi c

Field

To Filename

Table or
Arrav Name

i
j

Enti6
Entry

t

Table or
Array Name

.""""1|u

d

C-mment5

I 13

u"'' lcli

|:I:
il

ftf

59 6061

62

A

g

65 S

67 I

69

10

11 )2

13 74

l t ff+u

Figure 8-14. Describing Alternating-Format Table-lnput Records

Tables

8-13

T h e t a b l ee n t r i e sf o r T A B C S Ta r en o t i n a n y s p e c i aal l p h a _
b ' e t i co r n u m e r i co r d e rw h i c ht h e R p G l l C o m p i l e rp r o g r a m
could checkfor accuracy.Thus,no tablesequence
is speci_
f i e d f o r T A B C S T( c o l u m n5 7 i s l e f t b l a n k ) . L i k e w i s et,e l e _
plronenumbersin a directoryare not in sequence.
However,
just as phonenumbersarearrangedto correspond
with relatednames,the TABCSTentrieshavebeenarrangedso a
particularunit cost corresponds
with its relateditem code.

Codingthe Table Loor eo n e t o s i x c h a r a c t e r sl o n g u n l e s st h e n a m e ( w i t h i n d e x )
u s e dt o r e f e r t o a n i n d i v i d u a la r r a y e l e m e n t i s s p e c i fi e d o n l y
a s F a c t o r 1 o r F a c t o r 2 o n t h e C a l c u l a t i o ns h e e t . I n t h i s
oase,the array name plus comma plus index may be as long
its ten characters. Howetver,the array name portion of the
'eferencestill cannot ex,ceedsix characters.
F i g u r e9 - 2 1 , l i n e 0 1 , s h o w sa v a l i d r e f e r e n c et o t h e n l n t h
e l e m e n to f a n a r r a y n a n r e dA R Y 1 . H o w e v e r ,i f t h e a r r a y
c o n t a i n st e n o r m o r e e l r : m e n t ss, o m e o f w h i c h m a y h a v et o
be referenced,the name of this array would have to be
s h o r t e n e dt o p r o v i d ee n o u g h p o s i t i o n sf o r t h e i n d e x ( F i g u r e 9 - 2 1 . l i n e 0 4 ) . T h e l i m i t o f s i x c h a r a c t e r sa p p l i e se v e n
i f t h e n a m e o f a f i e l d i s u s e da s a n i n d e x " A s l i n e 0 7 s h o v r s ,

RPG

i f a n i n c J e xf i e l d I F L D i s s p e c i f i e d ,o n l y o n e c h a r a c t e r( B )
can be useli a$ ihe ilanle of the array becausethe indexed
n a m e i s s p e c i f i e r uj n d e r R e s u l t F i e l d . H o w e v e r ,C O M ,
I N D E X o r r l i n e 0 7 i s v a l i d , e v e nt h o u g h l o n g e rt h a n s i x
c h a r a c t e r sb, e c a u s ei t i s s p e c i f i e do n l y u n d e r f a c t o r c o l '
umrls.

Specifying an !ndex Which Does Not Change
l f y o u k n o w e x a c t l y w h i c h e l e m e n ti s t o b e u s e d i n a c a l c u '
lation or output operation and the specification is to refe r e n c et h e s a m ee l e m e n t i n e v e r y p r o g r a mc y c l e , y o u m a y
use a cclnstantas the irrdex. Assume a 7-element array
( S L S ) i s d e f i n e d t o c o n t a i n a s a l e s m a n 's i x d a i l y c o m m i s '
s i o n a m o u n t s a n d h i s t o t a l c o m m i s s i o nf o r t h e w e e k ' T h e
s i x d a i l y a t r o u n i s f r o r n o n e o f t h e s a l e s m e n ' isn p u t r e c o r d s
a r e r e a d i n t o e l e m e n t s1 - 6 o f t h e a r r a y . T h e s e v e n t h
f i e l d o n t h e i n p u t r e c o r d c o n t a i n sz e r o sa n d i s r e a d i n t o
e l em e n t 7 o f t h e a r r a y ( F i g u r e9 ' 2 2 . i n s e r t A ) .
The arrav elernentsare defined as 5-digit numbers with tvvo
d e c i r n a lp o s i t i o n s . O n c e t h e d a t a i s i n t h e a r r a y , t h e X F O O T
calculation operation is performed to add all elementsof the
a r r a y a n d p l a c et h e t o t a l i n t h e s e v e n t he l e m e n t { F i g u r e
9 - 2 2 . i n s e r t B ) . T h e w e e k l y t o t a l f o r e v e r y s a l e s m a ni s a l ways stored in the seventh element. Therefore, the actual
r r u n r b e r7 c a n b e s p e c i f i e da s t h e i n d e x . I n a d d i t i o n , a $ 2 5
b o n u s i s r c l b e a d d e d t o a s a l e s m a n 'tso t a l i f h i s w e e k l y c o m m i s s i o ne x c e e d s$ 1 7 5 ( F i g u r e9 ' 2 2 , i n s e r tC ) . T h u s , i n e v e r y
p r o g r a r nc y c l e , e l e m e n t 7 m u s t f i r s t b e c o m p a r e dt o $ 1 7 5 t o
determine if the bonus is to be added to the contents of
e l e m e n t7 .

CALCULAl'ION SPECIFICATIONS

l-

I
Operatron i

! .rrtur l

1

0 4
0 1 5

l--+
to--i, i t6 "
r 7l
lo
r- 8 ].'
l0

f--1--

I
f
f

I

i

Figure 9-21, Referencing a Particular Element of an Array

9-20

1| i1i] 11ftTt-l

035.20

027.80

042.37 031.87

025.93

000.00

SLS array
Element

RPG

CALCULATION SPECIFICATIONS

R e f e r e n c ee v e r y R e f e r e n c eo n l Y
e l e m e n t o f a r r a y 7 t h e l e m e n to l a r r a y

-..-...-*
t-iTl.lr

1+1t+, rorAL @

03520 o2780 o4237 0 3 1 8 7 01790 02593 1 8 1 0 7 SLS array
Element 7

RPG

SLS array 03520

CALCULATION SPECIFICATIONS

o2780 o4237 0 3 1 8 7 01790 02593 1 8 1 0 7
2500

S L S a r r a y 13520

o2780 04237 0 3 1 8 7 o1790 02593 20607
Element 7

Figwe 9-22. Specifying a Number as an Index

Arrays

g-21

Specifying an lndex Whi<:h Can Be Changed

Output of Individual Elements of an Array

O n t h e o t h e r h a n d , i f t h e a r r a y e l e m e n tw i l l v a r y w h e n a
p i t r t i c u l a rs p e c i f i c a t i o ni s p e r f o r m e d ,t h e i n d e x s h o u l d b e a

T o p u t o u t i n d i v i d u a le l e m e n t so f a n a r r a y , y o u c o d e t h e
s a m eo u t p u t s p e c i f i c a t i o n sy o u w o u l d f o r n o r m a l f i e l d s .
T h e o n l y d i f f e r e n c ei s t h a t u n d e r F i e l d N a m e o n t h e O u t p u t
s h e e ty o u m u s t s p e c i f y t h e a r r a y n a m e f o l l o w e d b y a c o m m a
and an index. The index then pointsto the particular
e l e m e n tt o b e p u t o u t ( F i g u r e9 - 2 4 ) .

f i e l d n a m e r a t h e rt h a n a n a c t u a l n u m b e r . l r r t h i s w a y , t h e
n u m b e r s t o r e d i n t h e i n d e x f i e l d c a n b e c h a n g e dd u r i n g t h e
p r o g r a mt o i n d i c a t er r u h i c ha r r a y e l e m e n t i s t o b e r e f e r e n c e d .
A n a r r a y ( S T K ) i s u s e dt o c o n t a i n t h e q u a n t i t i e si n s t o c k o f
a l l p a r t s m a n u f a c t u r e db y a c o m p a n y . E l e m e n t 1 o f t h e a r r a y c o n t a i n st h e q u a n t i t y f o r p a r t # i , e l e m e n t2 f o r p a r t
#2, and so on. When adclitiorralparts are manuf actured, the
v a l u e si n t h e a p p r o p r i a t ee l e m e n t sr n L t s b
t e updated. Therefore, records are punchecldaily for eaclr type ot part prod , r c e d . E a c h r e c o r dc o n t a i n s t h e p a r t n u m b e r ( N M ) a n d t h e
q u a n t i t y o f t h a t p a r t p r o d u c e d( O T Y ) .
'[o

p e r f o r m t h e u p d a t i n g ,t h e c o n t e n t so f t h e Q T Y f i e l d
nrust be added to one of the array elements for every reco r d p r o c e s s e d .T h u s , a n i n d e x m u s t b e u s e di n o r d e r t o
r e r f e r e n coen l y t h e i n d i v i d u a le l e m e n tt o b e u p d a t e d . S i n c e
e a c hd a i l y r e c o r d i s f o r a d i f f e r e n t p a r t n u m b e r , t h e a r r a y
e l e m e n tt o b e i n c r e a s e dl v i l l v a r y e a c ht i m e t h e s p e c i f i c a t i o n
i s p e r fo r m e d . F o r t h i s r e a s o n ,a n a c t u a l n u m b e r c a n n o t b e
s p e c i f i e da s t h e i n d e x , b e c a u s eO T Y w o u l d b e a d d e d t o t h e
s e r m e l e m e n t f o r e v e r y p a r t n u m b e r . I n s t e a d ,t h e N M f i e l d .
w h i c h c o n t a i n st h e p a r t n u m b e r f o r e a c h r e c o r d .c a n b e
s p e c i f i e da s t h e i n d e x ( F i g u r e9 - 2 3 ) . T h e n , e v e r y t i m e r h e
a r J d i t i o ns p e c i f i c a t i o rirs p e r f o r m e d ,t h e p a r t n u m b e r j u s t
s l o r e d i n N M i n d i c a t e sw h i c h e l e m e n to f t h e c r r a y i s t o b e
referenced.

T h u s , r e f e r e n c i n gi n d i v i d u a la r r a y e l e m e n t sf o r o u t p u t i s
t h e s a m ea s r e f e r e n c i n gt h e m f o r c a l c u l a t i o n s .l f t h e s a m e
e l e m e n t i s t o b e p u t o u t e v e r y t i m e t h e o u t p u t s p e c i fi c a t i o n
i s p e r f o r m e d ,a n a c t u a l n u m b e r c a n b e u s e da s a n i n d e x .
O t h e r w i s e ,i t d i f f e r e n t e l e m e n t sa r e t o b e p u t o l r t i n d i v i r l u .
a l l y , a f i e l d s h o u l d b e s p e c i f i e dw h i c h c o n t a i n st h e c h a n g i n g
i n d e x v a l u e . I n a n y c a s e ,t h e a r r a y e l e m e n t ( a r r a y n a m e
p l u s c o n r m a p l u s i n d e x ) o n t h e O u t p u t s h e e tc a n n o t e x c e e d
s i x c h a r a c t e r si n l e n g t h .
E d i t c o d e sa n d e d i t w o r d s c a n b e u s e dt o o u n c t u a t ea n i n d i v i d u a ln u m e r i ca r r a y e l e m e n t . l f a n e n t i r e a r r a y i s t o b e
p u t o u t b u t t h e e l e m e n t sr e q u i r ed i f f e r e n t p u n c t u a t i o n ,e a c h
e l e m e n ta n d i t s e d i t i n g s h o u l d b e s p e c i fi e d i n d i v i d u a l l y .
E d i t i n g t o b e d o n e o n a n i n d i v i d u a la r r a y e l e m e n t i s s p e c i f i e d
a n d p e r f o r m e di u s t a s i t w o u l d b e f o r a n y n o r m a l e l e m e n t .
T h i s m e a n st h a t , i f a n e d i t c o d e i s s p e c i f i e df o r a n i n d i v i d u a l
a r r a y e l e m e n t ,t w o b l a n k s a r en o t a u t o m a t i c a l l yi n s e r t e db e f o r e t h e e l e m e n t ,a s w a s t h e c a s ew i t h a n e n t i r e a r r a y . F u r t h e r m o r e , a l t h o u g ha n y t y p e o f o u t p u t c a n b e e d i t e d , e d i t i n g
i s g e n e r a l l yn o t s p e c i f i e df o r a n a r r a y e l e m e n tw h i c h i s t o b e
punched on a card or written on disk to be used as input to
a n o t h e rr u n .

1-IBlit

RPG

F i g u r e 9 - 2 3 , S p e c i f y i n gt h e n { a m eo f a F i e l d a s a n I n d e x

9-122

CALCULATION SPECIFICATIONS

**;i"

75 t6

/7

Prq,am t-IT
T
r d e , n i c a ni Iol .Li

78 79 80

i

r ]
I j

OUTPUT

G X 2 l 9 @ 0 U / M0 $ '
P n n r e nd U s a

SPECIFICATIONS

IBM

F;;F:'r-;

0

3

o

d

1

2

7 5 7 6 1 7 1 8 1 9 4 4

Poq"m
l'- f-f
I
rd""'r,",''".1 | I

-* * l t-T'l
l"-

fT
l
| 1 |

R e f e r e n c i n gt h e s a m e e l e m e n t
b y u s i n ga c t u a l n u m b e r a s i n d e x
.

T I
0 t5

T

-

f

_

1 1
o

R e f e r e n c i n gd i f f e r e n t e l e m e n t s
b y u s i n ga f i e l d a s t h e i n d e x

1

0 8

Figure9-24, Output of Individual Array Elements

ReferencingOnly Part of a Field
W h e n a f i e l d i s r e f e r e n c e di n a s p e c i fi c a t i o n , a l l c h a r a c t e r s
w i t h i n t h a t f i e l d a r e u s e d i n t h e c a l c u l a t i o no r o u t p u t .
H o w e v e r ,y o u m a y w i s h t o r e f e r e n c eo n l y s o m e o f t h e d a t a
s t o r e d i n a f i e l d . F o r e x a m p l e ,c o n s i d e rt h e c a s ed u r i n g
a d d r e s sp r i n t i n g w h e r e t h e z i p c o d e i s w i t h i n t h e s a m ef i e l d
as the city and state on an input record but must be printed
o n a s e p a r a t el i n e o n t h e o u t p u t r e c o r d ( F i g u r e9 - 2 5 ) .

T h e i n d e x i n gc a p a b i l i t y o f a r r a y sc a n b e u s e dt o e n a b l ey o u
t o r e f e r e n c es p e c i f i cc h a r a c t e r sf r o m a n i n p u t f i e l d . T h i s i s
a c c o m p l i s h e db y s e t t i n gu p t w o a r r a y s ;o n e t o c o n t a i n t h e
e n t i r e f i e l d o f d a t a a n d o n e t o h o l d o n l y t h e s p e c i f i cc h a r a c ters you want to reference.

output record

lnput record

KENNETR
HAy
l + s a z oN
l ELSoN
L VENUE
NoRTHI
1 1 4 6 1R9u s s E L A
lRocHesrenM
, r N Ns s 9 o 1

|

NELSON KENNETH RA\
flg RIJ]SELL AVENUE NO RTH
R O C H E S T E RM
, INN
55901

\

csz field to be printed as:

ROCHESTERf M I NN655901{bb666b66
CSZ field

F i g u r e 9 - 2 5 . Referencing Parts of a Field Separately
Arrays

9-23

F i r s t ,t h e e n t i r e f i e l d f r o n r w h i c h y o u w i s h t o u s ed a t a i s
s t o r e d i n a n a r r a y o f t h e s . a m en a m e a s s h o w n i n F i g u r e
9-116. (See Loading Arrays, Storing lnput Data into Execu-

r a y w i l l t h e n c o n t a i n t h e p o r t i o n o f t h e o r i g i n a li n p u t f i e l d
w h i c h y o u w i s h t o r e f e r e n c es e p a r a t e l yi n c a l c u l a t i o n so r
output.

t i o n T i m e A r r a y s l a t e r i n t h i s c h a p t e rf o r a n e x p l a n a t i o no f
t h i s m e t h o d o f l o a d i n ga n a r r a y . ) T h i s a r r a y i s p r e v i o u s l y

F o r a n a d d r e s sp r i n t i n g p r o g r a m ,l e t ' s a s s u m et h e i n p u t r e c o r d s
a r e d e f i n e d a s s h o w n i n F i g u r e9 - 2 7 . T h e C S Z f i e l d c o n t a i n s
t h e c i t y / s t a t ea n d z i p c o d e . A l t h o u g h n a m e so f t h e c i t y a n d
s t a t e m a y v a r y i n l e n g t h ,t h e z i p c o d e i s a l w a y sf i v e d i g i t s
l o n g . A n y r i g h t h a n d ,u n u s e dp o s i t i o n so f t h e C S Z f i e l d w i l l

d e f i n e d a s c o n t a i n i n ga s n r a n y o n e - b y t ee l e m e n t sa s t n e r e
a r € c) h a r a c t e r si n t h e f i e l d t o b e r e f e r e n c e d .T h u s , e a c h
c h i e r a c t eor f t h e o n e f i e l d i s a c t u a l l y s t o r e d i n a s e p a r a t e
e l e m e n t o f t h e a r r a y . T h e a r r a y e l e m e n t sc a n t h e n b e r e f e r e r n c eodn e a t a t i m e ( u s i r r ga n i n d e x ) u n t i l a n e l e m e n tc o n -

containblanks.

t a i n i n g a s p e c i fi c c h a r a c t e ri s l o c a t e d . T h i s p r o c e s so f c h e c k i n g lt h e e l e m e n t so f a n a r r a y f o r p a r t i c u l a rd a t a i s r e f e r r e dt o
as field vanning.

T h e t w o a r r a y sf o r t h i s p r o g r a ma r e d e f i n e d w i t h t h e e x t e n s i o n s p e c i f i c a t i o n si n F i g u r e9 - 2 8 . C S Z i s s e t u p t o c o n t a i n
3 0 e l e m e n t s ,o n e f o r e a c hc h a r a c t e ro f t h e C S Z f i e l d f r o m
t h e i n p u t r e c o r d . T h e f i v e e l e m e n t so f t h e Z I P a r r a y w i l l b e
u s e dt o c o n t a i n t h e z i p c o d e p o r t i o n o f t h e C S Z f i e l d .

A f t e r s c a n n i n gt h e e l e m e n t sa n d l o c a t i n ga s p e c i fi c c h a r a c t e r , y o u c a n t h e n m o v e t h a t c h a r a c t e ra n d a n y c h a r a c t e r s
( e l e m e n t s )o n e i t h e r s i d e o f i t t o a s m a l l e ra r r a v . T h i s a r -

CSZ field (30 characters)

ROCHESTER,5MI NN5559016bbb6btt56

R

o

C

H

E

e

T

E

R

4

M

N

N

6

5

I

0

1

CSZ array (30 elements)

5

5

o

0

1

7lP array (5 elementsl

F i g u r e 9 - 2 6 . l s o l a t i n g P a r t o f a rF i e l d

9-2tl

6

x

s

5

5

6

6

5

6

cx2i $9a u/M o50'
Pr^redLnusa

RPG INPUTSPECIFICATIONS

75 76 11 1A 79 aO

P,qram [-fTT-t-T-l
taenrt'catool

Becord ldentitication Codes

I

2

!

=

z

a

3

5

I

F :TF --T;

!
d

j

F i e l dN a m e

. E a

E
!

924

122232.

26

[;

To

o

E

' t r 0 1 1 l 2 1 3 t 1 4r 5 t 1 6

From

|

|

|

I

Field
lndicators

Field Location
3

E
Fi l e n a m e

I

I

8

; P
: d

Ze.o
&
Blank

!
.9

,3 54 55 56 57 5a

15 36 37 33

I NNb55901
ROCHESTER,bM
Ubububbb$
CSZfield

Figurc 9-27 . Defining a Field to be Scanned

ForD X21.Sr
fri^rd 'n U.S.A.

RPG EXTENSIONAND LINE COUNTERSPEC]FICATIONS
IBll

"'--,-n

"*.*rrn,rc

co*..ro
876771a79f,)

G,d Elecro Numbr
_

I Dar€

Eq,!m l-ri-rrT.l
ld.nrt€rionl
I

I

I

|

|

I

Extension Specifications

E

'*l

Squence

of rhe Chaining

File

pr ol the Ch.ining Field

To Filename
From Filflame

.t

Table q
Arrav Name

Table or
Arrav Name

.9

E
E

I

9m21222321252r

F
t2s

;

Comments

*

t

Figure 9-28, Dofining Arrays for Field Scanning

Arrays

9-25

T o l o c a t e t h e z i p c o d e i n t h e C S Z a r r a y , t h e e l e m e n t sm u s t
b e r ; c a n n e do n e a t a t i r n e , b e g i n n i n gw i t h t h e l a s t ( r i g h t m o s t )
e l e r n e n to f t h e a r r a y . T h u s ,t h e i n d e x f i e l d ( C ) f o r r e f e r e n c i n gt h e i n d i v i d u a lf i e l d s o f C S Z i s i n i t i a l l y s e t u p i n t h e

The program can now proceed to perform the next group of
c a l c u l a t i o n sw h i c h m o v e t h e l o c a t e dc h a r a c t e rt o t h e r i g h t m o s t p o s i t i o n o f t h e Z I P a r r a y ( l i n e 0 9 ) . T h e c h a r a c t e ri n

C a l c u l a t i o ns h e e tt o c o n t a i n t h e v a l u e 3 0 ( F i g u r e 9 . 2 9 , l i n e
0 1 ) . W h e n t h e l a s t ( r i g h t m o s t )c h a r a c t e ro f t h e z i p c o d e i s
i o c a t e d ,i t s h o u l d b e m o v e d t o t h e r i g h t m o s t ( f i f t h ) e l e m e n t

t h e C S Z a r r a yw h i c h w a s m o v e dt o t h e Z I P a r r a y i s n o w
m a d e b l a n k ( l i n e i 0 ) s o t h e c i t y a n d s t a t el i n e c a n b e p r i n t e d
w i t h o u t t h e z i p c o d e . T h e i n d e x v a l u e sf o r b o t h a r r a y sa r e
decreasedby /, so the next zip code character (to the left

o f t h e Z I P a r r a y . T h e r e f o r e ,a 5 i s i n i t i a l l y s e t u p i n t h e i n d e x f i e l d ( Z ) w h i c h w i l l r e f e r e n c ea p a r t i c u l a rf i e l d o f Z l p
( F i g u r e9 - 2 9 , l i n e 0 2 ) .

of the last one moved) can be moved from CSZ to the next
p o r t i o n i n t h e Z I P a r r a y . W h e n t h e v a l u eo f Z b e c o m e s0
( i n d i c a t o r2 1 i s o n ) , a l l f i v e c h a r a c t e r so f t h e z i p c o d e h a v e

W i t h t h e i n d e x f i e l d s s e t u p , t h e p r o g r a mc a n b e g i n s c a n n i n g
CS.Zfor the zip code. The elementsof CSZ are checked,
f r o r n r i g h t t o l e f t , u n t i l t h e f i r s t n o n b l a n k c h a r a c t e ri s
located. ,Asline 04 shows, a character is compared to a
b l a n k . l f i t i s b l a n k . t h e i n d e x v a l u e i s d e c r e a s e d( l i n e 0 b )
so the next character to the left can be compared to a blank.
W h , . ' no n e ,o f t h e c h a r a c t e r sc h e c k e di s n o t a b l a n k ( i n d i c a t o r
2O 'cftl, the last character of the zip code has been located.
T h i s e n d st h e f i e l d s c a n n i n g .

RPG

b e e nm o v e d t o t h e Z I P a r r a y a n d m a d e b l a n k i n t h e C S Z
arrav.
A f t e r c a l c u l a t i o n st,h e o u t p u t s p e c i f i c a t i o n si n F i g u r e 9 - 3 0
c a u s et h e n a m e a n d a d d r e s st o b e p r i n t e d . T h e N A M E a n d
S T R E E T f i e l d s a r e p r i n t e d e x a c t l y a s t h e y a p p e a ro n t h e i n put record. City and state, on the other hand. are printed
f r o m t h e C S Z a r r a y r a t h e r t h a n t h e i n p u t f i e l d , b e c a u s et h e
z i p c o d e h a s b e e n b l a n k e d o u t . T h e z i p c o d e ,w h i c h w a s
m o v e d t o t h e Z I P a r r a y , i s t h e n p r i n t e d a l o n eo n t h e n e x t
outout line.

C A L C U L A T ' I O NS P E C I F I C A T I O N S
1

2

71 18 19 AA

f t'-t

[]

a
E

a

Figure9-29. Field Scanning

9-26

P'oerdm f-T
__

th.r,{caro.Ll

l f-fl-l
L

I

1

I

OUTPUT

SPECIFICATIONS

**11",

O,tnr,

Constano
t r E d L tV y ' o r d

o
0

2

;l,l
l

' l - 1 r

o
o

i

0

4

o
o

5
it 5

L !

. l r

llj

t t

0 t6
t l
o 7
I

I

l l -

O n l y c i t y a n d s t a t ew i l l b e p r i n t e d s i n c e
z i p c o d e b l a n k e do u t .

r 1 -

O n l y z i p c o d ew i l l b e p r i n t e d .

' - ]

Figure9-30. Output of Parr of a Field

LOKUP OF AN ARRAY

1.

T h e s e a r c hw o r d t o b e u s e d .

Searchingan Array for a Particular Element

2.

T h e L O K U P o p e r a t i o nc o d e .

A n a r r a y c a n b e s e a r c h e dt o d e t e r m i n ei f a p a r t i c u l a r
e l e m e n to f d a t a i s s t o r e d i n t h e a r r a y . A c t u a l l y , t h e a r r a y
l o o k u p i s c o d e d a n d p e r f o r m e d i n a l m o s t t h e s a m ew a y a s

3.

The arrayto be searched.

4.

T h e c o n d i t i o n w h i c h m u s t b e s a t i s if e d .

a s i n g l et a b l e l o o k u p . A s t h e C a l c u l a t i o ns h e e t i n F i g u r e
9 - 3 1 s h o w s ,y o u s p e c i f y :

5.

T h e r e s u l t i n gi n d i c a t o rw h i c h t u r n s o n i f t h e c o n d i tion is met.

RPG

Fo,m CX21 9093

CALCULATION SPECIFICATIONS
/5

P'oean fT
rren,rcaro.l

16

I

17

19

7A

80

TT-T_T_-]
j_J
I

I

I

t
: o

,;
0

l

Jli
i'l1il

T

f

_T
I

i i

+

A c t u a l s e a r c hw o r d
or fieldcontaining
s e a r c hw o r d

Name of array
to be searched

C o n d i t i o nw h i c h s a t i s f i e s e a r c h
a n d w h i c h r e s u l t i n gi n d i c a t o r
isturnedon

F i g u r e 9 - 3 1 , S e a r c h i n ga n A r r a y f o r a P a r t i c u l a r E l e m e n t

Arravs

9-27

Pageof GC21-7567-2
lssue2
d 4 M a v1 9 7 6
BvTNL: GN21-5389
T h e a r r a y l o o k u p c o n t i n u e so, n e e l e m e n ta t a t i m e , u n t i l
t h e s e a r c hc o n d i t i o n i s s a t i s f i e do r t h e e n d o f t h e a r r a y i s
r e a c r h e dw, h i c h e v e ro c c u r sf i r s t . A s i s t h e c a s ef o r t a b l e
loollupsa
, r r a y e l e m e n t sm u s t b e i n s e q u e n c e( A o r D ) i f
s e a r c h i n gf c l r e i t h e r a l < l wo r h i g h c o n d i t i o n . A d d i t i o n a l
c o d i n g i s n e c e s s a r yi f s r : a r c h i n g
a n o u t - o f - s e q u e n ca
er r a y
for either high or low. (See Searching an Array for More
Than One Element and Output During an Array Search.)
A l t h o u g ha r r a y a n d t a b l es e a r c h easr e s i m i l a r ,t h e r e i s a n
i m p o r t a n l .c l i ff e r e n c ey o u m u s t b e a w a r e o f . R e m e m b e r ,
t h e a r r a y l o o k u p i s s i m i l a rt o a s i n g l e - t a b lleo o k u p , n o r a
t w o - t a b l e l o o k u p . O n l y o n e a r r a y i s s p e c i f i e di n t h e l o o k u p o p e r a t i o n . A n y e l e m e n tw h i c h i s r e f e r e n c e da s t h e r e s u l t
o f a s u c c e s s f usl e a r c hc a n o n l y b e f r o m t h e a r r a y a c t u a l l y
s e a r c h e d .I n o t h e r w o r d s , t h e a r r a y c a n n o t b e s e a r c h e dt o
m a k : ea n e l e m e n tf r o m a n o t h e r a r r a y a v a i l a b l e a, s i s t h e c a s e
w h en t w o r e l a t e dt a b l e sa r e u s e d i n a l o o k u p o p e r a t i o n . F o r
t h i s r e a s o r rn, o r e s u l tf i e l d m a y b e s p e c i f i e di n a n a r r a y l o o k up operataon.

W i t h a r r a y s ,h o w e v e r ,y o u a l s o h a v et h e c a p a b i l i t y o f b e g i n n i n ga n a r r a y s e a r c ha t a n y e l e m e n ty o u s p e c i f y . U n d e r
F a c t o r 2 . y o u s p e c i f y t h e a r r a y n a m e ,f o l l o w e d b y a c o m m a
a n d a n i n d e x . T h e i n d e x ,w h e t h e r a n a c t u a ln u m b e r o r t h e
n a m e o f a f i e l d c o n t a i n i n ga n u m b e r , p o i n t s t o t h e a r r a y
e l e m e n tw h e r et h e s e a r c hi s t o b e g i n( F i g u r e9 - 3 2 ) .
I n a l a r g ea r r a y w h e r e y o u k n o w t h a t t h e v a l u e y o u a r e
s e a r c h i n gf o r i s n o t i n a p a r t i c u l a rs e c t i o no f t h e a r r a y ,
s e a r c ht i m e c a n b e g r e a t l yd e c r e a s e db y b e g i n n i n gt h e
l o o k u p a t a p a r t i c u l a re l e m e n t . S u p p o s ey o u h a v ea 3 0 0 e l e m e n ta r r a y n a m e A R Y c o n t a i n i n gt h e v a l u e s0 0 1 t h r o u g h
3 0 0 i n a s c e n d i n gs e q u e n c e .T o l o c a t ea v a l u eo f 0 4 7 , o n l y
4 7 e l e m e n t sw o u l d h a v e t o b e c h e c k e db e f o r e t h e s e a r c h
c o n d i t i o n w a s s a t i s if e d . H o w e v e r ,t o l o c a t et h e v a l u e 2 8 9 ,
2 8 9 e l e m e n t sw o u l d h a v e t o b e c h e c k e d ,i f t h e s e a r c hb e g a n
at the f irst arravelemenr.
N o w , d i v i d e t h e a r r a y i n t o t h r e e p a r t s o f 1 0 0 e l e m e n t se a c h :

E l e m e n t1s- 1 0 0 :

v a l u e 0s 0 1 - 1 0 0 .

Starting the Search at a Particular Element

E l e m e n t1s0 1 - 2 0 0 :

value1
s01-200

A n o t h e r v e r y i m p o r t a n t d i f f e r e n c eb e t w e e n t a b l e sa n d a r r a y s c o n c o r n sw h e r e t h e s e a r c hc a n b e g i n . I n a t a b l e s e a r c h ,

E l e m e n t2s0 1 - 3 0 0 :

v a l u e 2s 0 1 - 3 0 0 .

o n l y t h e n a m e o f t h e t a b l e t o b e s e a r c h e dc a n b e s p e c i f i e d
a s F a c t o r 2 o f t h e l o o k u p o p e r a t i o n . A s a r e s u l t ,a t a b l e
s e a r c ha l u ' a y sb e g i n sa t t h e f i r s t t a b l e e l e m e n t . L i k e w i s e ,i f
o n l l r 3 n a r r a y n a m e i s s p e c i f i e da s F a c t o r 2 o f a l o o k u p
o p e ' a t i o n ,t h e s e a r c ha u t o m a t i c a l l yb e g i n sa t t h e f i r s t
e l e n r e n to f t h e n a m e d a r r a y .

RPG

f ',

C A L C U L A T i O NS P E C I F I C A T I O N S
)

i"',,i,

I'"""I:,rr:iilliLl

I

2

Otrriot c'

Actual number
as index

, i
l

t
.

l

F i g ur e 9 - 3 i 1 . S t a r t i n g a n A r r a y S e a r c ha t a P a r t i c u l a r E l e m e n t

9-2a

J t l 6 l 1 7 8 l 9 8 A

P ot TL rl l . , _ P,_,o :, ." ,, ,, T. ,- .l l1I 1I I I fI l l

Name of index field containing number

F o , ra n y v a l u eo f l e s st h a n 1 0 1 ,t h e f i r s t t h i r d o f t h e a r r a yi s
s e a r c h e db,e g i n n i n ag t e l e m e n t1 . F o r v a l u e sg r e a t etrh a n
1 0 0 ,b u t l e s st h a n 2 0 1 ,t h e s e c o n dt h i r d o f t h e a r r a yi s
s e a r c h e db,e g i n n i nagt e l e m e n t1 0 1 . L i k e w i s ea, s e a r c hi s
sterrted
at element201 to locateany valuegreaterthan 200.
In any case,no more than 100 elementshaveto be checked
to satisfythe searchcondition.
F o r t h i se x a m p l et,h e n u m b e ro f t h e a r r a ye l e m e nat t w h i c h
t h r es e a r c hi s t o b e g i nw i l l v a r y ,d e p e n d i nogn t h e v a l u eb e i n g
for. Figure9-33 showsthat three LOKUP'shave
searched
beencoded. Only one of the lookup operationsis performed
f o r a p a r t i c u l avr a l u e .
To determine
w h i c h L O K U P( l i n e0 4 , 0 5 , o r 0 6 ) i s p e r formed,you must first determinein which part of the array
the valueis located.The first COMP(compare)operation
( l i n e0 2 ) c h e c k sf o r a v a l u ei n t h e f i r s t 1 0 0e l e m e n t s l.f t h e
v a l u ei s l e s st h a n 1 0 1 ,i n d i c a t i n tgh e f i r s t o n et h i r d o f t h e
r 3 i s s e to n . l f 3 3 i s o n , t h e L O K U Pb e g i n a r n a yi,n d i c a t o 3
n i r n ga t e l e m e n 1
t i s p e r f o r m e d( l i n e0 4 ) . H o w e v e ri,f t h e
v a l u ei s n o t i n t h e f i r s t t h i r d o f t h e a r r a y( 3 3 o f f ) , a n o t h e r
c o m p a r e( l i n e0 3 ) i s n e c e s s a tr oy d e t e r m i n ei f t h e v a l u ei s i n
the secondthird of the array (indicator44 set on). Thus,
t h e L O K U Pb e g i n n i n ag t e l e m e n t1 0 1 ( l i n e0 5 ) i s p e r f o r m e d
w i t h i n d i c a t o4
r 4 o n . l f n e i t h e ri n d i c a t o r( 3 3 o r 4 4 ) w a ss e t
on, the valuemust be in the lastthird of the arr'ay.if it is in
the arrayat all. Therefore,with both 33 and 44 off, the
L O K U Pb e g i n n i n ag t e l e m e n2t 0 1 i s p e r f o r m e d .

RPG
.,",.",

IBIiI

"."

F o r t h e f i r s t L O K U P ( l i n e 0 4 ) , i t i s n o t n e c e s s a r yt o a c t u a l l y
s p e c i f yt h e n u m e r i c v a l u e 1 a s t h e i n d e x , i n t h e s a m em a n n e r a s 1 0 1 i s s o e c i f i e df o r t h e s e c o n d L O K U P . W h e n n o i n d e x i s s p e c i f i e dw i t h t h e a r r a y n a m e , t h e s e a r c ha u t o m a t i c '
a l l y b e g i n sa t t h e f i r s t f i e l d , a s i f t h e i n d e x w e r e 1 .
ruote.' Setting off indicator 44 (line 01) prevents an error
i n t h e l o o k u p f u n c t i o n . W h a t w o u l d h a p p e ni f t h e S E T O F
operation was not used and indicator 44 was set on in the
f i r s t c y c l e a n d 3 3 i n t h e s e c o n dc y c l e ? I n t h a t c a s e ,4 4
would not be set off in the second cvcle becausethe N33
c o n d i t i o n w o u l d n o t b e s a t i s f i e di n l i n e 0 3 . T h u s . b o t h
l i n e s0 4 a n d 0 5 w o u l d b e e x e c u t e d . T h e L O K U P o p e r a t i o n
i n l i n e 0 4 w o u l d b e s u c c e s s f ual n d i n d i c a t o r 6 6 w o u l d t u r n
on. The LOKUP operationin line 05 would not be successful and 66 would be turned off . Thus,a not-found condit i o n w o u l d r e s u l te v e nt h o u g h t h e L O K U P w a s s u c c e s s f u l .
l f t h e v a l u eo f t h e i n d e x c h a n g e sa, s i n t h i s c a s e ,y o u c a n
u s ea n i n d e x f i e l d t o c o n t a i n t h e n u m b e r o f t h e a r r a y f i e l d ,
r a t h e r t h a n u s i n gt h e a c t u a l n u m b e r . I n t h i s w a y , i t i s n e c e s s a r yt o c o d e o n l y o n e L O K U P . O f c o u r s e ,y o u m u s t
p l a c et h e a p p r o p r i a t en u m b e r i n t h e i n d e x f i e l d e v e r y t i m e
b e f o r et h e l o o k u p o p e r a t i o n i s p e r f o r m e d . T h u s a n i n d e x
f i e l d w i l l n o t a l w a y s r e d u c et h e n u m b e r o f s p e c i f i c a t i o n s
required.

Forh GX21 S93

CALCULATION SPECIFICATIONS

Pr'nrdd ^ u.s a

Bunn.*M,chn€coroo..,on
75

t-T-l

"*LLl"

c
:;

1

Length
6 l

A 9 ll(

z

z

,"1,

419202122232425262

c

1
0

-f
c
4

11

18

79

8A

I-TT-I

Plus lM'n!sl ZFI

Operation

6 E

0

16

f-T_--f

' 0 " r , , ' , " o . 1 _|. 1| l . l

Fesult Field

: 6
jz 5
llP,r 3
ATE
P,5i

\
TAX Array

RPG

,F ir,, N -r,''

ll

r
i

r

l

/!

?

''"L' ]''---

l

o,rt,rroFl

76 77 7! r9 n!

i ' f l
I

I

1

1 il

_L

I ICATIONS
INPUT SPECF

RPG

[" ",'"
jr;
[: ,r

_ l

E X T E N S I O NA N D L I N E C O U N T E RS P E C I F I C A T I O N S

t : ' : " ' l i i
1

-fl

1

I ";t

[.[--

[:tI

, l l l

'r,...,.d,,..i-,;,o,,,;:

[ , - T -

-[

-, f l r l l-

'i -

i

l[Tlnqdi.
i : l q-f
l

i-r

-]'T[
l i
l l i l l ,1,1,
r
; l:i.l[
l]lt t.r
lilii
lit ,t. L | ' l t l tl :- 'rl l'r
f-

t:i:
rI lzl.

i

1

l l l

l

i

rl'il'

i
iI
l l l l i ll j iri l
, it ll il i Ii l i t i

l.il'r1'lFr1
ir
lii
[;:1
ll, , "11+
l l l l l
,
l
l
r l l rt 1
, , ,l l:li li i l l i rl l
i:,;,1
iL

l '

l l l l i r

] l t l

I

l, l : 1 ,

t i l i
r
l t i l i lt
i l l l i i

l l

l

I

- . l l- 1 1 - :

s r n c et n e
I
c o o er sa \
,
-Jl l l sysrems.

s.lTill

)
'

'

l

'

l

r

4 r r5li fIAX,,2
[A/'a
' l '

l iI T A I.6i lr.Axr2
L.1l 2.r-lir Ax) .2
ilrAxr,2
li li ii i l i l i tr i i 4 a6i
3rl fAXr 2
I

l : r : l l l i; i, l:1 , l l i l ,
'

i

[-

I
I

l

I'
l

F i g u r e 9 - 4 8 . L o a d i n g A r r a y D a t a C o n s e c u t i v eo n M o r e t h a n O n e R e c o r d ( M o d e l 1 0 C a r d S y s t e m )
A r r ay s

943

P a g ec : t G C 2 1 - 7 5 6 7 - 2
l s s u e d1 2 4M a y 1 9 7 6
By TN l-: GN21-5389

It is inportant to note that when data is storedin an array
b y s p e c i f y i n gt h e a r r a y n a m e a s t h e f i e l d n a m e , t h e i n f o r m a t i o n i s p l a c e da t t h e b e g i n n i n go f t h e a r r a y . T h u s , t h e 9 5
c o l u n r n so f d a t a f r o m t h i s f i r s t i n p u t r e c o r d a r e s t o r e d i n
e l e m e r n t1s- 1 9 o f t h e a r r a y ( F i g u r e9 - 4 8 ) .
A l t h c , u g ht h e d a t a o n t h e s e c o n dr e c o r d i s a l s o a r r a n g e d
c o n s e c u t i v e l ye, a c he l e m e n t i s l o a d e ds e p a r a t e l y .T h e s e c o n d r e c o r d c a n n o t b e d e f i n e d a s a s i n g l ea r r a y f i e l d a n d
s t o r e  nr e c o r d st w o a n d t h r e e . B e c a u s eo f t h i s , y o u m i g h t
w a n t t o c o n s i d e rl o a d i n gt h e a r r a y a s a c o m p i l e t i m e o r p r e e x e c u t i o nt i m e a r r a y , i n s t e a d .

9-44

Array Data Consecutiveon More Than One Record (Model
6, Model 10, Model 12 andModel 15)
O n t h e M o d e l6 , M o d e l 1 0 , M o d e l 1 2 a n d M o d e l 1 5 , i t i s
m u c h e a s i e rt o l o a d a r r a y d a t a t h p t i s c o n s e c u t i v eo n m o r e
t h a n o n e i n p u t r e c o r d . C o n s i t J etrh e p r e v i o u se x a m p l e
( F i g u r e9 - 4 8 ) . T h e A ' r c y d a t a o n t h e s e c o n dr e c o r d c a n b e
d e s c r i b e da s a s l n g l ef i e l d o n t h e s es y s t e m s ,b e c a u s et h e
M O V F A o p e r a t i o n c o d e i s a v a i l a b l eo n t h e s es y s t e m st o
ri-rovedata from a field to an array. Figure 9-49 shows the
c o d i n g n e c e s s a r tyo l o a d t h e T A X a r r a y w h e n t h e M O V E A
o p e r a t i o ni s u s e di n c a l c u l a t i o n s .
U s i n gt h e M O V E A o p e r a t i o n ,d a t a t h a t i s c o n s e c u t i v eo n
m a n y i n p u t r e c o r d sc a n c o n v e n i e n t l yb e l o a d e dd u r i n g
p r o g r a me x e c u t i o n . S e e y o u r R P G l l R e f e r e n c eM a n u a l f o r
a c o m p l e t ed e s c r i p t i o no f t h e u s e o f M O V E A .

Fo.m X21.S1

SPECIFICATIONS
A N D L I N EC O U N T E R
RPG EXTENSION
$'ch n€ co'po.aron

,.'.,^.''"".,

[Bll

P . , n r e d i nU S A

T_15

**il.'_

",''nes

15

76

/7

18

P'qrum fT-ffn-l
ldentricrrionL I
I
I

19

L

80

|

|

E x t e n s i o nS
. p e c i fi c a t i o n s
Reco.d

Sequence

ot the Chai.rnq

Frr!

T a b l eo r
Array Name

M r t h , n .c o , p o , a r o n

:l8ll,,,.,",,,.",,

U / MO 5 0 '

G X 2 rS 9 4

RPG INPUTSPECIFICATIONS

75 76 77 78 79 80

"",nes

P'oer'm f-i--[_l-T]-l
ldenul,car,onL
|
|
|
L

Record

I

I U
I E

t--

'

--T--

,

r; :-rh l

F

J I P

3la

F ielo Ndme

To

rll-El!

-

N I D

3

LI

t i
1

|+,

l

I

I

RPG

; P
= o
tl 6t

'ii-ri'r-l
0

6

,,I

3t14

a
6

E

rioir rlri I i
r

lndicators

!

I l;
- t! n" lt F
n

5

a

Freid Location

I

|::
F il€nafie

I

Field

ldentif ication Codes

T

|

Ti

-t
I

] L

i I

Lir
l.

1

lLl

rlaivJ
-A1r

CALCULATION SPECIFICATIONS
75 76 71 18 79 AD

Proe,am [fT-Tl-Tl
_

a lsigure 949.

Loading Array Data Consecutive on More Than One Recod (Model 6. Model 1O Di*

ldenriricanonl

I

I

I

I

ll

System. and Model 151

Arrays

945

tlrray Data Scattered on More Than One Record
llegardleso
s f h o w n r a n y r e c o r d sa r e u s e dt o c o n r a t n
array
c i a t a ,i f t h e f i e l d s a r e s c a t t e r e do n t h e r e c o r d s ,e a c h f i e l d
r n u s tb e i n d i v i d u a l l yl o a d e di n t o i t s a p p r o p r i a t ep o s i t i o n
in
t h e a r r a y . H o w e v e r ,a s e p a r a t es p e c i f i c a t i o ni s n o t a t w a y s
n e c e s s a r fyo r e a c hf i e l d o f d a t a t o b e l o a d e d . I n s o m e c a s e s ,
t h e s a n r es p e c i f i c a t i o nc a n b e u s e df o r a l l t h e r e c o r d s . T h i s
c e p e n d so n w h e t h e r a l l t h e i n p u t r e c o r c l sf o r a s i n g l ea r r a y
a r e o r g a n i z e di n t h e s a m ef o r m a t a n d w h e t h e r t h e f i e l d s
f r o m d i f f e r e n t r e c o r d sc a n b e a s s i g n e dt h e s a m en a m e .
l \ s s u m et h a t a 2 2 - e l e m e n ta r r a y , n a m e d A R A , i s d e f i n e d .
l ' h e d a t a f o r t h e a r r a y i s s c a t t e r e do n s i x i n p u t r e c o r d s ,a s
s h o w n i n F i g u r e9 - 5 0 . A l t h o u g h t h e a r r a v d a t a i s n o t c o n s r - ' c u t i v et h, e f o u r f i e l d s o n e a c ho f t h e f i r s t f i v e r e c o r d sa r e
i n t h e s a m ef o r m a t o n e a c h r e c o r d . T h e r e m a i n i n gt w o f i e l d s
o n t h e s i x t h r e c o r d a r e i n t h e s a m ef o r m a t a s t h e f i r s t t w o
f i e l d so n a l l o t h e r r e c o r d s .
S i n c et h e a r r a y d a t a f o l l o w s t h e s a m eo r g a n i z a t i o no n a l l
r o c o r d sd, e s c r i b i n g
o n e s e t o f f i e l d s( F i g u r eg - S 1 )a c t u a l l y
d e s c r i b e st h e f i e l d s o n a l l r e c o r d s ,e x c e p t t h e l a s t . A s e p a ' a t e i n p u t s p e c i fi c a t i o n s h o u l d b e c o d e d t o i n d i c a t et h a t
r e c o r d 6 o n l y c o n t a i n st w o o f t h e f i e l d s . ( N o t e o n t h e l n p u t s h e e tt h a t r e c o r d s1 - 5 a r e d e s c r i b e di n a n O R r e l a t i o n s h i p . T h e r e f o r e ,a s p e c i f i cc a r d s e q u e n c ec a n n o t b e s p e c i _
f i e d i n c o l u m n s 1 5 a r r d ' l 6 . y o u c a n a s s u m et h a t t h e a r r a - y
i r r p u t r e c o r d sa r e i n s e q u e n c e .R e c o r d t y p e 1 i s t h e f i r s t
r e r c o r dr e a d a n d r e c o r d t y p e 6 i s t h e l a s t . )

9rl6

l r . o t .l
, a o rIu

l.,-otu
I
Ir . o ,lt
I r.ot,

l'.o'l
r

lt,-orl

lt.o,

I r,-o.
I
| '.ooI
O r g a n i z e di n
Same Format

Frigure9-50. Array Data Scattered on More than One Record

Arrays

947

RPG INPUTSPECIFICATIONS
I81t,...",..,

t * I

Purch q

Figure 9-51. Describing One Sot of Array lnput Fields for Several Records

9.f8

G X 2 1 . S 9 4 U / M0 5 0 '

B.1nesMachnec.,..,d,.n
Cd.d El6cro Numb,

**[-fl"_',ix:L,
".[l-T[fTl

PaseoI GC21-7567-2
1979
lssued21 December
By TNL: GN21-5709
B e c a u s et h e f i e l d so n t h e d i f f e r e n t r e c o r d sh a v e t h e s a m e
f i e l d n a m e s ,o n l y o n e M O V E s p e c i f i c a t i o ni s n e c e s s a r yf o r

w a y , t h e v a l u e si n t h e i n d e x f i e l d s o n l y h a v et o b e c h a n g e d
e v e r y t i m e a n o t h e r a r r a y i n p u t r e c o r d i s p r o c e s s e d .W h e n

e a c h u n i q u e f i e l d n a m e . T h e s p e c i f i c a t i o no n l i n e 0 7 o f
F i g u r e9 - 5 2 , w h e n r e p e a t e df o r e a c h r e c o r d ,m o v e s F L D A

t h e f i r s t r e c o r d i s r e a d ,t h e i n d e x f i e l d s A , B , C , a n d D a r e
i n i t i a l i z e dt o 1 , 2 , 3 , a n d 4 , r e s p e c t i v e l yt o, p r e p a r ef o r
m o v i n g t h e t i e l d s f r o m r e c o r d t y p e 1 ( F i g u r e9 - 5 2 , l i n e s

o { t h a t r e c o r d t o t h e a p p r o p r i a t ee l e m e n to f t h e A R A a r r a y
Lines 09 and 10 are performed for every record except the

0 1 - 0 4 ) . A f t e r t h e f o u r f i e l d s a r e m o v e d ,t h e v a l u e 4 i s
a d d e d t o e a c h o f t h e i n d e x f i e l d ss o t h e y p o i n t t o w h e r e t h e
f o u r f i e l d s o n t h e n e x t r e c o r d s h o u l d b e s t o r e d ( F i g u r e9 - 5 2 ,
l i n e s 1 2 - 1 5 ) . T h e s a m ec a l c u l a t i o ns p e c i f i c a t i o n sa r e r e o e a t e du n t i l f i e l d s F L D A a n d F L D B f r o m t h e s i x t h r e c o r d
h a v eb e e n m o v e d t o t h e l a s t t w o a r r a v e l e m e n t s .

l a s t ,w h i c h d o e s n o t h a v ef i e l d s F L D C a n d F L D D .
S i n c et h e f i e l d s o n t h e i n p u t r e c o r d sa r e i n t h e s a m eo r d e r
a st h e y a r e t o b e s t o r e di n A R A , a d e f i n i t e p a t t e r n i s e s t a b l i s h e da s t o w h e r e t h e d a t a i s t o b e m o v e d . F i e l d sf r o n r r e c o r d 1 a r e s t o r e d i n a r r a y e l e m e n t so n e t h r o u g h f o u r , f i e l d s
f r o m r e c o r d 2 i n a r r a y e l e m e n t s5 t h r o u g h 8 , f i e l d s f r o m
r e c o r d 3 i n a r r a y e l e m e n t s9 t h r o u g h 1 2 , a n d s o o n .

Conditioning Operations Until All Array Data is Stored

A r r a y i n d e x f i e l d s c a n b e u s e dt o i n d i c a t et o w h i c h a r r a y
e l e m e n t st h a t d a t a i s t o b e m o v e d . F o r e a c h u n i q u e f i e l d
n a m e , a n i n d i v i d u a li n d e x f i e l d s h o u l d b e s e t u p . I n t h i s

RPG

A l l i n f o r m a t i o n m u s t b e s t o r e d i n a n a r r a y b e f o r ey o u c a n
r e f e r e n c et h e d a t a b y s p e c i f y i n gt h e a r r a y n a m e o r a r r a y
n a m e w i t h a n i n d e x . T h u s , a n y s p e c i f i c a t i o n st o l o a d t h e
d a t a i n t o t h e a r r a y m u s t b e s p e c i if e d b e f o r e a n y c a l c u l a t i o n s
which usethe arrav information-

CALCULATION SPECIFICATIONS
cJ;r;;';rlm

l

I

j

lii l

lr
ii
if

fi

il

iz
I

i
f

l

+
l

l

fi
Figure 9-52. Using the Same MOVE for Fields from Several Records

Arravs

949

F o r e v e r y r l . c o r d o f a r r a y d a t a , R P G l l g o e st h r o u g n a c o m p l e t e p r o g r a mc y c l e ,j u s t a s i t d o e s t o p r o c e s sa n y o t h e r d a t a
c a r d . T h i s m e a n st h a t i n p u t , c a l c u l a t i o n ,a n d o u t p u t s p e c i f i c a t i o n sc a n b e p e r f o r m r . ' de v e r y t i m e a n a r r a y i n p u t r e c o r d
i s p r o c e s s e d .Y o u w a n t i n p u t s p e c i if c a t i o n st o b e p e r f o r m e d
t o d e l ; c r i b et h e a r r a y r e c o r d t o t h e s y s t e ma n d , p e r h a p s ,t o
l o a d t h e a r r a y d a t a a t t h e s a m et i m e . P e r h a p sc, a l c u l a t i o n
s p e c i l i c a t i o n sw h i c h m o v e t h e d a t a f r o m t h e r e c o r d t o t h e
a r r a y s h o u l r Ja l s o b e p e r f o r m e d . H o w e v e r ,i f t h e r e a r e s t i l l
s o m e a r r a y r e c o r d sw h i c h h a v e n o t b e e n p r o c e s s e d( t h u s ,
n o t s l o r e d i n t h e a r r a y ) ,c a l c u l a t i o n sa n d o u t p u t w h i c h r e f e r e n c r t?h e a r r a y m u s t n o t b e p e r f o r m e d . F o r e x a m p l e ,i f
o n l y f i v e f i e r l c losf d a t a h a v e b e e n l o a d e d i n t o a 1 0 - e l e m e n t
a r r a y ,a d d i n ga l l e l e m e n t so f t h e a r r a y o r p r i n t i n ga l l e l e m e n t ! ;w i l l c e r t a i n l y n o t p r o v i d et h e r e s u l t sy o u w a n t .
O n c e t h e l a : ; ta r r a y i n p u t r e c o r d h a s b e e n s t o r e d ,a n y s p e c t f i c a t i o n sr e f e r e n c i n gt h e a r r a y e l e m e n t sc a n b e p e r f o r m e d .
T h u s , y o u m u s t s p e c i f ya c o n d i t i o n i n gi n d i c a t o r ( c o l u m n s
9 t h r o u g h 1 7 o n C a l c u l a t i o ns h e e ta n d c o l u m n s 2 3 t h r o u g h
3 1 o n O u t p u t s h e e t )w h i c h i n d i c a t e sw h e n t h e l a s t a r r a y
record has been processed.

L i n e s 0 2 t h r o u g h 1 3 o f t h e C a l c u l a t i o ns h e e t i n F i g u r eg - 5 3
a r e p e r f o r m e dt o m o v e d a t a f r o m t h e s i x a r r a y i n p u t r e c o r d s ( s e eF i g u r e9 - 5 0 ) i n t o t h e a r r a y A R A . W h e n t h e l a s t
r e c o r d i s p r o c e s s e d( r e c o r d i d e n t i f y i n g i n d i c a t o r 0 6 o n ) , t h e
t w o a r r a y o p e r a t i o n so n l i n e s i 6 a n d 1 7 c a n b e p e r f o r m e d
d u r i n g t h a t p r o g r a m c y c l e . T h e r e f o r e .w h e n r e c o r d t y p e 6
h a s b e e n s t o r e d ,i n d i c a t o r 3 3 i s s e t o n ( F i g u r e g - 5 3 , l i n e 1 4 ) .
I n d i c a t o r3 3 ( o r a n y o t h e r i n d i c a t o rw h i c h i s s e t o n l c a n
t h e n c o n d i t i o n t h e X F O O T a n d S U B o p e r a t i o n st o b e p e r f o r m e d i n a p r o g r a mc y c l e .
T h e r e c o r d i d e n t i f y i n g i n d i c a t o r 0 6 w a s n o t s p e c i f i e dt o
c o n d i t i o n t h e a r r a y o p e r a t i o n s ,b e c a u s e0 6 i s o n o n l y f o r
t h e c y c l e i n w h i c h t h e s i x t h a r r a y r e c o r d i s p r o c e s s e d .S i n c e
t h e a r r a y o p e r a t i o n so n l i n e s 1 6 a n d 1 7 m u s t b e p e r f o r m e d
i n t h e f o l l o w i n g p r o g r a m c y c l e sa l s o ( f o r e x a m p l e ,i f n o r m a l
d a t a r e c o r d sf o l l o w t h e a r r a y r e c o r d s ) ,t h e y m u s t b e c o n d i t i o n e d b y a n i n d i c a t o rw h i c h i s o n d u r i n g t h e f o l l o w i n g
c y c l e s . O n c e i n d i c a t o r 3 3 h a s b e e n s e t o n , i t r e m a r n so n
t h r o u g h f o l l o w i n g p r o g r a m c y c l e s ,u n t i l s e t o f f ( l i n e 0 1 )
w h e n a n o t h e r g r o u p o f a r r a y r e c o r d sa r e p r o c e s s e d .

RPG CALCULATION
SPECIFICATIONS

IBM ,

t.,",'.,.
i;:.,;,;;

if cl l ;r r,
I

I

I

.'l'-l-T

-*;;rtr'l
I ;; T;;.'-,
T I i j _i
Ll i l t - t
l
- ; . ; Er
- l -- - - TL::'::
- l - -llJr__i.,
--l--T1

-.-

I

-"."*;-

I

l:l.i I

I
An,

I

|I

I

|
i

fri,ill

I

I l:i:;F-'lJlTJl
l- Tl l-s'l Tlrl1-l ;
I

I l

I l'l
I'l'i
l".i'i
I l'i
l"l'l

,l

Orefdron

|I

I

I
I
iFflffil-

, , l ' . . t ' " 1 ' '. l ' . 1 ,' " . . 1. ?2 r) 4/ . , 0 , , 1 ,n"" o , ' , , 1 ., " , ,

laA ltl
,1, ErADdr
lALl I L,, i,r,,Er-nldda,
lt d, 6t rt l | | , , j . ; - H - A q $ ,i
l.l, ,.i,1',8-epDl'tl;,
I I'i'1,;
llt-hF{YElFi-D

l','l'l I.,l

,l.,l,;

r - . - - M D iIvFEI Li D

f " , F l ,[ , t g b )L, ] i , , ; l l ; ' " ,f s v l J l r - ] o 1

l ' " i " l l N g IAI l1 , , 1 ,- , 1 r ,i r , f l o v E " l F j l D
. ll l A , l l l f , h l d d - l r l ] ,
l ' ' L :,lr N g l a
l " l " l _ N pI { 6
I 1 B _ i . , _, t1 ; A l o o l l X i ,
L l ' l l N E;bf lt i , H I l l i f ' h D a; 1 1l l
l ' , l . Li,N E 6 i lI;ilD ; , ; _ , _ l, h o d l . {
l ' " ,l ' l l g . d r li . i J ! l , , l l t _ f _ - b Elr,O
_Nl
l ' ' ,l ' l *I l i lj lf ll lll ,l ll ,l ll l l * - l f l L l, , t l

ll illx,FOoEAtslA
l'"1'l i33l
i , i . l l J 3 : 1 , l A l R A o r ei ,.lFb li . t 4 d l M
l

F i g u r e 9 - 5 3 . C o n d i t i o n i n g O p e r a t i o n sU n t i l A l t A r r a y D a t a i s S t o r e d

9-50

**fl'

F i g u r e9 - 5 4s h o w sh o w t h e a r r a yo p e r a t i o nm
s u s tb e c o n d i t i o n e df o r a n o t h e rs i t u a t i o n .I n t h i s c a s er, e c o r di d e n t i f y i n g
r 3 b e c a u sien f o r m a i r r d i c a t o0r6 d o e sn o t s e to n i n d i c a t o 3
t i o n ( D S C N T f) r o m d a t ar e c o r d sf o l l o w i n gt h e a r r a yr e c o r d s
nrustbe availablebeforethe arrayoperationscan be perf o r m e d( l i n e1 6 ) . l f i n d i c a t o 0r 6 c a u s e di n d i c a t o 3
r 3 to be
s o to n . t h e a r r a yo p e r a t i o nws o u l db e p e r f o r r n ed u r i n gt h e
p r o g r a r cny c l ei n w h i c ht h e s i x t ha r r a yr e c o r di s s t o r e d .A t
t h a t p o i n t ,t h e D S C N Td a t ai s n o t a v a i l a b l eT. h e r e f o r er,e c r 9 ( t h ef i r s t t y p e o f d a t ac a r df o l o r d i d e n t i f y i n gi n d i c a t o 0
indicator
l o w i n gt h e a r r a yr e c o r d ss) e t so n t h e c o n d i t i o n i n g
33 instead.

RPG

A t t h i s p o i n t ,w e m u s t m e n t i o na p r o b l e mw h i c hc a nc o m e
up if arrayelementsarecontainedon morethan one record
(or the samerecordtypg), and the recordscontainnormal
input dataaswell asarraydata. Assumethreecardscon'
t a i n t h e a r r a yd a t aa n da r lt h e d a t am u s tb e s t o r e di n t h e
a r r a yp r i o rt o p e r f o r m i n ag n y c a l c u l a t i oonr o u t p u t o p e r a tions. This meansthe threerecordsmust be readbefore
processing.As eachnew record(of the samerecordtype)
is read.the datafrom the previousrecordis destroyed,unl e s si t h a sb e e nm o v e do r s t o r e di n a s p e c i apl l a c es, u c ha s
a n a r r a y . S i n c en o r m a li n p u td a t a( n o n a r r a fyi e l d s )f r o n r
t h e f i r s t t w o r e c o r d si s n o l o n g e ra v a i l a b loen c et h e t h i r d
r e c o r dh a sb e e nr e a d ,a n y c a l c u l a t i o on r o u t p u t s p e c i f i c a t i o n sw h i c h r e f e r e n cteh i s i n p u td a t am i g h tg i v ei n c o r r e c t
results.

CALCULATION SPECIFICATIONS
75 76 77 78 79 80

"*[I],

Proqram Tf l-Il-Tl
r d . , r : r , e aLrLol.. l _ 1

1 _.1

Resdlt Field

Fa.ro! 2

jr,1
0 i 5

i:+
Fi;
il;
n;

3
I

sl

,l

|

O 9 s e t o n b y r e a d i n gf i r s t d a t a
r e c o r df o l l o w i n ga r r a y i n p u t r e c o r d s . i

i i f i e t c to f d a t a o n t h e d a t a r e c o r d s w h i c h f o l l o w
I
input records.
l
! the
"rruy

'Figur" 9-54. Conditioning Operations Until All Array Data is Stored and lnput Data is Available

Arrays

9-51

9-!t2

Review9

l.

I n w h i c ho f t h e f o l l o w i n gw a y si s a n a r r a yl i k ea t a b l e( s t a t et r u e o r f a l s ea n dt h e
r e a s o nfso r y o u r a n s w e r ) ?
a. Eachcan be referenced
asone groupof information.
b . E a c hi s a c o n t i n u o u s e r i e o
s f d a t af i e l d s( e l e m e n t sslt o r e ds i d eb y s i d e .
c. A particularitem of datacan be individuallyreferenced
in eithera tableor an
atray.
d . E a c hi s d e f i n e db y c o d i n ge x t e n s i o n
specifications.

2.

Canone arraybe comparedto anotherarrayto determinewhich is greateror lessT
Statethe reasonfor your answer.

3.

Explainwhat happensif an array(a) of 18 elementsis addedto an array /b/ of three
elements,with the resultplacedin an array (c) of 18 elements.

4.

T h e f o l l o w i n ga r r a y( A R A S I X )i s t o b e s e tu p d u r i n ga p r o g r a mr u n :

I

a.
b.
c.
d.
e.

2

72

5

20

15

Definethe arrayon an Extensionsheet.
l f A R A S I X i s m u l t i p l i e db y 3 , w h a t d a t aw i l l b e p l a c e di n t h e r e s u l ta r r a yR E S A R A ?
Shouldthe resultarray RESARAbe definedon the Extensionsheetalso?
lf so,codethe necessary
extensionspecifications
to define RESARA,
What is accomplished
by definingan arrayon the Extensionsheet?

5.

a. Explainwhat happenswhen an XFOOT operationis performed.
b. lf ARASIX (referto question3) is specifiedon the Calculationsheetas Factor2
of an XFOOT operation.what datawould be placedin the resultfield?

6.

How doesa programmerspecifythat an entirearray is to be printedor punched(a)
duringoutput time in the objectprogramcycle;(b) at end of job?

7.

How doesa programmerspecifywhetheran entirearrayor only a particulararray
elementis to be operatedupon or usedfor outputT

Review 9

9-53

8.

D a t af o r a S A L E Sa r r a yi s r e c o r d e d
o n a o n e - r e c o ridn p u t f i l e c a l l e dI N F I L E i n t h e
f o l l o w i n gf o r m a t :
Field

Columns

Field

Columns

Clerkl
Clerk2
Clerk3
Clerk4
Clerk5

1-10
11.20
21.30
31-40
41-50

Clerk6
ClerkT
ClerkS
Clerkg
r e c o r dc o d e

51-bur
61-70
71-80
81.90
g 1 ( n o t a r r a yd a t a )

Eachc,fthe clerk fieldscontainsdatawith two decimalpositions.Codethe specificationsnecessary
to:
a. Define the arrayas a pre-execution
time array.
b. lf necessary,
describethe input recordand storethe data in the SALESarray.
9.

10.

Showtwo waysthat datafrom the first five fieldsof the followingrecordcould be
s t o r e di n a n e x e c u t i o nt i m e a r r a yn a m e dS E T ( 1 5 e l e m e n t st h
, r e en u m e r i cc h a r a c t e r s
each,no decimalpositions).Column 1 of the recordcontainsa P asthe record
i d e n t i f y i n gc o d e .

F ielcl

Columns

Frdl
Ftd2
F rd3
F td4
Ftds

2-4
6-8
1G12
14-16
18-20

F reld

Ftd6
FtdT
FtdS
Ftd9
Ftd10

Columns

Field

Columns

22-24
26-28
3G32
34-36
38-40

Ftd1l
Ftdl2
Frdl3
Ftdl4
Ftdl5

42-44
46-48
5G52
54-56
58-60

a. Code the output specificationsto print the 13th element of the array SET
( o u t p u t f i l e n a m e P RI N T ) .
b . C o d e t h e s p e c i f i c a t i o n st o p r i n t t h e e n t i r e a r r a y S E T a t e n d o f j o b ( o u t p u t
f i l e n a m eP R I N T ) .

1 1 . S E A R C H i s t h e n a m e o f a f i e l d c o n t a i n i n gd a t a y o u w i s h t o l o c a t e i n t h e & e l e m e n t
PAY array. Code the specificationsto searchthe array to determine if the data is
present. lf present. print the number and contents of the array element. lf more
than one array element satisfiesthe search,each is to be printed.

12.

9-54

Code specificationsto:
a . A d d A R A I t o A R A 2 a n d p l a c et h e r e s u l t i n A R A 2 .
b . S u m a l l e l e m e n t so f A R A 2 a n d p l a c et h e r e s u l t i n T O T A L .
c. Print both results.

AnswersTo Review9

1.

a . F a l s e .O n l y o n et a b l ee l e m e nct a n b e r e f e r e n c eadt o n e t i m e .
b. True.

True.
d . True.

2.

N o . A n o p e r a t i o n t o b e p e r f o r m e d o n a n a r r a y i s r e p e a t e df o r e a c h e l e m e n t i n t h e
a r r a y . T h e r e f o r e ,a c o m p a r e ( C O M P ) o p e r a t i o n c a n n o t g i v e a m e a n i n g f u lr e s u l t f o r
t h e e n t i r e a r r a y . T h e t w o a r r a y s ,h o w e v e r ,c o u l d b e t o t a l e d u s i n gt h e X F O O T
o p e r a t i o n a n d t h e r e s u l t i n gt o t a l s c o u l d b e c o m p a r e d .

3.

T h e f i r s t t h r e e e l e m e n t so f a r r a y a w o u l d b e a d d e d t o t h e t h r e e e l e m e n t so l a r r a yb ,
w i t h t h e t h r e e r e s u l t sp l a c e di n t h e f i r s t t h r e e e l e m e n t so f a r r a y c . T h e r e m a i n i n g
1 5 e i e m e n t so f a r r a y c ( r e s u l ta r r a y ) r e m a i n u n c h a n g e d .

4.

a . E n t r i e ss h o w n a r e r e q u i r e d ;n o o t h e r e n t r i e ss h o u l d b e m a d e . T h e e n t r y i n
c o l u m n 4 4 i s n e c e s s a r tyo i n d i c a t et h e e l e m e n t sa r e n u m e r i c f o r a r i t h m e t i c
operatrons.
E x t e n s i o nS p e c i fi c a t i o n s

b.
o

216

15

60

45

c . Y e s , a l l a r r a y st o b e u s e d i n a p r o g r a m m u s t b e d e f i n e d o n t h e E x t e n s i o ns h e e t .
d . E n t r i e ss h o w n a r e r e q u i r e d ;n o o t h e r e n t r i e ss h o u l d b e m a d e . L e n g t h o f a r r a y
e l e m e n t ( c o l u m n s 4 0 - 4 2 1m u s t b e 3 t o c o n t a i n t h e l a r g e s ta d d i t i o n r e s u l t .
E x t e n s i o nS p e c i { i c a t i o n s

e . A n a r e a i n s t o r a g es u f f i c i e n tt o c o n t a i n t h e a r r a y d a t a i s r e s e r v e d .T h e a c t u a l
a r r a y d a t a m a y b e s t o r e d i n t h e a r r a y l a t e r ,w h e n i n p u t r e c o r d sa r e r e a d o r
d u r i n gc a l c u l a t i o n s .
A n s w e r sT o R e v i e w I

9-55

P a g eo f G C 2 1- 7 i 6 7 - 2
l s s u e ( l2 4 f v l a y 1 9 7 6
8y ThlL: cN21-b389

a. TheXFoor operation
c a u s easi l e r e m e n tisn t h e a r r a ys p e c i f i e d

a s F a c t o r2 t o b e
a d d e dt o g e t h e r .T h e s i n g r er e s u r ot f t h e a d d i t i o n si s p r a c e d
i n t h e r e s u l tf i e r d
s p e c i f i ew
d i t h t h e X F O O To p e r a t i o n .
b . T h e t o t a l o f a l l e l e m e n t isn t h e A R A S I X
a r r a v( 1 1 5 )w o u l d b e p l a c e di n t n e
r e s u lft i e l d .
o.

a . T h e n a m e o f t h e a r r a y i s s p e c i f i e du n d e r F i e l o N a m e( c o l u m n s
3 2 t h r o u g h3 7 )
o n t h e O u t p u t s h e e t . T h e f i l e n a m e( c o l u m n s7
t h r o u g h1 4 ) m u s ta l s ob e s p e c i f i e d ,
asfor output of anVf ield.
b . T h e n a m e o f t h e o u t p u t f i l e i s s p e c i f i e du n d e r
T o F i l e n a m e( c o l u m n s i 9 - 2 6 ) o n
t h e E x t e n s i o ns h e e t . N o e n t r y i s n e c e s s a r yo n
the Output sheet. (This method
o f a r r a y o u t p u t c a n n o t b e u s e c fl o r e x e c u t i o n
time arravs.)

7.

1 - h ea r r a y n a m e i s s p e c i f i e da l o n e ( o n t h e C a l c u l a t i o n
o r O u t p u t s h e e t )t o r e f e r e n c e
the entirearray. The array name must be followeci
by a comma and an index
n u m b e r o r i n d e x f i e l d t o r e f e r e n c eo n l y a p a r t i c u l a r
arravelement.
a . E x t e n s i o ns p e c i f i c a t i o n st o d e f i n e t h e a r r a v :

E x t e n s i o nS p e c i fi c a t i o n s

b . I n p u t s p e c i f i c a t i o n st o d e s c r i b et h e i n p u t r e c o r d
a n d s t o r et h e d a t a i n t h e s A L E S
a r r a y a r e n o t n e c e s s a r ys, i n c et h e a r r a y i s a u t o m a t i c a i l y
r o a d e db e f o r e e x e c u t r o n
of the program.
F i r s tm e t h o d :

RPG
f

lrr':

I
I
I
I
I
I

' i li

r

l ' , ', ', ,un ', ",l ",

I

INPUTSPECIFICATIONS
-

I

'

t'i l lll

I

r ll

)

2

t u *- TL'lt l " '

:rNP.UT.
r

L

i

- l i l
- + r

j

l
T

9-56

S e c o n dm e t h o d :

RPG INPUTSPECIFICATIONS
IBM,",",^",,,,".,

co.oo,.,on
",,n.$Ma.h.,

I

9

RPG

CALCULATIONSPECIFICATIONS

1 0 . a . O u t p u to f 1 3 t he l e m e not f S E Ta r r a v :

GX2lsm

SPECIFICATIONS
IBIII

.,".".,"""

U/M0$.

a u ! i e s M a c h , ec o r b o , a , . i

_

Proqram fT-T-T-fTl
rdenr,r
csronLL
I I

I

I

I

in

Constant ur Edit \tr/ord

I 1r
lr
1

T

I

I

I

l

Answers To Review 9

9-57

b . O u t p u to f e n t i r eS E Ta r r a ya t e n d o f j o b s i n c eS E T i s a n e x e c u t i o nt i m e a r r a y ,
m u s tb e d o n eu s i n go u t p u ts p e c i f i c a t i o nass,s h o w nb e l o w :

OUTPUT
.,",,.,...

Illll

",,,^.$

U/MOS'

GX21.m

SPECIFICATIONS

M.ch,n.
co',o,,non
Card Electo Num&r

Graphic

I o""

**lii'_
No Siqn

CB
Prus Sign
B
c
D

L

l f S E Tw e r ea c o m p i l et i m e a r r a yo r a p r e - e x e c u t i ot inm e a r r a y ,o u t p u t o f t h e
e n t i r ea r r a yc o u l db e a c c o m p l i s h ebdy e n t e r i n gt h e o u t p u t f i l e n a m ei n T o F i l e n a m e( c o l u m n s1 9 - 2 6 )i n t h e e x t e n s i o n
s p e c i f i c a t i ofno r t h e a r r a y :

RPG EXTENSION
A N D L I N EC O U N T E R
SPECIFICATIONS
Punch

fs

Gceh

C a r d E L e d r oN u m & r

c

]

Fo.m X2t Sl
pi,nr.d'nUSA

**ffi"-

75

76

?7

ldenr,tcauonl

I

|

|

E x t e n s i o nS p e c i fi c a t i o n s

E

Sequence oi the Chaining

Frle

To Filename

T a b l eo r
Arrav Nam€

Table or
Array Name

Commenls
Enrry

Enrry

n
92421222324252t

0
0

(

,:

9-5,8

1I
iE

n

ta 59 60 61 6?

I

1

63 64

65 66

67 68 69

70

79

78

Proq'am fm-T-T_T_]

71 72

I

80

|

|

11.

C A L C UL A T I O NS P E CFI I C A T I O N S

F o / mG X 2 r . S !
Pnnrd i6 U S.A.

_

r r q r a
rden"rril,oil

75 76 17 7A rg 80
m t t t t t t l
I

SPECIFTCATIONS
I811

,.,",".,,...,
",,,.e$

I D"p

|

|

|

|

Gx2t.ffi
U/M @.
Pnn$d tn u.s A.

M.chneco.Do,.,o^
C a r d E l e c t r oN u m e r

P,oe.anrc,

|

**[i'],_

75 76 77 78 79 80

f ' q , . t mt t t t t l
idenririLarlohl

I

I

I

|

|

|

Constant or Edlt Word

Answers To Review I

9-59

12,

RPG CALCULATIONSPECIFICATIONS
IBlll,'"."-r.-,m

ForBGX2l.m
Prinrd

&rd

Graohic

Elero

'."fi1n-ftq.m

Numbf

l&^tir'olionl

I orr.

(:

Indlcrton

t6 76 t7 78 70 t0

[-TT-T-T-T-]
|

|

|

|

|

R6ull Fi.ld

l'
a ,

t ,t :

r.i* li

Frtor

I

F&tor 2

Orration

Commant!
Llngth

N!6a

6 c

!:

t

l>2ll<2ll-?
.@lurlFrcrq 2li

m:m

,

Gt2r.s

SPECIFICATIONS
IEII,.",".,.-,

cd,.. c@..rd
"""n.{
&rd

Grrphic

El*to

Numbl

I orrr

I2

s{p

a

I

outpur lhdicstori

ffiE@ltr@F

rtTlsls[]-l[J]-[il

Fi6ld N.me

Fil.name

9€l)

'. U.3,4

Mdid coe,.rio

l

l

A

d

r

L

.AUTO

--n
E n d
Porilon
in
oupr
aro'a

l l
| |
l-l
l5l
lEl

Z.ro 8.lMc6

{o Sis
I
2

CR
J

I
c

K
L

Conltsnt or Edit Word

z

Plur Sien
D.t!
Fi.H €dn
Za.o

u/r @.

I

Chapter 10. Working With Data Structure

C H A P T E R1 OD E S C R I B E S :
Representationof characterson cards.
Representationof charactersin storage(disk and insidethe computerl.
Packedand binarydata.
Collatingsequence
of characters.
Movezoneoperations.
F i l et r a n s l a t i o n .

A F T E R R E A D I N GT H I S C H A P T E RY O U S H O U L DB E A B L E T O :
Describethe representationof charactersand negntivenumberson clrds.
Describethe representationof characterson disk and inride the computer.
Definebyte, bit, zoneportion and digit portion.
Comparethe storingof characterson oards.tothe storingof character3in storage.
ldentify bit combinationswith numericalvalues.
Asign numericalvaluesto zoneand digit portion!.
Define unpackeddecimalformat, packeddecimalformat, and binary format.
Describethe hexadecimal
numberingsystem.
Describethe collatingsequenceof characters.
Codespecificationsto changethe collatingsequence.
Alter the structureof charactersin storageby usingmove zone oporttiong.
Translatecharactersby codingthe TranslationTable and Alternate CollatingSheet.
Note: You can usethe reviewquestionscontainedln BeYiav tO rt the end of this
chapterto test your comprehensionof eachtopic in the chrptor. Ouestionsaro
groupedaccordingto the topic to which they apply. Aruwer follow tho rsview
questions.

Wakine With DataStructure

l(}l

CHARACTER STRUCTURE

S i n c et h e r e a r e s i x p u n c h p o s i t i o n sa v a i l a b l e t, h e n u m b e r
a n d p o s i t i o n so f t h e h o l e s m a y b e v a r i e d t o f o r m 6 4 d i f f e r e n t p u r r c hc o m b i n a t i o n s . E a c h u n i q u e c o m b i n a t i o n o f
p u n c h e si s a s s o c i a t e dw i t h a p a r t i c u l a rc h a r a c t e r .T h e r e fore, you can represena
t ny one of 64 differentcharacters
i r r a c a r d c o l u m n ( F i g u r e1 0 - 1 ) .

flepresentationof Characterson 96-Golumn Cards
F r u n c h e dc a r d sp r o v i d e d a t a t h e c o m p u t e r i s t o w o r k w i t h .
E a c h o f t h e 9 6 c o l u r n n so f a c a r d c a n c o n t a i n p u n c h e sf o r a
s i n g l ec h a r a c t e r .T h e r e f o r e ,u p t o 9 6 c h a r a c t e r so f i n f o r n r a t i o n c a n b e r e p r e s e n t e do n a s i n g l er e c o r d .

A c a r d c o l u m n c o n s i s t so f b o t h a z o n e p o r t i o n a n d a d i g i t
p o r t i o n . B a n d A a r e r e f e r r e dt o a s z o n e p u n c h p o s i t i o n s ,
while 8, 4,2, and / aredigit punch positions.The comb i n a t i o n so f z o n e a n d d i g i t p u n c h e sm a k e i t p o s s i b l et o
s e p a r a t et h e c h a r a c t e r si n t o t h r e e g r o u p s ( F i g u r e 10 - 1) :

E l a c hc o l u m n o f a c a r d c o n s i s t so f s i x p u n c h p o s i t i o n s ,
liabeledB, A, 8, 4, 2, and l, fromthe top of a column to
t h e b o t t o m . C h a r a c t e r sa r e r e p r e s e n t e db y a c o m b i n a t i o n
o f f r o m z e r o t o s i x h o l e s p u n c h e d i n t h e p u n c h p o s i t i o n so f

a A l p h a b e t i c l e t t e r sa r e r e p r e s e n t e db y a t l e a s to n e p u n c h
i n b o t h t h e z o n e a n d d i g i t p o r t i o n so f a c o l u m n .

a s i n q l ec o l u m n .

T h e 2 8 s p e c i a lc h a r a c t e r sc a n c o n s i s to f n o p u n c h e s ,
o n l y z o n e p u n c h e s ,o n l y d i g i t p u n c h e s ,o r b o t h z o n e
and digit punches.
a

Numeric Characters

0 t

2 3 4

5 6

7 B l 9

I

Tona

P o s i t i v en u m b e r sa r e r e p r e s e n t e db y h o l e so n l y i n t h e
digit punch positions. The one exceptionis the number
O w h i c h i s r e p r e s e n t e db y a s i n g l ep u n c h i n t h e 4 z o n e
punch position.

A

Punch
Positions

I

I
4 4

4
Digir

2

2 2

1

1

4

I

4

2 2

1

1

1

Special Characters

Zone

]

cl.l<

A

ra-fafe B
n l n f eA

B
A

I

P un c h
Positions

4
Digit

z
1

I

l4

z l zI

4

I

&

$

A

A

8 I
4 4
2 2

I r l

I

8 I
2 2
1

8 I
4 4

8 8
4

4

2

2
1

A
I

1

A

A

A

I

8 I

4

2 2
1

| + l o l '| =

o/

4

4

4

2 2
1
t

v

l l t t
Ft44 4

i { e l a l e l a8

z l z l I l z 'z
I r l l t l

tffi,i F i g u r e10 - 1 . C h a r a c t e rS e t a n d P u n c h C o m b i n a t i o n s

10-2

Representationof Negative Numbers

CHARACTERS

Note that positive numbers are representedonly by digit
p u n c h e s . N e g a t i v en u m b e r s ( - / t h r o u g h - 9 a n d _ 0 ) c a n
alsrobe representedto the computer. However, to indicate
t h a t a n u m b e r i s n e g a t i v e a, c o l u m n m u s t c o n t a i n b o t h t h e
p u n c h c o m b i n a t i o nf o r t h e n u m b e r a n d t h e p u n c h c o m -

Punch
Position

-l

-6

-J

-8

-9

-0

o

a

a

B

bination for the minussign. As column 7 of Figure l0_2
s h o w s ,t h e 8 a n d / d i g i t - p u n c hp o s i t i o n sa r e p u n c h e dt o
r e p r e s e n t h e n u m b e r 9 . A - 9 i s r e p r e s e n t e di n c o l u m n 1 2
b y t h e s a m ed i g i t p u n c h e sp l u s a h o l e i n t h e B z o n e - p u n c h
position.
A s m e n t i o n e d ,a l l 6 4 p o s s i b l ep u n c h c o m b i n a t i o n sa r e a s .
s o c i a t e dw i t h a c h a r a c t e r .T h e r e f o r e ,a d d i n g a g z o n e p u n c h
t o t h e p u n c h c o m b i n a t i o n o f a n u m b e r m e a n st h e p u n c h
c o m b i n a t i o n f o r a n y n e g a t i v en u m b e r i s t h e s a m ea s t h e
p u n c h c o m b i n a t i o n a l r e a d ya s s i g n e dt o o n e o f t h e 6 4 c h a r -

Punch
P o s i t i on
a

a

a

a

a

a
a
a

T h e R P G l l p r o g r a md e t e r m i n e sw h e t h e r t h e p u n c h c o m _
b i n a t i o n i s a l e t t e r o r a n u m b e r a c c o r d i n gt o w h e t h e r a n
e n t r y h a s b e e nm a d e i n c o l u m n 5 2 o f t h e i n p u t s p e c i f i c a _
t i o n s . C o l u m n 5 2 i s u s e dt o s p e c i f yt h e n u m b e r o f d e c i m a l
p o r ; i t i o n si n a f i e l d . l f a n e n t r y i s p r e s e n t ,t h e R p G l l p r o -

a

a

a c l . e r s .T h e n e g a t i v en u m b e r s- / t h r o u g h - 9 a r e r e p r e s e n t e d
b y t h e s a m ep u n c h c o m b i n a t i o n sa s t h e l e t t e r sJ t h r o u g h R ;
- 0 h a s t h e s a m ep u n c h c o m b i n a t i o n a s
t h e s p e c i a lc h a r a c ter I
y'y'ofeA
: l t h o u g h t h e v a l u e- 0 ( n e g a t i v e
z e r o ) i s n o t u s e db y
i t s e l f ,i t c a n e x i s t a s a p u n c h c o m b i n a t i o n i n t h e u n i t s
p o : ; i t i o no f a d a t a f i e l d .

a

o

a

a
a

a

o

a

a

a
a

o

a

F i g u r e 1 O - 3 . N e g a t i v eN u m b e r P u n c h C o m b i n a t i o n st h e S a m e a s
Punch Combinatiors for J-R

g r a m a s s u m e sa n y c h a r a c t e ri n t h a t f i e l d t o b e n u m e r i c . A b
s e n c eo f a n e n t r y i n c o l u m n 5 2 t e l l s t h e R p G l l p r o g r a m
t h a t i t i s r e a d i n ge i t h e r a l e t t e r o r a s p e c i a lc h a r a c t e ri n a n

P o s i t i v e9

Neg6tive 9 Character
( P r i n t sa s " R " )

D i g i t P un c h e s
On y for Positive
Nurnber

"8" Punchfor MinusSign
2
B

Digit Punchesfor Number

a
2

F i g u r e 1 0 - 2 , P u n c h e sf o r N e g a t i v eN u m b e r s

Working With Data Structure

10-3

a l p h a m e r ifci e l d . B y e x a m i n i n cgo l u m n5 2 , t h e R P Gl l p r o with
gramrecognizes
when the I zonepunchis associated
J
l
e
t
t
e
r
s
t
h
r
o
u
g
hi 9 o r
p
u
n
c
h
o
f
t
h
e
o
f
o
n
e
combination
the
p
u
n
c
h
n
u
m
b
e
r
.
n
e
g
a
t
i
v
e
o
f
a
combination
the
I n t h e d i s c u s s i osno f a r , y o u h a v el e a r n e dh o w d a t ai s r e c o r d e di n a f o r m w h i c ht h e c o m p u t e cr a n u n d e r s t a n dT. h e
as punchedholeson 96-columncards.
datais represented
p
B e f o r et h e R P Gl l r o g r a mc a nu s et h e d a t a ,a si n c a l c u l a '
tions or output operations,it must stbrethe information.
T h e d a t ai s t h e na v a i l a b lien c o m p u t e sr t o r a g ew h e n e v eirt
i s n e e d e d u r i n gt h e r u n o f a p r o g r a m .

in Storage
of Characters
Representation
W h e ny o u l o o k a t t h e p u n c ha r e ao f a c a r d ,y o u c a n n o t
e h i c hc h a r a c t e rasr es t o r e do n t h e
i m m e d i a t e ldVe t e r m i n w
y
o
u
w h i c hc h a r a c t eirs a s '
h
a
v
e
t
o
determine
card. First,
p
u
n
c
h
p
a
r
t
i
c
u
l
a
r
c
o
m b i n a t i o nT
. hepunched
w
i
t
h
a
sociated
h o l e st,h e n ,a r et h e m e a n so f r e p r e s e n t i ncgh a r a c t e rosn a
c a r d . S i m i l a r l ya, c h a r a c t esru c ha st h e l e t t e rA i s n o t s t o r e d
o n d i s ko r i n s i d et h e c o m p u t e ri n a f o r m y o u w o u l d r e c o g n i z ea st h e l e t t e rA . O n d i s ko r i n s i d et h e c o m p u t e rt,h e r e
i s a l s oa m e a n so f r e p r e s e n t i ncgh a r a c t e r s .
l n f o r m a t i o nf r o m e a c ho f t h e 9 6 c o l u m n so f p u n c h e dc a r d s
can be transferredto disk. Datafrom eachcolumnis stored
s n d i s ki n t h e f o r m o f m a g n e t i z e d
i n c o r r e s p o n d i npgo s i t i o n o
spots.
electronicallyin computerstorage.
are represented
Characters
The storageareaof the computerconsistsof a numberof
an
magneticbits, which can be turnedon or off by passing
e l e c t r i cc u r r e n t h r o u g ht h e m . T h e e x a c td e t a i l so f h o w t h i s
n ;h a t i s i m p o r t a n t
i s d o n ei s n o t i m p o r t a n t o t h i s d i s c u s s i o w
is that eachbit can be in eitheran on stateor an off state.
t sb i t
W e u s ea / t o s h o wa b i t t h a t i s o n ; w h i l e a 0 r e p r e s e n a
(
F
i
g
u
r
e
1
0
4
)
.
o
f
f
i
s
that

"off"

0

1

0

1

1

0

0

1

1

0

The magneticbits insidethe computeror on disk arearrangedin groups,calledbytes,just asthe punchpositions
on a cardarearrangedin groupscalledcolumns(Figure
1 0 - 4 ) .J u s t a se a c hc o l u m no n a c a r dC a nc o n t a i na c h a r a c ter, eachbyte in storagecan alsocontaina character.A
particularcombinationof on and off bits in a byte represent
a certaincharacterinsidethe computer,just asa particular
p o s i t i o n isn a c o l combinatioo
n f p u n c h e da n d u n p u n c h e d
that characteron a card.
umn represent
on a card,characterby character;likeDatais represented
wise,data is storedinsidethe computer,characterby character. Just as you can look at a punchedcardand referto a
characterby the particularcolumncontainingthat characa
ter's punchcombination,the computercan reference
characterby the particularbyte in storagewhich contains
that character's
bit combination.

DifferenceBetweenCharacterRepresentationon Cards
and in Storage
A l t h o u g ht h e r ea r em a n ys i m i l a r i t i eisn t h e w a y a c h a r a c t e r
in storageand on a punchedcard.it is imis represented
portantto note one difference.Whilea cardcolumnconsistsof six positions,a byte consistsof eightpositionsor
bits. Thus,within the computer,eight positionsare used
to representa singlecharacter,whereasonly six positions
a r ea v a i l a b loen a c a r d .
A byte is dividedinto a zoneportion and a digit portion,
i u s ta sa c a r dc o l u m ni s ( F i g u r e1 0 - 5 ) .T h e f o u r d i g i t p o s i t i o n s ,i n b o t h a b y t ea n d a c o l u m n ,a r e l a b e l e d1 , 2 , 4 , a n d
8. However,a byte containsfour zonepositions,whereas
a c a r dc o l u m nc o n t a i n so n l y t w o z o n ep o s i t i o n s .

bit

1

1

0

0

--Byte 1
(Containing
Bit Combination
for a SingleCharacter)

Figure 10-4. Representation of Characters in Storage

1

1

1 1 0 1 0 1 1 0

N

Zione

P'ortion

{

i

&!r!2s3s.

i

r

e

f,L:l

8

D,igit i 4
(;

l

o

q

2

P,crtion

z

I

',',.o.,u.u..n l
B
a
2
.o,,,.",,.",,"1
rtt 37@

BYTE

1 1 6 t t , O1 O t l ,

6 t

1 a g 1 1

8 4 2 1 a 4 2 1

'-,-/\--v-

Zone
Portion

Digit
portion

Figrrre 1O-5. Correspondenc€ Betwe€n a Byt€ and a Card Column

W o r k i n gW i t h D a t a S t r u c t u r e

10-5

S i n c e t h e r e a r e f o u r d i g i t p o s i t i o n si n b o t n a b y t e a n d a
c a r d c o l u m n , t h e d i g i t p o r t i o n o f a b y t e c o r r e s p o n d so n e f o r - o n e w i t h t h e d i g i t p o r t i o n o f t h a t c h a r a c t e r ' sp u n c h
combination. That is. if a digit punch positionis punched,
t h e c o r r e s p o n d i n gd i g i t b i t i s s e t o n ( 7) i n s t o r a g e . L i k e w i s e a d i g i t b i t i s s e t o t t ( 0 ) i f t h e c o r r e s p o n d i n gp u n c h p o s i -

S i n c et h e z o n e p o r t i o n s d i f f e r , a t r a n s l a t i o nt a k e s p l a c e
w h e n a c a r d i s r e a d a n d t h e d a t a ( c h a r a c t e r si)s s t o r e d i n s i d e
t h e c o m p u t e r . T h e m a c h i n e r e a d st h e p u n c h c o m b i n a t i o n
o n t h e c a r d a n d e l e c t r o n i c a l l yp r o d u c e st h e a p p r o p r i a t eb i t
c o m b i n a t i o n si n s t o r a g e . S u c h t r a n s l a t i o n s( s h o w n i n F i g u r e 1 0 - 7 ) a r e a u t o m a t i c ; t h e r e f o r e ,y o u n e e d n o t b e c o n -

t i o n d o e sn o t c o n t a i n a p u n c h . T o c h e c kt h i s , n o t e h o w t h e
d i g i t p o r t i o n o f t h e p l u s s i g n ( + ) c h a r a c t e ri s r e p r e s e n t e do n
a c a r d a n d i n s t o r a g e( F i g u r e 1 0 - 6 ) . ( / V o t e : A m p e r s a n d ( & )

c e r n e dw i t h h o w t h e c o m p u t e r k n o w s w h i c h b i t s t o t u r n o n

i s a n e x c e p t i o nt o t h i s r u l e ; s e e F i g u r e i 0 - 7 . 1

W h e n p r o g r a m m i n gi n R P G l l , h o w e v e r ,y o u d o h a v et o b e
c o n c e r n e dw i t h z o n e sa n d d i g i t s a s t h e y a r e r e p r e s e n t e di n s i d et h e c o m p u t e r . T h e d i v i s i o no f t h e c a r d c o l u m n i n t o
z o n ea n d d i g i t p o r t i o n s i s o n l y f o r c o n v e n i e n c e .

and off.

T h e z o n e p o r t i o n so f a c a r d c o l u m n a n d a b y t e d o n o t c o r respond one-to-one,however. This is becausethere are four
z o n e b i t s i n s t o r a g ef o r e a c hc h a r a c t e r ,w h i l e t h e r e a r e o n l y
t w o z o n e p o s i t i o n si n a c a r d c o l u m n . L o o k i n g a t F i g u r e
1 0 - 6 a g a i n ,y o u c a n s e et h a t e v e nt h o u g h 4 a n d I p u n c h
p o s i t i o n sc o n t a i n p u n c h e sf o r t h e p l u s s i g n c h a r a c t e r ,t h e

O n t h e I n p u t s h e e t ,y o u c a n s p e c i f y r e c o r d i d e n t i fi c a t i o n
c o d e s . l f y o u c h o o s et o u s e o n l y t h e z o n e p o r t i o n o f a
c h a r a c t e r ,y o u w i l l b e u s i n gt h e z o n e p o s i t i o n sa s t h e y a r e
i n s t o r a g e . A s s u m et h a t a r e c o r d i d e n t i fi c a t i o n c o d e w i t h

2 and 1 zone bits in storageare not on.

B
A
8
4
2
1

Bit
Position

o

1

o

o l r

8

4

2

1

1

-.-/"--v_\-=

Zone
Portion

Figure 1G6. Similarity in Digit Portion of Byte and Card Column

'I

0-6

1

o

B
A
a
4
2
1

p

B

A

A

8
4
2
t
B

8
4
2
1
B

Column 5 of the card
Punch
Position

'
.
a
4
a

P un c h
Combination

Bir
C om b i n a t i on

Character
Zon

Digit

B A 8 4

Zone

D igit

0 10 0

0000

o

0 10 0

1010

o o

0 10 0

1 0 11

I
(blank)

_ + _

a a a

o o

O
( p e r i od )

o a a a

(

a o o o

+

O
O

--l

o

o o o a o

o
$

0 10 0

a o o a

o a

&

o

o

o

a

O

O

a a

a

a a o

o

11 0 1

0 10 0

1110

0 10 0

0 10 1

o o
O

0 10 1
0 10 1

a

o o o o

o

1100

0 10 0

0 10 1

a

O

1111

1 0 11
11 0 0
11 0 1

0 10 1

1110

0 11 0

1111

0000

O

o o
%

a o

o a o
O

O

a

o

I

@

o o

B

o a
a o

n

o o

o

E

o o

a

F

o c

u

a o

H

a

3

o

a

O

o

) or-0

0011

11 0 0

0100

a

1100

0 10 1

a a

1100

0 11 0

a a o

1100

0 11 1

1100

x000

1100

1001

11 0 1

0000

1 t0 1

0001

o

0010

Lor-3

o

o a

1101

oOt1

Mor-4

o

o

1101

0100

Nor-5

o

o

a

1101

0101

Oor-6

a

o o

1101

0 11 0

Por-7

o

a a o

11 0 1

0 11 1

1101

1000

o

1101

1001

a

1110

o010

a a

1110

0011

1110

0100

o

1110

0101

Oor-8

o

o

0110

1 0 11

Ror-9

o

a

0 11 0

1100

S

o

0 11 0

11 0 1

I

o

U

o

o

a

o

W

a

a o

1110

0 11 0

X

o

o a a

1110

0 11 1

1110

1000

1110

1001

1111

0000

1111

0001

1110

0 11 0

1111

1 10 0

z

o o

0 1 11

11 0 1

+0

o

0 11 1

1110

O

1100

11 0 1

0 11 1

O

o o

a

1 0 11

o

0010

a

0 11 1

O

1100

Kor-2

a o

a o o

o

a

a

(apostrophe)

m01

a

1010

o

1100

o a

0 11 1

a o

Digit

Jor-l

o
o

Zone

a

o

O

2

o001

0 11 0

o a o o

8

A

A

Bit
Combination

Digit

0 11 0

tlunderscorel
o a o o

Zone
o

1010

0 10 1

0 10 1

Ch a r a c t e r

0000

lminus)

o

P un c h
Cornbination

0 11 1

1111

a a
a

o
2

a

J

t

4

a

5

o

b

a o
I

8

a

I

a

o

a

a a

O

1111

0010

1111

0011

1111

0100

H11

0101

1111

0 11 0

1111

0 11 1

1111

1000

1111

1001

F i g u r e 1 O - 7 . B i t a n d P u n c h C o m b i n a t i o n sf o r C h a r a c t e r s

W o r k i n gW i t h D a t a S t r u c t u r e

1O-7

the zoneof a $ characterin column / is to turn on resulti n gi n d i c a t o 2
r 1. l t a n i n p u tr e c o r di s r e a dw i t h t h e c h a r a c t e r J i n c o l u m n7 , i n d i c a t o 2
r 1 will not turn on. Even
thoughthe card zonepunchesfor $ andJ arethe same(both
havethe B zonepunched),the bit combinationsin storage
f o r t h e $ a n dJ d o n o t h a v ei d e n t i c azl o n ep o r t i o n s( F i g u r e
10-8).

Z O N E P O R T I O N SO F C A R D

IN STORAGE
Z O N EP O R T I O N S
P u n c h C o m b i n a t i o n f o r C h a r a c t e r$

$

B o

-E'

8

a

8

a
1 a
B

2
j

2

2

a

I

B

Bit Combination for Character lB

a

a

1

2
1

B15r7rar9
IBX37S

Zone
Portions
Differ

Zone
Punches
Id e n t i c a l

Bit Combination for Character J

r l s s

P u n c h C o m b i n a t i o n f o r C h a r a c t e rJ

J

8

4

\-/-\"--\.--

Zone Portion
as 56 5t aa a9

--r
B o

F rtu6r
B

-

e
2
1 .
' r r 4
ts
A
8
4
2
1
BIvIr.
A
a
4
2
1

a
2
1
25ft?r,3?eronlB
A
A
4
2
. r 5 3 5 e 5 o e 6 ' 5 r16 . 8

55gar66a
rtt

-

tx111a1t

!5ra07.aageo

37@

Figure 1O-8, Difference in Zone Portions of a Byte and a Card Column

1G8

A
8
4
2
1

2

1

Thereareexceptionswhich shouldbe noted in specifying
that the zonesof characters
be usedto identify records.
Ar:cordingto Figure10-9,the zoneof the letterJ is used
t o i d e n t i f yr e c o r dt y p e 0 1 , w h i l et h e z o n eo f a m i n u ss i g n
is usedto identify recordtype 02. Recordedon cards,both
characters
havea B zone punch. However,insidetne computer,their zonerepresentations
differ.

I

2

!

F i l e n am e

n

c

!

9

l*ol*oo
442',!

_ [','l ooo,
8421

G :Tt; m

l,l
3

Althoughthe zonesdiffer, the RPG ll programconsiders
the two the same.Thus,a cardwith a minuspunchedmight
turn on eitherthe 01 or 02 indicator. Likewise,a cardwith
the letterJ could turn on eitherindicator.

r

e ,o ,, ,? ,.rlro

l

t

F

c
2 1 2 2 2 J ? 4 25

,1t
A)

2a 29 30 :1

fjs
t i -

Figure 10-9. Exception: Zone Repreentation Considered the Same

y, the zoneof the characterblank is treatedthe
Siimilarf
serme
asthe zoneof 0 through9. Also, the zoneof &
(ermpersand)
is treatedthe sameasthe zonesof the letters
A through L To avoidconfusion,you shouldnot specify
both (zonesof the characters
J and -; blankand 0-9; & and
A-l) for identificationof recordtypeswhich areto be used
inrthe sameprogram.
Figurel0-10 showsthe groupsof characters
that have
zonesthat test asequalfor purposes
of recordidentification and the TESTZ operation. Noticethat thesegroupingsaredifferentfrom the groupingsof characters
for
p u r p o s eosf c o l l a t i n gs e q u e n cbey z o n e( F i g u r e1 0 - 2 8 ) .

Working With Data Structure

1O-9

Character

{
(period)

Bit
Combination

Zone

Digit

0100

1 0 10

0100

1 0 11

0100

Collating
Sequence
of
Zones

Bit
Combination

Zone

Digit

0 11 0

0000

I
I

11 0 1

0000

11 0 0

Jor-l

1101

0001

(minus)

(

0100

11 0 1

Kor-2

11 0 1

0010

+

0100

1110

Lor-3

11 0 1

0011

0100

1111

Mor-4

11 0 1

0100

0101
D

)
-l

%

1 0 10

Nor-5

11 0 1

0101

0101

10't1

Oor-6

11 0 1

0 11 0

0101

11 0 0

Por-7

11 0 1

0 11 1

0101

1101

Oor-8

1101

1000

0101

1110

Ror-9

1101

1001

0101

1111

s

110

0010

0 11 0

0001

T

1110

001I

0 11 0

1 0 11

U

1110

0100

1110

0101

W

1110

0 11 0

X

1110

0 11 1

1110

1000

z

1110

1001

b

0100

0000

0 11 0

11 0 0

0 11 0

11 0 1

0 11 0

11 1 0

7

0 11 0

1111

0 11 1

1010

t

0 11 1

1 0 11

@

0 11 1

11 0 0

(undlrscore)

0 11 1

&
B

lhlanLl

+0

1111

0000

1

1111

0001

2

1111

0010

1101

(apostrophe)

0 11 1

1110

3

1111

0011

0 11 1

1111

4

1111

0100

1111

0101

o

1111

0 11 0

0101

o000

1100

0001

1100

0010

c

1100

0011

D

1100

0100

E

1100

0101

r

11 0 0

0 11 0

u

1100

0 11 1

H

1100

1000

1100

1001

F i g u r e 1 0 - l 0 . C h a r a c t e rG r o u p s W i t h Z o n 6 s t h a t T e s t a r E q u a l f o r
Record lD and TESTZ

1rF10

Character

7

1111

0 11 1

I

1111

1000

I

1111

1001

Collating
Sequence
of Zones

P a g eo f G C 2 1 - 7 5 6 7 - 2
l s s u e d2 4 M a Y 1 9 7 6
Bv TNL: GN21-5389

C o n s i d e ra n o t h e r e x a m p l ew h i c h p o i n t s o u t t h e d i f f e r e n c e
i n h o w n e g a t i v en u m b e r sa r e s t o r e d a n d h o w y o u m a y t h i n k
t h e y a r e s t o r e d . T h e m i n u s s i g n a l o n e i s r e p r e s e n t e do n a
c a r d a n d i n s t o r a g ea s s h o w n i n F i g u r e1 0 - 1 1 ,i n s e r tA .
O n l y t h e z o n e p o r t i o n o f t h e c a r d c o n t a i n sa p u n c h . F i g -

A c o n c l u s i o nc a n b e d r a w n f r o m t h e p r e v i o u se x a m p l e s :
e a c h u n i q u e p u n c h c o m b i n a t i o n i s a s s o c i a t e dw i t h a d i f f e r e n t b i t c o m b i n a t i o n . O f c o u r s e ,i n d i s c u s s i n gn e g a t i v e
n u m b e r sb e f o r e , w e s t a t e dt h a t t h e p u n c h c o m b i n a t i o n so f
- / t h r o u g h - 9 a n d - 0 a r e , t h es a m ea s t h e p i u n c h e sf o r t h e

u r e 1 0 - 1 1 , i n s e r t B , s h o w sh o w a p o s i t i v e5 i s r e p r e s e n t e d
o n a c a r d a n d i n s t o r a g e . I n t h i s c a s e ,o n l y t h e d i g i t p o r t i o n
o f t h e c a r d c o n t a i n sp u n c h e s . N o t e F i g u r e 1 0 - 11 , i n s e r t C ,
f o r t h e p u n c h a n d b i t c o m b i n a t i o n sw h i c h r e p r e s e n a
t -5.

l e t t e r sJ t h r o u g h , 9 a n d I
Thus, the bit combinations
f o r t h e n e g a t i v en u m b e r sa r e a l s o t h e s a m ea s t h o s e f o r J

W h e n c h e c k i n gt h e c a r d sy o u c a n s e et h a t t h e d i g i t p u n c h e s
f o r t h e p o s i t i v e5 a n d t h e n e g a t i v e5 a r e t h e s a m e . F u r t h e r m o r e , t h e d i g i t b i t s i n s t o r a g ef o r t h e t w o c h a r a c t e r sa r e a l s o
t h e s a m e . T h e z o n e p u n c h f o r - 5 i s t h e s a m ea s t h e z o n e
p u n c h f o r t h e m i n u s s i g nc h a r a c t e r . H o w e v e r ,t h e z o n e b i t s
in storagefor the two charactersare not the same. Theref o r e , y o u s h o u l d n o t a l w a y sa s s u m et h a t , i n s t o r a g e t, h e
z o n e b i t s f o r a n e g a t i v en u m b e r w o u l d b e i d e n t i c a lt o t h e
z o n e b i t s f o r t h e m i n u s s i g n ( F i g u r e1 0 - 1 1 ) .
The reason is that the computer checks the entle punch
c o m b i n a t i o n ( b o t h z o n e a n d d i g i t p o r t i o n s )o f a c o l u m n t o
determine which zone bits are to be on or off . Since the
e n t i r e p u n c h c o m b i n a t i o n s( n o t o n l y z o n e p u n c h e s )f o r t h e

through r3.
C o n s i d e ra g a i nt h e n u m b e r o f p o s i t i o n sa v a i l a b l et o r e p r e s e n t a c h a r a c t e r .A c h a r a c t e r i s t io
c f c o d e si n v o l v i n gd i f f e r e n t
c o m b i n a t i o n s( s u c ha s b i t s o n a n d o f f o r p u n c h e s )i s t h a t t h e
g r e a t e rt h e n u m b e r o f p o s i t i o n sa v a i l a b l et o r e p r e s e n ta n y
o n e c o m b i n a t i o n ,t h e g r e a t e rt h e n u m b e r o f c o m b i n a t i o n s
t h a t a r e p o s s i b l e . A s m e n t i o n e d ,w i t h s i x p u n c h p o s i t i o n s ,
6 4 u n i q u e p u n c h c o m b i n a t i o n sc a n b e m a d e , a n d , t h e r e f o r e ,
6 4 d i f f e r e n t c h a r a c t e r sc a n b e r e p r e s e n t e do n a c a r d . W i t h
e i g h t b i t s ( p o s i t i o n s ) ,2 5 6 u n i q u e c o m b i n a t i o n so f o n - o f f
b i t s c a n b e c r e a t e da n d , t h e r e f o r e ,2 5 6 d i f f e r e n t c h a r a c t e r s
c o u l d b e r e p r e s e n t e di n s i d et h e c o m p u t e r . H o w e v e r ,y o u
o n l y n e e d 6 4 c h a r a c t e r st o p r o g r a mt h e c o m p u t e r ; t h e r e f o r e , o n l y 6 4 o f i t s 2 5 6 b i t c o m b i n a t i o n sa r e a s s o c i a t e dw i t h
a p r i n t a b l ec h a r a c t e r .

m i n u s c h a r a c t e ra n d t h e n e g a t i v e5 a r e d i f f e r e n t , t h e i r z o n e
bits in storageare also different.

W o r k i n gW i t h D a t a S t r u c t u r e

10-11

F l e p r e s e n t a t i o no f M i n u s ( - ) C h a r a c t e r

0

1

o l o

0

F l e p r e s e n t a t i o no f " 5 " C h a r a c t e r( p o s i t i v e )

o

0

1

R e p r e s e n t a r i o no t " - 5 "

1

C h a r a c t e r( N e g a t i v e )

B

I

BIT

F i g u r e 1 0 - 11 . R e p r e s e n t a t i o no f a N e g a t i v eN u m b e r

10-12

0

1

1

0

0

1

r i o

1

0

ldentifying Bit Combinationswith NumericalVah"res

tr
6 r

Eachuniquecombinationof eightbits can be associated
how the numerical
with a numericalvalue. Beforediscussing
valueis determinedfor a character,perhapsfirst you would
like to know why numericalvaluesareassigned.

s

9 lo ll

12 [

[

15 16 17 ts t9 20 2t 2

23 2a 23 26 27 2S 2s 30 31 32

33 3. 3s 36 37 33 39 40 {l 12 13 44 45 46 47 4a a9 50 sl 52 s3 54 5s 55 5? 53 59 60 6t 62 63 54

65 66 67 63 69 10 )t 72 13 14 7s 76 77 7A 79 & St 32 $

A! As 66 A7 33 39 90 9t 92 93 94 95 e6

97 9399rm0D2103loa105rGto7103l@fio

{617lrsll9i20rze2l23r241ap6tnrs

B

a
a

a

on punched
As mentionedbefore,datacan be represented
cards.Actually,after readinga card,the computerdoesnot
immediatelydeterminewhat characteris punched. lt can,
however,distinguishone punchcombinationfrom another
punchcombination.Furthermore,the particularcombination of punchesindicatesto the computerwhich bits should
be seton and off to representthat punchcombinationinsidethe machine.At this point, the representation
on the
cardis just a particulargroupof punchesand the representation in stoiageis merelya particularcombinationof on and
off bits.

a

a
1
1
1 2 3 4 5 6 r 6 I tO
B

4
2
t 6 t 7 1 3 1 9 2 20 1 2 2 2 3 22 3 r U " r r " r " " o " r r " L

a
2
1

3 3s 3 5 3 5 3 7

2
s3sa5555
6 t " " U " " O a 'U r U a " O1
B

iXA1.34647

;

a
2
I

2
t

6 5 S 6 7 6 4 6 19 0 7 t 7 2 7 3 7 a 8 1 6 7 7 7 A 7 s

a5a607gss9so",
"a"a"a"ur"

rax37@

\
\

One Byte in Storage

To usethe byte of datafor output, the computermust
know what characterto punchor print. This is done by
associating
a numericalvaluewith eachuniquebit combination. The computerautomaticallyknowsthat a certain
valueis relatedto a particularcharacter,suchasthe value
209 indicatesthe character
J.
C o n s i d ehr o w a n u m e r i c avl a l u ea n d h o w t h e c h a r a c t ear r e
determined.Eachof the eight bits in a byte areassigned
a
number. The valuesbeginwith 7 for the I bit and are
doubledfor eachof the next bits (Figure10-12]..By adding only the numberswhich correspondto bits which are
on (l), a numerlcalvalueis obtainedfor a byte. As Figure
1 0 - 1 2s h o w sf,i r s i t h e p u n c hc o m b i n a t i o n( f o r t h e c h a r a c in
t e r F ) i n c o l u m n7 i s t r a n s l a t e idn t o t h e b i t c o m b i n a t i o n
storage.The bits on resultin a numericalvalueof 198,
which the computerassociates
with the characterF.
Any differencein the bit combinationresultsin a differencein numericalvalue. Therefore,everycharacteris associatedwith a differentnumericalvalue. The greatest
numericalvaluewhich can be associated
with a bit combinat i o n i s 2 5 5 ( a l le i g h tb i t so n ) , w h i l et h e l o w e s tn u m e r i c a l
valueis 0 (all eightbits off). This resultsin a total of 256
possiblenumericalvaiues.Only 64 differentcharacters
can
cn a 96 columncard;therefore,we areconbe represented
cernedwith orrly64 of the differentnumericalvalues.Howe v e r ,a s F i g u r e1 0 - 1 3s h o w st,h e 6 4 n u m e r i c avl a l u e sa s s o c i can rangeanywherefrom 0 through
atedwith the characters
255. The numericaivaluesmissingfrom the chart are not
relatedto any printablecharacter.

,|
BIT
Numerical
Value
Assigned

8

0

1
4

2

0
"

0
t

1
8

1

0

2

1

4

t t t t t r i r
r r t t t t t
12 8 6 4 3 2 1 6 8 4 2 1

Add Value of
Bits That Are On

128 + 64

+ 4+2

=

198

N U M E R I C A LV A L U E 1 9 8= F C H A R A C T E R

Figure10-12, Determininga NumericalValuefor a Character

Working With Data Structure

10'13

l

P a g eo f G C i 2 1- j 5 6 7 - 2
l s s u e d2 4 M a y 1 9 7 6
By TNL: cN21-5389

0rCo0000O
0{1000001

Bit
Combination

Numerical
Value

00110011
00110100
uul r ol 01
oo110110

51

Character

3t

54

o0110111

10
'11
12
13

00111000
00111001
oo111010
00111011
00111100
o0111101
00111110
oo111111
01000000
01000001
010000t0
01000011
01000100
01000101
01000110
01000111
01001000
01001001
01001010
0 r 0 0 10 1 I

OO0ttOtt r

27

ooortroo I

ze

0l1 1 1 0 1[
ze
'o
og
oo
- o o o1t t111l 0- i - 3 b :r
l-oor

oooo0_l-_ :.r__

01001100
01001101
01001110
01001111
01010000
01010001
01010010
0 10 1 0 0 1 1
UTUI UI UU

01010101
01010110
01010111

01011000

ootororr 1- 43
oolollol I
ns
00101111

oolr oooo

F i g u r e 1 0 - 1 3 { P a r l 1 o f 3 ) . N u m e r i c a l V a l u e s A s s o c i a t e dw r t h
Characters

10-14

0101 1001
01011010
or011011
01011100
01011101
01011110
01011111

911eoigq_

01100001
ol 100010
01100011
01100100
01100101

56
5t

58
59

60
61
b2.
OJ

b4

Blank

65
66
ot

68
Aq

70
71
72
72
74
75

A

v

t6

77
78
79
80
81

(
&

a2
6J

84

85
atb

87
88
dY

90
91
92

93
94
95
96
o7

98
99
100
101

-1

8it
Combination

Numerical
Value

01100110

102

01100111
01101000

103
104

0 11 0 1 0 0 1

10s

0 11 0 1 0 1 0

106

01101100
1 0 11 0 1

108
109

1 0 11 1 1
01110000
01110001
0 111 0 0 1 0
'1
0 11 1 0 0 1
01110100
0 111 0 1 0 1

1 11
112
113
'114

01110111
0111'l000
111001
01111010

119
120
121
122

115
116
117

Bit
Combination

1001 1001
10011010
10011011
10011100
't0011 101
10011110
10011111
10100000
10100001

10100010
1010001 1
101 001 00

10100101
10100110
1 0 10 0 111
10101000
I 0101001
10101010
10101011
10101100
10101101
10101110

125

01111101
t111110
0 11 1 1 1 1

127
128

o000000

loooooot
10000010
--m000011
i

10000100

129
-

130

131
132

10000111
10001
0001001
10001010

135
136
1
138

10001101

141

10001111
10010000

1
144

10010100

lqqqg1'_

10010110
10010111

148

14e
150
151

10101111
10110000
101 10001
10110010
10110011
10110100
10110101
10110110
10110111
----mitlboo-10111001
10111010
10111011
10111100
10111101
1 0 1111 1 0
1 0 111 11 1
11000000
11000001
11000010
1100001 1
11000100
1100010r
11000110
11000111
11001000
11001001
11001010
11001011

Numerical
Value

Character

tcJ
t3q
t55

156
t3/

158
159
160
161
162
't63
164
165
too

167
168
169
170
171
172
173
174

175
176
177
178
179

180
181
142

183
184
185

186
147
188

189
190
191
192
193
194
195
196

197
198
199
200
201
202
203

B
D
E
F
G
H
I

F i g u r e 1 0 - 1 3 l P a r t 2 o f 3 ) . N u m e r i c a l V a l u e s A s s o c i a t e dw i t h C h a r a c t e r s

Working With Data Structure

1 0 - 15

Bit
Combination

Numerical
Value

11001100
11001101
11001110
11001111

2U

r 1010000
11010001

11010010
11010011
11010100
11010101
11010110
1101011
11011000
1011001
1011010
1101101
1101't100
11011101
1 1 0 11 1 1 0
1 1 0 11 11 1
100000
1I 100001
11100010
11100011

11100100
11100101
r1100t10
11100111

'|

1 101 0(x)

11101001
101010
11101011
11101100
11101101
1 1 r 0 11 1 0
1 1 1 0111 1
'rr 1
10000
11110001
11110010
11110011
11110100
11110101
1 1r 1 0 11 0
r'rlto'ttl
11111000
11111001
11 11 1 0 01
t t 1 1 0 1I

11111100
11 0 1
1111110
'11111111

Assigning Numerical Values to Zone and Digit portions
Character

205
206
207
208
209
210
21',!
212

I or-O
Jor-1
Kor-2
L or.3
Mor-4

213

Nor-5
Oor-6
Por-7
Oor-8
Ror-9

214
215
216
217
218
219
220
221

222
223
224
22F'

226
221
228
229
230

W

231

X

z

233
234
235
236

237

244

245
246
247
248
249
250
251
252
253
254
255

Y o u m a y b e w o n d e r i n gw h y a c h a r a c t e rw o u l d e v e r
be ass o c i a t e dw i t h t w o p a i r e d n u m b e r s ,s i n c e i t c a n b e a s s o c i a t e d w i t h j u s t a s i n g l en u m b e r . I n c e r t a i nj o b s , y o u m a y
b e c o n c e r n e dw i t h o n l y t h e d i g i t p o r t i o n o r o n l y t h e z o n e
p o r t i o n o f a c h a r a c t e r . F o r e x a m p l e ,i f r e c o r d s
within a
g r o u p a r e t o b e s e q u e n c ec h e c k e do n l y o n t h e
b a s i so f t h e
z o n e o f a c h a r a c t e r ,t h e c o m p u t e r m u s t l o o k a t o n l y t h e
z o n e b i t s a n d d e t e r m i n ea n u m e r i c a lv a l u e f o r t n e z o n e p o r _
tion alonein order to make the comparison.Also, if you
w a n t t o a l t e r t h e c o l l a t i n gs e q u e n c eo r t r a n s l a t ea f i l e . b o t h
t o b e d i s c u s s e dl a t e r , y o u m u s t k n o w t h e s e p a r a t ev a t u e s
f o r t h e z o n e a n d d i g i t p o r t i o n so f a c h a r a c t e r .

I

U

232

238
239
240
241
242
243

Y o u h a v es e e nh o w a s i n g l en u m e r i c a lv a l u e i s d e t e r m i n e d
for a combinationof eight bits. The numerical
v a l u eo f a
c h a r a c t e ri n s t o r a g ec a n a l s o b e e x p r e s s e da s a p a i r o f n u m b e r s ,r a t h e r t h a n a s i n g l ev a l u e . O n e n u m b e r d e s i g n a t e s
t h e v a l u eo f o n l y t h e f o u r z o n e b i t s ; t h e o t h e r n u m b e r
r e p r e s e n t st h e v a l u e o f t h e f o u r d i g i t b i t s .

0
1

2
2

4
5

D e t e r m i n i n gs e p a r a t ez o n e a n d d i g i t v a l u e si s s i m i l a r t o d e _
t e r m i n i n g a s i n g l ev a l u e f o r a n e n t i r e b i t c o m b i n a t i o n ;t h a t
i s , v a l u e sa r e a s s i g n e dt o e a c ho f t h e b i t p o s i t i o n s . T h e
valueswhich correspond to on bits (l ) are then added to
obtain a value.
T o d e t e r m i n es e p a r a t ev a l u e s ,t h e z o n e a n d d i g i t p o r t i o n s
a r e e a c ht r e a t e d a s s e p a r a t e4 - b i t c o m b i n a t i o n s . T h e f o u r
b i t s i n e a c h p o r t i o n a r e a s s i g n e dt h e v a l u e s1 , 2 , 4 , a n d g
( F i g u r e 1 0 - 1 4 ) . T h e r i g h t m o s tz o n e a n d d i g i t
b i t s e a c hh a v e
the value /; while the leftmost bits in eachportion areass i g n e dt h e v a l u e8 . A v a l u e f o r t h e z o n e p o r t i o n o f a b y t e
i s d e t e r m i n e db y a d d i n g o n l y t h e v a l u e sc o r r e s p o n d i n gt o
z o n e b i t s w h i c h a r e o n ( l ) . L i k e w i s e ,a d i g i t v a l u e i s o b t a i n e d b y c o n s i d e r i n go n l y d i g i t b i t s w h i c h a r e o n .

o

7

I
I
Zone

Digit

-,+-_/-\__'^-

r

o

/.-r-tu-^-

l

o

l

o

o

l

t

Bit
F i g u r e 1 O - 1 3 ( p a r t 3 o f 3 1 . Numerical Values
Associated with Characters

Assigned
Value

F i g u r e 1 0 - 1 4 , A s s i g n i n gV a l u e sf o r Z o n e a n d D i g i t P o r t i o n s
of a
Character

1G16

for
A , sF i g u r ei 0 - 1 5 , i n s e r tA , s h o w st,h e b i t c o m b i n a t i o n
(
/
)
p
r
o
d
u
c
e
s
z
o
n
e
a
digit
c
h
a
r
a
c
t
e
r
a
v
a
l
u
e
o
f
6
a
n
d
theslash
P
u
t
t
i
n
g
t
h
e
t
w
o
v
a
l
u
e
s
t
o
g
e
t
h
e
r
t
,
h
e
e
n
t
i
r
e
c
harv a l u eo f 1 .
h
o
w
e
v
e
r
,h a t
e
x
p
r
e
s
s
e
d
v
a
l
u
e
N
o
t
e
,
t
a st h e
a c t e rc a nb e
61.
i
n
o
u
r
d
e
c
imal
t l r i si s n o t t h e s a m ea st h e n u m e r i c avl a l u e6 1
n
u
m
e
r
i
c
a
l
numbering
a
s y s t e m .l f w e w e r et o d e t e r m i n e
valuefor the entire8-bit combination,we would obtainthe
t ).
v a l u e9 7 ( F i g u r e1 0 - 1 5i,n s e r B
hs mentionedbefore,with eightbits or positionsin a byte,
2 5 6 d i f f e r e n t8 - b i tc o m b i n a t i o ncsa n b e f o r m e d . T h e 2 5 6
c o m b i n a t i o ncsa n b e a s s o c i a t ewdi t h t h e n u m e r i c avl a l u e s
0 l 2 5 5 ( F i g u r e1 0 - 1 6 ,i n s e r tA ) . l f e i t h e rt h e z o n eo r d i g i t
prortionareconsidered
however,only four bits
separately,
p
o
s
i
t
i
o
n
s
T
h
e
r
e
f
o
r ea, m a x i m u mo f 1 6 d i f o,r
a r ea v a i l a b l e .
d e i t h e rt h e
f e r e n t4 - b i tc o m b i n a t i o ncsa nb e r e p r e s e n t ei n
p
o
r
t
i
o
n
z
o
n
e
o
r d i g i tc o m d
i
g
i
t
o
f
a
b
y
t
e
.
T
h
e
1
6
z o n eo r
t
h
e
t
h
r o u g h1 5
w
i
t
h
v
a
l
u
e
s
0
b r i n a t i o ncsa nb e a s s o c i a t e d
( F i g u r e0
' l - 1 6 ,i n s e r B
t ).
-l-he
v a l u eo b t a i n e df o r a z o n eo r d i g i t b i t c o m b i n a t i o ni s
referredto ashexadecimalnumber. Hex means6, while
c l e c i m ar le f e r e tso 1 0 . H e x a d e c i m at lh, e n ,m e a n s6 + 1 0 ,o r
n lu m b e rc a nb e a n y o n e o f 1 6 p o s s i b l e
16. A hexadecima

l u m b e r sf o r
v a l u e s( 0 - 1 5 ) . P u t t i n g t h e t w o h e x a d e c i m a n
t h e z o n e a n d d i g i t p o r t i o n s t o g e t h e rg i v e sa h e x a d e c i m a l
v a l u e f o r t h e e n t i r e c h a r a c t e r .6 / i s t h e h e x a d e c i m avl a l u e
for the / character. Keepin mind that this hexadecimal
v a l u e i s a c t u a l l y t w o s e p a r a t ev a l u e s ,o n e f o r t h e z o n e a n d
one for the digit portion.
A l l o f t h e 2 5 6 p o s s i b l e8 - b i t c o m b i n a t i o n sc a n b e r e p r e s e n t e db y a h e x a d e c i m a vl a l u e ;t h a t i s , t w o h e x a d e c i m a l
l umber can take up
n u m b e r s . H o w e v e r ,e a c h h e x a d e c i m a n
'il
o n l y o n e p o s i t i o n . l f a z o n e p o r t i o n h a st h e v a l u e 5 a n d
a d i g i t p o r t i o n h a st h e v a l u e 1 2 , t h e h e x a d e c i m avl a l u ef o r
t h e c h a r a c t e rc a n n o t b e e x p r e s s e da s 1 5 1 2 . C o n s e q u e n t l y .
a z o n e o r d i g i t p o r t i o n w h o s e n u m e r i c a lv a l u e i s 1 0 o r
g r e a t e r( 2 - p o s i t i o nn u m b e r ) m u s t b e r e p r e s e n t e di n a s l i g h t a s i n g l el,e t t e r
ly differentf orm. This is done by assigning
a s a s u b s t i t u t ef o r t h e n u m b e r . T h e l e t t e r s4 t h r o u g h F
s e r v ea s t h e h e x a d e c i m a fl o r m s o f t h e v a l u e s1 0 t h r o u g h 1 5
a s s h o w n i n F i g u r e1 0 - 1 7 .

@
D E T E RM I N I N G N U M E R I C A L V A L U E F O R E N T I R E B Y T E

1

I

I

V A L U E B Y Z O N EA N D D I G I I
Digit

Zone

Bit Combination
for "/" Character

V a l u e A s s i-q n e d
128
To Bit

I
0

1

1

0

t

0

0

0

Maximum
Numerical
Value

I

Bit

32

1

8

4

I

1

16

"128
+64+32+16

8 + 4 + 2 + 1 = 2 5 5

+ 1

4 + 2

Zone Value

64

1

1

I

V a l u e sF o r
"oN" Bits

I
I

Bil

-A\.J\-,-r

-,,^*/\--^-

I

6

D E T E R M I N I N GN U M E R I C A L V A L U E F O R Z O N E O R D I G I T

Digit Value

DIGIT

ZONE
,,+-_

-,A\_/\_,--

=-IR

V A L U EF O RE N T I R EB I T C O M B I N A T I O N
Bit Combination
For " 1" Character

0

1

1

0

I

t

0

0

0
1

Bit
ValuesFor
"oN" Bits

1

Bit

8

4

8

4

I

64+32

+

1

Value 97

F i g u r e 1 0 - 1 5 . D i f f e r e n c e i n V a l u e o f E n t i r e C h a r a c t e ra n d V a l u e
ol Zone and Digit Portions of Character

V a l u e A s s i-q n e d
ToBit

2

8 + 4 + 2 + 1 = 1 5
Maximum Numerical
Value For Zone Bits

8 + 4 + 2+ 1 =1 5
Maximum Numerical
Value For Digit Bits

F i g u r e 1 0 - 1 6 . M a x i m u m V a l u e sf o r E n t i r e C h a r a c t e ra n d f o r Z o n e
and Digit Portions

W o r k i n gW i t h D a t a S t r u c t u r e

1O-17

Character
Decimal
Number
0
1
2
3
4

Hexadecimal
Value

I J

14
15

Blank

40

c

4A
4B
4C
4D
4E

0
1
2

(
T

4

4F

F

6
7
I
9
10
11
12

Hexadecimal
Value

&
6

s
8
9
A
B

I

50
5A
5B
5C
5D
5E
5F

60
t)

E
F

lFigure10-17. Hexadecimal
Valuesof NumbersO-1S

A n 8 - b i t c o m b i n a t i o nw i t h a z o n e v a l u e o f 1 5 a n d a d i g i t
v a l u e o f 1 2 i s e x p r e s s e da s h a v i n ga h e x a d e c i m a vl a l u e o f
F C . B e c a u s et h e c o m p l e t e n u m b e r i n gs e r i e si s c o m p o s e o
of numbers 0 through 9 followed by letters4 through F,
a h e x a d e c i m avl a l u e f o r t h e z o n e a n d d i g i t p o r t i o n o f a n
8 - b i t c o m b i n a t i o n c a n a p p e a ra s a p a i r o f n u m b e r s ( 6 1 ) , a
l e t t e r a n d a n u m b e r l C 4 , 4 F l , o r a p a i r o f l e t t e r s( D B ) .
S i n c e z o n e a n d d i g i t v a l u e sa r e d e t e r m i n e ds e p a r a t e l yq,
s i n g l ec o m b i n a t i o n o f e i g h t b i t s c a n h a v et h e s a m eh e x a _
d e c i m a ln u m b e r f o r b o t h t h e z o n e a n d d i g i t p o r t i o n . T h u s ,
1 1 , 2 2 , 3 3 , A A , a n d o t h e r s u c h v a l u e sr e p r e s e n tg - b i t c o m b i n a t i o n sw h i c h h a v et h e s a m eb i t s o n i n b o t h t h e i r z o n e
and digit portions.
E n t i r e l y d i f f e r e n t 8 - b i t c o m b i n a t i o n sc a n h a v e i d e n t i c a l
z o n e h e x a d e c i m an
l u m b e r so r i d e n t i c a ld i g i t h e x a d e c i m a l
numbers, but not both. That is, the zone portion of one
r;haractercan contain the same bits on and off as the zone
portion of another character. In such a case,the identical
; z o n eb i t c o m b i n a t i o n sw o u l d g i v e i d e n t i c a lz o n e h e x a rJecimalvalues. However. if they are different characters
a n d t h e z o n e v a l u e sa r e i d e n t i c a l ,t h e d i g i t b i t s a n d , t h u s ,
the digit values.must differ. This is becauseno two characters can have the same 8-bit combination.
Figure 10-18 shows the hexadecimalvaluesassociatedwith
the 64 printable charactersthe computer recognizes. The
h e x a d e c i m avl a l u e sa r e i n s e q u e n c ej u s t a s t h e r e g u l a rn u m _
e r i c a lv a l u e sa r e . F u r t h e r m o r e ,t h e h e x a d e c i m a vl a l u e a s s;ociatedwith a character is equivalent to the numerical
value asociated with that character. However, there is no
need for you to be able to translate back and forth between
n u m e r i c a lv a l u e sa n d h e x a d e c i m avl a l u e s . l f v o u m u s r u s e
a c h a r a c t e r ' sh e x a d e c i m avl l a u e i n y o u r p r o g r a m m i n g ,y o u
can refer to the chart showing the appropriate vatue.

t

(E

61
6B
6C
6D
6E
6F
7A
7B
7C
70
7E
7F

A

c1

B

E

c2
c3
c4
c5

F

c6

G

c7
c8

c

H

c9
DO
D1
D2

Numerical
Value
64
74
75
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

)or-0
Jor-1
Kor-2
Lor-3
Mor-4
Nor-5
Oor-6
Por-7
Oor-8
Ror-9

D4
D5
D6
D7
D8
D9

208
2@
210
211
212
213
214
215
216
217

s

EZ

22fj

T

E3

227

U

E4
E5
E6
E7
E8
E9
FO
F1
F2
F3
F4
F5
F6
F7
F8
F9

228
229
230
231
232
233
240

W
X

z
0

2
3
4
3

6
7
8
I

D3

241
242

243
2M
245
2$
247

24
249

Figure 1O-18. Hexadecimal Values Associated with Characters

1G18

The signpart of the low-orderbyte is usedto indicate
w h e t h e rt h e n u m e r i cv a l u er e p r e s e n t ei n
d t h e d i g i t p a r t si s
p o s i t i v eo r n e g a t i v eC
. o m p a r eh o w t h e d e c i m anl u m b e r
d p a c k e dd e c i m aflo r m a t( F i g u r e
9 , 2 6 9i s r e p r e s e n t ei n
1 0 - 2 2 )w i t h i t s u n p a c k e dr e p r e s e n t a t i o( F
n i g u r e1 0 - 2 0 ) .

SavingDiskStorageSpace
Arslou havelearned,eachbyte of storage,whetheron disk
or in the computer,can containone character.That chara c t e rc a n b e a d e c i m anl u m b e ro r a n a l p h a b e t iocr s p e c i a l
character.The format of the characters
is known asunpackeddecimalformat. Eachbyte of storageis divided into
a 4 - b i t z o n ea n da 4 - b i td i g i t p a r t . F i g u r e10 -1 9 s h o w st h e
u n p a c k e d e c i m aflo r m a t .

7 0

T'hezonepart of the low-order(rightmost)byte indicates
u r h e t h etrh e d e c i m anl u m b e ri s p o s i t i v eo r n e g a t i v e I. n u n p ' a c k edde c i m afl o r m a t ,t h e z o n ep a r t i s i n c l u d e df o r e a c h
d i g i t i n a d e c i m anl u m b e r h
; o w e v e ro, n l y t h e z o n eo v e rt h e
l o w - o r d edr i g i t s e r v eas st h e s i g n . T h e l o w - o r d edr i g i t i s t h e
o n l y d i g i t w h i c hm a k e su s eo f t h e z o n ep o r t i o n . F i g u r e
1 0 - 2 0s h o w st h e u n p a c k e d e c i m afl o r m a tf o r d e c i m a nl u m brer9,269.

Digit

Digit

Sign

Oigit

I

----v-\.-Byte

F i g u r e 1 O - 2 1 . P a c k e dD e c i m a l F o r m a t

F'ackedDecimal Format

Positive

ln packeddecimalformat meansthat one byte of storage
c a nc o n t a i nt w o d e c i m anl u m b e r s .A d e c i m anl u m b e rw i l l
o c c u p yt h e z o n ep o r t i o nw h i c h i s u n u s e di n u n p a c k e d e c i n n afl o r m a t . T h i sf o r m a ta l l o w sy o u t o p u t a l m o s t w i c ea s
n n u c hd a t ai n t o a b y t e a sy o u c a n u s i n gt h e u n p a c k e d e c i rnalformat.

0010

Zone

7,0 ___+
Digit

Zone

7,0 +7'
Zone

, D i q-i t

Digit

Zone

'

1111

Figure 10-22, PackedFormat of Decimal Number 9,269

7 ' Q+

o+

1001

3Bvtes+

'l-he
low-orderbyte in packeddecimalformat is alsodivided
into two 4-bit parts. Eachbyte, exceptthe low-orderbyte,
c o n t a i n so n e d e c i m adl i g i t i n e a c h4 - b i t p a r t . T h e l o w - o r d e r
b y t ec o n t a i n sa d e c i m adl i g i t i n t h e l e f t m o s t4 - b i t p a r t ( b i t s
$ 3 ) a n dt h e s i g no f t h e d e c i m afli e l d i n t h e r i g h t m o s4t - b i t
p a r t ( b i t s4 - 7 ) . F i g u r e1 0 - 2 1s h o w sp a c k e dd e c i m afl o r m a t .

0 --.+

0 11 0

Digit

7

Sign

Digit

=--'| =\-Byte

1 10011= M i n u s s i g n
1 1 1 1= P l u s s i g n

f:igure10-19, UnpackedDecimal Format

Posi tive
Sign

Zone

2

I

1111

1001

1111

I

o

0010

1111

0 110

1111

1001

4 Bvtes
liigure 10-20. Unpacked Format of Decimal Number 9,269
W o r k i n gW i t h D a t a S t r u c t u r e

10-19

Y o u c a n s p e c i f y p a c k e di n p u t , o u t p u t , t a b l e ,o r a r r a y f i e l d s :
o P a c k e di n p u t f i e l d s . E n t e ra p i n c o l u m n
43 of the Input
sheet. This causesthe data to be unpacked before it is
stored.
o P a c k e do u t p u t f i e l d s . E n t e r a p i n c o l u m n
44 of the
O u t p u t - F o r m a t s h e e t . T h i s c a u s e st h e d a t a t o b e p a c k e d
beforeit is written our.

E a c ht w o - b y t eb i n a r yf i e l dc o n s i s tosf a s i g nb i t f o l l o w e d
b y a 1 5 . b i tn u m e r i cv a l u e .T h i sv a l u ec a nb e a s l a r g ea s
9,999. Whena rwo-bytebinaryfield from disk storageis
r e a di n t o t h e c o m p u t e rt,h e R p G l l p r o g r a mc o n v e r t si t t o
a f o u r - b y t eu n p a c k e d e c i m afl i e l d . F i g u r e1 0 - 2 3s h o w sa
t w o - b y t ef i e l di n b i n a r yf o r m a t .
0
a

.

P a c k e dt a b l e o r a r r a y f i e l d s . E n t e r a p i n c o l u m n 4 3
andl
o r 5 5 o f t h e E x t e n s i o ns h e e t . T h e d a t a w i l l b e u n p a c k e d
b e f o r e i t i s s t o r e d . P a c k e dt a b l e so r a r r a y sa r e a l l o w e d
o n l y a t p r e - e x e c u t i o nt i m e .

S i n c e d a t a m u s t b e r e p r e s e n t e di n u n p a c k e dd e c i m a l f o r m a t
o n c e i t i s i n s i d et h e c o m p u t e r , y o u m u s t g i v e t l t e R p G p r o _
g r a m a n i n d i c a t i o nw h e n i n p u t f i e l d s a r e i n a d i f f e r e n t
format.
B e c a u s ed a t a m u s t b e r e p r e s e n t e di n u n p a c k e dd e c i m a l f o r m a t b e f o r e i t c a n b e p r o c e s s e du, n p a c k e dd e c i m a l f i e l d s
m a y b e s t o r e d o n d i s k t o e l i m i n a t ec o n v e r t i n gt h e f i e l d s
f r o m p a c k e dt o u n p a c k e d f o r m a t d u r i n g i n p u t . H o w e v e r ,
s t o r i n g u n p a c k e df i e l d so n d i s k r e q u i r e sm o r e s p a c et h a n
s t o r i n g p a c k e df i e l d s .

-15

1Number

n

Figure10-23. Two-ByteFieldin BinaryFormat

E a c h f o u r b y t e b i n a r y f i e l d c o n s i s t so f a s i g n b i t f o l l o w e d
b y a 3 l - b i t n u m e r i cv a l u e . T h i s v a l u ec a n b e a s t a r g ea s
999,999,999. When a four-byte binary f ieldfrom disk
s t o r a g ei s r e a d i n t o t h e c o m p u t e r , t h e R p G l l p r o g r a mc o n _
v e r t s i t t o a n i n e - b y t eu n p a c k e dd e c i m a lf i e l d . A f o u r _ b y t e
binary f ield is shown in Figure 10-24.

q

i

s

Number

n

Einary Format
Y o u c a n s a v ee v e n m o r e d i s k s p a c et h a n i n p a c k e dd e c i m a l
format by storing numeric data in binary format. In binarv
f o r m a t , e a c hn u m e r i c f i e l d o n d i s k m u s t b e e i t h e r t w o o r
f o u r b y t e s l o n g . E a c ht w o - b y t e b i n a r y f i e l d c a n c o n t a i n a
v a l u ee q u i v a l e n tt o f o u r d e c i m a l p l a c e s ;e a c hf o u r _ b v t e
b i n a r y f i e l d c a n c o n t a i n a v a l u ee q u i v a l e n tt o n i n e d e c i m a l
p l a c e s . I n o t h e r w o r d s , a n u m e r i cv a l u e i n b i n a r y f o r m a t
o c c u p i e sa p p r o x i m a t e l yh a l f a s m a n y b y t e s o f d i s k s t o r a g e
a s t h e e q u i v a l e n tv a l u e i n u n p a c k e dd e c i m a l f o r m a t .

Figure1O-24.Four-ByteFieldin BinaryFormat

I n e a c h c a s e ,t h e s i g n p o r t i o n o f t h e h i g h - o r d e rb y t e ( l e f t m o s t ) i s u s e d t o i n d i c a t ew h e t h e r t h e n u m e r i c v a l u e i s
p o s i t i v eo r n e g a t i v e . N o t i c e t h a t i n t h e b i n a r y f o r m a t t h e
z o n e p o r t i o n o f t h e d e c i m a ln u m b e r i s n o t g i v e n . C o m p a r e
h o w t h e d e c i m a l n u m b e r 9 , 2 6 g i s r e p r e s e n t e di n b i n a r y
f o r m a t ( F i g u r e 1 0 - 2 5 ) w i t h i t s p a c k e da n d u n p a c k e dr e p r e s e n t a t i o n( F i g u r e 1 0 - 2 0 a n d 1 0 - 2 2 1 .

Positive
Si gn
I

*

o l e r s z l + o g o l z o1024
+e

128

T h e n u m e r i cv a l u e f o r e a c hb i n a r y b y t e i s o b t a i n e db y a d d i n g t h e n u m b e r s
w h i c h c o r r e s p o n dt o t h e b i t s t h a t a r e o n .
( B i t s t h a t a r e o n a r e r e p r e s e n t e ad s 1 ' s . ) T h e
s i g n b i t i s n o t i n c l u d e di n t h e v a l u eo f t h e n u m b e r . T h e b i t t o t h e
right
o f t h e s i g n b i t i s a l w a y s 0 , b e c a u s et h e m a x i m u m v a l u e o f a t w o - b y t e
binary fierd is 9.999.

F : i g u r e1 0 - 2 5 , B i n a r y F o r m a t o f D e c i m a l N u m b e r 9 , 2 6 9
10-20

256

9,269*

Since data must be representedin unpacked decimal form a t w h e n i t i s i n s i d et h e c o m p u t e r , y o u m u s t i n d i c a t et o
t h e R P G l l p r o g r a mw h e n f i e l d sa r e i n a n o t h e r f o r m a t .
Y o u c a n s p e c i f yb i n a r y i n p u t , o u t p u t , t a b l e ,o r a r r a y f i e l d s :
.

B i n a r y i n p u t f i e l d s . E n t e ra I i n c o l u m n 4 3 o f t h e I n p u t
s h e e t . T h e d a t a i s t h e n c o n v e r t e di n t o d e c i m a l b e f o r e i t
is stored.

o

o

Binary output fields. Enter a I in column 44 of the
O u t p u t - F o r m a t s h e e t . T h e d a t a i s t h e n c o n v e r t e di n t o
binarv beforeit is stored.
Binarytable or arrayfields. Enter a I in column 43
a n d / o r 5 5 o f t h e E x t e n s i o ns h e e t . T h e d a t a w i l l b e c o n v e r t e d t o d e c i m a l b e f o r e i t i s s t o r e d . B i n a r y t a b l e so r
a r r a y sa r e a l l o w e d o n l y a t p r e - e x e c u t i o nt i m e .

T o f u r t h e r p o i n t o u t t h e n e e df o r a s e t o r d e r o f c h a r a c t e r s ,
a s s u m et h e c o m p u t e r m u s t c h e c k t o m a k e s u r e r e c o r d si n a
f i l e a r e i n p r o p e r o r d e r a c c o r d i n gt o a d e p a r t m e n tf i e l d .
S o m e d e p a r t m e n tc o d e sa r e a l p h a b e t i c ,a s d e p a r t m e n tA ;
w h i l e s o m e d e p a r t m e n t c o d e sa r e n u m b e r s ,s u c h a s d e p a r t m e n t 8 . S h o u l d t h e n u m e r i c d e p a r t m e n t r e c o r d sa p p e a rb e f o r e t h e a l p h a b e t i cd e p a r t m e n t r e c o r d s ,o r v i c e v e r s a ? l t i s
l i k e l v t h a t t h e a n s w e rw o u l d d e p e n d o n w h o i s a s k e d . H o w e v e r ,f o r e f f i c i e n t d a t a p r o c e s s i n gy, o u c e r t a i n l yd o n o t w a n l
r e c o r d ss o r t e d o n e w a y o n e t i m e a n d a n o t h e r w a y t h e n e x t
t i m e . T h u s , t h e c o m p u t e r m u s t u s eo n e s e to r d e r o f c h a r a c ters.
E v e r y c h a r a c t e rr e c o g n i z e db y t h e c o m p u t e r m u s t h o l d a
c e r t a i n p o s i t i o n i n t h i s o r d e r i n r e l a t i o nt o t h e p o s i t i o n o f
t h e r e s t o f t h e c h a r a c t e r s .S u c h a n o r d e r i s r e f e r r e dt o a s a
collating sequenceof characters. By def inition, to collate
m e a n st o a r r a n g eo r v e r i f y t h a t d a t a a p p e a r si n p r o p e r o r d e r
or sequence.

C O L L A T I N G S E O U E N C EO F C H A R A C T E R S
T o p e r f o r m d a t a p r o c e s s i n ga p p l i c a t i o n se f f i c i e n t l y , y o u
u s u a l l yo r g a n i z ey o u r i n f o r m a t i o n i n s o m e o r d e r o r s e q u e n c e .
l m a g i r r et r v i n g t o l o c a t e a p e r s o n ' sp h o n e n u m b e r i f t h e
n a m e si n a t e l e p h o n eb o o k w e r e n o t i n a l p h a b e t i c a ol r d e r .
O f c o u r s e ,b e f o r e u s i n gt h i s o r d e r o r s e q u e n c ey, o u m u s t
k n o w w h a t i t i s . T h r o u g h t h e l e a r n i n gp r o c e s s y, o u k n o w
t h a t a l p h a b e t i c a ol r d e r m e a n st h a t 4 c o m e s b e f o r e B , B
, is
b e f o r e C , a n d s o o n . L i k e w i s e ,i n n u m e r i c a ls e q u e n c e 7
l e s st h a n 2 . 2 l e s st h a n 3 , a n d s o o n .
a p p l i c a t i o n s t, h e c o m p u t e r
In most of your data processing
m u s t b e a b l e t o r e c o g n i z ea n o r d e r o r s e q u e n c eo f d a t a . F o r
e x a m p l e ,i f y o u i n s t r u c t t h e c o m p u t e r t o s e q u e n c ec h e c k a
f i l e a c c o r d i n gt o a n a l p h a b e t i cd e p a r t m e n tc o d e o n e a c h
r e c o r d , i t m u s t b e a b l e t o d e t e r m i n ei f t h e d e p a r t m e n t f
r e c o r d s h o u l d a p p e a rb e f o r e t h e d e p a r t m e n tX r e c o r d , o r
v i c e v e r s a . I n a n o t h e r i n s t r u c t i o n ,p e r h a p st h e c o m p u t e r i s
t o c o m p a r et w o q u a n t i t i e s ,s u c h a s 3 a n d 8 , a n d t u r n o n a n
i n d i c a t o r i f t h e f i r s t q u a n t i t y i s l e s st h a n t h e s e c o n dq u a n t i t V . T h e c o m p u t e r m u s t d e t e r m i n ei f 3 i s l e s st h a n 8 o r i f
8 i s l e s st h a n 3 .
T h e p r e v i o u st w o t a s k sw o u l d b e e a s yf o r y o u t o p e r f o r m
b e c a u s et,h r o u g h m e m o r i z a t i o no r h a b i t , y o u k n o w t h e
natural order of the alphabetic charactersA through Z and
t h e n u m b e r s0 t h r o u g h 9 . H o w e v e r ,a c o m p u t e r h a s n o t
m e m r r r i z e ds u c l ro r d e r s . F o r t h e c o m p u t e r t o p e r f o r m t h e s e
t a s k s "a n o r d e r o r s e q u e n c eo f c h a r a c t e r sm u s t b e e s t a b l i s h e d .

. he seT h e r e c a n b e a n y n u m b e r o f c o l l a t i n gs e q u e n c e s T
q u e n c eu s e dd e p e n d so n t h e p a r t i c u l a ro r d e r i n w h i c h c h a r a c t e r sa r e t o b e r e c o g n i z e d . I n a n y c a s e ,t h e c o m p u t e r
s h o u l d u s e o n l y o n e c o l l a t i n gs e q u e n c ea t a t i m e .
T h e s t a n d a r dc o l l a t i n gs e q u e n c eo f 6 4 c h a r a c t e r si s s h o w n
i n F i g u r e 1 0 - 2 6 . T h e b l a n k , w h i c h i s t h e f i r s t c h a r a c t e r ,i s
c o n s i d e r e da s t h e l o w e s t i n t h e s e q u e n c ew h i l e t h e n u m b e r
9 , t h e l a s t c h a r a c t e r ,i s t h e h i g h e s ti n t h e s e q u , e n c eN. o t e
t h a t a l l o f t h e s p e c i a lc h a r a c t e r se. x c e p t t h e [ ( b r a c e ] ,a r e
f i r s t i n t h i s s e q u e n c e f, o l l o w e d b y t h e a l p h a b 6 t i cc h a r a c t e r s
4 t h r o u g h Z i n t h e i r n a t u r a l o r d e r , a n d t h e n t h e n u m b e r sO
t h r o u g h 9 i n t h e i r n a t u r a l o r d e r . T h e o n l y c h a r a c t e rw h i c h
which
you might not expectto be in its positionis the
I
J.
letters
I
and
the
between
comes
T h i s c o l l a t i n g s e q u e n c ei s t h e o r d e r u s e d b y t h e c o r n p u t e r
f o r t h e p u r p o s eo f s o r t i n gc a r d s ,c o m p a r l n gn u m b e r st o d e t e r m i n e w h i c h i s g r e a t e ro r l e s s ,c h e c k i n gt h e s e q u e n c eo f
r e c o r d si n a f i l e , a n d m a t c h i n g r e c o r d sf r o m t w o f i l e s t o d e t e r m i n e w h i c h r e c o r d s h o u l d b e p r o c e s s e dn e x t . A c c o r d i n g
t o t h e c o l l a t i n g s e q u e n c et,h e c o m p u t e r c o m p a r e st w o c h a r '
a c t e r st o d e t e r m i n e i f o n e c o m e s b e f o r e o r a f t e r t h e o t h e r ,
o r i s l e s st h a n o r g r e a t e rt h a n t h e o t h e r . O f c o u r s e ,y o u
s p e c i f y w h i c h c h a r a c t e r s( o r f i e l d s o f c h a r a c t e r s a) r e t o b e
c o mp a r e d .

Working With Data Stt ttcturc

1O'21

P a g eo f G C 2 1 - 7 5 6 7 - 2
l s s u e d2 4 M a y 1 9 7 6
By TNL: GN21-5389

F o r s o r t i n g ,s e q u e n c ec h e c k i n g ,a n d m a t c h i n g ,y o u
can
s p e c i f ya n a s c e n d i n go r d e s c e n d i n gc o l l a t i n gs e q u e n c e .
For
e x a r n p l e ,i f r e c o r d sa r e t o b e i n a s c e n d i n gs e q u e n c e ,
the
c h a r a c t e r sb e i n gc h e c k e ds h o u l d b e i n t h e o r d e r
shown in
F i g u r e I 0 - 2 6 . T h a t i s ,a c a r d w i t h a b l a n k s h o u l d
come before a cardwith the letterK. (The blank character
is lower
i n s e q u e n c et h a n t h e l e t t e r K . ) L i k e w i s r . a
,, cardwith the
l e t t e r K s h o u l d c o m e b e f o r e a n y r e c o r d l ;c o n t a i n i n g
one of
t h e n u m b e r s0 t h r o u g h 9 . l f y o u s p e c i f yd e s c e n d i n g
se_
q u e n c e ,t h e c o m p u t e r c o m p a r e st o m a k e
s u r et h e v a r e i n
t h e o p p o s i t eo r d e r , t h e c h a r a c t e r sh i g h e r i n s e q u e n c e
comillq
first.
A s m e n t i o n e d ,a c o m p u t e r c a n n o t m e m o r i z e t h e o r d e r
of
char€fcters;it must use another method for remembering
t h e c o l l a t i n gs e q u e n c e .T o d o t h i s , i t u s e st h e v a r u e s
associated with charactersto determine each character,s
relation
t o a n o t h e r c h a r a c t e ri n t h e s e q u e n c e .
I n a p r e v i o u sd i s c u s s i o na, v a l u e i s c a l c u l a t e df o r e a c h
bit
c o m b r i n a t i o ni n s t o r a g e .T h e v a l u ec a n b e t h o u g h t
o f a sa
s i n g l enr u m e r i c a lv a l u ef o r t h e e n t i r e g - b i t c o m b i n a t i o n
or
a s a 2 l - d i g i th e x a d e c i m a vl a l u e ,w h i c h i s a c t u a l l y
one nexad e c i n r a ln u m b e r f o r e a c h 4 - b i t c o m b i n a t i o n ( z o n e
and digir).
A h e > r a d e c i m av la l u e i s a n o t h e r w a y o f r e p r e s e n t i n g n u m _
a
e r i c a lv a l u e .
O n c e a v a l u e i s c a l c u l a t e d t, h e c o m p u t e r u s e si t t o o e t e r m i n e w h i c h c h a r a c t e ri s r e p r e s e n t e d .T h u s , t h e n u m e r i c a l
v a l u e 1 9 3 ( s a m ea s h e x a d e c i r n avl a l u e C 1 ) i s a s s o c i a t e d
with
t h e c h a r a c t e r4 w h i l e t h e n u m e r i c a lv a l u e 2 4 3 ( h e x a d e c i m e r l
v a l u e F 3 ) i s a s s o c i a t e dw i t h t h e n u m e r i c c h a r a c t e r3 . p e r .
h a p sy o u w o n d e r w h y a p a r t i c u l a rv a l u e ,s u c h a s l 9 3 ( C 1 )
is related to the letter A, rather than a different value.
T h e v a l u e sa s s o c i a t e dw i t h t h e 6 4 c h a r a c t e r sw e r e o r i g i n a l l y
a s s i g n e ds u c h t h a t t h e n a t u r a l s e q u e n c eo f t h e v a l u e sc o r r e s p o n d s w i t h t h e p o s i t i o n sc h a r a c t e r sa r e t o h o l d
within the
c o l l a t i n gs e q u e n c e .F o r e x a m p l e ,t h e c h a r a c t e r4 i s a s s o c i a t e d M / i t hv a t u e 1 9 3 ( h e x a d e c i m aC
l 1). B with 1g4
lC2\. C
w i t h 1 9 5 ( C 3 ) ,a n d s o o n . J u s t a s 4 i s l o w e r t h a n g
andg
i s l o w r - ' rt h a n C i n t h e c o l l a t i n gs e q u e n c e 1, 9 3 ( C l ) i s l e s s
t h a n 1 9 4 ( C 2 ) ,a n d 1 9 4 ( C 2 l i s t e s st h a n 1 9 5 ( C 3 ) .

10-22

1

Blank

o

7
I

&

o

10
11
12
13
l4
t5

't6
17
18
19
20
21
22

23
24
25
26
27
28
29
30
3l
JZ

F
u
H

36
37
38

o

40

n

47
48
49
50
51
52

S

54
55
56
57

T
U

W
X

z
0
I

2

I

qo

4

K

60
61

o

40

I

ol

7

41

M
N

bJ

?o

(u n d e r s c o r e )

D

JJ

_l
(minus)

A

D
E

34

I

45
@

42
43
44

o
P

Figure 10-26. StandardCollatingSequence

64

5

o

Pageof GC21'1567-2
l s s u e2
d 4 M a Y1 9 7 6
B YT N L : G N 2 1 - 5 3 8 9
F i g u r e 1 0 - 2 7 s h o w st h e 2 5 6 p o s s i b l eb i t c o m b i n a t i o n s ,t h e i r
n u m e r i c a la n d h e x a d e c i m a vl a l u e s ,a n d t h e c h a r a c t e r sa s s o c i a t e d w i t h e a c h . I n t h i s l i s t o f b i t c o m b i n a t i o n s .t h e n u m e r i c a l v a l u e sa r e i n o r d e r f r o m 0 t h r o u g h 2 5 5 ( h e x a d e c i m a l
v a l u e s0 0 t h r o u g h F F ) , a n d t h e a s s o c i a t e dc h a r a c t e r sa r e i n
t h e s t a n d a r da s c e n d i n gc o l l a t i n gs e q u e n c e .

Bit
Combination

00000000
00000001
00000010
00000011

oo000100
f)ooo0101
00000110

Character

Hexadecimal
Value

00011001
00011010
00011011
00011100
00011 101
00011110
00011111
00100000
0010000'l
00100010
00100011
00100100
oot 00101
00100110
00100111
o0101000
00101001
00101010
ool 01011
00101100
00101101
00101110
00101111
00110000
00110001
00110010

Bit
Combination

o0110011
00110100

2

00110101
00110110
00110111
00111000
o0111001
00111010
00111011
oo111100
o0111101
o0111110

-t

o4
05

4

06

o

08
09
OA
OB

oo011000

Numerical
Value

n

o7

oo010001
00010010
00010011
00010100
00010101
000101't0
oo010111

l 2 ) , d o e s n o t i m m e d i a t e l yf o l l o w t h e
2 2 6 ( h e x a d e c i m aE

oo

00001000
00001001
00001010
00001011
00001100
ooool 101
00001110

00010000

t h e c h a r a c t e rS f o l l o w s t h e c h a r a c t e rR i n t h e c o l l a t i n gs e q u e n c eo f c h a r a c t e r s .H o w e v e r ,t h e n u m e r i c a lv a l u e o f S ,

o1
02
03

000001 1 1

00001 1 1 1

A s y o u c a n r e a d i l y s e e ,t h e v a l u e a s s o c i a t e dw i t h a c h a r a c ter does not always immediately follow the value associated
w i t h t h e p r e v i o u sc h a r a c t e ri n t h e s e q u e n c e .F o r e x a m p l e ,

0c
OD
UE

OF
10
t1
12
13
14

't5

16
17

18
19
1A
1B

8
I

10
11

12
13
t4
15
t6
11

18
19
20
21
22
23
24
25
zo
a1

1C

28

1D
1E

2J

t r

31

20
21
22
23
24

?n

JI
JJ

34
Jb

tq

JT

zo

?a

27

39
40
41
42

2a
29
2A
3

01000100
01000101
01000110
01000111
01001000
01001001
01001010
01001011
0100110
01001101
01001110
01001111
01010000
01010001
01010010
01010011
01010100
01010101
0 1 0 1 0 11 0

01 100000
r)1 100001

s2

50

38
39
3A
Jb

3C
3D

Blank

01100010
01 10001 1
01100100
01 100101

Numerical
Value

52
54
55

56
57
5u
qq

3F
40

60
61
62
63
64

41

HT

42
43

oo

44

btJ

+c

69
70
71

JE

46
47

48
49

ot

IZ
11

74

4A
48
4C

75
76

+

4D
4E

78
7q

&

4F
50
3l

81

d

(

80

a2
a?

54
55
56

84
85
86
87

56

88

59
5A

89
90

$

5B

9l

)

tn

VJ

5E

94
95
96
97
98
99

01010111
01 01 1000

40

47
48
49

35
36

01000011

44

30
31

z?

01000000
01000001
01uu00tu

Hexadecimal
Value

34

00111111

01011001
01011010
01011011
01011100
01011101
01011110
01011111

2D

2E

Character

92

5F
60
61
oz

63
64
65

100
101

F i g u r e 1 O - 2 7 ( P a r t 1 o f 3 ) . C h a r a c t e r sa n d V a l u e s A s s o c i a t e dw i t h t h e 2 5 6 B i t C o m b i n a r i o n s
W o r k i n gW i t h D a t a S t r u c t u r e

1O-23

n u m ' 3 r i c avla l L r o
e f R , 2 1 7 ( h e x a d e c i m aDl 9 ) . T h e r e a s o n
f o r t h e g a p i s b e c a u s et h e b i t c o m b i n a t i o n sw i t h t h e n u m e r i c a l v a l u e s2 1 8 t h r o u g h 2 2 5 a r e n o t a s s o c i a t e dw i t h a n y o f
t h e € i 4 p r i n t a b l ec h a r a c t e r s .R e g a r d l e s st h, e c o m p u t e r d e t e r m i n e st h a t B i s l o w e r i n s e q u e n c et h a n ( c o m e sb e f o r e )S
because
t h e v a l u eo f R ( 2 1 7 o r h e x a d e c i m aDl 9 ) i s l e s st h a n
t h e v a l u e o t S ( 2 2 6 o r h e x a d e c i m a lE 2 \ .

Bit
Combination

0 11 0 0 11 0
01100111
01101000
01101001
01101010
01101011
01101100
01101101
01101110
01101111
01110000
01110001

C haracter

%

102

ot

IUJ

6B
69
6A

104

6C
OU

105

106
107
108
109

or

110
111

70

112

71
72

114

OE

?

Numerical
Value

oo

ob

01110010

01110011
01110100
01110101
01110110
0t11011
01111000
01111001
01111010
01111011
01111100
01111101
0 11 1 1 1 1 0

Hexadecimal
Value

IJ

74
76
77
78
79
7A
7B
@

113
115
116
117
118
119

't20
121

122
123

7D

124
125

T '

120

0 11 1 11 1 1

7F

127

10000000

80

t26

r oooo001

81

10000010
10000011
10000100
10000101
10000110
10000111
| 0001000
10001001
10001010
10001011
10001100
10001 101
10001110
10001111
10010000
10010001
10010010
10010011
10010100
10010101
10010110
10010111
10011000

Bit
Combination

10011001
10011010
10011011
10011100
10011101
10011110
10011111
10100000
10100001
10100010
I Ol 00011
10100100
10100101
10100110
1010011
10101000
10101001
10101010
10101011
10101100
10101101
10101110

130
131

133

10110101
10110110
1 0 1 1 0| 1
10111000

134

10111001

87
8B
89
8A
8B

136
137
tJd

139

Q/^

140

8D
8E

141
142
143

or

90
91
92
93
94
95
96

144
145

o7

151

98

146
't47
148
't49
150
't52

10111010
10111011
10111100
10111101
1011110
1 0 1 1 11 1
11000000
11000001
11000010
1100001 1
11000100
11000101
11000110
11000111
11001000
11001001
11001010
11001011

F i g u r r : 1 0 - 2 7 ( P a r t 2 o f 3 ) . C h a r a c t e r sa n d V a l u e s A s s o c i a t e dw i t h t h e 2 5 6 B i t C o m b i n a t i o n s
1C'24

on

157

VE

VF

158
159

AO

160

A1

161

A3

162
163

A4
A5

164
t03
tbb

A7
A8

167

A9
AA

169
170

AB

171

AC

172
173

AD
AE

oz

B3
B4
B5
bo

B7
BB
B9
BA
BB
BC
BD
BE
BF

c0
A

a1

B

C2
^'l

D
E

c4

F

c6

168

174
175

176
177
178
179

180
181

182
183
184
185
t60

187
188
189
190
191

192
193
194
195

196
197

198
199

u

H
I

154
155
156

AO

BO
B1

aa

6b

153

10110000
101 10001
10110010
10110011

a2

Numerical
Value

99
9A
9B
9C

AF

1 0 11 0 ' t 0 0

't32

Hexadecimal
Value

10101111

't29

84
85

Character

c8

100

C9

101

CB

202
203

Gollating By Zone Or Digit
Bit
Combination

Ch a r a c t e r

11001100
11001101
11001110
11001111
11010000
11010001

CD
LE
LF

11010010

K

11010011
11010100
11010101
11010110
11010111
11011000
11011001
11011010
11011011
11011100
11011101
11 0 11 11 0
1 1 0 11 1 1 1
11100000
11100001
11100010
11100011
11100100
11100101
11100110
1 1 1 0 011' l
t1101000
11101001
11101010
11101011
11101100
11101101
1 1 1 0 11 0
11101111
11110000
11110001
11110010
11110011
11110100
11110101
1 111 0 11 0
11 11 0 11 1
11111000
11111001
11111010
1 11 1 1 011

L
M
N

1 ' t' t1 11 0 0

11111101
11111110
11111111

Hexadecimal
Value

Numerical
Value

204
205
206
207

DO
D1
D2

208

UJ

211
212
213

209

2',to

o

D4
D5
D6

P

D7

zt5

o

D8
D9
DA
DB

2't6
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239

h

DD
DE
DF
EO
E1
c

T
U

E2

tsJ

E4
tr5

W
X

z

Eb

E7
EB
E9
EA
EB
EC
ED
Etr
ET

n

214

240

1
2

FO
F1
F2
F3

4

F4

244

q

F5
F6
F7
F8
F9
FA
FB

245
246
247
248
249

b

7
e
o

FC

FD
FE
FF

241
242
243

250
251
252
253
254
255

Figure 1O-27 (Part 3 of 3). Charactersand Values Associated with
the 256 Bit Combinations

Y o u l e a r n e df r o m a p r e v i o u sd i s c u s s i o nt h a t t h e z o n e a n d
d i g i t p o r t i o n s o f c h a r a c t e r sc a n b e t r e a t e da s s e p a r a t ea n d
d i s t i n c t g r o u p so f f o u r b i t s , e a c h w i t h i t s o w n h e x a d e c i m a l
n um b e r .
D i f f e r e n t c h a r a c t e r sm a v h a v e i d e n t i c a lz o n e b i t s o r i d e n , ifferentchartical digit bits, but not both. Consequentlyd
a c t e r sm a y b e a s s o c i a t e dw i t h t h e s a m ez o n e h e x a d e c i m a l
l umber but not both.
n u m b e r o f t h e s a m ed i g i t h e x a d e c i m a n
A s a n e x a m p l e ,t h e c h a r a c t e r , 4i s a s s o c i a t e dw i t h t h e v a l u e
C 1 . B i s a s s o c i a t e dw i t h C 2 , a n d K i s a s s o c i a t e dw i t h D 2 . . 4
h a st h e s a m ez o n ev a l u e ( C ) a s B , w h i l e K h a st h e s a m ed i g i t
v a l u e ( 2 ) a s 8 . H o w e v e r ,B i s t h e o n l y c h a r a c t e rw i t h b o t h
a z o n ev a l u eo f C a n d a d i g i t v a l u eo f 2 .
I n m o s t d a t a p r o c e s s i n gt a s k s ,t h e c o m p u t e r u s e se n t i r e
c h a r a c t e r so r t h e v a l u e so f t h o s e c h a r a c t e r st o m a k e c o m p a r i s o n s t, o d e t e r m i n ew h i c h i s g r e a t e ro r l e s s ,a n d s o o n .
H o w e v e r ,f o r c e r t a i n p u r p o s e s s, u c h a s s o r t i n gc a r d s ,y o u
m a y w i s h t o h a v et h e c o m p u t e r c h e c k o n l y t h e z o n e o r
o n l y t h e d i g i t p o r t i o n o f c h a r a c t e r s .I n s u c h a c a s e ,t h e
c o m p u t e r m u s t u s e a c o l l a t i n gs e q u e n c eb a s e do n z o n e o r
d i g i t v a l u e sr a t h e r t h a n t h e s t a n d a r dc o l l a t i n gs e q u e n c e
b a s e do n t h e e n t i r e v a l u e .
l f t h e c o m p u t e r u s e sa c o l l a t i n gs e q u e n c eb a s e do n t h e z o n e
p o r t i o n s o f c h a r a c t e r sa, n y d i f f e r e n c e si n t h e d i g i t b i t s a r e
i g n o r e d . O n l y t h e v a l u eo f t h e z o n e b i t s a r e c o n s i d e r e d '
T h e r e v e r s eo c c u r s i f a c o l l a t i n gs e q u e n c eb a s e do n t h e d i g i t
p o r t i o n s o f c h a r a c t e r si s t o b e u s e d '
T h e f a c t t h a t c e r t a i n c h a r a c t e r sh a v et h e s a m e z o n e o r d i g i t
v a l u e sc a n b e u s e dt o g r o u p c h a r a c t e r sw i t h i n a c o l l a t i n gs e o u e n c e . O n t h e b a s i so f z o n e v a l u e s ,t h e 6 4 p r i n t a b l ec h a r a c t e r sa r e d i v i d e d i n t o e i g h t g r o u p s ( F i g u r e 1 0 2 8 ) . T h e
z o n e b i t s ( a n d v a l u e s )a r e i d e n t i c a lf o r a l l c h a r a c t e r sw i t h i n
a g r o u p . l f c o l l a t i n g i s t o b e o n t h e b a s i so f d i g i t v a l u e s ,t h e
c h a r a c t e r sc a n b e d i v i d e d i n t o 1 6 g r o u p s ( F i g u r e 1 0 - 2 9 ) . I n
s u c h a c a s e ,d i g i t b i t s ( a n d v a l u e s )a r e i d e n t i c a lf o r a l l c h a r a c t e r sw i t h i n a P a r t i c u l a rg r o u P .
U s i n gt h e s t a n d a r dc o l l a t i n gs e q u e n c et,h e c o m p u t e r c o n s i d e r se a c h c h a r a c t e rt o h o l d a s p e c i f i cp o s i t i o n i n t h e s e quence. Therefore, no two characterscan be considered
e q u a l ; o n e m u s t c o m e b e f o r e a n o t h e r o r b e l e s st h a n a n other character.
O n t h e o t h e r h a n d , u s i n ga c o l l a t i n gs e q u e n c eb a s e do n z o n e s
or digits, one group of charactersfollows another group ot
characters. The characterswithin a group can occupy any
p o s i t i o nw i t h i n t h a t g r o u p . T h u s , t h e r e i s a n o r d e r o f g r o u p s
b u t n o p a r t i c u l a ro r d e r o f c h a r a c t e r sw i t h i n a g r o u p .

Working With Data Structure

1O'25

Character

8it
Combination
Zone

Digil

b
(blank)

0100

ooo0

{

0100

't01
0

0100

1 0 11

0t 00

11 0 0

(

0100

11 0 1

+

0100

1110

(period)

&

$

-i

0100

1111

ol 01

0000

0101

1 0 10

0101

1 0 11

0 10 1

11 0 0

0 10 1

1101

0101

1t10

0101

1111

0 11 0

oo00

(minus)

Collating
Sequence
of
Zones

Character

Bit
Combination
Zone

Digir

A

1100

0001

t'

1100

0010

1100

0011

D

11 0 0

0100

E

1100

0101

F

1100

0 11 0

G

1100

0 11 1

H

1100

I

1to0

1000
,|
001

11 0 1

ooo0

Jor-1

1101

0001

Kor-2

1101

0010

Lor-3

1101

0011

Mor-4

11 0 1

0100

Nor-5

1101

0101

Oor-6

1101

0 11 0

Por-7

11 0 1

0 11 1

0 11 0

oool

Oor-8

1101

1000

0 11 0

1 0 11

Ror-9

11 0 1

10 0 1

0 11 o

1100

s

1110

0010

0 11 0

1101

T

1110

0011

U

1110

0100

0 11 0

11 1 0

1110

0101

0 11 0

1111

1110

0 11 0

0 11 1

1 0 10

1110

0 11 1

t

0 11 1

'101
1

1 11 0

1000

@

0 11 1

1100

z'

1110

1001

0 11 1

11 0 1

+o

1111

oo00

1

1111

0001

't111

0010

?

1111

0011

4

1111

0100

5

1111

0101

t)

1111

0 11 0

7

1111

0 11 1

I

1111

1000

I

1111

1001

(undilscore)

(apostrophe)
0 11 1

1 11 0

0 11 1

1111

F : i g u r e1 0 . 2 8 . C o l l a t i n g S e q u e n c eb y Z o n e

1G.26

W

z

Collating
Sequence
of Zones

Character

A

Bit
Combination
Zone

Digit

0100

0000

0101

0000

Collating
Sequence
of
Digits

(blank)

&

0 11 0

C ha r a c t e r

Zone

Digit

H

11 0 0

1000

Oor-8

1101

1000

1 11 0

1000

1111

1000

1100

1001

0000

(rninusl

Bit
Combination

6

t
I

1101

0000

+0

1111

000c

R or-9

11 0 1

1001

oo01

z

1110

1001

A

11 0 0

0001

9

1111

1001

Jor-1

1101

0001

Y

0100

1 0 10

1

1111

0001

0101

1 0 10

0 11 1

1 0 10

0100

1 0 11

0101

1 0 11

0 11 0

1 0 11

0 11 0

B

1100

0010

Kor-2

11 0 1

0010

s

1110

0010

2

1111

o010

c

1100

0011

Lor-3

11 0 1

0011

T

1110

0011

1111

001I

D

11 0 0

0100

Mor-4

1101

0100

U

1110

0100

4

1111

0100

tr

1100

0101

Nor-5

11 0 1

0101

1110

0101

J

1111

0101

F

11 0 0

Oor-6

11 0 1

z

c

4

@

0 11 1

1 0 11

0100

1100

0101

11 0 0

0 11 0

1100

0 11 1

1100

0100

1101

0101

r101

0 11 0

1101

0 11 0

0101

1110

0 11 0

0 11 0
0 11 1

J110__
1 11 0

0100

1111

0101

1111

0 11 0

1 1 11

0 11 1

1111

0 11 0

0 11 0

U

1100

0 11 1

Por-7

11 0 1

0 11 1

X

1110

0 11 1

7

1111

0 11 1

12

13

I

I
I

1110

1111

11

(, nO"ra"or")

0100

1110

10

?

1101

o

I

(period)

0 11 1

W

Collating
Sequence
of
Digits

o

f

7

-l
?
I

I

(apostrophe)

I

I
15

I
I
I

16

F i g u r e 1 0 - 2 9 . C o l l a t i n g S e q u e n c eb y D i g i t

Working With Data Stru(:turt)

1O-2i

N o t e t h a t i n t h e c o l l a t i n gs e q u e n c eb y z o n e s h o w n i n F i g u r e 1 0 - 2 8 ,a n y c h a r a c t e ri n g r o u p 5 i s c o n s i d e r e dl o w e r i n
s e q u e n c et h a n a n y c h a r a c t e ri n g r o u p 6 . l f r e c o r o sa r e
s o r t e d i n a s c e n d i n go r d e r b y z o n e , a r e c o r d w i t h t h e l e t t e r
D ( g r o u p 5 ) c o m e sb e f o r ea r e c o r d w i t h t h e l e t t e r N ( g r o u p
6).
N o w c o n s i d e ra c a s ei n w h i c h c h a r a c t e r sf r o m t h e s a m ez o n e
g r o u p a r e t o b e c o m p a r e d . A s s u m eo n e r e c o r d c o n t a i n st h e
l e t t e r D ( g r o u p 5 ) a n d t h e n e x t r e c o r d c o n t a i n st h e l e t t e r F
( g r o u p 5 ) . W h i c h s h o u l d b e s o r t e d f i r s t a c c o r d i n gt o a c o l l a t i n g s e q u e n c eb a s e do n z o n e s ? S i n c et h e c o m p u t e r i g n o r e s
t h e d i g i t b i t s o f e a c h c h a r a c t e r ,t h e y a r e c o n s i d e r e de q u a l
b e c a u s et h e y b o t h h a v et h e s a m ez o n e v a l u e . T h e r e f o r e ,n o
o n e c h a r a c t e rm u s t c o m e e a r l i e ri n t h e s e q u e n c et h a n a n other character from the same group. fhe sequenceof the
c h a r a c t e r si s t h e s a m eo r d e r i n w h i c h t h e r e c o r d sa r e r e a d .
T h u s , i f t h e D c a r d i s r e a d f i r s t b y a s o r t p r o g r a m ,t h e
D r e c o r dc o m e s b e f o r e t h e F r e c o r d . O n t h e o t h e r h a n d ,
i f t h e F c a r d i s r e a d f i r s t , t h e F r e c o r d c o m e s b e f o r et h e
D r e c o r d . I n e i t h e r c a s e ,t h e r e c o r d sa r e i n p r o p e r s e q u e n c e
o a s e oo n z o n e s .

F o r e x a m p l e ,y o u m a y w a n t a l p h a b e t i cc h a r a c t e r st o f o l l o w
t h e n u m b e r si n s t e a do f p r e c e d i n gt h e m . S u p p o s et h a t a c o m p a n y o r i g i n a l l ys t a r t e d w i t h a f e w d e p a r t m e n t s .T h e d e p a r t m e n t s w e r e a s s i g n e dn u m b e r sf r o m 0 1 - 9 9 . T w o c o l u m n s
w e r e d e v o t e dt o d e p a r t m e n tn u m b e r si n v a r i o u sr e c o r o s .
T h e c o m p a n y e x p a n d e da n d d e p a r t m e n t si n c r e a s e d .S o o n
t h e r e w e r e m o r e t h a n 9 9 d e p a r t m e n t s .T o a v o i d h a v i n gt o
c h a n g et h e d e p a r t m e n tf i e l d f r o m t w o t o t h r e e c h a r a c t e r s
i n a l l r e c o r d s ,t h e m a n a g e rd e c i d e dt o u s e t h e l e t t e r so f t h e
a l p h a b e tt o r e p r e s e n td e p a r t m e n tn u m b e r s : 9 9 , A 0 , A 1 ,
e t c . I n t h i s c a s e .A m u s t f o l l o w t h e n u m b e r 9 i n t h e s e q u e n c e . T h u s i t i s n e c e s s a r tyo a l t e r t h e c o l l a t i n gs e q u e n c e
s o t h a t n u m b e r sc o m e b e f o r e a l p h a b e t i cc h a r a c t e r s .
T h e r e c a n b e o t h e r r e a s o n st h a n t h e o n e i u s t e x p l a i n e df o r
a l t e r i n gt h e c o l l a t i n gs e q u e n c e .Y o u r l a n g u a g em a y d e m a n d t h a t y o u h a v ec h a r a c t e r s u c h a sA ' , a ' , ' C i , ' d , f i n c l u d e d i n t h e a l p h a b e t i cs e q u e n c e( A , ' i , B l . S i n c e t h e 6 4
g r a p h i c sd o n o t i n c l u d e t h e s ec h a r a c t e r so, t h e r s e l d o m u s e d
c h a r a c t e r sc a n b e s u b s t i t u t e df o r t h e m a n d r e p o s i t i o n e di n
t h e c o l l a t i n gs e q u e n c e .F o r e x a m p l e ,a n u m b e r - s y m b o l( # )
repositioned between the letters A and B can substitute for
a n A ; a n a t - s y m b o l ( @ l r e p o s i t i o n e db e t w e e nO a n d P s u b stitutes for an'Ci.

A L T E R I N G T H E C O L L A T I N GS E Q U E N C E
A c o l l a t i n gs e q u e n c ei s t h e o r d e r i n w h i c h c h a r a c t e r sa r e a r r a n g e d .A s y o u k n o w , a l l c h a r a c t e r as r e a s s o c i a t ew
dith diff e r e n t n u m e r i c avl a l u e si n o r d e r t h a t t h e c o m p u t e rm a V
r e c o g n i z et h e m . T h e s e q u e n c eo f n u m e r i c a lv a l u e s( a s c e n d i n g o r d e s c e n d i n gs e q u e n c e d
) e t e r m i n e st h e o r d e r i n w h i c h
c h a r a c t e r sa s s o c i a t e dw i t h t h e v a l u e sa r e r e c o q n i z e d .
T h e a s s o c i a t i o nc f a p a r t i c ul a r c h a r a c t e rw i t h a n u m e r i c a l
v a l u ei s a n a r b i t r a r yd e c i s i o n .T h u s ,t h e c o l l a t i n gs e q u e n c e
i t s e l f i s a r b i t r a r y . S y s t e m / 3 i s p r o g r a m m e dt o e x p e c t t h e
c o l l a t i n gs e q u e n c ed i s c u s s e dp r e v i o u s l yi n t h e s e c t i o nC o l lating Sequence of Characters. This does not mean, nowe v e r ,t h a t y o u m u s t a l w a y s u s e t h i s s e q u e n c e .Y o u c a n
c h a n g ei t a n d t h e r e m a y b e t i m e s w h e n V o u d e s i r et o d o s o .

10-28

T h e s ea r e o n l y a f e w r e a s o n sf o r a l t e r i n gt h e c o l l a t i n gs e q u e n c e . Y o u m a y h a v eo t h e r s . J u s t r e m e m b e rt h a t y o u
c a n a l t e r t h e c o l l a t i n gs e q u e n c ei n a n y w a y t h a t f i t s y o u r
neeos.

Specifying Changesin Collating Sequence
T o c h a n g et h e c o l l a t i n gs e q u e n c ey, o u m u s t a s s o c i a t ec h a r a c t e r sw i t h d i f f e r e n t n u m e r i c a lv a l u e s . T h e f o l l o w i n q s e c t i o n s w i l l e x p l a i nh o w t h i s i s d o n e .

gq

a:_E

c

=l*
-l-

.l

_t-

-lo :

l_

I

c

d'6

Fl-

:t=
- t - l=

E

I

5*O

B!!

il

-l

"l-

f

E

u
u

E

I

66
t-

z
E

l;

t;

4

E

T- t-l=l:

l 8I F

-t-

t:l '

I
I

u
u
a

(,

I

z

E-;*

,1"

lg
J
J

ul-

u

o

F

.l

z
G

u
F

C)

J

z

o

u

2
i

k

;

s;_E

z
F

; F

a6

t.
t;

t'

uI

e;!

.l.l"l.l.
"l'l"l'l'

8

ut_t

;- .9
; 6

-l.l-l.l-

x'
gl

;t.

5lB
lBlElE

l.l

Figure10-30, FormsNeededfor Alternatecottatingsequencespecifications
WorkingWith DataStructure

10'29

Forms For Altering the Collating Sequence

Character Associated
with Bit Combination

'l

F i g u r e 0 - 3 0 i i l u s t r a t e st w o f o r m s o n w h i c h V o u m u s t
s p e c i f y c h a n g e st o t h e c o l l a t i n gs e q u e n c e .O n e f o r m i s t h e
R P G l l C o n t r o l C a r d a n d F i l e D e s c r i p t i o ns h e e t ;t h e o t h e r
i s t h e T r a n s l a t i o nT a b l e a n c jA l t e r n a t e C o l l a t i n gS e q u e n c e
C o d i n g S h e e tw h i c h i s u s e df o r l i s t i n gt h e a c t u a l c h a n g e si n
s e q u e n c e "B o t h f o r m s a r e u s e d i n c o nj u n c t i o n w i t h t h e
R P G l l I n p u t , O u t p u t a n d C a l c u l a t i o ns h e e t s .

urapnrc

11110000

Entry

;-|;t

11110001
11110010

ili roori

A l e t t e r . Se n t e r e di n c o l u m n 2 6 o f t n e R p G l l c o n t r o l c a r c l
n o t i t i e s t h e p r o g r a mt h a t a d d i t i o n a l i n f o r m a t i o n w i l l b e
f u r n i s h e 3

2
ts

5 5

=

:
:=

- a

:ts

:==

5 E 5

P 3*

; - e

-.
trl
F'

F i g u r e 1 0 4 4 . F o r m s N e e d e df o r F i l e T r a n s l a t i o n S p e c i f i c a t i o n s
Working With Data Structure

1043

TRANSLATING CHARACTE RS
I n t h e p r e v i o u sd i s c u s s i o ny, o u l e a r n e dt h a t
the program
c a n a l t e r t h e s t r u c t u r eo f c h a r a c t e r sb y m o v i n g
zones. But,
t h r o u g h t h e f i l e t r a n s l a t i o nf u n c t i o n o f t h e R p G
ll language,
i t c a n d o e v e n m o r e . l t c a n t r a n s l a t eo n e
c h a r a c t e ri n t o a n other.
T h e t r a n s l a t i n gf u n c t i o n i s k n o w n a s f i r e t r a n s r a t i o n
because
characterscan be translated either when they
are read in or
before they are recorded in the output file.
Tne program
a c t sl i k e a n i n t e r p r e t e r . J u s t a sa h u m a n i n t e r p r e t e r
transl a t e sl a n g u a g e (sa w o r d i n G e r m a n f o r a w o r d
in English),
t h e c o m p u t e r t r a n s l a t e sc h a r a c t e r sb y r e p l a c i n g
one character with another.

Need for File Translation
T h i n k o f t h e u s e f o r f i l e t r a n s l a t i o nw h e n t r a n s l a t i n g
codes.
Codes are often used as a security measureto prevent
access
t o c l a s s i f i e di n f o r m a t i o n . I n f o r m a t i o n i s r e c o r d e d
on cards
i n c o d e d f o r m . I n o r d e r t o p r o c e s st h e i n f o r m a t i o n ,
it must
be decoded. A coded character must be replaced
bv the cornespondingdecoded character.
l F o re x a m p l e ,a f i r m w h i c h k e e p sa i l i n f o r m a t i o n . c r a s s i f
ied
u s e st h e c h a r a c t e r si n t h e w o r d F I T Z G E R A L D
a sa c o d e
1 ' o rt h e n u m b e r s0 t h r o u g h 9 . F i s t h e c o d e f o r
z e r o ,I f o r
one, etc. When recorded on a card, the number 1432
app e a r sa s I G Z T . l t a f i e l d c o n t a i n i n g I G Z T
is read into the
c o m p u t e r a n d u s e d i n a r i t h m e t i c o p e r a t i o n s ,r e s u r t s
received
€ r r ew r o n g . I G Z T m u s t f i r s t b e d e c o d e d ,o r t r a n s l a t e d
into
't432.

O n l y c o l u m n 4 3 i n t h e R p G l l c o n t r o l c a r d r e l a t e st o
the
c h a n g ei n s e q u e n c e .A l e t t e r F e n t e r e di n c o l u m n 4 3 n o t i _
f i e st h e c o m p u t e r t h a t a d d i t i o n a l i n f o r m a t i o n f u r n i s h e d
for
t r a n s l a t i n gf i l e s . A l r o t h e r c o r u m n sc o n t a i n t h e i n f o r m a t i o n
t h a t m u s t n o r m a l l y b e e n t e r e df o r a p r o g r a m .
T h e T r a n s l a t i o nT a b l e a n d A l t e r n a t e C o l l a t i n gS e q u e n c e
C o d i n g S h e e t l i s t s 2 5 6 b i t c o m b i n a t i o n sa l o n g w i t h t h e i r
hexadeciman
l u m e r i c a lv a l u e s . y o u l e a r n e df r o m d i s c u s _
s i o n so f c h a r a c t e rs t r u c t u r et h a t t h e l e f t _ h a n dn u m b e r
in
t h e h e x a d e c i m a vl a l u e r e p r e s e n t st h e n u m e r i c a lv a l u e
of the
c h a r a c t e r ' sz o n e a n d t h e r i g h t - h a n dn u m b e r r e p r e s e n t s
the
n u m e r i c a lv a l u e o f t h e c h a r a c t e r , sd i g i t . T h e 6 4 p r i n t a b l e
c h a r a c t e r sa r e l i s t e d b e s i d et h e b i t c o m b i n a t i o n a n d h e x a d e c i m a lv a l u e sw i t h w h i c h t h e y a r e a s s o c i a t e d .

Coding the Translation
E a c h c h a r a c t e rt h a t w i l l b e a f f e c t e dd u r i n g t h e t r a n s l a t i o n
o f a s p e c i f i e df i l e m u s t b e i d e n t i fi e d o n t h e c o d i n g s h e e t .
ln the column entitled ReplacedBy, enter the hexadecimal
v a l u e o f t h e c h a r a c t e rw h i c h i s t o r e p l a c et h e c h a r a c t e rp r e s e n t l y a s s o c i a t e dw i t h t h e b i t c o m b i n a t i o n s h o w n . T h i s
m e a n st h a t t h e c h a r a c t e ra s s o c i a t e dw i t h t h e v a l u e f o u n d i n
t h e E n t r y c o l u m n w i l l b e t r a n s l a t e di n t o t h e c h a r a c t e ra s s o c i ated with the value entered in the Replaced By column.
F i g u r e 1 0 - 4 5 i l l u s t r a t e st h e e n t r y m a d e o n t h e c o d i n g s h e e t
t o t r a n s l a t ea c h a r a c t e r . l f a n i n p u t f i l e i s t o b e t r a n s l a t e d ,
t h i s e n t r y m e a n st h a t t h e l e t t e r F w i l l b e t r a n s l a t e da s t h e
n u m b e r 0 ( F 0 i s t h e h e x a d e c i m a vl a l u e a s s o c i a t e dw i t h 0 ) .

Character Associated
with 8it Combination

Sipecifying
File Translation

NumericalValue of
R e p l a c e m e n tC h a r a c t e r

S i p e ciicf a t i o n sf o r f i r et r a n s r a t i oanr ei d e n t i c atro t h o s eu s e d
t o a l t e rt h e c o l l a t i n gs e q u e n c e .
Code

f:orms Used for a File Translation
F i g u r e1 0 - 4 4s h o w st h e f o r m so n w h i c hy o u m u s t
specify
t l ' l ew a y i n w h i c hf i l e sa r et o b e t r a n s l a t e dO
. n ef o r m c o n s i s t so f t h e R P Gl l C o n t r o lC a r da n d F i l e D e s c r i p t i osnh e e t ;
t h e o t h e rc o n s i s tosf t h e T r a n s l a t i oTn a b l ea n dA l t e r n a t e
C o l l a t i n gS e q u e n cC
e o d i n gS h e e tf o r l i s t i n gt h e c n a r a c t e rt so
b e t r a n s l a t e dB
. o t h f o r m sa r eu s e di n c o n j u n c t i o nw i t h t h e
R P Gl l I n p u t ,O u t p u t .a n d C a l c u l a t i osnh e e t s .

11000100
11000101
11000110

System/3
Graphic

Entry

D
E

c4

F

UO

Replaced
By

FO <-

11000111

11001000
11001 001

H

^a

I

ao

N u m e r i c a lV a l u e
of Bit combination

/
L

r i"translated to o

&Position Bit Combination

F i g u r e 1 O 4 5 . E x p l a n a t i o n o f F i l e T r a n s l a t i o nC o d i n g S h e e t

1044

l f t h e o u t p u t f i l e i s t o b e t r a n s l a t e d t, h i s e n t r y m e a n st h a t
t h e n u m b e r 0 w i l l b e t r a n s l a t e db a c k i n t o a n F b e f o r e b e i n g
w r i t t e n o u t . Y o u c a n t h i n k o f t h e c h a r a c t e ra s s o c i a t e dw i t h
t h e v a l u e i n t h e E n t r y c o l u m n a s b e i n g t h e c h a r a c t e rr e a d i n
o r p r i n t e d o u t . O n t h e o t h e r h a n d , t h e c h a r a c t e ra s s o c i a t e d
with the valuesin the Replaced 8y column is the character
r e p r e s e n t eidn t h e m a c h i n e( F i g u r e1 0 4 6 ) .

What Files Should Be Translated?
A n y i n p u t f i l e sw h i c h c o n t a i n i n f o r m a t i o n r e c o r d e di n
c o d e d f o r m s h o u l d b e t r a n s l a t e di f c o r r e c t r e s u l t sa r e t o b e
o b t a i n e d . A l l c h a r a c t e r sw h i c h y o u s p e c i f yt o b e t r a n s l a t e d
a r e t r a n s l a t e dw h e n e v e rt h e y a r e e n c o u n t e r e d . T h i s m e a n s
i f y o u s p e c i f ya n F t o b e t r a n s l a t e dt o O , a l l F ' s r e a d i n w i l l
b e t r a n s l a t e d .W h e n t h e r e a r e s e v e r a ol t h e r f i e l d so n t h e

Differences Eetween File Translation and Alternate
Collating Sequence

c a r d si n a d d i t i o n t o t h e o n e c o n t a i n i n gc o d e d I n f o r m a t i o n ,
r e m e m b e ra l l c h a r a c t e r ss p e c i f i e dt o b e t r a n s l a t e da r e t r a n s l a t e d r e g a r d l e sosf f i e l d s .

B e c a u s eo f t h e s i m i l a r i t y o f e n t r i e su s e d i n c o d i n g a n a l t e r n a t e c o l l a t i n gs e q u e n c ea n d a f i l e t r a n s l a t i o n ,t h e s ef u n c t i o n s
m a y s e e mi d e n t i c a l . T h e y a r e n o t , h o w e v e r . T h e d i f f e r e n c e
o c c u r s i n t h e w a y t h e p r o g r a mw o r k s w i t h t h e c h a r a c t e r si n volved.

W h e n p r i n t i n g o r p u n c h i n gi n f o r m a t i o n o u t , y o u m a y o r
m a y n o t f i n d i t n e c e s s a r yt o s p e c i f yf i l e t r a n s l a t i o nf o r t h e
o u t p u t f i l e s . l f y o u h a v et r a n s l a t e d( d e c o d e d )y o u r i n p u t
f i l e , y o u s h o u l d t r a n s l a t ei n f o r m a t i o n b a c k i n t o c o d e d f o r m
b e f o r e i t i s w r i t t e n o r p u n c h e do u t . l f a l l F ' s a r e t r a n s l a t e d

W h e n a l t e r n a t ec o l l a t i n gs e q u e n c ei s u s e d ,t h e c h a r a c t e r s
a r e a l t e r e do n l y t e m p o r a r i l y f o r s e q u e n c i n go p e r a t i o n s .
T h e o r i g i n a l b i t c o m b i n a t i o n o f t h e c h a r a c t e r ,o b t a i n e d
f r o m t h e p u n c h c o m b i n a t i o n f o r t h a t c h a r a c t e r ,i s n o t

a s 0 ' s w h e n r e a d i n , t h e n a l l O ' ss h o u l d b e t r a n s l a t e dt o F ' s
b e f o r et h e y a r e p u t o u t . K e e p i n m i n d t h a t o n l y c h a r a c t e r s
w h i c h y o u s p e c i f y a r e i n v o l v e di n t h e r e t r a n s l a t i o n .

c h a n g e d . T e m p o r a r y s u b s t i t u t i o no f a n o t h e r b i t c o m b i n a tion is done instead.
F o r f i l e t r a n s l a t i o n ,b i t c o m b i n a t i o n sa r e a c t u a l l y c h a n g e d .
A s a r e s u l t ,o n e c h a r a c t e ri s c h a n g e d( t r a n s l a t e d )i n t o a n o t h e r . T h i s t r a n s l a t i o no c c u r sb e f o r e y o u r p r o g r a m i n s t r u c tions are executed.

W o r k i n gW i t h D a t a S t r u c t u r e

1045

Int.fr

arond

Bunncss M,chiner

(i'ponitun

TRANSLATION TABLE AND ALTERNATE COLLATING
S E O U E N C EC O D I N G S H E E T

Code

0 t 1 0 0 1l 0
0 t 1 0 0 111

66
6l

t0rm
0 1r 0 1 0 0 1

ss

.69
!4_
9!

9f
9F
A0
A1
A2

6C

6ar

l

FE

49
4!
A5

A6

F

A9

F6

i

A8

AC

EFZTG

AD

At

.a

8b
8l

B2
83
B4
B5
q6
q7

InputFile

88

Inputdata is
tra n slated

8F

cg
c1
c]
C3

o c e s s i n gU n i t

a4

F4

q9

Fa
F U

c5

EFZTG+ 50324
50324x10=503240
503240+ EFZTGF

C1
CB
C9
c4
CB

F

I

0

Output File

10.46

F I

F i l e T r a n s l a t i o ns p e c i f i c a t i o nus s e d
f o r t r a n s l a t i n gb o t h i n p u t a n d o u t p u t
f i l e sa s f o l l o w s :

Data is translated
before beingput out

Figure 1O46. File Translatron

E R

iTTTiiIi
2 3 4 5 6 7 8 9

l f y o u d o n o t s p e c i f yf i l e t r a n s l a t i o fno r o u t p u tf i l e s ,i n f o r m a t i o ni s p u t o u t e x a c t l ya si t i s i n t h e m a c h i n e .l f y o u
clo not intendto translatecardor printeroutput files,be
c e r t a i nt h a t a l l c h a r a c t e rf sr o m t h e i n p u t f i l e a r et r a n s l a t e d
i n t o a v a l u ea s s o c i a t ewdi t h a p r i n t a b l eg r a p h i c .A n y h e x a d e c i m avl a l u ew h i c hd o e sn o t h a v ea n a s s o c i a t egdr a p h i c
c a n n o tb e w r i t t e no r p u n c h e do u t ( F i g u r e1 0 - 4 7 1 . l fa n u n p r i n t a b l eg r a p h i ci s s p e c i f i e tdo b e p u t o u t , a b l a n ka p p e a r s
in itsplace.

l.lerntrtbnal

Btrnn$1

Vr.hrnes

( oI$rrlron

. T I O N T A B L E A N D A L T E R N A T E C O L L A T I N G S E O U E N C EC O O I N G S H E E T

A L T E R N A T E C O L L A T I N G S E O U E N C EC O D I N G S H E E T

;v(em/il
Enr'

1 o o 1r o o l i
1 0 o r1 0 1 0 I
1 0 0 11 0 11 l

rbon rco I
r o o tt t o r I
r m r r r r of
i o o r r r r rI
roroom ]
rcroooor I
r o l o o o r oI
r o r o o o r rI
rbrboroo T
r o r o o r o rI
- u o o rr o I
l 0 r m rr r l
rqr1togo I
1 0 1 0 1 0 0Ir
roroiom I
rorolorll
rcr0r 00 I
L 0 1 0 L r 0 rI
r 0 r 01r r o I

C6 (F) when changed
to an A0 cannot be
printed for A0 has
n o a s s o c i a t e dg r a P h i c .
The printer output
f ile must be translatedso that A0
will print out as F.

T s c
1 s o
J s e

I
I
T

l

l

I

iri I

l

Irl\j

ll
l

Iill l

1 i lI\ " ll
A A I

I a ql l
l A c l

:|i5n;\:J

1 0 1 0 1I 1 l

il s8 3?

| 1 o rt o r o l
fmlro
I roruir
f ioinmI roriwr
f rorr iorc
I rorroii
[ rcrriioo
I rorrml
I rottttto
I roirrrii
f iroooooo
r
f iroriomr
e
l llbbooru
I romoi r c
f r iobmoo D

l rioooroi !
I rioborro F
I iromri G
1roolooo
11!0]0o1
lroororo
liooior i

l
L
I

,r-t.[

*loiroooo l
10r10001
[mqoro

I
[
I
I
I

l 9 9
I 9 A
l 9 B

I

qt
89
87
qq
89
8A
l e e

T".
Jeo
J B E
T : l c o

Iai

J cz
I c :
C

lc4
f cs
6

hl
IT

I

ft

t1
I 1
lio
1

t:;

C6 (F) when changed
to a F0 will print
out as a zero. No
further translation
is necessary.

F i g u r e 1 O - 4 7 .P r i n t a b l e G r a p h i c s

Working With Data Structure

10'47

R e c o r d i n gS p e c i f i c a t i o n sf o r t h e T r a n s l a t i o n
Table
A f t e r y o u h a v ew r i t t e n a i l s p e c i f i c a t i o n sf o r f i r e
transration,
you carireccrdthem so that they can
b e e n t e r e di n t o t h e
s y s t e r n " R e c o r d sc o n t a i n i n gt h e s es p e c i f i c a t i o n s
must be
formatted as follcrws:

Positians

Entry

1 6
or
t-u

'FILES
A filerrame

7-8

B l a n ki f n o t r e r l u i r e d

9-96

N u r n e r i c avl a l u e si n v o l v e di n t r a n s l a t i n g
characters

l f a l l f i l e s( b o t h i n p u t a n d o u t p u t ) a r et o b e t r a n s l a t e d ,
use
t h e e n t r y - F I L E S i n p o s i t i o n s1 t h r o u g h6 . l f o n t y
onefile
t s t r a n s l a t e du, s et h a t f i l e n a m ei n p o s i t i o n s1 t h r o u g hg .
lf
: i e v e r a tb, u t n o t a l l f i l e s ,a r e t o b e t r a n s l a t e d y, o u
mu5t for_
r n a t s e p a r a t er e c o r d sf o r e a c hf i l e _
I n p o s i t i o n sg t h r o u g h 9 6 , t h e r e a r e 2 2 g r o u p so f f o u r p o s i _
1 . i o n s .E a c h g r o u p ( 9 - 1 2 , 1 3 - 1 6 ,e t c . ) m u s t c o n t a i n
two
l r e x a d e c i r n avla l u e si r - r v o l v eidn t h e t r a n s l a t i n go f
one char_
a c t e r . T h e f i r s t t w o p o s i t i o n so f t h e g r o u p a r e f o r
the hexad e c i m a l v a l u et a k e n f r o n r t h e E n t r y c o l u m n o f t h e
Translat i o n T a b l e a n d A l t e r n a t e C o l l a t i n gS e q u e n c eC o d i n g
Sheet.
'll-he
l a s t t w o p o s i t i o n sa r e f o r t h e h e x a d e c i m a vl a l u e t a k e n
f r o m t h e R e p l a c e dB y c o l u m n o f t h e c o d i n g s h e e t .

1Cr-4B

More than one record can be used to specify the
characters
w h i c h m u s t b e t r a n s l a t e d . H o w e v e r ,e a c ha d d i t i o n a l
record
m u s t b e f o r m a t t e d i n t h e s a m ew a y a s t h e f i r s t . A l l r e c o r d s
f o r o n e f i l e m u s t b e g r o u p e dt o g e t h e r . A n e r r o r w i l l
occur
i f f o u r r e c o r d sa r e e n t e r e di n t h e f o l l o w i n g o r d e r :
1.

F IL E A

2.

FILEA

3.

FILEB

4.

FILEA

A l s o , t h e f i r s t b l a n k a p p e a r i n gi n p o s i t i o n s9 t h r o u g h 9 6 i s
r e c o g n i z e db y t h e c o m p u t e r a s t h e e n d o f t h e t r a n s l a t i o n
s p e c i f i c a t i o n s .C o n s e q u e n t l yb l a n k ss h o u l d n o t a p p e a rb e _
t w e e n p a i r so f h e x a d e c i m a vl a l u e s .
A r e c o r d c o n t a i n i n g * * 6 ( t w o a s t e r i s k sa n d a b l a n k ) i n p o s i _
t i o n s 1 t h r o u g h 3 m u s t p r e c e d et h e f i l e t r a n s l a t i o nr e c o r d s .
A l l r e c o r d su s e d f o r f i l e t r a n s l a t i o ne x c e p t t h e R p G l l c o n t r o l c a r d m u s t f o l l o w R P G l l i n p u t , c a l c u l a t i o n ,a n d o u t p u t
s p e c i fi c a t i o n sa n d m u s t p r e c e d ea n y t a b l e so r a l t e r n a t ec o l l a t i n g s e q u e n c er e c o r d su s e d .

Review10

CharacterStructure
1.

l n t o w h a t t w o p o r t i o n sm a y e v e r yc o l u m no f a 9 6 - c o l u m nc a r da n d e v e r yb y t e i n
storaga
e n do n d i s kb e d i v i d e d ?

2.

that havean A zonepunchedin the zoneportion of a 96'column
Do all characters
in storage?Why or why not?
cardhavethe samezonerepresentation

3.

C a l c u l a t teh e n u m e r i c avl a l u eo f e a c ho f t h e f o l l o w i n gb i n a r yn u m b e r sa sr e c o r d e di n
one byte of storage:
a . 11 0 0 0 1 0 0 .
b.11010101.
c.11101000.
d. 11110011.

4.

Expressthe numericalvalueof the bytesshownin Ouestion3 asa pair of numbers
( h e x a d e c i mvaal l u e )r, a t h e rt h a na sa s i n g l ev a l u e .

CollatingSequenceof Characters
5,

of characters?
Whatdoesthe computeruseto determinethe collatingsequence

6.

A r r a n g et h e f o l l o w i n gc h a r a c t e ri sn a s c e n d i ncgo l l a t i n gs e q u e n c eA. r r a n g et h e s a m e
by zoneand digit.
collatingsequence
in ascending
characters
Character

Hexadecimal
Value

c3

195

61

97

D7

215

D1

2@

5C

92

trQ

227

D9

217
245

4

6

Numerical
Value

50

80

F9

249

FO

240

Review 10

1O-49

Altering the Collating Sequence
7.

F i l l i n t h e A l t e r n a t e C o l l a t i n gS e q u e n c e
C o d i n g S h e e tt o :
a . I n s e r t . U b . t * . . n t J a n d V ( u s et h e
#signio r"pr.r.n, iit.
b . M a k e a b l a n k f a l l i n t h e s a m es e q u e n c e
aszero.
Show how this informationwould be recorded
i n a n a l t e r n a t ec o l l a t i n gs e q u e n c e
record.

8'

I n w h a t R P G t o p e r a t i o n si s t h e a r t e r n a t e
c o t a t i n g s e q u e n c eu s e d ?

9.

W h e r ei s t h e s i g n l o c a t e di n a n u m e r i c f i e l d ?

Altering the Structure of Characters
10.

T h e T E S T Z o p e r a t i o n c h e c k st h e z o n e so f :
a. any positionin a field.
b . o n l y t h e l o w - o r d e rp o s i t i o n i n t h e f i e l d _
c . o n l y t h e h i g h - o r d e rp o s i t i o n i n a f i e l d .

11'

A f i e l d m a y b e a l p h a m e r i cf o r a n y m o v e z o n e
o p e r a t i o n s . c h e c k t h o s e f i e l d s( F a c t o r
2 , R e s u l t )w h i c h c a n b e n u m e r i c f o r t h e f o t o w i n g
move zone operations:

Operation

'12.

a.

MHLZO

b.

MLHZO

c.

MLLZO

d.

MHHZO

Factor 2

Result

c o d e t h e c a r c u r a t i osnp e c i f i c a t i o nt os m a k et h e
c o n t e n t so f a p o s i t i v en u m e r i c
A M T D U Ef i e l d n e g a t i v e .

TranslatingCharacters
13'

what is the differencebetweenthe way the computer
workswith characters
invorved
in an alternatecollatingsequence
and the way it works with characters
involvedin
filetranslation?

14.

F i l l i n t h e c o d i n gf o r m st o t r a n s r a t4e, s t o / , s
a n dg , s t o 3 , s . s h o w h o w t h e s es p e c i _
ficationswould be recordedin a translation
tablerecordwhen all filesareto be
translated.

AnswersTo Review10

'I

.

2.

Zone and digit.
A l l c h a r a c t e r sw h i c h h a v et h e s a m ez o n e p u n c h i n a 9 6 - c o l u m n c a r d d o n o t n e c e s s a r i l y h a v et h e s a m ez o n e r e p r e s e n t a t i o ni n s t o r a g e .T h e r e a r e f o u r z o n e b i t s f o r
e a c hc h a r a c t e ri n s t o r a g ea n d o n l y t w o z o n e p o s i t i o n si n a 9 6 - c o l u m n c a r d c o l u m n .
T h e r e f o r ea t r a n s l a t i o nm u s t t a k e p l a c ew h e n t h e c h a r a c t e ri s r e a d . T h e c o m p u t e r
c h e c k st h e e n t i r e p u n c h c o m b i n a t i o n ( b o t h z o n e a n d d i g i t ) o f a c h a r a c t e rt o d e t e r m i n e
w h i c h b i t s a r e t u r n e d o n o r o f f i n o r d e r t o r e p r e s e n t t h ec h a r a c t e ri n s t o r a g e .

3.

a. 196

1 1 0 0
0 1 0 0
1 2 8 + 6 4 + 0 + 0+ 0 + 4 + 0 + 0 =1 9 6
b. 213
c.232
d. 243
4.

a. C4
1 1 0 0
0 1 0 0
c=8+4+0+0 + 0+4+0+0=4
b. D5
c. E8
d. F3

5.

the
T h e c o m p u t e ru s e st h e n u m e r i c avl a l u e sa s s o c i a t ewdi t h c h a r a c t e rt so d e t e r m i n e
of characters.
collatingsequence

A n s w e r sT o R e v i e w 1 0

1O-51

6.

w h e n c h a r a c t e r sa r e c o i l a t e d b y z o r r ea n c rd i g i t , t h e y
arecolated in this order:
Character

I

Numerical
Value

80
92
97
195
209
215
217
227
240
244
249

W h e n c h a r a c t e r sa r e c o l l a t e d b y z o n e t h e l e f t h a l f o f
t h e h e x a d e c i m a vl a l u e i s u s e dt o
d e t d r m i n et h e o r C e r ; w h e n c o l l a t i r i gf r y t l i g i t t h e r i g h t h a l f
o f t h e h e x a d e c i m avl a l u e i s
u s e d . W h e n c h a r a c t e r sa r e c o l l a t e d b y z o n e o r d i g i t , s e v e r a l
m a y h o l d t h e s a m ep o s i t i o n i n t h e s e q u e n c ea n c lt h u s b e i o n g i n t h e s a r n eg r o u p .
within that group tney may
hold any posltion.

C h a r a c t e r sc o l l a t e d b y z o n e a r e i n t h i s o r d e r :
Character

E )
t

C h a r a c t e r sc o l l a t e d b y d i g i t a r e i n t h i s o r d e r :

Hexadecimal
Value Used

Character

qo

0 tr
^

lc

l

/ t

91

( -

Q3
P ' ,
t

I
;

-!

Hexadecimal
Value Used

Fq
5g
61
D.!

g7

c j
) *
I

pl

I

'

c3
E3

D9

4

F4

trJ

P

D7

f4

R

.T
4
9

;

I)

F9

I

r

I

).*

I

D9
F9

\

o . l

10-52

rU

Characters within brackets
rnay be in any order since
they are in the same group,

5C
*

Characters
within brackets
rnay be in any order since
they arein the same6oup.

7.
Iniernaricnil

tsusincs Mr.lin.r

(orpo.arol

SHEET
COLLATING
S E O U E N CCEO D I N G
T R A N S L A T I OTNA B L EA N DA L T E R N A T E

9E
9l

nq
ar .AtA5

A8

l],
lq=
.zq]E
lF_

qa
81,
82
83

C3

c5
cq
cl
c8

qs_
CA
c8

A L T S EO

4 g F g E 5 7 B E6 E 5 E 7 E6 E 8 E 7 E 9 E 8

EAE9

B

B
a

a

1

2
1

, 6 , ? , . , 9 t r o 3 | ] ? B

a
2
l

B

5 d 5 e 6 0 6 r & 6 3 6 '

2
1
B

a
2
l

l

Answers To tleview t 0

10-53

8.

An alternatecollatingsequence
is usedonly for alphamericcompareoperationsand
matchingor sequence
checkingoperationsdoneon matchfields.

9.

The signof a numericfield must be in the low-order(rightmost)position
of the loworder byte.

10. c
11.

Factor2
a.

b.x
c.X

ResultField
X
X

d.

12.

RPG CALCULATIONSPECIFICATIONS

**[]"_'J::riil",."
[TTl_t]

13'

In file translationa characteris actuallytranslatedinto anothercharacterbecause
the
computerchangesbit combinations.All affectedcharacters
arechangedfor the entire
program.The bit combinationsfor characters
involvedin an alternatecollating
sequence
are not changed.Bit combinations
aresubstitutedfor othersduringsequencing
o p e r a t i o nosn l y .

14.

lnhrnafi

onrl

lJusnr$

M.rhrn.s

(irootrlror

T R A N S L A T I O N T A B L E A N D A L T E R N A T E C O L L A T I N G S E O U E N C EC O D I N G S H E E T

System/3
Cod.

o r r ( n rl o I
o r i , n ri i I
olorpoo J
0 11 0 1 0 0 1
o rr u r o r o I
oiorbr I .
oiiorob I rr
oiloiror T
oiroiro i
0 1 1 0 r 1 1I 17
nn ioooo I
0 rr r 0 0 0 1 I
o r r r o o r oI
o 1 r 1 0 o rl1
b r r i o r o oI
0t 11 0 1 0 1
o t r t o tr o I
01110111

lil rlboo ]
0 r 1r 0 0 r I
otrtotol,
orrior I r
orrirrco T cJ
- uo it rt irrnr o r I
i
orrrnr I "
roooooooT
romoor i

10000010
L
roooool L
rooooioo
I
ioooororI
ro J
roooor
loomrii f
roooreoo1
imrooi T
romroloI
imoiori I
mbrroo I
r o o o r r o Ir

' r 1m0o0 i0i 1r 1r 1| 0
T
I rooiooooI
I roormor f
I r o o r o o r oI
| 1 0 0 1 010 1l
I r 0 0 r 0 r 0 0|
flooroiol I
llmreim T
rooirobol

Graphic

Enl

66

1

67

|

|

l o s T
T a g T

I
I

I q6 8 r I1

l|

j 6 c

I

I

l a o

I

I

l q F
t 7 0
l 7 r
liz
i z:
1 ,o
1' i rt cz

I
t
I
I
I
I
T

I
I
l
I
I
I
I

lu. I

I

1q-qqooo
10100001
1q r lrqqlg
101000il
I ot ooroo
r0100101
1 0 1 0 0t10
r o l o o ri i
roiorooo
rororoof
ioi o1oio
I 0 1 0 1 011
r 0 1 0 r1 0 0
o ri o r i o r
' rr o
oir io
r b i o l 1 r1

I

l|

1
' oT I
t
I )e
l r c

T
T

I 7D
I - "

l

]F

t00llool
100I010
1 0 0 11 0 11
1 0 0 111 0 0
_ 1 0 ! tl t o l
1 0 0 1 1I 0
10011111

l

1 /,8 , i1
A

ll
l
I

I

L

2:, I

I
1
]
I
I
T
I
I
I
i

a4

8

a

l

; n l
8 c l
8!
l
I 8 E l
I s F l
1
I 90
I
|

;
I

I

9C
9E
9F
AO

101|110
ioiir ir r
11000000t
i mooor
iloobom
ioooorr
1r 0001
00
11000101
rroooro
1rq0!1ll

BA
BC

li1 :

c1

s

^ -"
Y
96

1f
1

l

I

gs

I

| 11001m]
f-roor oio
t limiori

t;

l

I
|
E

T c r
)

l o z
l ^ a
1 "ls4
f D5
j D a
f az

t

n

I

t

I
o

lol

x
;e
r\
N
o
P

l
|

l

o

I

!10100L]
!0lq1Q0
L10lltol
1!qlql10
11 0 1 0111
o
1 t 0 tt m 0
1rct 1001
r r01rc10
11qlr011
il01i100
1 1 0 1r 0 1
1r011110
lottttt
11100000
1 rl m o o l
riroouo
!
l110ool1
111 0 0 1 0 0 {

D

S

l o s
r;;

l

l

l

I
T
+
I
I
+
I

I
l
l
l
l
l
l

I

I

l

I

I

l o a I
I o c f
F
:u c:
II
I
l D ? t
I

-^

tr

I r i I
lt e- ^z IT
i

t

+ EJ
E

4

-

+

L

CO

t::

L

Lr 109!1q
lllml!1
1r r 0 r o o 0
l l t q 10 0 1
r L1gl0r0
1110r011
il101100
. r11011q]
11101I1Q
-.,11!A!1la
11r.1.0.9qq
__l!!!olqr
1 11 0 0 1 0

8g

8l
8F

l c c
I co

110011,10
11001111

t

A}
E0
qr
B2
83
B4
qq
8q

I

11 0 0 1 0 0

!!1q0o0
11010081

l
l

qZ
qq

i
I
I

q

9C

AC
AD

I
IF
l

; ; l

I

ByiTakes
Pla.e Oi

EntV

Graphic

I

A9

1 0 11r 0 0 l
L 0 11r 0 1 0
1
10',!110r
- 10111100
10111r01

-

9S
9A

A8

u u l
-c :o +t

Syilem/3

By/Takes
PlaceOi

As
Ao

1 0 11 0 l o L
1 0 11 0 11 0
1 0 11 0 111

;s a: lf

Enrr

41
42
8?

I 01I lrlrqo
lol 10001 I
101Lqllq
1 0 r1 0 011

-

II '8 o
II
1

T F I L E S

a

Sysiem/3

BylTakes

Graphrc

__

fa

fct
c5
c6
l c 7

11110101

L!LtqI
I rrllo0l
fr r roio
| 1111r0r1

l c q

L::

l l t

l c B

|
|

1 l
1l

11 1 0 1
r1110
tilt

C 1 F 1 C 2 F 3

B

a

a

2

2

a

a

2
1
B

2
l
B

a
2
l

A n s w e r sT o R e v i e w 1 O

10-55

10-56

Chapter11. DEBUG

C H A P T E R1 1 D E S C R I B E S :
How to usethe DEBUGoperation.
Format of recordscreatedby DEBUG.

B E F O R ER E A D I N GT H I S C H A P T E RY O U S H O U L DB E A B L E T O D E S C R I B E :
RPG ll logic for indicators lseeChapterl, RPG ll Logicl.

A F T E R R E A D I N GT H I S C H A P T E RY O U S H O U L DB E A B L E T O :
to employ the
Codethe Control Card and Calculationspecificationsnecessary
DEBUGoperation.
Placethe DEBUGoperationwithin your programso that it will providemeaningful
data.
/Vote.' You can usethe reviewquestionsat the end of this chapterto test your comprehensionof this topic. Answersfollow the reviewquestions.

DEBUG 11.1

INTRODUCTION
A p r o g r a mt h a t y o u w r i t e m a y n o t a l w a y sw o r k p e r f e c t l y
t h e f i r s t t i m e o r e v e nt h e f i r s t f e w t i m e s i t i s r u n . f h e
r e a s o nf o r t h i s i s t h a t t h e p r o g r a mc o n t a i n se r r o r s - e r r o r s
t h a t y o u w e r e n o t a w a r ey o u w e r e m a k i n g w h e n y o u w r o t e
t h e p r o g r a m . S o m e o f t h e e r r o r sy o u c a n m a k e a r e e a s yt o
find;others may be very diff icult to find. Nevertheless,
t h e y a l l h a v et o b e c o r r e c t e d . B u t h o w d o v o u d o t h i s ?
W h e r ed o y o u s t a r t ?
J u s t k n o w i n g t h e t y p e s o f e r r o r sw h i c h a r e c o m m o n l y m a d e
c a n g i v e y o u a h i n t a s t o w h a t y o u s h o u l d c h e c k . l v 4 o sot f
t h e e r r o r sm a d e f a l l i n t o o n e o f t h e f o l l o w i n g c a t e g o r i e s :
a

l n c o r r e c t u s e o i R P G l l e n t r i e so n t h e s p e c i f i c a l . i o n s
sheets.

.

E r r o r s i n d e s c r i b i n gi n p u t d a t a o r t h e f o r m a t o f o u t p u t
data.

I t w o u l d c e r t a i n l yb e h e l p f u lt o y o L rt o f i n c lo t . r tl u s t h o w
f a r a l o n g i n y o u r p r o g r a me v e r y t h i n gi s w o r k i n g c o r r e c t l y .
B u t h o w c a n y o u f i n d o u t i n f o r r n a t i o ny o u r p r o g r a m i s
w o r k i n g w i t h a t v a r i o u sp o i n t si n y o u r p r o q r a r n ?
T f r e R P G l l l a n g u a g eh a s a s p e c i a lo p e r a t i o nc o c l ew h i c h
s h o w sy o u s o m e o f t h e i n f o r m a t i o n t h e c o m p u t e r i s w o r k i n g w i t h . T h i s c o d e i s k n o w r ra s t h e D E B U G c o d e . T h e
c o d e r e c e i v e di t s n a m e f r o m t h e s l a n gt e r r n " b u g s " w h i c h
i s u s e dt o m e a n e r r o r s i n a p r o g r a n r . T o t l e b u ga p r o g r a m ,
t h e r e f o r e ,m e a n st o g e t a l l t h e e r r o r so u t o f i t . T i r i s i s w h a t
t h e D E B U G c o d e h e l p sy o u d o .
T h e D E B U G c o d e w i l l c a u s ea m a x i m u m o f t w o d i f f e r e n t
t y p e s o f r e c o r d st o b e p r i n t e d o r p u n c h e r io u t s h o w i n g
you:
o W h a t d a t a i s c o n t a i n e di n a s p r e ciief d f i e l d .

o

E r r o r s i n s p e c i f y i n gt h e c a l c u l a t i o no p e r a t i o n s .

o S p e c i f y i n gc a l c u l a t i o no p e r a t i o n si n t h e w r o n g s e q u e n c e .
T h e R P G l l C o m p i l e r ,w h e n c o m p i l i n gy o u r p r o g r a m ,w i l l
d i a g n o s et h e s p e c i f i c a t i o n tso s e e i f t h e y c o n t a i n e r r o r s . l f
t h e y d o , t h e c o m p i l e r w i l l p r i n t m e s s a g etse l l i n g y o u t h e
e r r o r sm a d e . l n t h i s w a y , y o u c a n f i n d e r r o r sm a d e :i n t h e
s p e c i fi c a t io n s .

USINGTHE DEBUG FUNCTION
Y o u m a y , h o w e v e r ,h a v e m a d e a l l c o r r e c t e n t r i e so r - rt h e
s h e e t sa n d s t i l l g e t t h e w r o n g r e s u l t s . W h a t c a n y o u o o
t h e n ? Y o u c a n , o f c o u r s e ,c h e c k t h r o u g h y o u r w o r k . B u t
t h i s d o e s n o t a l w a y ' ss h o w y o u w h e r e t h e e r r o r ( s )l i e s .
S o m e t i m e s ,t h e s p e c i fi c a t i o n sy o u w r i t e w i l l n o t c a u s et n e
computer to do what you think they will. lt is often poss i b l et o m i s sa n e r r o r b e c a u s ey o u a s s u m et h a t a s t a t e m e n t
o r g r o u p o f s t a t e m e n t sn e e d e dt o p e r f o r m a c e r t a i n t a s k
w o r k c o r r e c t l y ,w h e n , i n f a c t , t h e y d o n o t . F o r e x i a m p l e ,
y o u m a y p a s ss t a t e m e n t0 6 b e l i e v i n gi t i s c o r r e c t w h e n i t i s
n o t a n d s p e n dh o u r sl o o k i n g f o r e r r o r si n t h e r e s to f t h e
s t a t e m e n t sw h i c h a r e r e a l l Vc o r r e c t .

.

W h a t i n d i c a t o r sa r e o n .

O n e o f t h e m o s t c o m m o n e r r o r sf o u r r d i n a p r o g r a m i s t h e
i n c o r r e c tu s e o f i r r d i c a t o r s .l f t h e p r o g l r a r r r r r rf ea ri l s t o
t h o r o u g h l yu n d e r s t a n dR P G l l l o q i c ,h e m a y c o r r d i t i o na n
o p e r a t i o nu s i n ga n i n d i c a t o rw h i c h h e t h i n k s i s o n w h e n i t
i s r e a l l y n o t . T h u s t h e p r o g r a md o e s n o 1 v v o r k p r o ; t e r l y .
l f , a t a n y p o i n t i n y o u r c a l c u l a t i o n sy,o u w a n t t o c h e c kt o
s e ei f y o u a r e u s i n g i n d i c a t o r sp r o p e r l y y o u c a r rs p e c i yf
-fhis
DEBUG.
c o d e w i l l c a u s ea r e c o r d t o b e p u t o u t s h o w i n g w h a t i n d i c a t o r sa r e o n a t t h e p o i r r tD E B U G i s s p e c i f i e d .
l f y o u w i s h t o k n o w t h e c o n t e n t so f a f i e l c li n a d d i t i o n t o
k n o w i n g w h a t i n d i c a t o r sa r e o n , y o u c a n a l s o s p e c i f ys o i n
t h e D E B U G s t a t e m e n t . A s e c o n dr e c o r d t y p e w i l l t h e n b e
p u t o u t s h o w i n g t h e c o n t e n t so f t h e f i e l d .

S p e c i fi c a t i o n sf o r D E B U G
W h e n u s i n g D E B U G , t h e f i r s t s p e c i fi c a t i o r .wr h i c h y o u m u s t
m a k e i s o n t h e c o n t r o lc a r d . A / i n c o l u m n 1 5 i n d i c a t e s
t h a t D E B U G i s g o i n gt o b e u s e d( s e eF i g u r e1 1 - i ) . l f t h i s
c o l u m n i s l e f t b l a n k , a l l D E B U G s t a t e m e n t sw i l l b e t r e a t e d
a 5c o m m e n t s .
l ' h e n i n c o l u m n s 2 8 - 3 2 ( O p e r a t i o n )o n t h e C a l c u l t i o n
s h e e t ,s p e c i f y t h e c o d e D E B U G . Y o u m a y s p e c i f y i t a t a n y
p o i n t i n t h e c a l c u l a t i o n sa n d a s m a n y t i r n e sa s y o u w a n t .
F o r e a c h D E B U G s t a t e m e n t ,e n t e r i n c o l u m n s 3 3 - 4 2 ( F a c t o r
2 ) t h e n a m eo f t h e f i l e o n w h i c h D E B U G r e c o r d sw i l l b e
'l
w r i t t e n o r p u n c h e d ( s e eF i g u r e 1 - 1 ) . U s e t h e f i l e n a n r e
p r e v i o u s l ya s s i g n e do n t h e F i l e D e s c r i p t i o ns h e e t . T h e s a m e
o u t p u t f i l e m u s t b e u s e df o r a l l D E B U G o p e r a t i o n si n a p r o gram.

11-2

RPG CONTROLCARD Af'tD FtLE DESCRtpTtONSPECtFICAT|ONS
Illlil

,.,.,,",-.

",",s "*,d

GX21S2

UM/m.

cotu,eron

t o n c h ,Tr y; ; * " f

^'l"il [

l

I

f

tl

[T&,dth;n.*,'l

""* fTT-l L]-i-l ---

l

**|.i1'*[nri;.".
tTfllll

Control Card Specif ications

Reler to he rrific

System Rere.ene Lib..ry manual ror actu.r entie!

T ' f r ee r r t r y ' l i n r h i s c o l u r n ni n d i c a t e sl h a t a l l D E B U G
s p o c i f i c a t i o n ss h o u l d b e p e r f o r m e d ; a b l a r r k i n d i c a t e st h a t
a l l D E B U G s p e c i f i c a t i o n sw i l l b e t r e a t e d a s c o m r n e n t s .

RPG

C A L C U I - A T I O NS P E C I F I C A T I O N S

, , , , , . " "l ;. ; J
t,

iil-f

,i
i

fc;ru,.-Nffir
I
|

r . _ l

l

,-ri
"*LLl.

o

'l
F i g u r e 1 - l . S p e c i fi c a t i o n s f o r D E B U G

DEBUG 1'I.3

The entriesjust described
will giveyou a recordshowing
w h a t i n d i c a t o rasr eo n . l f y o u a l s ow a n t t o k n o w t h e c o n t e n t so f a f i e l d ,y o u m u s tm a k ea n o t h e re n t r y : T h e n a m e
of the field whosevalueyou wish to know must be entered
a st h e R e s u l tF i e l di n C o l u m n s4 3 - 4 8( s e eF i g u r e1 1 - 2 , i n s e r tA ) .

Format of RecordsCreatedby DEBUG
Two recordsmay be createdby the DEBUGrcperation.
Record1 is required;Record2 is optional. Flecord1 (Figu r e 11 - 3 )w i l l l o o k l i k et h i s :

C o l u m n s1 8 - 2 7( F a c t o r1 ) a r eo p t i o n a l . l f y o u h a v es e v e r a l
DEBUGstatements,
you may wish to know which records
werecausedby a particularDEBUGstatement.\,ou can
n a m et h e D E B U Gs t a t e m e nbt y e n t e r i n ga l i t e r a li n c o l u m n s
1 8 - 2 7 .T h i s n a m ew i l l t h e n b e i n c l u d e di n t h e r e c o r d sw h i c h
t h e s t a t e m e ncta u s etso b e p u t o u t ( s e eF i g u r e1 1 " 2 ,i n s e r t
B).
C o fu m n s7 - 1 7m a y c o n t a i na n y v a l i dc o n d i t i o n i n ignt d i c a t o r .
T h e e x t e r n ailn d i c a t o r U
s 1 - U 8a r em o s to f t e n u s e dh e r e .
T h e y m a k et h e D E B U Gs t a t e m e not p t i o n a l .T h r o u g ht h e i r
u s ey o u c a ne s t a b l i s hp.r i o rt o a r u n , w h e t h e ro r n o t y o u
wish to useDEBUG (seeChapterS, Controlling O'perations
in an RPG ll Programfor usesof U1 to Ug). Columns
53-59cannotbe usedfor the DEBUGstatement.

RPG

Entry

1-8

D E B U G=

9 - 16

The nameenteredin Factor 1 of the debug statement.Thesecolumnswill be
b l a n ki f n o e n t r y i s f o u n d i n F a c t o r1 .

17-18

Blank

19-33

I N D I C A T O RO
SN=

34

Blank

35-37,
38-40,
etc.

Nameof the indicatorswhich areon.
E a c hi n d i c a t o irs f o l l o w e db y a b l a n k .
lf a largenumberof indicatorsareon,
morethan one recordmay be required
to showall indicators.

CALCULATION SPECIFICATIONS

l,--l

i

i- l_l-Jffi

""'['-"r-I-i:L

F i g u r e 1 1 - 2 . A d d i t i o n a l E n t r i e sW h i c h C a n B e M a d e f o r D E B U G

114

Positions

F l e c o r2d ( F i g u r e1 1 - 3 )w i l t t o o kt i k et h i s :

e x a m p l e ,i f y o u a r e c o n c e r n e da b o u t t h e s t a t u so f a n i n d i c a t o r a t a c e r t a i n p o i n t i n y o u r p r o g r a m ,b e s u r e t o p o s i t i o n
D E B U G s o t h a t t h e i n d i c a t o r h a s n o c h a n c et o c h a n q eb e fore it is displaved.

Positions

Entry

1-14

F I E L DV A L U E -

1 5-

T h e c o n t e n t so f t h e f i e l d n a m e da s t h e
r e s u l tf i e l d i n t h e d e b u g s t a t e m e n t . l f
t h e f i e l d i s r a t h e rl a r g e o
, nly 80 of the
r i g h t m o s t c h a r a c t e r sa r e d i s p l a y e d .

l f y o u w a n t t o f i n d o u t i f a s t a t e m e n to r g r o u p o f s t a t e mentsis working correctlyyou must know what is in the
f i e l d i n v o l v e di m m e d i a t e l yb e f o r e a n da f t e r t h e s t a t e m e n t ( s ) .
T h i s m e a n sp l a c i n gD E B U G b e f o r e a n d a f t e r t h e s t a t e m e n t ( s )y o u a r e c h e c k i n g . I n o r d e r t o d e t e r m i n ei f t h e r e s u l t so b t a i n e d f r o m t h e s es t a t e m e n t sa r e c o r r e c t ,y o u w i l l
h a v et o m a n u a l l ym a k e t h e s a m ec a l c u l a t i o nas n d c o m o a r e

G e t t i n g R e s u l t sf r o m D E B U G
DTEBUG
w i l l n o t a u t o m a t i c a l l yp r o v i d ey o u w i t h t h e s p e c i ifc
r e a s o ny o u r p r o g r a m i s i n e r r o r . B u t b y s h o w i n gt h e i n d i c a _

t h e t w o r e s u l t s . I n t h i s c a s e ,h o w e v e r ,y o u m u s t m a k e c e r t a r n y o u r o w n c a l c u l a t i o n sa r e c o r r e c t . M u c h t i m e c a n b e
w a s t e dt r y i n g t o m a k e t h e c o m p u t e r a r r i v ea t t h e s a m e
w r o n g a n s w e ry o u h a v ec a l c ul a t e d .

t o r s e f t i n ga n d c o n t e n t so f f i e l d s a t v a r i o u sp o i n t s , i t c a n
g v e y o u a c l u e a s t o w h e r e t h e e r r o r l i e s . F r o m t h e r e ,y o u
w i l l h a v et o w o r k t h r o u g h t h e l o g i c o f s e c t i o n si n y o u r p r o _
gram to f irrd specific bugs.

M a k i n g Y o u r P r o g r a mW o r k f o r A l l C a s e s

P l a c e m e n to f D E B U G

B e c e r t a i n t h a t y o u t e s t y o u r p r o g r a mt o s e et h a t i t w i l l
h a n d l ec o r r e c t l ya l l p o s s i b l es i t u a t i o n sw h i c h m i g h t a r i s e .
l f y o u t e s t f o r o n l y o n e o r t w o s i t u a t i o n s .V o u c a n b e s u r e
y o u r p r o g r a mw o r k s o n l y f o r t h o s e s i t u a t i o n s . T h i s m e a n s

D E B U G s t a t e m e n t cs a n b e p l a c e da n y w h e r ei n t h e c a l c u l a t i o n s . H o w e v e rm u c h t h o u g h t s h o u l d b e g i v e nt o t h e i r p o s i t i o n . l f t h e y a r e n o t p l a c e di n p r o p e r p o s i t i o n s ,r n e y m a y
g i v em i s l e a d i n g
i n f o r m a t i o na n d b e o f n o h e l p a t a l l . F o r

that the data you use to test your program be complete
a n d v a l i d s o t h a t i t t e s t sa l l p o s s i b l es i t u a t i o n s I. n t h i s w a V ,
y o u c a n b e s u r ey o u r p r o g r a mc a n h a n d l ea l l s i t u a t i o n s
w i t h o u t e n c o u n t e r i n gh i d d e n ' b u g s ' .

Record1
I

D E B U G= D E B U G 1

I N D I C A T O R SO N

20 42 02 11 MR

I

Record 2
I

FrELD VALUE = 005648219R

F i g u r e1 1 - 3 . F o r m a t o f D E B U G R e c o r d s

DEBUG

11 . 5

1r-6

R e v i e w1 1

1.

W h a td o e sD E B U Gd o i n a n R P Gl l p r o g r a m ?

2.

W r i t ea D E B U Gs t a t e m e nt to d i s p l a yo n t h e f i l e c a l l e dO U T F I L Ea f i e l d c a l l e d
A N S W E Ra n dt h e i n d i c a t o rtsh a t a r eo n a t t h i s p o i n t . l d e n t i f yt h e D E B U Gr e c o r d s
w i t h t h e c o n s t a n-t T E S T l . W h a te n t r i e si n o t h e rs p e c i f i c a t i osnh e e t sm u s tb e m a d e ?

R e v i e w1 1

11-7

AnsrersTo Review11

1.

DEBUGallowsyou to displaythe contentsof a datafield in your programand to list the
indicatorsthat areon.

2.

A 1 must be enteredin column 15 of the RPG ll control card.

C A L C U L A T I O N S P E C IF I C A T I O N S
C.rd €l.cro

Gr.phi(

Nvmb,

I o."

c

Indrcators

: d
E iz 
Source Exif Data:
File Type                       : PDF
File Type Extension             : pdf
MIME Type                       : application/pdf
PDF Version                     : 1.4
Linearized                      : No
Page Count                      : 516
Producer                        : iText 2.0.3 (by lowagie.com)
Modify Date                     : 2010:09:08 22:10:25+02:00
Create Date                     : 2010:09:08 22:10:25+02:00
EXIF Metadata provided by EXIF.tools

Navigation menu