Beruflich Dokumente
Kultur Dokumente
DAY 2
Procedures
NAME: A: PROCEDURE;
.
Primary Entry Point
.
.
END NAME;
Secondary Entry Point
END Statement;
Label Optional
Both internal and external procedures are normally loaded into main storage
at the same time as the invoking procedure.
However, an external procedure can be compiled separately from the
invoking procedure and loaded when needed.
By the use of FETCH and RELEASE statements, the invoking procedure
loads the external procedure into main storage and deletes it when it is no
longer required.
The use of arguments and parameters provides the means for generalizing
procedures so that data whose names are not known within such
procedures can, nevertheless, be operated upon.
A parameter has no storage associated with it. It is merely a means of
allowing the invoked procedure to access storage allocated in the invoking
procedure. A reference to a parameter in a procedure is a reference to the
corresponding argument. Any change to the value of the parameter is made
to the value of the argument
A procedure (subroutine or function) can have one or more entry points. The
primary entry point to a procedure is established by the leftmost label of the
PROCEDURE statement.
Secondary entry points to a procedure are established by additional labels
of the PROCEDURE statement and by the ENTRY statement. Each entry
point has an entry name.
Each PROCEDURE or ENTRY statement can specify its own parameters
and, in the case of functions, returned value attributes.
a PROCEDURE or ENTRY statement has more than one entry constant the
first can be considered as the only label of the statement.
Each subsequent entry constant can be considered as a separate ENTRY
statement having an identical parameter list as specified in the
PROCEDURE statement.
For example:
A: I: PROCEDURE (X);
is the same as
A: PROCEDURE (X);
I: ENTRY (X);
entry-constant:
PROCEDURE (parameter) ,
RETURNS (attribute)
OPTIONS (characteristic list)
IRREDUCIBLE/REDUCIBLE
RECURSIVE
ORDER/REORDER
GRAPHIC/CHARGRAPHIC
entry-constant:
ENTRY (parameter) ,
RETURNS (attribute)
OPTIONS (characteristic list)
IRREDUCIBLE/REDUCIBLE
Characteristic List
FETCHABLE
MAIN
NOEXEOPS
COBOL
FETCHABLE NOMAPOPTIONS
BYADDR/BYVALUE
RENTRANT
TASK
NOMAPOPTIONS
The options are separated by blanks or commas. They can appear in any
order.
OPTIONS can be specified only for an external procedure, and only one
procedure must have the OPTIONS (MAIN) designation.
BYADDR or BYVALUE options Specify how all parameters defined for this
procedure entry are passed.
If you specify BYADDR, parameters are received by address.
If you specify BYVALUE, parameters are received by value.
Any change to a parameter that is being passed by value is not reflected in
the argument passed by the caller.
BYADDR is the default unless the procedure is MAIN and is being compiled
with the SYSTEM(CICS) or SYSTEM(IMS) compile-time options.
In this case, BYVALUE is implied and BYADDR is invalid.
For example:
The PL/I procedure is the initial procedure of a PL/I program. The operating
system control program invokes it as the first step in the execution of that
program.
NOEXECOPS The NOEXECOPS option is valid only with the MAIN option.
It indicates that the character string is passed to the main procedure without
evaluating the run-time options for the SYSTEM(MVS), SYSTEM(CMS),
and SYSTEM(CMSTPL) compile-time options.
The run-time options are not honored if they are received. NOEXECOPS is
also implied with the SYSTEM(IMS), SYSTEM(CICS), and the
SYSTEM(TSO) compile-time options.
The mapping of a data aggregate passed by COBOL might not match the
mapping used by PL/I.
If PL/I detects a possible mapping discrepancy, PL/I creates a dummy
argument for the data aggregate.
The dummy argument uses the PL/I mapping algorithm.
PL/I then automatically assigns the incoming data aggregate values to the
dummy argument.
The PL/I routine uses the dummy argument.
On return to COBOL routine, the dummy argument values are remapped to
the data aggregate.
You can use the NOMAP, NOMAPIN and NOMAPOUT options to prevent
this automatic mapping of values
NOMAP
Specifies no mapping of values either at entry to PL/I or on return to
COBOL. When you specify this option, PL/I does not create a dummy
argument.
NOMAPIN
Specifies no mapping of values at entry to PL/I. When you specify this
NOMAPOUT
Specifies no mapping of values on return to COBOL. When you specify
The NOMAP, NOMAPIN and NOMAPOUT options are effective only for
structures that are passed from COBOL.
The options do not apply to scalars. Use these options when program
efficiency is important. These options help you avoid unnecessary mapping
code.
NOMAP, NOMAPIN, and NOMAPOUT can all appear in the same
OPTIONS specification. Specifying NOMAPIN and NOMAPOUT for the
same parameter is the same as specifying NOMAP for that parameter.
ORDER and REORDER are optimization options that are specified for a
procedure or begin-block.
If neither option is specified for the external procedure, ORDER is the
default. The default for internal blocks is to inherit ORDER or REORDER
from the containing block.
The ORDER option indicates that only the most recently assigned values of
variables modified in the block are available for ON-units that are entered
because of computational conditions raised during statement execution and
expressions in the block.
The REORDER option allows the compiler to generate optimized code to
produce the result specified by the source program when error-free
execution takes place.
An active procedure that is invoked from within itself or from within another
active procedure is a recursive procedure; such an invocation is called
recursion.
A procedure that is invoked recursively must have the RECURSIVE option
specified in its PROCEDURE statement. This option also applies to any
secondary entry points that the procedure might have.
The environment (that is, values of automatic variables, etc). of every
invocation of a recursive procedure is preserved in a manner analogous to
the stacking of allocations of a controlled variable. Think of an environment
as being pushed down at a recursive invocation, and popped up at the
termination of that invocation. A label constant in the current block is always
a reference to the current invocation of the block that contains the label.
I=1;
CALL A; /* FIRST INVOCATION OF A */
A: PROC RECURSIVE;
DECLARE EV ENTRY VARIABLE STATIC;
IF I=1 THEN
DO;
I=2;
EV=B;
CALL A; /* 2ND INVOCATION OF A */
END;
ELSE CALL EV; /* INVOKES B WITH ENVIRONMENT */
/* OF FIRST INVOCATION OF A */
B: PROC;
GO TO OUT;
END B;
OUT: END A;
The GO TO statement in the procedure B transfers control to the END A statement in the
first invocation of A, and terminates B and both invocations of A.
The FETCH statement checks main storage for the named procedures. The
named procedures must not be internal procedures. Procedures not already
in main storage are loaded from auxiliary storage.
The RELEASE statement frees for other purposes main storage occupied
by procedures identified by the specified entry constants.
PRMAIN: PROCEDURE;
DECLARE NAME CHARACTER (20),
ITEM BIT(5),
OUTSUB ENTRY;
CALL OUTSUB (NAME, ITEM);
END PRMAIN;
The CALL statement in PRMAIN invokes the procedure OUTSUB, and the
argument list in this procedure reference contains the two arguments being
passed to OUTSUB.
The PROCEDURE statement defining OUTSUB associates two parameters,
A and B, with the passed arguments. When OUTSUB is executed, each
reference to A in OUTSUB is treated as a reference to NAME and each
reference to B is treated as a reference to ITEM.
Therefore, the PUT LIST (A,B) statement transmits the values of NAME and
ITEM to the output file, SYSPRINT.
In the declaration of OUTSUB within PRMAIN, no parameter descriptor has
to be associated with the ENTRY attribute, since the attributes of NAME and
ITEM match those of, respectively, A and B.
A: PROCEDURE;
DECLARE RATE FLOAT (10), The arguments RATE, TIME,
TIME FLOAT(5), DISTANCE, and MASTER are passed
DISTANCE FLOAT(15),
MASTER FILE; to the procedure READCM and
CALL READCM (RATE, TIME, associated with the parameters W, X,
DISTANCE, MASTER); Y, and Z. Consequently, in the
READCM: subroutine, a reference to W is the
PROCEDURE (W,X,Y,Z); same as a reference to RATE, X the
DECLARE W FLOAT (10),
X FLOAT(5),
same as TIME, Y the same as
Y FLOAT(15), Z FILE; DISTANCE, and Z the same as
GET FILE (Z) LIST (W,X,Y); MASTER.
Y = W*X;
IF Y > 0 THEN
RETURN;
ELSE
PUT LIST('ERROR READCM');
END READCM;
END A;
You can make use of built-in subroutines. These have entry names that are
defined at compile-time and are invoked by a CALL statement. The entry
names are known as built-in names, and can be explicitly or contextually
declared to have the BUILTIN attribute.
PLITDLI and ASMTDLI cannot be declared with the BUILTIN attribute but are
treated as special subroutines.
RETURN (expression);
Arrays
Data Items
Any individual element of an array is referred to by giving its position within the
array.
This attribute also specifies either the bounds of each dimension or indicates
that the upper bound is taken from an associated argument.
Bounds that are expressions are evaluated and converted to FIXED BINARY
(31,0) when storage is allocated for the array.
The extent is the number of integers between, and including, the lower and
upper bounds.
Examples
The lower bound must be less than or equal to the upper bound.
Data items are assigned to an array in row major order, that is, with the right-
most subscript varying most rapidly.
Any expression that yields a valid arithmetic value can be used for a subscript.
For example, TABLE(*,1) refers to all of the elements in the first column of
TABLE. It specifies the cross section consisting of TABLE(1,1), TABLE(2,1),
TABLE(3,1), and TABLE(4,1).
The subscripted name TABLE(2,*) refers to all of the data items in the second
row of TABLE.
Therefore, all arrays referred to in an array expression must have the same
number of dimensions, and each dimension must be of identical bounds.
Array Expressions
Array and Element Operations Array and Array Operations Array and Structure Operations
Each element of the resulting array is the result of the operation between each
corresponding element of the original array and the single element. For
example:
If A is the array
5 10 8
12 11 3
then A*3 is the array
15 30 24
36 33 9
50 100 800
1200 1100 300
If the two operands of an infix operator are arrays, the arrays must have the
same number of dimensions, and corresponding dimensions must have
identical lower bounds and identical upper bounds.
The result is an array with bounds identical to those of the original arrays; the
operation is performed upon the corresponding elements of the two original
arrays. For example:
A + B A+B
2 4 3 1 5 7 3 4 10
6 1 7 8 3 4 14 4 11
4 8 2 6 3 1 10 11 3
Programming Example
DCL X(100),
XA(99) DEFINED(X),
XB(99) DEFINED(X(1SUB+1));
If the two operands of an infix operator are an array and a structure, the result
is an array of structures with bounds identical to the array.
The structuring of the result is identical to the original structure. In the following
example:
ALL
ANY
DIM
HBOUND
LBOUND
POLY
PROD
SUM
ALL returns a bit string in which each bit is 1 if the corresponding bit in each
element of x exists and is 1. The length of the result is equal to that of the
longest element.
ALL(X)
X is an Array expression.
ANY returns a bit string in which each bit is 1 if the corresponding bit in any
element of x exists and is 1. The length of the result is equal to that of the
longest element.
The syntax for ANY is:
ANY(X)
X is an Array expression.
DIM returns a FIXED BINARY (31,0) value specifying the current extent of
dimension y of x.
DIM (x, y)
x Array expression.
x must not have less than y dimensions, and x must not be an array of
structures.
HBOUND returns a FIXED BINARY (31,0) value specifying the current upper
bound of dimension y of x.
HBOUND (x, y)
x Array expression.
x must not have less than y dimensions, and x must not be an array of
structures.
y must be greater than or equal to 1.
LBOUND returns a FIXED BINARY (31,0) value specifying the current lower
bound of dimension y of x.
LBOUND (x, y)
x Array expression.
x must not have less than y dimensions, and x must not be an array of
structures.
y must be greater than or equal to 1.
PROD returns the product of all the elements in x. The syntax for PROD is:
PROD (x)
x Array expression.
If the elements of x are strings, they are converted to fixed-point integer values.
If x is a reference to a defined variable, x must not be iSUB-defined.
SUM returns the product of all the elements in x. The syntax for SUM is:
SUM (x)
x Array expression.
If the elements of x are strings, they are converted to fixed-point integer values.
If x is a reference to a defined variable, x must not be iSUB-defined.
Structures
Like an array, the entire structure is given a name that can be used to refer to
the entire aggregate of data.
Minor structures and elementary names are declared with level numbers
greater
than 1.
DECLARE 1 PAYROLL,
4 NAME,
5 LAST CHAR(20),
5 FIRST CHAR(15),
2 HOURS,
6 REGULAR FIXED DEC(5,2),
5 OVERTIME FIXED DEC(5,2),
2 RATE,
3 REGULAR FIXED DEC(3,2),
3 OVERTIME FIXED DEC(3,2);
Structure-qualification is in the order of levels; that is, the name at the highest
level must appear first, with the name at the deepest level appearing last.
Names within a structure, except the major structure name itself, need not be
unique within the procedure in which it is declared.
Qualifying names must be used only so far as necessary to make the reference
unique.
DECLARE 1 A, 2 C, 2 D, 3 E;
BEGIN; DECLARE 1 A, 2 B, 3 C, 3 E;
A.C = D.E;
A.C refers to the C in the inner block and D.E refers to E in the outer block.
DECLARE 1 A, 2 B, 2 B, 2 C, 3 D, 2 D;
DECLARE 1 A, 2 B, 3 C, 2 D, 3 C;
DECLARE 1 A, 2 A, 3 A;
In this example, a reference to A refers to the first A, A.A to the second A, and
A.A.A to the third A.
DECLARE X;
DECLARE 1 Y, 2 X, 3 Z, 3 A,
2 Y, 3 Z, 3 A;
The LIKE attribute specifies that the variable being declared is a structure
variable with the same structuring as the variable following the attribute
keyword LIKE.
LIKE structure-variable
The structure-variable must be known in the block containing the LIKE attribute
specification.
The structure names in all LIKE attributes are associated with declared
structures before any LIKE attributes are expanded. Neither the structure-
variable nor any of its substructures can be declared with the LIKE attribute.
DECLARE 1 A, 2 C, 3 E, 3 F,
1 D(10), 2 C, 3 G, 3 H;
.
.
BEGIN; DECLARE 1 A LIKE D;
DECLARE 1 B(2) LIKE A.C;
.
.
END;
DECLARE 1 A LIKE C,
No
1 B,
because the LIKE attribute of A
2 C,
specifies a structure, C, that
3 D, contains an identifier, E, that has
3 E LIKE X, the LIKE attribute.
2 F,
1 X,
2 Y;
e.g.
DECLARE 1 WEATHER(12),
2 TEMPERATURE,
3 HIGH DECIMAL FIXED(4,1),
3 LOW DECIMAL FIXED(3,1),
2 WIND_VELOCITY,
3 HIGH DECIMAL FIXED(3),
3 LOW DECIMAL FIXED(2),
2 PRECIPITATION,
3 TOTAL DECIMAL FIXED(3,1),
3 AVERAGE DECIMAL FIXED(3,1);
DECLARE 1 A (2,2),
2 B (2),
3 C,
3 D,
2 E;
A.B.C(1,1,2)
A(1,1,2).B.C
A(1,1).B(2).C refer to the same thing in the prior array of structures.
Unless all of the subscripts are moved to the lowest level, the reference is said
to have interleaved subscripts; thus, A.B(1,1,2).C has interleaved subscripts.