Base Transaction in For Each command

Official Content

Since GeneXus X Evolution 3 you can define next to the For Each command the Transaction name or Transaction.Level name that you want to use as Base Table for the For Each.


For Each Invoice
    Print CustomerName, InvoiceDate
    For Each Invoice.Line
        Print ProductName, InvoiceLineQuantity, InvoiceLinePrice, InvoiceLineTotal

Read Base Transaction clause to learn the complete topic.

More than one base transaction can be referenced

Read Multiple Base Transactions in a For Each command to learn the complete topic.

How is the base table determined

If one Base Transaction is declared in the For Each, the table associated with that Base Transaction is considered as the base table, and the attributes inside the body of the For Each, conditions, orders, etc. must be included in the extended table.

If more than one Base Transaction is declared, if it's possible, a JOIN is made between the tables associated with these Transactions. Otherwise, a Cartesian Product is done. The attributes of the For Each have to be in the extended table of any of these tables.


Advantages of mentioning Base Transaction(s) in the For Each

In addition to the scenarios presented above, the advantages of using the Base Transaction in the For each include:

• Improved capacity to understand existing KBs. If the For Each has Base Transaction when you facing a new KB will not have to see the navigation to determine the table on which the iteration is taking place.

• Enhanced expressive capacity of the For Each and more simplicity.

• Improved specification time: The time for the specification is improved because it isn't needed to do the calculation of the For Each’s Base Table.

• Reference in the KB between Base Transactions and the For Each commands that mention them: The KB stores the reference between the Transactions and the For Each commands that use them as Base Transaction, so, if a Transaction changes, you can directly see the For Each commands that may be affected by such change.


Since GeneXus X Evolution 3.

Compatibility Notes

1) In order to avoid ambiguity in the For Each Order clause, the Order clause is not optional anymore.
2) In case you program the following, you will get an error: error: Program 'AttributeX' does not exist:

For Each AttributeX


You need to change it to:

For Each Order AttributeX


3) In the case of KBs which are converted to GeneXus X Evolution 3, or xpz files that were generated in a previous version, an automatic conversion is performed when the object is opened or specified.