TechTalk: Pass data through imports and exports in RPG IV.

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

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 
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: