AMT Help Files

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 :=.

 If the expression contains Realstring values with trailing spaces, these spaces will be
 kept in the result operand. However, if the <Target> would be a String, these spaces
 are not stored in this target field.

Examples:

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 of faxnum is not empty
//and to false if faxnum is empty

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:

It is not possible to use the * option within a WITH loop.

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: 

rec_0.alpha1 := tq_cust.alpha1
rec_0.alpha2 := tq_cust.alpha2

Instead, 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 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:

rec_1 := rec_0 + ' ABC'


 

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:

Examples:

array1 := array1[j+1]

sa_array[32] := sa_array[51]


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:

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:

lay_1 := 'abcdefghijklmnopqrstuvwxyz'

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:

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

  1. When the first character is the minus sign '-', then a signed numeric will become negative.
  2. Overpunch left or right are both interpreted. A signed numeric will become negative when the overpunch represents a negative value.
  3. A space will become 0 for each character (e.g. '3 4' will become 304).
  4. Both the decimal and thousand seperator (i.e. '.' and ',') are invalid characters.
  5. When the alpha value contains invalid characters, the numeric value will become zero.

Rules regarding Alpha to numeric/signed without decimals

  1. The assignment is RIGHT aligned.
  2. 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

  1. 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)
  2. 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

  1. The assignment of the contents of a complete structure to a numeric/signed (with or without decimals) is LEFT aligned
  2. On assignment the contents of the structure will be copied into the memory of the numeric/signed unchanged (including possible invalid characters)
  3. 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

  1. The assignment of the contents of a complete structure to a numeric/signed with format is LEFT aligned
  2. On assignment the contents of the structure will be copied into the memory of the numeric/signed unchanged (including possible invalid characters)
  3. 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.