Previous Topic Next topic Print topic


GLOBALREF

GLOBALREF is a storage class and scope attribute that declares a global symbol, which is defined in an external procedure either with the GLOBALDEF attribute or, if the external procedure is written in another programming language, with its equivalent in that language. Its format is:

GLOBALREF [(name)]

where name is an identifier that is accepted as legal syntax for compatibility with other Open PL/I extensions, but is ignored, having no effect.

The GLOBALREF attribute implies the EXTERNAL and STATIC attributes. A variable may be declared with the GLOBALREF attribute in as many procedures as desired. Unlike GLOBALDEF, GLOBALREF does not cause actual storage to be allocated for the external variable, but allows access to the storage that was allocated by some other external procedure.

If GLOBALREF is present, any INITIAL attribute for the variable is ignored.

P1: PROCEDURE;         P2: PROCEDURE;
DECLARE                   DECLARE
   XVAR FIXED BIN(15)        XVAR FIXED BIN(15)
      GLOBALDEF;             GLOBALREF;
XVAR = 23;             IF XVAR > 0 THEN XVAR = 100;
CALL P2;               .
.                      .
.                      .
.

In this example, XVAR is declared with the GLOBALDEF attribute in procedure P1 and is assigned storage as a result. The value 23 is assigned to XVAR. Procedure P2 has declared XVAR with the GLOBALREF attribute and will access the same memory location allocated by P1 . Procedure P2 can test and/or change the value of XVAR.

Previous Topic Next topic Print topic