GLOBAL-ENDGLOBAL
WSupported on Windows
|
USupported on Unix
|
VSupported on OpenVMS
|
NSupported in Synergy .NET
|
[INTERNAL] GLOBAL[ DATA][ SECTION] name[ ,INIT] . . . ENDGLOBAL
Arguments
INTERNAL
(optional) Access is limited to the current assembly. (Synergy .NET only)
DATA
(optional) A keyword that you can use to make your global declaration clearer. Its presence does not affect the function of the GLOBAL statement.
SECTION
(optional) A keyword that you can use to make your global declaration clearer. Its presence does not affect the function of the GLOBAL statement.
name
The name of the global data area being referenced.
(optional) A keyword that enables you to declare the initial value of the global data area. Each global data section must have exactly one INIT option in the set of references to that data section. The module that contains the initializer defines which executable program or ELB “owns” that global data section.
Discussion
The GLOBAL statement defines the beginning of a global data section, and the ENDGLOBAL statement defines the end of a global data section.
Because a global data section is not directly associated with any specific routine, you can define it in any routine and then reference it from any other routine in your program. After you link your program, the size of the global data section matches the largest reference to that area in any of your program routines.
To define global records, use the unqualified RECORD statement after the GLOBAL statement. A GLOBAL statement block must end with the ENDGLOBAL statement. Any RECORD statement that appears between the GLOBAL and ENDGLOBAL statements defines a global record and its component fields.
Unlike COMMON, the names of the records and fields in a GLOBAL statement block in one subroutine do not have to match the names of the records and fields in the same GLOBAL statement in another subroutine. A GLOBAL statement in one subroutine is an overlay of the GLOBAL statement in another subroutine by the same GLOBAL name. The data accessed by a field in a GLOBAL statement block is defined by the position of the field relative to the beginning of the GLOBAL statement and the locally specified size of the field.
Your global record declarations will look something like this:
global data section glb record rec1 f1 ,a10 f2 ,d5 record rec2 fa ,d3 fb ,d4.2 endglobal
Global data sections can be scratch areas: their contents may be undefined upon entry to a subroutine unless the INIT option is specified. When INIT is present, the RECORD statements within the GLOBAL-ENDGLOBAL block can declare initial values. If the global data section in more than one routine uses the INIT option, an error is generated when you link your program.
If you have several definitions of a global data section and you specify the INIT option on one of the smaller layouts, only the size of the locally defined data is initialized. The rest of the global data section remains undefined.
If the INIT option is not present, Synergy DBL ignores any initial values specified in the global RECORD definitions, except to determine the size of an automatically sized field designated with a size of *. The data in that global data section remains undefined.
Differing record definitions for a global data area are not supported in Synergy .NET. Every record in a global data declaration that does not include INIT must match a record in the declaration that does include INIT. (The INIT declaration may have additional records, but every record in the non-INIT declaration must also be in the INIT declaration.) A record must match in name, number of fields, field names, field types and sizes, etc. If you have a record whose non-INIT and INIT declarations do not match, create an overlay in the INIT declaration to match the non-INIT record.
Within any given routine, only one GLOBAL statement can reference a particular global data section. A global data section cannot have the same name as a common record or field that gets a global definition.
Object handles are not allowed in global data sections. Also, a global data section cannot be declared within a class. |
Examples
The example below defines a global data section named gbl.
subroutine aaa arg ,a global data section gbl, init record xyz fld1 ,a3, "abc" fld2 ,a4, "defg" fld3 ,a5, "hijkl" endglobal proc arg = fld1 ;arg = "abc" arg = fld2 ;arg = "defg" arg = fld3 ;arg = "hijkl" arg = gbl ;arg = "abcdefghijkl" xreturn endsubroutine ;Subroutine bbb shows that the order of the fields has changed; thus the ;data accessed by the fields named the same is different based on the ;offset from the beginning of the GLOBAL section. ; ;The xyz record still accesses the same data as defined in subroutine aaa ;even though the order of the fields locally has changed, since the name ;is at the same position relative to the beginning of the GLOBAL DATA ;SECTION name and the size is still the same. subroutine bbb arg ,a global data section gbl record xyz fld3 ,a5 fld1 ,a3 fld2 ,a4 endglobal proc arg = fld1 ;arg = "fgh" arg = fld2 ;arg = "ijkl" arg = fld3 ;arg = "abcde" arg = xyz ;arg = "abcdefghijkl" xreturn endsubroutine ;Subroutine ccc shows that even though the order of the fields is the ;same, the data accessed is different, since the fields are different ;sizes from what was specified when the fields were defined. ; ;The beginning of the data accessed is defined by the offset from the ;beginning of the GLOBAL section. The size of the data accessed is ;defined locally by the size of the local field. ; ;The xyz record still accesses the same data as it is defined in ;subroutine aaa even though the size of the fields locally has changed, ;since the name is at the same position relative to the beginning of the ;GLOBAL DATA SECTION name, and the size is still the same, as the sum of ;the fields is also the same. ; subroutine ccc arg ,a global data section gbl record xyz fld1 ,a6 fld2 ,a2 fld3 ,a4 endglobal proc arg = fld1 ;arg = "abcdef" arg = fld2 ;arg = "gh" arg = fld3 ;arg = "ijkl" arg = xyz ;arg = "abcdefghijkl" xreturn endsubroutine