1 / 17

Advanced RPG

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.

danil
Download Presentation

Advanced RPG

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Advanced RPG Chapter 10 Modular Programming Concepts

  2. 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

  3. 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.

  4. 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

  5. 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.

  6. 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)

  7. 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

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

  9. 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

  10. Modular Programming C CALL ‘Prog2’ PARM FldA PARM FldB PARM FldC

  11. Modular Programming • Alternative Option: C PlistA PLIST PARM FldA PARM Fldb PARM Fldc C CALL ‘Prog2’ PlistA

  12. 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)

  13. 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

  14. 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

  15. 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.

  16. Modular Programming • Prototype Differences: • VALUE keyword: actual value instead of memory address is passed • CONST keyword: read only reference

  17. Modular Programming

More Related