Wednesday, July 16, 2008

Global Variables with IMPORT and EXPORT:

There are many ways to share the information between two programs such as passing parameters, data area, data queues etc., but there is another way to effectively and efficiently share the information -- use EXPORT and IMPORT keywords. In this example, we are going to share the variable "Wk_Global".
PGM1
-------

DAddNum PR 3 0
D Num1 2 0
D Num2 2 0
*
D Wk_Global S 3S 0 EXPORT
*
C Z-Add 10 A 2 0
C Z-Add 11 B 2 0
C Z-Add 0 C 3 0
C Eval C = AddNum(A:B)
C Z-Add C Wk_Global
C CallB 'PGM2'
*
C Seton Lr
*
*
PAddNum B
D PI 3 0
D NumX 2 0
D NumY 2 0
*
C Z-Add 0 Answer 3 0
C Eval Answer = NumX + NumY
C Return Answer
P E


PGM2
-------

D Wk_Global S 3S 0 IMPORT
C Wk_Global Dsply
C Return


This Wk_Global value will be passed to the next program.

No comments: