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.
An example of the package statement appears in Figure 3.
*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;