Professional Documents
Culture Documents
Part 13
System looks for called program when Callp executes Dynamic object resolution process may cause performance problem for callintensive applications
2
Static Binding
Integrated Language Environment (ILE) includes option of connecting modules before runtime
Static binding
Binding step
CRTPGM creates *PGM object Not language specific
Bind-by-copy
Binding step physically copies code from module to program
4
Modules can be written in different languages Binding step designates one module as entry module
First module that will execute
ILE program consists of main procedure and, optionally, one or more subprocedures
Are recursive
Can call themselves
9
Appropriate when
Procedure will not be reused in several programs Need features beyond subroutines Relegate complex code to subprocedure
10
Procedure Prototype
Lets compiler compare parameter definitions in calling and called procedures
Checks for inconsistencies that could cause bugs when program runs
Parameter description(s)
12
Procedure Prototype
Prototype header
Prototype name (7-21) Definition type (24-25)
PR = Prototype
Procedure Prototype
Parameter description(s) same as program prototype
Comment (7-21)
Optional
Parameter length (3339) Parameter data type (40) Parameter decimal positions (4142)
*.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++++ D Celsius PR 5 0 D 5 0
14
Calling a Procedure
If procedure supports return value, it can be included in expression
Otherwise, use Callp
Metrictemp = Celsius(Englishtemp); If Celsius(Englishtemp) > 0; Status = Thawed; Else; Status = Freezing; Endif;
15
18
19 continued
continued
*.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 PName+++++++++++..T...................Functions++++++++++++++++++++++++++++ DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++++ // ---------------------------------------------------------------------// // Procedure ... Celsius ... Converts Fahrenheit to Celsius // // ---------------------------------------------------------------------P Celsius B
D D Fahrenheit
PI
5 5
0 0
// ------------------------------------------------------ Local variables D Temperature S 5 0 /Free Eval(H) Temperature = (5/9) * (Fahrenheit - 32); Return Temperature; /End-Free P Celsius E
20
21
23
THISPGM
// ----------------------------------------------------- Global variables D Metrictemp S 5 0 D Englishtemp S 5 0 Inz(212) D Status S 8 // ------------------------------------------------------- Main procedure /Free Metrictemp = Celsius(Englishtemp); If Celsius(Englishtemp) > 0; Status = Thawed; Else; Status = Freezing; Endif; *Inlr = *On; Return; /End-Free
24
D-specs
Must include prototype
P-specs
Includes Export keyword to make procedure available to other modules in program
Without Export, other modules cannot find procedure
25
CELSIUS
D D
P D D D
// ----------------------------------------------------------- Prototypes Celsius PR 5 0 5 0 // ---------------------------------------------------------------------// Procedure ... Celsius ... Converts Fahrenheit to Celsius // ---------------------------------------------------------------------Celsius B Export PI 5 0 Fahrenheit 5 0 // ------------------------------------------------------ Local variables Temperature S 5 0 /Free Eval(H) Temperature = (5/9) * (Fahrenheit - 32); Return Temperature; /End-Free
P Celsius
26
27
28
Parameter data types need not exactly match prototype Absolute protection against parameter values being changed by called procedure
29
Export module allocates storage for data item Import module uses storage allocated by Export module Both modules must be bound to same program
31
Primary module
Module PROCA
*.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++ D Proca PR // Vara gets its value from primary module D Vara S 9 2 Import P Proca B P Proca E
32
34
35
36
38
39
Bind by copy
Bind by reference
40
41
42
43
Signature is stored in service program and in each program that uses it When caller loads, signature it expects must exist in service program
Otherwise program activation fails
45
46
47
Binder language controls signatures As service program changes, programs that use it may not need to be rebound
As long as signature is still supported
48
50