Set-value blocks

A set-value block is an area of code in which you can set both property and field values. For background, see Overview of EGL properties.

A set-value block is available when you take any of the following actions:

In the last two cases, you can assign values only to fields.

Note: A restriction applies to fields in fixed structures. You can use set-value blocks to assign the values of the primitive field-level properties, but not to set the values of the fields themselves.

Set-value blocks for elementary situations

Consider the rules that apply in the most elementary cases:
  • Each set-value block begins with a left curly brace ({), includes either a list of entries that are separated by commas or a single entry, and ends with a right curly brace (})
  • The entries are all in one of two formats:
    • Each entry is composed of an identifier-and-value pair such as inputRequired = yes; or
    • Each entry contains values that are assigned positionally, when successive values are assigned to successive elements of an array.

In all cases, the set-value block is in the scope of the part, variable, or field being modified. The variations in syntax are best illustrated by example.

The first example shows a dataItem part, which has two properties (inputRequired and align) :
  // the scope of the set-value block is myPart
  DataItem myPart INT 
    { 
    inputRequired = yes, 
    align = left 
    } 
  end
The next example shows a variable of primitive type.
   // the scope is myVariable
   myVariable INT
   {
      inputRequired = yes,
      align = left
   };
The next example shows an SQL record part declaration, which includes two record properties (tableNames and keyItems):
  // The scope is myRecordPart
  Record myRecordPart type SQLRecord
    { tableNames = [["myTable"]],
      keyItems = ["myKey"] }
    myKey CHAR(10);
    myOtherKey CHAR(10);
    myContent01 CHAR(60);
    myContent02 CHAR(60);
  end 
The next example shows a variable declaration that uses the previous part as a type, overrides one of the two record properties, and sets two fields in the record:
  // The scope is myRecord
  myRecord myRecordPart 
    {
      keyItems = ["myOtherKey"],
      myContent01 = "abc",
      myContent02 = "xyz"
    };
Additional examples include variable declarations and assignment statements:
  // the example shows the only case in which a 
  // record property can be overridden in a 
  // variable declaration.   
  // the scope is myRecord
  myRecord myRecordPart {keyItems = ["myOtherKey"]};

  // the scope is myInteger, which is an array
  myInteger INT[5] {1,2,3,4,5};

  // these assignment statements 
  // have no set-value blocks
  myRecord02.myContent01 = "abc";
  myRecord02.myContent02 = "xyz";

  // this abbreviated assignment statement
  // is equivalent to the previous two, and
  // the scope is myRecord02
  myRecord02
    {
      myContent01="abc",
      myContent02="xyz"
    };

  // This abbreviated assignment statement 
  // resets the first four elements of the array
  // declared earlier
  myInteger{6,7,8,9};

The abbreviated assignment statement is not available for fields in a fixed structure.

Set-value blocks for a field of a field

When you are assigning values for a field of a field, you use a syntax in which the set-value block is in a scope such that the entries are modifying only the field of interest.

Consider the following part definitions:
  record myBasicRecPart03 type basicRecord
    myInt04 INT;
  end

  record myBasicRecPart02 type basicRecord
    myInt03 INT;
    myRec03 myBasicRecPart03;
  end

  record myBasicRecPart type basicRecord  
    myInt01 INT;
    myInt02 INT;
    myRec02 myBasicRecPart02;
 end
You can assign a property value for any field as follows:
  • Create a set-value block for the record
  • Embed a series of field names to narrow the scope
  • Create the field-specific set-value block

The syntax for assigning a property value may take any of three forms, as shown in the following examples, which apply to the field myInt04:

  // dotted syntax, as described in 
  // References to variables in EGL.
  myRecB myBasicRecPart 
  { 
    myRec02.myRec03.myInt04{ align = left } 
  };

  // bracket syntax, as described in 
  // Bracket syntax for dynamic access.
  // You cannot use this syntax to affect
  // fields in fixed structures.
  myRecC myBasicRecPart 
  { 
    myRec02["myRec03"]["myInt04"]{ align = left } 
  };

  // curly-brace syntax 
  myRecA myBasicRecPart 
  { 
    myRec02 {myRec03 { myInt04 { align = left }}}
  };
Even in complex cases, you use a comma to separate one entry in a set-value block from the next; but you need to consider the level at which a given block is nested:
  // dotted syntax
  myRecB myBasicRecPart 
  { 
    myInt01 = 4,
    myInt02 = 5,
    myRec02.myRec03.myInt04{ align = left }, 
    myRec02.myInt03 = 6
  };

  // bracket syntax
  myRecC myBasicRecPart 
  { 
    myInt01 = 4,
    myInt02 = 5,
    myRec02["myRec03"]["myInt04"]{ align = left }, 
    myRec02["myInt03"] = 6
  };

  // curly-brace syntax; 
  // but this usage is much harder to maintain
  myRecA myBasicRecPart 
  { 
    myInt01 = 4,
    myInt02 = 5,
    myRec02 
      {
        myRec03 
          { myInt04 
            { action = label5 }},
        myInt03 = 6
      }
  };

Use of "this"

In a variable declaration or assignment statement, you can have a container (such as an SQL record) that includes a field (such as keyItems) which is named the same as a record property. To refer to your field rather than to the property, use the keyword this, which establishes the correct scope for the set-value block or for an entry in the set-value block.

Consider the following record declaration:
  Record myRecordPart type SQLRecord
    { tableNames = [["myTable"]],
      keyItems = ["myKey"] }
    myKey CHAR(10);
    myOtherKey CHAR(10);
    keyItems CHAR(60);
  end 
The following record declaration first sets a value for the property keyItems, then sets a value for the field of the same name:
  myRecord myRecordPart 
  { 
     keyItems = ["myOtherKey"],
     this.keyItems = "abc"
  };

The next section gives an additional example in an array declaration.

Set-value blocks, arrays, and array elements

When you declare a dynamic array, you can specify the initial number of elements, as in this example:
  col1 ConsoleField[5];
Assignments in a set-value block refer to properties and predefined fields in each of the initial elements of type ConsoleField, though not to any elements that are added later:
  col1 ConsoleField[5]
  { 
    position = [1,1],
    color = red
  };
To assign values to a particular element in a variable declaration, create an embedded set-value block whose scope is that element. As shown in the following example, you specify the scope by using the keyword this with a bracketed index:
  // assign values to the second and fourth element
  col1 ConsoleField[5]
  {
    this[2] { color = blue }, 
    this[4] { color = blue }
  };

For details on another use of the keyword this, see Scoping rules and "this" in EGL.

You can use positional entries in a set-value block to assigns value to successive elements in an array of any of these types (as is relevant only when processing reports or creating console forms):
  • ConsoleField
  • Menu
  • MenuItem
  • Prompt
  • Report
  • ReportData
The following example could be in an OpenUI statement. The scope of each embedded set-value block is a specific array element:
   new Menu
   {
     labelText = "Universe",
     MenuItems = 

     // property value is a dynamic array
     [ 
       new MenuItem 
       { name = "Expand", 
          labelText = "Expand" },
       new MenuItem 
       { name = "Collapse", 
          labelText = "Collapse" }
     ]
   }

Example with a complex property

To review a syntax that is an extension of what has gone before, consider the complex property @ProgramLinkData. That property includes the property fields programName and linkParms; and linkParms takes an array of property fields, each of complex property @LinkParameter.

You can define a DataItem part as follows:
  DataItem Prog1LinkItem char(9)
     {  @ProgramLinkData 
        { 
          programName = “my.company.sys1.PROG1”, 
          linkParms = 
          [ @LinkParameter {name=“parm1”, value=”abc”}, 
            @LinkParameter {name=”parm2”,value=”efg”} ] 
        }
     } 
  end
You can add another property after the set-value block that defines @ProgramLinkData, but first, you must add a comma to separate the two properties:
  DataItem Prog1LinkItem char(9)
     {  @ProgramLinkData 
        { 
          programName = “my.company.sys1.PROG1”, 
          linkParms = 
          [ @LinkParameter {name=“parm1”, value=”abc”}, 
            @LinkParameter {name=”parm2”,value=”efg”} ] 
        },
        displayName = “Go to Program02”
     } 
  end

Additional examples

Consider the following parts:
  Record Point
				x, y INT;
  end

  Record Rectangle
    topLeft, bottomRight Point;
  end
The following code is valid:
  Function test()
    screen Rectangle
    {
      topLeft{x=1, y=1},
      bottomRight{x=80, y=24}
    };
  
    // change x, y in code, using a statement 
    // that is equivalent to the following code:
    //   screen.topLeft.x = 1;
    //   screen.topLeft.y = 2;
    screen.topLeft{x=1, y=2};
  end
Next, initialize a dynamic array of elements of type Point in the same function:
  pts Point[2]
  {
    this[1]{x=1, y=2},
    this[2]{x=2, y=3}
  };
Set the value of each element that is now in the array, then set the first element to a different value:
  pts{ x=1, y=1 };
  pts[1]{x=10, y=20};

In the previous example, pts[1] is used rather than this[1] because the array name is unambiguous.

Next, consider another dynamic array of type Point:
  points Point[];
The following assignment statement has no effect because no elements exist:
  points{x=1, y=1};
In contrast, the following assignment statement causes an out-of-bounds exception because a particular element is referenced and does not exist:
  points[1]{x=10, y=20};
You can add elements to the array, then use a single statement to set values in all elements:
  points.resize(2);
  points{x=1, y=1};

Related reference
Arrays
Data initialization
openUI

Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.