Advanced RPG
E N D
Presentation Transcript
Advanced RPG Chapter 10 Modular Programming Concepts
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
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.
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
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.
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)
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
Modular Programming • CallB • Invokes a program module *module • Cannot call a bound program *pgm • Can be a literal or variable • Example p.213
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
Modular Programming C CALL ‘Prog2’ PARM FldA PARM FldB PARM FldC
Modular Programming • Alternative Option: C PlistA PLIST PARM FldA PARM Fldb PARM Fldc C CALL ‘Prog2’ PlistA
Modular Programming • Called Program (can contain only one): C *Entry PLIST PARM FldA PARM Fldb PARM Fldc (Fields or variables must be defined in called program)
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
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
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.
Modular Programming • Prototype Differences: • VALUE keyword: actual value instead of memory address is passed • CONST keyword: read only reference