• Aucun résultat trouvé

IBM System/3 RPG ll Additional Topics Programmer's Guide

N/A
N/A
Protected

Academic year: 2022

Partager "IBM System/3 RPG ll Additional Topics Programmer's Guide"

Copied!
516
0
0

Texte intégral

(1)
(2)
(3)

IBM System/3

RPG ll Additional Topics Programmer's Guide

Program Numbers:

5 7 0 2 - R G 1 ( M o d e l 1 0 ) 5 7 0 4 - R G 1 ( M o d e l 1 5 ) 5 7 0 4 - R G 2 ( M o d e l 1 5 )

5705-RG1 (Modet 12l.

(4)

P a g e o f G C 1 l 1 , 7 5 6 7 . 2 l s s u e d 3 O J u n e 1 9 7 8 B y T N L : c l ! 2 1 ' 5 6 1 6

T h i r d E d i t i o n ( J u l y 1 9 7 4 )

T h i s i s a m a l o r r e v i s i o n o f , a n d o b s o l e t e s , G C 2 1 - 7 5 6 7 - 1 . I n f o r m a t i o n c o n c e r n i n g l B l V l S y s t e m / 3 l V l r : d e l 1 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 e b 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 , v o r e x t e n s i v e l y r e v i s e c i i 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 r a p p l i e s t o t h e { o l l o w r r r g I B M S y s t e r n / 3 R P G l l p r o g r a m p r o d u c t s

V e r s i o n M o d i f i c a t i o n S y s t e m / 3 M o d e l

I a n d ' l 0 D i s l . 1 5 A , B , C 1 5 D 1 2

C h a n g e s a r e r p e r i o d i c a l l y m a d e t o t h e i n f o r m a t i o n h e r e i n : b e l o r e u s i n g t h i s p u b l i c a t i o n i n c o n n e c t i r s n w i t h t h e o p e r a t i o n o 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 t I B M S V s t e m / 3 B ' i b l i o g r a p h y , , G C 2 0 - 8 0 8 0 , { o r t h e e d i t i o n s t h a t a r e a p p i i c a b l e a n r l c u T i e n t .

T h i s p u b l i c , 3 t i o n c o n t a i n s e x a m p l e s o { d a t a a n d r e p o r t s u s e d in d a i l y b u s i r r e s s o p e r a t i o n s J o i l l u s t r a t , s t h e m a s c o r n p t e t e l y a s p o s s i b l e , t h e e x a t n p l e s i n c l u d e th c n a m e s o f

i n d i v i d u a l s , c o m p a n i e s , b 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 e n a m e s a r e f i c t i t i o u s a n d a n y s m i l a r i t y t o t h e n a m e s a r r d a d d r e s s e s u s e d b V a n a c t u a l b u s i n e s s e n t e r p r i s e i s e n t i r e l y c o i n c i d e n t a l .

L J s e t h i s p u b r l i c a t i o n o n l y f o r t h e p u r p o s e s s 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 s f 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 a n d f o r t e c h n i c a l i n f o r r n a t i o n a b o u t t h e s y s t e m s h o u l c l h e m a d e t o y o u r I B M r e p r e s e n t a t i v e c , r t o t h e l E i \ 4 b r a n c h o f f i c e s e r v i n g y o u r l o c a i i t y .

1 ' h i s p u b l i c a t i o n c o u l d c o n t a i n te c h n i c a l i n a c c u r a c i e s o r t y p o g r a p h i c a l e r r o r s . U s e th e F l e a d e r ' s C o r n m e n t F 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 n t o m a k e c o m m e n t s a 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 re m o v e d , a d d r e s s y o u r c o m m e n t s to 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 s , D e p a r t m e n t 2 4 5 . R o c h e s t e r . M i n n e s o t a 5 5 9 0 1 . C o m m e n t s b e c o m e t h e p r o p e r t y o l l B M .

1 5 6

zl

4

00 00 00 00

P r o g r a m N u m b e r 5 7 0 2 - R O 1 5 7 0 4 - R G 1 5 7 C ) 4 F r G 2 5 7 0 5 - R G 1

( ) l n t e r n a t i c , n a l B u s i n e s s M a c h i n e s C o r p o r a t i o n 1 9 - 1 1 . 1 9 7 4

(5)

T h i s rr r a n u a l p r e s e n t s a d v a n c e d R P G ll p r o g r a m m i n g t o p i c s O R G A N I Z A T T O N O F T H E M A N U A L f o r a p r p l i c a t i o n p r o g r a m m e r s a n d s t u d e n t s , w h o m u s t c o d e

p r o g r a m s f o r I B M S y s t e m / 3 :

P a g e o f G C 2 1 '1 5 6 1 - 2 l s s u e d 2 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 s p u b l i c a t i o n h a s e l e v e n c h a p t e r s . C h a p t e r s 1 - 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 c to m o s t d a t a p r o c e s s i n g j o b s : R P G l l p r o g r a m l o g i c , c l e t a i l e d i n f o r m a t i o n a b c u t w r i t i n g i n p u t , o u t p u t , a n d c a l c u l a t i o n s p e c i f i c a t i o n s a n d t h e c o n - c e p t s a n d s p e c i f i c a t i o n s i n v o l v e d i 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 g t o p i c s th a t y o u m a y r e q u i r e fo r y o u r j o b a r e p r e s e n t e d i n C h a p t e r s 7 - 1 1 : c o n t r o l l i n g in p u t 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 n t 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 M l o d e l 6

o l V o d e l 8

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

o l V l o d e l 1 2

R E L A T E D P U B L I C A T I O N S o l V l o d e l 1 5

T h e r e a r e n u m e r o u s I B M S y s t e m / 3 p u b l i c a t i o n s c o n t a i n i n g T h e S i y s t e m / 3 M o d e l 8 i s s u p p o r t e d b y S y s t e m / 3 M o d e l 1 0 f u r t h e r i n f o r m a t i o n o n R P G l l . T h e f o l l o w i n g a r e t h e r e - c o n t r o l p r o g r a m m i n g a 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 l a t e d r e f e r e n c e m a n u a l s :

d e s c r i b e d i n t h i s p u b l i c a t i o n fo r t h e M o d e l 1 0 a r e a l s o a p p l i-

cable to the Model 8, although the Model 8 is not referred . IBM System/3 Card System RPG ll Reference Manual,

t o . l \ o t e t h a t n o t a l l d e v i c e s a n d f e a t u r e s t h a t a r e a v a i l a b l e S C 2 1 - 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 e o n t h e M o d e l 8 . T h e r e f o r e ,

Model 8 users should be familiar with the contents of the . IBM System/3 RPG ll Reference Manual,SC2l 7504

IBM liystem/3 Modet 8lntroduction,cc2l-5144 | (Model 10, Model 12 and Model 15)

P R E F I E Q U I S I T E S

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

sc21 7511

T h i s r n a n u a l a s s u m e s t h a t y o u h a v e c o d e d a n d t e s t e d s o m e l f y o u a r e p r o g r a m m i n g o n a d i s k s y s t e m , it w o u l d b e h e l p - b a s i c R P G l l p r o g r a m s t h a t i n c l u d e li s t i n g r e c o r d s o n a f u l i f y o u w o u l d u n d e r s t a n d t h e d i s k c o n c e p t s a n d d i s k f i i e p r i n t e r , s i m p l e c a l c r - r l a t i o n s , g r o u p t o t a l s , a n d t h e u s e o f p r o c e s s i n g i 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 d th i s i n g t h i s b o o k :

e x p e r i e n c e t h r o u g h I B M e d u c a t i o n c o u r s e s , p r o g r a m m e d

instruction courses, or previous data processing experience. o IBM System/3 Disk Conceptsancl Planning Guide,

l n t r o < T u c t i o n t o R P G l l , G C 2 1 . 7 5 1 4 , c o n t a i n s s o m e o f G C Z | - 7 5 7 1 t h i s b a s i c in f o r m a t i o n .

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

(6)
(7)

This publication is a programmer's guide; it is not intended to serve the same purpose as a reference manual of language specifications and does not replace a reference manual.

R P C i ll p r o g r a m m i n g t o p i c s a r e a p p r o a c h e d a n d o r g a n i z e d a c c c , r d i n g t o t h e i r n o r m a l u s e in a d a t a p r o c e s s i n g j o b , u s i n g e x a r n p l e s w h e n e v e r p o s s i b l e . U n l i k e a r e f e r e n c e m a n u a l , i n d i ' r i d u a l c h a p t e r s a r e s e l f - c o n t a i n e d u n i t s o f i n f o r m a t i o n , interrded to be read from beginning to end. However, if you d e s i n e i n f o r m a t i o n a b o u t a s p e c i f i c t o p i c , y o u m a y g o direrctly to 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 l c h a p t e r h a s a s p e c i a l p 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 id e n t i f i e d o n t h e t i t l e p a g e o f the r:hapter.

Altfrough the chapters are complete units, there is a logical progression of 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 consecu- tivelly.

How To Use The Manual

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

ReYiew Ouestions

Review questions and answers are provided at the end of each chapter. Where chapters contain several related topics.

these questions are grouped by subtopic. lf you wish, you may turn to the end of the chapter after you complete each subtopic. to answer the review questions and reinforce what you have learned, before continuing the chapter.

(8)
(9)

P a q e c t G C 2 1 - 7 5 6 7 - 2 l s s u e d 2 1 D e c e m b e r 1 9 7 9 B y T N L : c N 2 1 - 5 7 0 9

Contents

C H ] A P T E R 1 . R P G I I L O G I C I ntroducti on

B a s i c D a t a P r o c e s s i n g L o g i c B a r ; i c R P G l l L o g i c

S p e c i f i c S t e p s i n E a s i c R P G t l Logic F i r s t P r o g r a m C y c l e .

S u m r n a r y o f B a s i c R P G l l L o g i c R P t G ll L o g i c R e l a t e d T o I n d i c a r o r s

1 P ( F r s t P a g e ) I n d i c a t o r s L a s t [ ] e c o r d I n d i c a t o r ( L R ) .

R e c o r d l d e n t i f y i n g I n d i c a t o r s ( 0 , | - 9 9 ) F i e l d I n d i c a t o r s ( 0 1 - 9 9 )

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 ) O v e r f o w I n d i c a t o r ( O A - O G . OV) M a t c h i n g R e c o r d s I n d i c a t o r ( M R ) S e t t i n g I n d i c a t o r s

IRE'VIEW 1

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

I 3 H A P T E I R 2 , D E S C R I B I N G A N D U S I N G I N P U T I n t r o d u c t i o n

l l o n t r o i F : i r 3 l d g S p l i t C o n t r o l F i e l d s

Checking the Sequence of Flecord Types Order of Record Types Within a Group

Check.ing the Order of Record Types in a Group I n c o r r e c t R e c o r d s W i t h r n a Group

S e q u e n c e d a n d U n s e q u e n c e d R e c o r d Types in a G r o u p

U n e x p e c t e d o r U n u s e d R e c o r d s Within a Group F i e l d R e c o r d R e l a t i o n l n d i c a t o r s

r O R R e l a t i o n s h i p

t 0 R Relationship With Field Record Relation E n t r i e s

F i e l d l l e c o r d R e l a t i o n w i t h Control Fields F i e l d R e c o r d R e l a t i o n w i t h Split Control Fields C o r r d i t i o r r i n g U s e o f l n p u t F i l e s ( E x t e r n a l Indicators)

U s i n g t ) n e P r o g r a r n t o d o M o r e Than One Job l E n d i n g T h e P r o g r a m B e f o r e Processing All Files

C o m p l e t e l y R E \ / f E W i 2

I \ N S W E R S T O R E V I E W 2 .

H O W T O U S E T H E M A N U A L i i i C I - I A P T E R 3 . C O N T R O L I - I N G P R I I \ I T E R O U T P U T I n l r o d u c t i o n

U s i n g O v e r f l o w a n d F e t c h Over-flow To Control Page F o r m a t l r n g

O v e r t l o w I n d i c a t o r s

S p e c i f i c a r i o n s f o r U s r n g O v e r f l o w I n d i c a t o r s 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 g Over l-he

P e r f o r a t i o n Fetch Overflow A l i g n i n g F o r m s E d i t r n g

M e t h o d s o t F d i t i n i l E d i t i n g a n d E n d P o s r t r o n

U s i n g * P L A C E T o P r i n t D u p l i c a t e I n f o r m a t i o n S p e c i f r c a t r o n s F o r L l s i n g * P L A C E

F o r m a t i o n O f P r i n t L r r r e s

P r i n t r n g A F i e l c J S e v e r a l T i m e s O n T h e S a m e L i n e U s i n g T w o P n n t e r U u t p u t F i l e s in O n e P r o g r a m

M o d e l 1 0 C a r d a n d D i s k S y s t e m s M o d e l 6 .

F i i e D e s c r r p t r o n S n e c i l r c a l r o n s 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 s E x a m p l e : E n i j o f t h e - M o n r h B i l l i n g R E V I E W 3

O v e r f l o w a n d F e t c h O v e r { l o w F o r r n s A l i g n m e n l

E d i t i n g

* P L A C F

D u a l P r i n t e r O u l p u l t i t e s A N S W E R S T O R E V I E W 3 ,

C H A P T E R 4 . C A R D O U T P U T . O P E R A T I O N S I n t r o d u c t r o n

P u n c h i n g A n d P r i n t r n g O n C a r d s P u n c h e d O u t p u t

P r i n t r n g O n C a r d s

U s i n g O n e F i l e F o r t s o t h l r r p u t A n d O u t p u t P u n c h i n g i n t o T h e S a n r e C a r d T h a t l s R e a d P u n c h i n g I n t o A B l a n k C a r d I n T h e F i l e W h e n T o S p e c i f y A C o m b i n e c l F i l e S t a c k e r S e l e c t i o n

I n p u t A r r d C o r n b i n e d F i l e C a r d s S t a c k e r S e l e c t i r i g O u t p u t F i l e C a r d s M e r g i n g I n p u t A n d O u t p u t F i l e C a r d s R E V I E W 4

P u n c h i n g a n c J P r i i ' r t i n g O n C a r d s

U s i n g O r r e F r l e F o r B o t h I n p u t A n d O r . r t p r u t S t a c k e r S e l c c t i o n

A N S W E R S T O R E V I E W 4 1 - 1

1 - 2 1 - 2 1 - 4 t - r ) 1 - 1 1 - 7 1 - 7 1 - 1 3

t - t o

1 - ' 1 9 1-25 1 - 3 1

I - J J

1-41 1-42

| - z + J

1 4 5 1 4 6 2-1

2-5 2-6 2-6 2 - 1 2 2 - 1 2 2-14

z - t q

2 - 1 5 2-15 2-16 2-18 2-18 2 - ' t 9 2 - ' t 9 2-22 2-25 2-28

3 - 1 3 2 3 2 .

? , )

3 4 . 3-6 3 8

J - l l

3 - 1 2 3 1 2 3 1 9 3 - 1 9

? 1 1

3 - 2 2 3-26

) a a

3 2 8 3 2 8 3 2 8 3-29 3 - 3 1 . 3-33

"

2 ?

3 3 4 3 3 4 3 - 3 5 3 - 3 5 . 3-36 . 4-1 . 4-2 . 4 2 . 4-2 . 4 2 4 8 4-8 4 - 1 1 4 1 4 4 1 4 4 1 5 4 1 1 4 1 5 4-21 4 - 2 1 4 2 1 4 2 3 . 4-25

(10)

C H A P T E R 5 . C O N T R O L L I N G O P E R A T I O N S I N A N R P G I I P I 1 O G R A M .

l r r t r o d u c t i o r r

A d d i t i o n a l L l s e s o f I n d i c a t o r s To Control Calculations

; : n d O u t p u t

P r e v e n t i n g O p e r a t i o n s F r o m Being Done When A n E r r r l r O c c u r s .

C o n t r o l l n g W h i c h O p e r a t i o n s Are Done for a S p e c i f i c P r o g r a m R u n

C o n t r o l l r n g C a l c u l a t i o n s W h e n Overflow Occurs P e r f o r m i n g C a l c u l a t i o n s On The Basis of the

R e s u l t r ; O f O t h e r C a l c u l a t i o n s

C o n l r o l l i n g t ] p e r a t i o n s o n t h e Basis of the Next l l e c o r d I n A F i l e

P r o c e s s n g C a r d o r D i s k Files C h e c k i n E F o r D u p l i c a t e s

D o i n g S p e c i a l O p e r a t i o n s W h e n There ls Onlv O n e R e c o r d I n A G r o u p

D o i n g S p e c i a l O p e r a t i o n s For The Last Record I n A G r o u p

A d d i t i o r r a l P o i n t s T o C o n s i d e r About Look Aheao M o v i n g D a t a

S p e c i f i c a t i o n s F o r M o v i n g D a t a

S a v i n g I n f o r m a t i o n F r o m A F i e l d Bv Move O p e r a t r r : n s

S e p a r a t i n g O n e F i e l d I n t o T w o P a r t s

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 c o r N u m e r i c ) B r a n c h i n g I n C a l c u l a t i o n s

B y p a s s i r r g C a l c u l a t i o n s B r a n c h i n g B a c k w a r d

U s i n g S u b r o u t i n e s in C a l c u l a t i o n s

U s i n g S u b r o u t i n e s T o D o T h e Same Calculations S e v e r a l T i m e s I n O n e C y c l e

C o n t r o l l i n g O v e r l a y b y U s i n g Subroutines R P G l l L i n k a g e E d i t o r

L i n k a g e E d i t o r M a p S i m p l e C t v e r l a y s S p e c i a i O p e n

O v e r l a y l i t a r t i n g A d d r e s s e s F i t t i n g A v a i l a b l e S t o r a g e

R P G l l l . - o g i c a n d F u n c t i o n Shifting S p e c i a l U s e r s o f C o n t r o l L e v e l I n d i c a t o r s

I n t e r n a l C o n t r o l L e v e l I n d i c a t o r L0

U s i n g C o n t r o l L e v e l I n d i c a t o r s A s Calculation C o n d i t i o n i n g I n d i c a t o r s

G r o u p P r i n t i n g

B i n a r y F i e l c l O p e r a t i o n s ( C o n t r o l l i n g Switches)

BITON Operation Code

BITOF Operation Code

TESTB 0peration Code E x a m p l e

I n c r e a s i n g ' I h e

S p e e d o f O p e r a t i o n s ( D u a l l / O A r e a s ) D u a l I n p r u t A r e a s

D u a l O u t p u t A r e a s

A N S W E R S T O R E V I E W 5 . . . 5-77

C H A P T E R 6 . M A T C H F I E L D S A N D M U L T I F I L E P R O C E S S I N G

R E V I E W 5

A d d i t i o n a l U s e s O f I n d i c a t o r s

C o n t r o l l i n g O p e r a t i o n s O n T h e B a s i s o f t h e Next R e c o r d I n A F i l e

M o v i n g D a t a

B r a n c h r n g In C a l c u l a t i o n s

U s i n g S u b r o u t r n e s I n C a l c u l a t i o r r s S p e c i a l U s e s O f C o n t r o l L e v e l I n d i c a t o r s B i n a r y F i e l d O p e r a t r o n s

D u a l I n p u t / O u t p u t A r e a s

I n t r o d u c t i o n

C h e c k i n g S e q u e n c e O f R e c o r d s W i t h i n A F i l e . F i l e C o n t a i n i n g O n l y O n e R e c o r d T y p e F i l e C o n t a i n i n g M o r e T h a n O n e R e c o r d Type 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 d R e l a t i o n for

M o r e T h a n O r r e R e c o r d T y p e i n a F i l e

M a t c h F i e l d s T h e S a m e F o r A l l R e c o r d T v p e s M a t c h F i e l d s D i f f e r B e t w e e n R e c o r d T y p e s M a t c h i n g R e c o r d s : O n e R e c o r d T y p e i n E a c h File

P r o c e s s i n g O r d e r : M o r e T h a n O n e M a t c h i n g Record I n A S e c o n d a r y F i l e

P r o c e s s i n g O r d e r : M o r e T h a n O n e M a t c h i n g Record

5-1

3 1

5-2 5-2 5-7 5 - 1 1 5-12 5 - 1 7 5 - 1 7 5-20 5-26 5-28 s-28 5-28 5-29

q _ e 1 E _ ? ?

5-34 5 - 3 6 5-42 5-44 5-45 5-54 5-54 5-55 5-56 5 - 5 6 . 1 5 - 5 6 . 1 5 - 5 6 . 3 5-56.3 5-56.4 5 - 5 6 . 4

5-59 5 - 5 9 5-67 5-67 5-67 5-68 5-69 5-69 5-69

5 - t l

I n T h e P r i m a r y F i l e M a t c h i n g R e c o r d s :

I n T h e O t h e r F i i e

5-73 5-73 5-14 5-7 4 5 - 7 5 5 - 7 5 5 - 7 6 5-76 5 - 7 6

6-1

b - l

6-2 6 , 2

C r - b

6-8 6,8 6-9 6-12 6 - 1 2

nr"ora" Which Have No Match 6-20 6-20 6-26 6 - 2 6 6-29 6 - 3 0 6-34 6 - 3 8 6-41 6-44 M a t c h i n g R e c o r d s : 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 F i e l d s I n D i f f e r e n t L o c a t i o n s I n T h e S a m e F r l e

P r o c e s s r n g R e c o r d s W h i c h D o N o t H a v e M a t c h F r e l d s

M a t c h i n g R e c o r d s : W h e n A l l R e c o r d s I n O n e F i l e H a v e B e e n P r o c e s s e d

U s e o 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 I n t h e S a m e F i l e

D e t e r m i n i n g W h e t h e r F i l e s S h o u l d B e P r i m a r y o r S e c o n d a r y

R E V I E W 6

Review Problern

A N S W E R S T O R E V I E W 6 . . 6 - 4 6

S o l u t r o n l - o T h e R e v i e w P r o b l e m 6-49

(11)

C H A P T E R 7 . P R O G R A M M E D C O N T R O L O F I N P U T A I { D O U T P U T

I n t r o d u c t i o n

l \ l t e r r i n g T h e O r d e r o f P r o c e s s i n g Files (Force 0 p e r a t i o n )

i3peofy'ing The Next File To Process A l t e r n a t i n g P r o c e s s i n g B e t w e e n T w o Files F o r c i n g A N u m b e r o f R e c o r d s From a File l - o o k - A h e a d T o D e t e r m i n e Whether A File ls To

Be Forced

P r o , r e s s i n g D e m a n d F i l e s ( R e a d Operation) l l o n s i r j e r a t i o n s For Using READ and Demand

F i l e s

f ] e p r e t i t i v e O u t p u t ( E x c e p t O p e r a t i o n ) l J s i n g E X C P T and *PLACE

l l o n d i t i o n i n g The Use of EXCPT Operation

P a g e o f G C 2 1 - 7 5 6 7 - 2 l s s u e d 2 1 D e c e m b e r 1 9 7 9 B y T N L : G N 2 1 - 5 7 0 9 CHAPTER 9" ARRAYS

Introduction

When To Use an ,Arrav Instead of a Table Defining An Array

Referencing All Elements In An Array Array to Array Calculations

Calculations Using Arrays and Single Fields (Or Constantsi

Adding All Elements Within An Array 9-8

Output of an Entire Array 9-g

Accumulating Groups Of Totals 9-14

Referencing Individual Elements of an Array 9-19

Indexing An Array 9-20

Output of Individual Elements of An Array 9-22

Referencing Only Part of a Field 9-23

LOKUP Of An Array 9-27

Searching An Array For A Particular Element 9-27

Searching An Array For More Than One Element 9-32

Output During An Array Search 9-34

Loading Arrays 9-35

Compile Time Arrays 9-35

Pre-execution Time Arravs 9-36

Storing Input Data Into Execution Time Arrays 9-38

Arrav Data Consecutive On More Than One Record

(Model 6, Model 10 Disk System, and Model 15) 9-44

REVTEW I . 9-53

A N S W E R S T O R E V I E W g . . 9 - 5 5

C H A P T E R 1 0 . W O R K I N G W I T H D A T A

STRUCTI.JRE . 1O-1

Character Structure 1O-2

Representation Of Characters On 96-Column Cards 10-2

R e p r e s e n t a t i o n O f N e g a t i v e N u m b e r s R e p r e s e n t a t i o n o f C h a r a c t e r s I n S t o r a g e Difference Between Character Representation on

C a r d s a n d I n S t o r a g e

l d e n t i f y i n g B i t C o m b i n a t i o n s W i t h N u m e r i c a l V a l u e s

A s s i g n i n g N u m e r i c a l V a l u e s t o Z o n e a n c l D i g i t

. 1 0 - 3 . 1 0 - 4 1 0 - 4 1 0 - 1 3 P o r t i o n s

S a v i n g D i s k S t o r a g e S p a c e C o l l a t i n g S e q u e n c e o f C h a r a c t e r s

C o l l a t i n g B y Z o n e o r D i g i t A l t e r i n g t h e C o l l a t i n g S e q u e n c e

S p e c i f y i n g C h a n g e s I n C o l l a t i n g S e q u e n c e . C o d i n g C h a r a c t e r s T o B e E q u a l

R e c o r d i n g S p e c i f r c a t i o n s F o r T h e A l t e r e d S e o u e n c e

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

l-2 . 7-2 . 7-4

1 1

/ - t c

7 - 2 2 7-26 7 - 2 6 7-26 7-29 ]lE\/tEW 7

FC)RCE I 1 E A D . E X C P ' T

. . 7 - 3 1 7-31 7 - 3 2 7 _ 3 3

B-5 B-7 8-8 8 - 1 1 8 - 1 3 B - 1 4 8 - 1 4 8 - 1 4 8 - 1 6 8 - 1 9 8-21 8-22 8-25 B - 2 5 B - 2 5 B-26 8-28

l\NrSU,/EtlS TO REVIEW 7 .7-34

C H , A P T E R 8 . T A B L E S 8 - 1

l n t r , c d u c t r o n 8 - 2

l S e a r c h i n g a S i n g l e T a b r e B - 4

D e s i g r r i n g T a b l e I n p u t R e c o r d s g - 4 D e s c r i b r i n g T a b l e I n p u t R e c o r d s With Extension

S p e c i f ic a t i o n s

{ l o d i n g The Table Lookup Operation (LOKUP) l - w o T a b l e S e a r c h

D e s i g n i n g T a b l e I n p u t F l e c o r d s F o r T w o T a b l e s D e s c r i L r i n g T 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 f ic a t i o n s

C o d i n q T h e T a b l e L o o k u p O p e r a t i o n ( L O K U P ) L J s i u g Ia b l e D a t a I n C a l c u l a t i o n s a n d O u t p u t

C o n d i t i i o n i n g O p e r a t i o n s O n T h e B a s i s of a Table L o o k u p

l ? e f e r e r r r c i n g D 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 l l e a r c h i n g F o r L o w , High, or Equal Conditions l V o v i n g D a t a I n A T a b l e E n t r y

l V l o d i f y i n g T h e C o n t e n t s Of A Table t . o a d i n g l i a b l e s

l l o m p l e T i m e Tables P r e - e x € ' c u t i o n l - i m e T a b l e s l * o a d i n g P r e - e x e c u t i o n T i m e T a b l e s O u l p u t o r a n E n t i r e T a b l e

flE\/lEW I . 8-29

l l e v i e w P r o b l e m 8-30

1 0 - 1 6 1 0 - 1 9 10-21 1 0-25 10-2_8 10-28 1 0-33 1 0-38

v l l

(12)

A l t e r r n g T h e S t r u c t u r e of Characters H o w M o v e Z o n e Operations Work C o d i n g a M o v e Z o n e O p e r a t i o n

D i f f e r e n c , e s In T h e M o v e Zone Operations F i e l d F o r r n a t a n d M o v e Z o n e Operations E x a m p l e o f a M o v e Z o n e Operation C l ' r o o s r n g th e M o d e l C h a r a c t e r For Factor 2 T r a n s l a t i n g C h a r a c t e r s

N e e d F o r F i l e T r a n s l a t i o n S p e c i f y r n ' g F i l e T r a n s l a t i o n

R e c o r d i n g S p e c i f r c a t i o n s F o r The Translation T a b l e

R E V I E W 1 O

C h a r a c t e r S t r u c t u r e

C o l l a t i n g l i e q u e n c e o f C h a r a c t e r s . A l t e r i n g ' l - h e

C o l l a t i n g S e q u e n c e A l r e r i n g l - h e S t r u c t u r e of Characters T r a n s l a t i r r r ; C h a r a c t e r s

C H A P T E R 1 1 . D E B U G lntroduction

Using The DEBUG Function

Specifications For DEBUG

Format of Records Created Bv DEBUG Getting Results From DEBUG

Placement of DEBUG

Making Your Program Work For All Cases R E V I E W 1 1

A N S W E R S T O R E V I E W 1 1 I N D E X

1 0-39 1 0-39 1 0-39 1 0-40 1 0 - 4 1 1 0 - 4 1 't0-42 10-44 10-44 10-44 10-48 1049 1 0-49

't 1"1 1 1 - 2

I t - l

1 1 , - 2

. r 1 - 5 1 1 , 5 11-7 1 1 - 8

x " 1

. 10_49

. 10_50 . 1 0 - 5 0 . 1 0 _ 5 0

ANiSYYgPg TO REVTEW 10 1O_S1

(13)

C H A P T E R 1 D E S C R I B E S : B a s i c R 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 d to 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 R Y O U S H O U L D B E A B L E T O D E S C R I B E : B a s i c th r e e - s t e p l o g i c o f a d a t a p r o c e s s i n g j o b .

D e t a i l ti m e a n d t o t a l t i m e .

S p e c i f i c s t e p s in 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 s d 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 d to 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 id 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 g i 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 g re c o r d s in 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 t o n s .

C h a p t e r 1 . R P G l l L o g i c

R P G l l L o g i c 1 - 1

(14)

I N T R O D U C T I O N

W h a t p r o c e d u r e s d 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 g b i l l s t o s e n d to 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 in l o r m a t i o n . Y o u h a v e to k n o w t h r e e th i n g s : ( 1 ) t h e c u s t o m e r ' s b a l a n c e a t t h e b e g i n n i n g o f t h e m o n t h ; ( 2 ) h i s p u r c h a s e s ; a 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 d t 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 c a l c u l a t i o n s t 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 e s a m e p r o - c e d u r e s f 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 y h a v e y 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 , th e c o m p u t e r m u s t k n o w t h e s a m e th 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 , te 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 the i n f o r m a t i o n , a n d w h a t t o g i v e y 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 s y 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 ; In 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 jo b , y o u d o t h i n g s in a l o g i c a l o r c j e r . y o u r e a d in 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 s s 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 s , y o u r e c o r d th e a m o u n t o w e d . T h e n y o u b e g i n to d o t h e s a m e th i n g s r n t h e s a m e o r d e r f o r t n e n e x t c u s t o m e r .

T h e c o n r p u t e r m u s t a l s o d o t h i n g s in a l o g i c a l o 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 s d 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 it n e e d s t 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 s t h i s . R P G l l l o g i c s u p p l i e d b 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 source pro- g r a m i s r : o m p i l e d , y o u r s o u r c e s t a t e m e n t s a 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 m lo g i c to 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 d p r o g r a m th 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 s t o d o y o u r j o b i n a l o g i c a l m a n n e r .

W h a t h a p p e n s i f , i n d o i n g y o u r b i l l i n g jo b , y o u f i n d t h a t a c u s t o m e r p 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 e a n d i n d i c a t e s o o n t h e i n v o i c e . H o w d o e s th e B P G | | p r o g r a m r e c o g n i z e t h i s s i t u a t i o n ? A n d h o w d o e s it k n o w w h a t t o d o w h e n s u c h a s i t u a t i o n occurs?

T h e R P G l l p r o g r a m u s e s s i g n a l s w 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 n o c c u r s a 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 e s i g n a l s a 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 s w h i c h s i g n a r m 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 th e i n d i c a t o r s s o t h a t t h e y s i g n a l to t h e c o m p u r e r w h a t y o u w a n t t h e m t o .

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 e in 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 s th e s e q u e n c e o f t h e p r o g r a m ' s o p e r a t i o n s . T h e l o g i c is s e t u p t o t e s t th e s t a t u s o f v a r i o u s in c l i c a t o r s a t s p e c i f i c t i m e s . B y t e s t i n g in d i c a t o r s , t h e p r o g r a m k n o w s w h a t t o d o n e x t .

R P G | | p r o g r a m lo g i c i s d e s i g n e d t 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 d t h i s l o g i c t o w r i t e s p e c i f i 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 e o f i t .

B e c a u s e t h e l o g i c is 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 t b 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 fi n i s h e d r e a d i n g t h i s s e c t i o n . y o u w i l l h a v e a 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 lo g i c w o r k s .

B A S I C D A T A P R O C E S S I N G L O G I C

U s u a l l y , a l l r e c o r d s in a f i l e o f i n p u t r e c o r d s a 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 e e n o u g h to 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 s a 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 s a 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 phrase pragram cycle refers to all the operations per- f o r m e d f r o m t h e t i m e o n e r e c o r d is r e a d u n t i l t h e n e x t r e c - o 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 e o 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 d to i l l u s t r a t e t h e p r o g r a m lo g i c . S i n c e o n e p r o g r a m c y c l e ( o n e r e v o l u t i o n ) is n e e d e d fo 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 s a r e r e q u i r e d fo r e v e r y jo b . C o n s i d e r h o w t h e t h r e e s t e p lo 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 s a d e t a i l e d li s t i n g o f p u r c h a s e s m 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 g o r d e r b y c u s t o m e r n u m b e r . E a c h r e c o r d c o n t a i n s c u s t o m e r n 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 h r e c o r d r e a d . E a c h r e c o r d r e a d i s k n o w n a s a d e t a i l r e c o r d a n d e a c h li n e p r i n t e d i s a d e t a i l l i n e .

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 is r e a d . N o c a l c u l a t i o n s a 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 s th 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 d b e g i n s w i t h t h e r e a d i n g o 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 s th 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 g j o b .

S u p p o s e , h o w e v e r , in s t e a d o f m e r e l y l i s t i n g th 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 r y o u a l s o w i s h t o f i n d t h e t o t a l c h a r g e s f 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 .

t - z

(15)

a

Write or punch resu lts

\

a record

P e r f o r m c a l c u l a t i o n s

. @

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 g J o b

1 7 9 6 J O H N B A R T 2 4 9 3 I 7 6 2 B I L L B E L L 1 3 1 4 2 1 6 4 5 J O E A A R O N

, I & 5 J O E A A R O N 7 4 2

1 645 1645

J O E A A R O N J O E A A R O N

7 . 4 2 6.43 1 3 . 8 5 *

1762 BILL BELL '13'1 .42

131 .42*

1 7 9 6 J O H N B A R T 2 4 . 9 3

1 7 9 6 J O H N B A R T 2 . 9 8

F i g u r e 1 - 2 . D e t a i l P r i n t i n g J o b

Printed reoort

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

R P G l l L o g i c

(16)

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 s t o a c c u m u l a t e a t o t a l 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 ) records. 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 have calculated? 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 , should be printed after all d e t a i l r e c o r d s f o r t h a t c u s t o m e r h 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 , in t h e t h r e e - s t e p l o g i c d i s c u s s e d s o f a r , t h e r e i s n o p r o v i s i o n f 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 is there a w a y t o d i s t i n g u i s h b e t w e e n in d i v i d u a l in 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 e w h e n a l l r e c o r d s for a customer have b e e n r e a d .

l f t h e R P G l l p r o g r a m u s e d o n l y the three-step l o g i c . it w o u l d n o t b e a b l e to d o t h i s j o b and many others like it.

I t c o u l d a d e q u a t e l y w o r k w i t h i n f o r m a t i o n f r o m only one r e c o r d a 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 jo b . lt could not correctly do operations to accumulate data from several records.

Perlorm detail o u t p u t o p e r a t i o n s

Detail time

B A S I C R P G I I L O G I C

R P G l l l o g i c , th e r e i o r e , is a n e x t e n d e d v e r s i o n of this 3-steo l o g i c . l t c a l l s fo r c a l c u l a t i o n s a n d o u t p u t o p e r a t i o n s t o b e done at two different times in one program cycle (see Fig.

ure 1-4). The names detail and total have been given to the t a m e s a t w h i c h c a l c u l a t i o n a n d o u t p u t o p e r a t i o n s a 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 charges for J o e A a r o n ( F i g u r e 1 - 3 ) is a n e x a m p l e o f a total time opera- 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 s are per- f o r m e d f o r i n d i v i d u a l re c o r d s . A n e x a m p l e of a detail time o p e r a t i o n is t h e p r i n t i n g o f a n i n d i v i d u a l charge for Joe 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 s a 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 s a r e r e a d ( s e e F i g u r e 1 - 5 ) .

R e a d a o

Perlorm detail c a l c u l a t i o n s

Total t i m e

o

O Perform total

output operations o

1 4

Figure 1-4. Basic RPG ll Logic

(17)

P a s e o I G C 2 1 - 7 5 6 7 - 2 l s s u e d 2 4 M a y 1 9 7 6 B y T N L : G N 2 1 - 5 3 8 9

D e t a i l o p e r a t i o n s

Done for every record

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

Figure 1-5. Detail Versus Total Operations

B e c a u s e t h i s b a s i c R P G l l l o g i c is 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 e to s u p p l y a d d i t i o n a l ir r f o r m a t i o n s 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 ll y o u r p r o g r a m w o r k 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 r s u p p l i e s y o u r p r o g r a m w i t h t h e l o g i c fr a m e w o r k w h i c h e n a b l e s i t t o d o detail and total operations. But you must tell it when total o p e r a t i o n s s 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 n a n d o u t p u t o p e r a t i o n s a 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 d o n e a t t o t a l t i m e .

R e m r - ' m b e r t h 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 s i s t o u s e in d i c a t o r s . C o n - t r o l l e v e l in d i c a t o r s a r e u s e d to t e l l t h e p r o g r a m :

1 . W h e n t o d o t o t a l o p e r a t i o n s . 2 . W h a t o p e r a t i o n s a 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 s f 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 d to t a l s f o r e a c h c u s t o m e r ? W h e n y o u e n c o u n t e r a r e c o r d w i t h a d i f -

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

1 7 1 3 L E E A R M S T R O N G 5 7 1

L E E A R M S T R O N G 4 7 5

G R O U P 2

T o t a l O p e r a t i o n s D o n e o n l y a f t e r a l l r e c o r d s in o n e g r o u p h a v e been processed.

, / o ^ o u ,

f e r e n t c u s t o m e r n 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 d a 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 e th 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 i s a c h a n c e th a t t w o c u s t o m e r s m a y h a v e th e s a m e n a m e . ) Y o u w o u l d t h e n r e c o r d th a t t o t a l b e f o r e g a t h e r i n g i n f o r - m a t i o n f o r t h e n e x t c u s t o m e r .

A n y f i e l d u s e d to 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 g i 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 g o n e o f t h e c o n t r o l l e v e l in 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 th i s s a m e c o n t r o l l e v e l in 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 s a 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 g th e i n d i c a t o r in c o l u m n s 7 - 8 o f t h e C a l c u l a t i o n s h e e t . T h o s e c a l c u l a t i o n s t 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 l in 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 in d i c a t o r s a 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 t to i n d i c a t e d 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 in c o l u m n 1 5 t o i n d i c a t e a 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 d to i n d i c a t e a n o o e r a t i o n d o n e a t d e t a i l t i m e .

L E E A R M S T R O N G 2 9 8

1 6 4 5 J O E A A R O N 7 4 2

R P G l l L o g i c 1 - 5

(18)

Spercific Steps in Basic RpG ll Logic

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 y t h e s e q u e n c e o f e v e n t s in a n R P G l l p r o g r a n r c y c l e . T h e R p G l l l o g i c a c t u a l l y co n s t s t s o f c l e f i n i t e s t L . l i s t a k e n d u r i n g t h e c y c l e " W h e r r y o u do a job y o u m e n t a l l r l a s k y o u r s e l f q u e s t i o n s s u c h a s , , , D o

I d o t h i s n o v r ? D o I h a v e a 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 d o n e x t ? " R P G l l l o g i c a l s o a s k s q u e s t i o n s . lt uses your pro- g r a r n to f i n d t h e a n s w e r and thus determines 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 c s t e p s t a k e n b a s e d o n t h e a n s \ r y e r s t o 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 .

T u r n o f f c o n t r o l l e v e l in d i c a t o r s L 1 - L 9 .

P e r f o r m detail o u t p u t o p e r a t i o n s { t h o s e id e n t i f i e d b y D o r H )

D e t a i l t i m e

. / /

P e r f o r m d 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 s in . / / c o l u r n n s 7 - B ) / /

M o v e d a t a f r o m

recoro reao at /

b e g i n n i n g o f c y c l e a / i n t o p r o c e s s i n g

a r e a

P e r f o r m t o t a l o u t p u t a o p e r a t i o n s ( t h o s e

r d e n t r l l e d D y a l ,

o

A c c o r d i n g to R P G l l l o g i c , a f t e r a r e c o r d is read the program c h e c k s t o s e e if 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 of the record J u s t s e l e c t e d i 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 s r e c o r d . ( T h e p r o g r a m a l w a y s s a v e s t n e c o n _ t r o l f i e l d in f o r m a t i o n s 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 . ) lf 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 in d i c a t o r {the one y o u a s s i g n e d ) i s t u r n e d o n . ' f h i s

m e a n s th 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 . All total operattorrs c 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 in d i c a t o r s are alwaVs t u r n e d o f f b e f o r e th e n e x t r e c o r d is r e a d .

R e a d a r e c o r d

\

P e r f o r m t o t a l

C h a n g e i n c o n t r o l f i e l d ? I f y e s , tu r n o n c o n t r o l l e v e l in d i c a t i o r s

;

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 d b y L 0 - L 9 o r L R i n c o l u m n s 7 - 8 o f C a l c u l a t i o n s h e e t )

o o

o

O O

o

o

o

4 \ o

T o t a l t i m e

a

O

o

| -ft

F i g u r e 1 - 6 . Steps in RpG ll Total and Detail_Time Loqic

(19)

N o t l c e t h e s t e p b e t w e e n to 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 g o 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 g a r e a a n d b e c o m e s a v a i l a b l e t o u s e in c a l - c r . r l a t i o n s a n 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 is n o t a v a i l a b l e a ' t to t a l t i m e . T o t a l o p e r a t i o n s a 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 d f r o m p r e v i o u s r e c o r d s . D e t a i l o p e r a t i o n s o n t l r e r e c o r d w h i c h c a u s e d t h e c o n t r o l l e v e l in d i c a t o r to 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 s f o r p r e v i o u s p1.'66rrds.

V / h v a r e t o t a l o p e r a t i o n s 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 ? - [ h i r r k

o f w h a t w o u l d h a p p e n if t h e r e c o r d w h i c h c a u s e d t l n e c o n t r o l l e v e l in d i c a t o r s t o b e t u r n e d o n w e r e p r o c e s s e d '

l n f o r m a t i o n o n t h i s r e c o r d w o u l d b e a d d e d to i n f o r m a t i o n f r o r n r e c o r d s in t h e p r e v i o u s g r o u p . A s a r e s u l t , th e t o t a l s p , r i r r t e d w o u l d b e i n e r r o r s i n c e th e y c o n t a i n e d in f o r m a t i o n f r o r n o n e r e c o r d in t h e n e x t g r o u p ( t h e r e c o r d iu s t r e a d ) . ' l - o

p r e v e n t d a t a f r o m t h e f i r s t r e c o r d in a n e w c o n t r o l g r o p p f r o r n b e i r r g a c c u m u l a t e d i 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 , to t a l o p e r a t i o n s a 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 '

First Program Cycle

W h e n c o n t r o l f i e l d s ; a r e s p e c i f i e d f o r a r e c o r d , th e f i r s t p r o - g r a r n c y c l e m a y b e s ; l i g h t l y d 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 l in d i c a t o r s a 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 g c o n t r o l { i e l d s . T h i s h a p p e n s b e c a u s e c o n t e n t s o f t h e c o n t r o l f i e l d s o n t h i s r e c o r d a 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 s t h a t w e r e i n m a i n s t o r a g e b 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 t p 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 s t 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 d o n t h e f i r r ; t c 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 s d 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 s a n d t o t a l o u t p u t o p e r a t i o n s a r e b y p a s s e d o n e a c h p r o g r a m c y c l e t h r o u g h a n d i n c l u d i n g th e f i r s ; t c 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 is r e a d '

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 s f o r t h e g r o u p p r i n t i n g jo b p r e v i o u s l y d i s c u s s e d a 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 d in 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 s i t s e l f f r o m the time the program is started until the last record is processed.

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

R P G I I L O G I C R E L A T E D T O I N D I C A T O R S

I t w a s p r e v i o u s l y s t a t e d th a t R P G l l l o g i c is 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 n d i s c u s s e s h o w l o g i c r e l a t e d to i n - d i c a t o r s fi 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 l o g i c s h o w n in F i g u r e 1 - 4 '

I n y o u r s p e c i f i c a t i o n s , y o u u s e in d i c a t o r s t o t e l l t h e p r o ' g r a m w 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 e in - 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 th 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 d t o c o n t r o l t h e s e t t i n g o f i n d i c a t o r s ' I n d i c a t o r s a r e s e t t o s i g n a l v a r i o u s c o n d i t i o n s th a t o c c u r d u r i n g t h e e x e c u t i o n o 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 s t e s t s to b e m a d e f o r v a r i o u s in d i c a t o r s a t c e r t a i n ti m e s i n t h e p r o g r a m c y c l e ' S p e c i f i c o p e r a t i o n s a 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 e te s t s ' I t i s v e r y e a s y to t h i n k t h a t a n i n d i c a t o r is o n w h e n i t r e a l l y i s o f f o r v i c e v e r s a . l t i s e x t r e m e l y im p o r t a n t t h a t y o u k n o w w h e n i n d i c a t o r s a 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 s f a i l i u s t b e c a u s e t 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 d R P G l l l o g i c c o n c e r n i n g i 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 s w i l l d i s c u s s t 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 s a r e s e t a n d t h e t i m e a t w h i c h t h e y a r e t e s t e d .

R P G l l L o g i c 1 - 7

(20)

I B I | I , "

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

]H]A]RF]I

i l fi r i r

lillll

R P G I N P U T S P E C I F I C A T I O N S

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

S P E C I F I C A T I O N S cx21 m0 u/M o50.

p.if,red in U s.A

15 16 11 7a 79 80 l d e n r n c a r , o n l | | | | | I

i i i

l - ' I

i f t

rti

I B l t , , " . " . , " , . a . n n e s M a . h , n s c . r p . r a n . n

IBI{

",",", ,^" aunnen Mach ie cd,oors, on

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

+ f

T I

i r

i l

l 1

l

1 l

l l

r J

l r

R e c o r d ldentif ication CocJes

- 7--T

P ! . c h , n s I G E P h i c I

'r:Y F,e-l L i

67 6a 6S 70 ?r 7? 71 7a

C o n s t a n t or Edit Word

E n d

(21)

' 1 6 4 s J o E A A B o N 7 4 2

1 1 6 4 5 J O E A A R O N 7 . 4 2

o o

o o

a

T u r n o f f c o n t r o l l e v e l i n d i c a t o r L 1

P e r f c r m d e t a i l o u t p u t P r i n t t h e r e c o r d

P e r f o r m d e t a i l c a l c u l a t i o n : A d d C H G t o T O T A L

00000 7 4 2 oo742

o

Move data from record

s e l e c t e d i n t o p r o c e s s i n g a r e a

o

f : i g u r e 1 - 7 ( P a r t 2 o f 5 ) . l l l u s t r a t i o n o f D e t a i l a n d T o t a l T i m e

I 6 4 5 J O E A A R O N 7 4 2

o

o

o

a

C h a n g e in c o n t r o l f i e l d ? Y e s , t u r n o n c o n t r o l l e v e l in d i c a t o r L 1

o a

Bypass total operations because t h i s i s t h e f i r s t r e c o r d w i t h a c o n t r o l f i e l d .

o

R e c a l l th a t t h e r e i s a l w a y s a c o n t r o l b r e a k o n t h e f i r s t c y c l e , a l t h o u g h t o t a l o p e r a t i o n s are bypassed.

o

R P G l l L o g i c 1 - 9

(22)

JOE AARON 7.42

JOE AARON 6.43

a o

o

6 4 5 J O E A A R O N

Perform detail output:

o

Print the record

Perform

d e t a i l c a l c u l a t i o n : Add CHG to TOTAL

oo742 643 j 01385

Move dat€ from record sol€cted into

processing area

o

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

o

C h a n g e in c o n t r o l f i e l d ? No

a

o

(23)

o o

o

1 7 6 2 B I L L B E L L 1 3 4 2

o

o

o

Perform detail calculations:

A d d C H G t O T O T A L 00000

1342 01342

o

C h a n g e in c o n t r o l f i e l d ? Y e s , t u r n o n c o n t r o l l w e l i n d i c a t o r L 1

Move data from rscord selected into

processing area

P e r f o r m t o t a l o u t p u t : P r i n t T O T A L ,

O reset field to

zelo

o ,,,,1

F i g u r e 1 - 7 ( P a r t 4 o f 5 ) . l l l u s t r a t i o n o f D e t a i l a n d T o t a l T i m e

R P G l l L o g t c

(24)

1 645 1 645

J O E A A R O N J O E A A R O N

B I L L B E L L

J O H N B A R T

7 . 4 2 6.43 1 3 . 8 5 * 13.42 13.42-

24.93

a

a o

o

T u r n o f f c o n t r o l l e v e l i n d i c a t o r L1

P e r f o r m detail output:

P r i n t t h e r e c o r d

Perform detail calculation : Add CHG to TOTAL

00000 2493 o2493

a

Move data from record

selected into processing ares

o

o

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

O

a

o

C h a n g e in c o n t r o l field?

Y e s , t u r n on control l e v e l in d i c a t o r L1

o

P e r f o r m t o t a l o u t p u t : P r i n t T O T A L , reset field to zefo

:::::::::::tj:

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

:::;::iit;

O l::j::::i::;

. : ; : : : : ; : i

.i::j:::ij; O

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

,'.j.t""

F i g u r e 1 - 7 ( P a r t 5 of 5).

1 - 1 2

I 7 9 6 J O H N B A R T 2 4 9 3

1 6 4 5 J O E A A R O N 7 . 4 2

1645 JOE AARON 6.43

1 3 . 9 5 * 1 7 6 2 B I L L B E L L 1 3 . 4 2

lllustration of Detail and Total Time

(25)

1P' (F:irst Page) In<iicators

I t w a s s t a t e d b e f o r e th a t t h e f i r s t p r o g r a m c y c l e i s s l i g h t l y d i f f e r e n t f r o m t h e o t h e r s b e c a u s e t o t a l o p e r a t i o n s a r e b y ' p a s s e d o n t h e f i r s t c y c l e . A n o t h e r d i f f e r e n c e i n t h e f i r s t c v c l e r i s t h a t t h e f i r s t p a g e in d i c a t o r ( 1 P ) i s o n d u r i n g t h e b e g i n n i n g o f t h e c y c l e . A n y r e c o r d s c o n d i t i o n e d b y t h e 1 P i n d i c a t o r a r e p r i n t e d b e f o r e t h e f i r s t r e c o r d is r e a d . T l r i s i n d i c a t o r is u s e d to c o n d i t i o n r e c o r d s w h i c h a r e t o b e p r i n t e d o n t h e f i r s t p a g e o f a r e p o r t . T h e s e re c o r d s a r e u s , u a l l y h e a d i n g s u s e d to i d e n t i f y i n f o r m a t i o n f o u n d o n t h e p a g e , b u t n r a y a l s o b e d e t a i l l i n e s .

o

O Trrn off control l e v e l in d i c a t o r s L 1 - L g a n d l P

o

P e r f o r m h e a d i n g a n d d e t a i l o u t p u t f o r w h i c h c o n d i t i o n s h a v e b e e n m e t , i n c l u d i n g 1 P o u t p u t ( f i r s t c y c l e o n l Y )

Perform detail c a l c u l a t i o n s

Move data into O processing area

T h e 1 P in d i c a t o r i s t u r n e d o n o n l y fo r t h e b e g i n n i n g o f t h e f i r s t c y c l e . lt i s t u r n e d o f f b e f o r e a r e c o r d i s r e a d a n d is n e v e r u s e d a g a i n d u r i n g t h e p r o g r a m ( s e e F i g u r e 1 - 8 ) ' N o t i c e i n F i g u r e 1 - 8 th a t t h e p r o g r a m p e r f o r m s 1 P o u t p u t a n d o t h e r h e a d i n g a n d d e t a i l o u t p u t fi T s t w h e n it i s s t a r t e d '

This is always true. ln any program, 1P output and any o t h e r h e a d i n g o r d e t a i l o u t p u t fo r w h i c h s p e c i f i e d c o n d i - tions have been met is performed before the first record is r e a d . O n s u c c e e d i n g c y c l e s , h o w e v e r , i t i s u s u a l l y e a s i e r t o t h i n k o f r e a d i n g a r e c o r d a s th e fi r s t s t e p in t h e c y c l e '

C h a n g e in c o n t r o l f i e l d T l f y e s , t u r n o n c o n t r o l O l e v e l in d i c a t o r s

o o

o o

a

o

a

o

a

o

Bypass total o p e r a t i o n s

O ( 1 P i s o n )

F i g u r e 1 - 8 . L o g i c f o r t h e F i r s t P a g e (1 P l I n d i c a t o r

R P G l l L o g i c 1 - 1 3

(26)

Assume that a heading is desired on the report created by t h e p r e v i o u s e x a m p l e ( F i g u r e l - 7 ) . T h e h e a d i n g s h o u l d b e printed on the first page before any records are printed.

T h u s t h e h e a d i n g l i n e is c o n d i t i o n e d b y 1 p ( s e e F i g u r e l - g ) . Figure 1-10 shows what happens in the first cycte according t o R P G ll l o g i c .

IB}l ,",.,"", ...,

",,,n.,, Mg ^. co,F,., on

lFigure 1-9. Heading Line Conditioned by th€ First page Indicator

OUTPUT S P E C I F I C A T I O N S

"*flf "_

G ) n s r a n t or Edh Word

II iJ

: i i 1

7 5 1 6 7 1 7 A 7 9 N

P,qram t

Références

Documents relatifs

The model, which enables calculation of the data communications system performance, is described by the defined terms of error correction improvement factor, information

The procedures developed for analysis reverse this procedure in five processing steps: lexical lookup, surface grammar parsing, transformation reversal, context-sensitive

When a status operation is requested, the Common Synchronizer must connect the designated station status code to the A Register input data lines.. For the

Outstanding features include self modifying B- box operation, built in stencil in each order, dual half word arithmetic, programmable (serial or parallel)

(subtraction) with use of double precision orders. Addresses evenly divisible by four always correspond to the character read out as MO. Instruction words are

When control fields are specified for a record, the first pro- gram cycle may be slightly different from the others. Control level indicators are turned on by the first

The standard tnessage fbrrnat consists of characters of data When tl.re control sequence has been completed. the calling from the code selected. excluding specially designated

Because members are allowed to claim only two life suppor t courses (ie, Advanced Cardiac Life Suppor t, Advanced T rauma Life Suppor t, Advanced Life Support in Obstetrics) per