To expand the visibility
of code elements, use the EGL import and use statements.
In EGL, the
import and
use statements
are commonly used in these situations:
- You import a
logic part (such as a Program
or Library) or a data part (such as a Record or data item) so that
you can refer to the part as though it were part of the current package.
- You import an entire package so that
you can refer to any of the parts that it contains as if they were
part of the current package.
- You use a
library that is in your current
package so that you can drop the library prefix from any function
names or variable names that you use from that library.
- To refer to a function or variable in a library from a different
package, you can combine the import and use statements.
For more information, see “import” and “use.”
Implicit import and use
You
can refer directly to any of the parts that EGL defines without having
to import them, and you can refer directly
to functions in system libraries or EGL-defined enumerations without
having to use them. These parts are therefore
described as implicitly imported and used.
For
example, you can call the
sysLib.writeStdOut() system
function without referring to the library because of this implicit
use:
writeStdOut("Progam complete.");
Example
Suppose that you want
to access customer information in your accounts receivable (AR) package
by using the data definitions and functions from your customer relations
management (CRM) package. To call the function
getCustomer() from
the
CustomerLib library in the
com.companyb.crmpackage package,
you can use the following code:
package com.companyb.arpackage;
import com.companyb.crmpackage.*; // home of CustomerLib library
program CustomerTest type BasicProgram
use CustomerLib; // add these functions to my scope
function main()
getCustomer();
end
end
Note the following aspects of the example:
- EGL
uses the import com.companyb.crmpackage.*; line
to include the entire CRMPackage in the scope of
the current logic part. Only the parts you reference will be added
to the code.
- If you comment out the use statement,
you cannot generate the program unless you add the library name to
the function name, as in CustomerLib.getCustomer().
- If, later in the CustomerTest program, you define
a local getCustomer() function, EGL invokes that
function in preference to the function of the same name in com.companyb.crmpackage.CustomerLib.
Similarly, if you have libraries named CustomerLib in
both the ARPackage and CRMPackage,
EGL uses the local (ARPackage)
version.