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

Packages

A package is a block that can contain only declarations, default statements, and procedure blocks. The package forms a name scope that is shared by all declarations and procedures contained in the package, unless the names are declared again. Some or all of the level-1 procedures can be exported and made known outside of the package as external procedures. A package can be used for implementing multiple entry point applications.

A package that contains a MAIN procedure must not also contain any FETCHABLE procedures. A package that contains a MAIN procedure may also not be linked into a DLL. It should form part of a base executable that may, if desired, invoke routines in a DLL. Such a package may, of course, also define external routines that may be called from other routines statically linked with it, and the package may also define EXTERNAL STATIC data that may be referenced from other routines statically linked with it.

If a package (not containing a MAIN routine) is linked into a DLL, then the only EXTERNAL STATIC variables that will be exported from that package out of the DLL will be those variables that have the RESERVED attribute.

Read syntax diagramSkip visual syntax diagram>>-condition-prefix--:--package-name--:--PACKAGE---------------->
 
>--+--------------------------------------+--------------------->
   |               .-,-------------.      |
   |               V               |      |
   '-EXPORTS--(--+---| procedure |-+-+--)-'
                 '-*-----------------'
 
>--+---------------------------------------+-------------------->
   |                .-,-------------.      |
   |                V               |      |
   '-RESERVES--(--+---variable name-+-+--)-'
                  '-*-----------------'
 
                            .-------------------------.
                            V                         |
>--+------------------+--;----+-declare-statement---+-+--------->
   '-OPTIONS(options)-'       +-default-statement---+
                              '-procedure-statement-'
 
>--END--+--------------+--;------------------------------------><
        '-package-name-'
 
procedure:
 
|--procedure-name--+----------------------------+---------------|
                   '-EXTERNAL(environment-name)-'
 
condition-prefix
Condition prefixes specified on a PACKAGE statement apply to all procedures contained in the package unless overridden on the PROCEDURE statement. For more information on condition prefixes, refer to Condition prefixes.
package-name
The name of the package.
EXPORTS
Specifies that all (EXPORTS(*)) or the named procedures are to be exported and thus made externally known outside of the package. If no EXPORTS option is specified, EXPORTS(*) is assumed.
procedure name
Is the name of a level-1 procedure within the package.
EXTERNAL (environment name)
Is a scope attribute discussed in Scope of declarations.
RESERVES
Specifies that this package reserves the storage for all (RESERVES(*)), or only for the named variables that have the RESERVED attribute, see RESERVED attribute.
variable name
Is the name of a level-1 external static variable.
OPTIONS option
For OPTIONS options applicable to a package statement, refer to OPTIONS option and attribute.
declare statement
All variables declared within a package but outside any contained level-1 procedure must have the storage class of static, based, or controlled. Automatic variables are not allowed. Default storage class is STATIC. Refer to Data declarations.
default statement
Refer to Defaults for attributes.
procedure statement
Refer to PROCEDURE and ENTRY statements.

An example of the package statement appears in Figure 3.

Figure 3. Package statement
*Process S A(F) LANGLVL(SAA2) LIMITS(EXTNAME(31)) NUMBER;
 Package_Demo: Package exports (Factorial);
 
 /***********************************************/
 /*                 Common Data                 */
 /***********************************************/
 
 dcl N fixed bin(15);
 dcl Message char(*) value('The factorial of ');
 
 /***********************************************/
 /*                 Main Program                */
 /***********************************************/
 
 Factorial: proc options (main);
    dcl Result fixed bin(31);
    put skip list('Please enter a number whose factorial ' ||
                  'must be computed ');
    get list(N);
    Result = Compute_factorial(n);
    put list(Message || trim(N) || ' is ' || trim(Result));
 end Factorial;
 
 /***********************************************/
 /*                  Subroutine                 */
 /***********************************************/
 
 Compute_factorial: proc (Input) recursive returns (fixed bin(31));
    dcl Input fixed bin(15);
    if Input <= 1 then
       return(1);
    else
       return( Input*Compute_factorial(Input-1) );
 end Compute_factorial;
 
 end Package_Demo;

Terms of use | Feedback

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