36915189-Adv-RPG-Chapter-10.ppt

17
Advanced RPG Chapter 10 Modular Programming Concepts

description

AS400 Modular Programming

Transcript of 36915189-Adv-RPG-Chapter-10.ppt

Page 1: 36915189-Adv-RPG-Chapter-10.ppt

Advanced RPG

Chapter 10

Modular Programming Concepts

Page 2: 36915189-Adv-RPG-Chapter-10.ppt

Modular Programming

• Developing smaller standalone units of code– makes units reusable– easier to test– code changes with less side effects– easier to spread among programming team

Page 3: 36915189-Adv-RPG-Chapter-10.ppt

Modular Programming

• Figure 10.1 Flow of Control with calls– Call passes control to called program until it

reaches a return, then it returns control to the program that called it.

Page 4: 36915189-Adv-RPG-Chapter-10.ppt

Modular Programming

• Dynamic binding: – compile each program separately – use call to invoke another program – System will look for program and bound it to

the calling program during runtime• reduced performance compared to subroutines

• Static binding:– introduced with ILE– option to connect modules prior to runtime

Page 5: 36915189-Adv-RPG-Chapter-10.ppt

Modular Programming

• Static binding:– Use CRTRPGMOD (create RPG module)– Creates object of type *Module (not *pgm)– Once modules are create, you create *pgm

and bind together the modules. – Once run, binding is completed and

performance is not affected.

Page 6: 36915189-Adv-RPG-Chapter-10.ppt

Modular Programming

• Use Call command to activate module– CALL (call a program, Dynamic)– CALLB (call a bound module, Static)– CALLP (call a Prototyped Procedure or

program)

Page 7: 36915189-Adv-RPG-Chapter-10.ppt

Modular Programming

• Call– Used to call objects of type *pgm– Use actual file name when possible– Can use a variable name– Will return to called program on return

• Be sure to turn on LR if you want subsequent calls to rerun the program, otherwise it will return to where you left off.

– Example: p. 211

Page 8: 36915189-Adv-RPG-Chapter-10.ppt

Modular Programming

• CallB– Invokes a program module *module– Cannot call a bound program *pgm– Can be a literal or variable– Example p.213

Page 9: 36915189-Adv-RPG-Chapter-10.ppt

Modular Programming

• PARM (Identify Parameters): used to pass values between called programs (works with Call and CallB)– List of Parms in calling program must have a

list of Parms in called program– Listed after the call

• Each field to pass is listed separately– Name of fields can be different but type and size must be

the same

Page 10: 36915189-Adv-RPG-Chapter-10.ppt

Modular Programming

C CALL ‘Prog2’

PARM FldA

PARM FldB

PARM FldC

Page 11: 36915189-Adv-RPG-Chapter-10.ppt

Modular Programming

• Alternative Option:

C PlistA PLISTPARM FldAPARM FldbPARM Fldc

C CALL ‘Prog2’ PlistA

Page 12: 36915189-Adv-RPG-Chapter-10.ppt

Modular Programming

• Called Program (can contain only one):

C *Entry PLISTPARM FldAPARM FldbPARM Fldc

(Fields or variables must be defined in called program)

Page 13: 36915189-Adv-RPG-Chapter-10.ppt

Modular Programming

• Parm passes address of storage location, therefore any changes in called program will be reflected in calling program. (pass by reference, not pass by value)

• Can get around this with modified Parm

C CALL ‘Prog 1’

PARM FldA FldX

Page 14: 36915189-Adv-RPG-Chapter-10.ppt

Modular Programming

• Additional CallB feature:– Two new keywords in D specs will cause

values to be parmed without specifically specifying it.

• Calling Program: EXPORT• Called Program: IMPORT

• Page 215 - 216

Page 15: 36915189-Adv-RPG-Chapter-10.ppt

Modular Programming

• Subprocedure: similar to subroutine– Can be independent from a program– Variables are not global through

subprocedures, they are local– Coding is more complex, p.216– CALLP is used to initiate a subprocedure that

does not return values.• Uses Prototype to pass values to called module.

Page 16: 36915189-Adv-RPG-Chapter-10.ppt

Modular Programming

• Prototype Differences:– VALUE keyword: actual value instead of

memory address is passed– CONST keyword: read only reference

Page 17: 36915189-Adv-RPG-Chapter-10.ppt

Modular Programming