-
Call Stack
- - list of active programs in a job
- - no "recursive call"
-
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
-
Prototype has different name from Program
- Dcl-pr Updcust Extpgm('AR002');
- Company Char(5);
- Customer Zoned(7:0);
- End-pr;
-
Prototype has the same name as program
- Dcl-pr AR002 Extpgm;
- Company Char(5);
- Customer Zoned(7:0);
- End-pr;
-
Prototype with subfiled name duplicating opcode
- Dcl-pr AR002 Extpgm;
- Dcl-parm Return Char(5);
- Customer Zoned(7:0);
- End-pr;
-
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;
-
Call prototyped procedure or program
UpdCust(Company:CustNbr);
-
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;
-
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);
-
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;
-
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;
-
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;
-
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
-
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.
-
- Return
- returns control to the calling program
-
*Inlr = *on
- system releases any resources in called program
-
*Inlr is not w/i the called program
- called program remains activated (all variables and ind's keep values, all files remain opened)
-
Data Area
- system objects we use to share data b/w programs w/i a job or b/w jobs
-
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)
-
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
-
Data Area Data Structure
- makes DA accessible to a program
- - Dtaara(*Auto)
- - identifies Data-Area Data Structure
- - unnamed DA (*N) represents LDA
-
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;
-
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;
-
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;
-
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;
-
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
-
*Usrctl
- *Usrctl option - to use 'In', 'Out' and 'Uncock' with DA
-
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
|
|