Rational Developer for System z
Enterprise PL/I for z/OS, Version 3.8, Language Reference Manual

Parameter attribute

A parameter is contextually declared with the parameter attribute by its specification in a PROCEDURE or ENTRY statement. The parameter should be explicitly declared with appropriate attributes. The PARAMETER attribute can also be specified in the declaration. If attributes are not supplied in a DECLARE statement, default attributes are applied. The parameter name must not be subscripted or qualified.

Read syntax diagramSkip visual syntax diagram>>-PARAMETER---------------------------------------------------><
 

Table 8, and the following discussion, describe the attributes that can be declared for a parameter.

A parameter always has the INTERNAL attribute.

If the parameter is a structure or union, it must specify the level-1 name.

A parameter cannot have any storage class attributes except CONTROLLED. A controlled parameter must have a controlled argument, and can also have the INITIAL attribute.

Parameters used in record-oriented input/output, or as the base variable for DEFINED items, must be in connected storage. The CONNECTED attribute must be specified both in the declaration in the procedure and in the descriptor list of the procedure entry declaration.

Simple Parameter Bounds, Lengths, and Sizes

Bounds, lengths, and sizes of simple parameters must be specified either by asterisks or by restricted expressions. When the actual length, bounds, or size can be different for different invocations, each can be specified in a DECLARE statement by an asterisk. When an asterisk is used, the length, bounds, or size are taken from the current generation of the associated argument.

An asterisk is not allowed as the length specification of a string that is an element of an aggregate, if the associated argument creates a dummy. The string length must be specified as an integer.

Controlled Parameter Bounds, Lengths, and Sizes

The bounds, length, or size of a controlled parameter can be specified in a DECLARE statement either by asterisks or by element expressions.

Asterisk Notation

When asterisks are used, length, bounds, or size of the controlled parameter are taken from the current generation of the associated argument. Any subsequent allocation of the controlled parameter uses these same bounds, length, or size, unless they are overridden by a different length, bounds, or size specification in the ALLOCATE statement. If no current generation of the argument exists, the asterisks determine only the dimensionality of the parameter, and an ALLOCATE statement in the invoked procedure must specify bounds, length, or size for the controlled parameter before other references to the parameter can be made.

Expression Notation

Each time the parameter is allocated, the expressions are evaluated to give current bounds, lengths, or sizes for the new allocation. However, such expressions in a DECLARE statement can be overridden by a bounds, length, or size specification in the ALLOCATE statement itself.

Example of array argument with parameters

In Figure 4, when Sub1 is invoked, A and B, which have been allocated, are passed.

Figure 4. Array argument with parameters
%process or('|') num  margins(1,72);
Package:package exports(*);

 
Main: procedure options(main);
declare (A(NA), B(NB), C(NC), D(ND) ) controlled;
declare (NA init(20), NB init(30), NC init(100),
ND init(100) ) fixed bin(31);
declare Sub1 entry((*) controlled, (*) controlled);
declare Sub2 entry ((*) ctl, (*) ctl, fixed bin);

 
allocate A,B;  /* A(20), B(30) */
display ('Gen1: DIM(A)=' || dim(A) || ', ' || "DIM(B)=" || dim(B));
call Sub1(A,B);

 
display ('Gen2: Allocn(A)=' || allocn(a) || ', ' ||
'Allocn(B)=' || allocn(B) );
display ('Gen2: DIM(A)=' || dim(A) || ', ' || "DIM(B)=" || dim(B));
free A,B;
display ('Gen1: Allocn(A)=' || allocn(A) || ', ' ||
'Allocn(B)=' || allocn(B) );
display ('Gen1: DIM(A)=' || dim(A) || ', ' || "DIM(B)=" || dim(B));
free A,B;
display ('Gen0: Allocn(A)=' || allocn(A) || ', ' ||
'Allocn(B)=' || allocn(B) );
call Sub2 (C,D,10);

 
display ('Gen1: Allocn(C)=' || allocn(C) || ', ' ||
'Allocn(D)=' || allocn(D) );
display ('Gen1: DIM(C)=' || dim(C) || ', ' || "DIM(D)=" || dim(D));
free C,D;
display ('Gen0: Allocn(C)=' || allocn(c) || ', ' ||
'Allocn(D)=' || allocn(D) );
end Main;

 
Sub1: procedure (U,V);
dcl (U(UB), V(*)) controlled,
UB fixed bin(31);
display ('Gen1: Allocn(U)=' || allocn(U) || ', ' ||
'Allocn(V)=' || allocn(V) );
display ('Gen1: DIM(U)=' || dim(U) || ', ' || "DIM(V)=" || dim(V));
UB=200;
allocate U,V; /* U(200), V(30) */
display ('Gen2: Allocn(U)=' || allocn(U) || ', ' ||
'Allocn(V)=' || allocn(V) );
display ('Gen2: DIM(U)=' || dim(U) || ', ' || "DIM(V)=" || dim(V));
end Sub1;

 
Sub2: procedure (X,Y,N);
dcl (X(N),Y(N)) controlled,
N fixed bin;
display ('Gen0: Allocn(X)=' || allocn(X) || ', ' ||
'Allocn(Y)=' || allocn(Y) );
allocate X,Y;  /* X(10), Y(10) */
display ('Gen1: Allocn(X)=' || allocn(X) || ', ' ||
'Allocn(Y)=' || allocn(Y) );
display ('Gen1: DIM(X)=' || dim(X) || ', ' || "DIM(Y)=" || dim(Y));
end Sub2;

 
end Package;

The ALLOCATE statement in Sub1 allocates a second generation of A and B. B has the same bounds for both generations while A has different bounds for the second generation.

On returning to Main, the first FREE statement frees the second generation of A and B (allocated in Sub1). The second FREE statement frees the first generation of A and B (allocated in Main).

In Sub2, X and Y are declared with bounds that depend on the value of N. When X and Y are allocated, their values determine the bounds of the allocated arrays.

On returning to Main from Sub2, the FREE statement frees the only generation of C and D (allocated in Sub2).


Terms of use | Feedback

This information center is powered by Eclipse technology. (http://www.eclipse.org)