GLOBAL

<< Click to Display Table of Contents >>

Navigation:  Gekko User Manual > Gekko statements >

GLOBAL

Previous pageReturn to chapter overviewNext page

The GLOBAL statement is used to designate variable names that are to be located in the Global databank. Following a global x; statement, any subsequent use of x (without databank designation) will be understood as global:x.

 

After Gekko leaves the program file, function or procedure, these global variables live on in the Global databank. Therefore, using GLOBAL or global:= ... can be practical regarding permanent storage of variables, for instance settings, without polluting the 'normal' databanks.

 

Use global <all>; to render all variables global. After a global <all>, you can still search for a variable x without databank indication outside of the Global databank by means of the special all: designation (for instance = all:x;).

 

See the description of the OPEN statement regarding different types of databanks in Gekko.

 

See also the similar LOCAL statement, for local variables.

 


 

Syntax

 

global varnames;

global <all>;

 

 

varnames

Comma-separated list of variables

ALL

(Optional). With this option, all following (in the rest of the program/function/procedure) left-hand side variables without explicit databank designation are located in the Global databank. For a variable x that you would like to keep in another databank despite using a global <all>, you may use first:x or another bank designation to circumvent global <all>.

 

 


 

Examples

 

global x, %y, #z;

 

After this, any use of x, %y, or #z  (in the present program file, function or procedure) will be interpreted as global:x, global:%y, and global:#z. The Global databank is searched last, if databank searching is active (that is, data- or mixed mode), cf. databank search.

 

Variables in the Global databank survive for instance READ and CLEAR statements, and the Global databank is practical for storing long-term variables like setting etc. For instance:

 

global:%per1 = 2010;
global:%per2 = 2050;
global:%path = 'm:\data\scenario2';
global:%unit = 1000;

 

As long as Global is not cleared explicitly (or a RESET or RESTART is issued), %per1, %per2, %path, and %unit would be available. If you want to be absolutely sure that the variable is taken from Global, you can use global:%per1 to refer to the variable.

 

To avoid all the global: indicators, you may consider this alternative, using a procedure for the global settings:

 

reset;
procedure globals;
  global<all>;
  %per1 = 2010;
  %per2 = 2050;
  %path = 'm:\data\scenario2';
  %unit = 1000;
end;
globals; //call the procedure
//
// the rest of the program here
//

 

 


 

Note

 

You are not forced to use the GLOBAL keyword, when operating with global variables. Defining global:%per1 = 2010; first, and referring to global:%per1 later on is fine, too. In that sense, the GLOBAL keyword is just for convenience, especially if %per1 is used several times.

 

Variables in the Global databank are practical for settings, etc. These variables survive READ, CLEAR, etc., and do not 'pollute' the first-position databank if this is later on written to file.

 

Note that the Local or Global databanks are always searchable (the Local databank is searched first, the Global databank last), independent on MODE etc.

 


 

Related statements

 

LOCAL