Assigns a value to an attribute.
att operator expression
Attribute to be assigned.
One of the following assignment operators: = , +=, -=, *=, /=.
Is any valid expression that can involve constants, functions, methods, procedures, variables, attributes, arithmetic calculations, Inline Formulas. The result must match the attribute data type definition.
Objects: Procedure, Transaction
Attribute assignments imply a database update.
If you need to assign a value to an attribute within the definition of an object, the object section where the assignment can be defined depends on the object (for example it can be done in Procedure Sources inside a For each command or in Transaction Rules).
The assigned value type must match the attribute type. Otherwise, a warning message will be displayed in the navigation report.
- Attributes that belong to the Base Table you are navigating.
- Attritubles that can be inferred because they belong to the extended table of the base table you are navigating.
If the update is done inside a For each command, the update is performed when the Endfor command of the associated group is encountered. Despite this, attributes referenced after an assignment and before the associated Endfor, will contain the last assigned value.
A Procedure is needed to update all the flight prices.
For each Flight //The base table navigated is FLIGHT
FlightPrice = FlightPrice * 1.10
In this example, is FlightPrice, the base table navigated by GeneXus is: FLIGHT.
Since no filters have been defined, all the table records will be navigated. For each flight, its price is updated and in this case, it's increased by 10%.
Remember that in a single For Each command several physical tables can be updated. A For Each command always has a base table that navigates and can update. However, it can also update the entire extended table of that base table.
In the following example, the base table of the For Each command is FLIGHT. As each flight has one airline, the details of the airline associated with each flight could be changed:
For each Flight //The base table navigated isFLIGHT
FlightPrice = FlightPrice * 1.10
AirlineName = ‘Copa Airlines’
AirlineDiscountPercentage = 20
- It is not valid to assign a value to an attribute when the attribute is part of the index used to scan over the base table. An error will be shown in the navigation list.
- It is not valid to assign a value to an attribute that belongs to a Dynamic Transaction. If you do so, the spc0212 error will appear.
Updating the database using Business Components
Assignment Command for variables
- Procedures don’t check the consistency of the data we assign. Since databases check the consistency of interrelated data, when the user runs the application and tries to assign an inconsistent value, the database will reject the operation and the inconsistent data will not be saved. However, the program will stop working and this isn’t very user friendly. Therefore, if you use procedures to update the database, it will be your responsibility to assign valid and well related data.
- Redundancy will not be automatically maintained when updating the database in Procedures. This maintenance is the programmer's responsibility. That is, if a Redundancy depends on the attribute being updated, GeneXus will not search or calculate data to store it in the redundant attribute.