Use
the EGL import and use statements
to expand the visibility of code elements.
EGL
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 DataItem) 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.
- You use a
form group in your
current package to gain unqualified access to the forms in that group.
- You can use a data table so the program
can
directly access its fields.
- You can combine the import and use statements
to refer to a function or variable in a library from a different package.
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
You might want to access
customer
information in your accounts receivable (AR) package using the data
definitions
and functions from your customer relations management (CRM) package.
To call
the function
getCustomer() from the library
CustomerLib in
the package
com.companyb.crmpackage, 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
The following aspects of the example are significant:
- The line import com.companyb.crmpackage.*; tells
EGL
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.