Imports and exports can be used to pass fields or data structures between one RPG IV module and another. The use of imports and exports is similar in concept to passing parameters. One module defines the storage for a data item and exports it to another module. The second module then imports the data item and can access the same storage variable.
The EXPORT keyword on the D-spec allows a data item defined within a module to be used by another module in the program. Storage for the data item is allocated in the module containing the EXPORT definition. The IMPORT keyword specifies that storage for the data item being defined is allocated in another module but may be accessed in the module containing the IMPORTkeyword.
Let's look at an example to see how the IMPORT and EXPORT keywords can be used. 4 shows an example of a module called MOD1 that uses the EXPORT keyword to export a field called Counter. This module performs a loop that repeats until the Counter field reaches 100. Within this loop, the CALLB operation is used to call a second module called MOD2, shown in 5. In MOD2, the IMPORT keyword is used to import the Counter field. This module increments the Counter field by a value of 1 and passes control back to the first module. After the CALLB to MOD2 in the first module, the value Counter is one greater than before the CALLB instruction. When Counter reaches 100, the program ends. This example shows you how the IMPORT and EXPORT keywords can be used to share data between RPG IV modules instead of having to pass parameters.
Let's look at an example to see how the IMPORT and EXPORT keywords can be used. Figure 4 shows an example of a module called MOD1 that uses the EXPORT keyword to export a field called Counter. This module performs a loop that repeats until the Counter field reaches 100. Within this loop, the CALLB operation is used to call a second module called MOD2, shown in Figure 5. In MOD2, the IMPORT keyword is used to import the Counter field. This module increments the Counter field by a value of 1 and passes control back to the first module. After the CALLB to MOD2 in the first module, the value Counter is one greater than before the CALLB instruction. When Counter reaches 100, the program ends. This example shows you how the IMPORT and EXPORT keywords can be used to share data between RPG IV modules instead of having to pass parameters.
- Robin Klima
TechTalk: Pass data through imports and exports in RPG IV.
Figure 4: RPG IV Module MOD1
*. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 D Counter S 7P 0 Export * C Dou Counter = 100 C Callb 'MOD2' C Enddo * C Eval *InLR = *On
TechTalk: Pass data through imports and exports in RPG IV.
Figure 5: RPG IV Module MOD2
*. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 D Counter S 7P 0 Import * C Eval Counter = Counter + 1 * C Eval *InLR = *On
LATEST COMMENTS
MC Press Online