ASSIGN statement

Moves data previously placed in the screen buffer by a data input statement or moves data specified within the ASSIGN statement by an expression to the corresponding fields and variables in the record buffer.

Data movement



Syntax

ASSIGN {
           [ [ INPUT ] FRAME frame | BROWSE browse ]
                  { field [ = expression] } [ WHEN expression ]
        } ... [ NO-ERROR ]
ASSIGN { record [ EXCEPT field ... ] } [ NO-ERROR ]
[ FRAME frame | BROWSE browse ] field
The name of the field or variable (field) to be set from the corresponding value found in the screen buffer or expression. The field must be qualified by a frame name (frame) or browse name (browse) if field is specified as an input widget in more than one frame. If field is set from expression, field can include all of the elements that are defined for the left side of an Assignment (=) statement.
expression
An expression with a data type that is consistent with the data type of field. In this case, the AVM determines the field value from the expression rather than from the screen buffer. For more information on expression, see the Expression reference entry.
WHEN expression
Moves data to the record buffer only when expression has a value of TRUE. Here, expression is a field name, variable name, or expression whose value is logical. The AVM evaluates WHEN expressions at the beginning of the assignment, before any assignments take place.
NO-ERROR

The NO-ERROR option is used to prevent the statement from raising ERROR and displaying error messages.

record
The record buffer name with the fields set, from the corresponding values in the screen buffer. Naming a record is a shorthand way to list each field in that record individually.

To use ASSIGN with a record in a table defined for multiple databases, you might have to qualify the record's table name with the database name. See the record definition in the Record phrase reference entry for more information.

EXCEPT field
All fields in the record buffer are affected except for those listed. Separate field names with a space.

Examples

The following procedure prompts you for a customer number and retrieves the customer record if one exists, or creates a new one if it does not exist. If it creates a new record, the value for the CustNum field is assigned from the value you entered in response to the PROMPT-FOR statement.

r-asgn.p

REPEAT:
  PROMPT-FOR Customer.CustNum.
  FIND Customer USING Customer.CustNum NO-ERROR.
  IF NOT AVAILABLE Customer THEN DO:
    CREATE Customer.
    ASSIGN Customer.CustNum.  END. 
  UPDATE Customer WITH 2 COLUMNS.
END.

The next procedure changes the order number and line number of an order-line record. (It copies an order-line from one order to another.) It sets the new values into variables and modifies the record with a single ASSIGN statement that contains two assignment phrases in the form field = expression. Thus, both fields are changed within a single statement. Because the AVM re-indexes records at the end of any statement that changes an index field value, and because OrderLine.OrderNum and OrderLine.LineNum are used jointly in one index, this technique does not generate an index until both values change.

r-asgn2.p

DEFINE VARIABLE neword   LIKE order-line.order-num LABEL "New Order".
DEFINE VARIABLE newordli LIKE order-line.line-num  LABEL "New Order Line".

REPEAT:
  PROMPT-FOR OrderLine.OrderNum OrderLine.LineNum.
  FIND OrderLine USING OrderLine.OrderNum AND OrderLine.LineNum.
  SET neword newordli.
  FIND Order WHERE Order.OrderNum = neword.
  ASSIGN 
    OrderLine.OrderNum = neword
    OrderLine.LineNum  = newordli.
END.

Notes

See also

Assignment (=) statement, CAST function, Class-based object reference, COPY-DATASET( ) method, COPY-LOB statement, COPY-TEMP-TABLE( ) method, Data types, Expression, FIX-CODEPAGE statement, INPUT function, NO-ERROR option, PROMPT-FOR statement, SET statement, UPDATE statement