-
Dynamic Program Call
- system looking for called program dynamically, during the run-time
-
Static Binding
- the calling and called components are bound together into a single *PGM object
-
Main Procedure
- a first user-written code that executes when program runs
-
Procedure
- is a self-contained, identifiable collection of RPG statements, w/i a program that performs a specific task and returns to the caller
-
Subprocedure
- - can be
- - created independently from the rest of the program
- - coded in separate source member
- - compiled in separate module
- - binded together when program is created
- - using local variables defined in the procedure
- - is recursive (can call itself)
- - can return a value to its caller outside the context of any parameter variables
-
Subprocedure Examnple
- Dcl-proc Celcius;
- // Procedure Interface
- Dcl-pi *N Int(5); // Int(5) - data attributes of the return value
- Fahrenheit Int(5); // accepts one parm Fahrenheit Int(5)
- End-pi;
- .
- Dcl-s Temperature Int(5); // - declaration of the return variable.
- Eval(H) Temperature = (5/9) * (Fahrenheit - 32);
- Return Temperature; // - returns variable's value (not variable itself)End-proc;
- - *N - NO interface name b/c subpr can have only one interface
- - Int(5) - data attributes of the return value
- - subpr can have only SINGLE return value
- - can be DS (using Likeds keyword)
- - can be array (using Dim keyword)
- - this subpr accepts one parm Fahrenheit Int(5)
-
Static KW
- - makes local var to preserve (keep) it's value b/w calls
- - will keep file opened for the next time the program call the procedure
- Dcl-s Temperature Int(5) Static;
- Dcl-f Customer Static;
-
Return Op Code w/i subprocedure
- - to return value
- Return Temperature;
- - return value can be expression or literal
- Return (5/9) * (Fahrenheit - 32);
-
Subprocedure Prototype
- - should be included within subpro source member, but outside the subpro
- .
- Dcl-pr Celcius Int(5);
- *N Int(5);
- End-pr;
-
Executing Procedure
- - Metrictemp keeps returned value
- Metrictemp = Celcius(Englichtemp);
- .
- - caller can be comparison expression
- If Celcius(Englichtemp) > 100;
- Endif;
-
Cycle Main Programs
- includes subprocedure w/i the same source (local procedure)
-
Linear Main Programs
- - does NOT include the RPG cycle
- - main section does not include any executable code, only global declarations
- - there is NO *Inlr - does not cleanup or close any resources
- - is recursive (can call itself)
- - when program starts implicitly...
- - initializes variables
- - locks data areas
- - open files
- - when program ends...
- - program must explicitly cleaned up or close all resources using operations
- - Ctl-opt 'Main' kw is a key to create a Linear program
- - explicitly names a procedure to be the Main Procedure
- .
- Ctl-opt Main(Driver);
-
Nomain Modules
- - contain only global declarations and subprocedures that can be combined w other modules to create a program
- - by itself it cannot create an object
- - Ctl-opt 'Nomain' kw is a key to create a Nomain Module
- .
- Ctl-opt Nomain;
-
Main KW
- - is a key to create a Linear program and specify main procedure in Linear Program
- Ctl-opt Main(proc-name);
-
Nomain KW
- - is a key to create a Nomain Module
- Ctl-opt Nomain;
-
Export KW
- - allows procedure to be called from outside of Nomain Module
- - w/o Export, procedure can be executed only from another procedure w/i this module
- Dcl-proc proc-name Export;
-
Command to create single-module program
- CRTBNDRPG
- - combines 2 program creation steps
- 1) Compile - creates *Module object
- 2) Bind - creates *Pgm object
-
CRTBNDRPG
- - command to create single-module program
- - combines 2 program creation steps
- 1) Compile - creates *Module object
- 2) Bind - creates *Pgm object
-
With Moduling Programming we have to use command...?
- 1) CRTRPGMOD (compile) - creates RPG *Module object
- - contains compiled executable code
- - can not be run by itself
- 2) CRTPGM (bind) - creates *Pgm object
- - physically copies compiled code from the modules into a program object
- - creates runable program
-
Build-by-copy
- - to create multiple-module program single entry-point program
- - CRTPGM
(bind) - creates *Pgm object- binding step that physically copyes the compiled code from the module into program
-
CRTPGM Command (detail, example)
- - to create multiple-module program single entry-point program - *Pgm Object
- - binding step that physically copyes the compiled code from the module into program
- - supports subprocedures and linear programs
- - entry point is a module which suppose to have Main Procedure
- - module can be written by any ILE language
- .
- CRTPGM PGM(pgm-name) + - name of the final program object
- MODULE(module-llist) + - list of the modules to bind (up to 300)
- ENTMOD(entry-module) - which of those modules is the entry module
- .
- CRTPGM PGM(ANATOLIYK/CEL_MODE)
- MODULE(ANATOLIYK/CEL_MODE ANATOLIYK/CELSIUS) +
- ENTMOD(ANATOLIYK/CEL_MODE)
-
Binding Directory
- an object (type *Bnddir) that contains a list of the modules and service programs
-
Command to create Binding Directory
CRTBNDDIR
-
Work w Binding Directory Entries command
- WRKBNDDIRE
- - To update (add or delete modules or Srv Pgm) Binding directory
- .
- WRKBNDDIRE BNDDIR(MOD_BNDDIR)
-
Display Binding Directory command
- DSPBNDDIR
- - To display Binding directory
- .
- DSPBNDDIR BNDDIR(MOD_BNDDIR)
-
CRTPGM command w all parameters including BNDDIR
- CRTPGM PGM(DRI_MAIN) // - name of the final program object
- MODULE(DRI_MAIN) // - defaults to using a module w the same name as program
- ENTMOD(DRI_MAIN) // - defaults to using the first listed module
- BNDDIR(MOD_BNDDIR) // - binding directory name
-
CRTPGM command (simplyfied) using default values of parameters
- CRTPGM PGM(DRI_MAIN) // - name of the final program object
- BNDDIR(MOD_BNDDIR) // - binding directory name
-
Command that lets you to replace only updated modules from original program
- UPDPGM
- - lets you list just the module(s) that you want to replace from original program with the new version of module(s)
- - performs the same function as CRTPGM, except that it replaces only module(s) from the list
- .
- UPDPGM PGM(ANATOLIYK/DRI_MAIN)
- MODULE(ANATOLIYK/DRI_MAIN ANATOLIYK/CEL_NOMAIN)
-
UPDPGM
- - lets you list just the module(s) that you want to replace from original program with the new version of module(s)
- - performs the same function as CRTPGM, except that it replaces only module(s) from the list
- .
- UPDPGM PGM(ANATOLIYK/DRI_MAIN)
- MODULE(ANATOLIYK/DRI_MAIN ANATOLIYK/CEL_NOMAIN)
-
Pass parms by value
- - it does NOT share storage address w called procedure
- - caller passes parm's actual value
- - called proc can make changes, but caller will never recognize them
- - coller's storage is ABSOLUTELY protected from change
- .
- Calling Procedure
- Dcl-pr Celsius Int(5);
- *N Int(5) Value;
- *N Char(256); // we can mix methods
- End-pr;
- .
- Called Procedure
- Dcl-pi Celsius Int(5);
- Fahrenheit Int(5) Value;
- Errmsg Char(256); // we can mix methods
- End-pi;
-
Value KW
- - to pass marms by value
- - it does NOT share storage address w called procedure
- - caller passes parm's actual value
- - called proc can make changes, but caller will never recognize them
- - coller's storage is ABSOLUTELY protected from change
- .
- Calling Procedure
- Dcl-pr Celsius Int(5);
- *N Int(5) Value;
- *N Char(256); // we can mix methods
- End-pr;
- .
- Called Procedure
- Dcl-pi Celsius Int(5);
- Fahrenheit Int(5) Value;
- Errmsg Char(256); // we can mix methods
- End-pi;
-
For locally scoped files (used w/i subprocedures) we must use...
a result Ext DS to hold data
-
To use PF w/i subrpocedure
- 1) Declare file w/i declaration block
- Dcl-f Customer;
- 2) Declaring result DS
- - w Likerec KW
- Dcl-ds Custdata Likerec(Custsrec);
- - w Extname KW
Dcl-ds Custdata Extname('CUSTOMERS':'CUSTSREC':*All);
- - *All - fields included from Rec Format
- - other allowed KW - *Input, *Output
- 3) Read file Customer specifying Ext DS Custdata
- Read Customers Custdata;
-
To use DSPF w/i subrpocedure
- 1) Declare file w/i declaration block.
- Dcl-f Wndyesno Workstn;
- .
- 2) Declaring result DS's w Likerec KW
- - all DS's are Qualified
- - NO End-ds b/c no additional subfields are allowed
- .
- a) *Input for Read opcode
- .
- Dcl-ds Windynds_I Likerec(WNDYESNOR:*Input);
- .
- b) *Output for Write opcode
- .
- Dcl-ds Windynds_O Likerec(WNDYESNOR:*Output);
- .
- c) *All for Exfmt opcode
- .
- Dcl-ds Windynds_A Likerec(WNDYESNOR:*All);
- .
- 3) To loald fields and display DSPF
- .
- Windynds_A.F001 = '1';
- Windynds_A.F002 = '1';
- .
- Exfmt WNDYESNOR Windynds_A;
- .
- 4) To write to DSPF
- .
- Windynds_O.F001 = '2';
- Windynds_O.F002 = '3';
- .
- Write WNDYESNOR Windynds_O;
- .
- 5) To read from DSPF
- .
- Read WNDYESNOR Windynds_I;
-
Compiller Directives
- /Copy
- /Include
- - compiling directive
- - begins w (/) in position 7 or later
- - to store source records in a secondary source member (copybook)
- - copy that source into a primary source member at compile time
- - can appear anywhere in a source
- - useful for storing prototypes
- .
- This is Compiler Directives
- .
- /Copy Mylib/Mysource,Prototypes
- /Include Mylib/Mysource,Prototypes.
- .
- - Mylib - library (default *LIBL)
- - Mysource - source file (default *QRPGLESRC)
- - Prototypes - source member name w all reusable prototype definitions (must specify)
- .
-
Compiller Directives processing SQL
- /Copy
- - expanded by SQL processor
- - /Copy program file may have its own embedded SQL code
- /Include
- - is NOT expanded by SQL processor
- - /Include program file CANNOT have its own embedded SQL code
-
Template KW
- - variable or DS definitions that can be used as templates for the definition of another data items
- - can be uses only w Like or Likeds KW's
- - can be part of copybook.
- Dcl-ds Templ_Indicators Len(99) Template;
- Exit Ind Pos(3);
- . . .
- End-ds
- .
- - Another source members that use /Copy to include the copybook code can then define a DS based on the template
- .
- Dcl-ds Indicators Likeds(Templ_Indicators);
-
Conditional Compiller Directives
- - /Define
- - names a condition and adds it to a list of currently defined conditions
- .
- - /Undefine
- - removes the condition from the list
- .
- - /If, /Elsif, /Else, /Endif
- - to test a condition's state
- .
- - /Eof
- - to direct the compiler to ignore the rest of the subsequent source
-
Using Conditional Compiller Directives
- This is copybook source member 'Prototypes' w all reusable ptototype definitions
- .
- // ----- Prototype: DayName
- .
- /If Defined(Pr_Dayname)
- Dcl-pr DayName Char(9);
- *N Date Value;
- End-pr;
- /Endif
- .
- // ----- Prototype: Dayofweek
- .
- /If Defined(Pr_Dayofweek)
- Dcl-pr Dayofweek Packed(1:0);
- *N Date Value;
- End-pr;
- /Endif
- .
- // ----- Prototype: Pr_Isweekday
- .
- /If Defined(Pr_Isweekday)
- Dcl-pr Pr_Isweekday Ind;
- *N Date Value;
- End-pr;
- /Endif
- .
- In each program that uses the pocedures, add the appropriate condition name to the compiler's list of conditions
- .
- /Define Pr_Dayname
- /Define Pr_Isweekday
- /Copy MyLib/MySource,Prototypes
- .
- Only prototypes that defined under conditions Pr_Dayname and Pr_IsWeekday w/i 'Prototypes' copybook will be compiled
|
|