IMPORT AND EXPORT


Any global variable (declared with the definition specification) can be exported for use by other modules with the same application program. The EXPORT keyword is used to export a global variable. This property makes the variable available to separately compiled source modules. Figure 6.5 illustrates how to code EXPORT and IMPORT keywords in separate source files.

click to expand
Figure 6.5: Independent source files.

Figure 6.5 illustrates two independent RPG source files. The first source file, STATUSONE (on the left of Figure 6.5), contains a variable named STATUSCODE. This variable has the EXPORT keyword specified. This field property means that the field is defined in STATUSCODE and resides within it, but is available for importing by any other module.

The other source file, STATUSCHK (shown on the right in Figure 6.5), is called by STATUSONE. The CALLP operation on line 5 performs the CALL operation to the STATUSCHECK file. Within the STATUSCHK module, the field STATUSCODE is also defined (line 2). In STATUSCHK, however, the STATUSCODE field contains the keyword IMPORT. This field property indicates that storage for the field is not allocated within the STATUSCHK module, but rather is located (i.e., resolved) when the related modules are bound together.

Only one copy of STATUSCODE exists, and its storage is allocated within STATUSONE. Any changes to this field in any module are immediately, and instantly, reflected in the other modules. They all reference the same storage location.

Figure 6.6 shows how modules within a single program share exported variables. The module in which the variable is defined is the module where the variable resides. Other modules that want to access the exported variable declare a variable with the same properties and specify the IMPORT keyword. When the modules are combined by the program binder, references to the exported variable (that is, all imported variables) are resolved. The imported variables are, essentially, pointers to the exported variable. Keep in mind the following points when using IMPORT and EXPORT:

click to expand
Figure 6.6: Modules sharing IMPORT/EXPORT data.

  • Only global variables can be imported or exported. Local variables (fields declared within a subprocedure) cannot be exported.

  • The module that contains the variable definition and storage is the one that contains the EXPORT keyword.

  • To access an exported variable from within a subprocedure in a separate module, declare a global variable in the second module, specify the IMPORT keyword, and refer to that global variable within the subprocedure.

  • Subprocedure names must be exported (using the EXPORT keyword) in order to access them from other modules.




The Modern RPG IV Language
The Modern RPG IV Language
ISBN: 1583470646
EAN: 2147483647
Year: 2003
Pages: 156
Authors: Robert Cozzi

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net