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

Examples

The following examples illustrate the invocation of functions that are internal to and external to the invoking block.

Example 1

In the following example, the assignment statement contains a reference to the Sprod function:

        Mainp: procedure;
               get list (A, B, C, Y);
 1             X = Y**3+Sprod(A,B,C);
 
 2      Sprod: procedure (U,V,W)
               returns (bin float(21));
               dcl (U,V,W) bin float(53);
               if U > V + W then
 3               return (0);
               else
 3               return (U*V*W);
         end Sprod;

 1 
When Sprod is invoked, the arguments A, B, and C are associated with the parameters U, V, and W in  2 , respectively.
 2 
Sprod is a function because RETURNS appears in the procedure statement. It is internal, and therefore needs no explicit entry declaration. If Sprod were external, Mainp would contain an entry declaration with RETURNS specified.
 3 
Sprod returns either zero or the value represented by U*V*W, along with control to the expression in Mainp. The returned value is taken as the value of the function reference, and evaluation of the expression continues.

Example 2

      Mainp:  procedure;
              dcl Tprod entry (bin float(53),
                              bin float(53),
                              bin float(53),
                              label) external
                returns (bin float(21));
              get list (A,B,C,Y);
 1             X = Y**3+Tprod(A,B,C,Lab1);
      Lab1:  call Errt;
      end Mainp;
 1      Tprod:  procedure (U,V,W,Z)
                returns (bin float(21));
                dcl (U,V,W) bin float(53);
                declare Z label;

 2              if U > V + W then
                    go to Z;
 3              else
                    return (U*V*W);
         end Tprod;
 1 
When Tprod is invoked, Lab1 is associated with parameter Z.
 2 
If U is greater than V + W, control returns to Mainp at the statement labeled Lab1. Evaluation of the assignment in  1  is discontinued.
 3 
If U is not greater than V + W, U*V*W is calculated and returned to Mainp in the normal fashion. Evaluation of the assignment in  1  continues.

Notice that Tprod is an external procedure. It has an explicit entry declaration in Mainp, which contains RETURNS.


Terms of use | Feedback

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