Specifications

Chapter 5. Data Types
71
5.5 Scope of Variables
You may scope work variables and register variables to be local or global with the PRIVATE
or GLOBAL statement, respectively.
(5) Global variables
A global variable can be accessed by any routine in source files to share information
between those routines. Before access to it, you need to declare it with the
GLOBAL
statement.
(6) Local variables
A local variable can only be accessed by any routine in a source file where it is defined.
Before access to it, you need to declare it with the
PRIVATE statement.
(7) Variables not declared to be global or local
If not declared to be global or local, a variable is closed in each file where it is defined.
A variable used inside the FUNCTION or SUB function without declaration is available
only within a function where it is defined.
You may also share variables between user programs when one program chains to another by
declaring variables to be common with the
COMMON statement.
5.5.1 Global Variables
A global variable can be shared between source files in a program. In each file where you want
to use a particular global variable, write
GLOBAL preceding a desired variable name or
DEFREG statement.
(Example)
GLOBAL aaa%
GLOBAL bbb$[10]
GLOBAL ccc$(5,3)[30]
GLOBAL DEFREG ddd
GLOBAL DEFREG eee%(5)
(Example 1) To share the variable aa% between Files 1 and 2, define aa% by using the GLO-
BAL
statement in each file as follows:
File 1
File 2
GLOBAL aa% GLOBAL aa%
Before access to a global variable, you should define it.