Add a local stack variable declaration

WTSupported in traditional Synergy on Windows
WNSupported in Synergy .NET on Windows
USupported on UNIX
VSupported on OpenVMS
[DISPOSABLE][BYREF] DATA variable, [dim, ...]type[<generic_type>][size][, init_value]


[DISPOSABLE] DATA variable = value



(optional) Indicates disposable data, which means that at runtime, the IDisposable.Dispose method will be run on exit from the scope in which the DATA statement is defined. (Synergy .NET only)


(optional) Indicates variable is a reference to another BYREF parameter, BYREF return method, or other BYREF local data or field, where the exact type is assigned with no conversions. (Synergy .NET only)


The name of the local stack variable. (a)


(optional) One or more array dimensions (real or dynamic), separated by commas (for example, [2] or [#,#]), or an actual pound sign (#) for automatically sized arrays. You must type the brackets around the dimension elements; they do not mean that the arguments are optional. The brackets must contain at least one element.


Any valid routine field data type. See the type argument in Field definition components for a complete list of valid data types.


(optional) A generic type parameter. See Generic types (.NET) for more information. (Synergy .NET only)


(optional) An expression indicating the number of characters in each occurrence of the field.


(optional) An initial value (a literal or an object instantiation) to be assigned to successive occurrences of the field, or an initial set of values for a set of properties or fields or a collection. Init_value can have one of the following syntaxes:

new class[<generic_type>] ([arguments]) 
new array_element_type[<generic_type>] [#[,#...] ] 
new type [<type_param_list>]([param_list]) [object_initializer_list] 
new array_element_type[<generic_type>] [#[,#...] ] {initial_values}       (.NET only)
new type [<type_param_list>]([param_list]) [collection_initializer_list]  (.NET only)

See NEW keyword for details about these syntaxes. (Note that initial_values is only supported on Synergy .NET.)


A variable, expression (including literals), method call, or object instantiation (see init_value above). The type of variable is the type of the result of the literal expression, method call, or object instantiation (NEW). If value is a literal, the type of variable is determined by changing the Synergy literal type to the same .NET literal type (for example, “abc” is type string, and 10 is int). If you want variable to have a Synergy literal type instead, cast value as the desired Synergy type (a or i).


The DATA statement defines a local stack variable in the procedure division. In the first syntax form, the data type of the initial value is explicitly stated, or “fixed.” In the second form, the data type of the initial value is implicitly stated, or “inferred,” from the specified initial value.

In traditional Synergy, any DATA statements must be enclosed in a BEGIN-END block, and they must precede any other statements in the block. Synergy .NET does not require that DATA statements be contained within BEGIN-END blocks, nor are they required to be at the beginning of blocks.

The scope of the local variable is limited to the block in which it is declared. It can have the same name as a local variable in another block. If the DATA statement is not contained in a BEGIN-END block (which is only possible in Synergy .NET), the scope is the method in which the DATA statement is defined.


A structfield from a non-CLS structure cannot be used in a DATA statement or referred to by reference. Descriptors also cannot be referred to by reference.

A call to a label in a higher scope is not allowed in a BEGIN-END block that contains a DATA statement using an object variable.

BYREF can't be used with ASYNC methods, YIELD iterators, or lambdas. For an example using BYREF, see Examples for METHOD-ENDMETHOD.

Disposable data

Disposable data should be used on any expensive object, including file channels, database connections, network connections, Select statement objects, etc. Specify the DISPOSABLE qualifier to mark data as disposable and to run IDisposable.Dispose automatically upon exiting the scope in which the local variable is defined. IDisposable.Dispose is a .NET Framework method that performs tasks associated with freeing, releasing, and resetting unmanaged resources.


In the example below, an i4 local variable named myfield is declared.

public method mymethod, void
    x   ,i4
    if (x .eq. 5)
        data myfield, i4

Below are examples of initial values where the data type is “fixed”:

data var1       ,a3,            "XYZ"
data var2       ,[2]d3,         123, 789
data var3       ,[2,2]d3.1,     11.1, 11.2, 11.3, 11.4
data date       ,d6,            32792
  month  ,d2 @date
  day    ,d2 @date+2
  year   ,d2 @date+4
data mystr      ,string,        "ABC"
data cvar       ,@class1,       new class1()
data cvar       ,@class1,       new class1("abc")
data myarr      ,[#]int,        new int[#] {1,2,3,4}
data myobj      ,@*,            (@d)10
data myobj      ,string,        ^NULL
namespace ns1
    class class1
      fld1      ,[#]string, new string[#] {"ab", "cd"} 

Below are examples of initial values where the data type is “inferred”:

data myint = 10
data myclass = new myclassarray[#] {1,2,3,4,5,6,7,8,9,10}
                                                ;Create a 10-element array
data mystr = new string[#] {"ab","de"}          ;Create a 2-element string array 

In the examples below, the data type is cast to Synergy literal types:

data myfloat = (float)10.2
data mystr = (string)"17"

In the example below, someclass implements the IDisposable.Dispose method.

disposable data mycollection, @someclass, new someclass()

Using the System.Collections.Generic.list<> class, an example of a simple collection intitializer follows. It results in a data field called l that is a list of 32-bit integers that contains five members with the values 1 through 5, respectively.

data l, @list<int>, new list<int>(){1, 2, 3, 4, 5}

The example below illustrates the combined use of object and collection initializers. Because of the collection initializers, this example would only work in Synergy .NET.

public class myClass2
    private lst,                        @list<int>
    public property myList,             @list<int>
        public method get
            mreturn lst
        public method set
            lst = value
    data hnd,           @myClass2,      new myClass2() {myList = 
  &                                     new list<int>() {1,2,3}}