USE Statement Overview

The USE statement gives a program unit accessibility to public entities in a module. For more information, see USE.

Examples

Entities in modules can be accessed either through their given name, or through aliases declared in the USE statement of the main program unit. For example:

USE MODULE_LIB, XTABS => CROSSTABS

This statement accesses the routine called CROSSTABS in MODULE_LIB by the name XTABS. This way, if two modules have routines called CROSSTABS, one program can use them both simultaneously by assigning a local name in its USE statement.

When a program or subprogram renames a module entity, the local name (XTABS, in the preceding example) is accessible throughout the scope of the program unit that names it.

The ONLY option also allows public variables to be renamed. Consider the following:

USE MODULE_A, ONLY: VARIABLE_A => VAR_A

In this case, the host program accesses only VAR_A from module A, and refers to it by the name VARIABLE_A.

Consider the following example:

MODULE FOO

integer foos_integer

PRIVATE

integer foos_my_integer

END MODULE FOO

PRIVATE, in this case, makes the PRIVATE attribute the default for the entire module FOO. To make foos_integer accessible to other program units, add the line:

PUBLIC :: foos_integer

Alternatively, to make only foos_my_integer inaccessible outside the module, rewrite the module as follows:

MODULE FOO

integer foos_integer

integer, private::foos_my_integer

END MODULE FOO