Set-values blocks
A set-values block is an area of code in which you can set property, field, or variable values. For background on properties, see "Overview of EGL properties."
- Define a part
- Declare a variable
- Create a part with the new operator
- Code a special form of a call, transfer, or show statement (properties only)
- Code a special form of an assignment statement (values only)
- Code an openUI statement, as described in "openUI" (values only)
In the last two cases, you can assign values only to fields.
program hello
myString STRING = "Hello, Cleveland";
{handleHardIOErrors = YES} // this works
...
endprogram hello
myString STRING = "Hello, Cleveland"
{handleHardIOErrors = YES}; // this is part of myString declaration
...
endThe problem is that handleHardIOErrors is now in the scope of the string "Hello, Cleveland." A string has no fields to set, let alone a field named "handleHardIOErrors," so EGL cannot resolve the expression.
- It turns off the null flag on a nullable variable.
- It initializes a new part for a null reference variable.
myInt INT?{};myList Dictionary; // myList = null
myList.x = 23; // illegal referenceHowever, the
following code initializes a new dictionary variable before attempting
the assignment:myList2 Dictionary; // myList2 = null
myList2{ x = 23 }; // myList2 now has one key, x, whose value is 23package com.companyb.customer;
Record StructuredRecordA
10 fullCheckNum NUM(25);
15 bankNum NUM(9);
15 acctNum NUM(10);
15 checkNum NUM(6);
end
program calculate type BasicProgram
function main()
myRec1 StructuredRecordA
{fullCheckNum = 9531008501602141091001484};
writeStdOut(myRec1.bankNum); // 953100850
writeStdErr(myRec1.checkNum); // 1484
end
end myRec2 StructuredRecordA {checkNum = 1485};
writeStdOut(myRec2.fullCheckNum); // 1485If you make multiple assignments to the same field or property in a set-value block, the last assignment takes effect. That rule also applies to fields of complex properties, which are described in "Set-values blocks in complex properties" in this topic.
Set-values blocks for elementary situations
- Each set-value block begins with a left brace ({), includes zero or more entries separated by commas, and ends with a right brace (})
- Each entry is in one of two formats:
- A name/value pair such as inputRequired = yes.
- A series of positional values (successive values assigned to successive elements of an array).
In any case, the set-values block is in the scope of the part, variable, or field being modified. The variations in syntax are best illustrated by example.
// the scope is myVariable
myVariable INT
{
inputRequired = yes,
align = left
}; // scope is optionEntry
DataItem optionEntry INT
{
inputRequired = yes,
align = left
};
end // scope is menu1Option
menu1Option optionEntry
{
inputRequired = no
}; myRecord02.myContent01 = "abc";
myRecord02.myContent02 = "xyz"; myRecord02
{
myContent01="abc",
myContent02="xyz"
};The abbreviated assignment statement is not available for fields in a structured record, and you cannot use it to set properties.
Set-values blocks for a field in a record
When you are assigning values for a field within a record variable, narrow the scope to the specific field, as follows.
record myBasicRecord03 type basicRecord
myInt04 INT;
end
record myBasicRecord02 type basicRecord
myInt03 INT;
myRec03 myBasicRecord03;
end
record myBasicRecord type basicRecord
myInt01 INT;
myInt02 INT;
myRec02 myBasicRecord02;
end- Create a set-values block for the record
- Embed a series of field names to narrow the scope
- Create a field-specific set-values block
The syntax for assigning a property value can take any of the forms shown in the following examples, which apply to the field myInt04:
// dotted syntax
myRecB myBasicRecord
{
myRec02.myRec03.myInt04{ align = left }
};
// bracket syntax
// You cannot use this syntax to affect
// fields in fixed structures
myRecC myBasicRecord
{
myRec02["myRec03"]["myInt04"]{ align = left }
};
// brace syntax
myRecA myBasicRecord
{
myRec02 {myRec03 { myInt04 { align = left }}}
};
// dotted syntax
myRecB myBasicRecord
{
myInt01 = 4,
myInt02 = 5,
myRec02.myRec03.myInt04{ align = left },
myRec02.myInt03 = 6
};
// bracket syntax
myRecC myBasicRecord
{
myInt01 = 4,
myInt02 = 5,
myRec02["myRec03"]["myInt04"]{ align = left },
myRec02["myInt03"] = 6
};
// brace syntax;
// but this usage is much harder to maintain
myRecA myBasicRecord
{
myInt01 = 4,
myInt02 = 5,
myRec02
{
myRec03
{ myInt04
{ action = label5 }},
myInt03 = 6
}
};
Use of "this" in set-values blocks
In a variable declaration or assignment statement, you can have
a container (such as an SQL record) that includes a field (such as keyItems)
that has the same name as a record property. To refer to your field
rather than to the property, use the keyword this,
which establishes the scope as being the declaration in which the
set-value block resides.
Record ExampleRecord type SQLRecord
{ tableNames = [["myTable"]],
keyItems = [myKey] }
myKey CHAR(10);
myOtherKey CHAR(10);
keyItems CHAR(60);
end myRecord ExampleRecord
{
keyItems = [myOtherKey],
this.keyItems = "abc"
};
For an example in an array declaration, see "Additional set-values block examples."
Set-values blocks in complex properties
myService ExampleServicePart
{ @xml
{name="myService",
namespace="http://www.customerpackage.companyb.commy.useful.service"}
};Additional set-values block examples
Record Point
x INT;
y INT;
end
Record Rectangle
topLeft Point;
bottomRight Point;
end 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 pts Point[2]
{
this[1]{x=1, y=2},
this[2]{x=2, y=3}
}; pts{ x=1, y=1 };
pts[1]{x=10, y=20};The keyword this has a different meaning outside of a set-values block (see The "this" keyword). In any case, the use of pts[1] here is not ambiguous, so no such distinction is necessary.
points Point[];
points{x=1, y=1};
points[1]{x=10, y=20}; points{};
points.resize(2);
points{x=1, y=1};