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 assignment target on the left side. If no object is specified, the specified field must be located in the current object.
<Target> := <Expression>
| Item | Description |
|---|---|
| <Target> | Field Specification to indicate where the result value for the expression must be stored. |
| <Expression> |
Expression |
Given the following variables:
st-res : string
st-real : realstring
st-real1 : realstring value 'abc '
st-real2 : realstring value 'efg '(A)
st-res := st-real1 + st-real2
if st-res <> 'abc efg'
gt-result &= 'ERROR: string := realstring + realstring'
endif
//st-res gets the truncated value of 'abc efg'(B)
st-real := st-real1 + st-real2
if st-real <> 'abc efg '
gt-result &= 'ERROR: realstring := realstring1 + realstring2'
endif
//st-real gets the full value of 'abc efg'(C)
st-real1 += st-real2
if st-real1 <> 'abc efg '
gt-result &= 'ERROR: realstring1 + realstring2'
endif
//This instruction is equal to:
//st-real := st-real1 + st-real2
//Refer to the Operations instructions
//to see which operations can be abbreviated
//st-real1 gets the full value of 'abc efg'Or given the following variables:
sw-fax : boolean
faxnum : alpha 12
faxnum := '012345'
sw-fax := faxnum <> ''
if sw-fax <> true
gt-result &= 'ERROR: boolean := alpha <> '' '
endif
//the boolean sw-fax will be set to true if faxnum is not empty
//and to false if faxnum is empty
To fill multiple fields at once, you can use one of the following options:
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, variables in the object specified on the left that match variable names in the object specified on the right are filled with the values from the object on the right.
<DestObject>.* := <SrcObject>.*
| Item | Description |
|---|---|
| <DestObject> | Object that contains the variables to copy to. |
| <SrcObject> | Object that contains the variables 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:
It is not possible to use the * option within a WITH loop.
Suppose a target object and a source object both contain matching field names. To assign those field values from source to target, the following code lines can be written:
rec_0.alpha1 := tq_cust.alpha1
rec_0.alpha2 := tq_cust.alpha2Instead, you can also write:
rec_0.* := tq_test.*Reading and writing complete layout files: It is possible to refer to complete layout objects in assignments. In the example below, the whole file layout 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".
rec_1 := rec_0 + ' ABC'Assigning the content of an array or array elements is slightly different from other assignments.
There are two options to specify array elements:
array1 := array1[j+1]
sa_array[3, 2] := sa_array[5, 1]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:
Suppose the following layout controls have been painted at the top of 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:
lay_1 := 'abcdefghijklmnopqrstuvwxyz'Display_0 now contains the value "defgh".
Name_0 now contains the value "lmnop". If, apart from the mentioned layout controls, there are
no further painted items, this means that the structure contains 5 elements with the following
positions:
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. info 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 |
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.