AZK RPG - Calling Programs

  1. Call Stack
    • - list of active programs in a job
    • - no "recursive call"
  2. Prototype
    • - in calling program
    • - prototype definition to define list of parameter's attributes to be sent to called program
    • - it passes parm arguments by passing the address of the storage location represented by parm
    • - Compiler does not define variables in parm-list and treats the parm-name as a comment
  3. Prototype has different name from Program
    • Dcl-pr Updcust Extpgm('AR002');
    •    Company  Char(5);
    •    Customer Zoned(7:0);
    • End-pr;
  4. Prototype has the same name as program
    • Dcl-pr AR002 Extpgm;
    •    Company  Char(5);
    •    Customer Zoned(7:0);
    • End-pr;
  5. Prototype with subfiled name duplicating opcode
    • Dcl-pr AR002 Extpgm;
    •    Dcl-parm Return  Char(5);
    •    Customer Zoned(7:0);
    • End-pr;
  6. Prototype with unnamed parameters
    • - Compiler does not define variables in parm-list and treats the parm-name (Company, Customer) as a comment
    • - that's why we can use unnamed parameters

    • Dcl-pr AR002 Extpgm;
    •    *N  Char(5);
    •    *N Zoned(7:0);
    • End-pr;
  7. Call prototyped procedure or program
    UpdCust(Company:CustNbr);
  8. Procedure Interface
    • - in the called program
    • - procedure interface definition to access storage location passed by calling program
    • - pi defines variable names to hold the parms
    • - program uses those names to refer the parms

    • Dcl-pi AR002;
    •    Company Char(5);
    •    Customer Zoned(7:0);
    • End-pi;
  9. Calling Program uses:
    • Dcl-pr
    •    - prototype definition to describe list of parms that will pass to the called program
    •    - it passes parm arguments by passing the address of the storage location represented by parm
    •    - prototypes in calling and called programs must match:
    •     1) same # of parameters
    •     2) corresponding parms must have the same data attributes

    • Dcl-pr Updcust Extpgm('AR002');      // calling program Pr
    •    *N Char(5);
    •    *N Zoned(7:0);
    • End-pr;
    •    . . .
    • UpdCust(Company:CustNbr);
  10. Called program AR002 uses:
    • Dcl-pr
    • - prototype definition to describe the corresponding list of parms that it is to receive from the caller

    • Dcl-pi
    • - procedure interface definition to access storage location passed by calling program

    • Dcl-pr AR002 Extpgm;        // called program Pr
    •    *N Char(9)
    •    *N Zoned(7:0);
    • End-pr;

    • Dcl-pi AR002;              // called program Pi
    •    Company Char(5);
    •    Customer Zoned(7:0);
    • End-pi;
  11. Main Procedure Interface
    • - it's good in called program to give main procedure interface consistent name 'Main'
    • - in this case Extpgm must refer to the actual program name

    • Dcl-pr Main Extpgm('AR002');    // Main Prototype
    •    *N Char(9);
    •    *N Zoned(7:0);
    • End-pr;

    • Dcl-pi Main;            // Main Interface
    •    Company Char(5);
    •    Customer Zoned(7:0);
    • End-pi;
  12. If program is called from program other than ILE RPG. . .
    • - if program is called from program other than ILE RPG, prototype is optional, but still recommended
    • - in the case if we omit the prototype, we need NOT name the procedure interface

    • Dcl-pi Extpgm('AR002');
    •    Company Char(5);
    •    Customer Zoned(7:0);
    • End-pi;
  13. Passing parameters by reference
    • - by default
    • - calling program passing parameters by passing the address of the
    • memory storage location represented by variable
    • - called program then uses that storage address to retrieve parm value
  14. Passing parameters by Read-only reference
    • - parm need NOT be represented by variable
    • - parm data type need NOT precisely match the prototype
    • - parm can be represented by literal ('BBY') or expression (Lastcust + 1)
    • - parm can NOT be changed by called program

    • Dcl-pr Updcust Extpgm('AR002');      // calling program Pr
    •    *N Char(5)    Const;
    •    *N Zoned(7:0) Const;
    • End-pr;
    •    . . .
    • UpdCust('BBY' : Lastcust + 1);

    • - if called program is written in another language that does not support prototyping, such as CL, it may be allowed to change the parm values
    • - But we shoult avoid so.
  15. - Return
    - returns control to the calling program
  16. *Inlr = *on
    - system releases any resources in called program
  17. *Inlr is not w/i the called program
    - called program remains activated (all variables and ind's keep values, all files remain opened)
  18. Data Area
    - system objects we use to share data b/w programs w/i a job or b/w jobs
  19. LDA
    • - Local Data Area
    • - system automatically creates LDA for each job in the system
    • - 1,024 position long - Character
    • - program w/i a job can share information in LDA
    • - when job ends, its LDA ceases to exist (destroyed)
  20. Commands to manage Data Area
    • CRTDTAARA - Create Data Area
    •    - created in this way DA remains an object on the system until we explicitly remove it
    • RTVDTAARA - Retrieve Data Area
    • CHGDTAARA - Change Data Area
    • DSPDTAARA - Display Data Area
    • DLTDTAARA - Delete Data Area
  21. Data Area Data Structure
    - makes DA accessible to a program

    • - Dtaara(*Auto)
    •    - identifies Data-Area Data Structure
    • - unnamed DA (*N) represents LDA
  22. Data Area Data Structure to use LDA
    - unnamed DA (*N) represents LDA

    • Dcl-ds *N Dtaara(*Auto);
    •    Returncode Ind;
    •    Company    Char(5);
    •    Nextresnbr Zoned(7:0);
    • End-ds;
  23. Data Area Data Structure to use Permanent DS
    • - for permanent DA name of the Ext DA must be provided
    • - usually name matches the Ext name
    • - PGM uses *LIBL/RESCOUNTER to populate the DS

    • Dcl-ds Rescounter Dtaara(*Auto);
    •    Returncode Ind;
    •    Company    Char(5);
    •    Nextresnbr Zoned(7:0);
    • End-ds;
  24. Data Area Data Structure to use Permanent DS in specific library
    • Dcl-ds Nextres Dtaara(*Auto:'MYLIB/RESCOUNTER');
    •    Returncode Ind;
    •    Company    Char(5);
    •    Nextresnbr Zoned(7:0);
    • End-ds;
  25. Name of the Data Area Data Structure does,t match name of the Permanent DS
    • Dcl-ds Nextres Dtaara(*Auto:'MYLIB/RESCOUNTER);
    •    Returncode Ind;
    •    Company    Char(5);
    •    Nextresnbr Zoned(7:0);
    • End-ds;
  26. Opcodes to manipulate Data Area
    • - In     - Retrieve a DA
    • - Out    - Write a DA
    • - Unlock - Unlock a DA so another pgms can read and update it
  27. *Usrctl
    - *Usrctl option - to use 'In', 'Out' and 'Uncock' with DA
  28. Code to manipulate Data Area
    • Dcl-ds Nextres Dtaara(*Auto:*Usrctl:'MYLIB/RESCOUNTER);
    •    Returncode Ind;
    •    Company    Char(5);
    •    Nextresnbr Zoned(7:0);
    • End-ds;
    •    . . .
    •       // - unlock DA, so another pgm can read and update it
    • Unlock Nextres;
    •    . . .
    • In *Lock Nextres;    // - to retrieve DA and lock it
    • Nextresnbr += 1;
    •    . . .
    • Out Nextres;        // - DA automatically unlocked
    • Out *Lock Nextres;    // - remains DA locked
    •    . . .
    • Unlock *Dtaara        // - unlocks all DA's locked by program
Author
flashsmilenet
ID
340579
Card Set
AZK RPG - Calling Programs
Description
AZK RPG - Calling Programs
Updated