Assigns the value of an expression to a database field or variable.

Data movement



Syntax

field = expression [ NO-ERROR ]
field
The name of an ABL data element to which you want to assign the value of expression and that is defined with a data type that is compatible with the data type of expression. This data element can include a:
  • Database or temp-table field
  • Variable scoped to the current procedure, user-defined function, or method of a class or an accessible class-based variable data member, including a subscripted or unsubscripted array variable
  • Parameter defined for the current procedure, user-defined function, or method of a class, including a subscripted or unsubscripted array parameter
  • Writable class-based or COM property, including a subscripted or unsubscripted array property
  • Writable handle attribute (such as PRIVATE-DATA)
  • Writable system handle (such as CURRENT-WINDOW)
  • ABL syntax that specifies a keyword-driven assignment statement (such as the PROPATH statement, SUBSTRING statement, or similar statement)
expression
An expression with a data type that is consistent with the data type of field. For more information, see the Expression reference entry.
NO-ERROR
The NO-ERROR option is used to prevent the statement from raising ERROR and displaying error messages.

For the assignment (=) statement with NO-ERROR, if ERROR is raised, then the left side of the assignment will be unchanged.

Note: You can use compound assignment operators (+=, -=, *=, /=) to perform an operation and an assignment, using a shorthand notation. Supported operations include addition (numeric and date-based) and concatenation, subtraction (numeric and date-based), multiplication, and division. For more information, see += Addition assignment operator, -= Subtraction assignment operator, *= Multiplication assignment operator, and /= Division assignment operator.

Example

This procedure resets all the monthly quota values to 2500 in all salesrep records. If you want to set values for individual array elements, you can do so by making an explicit assignment using the assignment statement (=) and a specific array reference, such as month-quota[1] or month-quota[i].

r-asgmnt.p

DEFINE VARIABLE ctr AS INTEGER NO-UNDO.

FOR EACH SalesRep:
  DO ctr = 1 TO 12:
    SalesRep.MonthQuota[ctr] = 2500.
  END.
END.

Notes

  • If field expression is a decimal, the AVM rounds the value of the expression before assigning it. If field is a decimal and expression is a decimal, the AVM rounds the value of the expression to the number of decimal places defined for the field in the Data Dictionary, or defined or implied for a variable or temp-table field.
  • If field is an ABL array type and expression is not an array, and you do not identify a particular array element, the AVM stores is an integer and expression in each element of the array. If you identify a particular element, the AVM stores expression in the specified array element.
  • If both field and expression are ABL array types, the AVM copies the data for all expression array elements into the corresponding elements of the field array. This is known as a deep copy. For more information, see Work with one-dimensional arrays in Basic ABL.
  • ABL allows you to assign ABL arrays and .NET array objects to each other. How an array assignment works between ABL and .NET arrays depends upon the array type of field (the target of the assignment) and the array type of expression (the source for the assignment). For more information, see the Data types reference entry.
  • If an assignment of one array to another encounters an error after some, but not all of the source array's elements are retrieved, none of the target's elements are updated.
  • If expression is an ABL handle-based object (for example, a temp-table, ProDataSet, widget, or socket), field must be a temp-table field, variable, or other ABL data element defined as a compatible handle. In this case, the AVM assigns only the handle of the ABL handle-based object to field, not the entire object and its contents.
  • If you assign a value to a database field, any ASSIGN trigger associated with that field executes at the end of the assignment statement (after any index changes are made). If the trigger raises ERROR, the assignment fails and the database changes are undone.
    Note: If the value to be assigned is the same as the value already in the database field, then any associated database ASSIGN triggers are not executed.
  • You can embed an assignment in a SET or UPDATE statement.
  • For multiple assignments, use the ASSIGN statement. This is more efficient than multiple assignment statements.
  • If field is a handle, the expression on the right-hand-side must also evaluate to a handle value that is specified using an appropriate reference to a handle-based object handle. For more information on object handle references, see the Handle Attributes and Methods Reference.
  • You can assign DATE, DATETIME, and DATETIME-TZ data. When the data type expression on the left side of the assignment statement contains more information than the data type expression on the right side provides (for example, datetime-tz = date where a DATETIME-TZ value contains more information than a DATE value), the time value defaults to midnight and the time zone is calculated using SESSION:TIMEZONE when that attribute is in use. If the attribute is not in use, the value defaults to the session's timezone. When the data type expression on the left side of the assignment statement contains less information than the data type expression on the right side provides (for example, date = datetime-tz where a DATE value contains less information than a DATETIME-TZ value), the AVM converts the DATETIME-TZ value to the local date and time of the session, then drops the time and time zone.
  • You can assign RAW values to MEMPTR variables and MEMPTR values to RAW variables. If the target variable is a RAW data type, the AVM re-sizes the target variable, if necessary, so that after the assignment is the same size as the source. Note that after the assignment (whether RAW = MEMPTR or MEMPTR = RAW), the target variable has a copy of the memory associated with the source—each variable has an independent copy of the data.
  • You can assign large object data from one BLOB or MEMPTR to another, and from one CLOB, LONGCHAR, or CHARACTER to another. You cannot assign large object data between BLOBs and CLOBs or MEMPTRs and LONGCHARs. You can accomplish this, indirectly, by using the COPY-LOB statement. For more information, see the COPY-LOB statement reference entry.
    Note: When assigning BLOB or CLOB fields, the field must appear by itself on either the right-hand or the left-hand side of the assignment.

    The following table lists the default character conversions that the AVM performs when assigning CLOB, LONGCHAR, and CHARACTER data between a source and target object. References to CLOBCP and CLOBDB represent CLOB data in either the CLOB's defined code page or the database's defined code page, respectively. References to the "fixed code page" represent the code page of a target LONGCHAR variable set using the FIX-CODEPAGE statement.

    Table 1. Default assignment character conversions
    When the target object (on the left) is a . . . And the source object (on the right) is a . . . The AVM converts the data in the source object to . . .
    LONGCHAR CLOBDB -cpinternal or the fixed code page
    LONGCHAR CLOBCP The CLOB's defined code page or the fixed code page
    LONGCHAR CHARACTER -cpinternal or the fixed code page
    LONGCHAR LONGCHAR The source LONGCHAR’s code page or the target’s fixed code page
    CLOBDB CHARACTER The database's defined code page
    CLOBDB LONGCHAR The database's defined code page
    CLOBCP CHARACTER The CLOB's defined code page
    CLOBCP LONGCHAR The CLOB's defined code page
    CHARACTER CLOBDB -cpinternal code page
    CHARACTER CLOBCP -cpinternal code page
    CHARACTER LONGCHAR -cpinternal code page
  • When you assign the Unknown value (?) to a BLOB or CLOB field, the AVM deletes any associated object data.
  • If expression is a solitary invocation of the NEW function (classes), this statement represents and conforms to the rules specified for the NEW statement.
  • If expression evaluates to an object reference value, field must also be a data element defined as a class or interface type that is type-compatible with expression according to the rules for assigning references to class instances defined for the NEW statement. For more information, see the NEW statement reference entry. Thus, you can assign one object reference variable to another object reference variable when the destination object reference (on the left side of the assignment) is defined for the same class, a super class, or an interface of the object reference being assigned (on the right side of the assignment). The destination object reference retains its defined class or interface type for compilation. However, following its assignment, at run time, the destination represents the subclass of field (or the class that implements the interface specified by field) that is defined by expression.

    If field has a class type that is a subclass lower in the class hierarchy than the class type represented by expression, you can cast expression to the type of field using the CAST function, but only if expression is a super class that actually contains an instance of the field class type. If field has a class type that implements an interface type represented by expression, you can similarly cast expression using the CAST function, but only if expression actually contains an instance of the field class type. For more information about the CAST function, see the CAST function reference entry.

    After the assignment, field contains a copy of the object reference value returned by expression, which points to the same object instance, not a copy of the object referenced by expression.

  • Although you can assign an object reference to a temp-table field defined as a Progress.Lang.Object class type, you cannot assign an object reference to a field in a database table. For more information, see Develop Object-oriented ABL Applications.

See also

ASSIGN statement, CAST function, Class-based object reference, COPY-DATASET( ) method, COPY-LOB statement, COPY-TEMP-TABLE( ) method, Data types, Expression, FIX-CODEPAGE statement, NEW statement, NO-ERROR option