Software Engineers Handbook - Language Dictionary - PLI - Procedures - Wikibooks, Open Books For An Open World
Software Engineers Handbook - Language Dictionary - PLI - Procedures - Wikibooks, Open Books For An Open World
Software Engineers Handbook - Language Dictionary - PLI - Procedures - Wikibooks, Open Books For An Open World
Software Engineers
Handbook/Language
Dictionary/PLI/procedures
Note: This article requires basic knowledge of PL/I which can be found in Software Engineers
Handbook/Language Dictionary/PLI.
https://en.wikibooks.org/wiki/Software_Engineers_Handbook/Language_Dictionary/PLI/procedures 1/10
5/1/24, 3:54 PM Software Engineers Handbook/Language Dictionary/PLI/procedures - Wikibooks, open books for an open world
Contents
Procedures
Procedures as Subroutines
Procedures as Functions
Changes of Parameter Variables
Asterisk Notation
Locale Variables
Scope
Storage Class
Multiple Entries
Multiple Parm Lists
Recursive Procedures
Entry Variables and Parameters
External Procedures
Static Linking
Fetched Procedures
"Pseudo-Fetching"
Notes
Procedures
Procedures as Subroutines
A PL/I program may contain user defined subroutines:
Procedures as Functions
https://en.wikibooks.org/wiki/Software_Engineers_Handbook/Language_Dictionary/PLI/procedures 2/10
5/1/24, 3:54 PM Software Engineers Handbook/Language Dictionary/PLI/procedures - Wikibooks, open books for an open world
"By reference" (also known as "by name") which means changes inside the procedure alters
the original variable.
"By value" (or "as dummy") which means changes inside the procedure alters only a copy of
the original variable.
In PL/I a variable which is
https://en.wikibooks.org/wiki/Software_Engineers_Handbook/Language_Dictionary/PLI/procedures 3/10
5/1/24, 3:54 PM Software Engineers Handbook/Language Dictionary/PLI/procedures - Wikibooks, open books for an open world
end change;
end example;
Asterisk Notation
If the size attribute of the parameter definition is an asterisk every matching variable with any
size is passed by reference.
If the dimension of the parameter definition is an asterisk every matching variable with any
dimension is passed by reference.
Locale Variables
Scope
The scope of PL/I variables is confined to procedures in which they are declared.
output:
'inner B'
'inner C'
'outer A'
'outer B'
https://en.wikibooks.org/wiki/Software_Engineers_Handbook/Language_Dictionary/PLI/procedures 4/10
5/1/24, 3:54 PM Software Engineers Handbook/Language Dictionary/PLI/procedures - Wikibooks, open books for an open world
end inner;
end outer;
Storage Class
There are two storage class locale variables may have.[2]
Automatic storage:
Multiple Entries
Procedures may have more than one entry.
https://en.wikibooks.org/wiki/Software_Engineers_Handbook/Language_Dictionary/PLI/procedures 5/10
5/1/24, 3:54 PM Software Engineers Handbook/Language Dictionary/PLI/procedures - Wikibooks, open books for an open world
value_write: ENTRY;
put skip list ( memory );
end value_set;
end example;
Syntax:
DCL procname
GENERIC ( procname_1 WHEN ( parm_descriptor_1 ) ,
procname_2 WHEN ( parm_descriptor_2 ) );
Meaning at compile time:
WHENEVER a call of procname is inside the source
IF the calling parameters are like parm_descriptor_1 THEN replace procname with procname_1
ELSE IF the calling parameters are like parm_descriptor_2 THEN replace procname with procname_2
ELSE throw compile error
Parm descriptor may contain the number of dimensions of the calling parameters:
Recursive Procedures
A procedure may be invoked recursively if the RECURSIVE option is specified.
https://en.wikibooks.org/wiki/Software_Engineers_Handbook/Language_Dictionary/PLI/procedures 6/10
5/1/24, 3:54 PM Software Engineers Handbook/Language Dictionary/PLI/procedures - Wikibooks, open books for an open world
Every invocation of the procedure has it's own value of the calling parameters
Every invocation of the procedure has it's own value of local variables which are automatic
All invocations of the procedure have a common value of local variables which are static
Output:
Level 1 started
loc_a = 11
loc_s = 111
Level 2 started
loc_a = 22
loc_s = 222
Level 3 started
loc_a = 33
loc_s = 333
loc_a = 33
loc_s = 333
Level 3 ended
loc_a = 22
loc_s = 333
Level 2 ended
loc_a = 11
loc_s = 333
Level 1 ended
https://en.wikibooks.org/wiki/Software_Engineers_Handbook/Language_Dictionary/PLI/procedures 7/10
5/1/24, 3:54 PM Software Engineers Handbook/Language Dictionary/PLI/procedures - Wikibooks, open books for an open world
do i = 1 to 5;
put skip list ( i || ':' || calc ( i ) );
end;
end list;
square_proc: proc ( v ) returns ( bin fixed (15) );
dcl v bin fixed (15);
return ( v * v );
end square_proc;
cube_proc: proc ( v ) returns ( bin fixed (15) );
dcl v bin fixed (15);
return ( v * square_proc ( v ) );
end cube_proc;
end example;
Output:
square-table:
1: 1
2: 4
3: 9
4: 16
5: 25
cube-table:
1: 1
2: 8
3: 27
4: 64
5: 125
External Procedures
A procedure may be external, i.e. the source may be contained in a separate file.
This approach offers the possibility to use this procedure in more than one main program.
Every program or procedure which uses an external procedure must declare this procedure.
Static Linking
Making a program executable requires two steps:
1. Compile the program and all the used external procedures in any order.
2. Use the linkage editor to combine the compile objects to an executable program.
https://en.wikibooks.org/wiki/Software_Engineers_Handbook/Language_Dictionary/PLI/procedures 8/10
5/1/24, 3:54 PM Software Engineers Handbook/Language Dictionary/PLI/procedures - Wikibooks, open books for an open world
The executable program now contains the binary code of its procedures at linking time,
i.e. if an external procedure is changed and recompiled after linking time this would not change the
behaviour of the executable program.
Fetched Procedures
PL/I allows dynamic linking of external procedures,
i.e. a main program may load the last compiled version of a procedure at run time.
The statement FETCH ABC loads the binary of procedure ABC from auxiliary storage into main
storage (unless ABC already exists in main storage).
"Pseudo-Fetching"
If in the example above both b1 and b2 are true ...
https://en.wikibooks.org/wiki/Software_Engineers_Handbook/Language_Dictionary/PLI/procedures 9/10
5/1/24, 3:54 PM Software Engineers Handbook/Language Dictionary/PLI/procedures - Wikibooks, open books for an open world
/* COMMENT: IF ABC IS NOT YET IN MAIN STORAGE THEN LOAD IT AUTOMATICALLY */
call abc;
end;
.....
if b2 then
do;
/* COMMENT: IF ABC IS NOT YET IN MAIN STORAGE THEN LOAD IT AUTOMATICALLY */
call abc;
/* COMMENT: IF DFG IS NOT YET IN MAIN STORAGE THEN LOAD IT AUTOMATICALLY */
call dfg;
end;
end example;
Notes
[1] or an array of structures of simple type variables ...
[2]
there are two more storage class (based and controlled for dynamically allocated storage)
which will be explained in another wikibooks PL/I special.
[3] in PL/I default values may be altered using the DEFAULT statement.
[4]the FREE statement for a fetched procedure will also free the local static variables of this
procedure.
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using
this site, you agree to the Terms of Use and Privacy Policy.
https://en.wikibooks.org/wiki/Software_Engineers_Handbook/Language_Dictionary/PLI/procedures 10/10