Assignments
In assignments, the resulting value of an expression on the right side of the ":=" is assigned to the field that is specified on the left side. If the <Target> or the <Expression> is specified as <Object>.<Field>, the specified field must be located in the specified object and must be of a type that is valid for the object specified on the left side. If no object is specified, the specified field must be located in the current object.
Syntax:
<Target> := <Expression>
Item | Description |
<Target> | Field Specification to indicate where the result value for the expression must be stored. |
<Expression> |
Expression that returns a valid value for
the <Target> on the left of the :=. |
Examples:
Given the following variables:
(A)
(B)
(C)
Or given the following variables:
Filling multiple fields through a single assignment
To fill multiple fields at once, you can use one of the following options:
Using the asterisk character
Multiple field values of an object can be assigned to equally named fields in another object with a single
assignment, by using the asterisk character (*). By using the syntax described below, all variables in the object
that is specified on the left and correspond with the variable names in the object that is specified on the right
will be filled with the value that is stored in the object that is specified on the right.
Syntax:
<DestObject>.* := <SrcObject>.*
Item | Description |
<DestObject> | Object that contains the variables to copy to. |
<ScrObject> | Object that contains the variable to copy from. |
The field names in both objects do not necessarily have to match. However, only the values of fields with matching names will be stored in the fields in the target objects specified on the left. If there are fields in the target object (left side) that do not exist in the source object (right side), these target fields keep their old values.
The target object and source object do not have to be of the same type. So, it is for example possible to fill the table query fields (in the target object) with field values from a screen buffer (in the source object).
The following object types can be used in combination with the * option, both for the target as for the source:
- a table query; e.g. QPARAM
- a layout; e.g. LAY_10
- a file layout field; e.g. REC_20
- a screen buffer; e.g. LOGON (form name of current form)
- a structure; e.g. SG_1 or substructure; e.g. SG_1.SG_S
- a global or local item that is defined directly within the "upper" structure. So, global and local definitions that are not part of a structure or that are defined inside a substructure are skipped.
Example:
Suppose that there is a table query object "iPARAM" and a screen buffer object "LOGON", that both contain three fields with the same name, "FIELD1", "FIELD2" and "FIELD3". To assign the field values for "FIELD1", "FIELD2" and "FIELD3" from the object "LOGON" to the equally named fields in the object "iPARAM", the following code lines can be written:
Instead, you can also write:
Reading and writing complete layout files It is possible to refer to complete layout objects in assignments. In the example below, the whole file lay
out object "REC_1" is read, and the item "ABC" is added to this object. Next, the total contents of the updated
object "REC_1" are copied to the layout object "REC_0".
Example:
Assigning array element values
Assigning the content of an array or array elements is slightly different from other assignments.
There are two options to specify array elements:
- Filling one, or a selection of array element(s)
In this case, the index number(s) to locate the array element(s) must be specified between brackets ([<Element index no>]). You specify the index number(s) in the expression (on the right side of the assignment) to locate one or more values that is/are stored in the source array (on the left side). You can also write an expression according to the syntax described above, to return a valid value to one or more target elements. On the left side of the assignment, you specify the position(s) where the resulting value(s) must be placed. The number before the first comma (,) in the position specification you specify the element number for the first dimension. Every following comma indicates that the next number specification is also for the next dimension. - Filling all array elements
In this case, you specify only the brackets ( [ ] ), on both sides of the assignment.
Examples:
sa_array[3, 2] := sa_array[5, 1]
Filling or reading the print layout as a structure
Under certain conditions the first line in a print layout, including all controls painted on that line, can be filled or read through a single assignment. This can be achieved by writing an assignment in the implementation section of your form or report in which you refer to the name of the print layout. In fact, this way the concerned print layout will be treated as a structure . For reports, the length for the structure is set to the value that is specified for the property Maximum Layout Width in the options screen. All painted controls belong to the structure and will be filled with that part of the specified print layout value that corresponds with their position on the line and their value length. The specified print layout value always overwrites the current value of the layout controls, even if the new value does not correspond to the type that was originally defined for the layout control.
To use the report layout as a structure, the following conditions apply:
- Multiple languages may not be specified; which means that only the default language may be listed in the languages screen for the application.
- The layout controls:
- must all be placed on the first line; which means that only the upper part of the report layout can be painted.
- may not use multiple occurrence;
- may not use outputmacros; which means that the outputmacros property may not be set.
- may not contain a dot (.) in their designation. So, file buffer items and table items cannot be used.
Example:
Suppose that the following layout controls have been painted in top of the layout "LAY_1":
Display_0 :(left = 4, type = alpha, length = 5)
Name_0 : (left = 12, type = numeric, length = 5)
Through the code, the following assignment is performed:
Display_0 will now contain the value "defgh".
Name_0 will now contain the value "lmnop". If, apart from the mentioned layout controls, there are no further items painted,
this means that the structure contains 5 elements, which use the following structure positions:
- position 1 - 3 (until the first painted layout control)
- position 4 - 9 (Display_0)
- position 10 - 11 (element space between both layout controls)
- position 12 - 16 (Name_0)
- position 17 - 132 (the remaining space, supposed that the maximum layout width is set to 132)
Implicit Type Conversion
When converting variables to a different type by simply assigning the value of the variable to a variable of a
different
type only a few combinations of source and destination types are supported. The supported conversions are shown in
the
list below. Conversion between other types may result in unpredictable results.
Note: For predictable results when converting Numerics to Alphas or Strings use the FORMAT command.
Source | Destination | Result alignment |
Alpha | Numeric | See section below |
Alpha | String | Left |
Numeric | String | Left |
Numeric | Signed | Right |
Numeric | Integer | Right |
Signed | String | Left |
Signed | Integer | Right |
Integer | String | Left |
Integer | Signed | Right |
Structure | String | Left |
Structure | Numeric | See section below |
Assigning Alpha Values or Structures to Numeric Fields
General rules
- When the first character is the minus sign '-', then a signed numeric will become negative.
- Overpunch left or right are both interpreted. A signed numeric will become negative when the overpunch represents a negative value.
- A space will become 0 for each character (e.g. '3 4' will become 304).
- Both the decimal and thousand seperator (i.e. '.' and ',') are invalid characters.
- When the alpha value contains invalid characters, the numeric value will become zero.
Rules regarding Alpha to numeric/signed without decimals
- The assignment is RIGHT aligned.
- When the Alpha Field is longer than the Numeric Field, the right side of the Alpha Field is placed in the
Numeric Field.
(i.e. when an alpha 10 is filled with '12345' and then assigned to a numeric 5 the resulting numeric value in the numeric will be zero)
Rules regarding Alpha to numeric/signed with decimals
- When the Alpha Field is shorter than the Numeric Field, the Alpha value is RIGHT aligned before the decimal
sign.
(i.e. when an alpha 2 is filled with '15' and then is assigned to a numeric 5.2 the resulting value in the numeric will be 015.00) - When the Alpha Field is longer than the Numeric Field, the left side of the Alpha Field is placed in the Numeric
Field.
(i.e. when an alpha 10 is filled with '12345678' and then is assigned to a numeric 5.2 the resulting value in the numeric will be 123.45)
Rules regarding Structure to numeric/signed with or without decimals
- The assignment of the contents of a complete structure to a numeric/signed (with or without decimals) is LEFT aligned
- On assignment the contents of the structure will be copied into the memory of the numeric/signed unchanged (including possible invalid characters)
- When then the numeric/signed item is used, the value of the numeric/signed will be evaluated according to the general rules (e.g. invalid characters in the memory will lead to the value read being zero, etc.).
Rules regarding Structure to numeric/signed with format with or without decimals
- The assignment of the contents of a complete structure to a numeric/signed with format is LEFT aligned
- On assignment the contents of the structure will be copied into the memory of the numeric/signed unchanged (including possible invalid characters)
- When then the numeric/signed item is used, the value of the item will be de-formatted according of the rules of the format. When the memory contains invalid characters the value will become unpredictable.
Assigning Literals to Alpha Fields
To send literals with ASCII characters to an alpha field, you can either use the character set "#$" or two surrounding @-characters. When a literal is assigned to an alpha field and this literal contains a hexadecimal key (always exactly two digits are expected) that is directly preceded by the character set "#$" or that is surrounded by two @-characters, the ASCII character that is concerned will be written to the specified field. The initiating characters ("#$" or the two @-characters) will be omitted when the literal is moved to the specified field.