Skip to main content

GLOBAL - Service

attribute := expression : GLOBAL [ ( cluster [, FEW ] ) ];

attributeThe name of the Attribute.
expressionThe definition of the attribute.
clusterOptional. A string constant specifying the name of the supercomputer cluster on which to build the attribute. This makes it possible to use the attribute on a smaller cluster when it must be built on a larger cluster, allowing for more efficient resource utilization. If omitted, the attribute is built on the currently executing cluster.
FEWOptional. When the expression is a dataset or recordset, FEW specifies that the resulting dataset is stored completely within the workunit. If not specified, then the dataset is stored as a THOR file and the workunit contains only the name of the file.

The GLOBAL service causes the attribute to be evaluated at global scope instead of the enclosing scope, similar to the GLOBAL() function -- that is, not inside a filter/transform etc. It may be evaluated multiple times in the same workunit if it is used from multiple workflow items, but it will share code with the context it is used.

GLOBAL is different from INDEPENDENT operates in that INDEPENDENT is only ever executed once, while GLOBAL is executed once in each workflow item that uses it.


I := RANDOM() : INDEPENDENT;  //calculated once, period
G := RANDOM() : GLOBAL;       //calculated once in each graph

ds := 
  DATASET([{1,0,0,0},{2,0,0,0}],{UNSIGNED1 rec,UNSIGNED Ival, UNSIGNED Gval , UNSIGNED Aval });

  SELF.Ival := I;
  SELF.Gval := G;
  SELF.Aval := RANDOM();     //calculated each time used
  SELF := L;

P1 := PROJECT(ds,XF(left)) : PERSIST('~RTTEST::PERSIST::IndependentVsGlobal1');
P2 := PROJECT(ds,XF(left)) : PERSIST('~RTTEST::PERSIST::IndependentVsGlobal2');

OUTPUT(P2);  //this gets the same Ival values as P1, but the Gval value is different than P1

See Also: GLOBAL function, INDEPENDENT