Global/External Variables

Updated and reviewed May 2011

By default, only variables defined within the function or procedure (i.e. Local Variables) are accessible within that routine. This is generally a good thing, as it helps prevent inadvertent references to the wrong variables, as well as unintended side-effects from calling a function or procedure. But the ability to access variables defined outside the routine can be enabled, by any of the following methods:

•   Private Map: You can share variables between a group of related functions or procedures by grouping them all within a single file and declaring the shared variables at the top of the file using PRIVATE MAP statements. See MAP Statement Extensions.

•   AUTO_EXTERN may be used to expose all global variables.

•   EXTERN_BEGIN, END: You can expose a list or block of global variables by repeating the original MAP statements for those variables within the function or procedure, enclosed by ++PRAGMA EXTERN_BEGIN and ++PRAGMA EXTERN_END, e.g.

++PRAGMA EXTERN_BEGIN

MAP1 SOME'VAR,F,6

MAP1 ANOTHER'VAR,S,20

++INCLUDE MOREVARS.MAP

++PRAGMA EXTERN_END

 

•   EXTERN may be used to expose individual global variables.