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

OPTIONAL attribute

OPTIONAL can be specified as part of the parameter-descriptor list or as an attribute in the parameter declaration.

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

OPTIONAL arguments can be omitted in calls and function references by specifying an asterisk for the argument. An omitted item can be anywhere in the argument list, including at the end. However, the omitted item is counted as an argument. With its inclusion in an entry, the number of arguments must not exceed the maximum number allowed for the entry.

Using OPTIONAL and BYVALUE for the same item is invalid, unless the item is a LIMITED ENTRY.

The receiving procedure can use the OMITTED built-in function to determine if an OPTIONAL parameter/argument was omitted in the invocation of the entry. (For more information on the OMITTED built-in function, see OMITTED.)

If the final parameters in an ENTRY declaration are declared as OPTIONAL, then the ENTRY may be invoked with those parameters completely omitted: it is not even necessary to specify the appropriate number of asterisks. So, for example, if an ENTRY is declared as having 5 parameters, of which the last 2 have the OPTIONAL attribute, then it may be invoked with 3, 4 or 5 arguments.

You may omit such trailing OPTIONAL parameters both when the ENTRY invoked is explicitly declared and when the ENTRY invoked is a nested subprocedure. Note also that unless the ENTRY has the OPTIONS(ASSEMBLER) attribute, the generated code will supply null pointers for the omitted parameters.

Figure 5 shows both valid and invalid CALL statements for the procedure Vrtn.

Figure 5. Valid and invalid call statements
  Caller: proc;
    dcl Vrtn entry (
             fixed bin,
             ptr optional,
             float,
             * optional);

/*  The following calls are valid:  */

    call Vrtn(10, *, 15.5, 'abcd');
    call Vrtn(10, *, 15.5, *);
    call Vrtn(10, addr(x), 15.5, *);
    call Vrtn(10, *, 15.5);
    call Vrtn(10, addr(x), 15.5);
 
/*  The following calls are invalid:  */
 
    call Vrtn(*, addr(x));
    call Vrtn(10,addr(x));
    call Vrtn(10);
    call Vrtn;
  end Caller;
 
  Vrtn: proc (Fb, P, Fl, C1);
    dcl Fb fixed bin,
        P ptr optional,
        Fl float,
        C1 char(8) optional;
 
    if ¬omitted(C1) then display (C1);
    if ¬omitted(P) then P=P+10;
end;

Vrtn determines if OPTIONAL parameters were omitted, and takes the appropriate action.


Terms of use | Feedback

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