There are two ways to update a database in a Procedure object:
1. Directly with commands.
2. Using Business Components.
Consider the following Transaction object:
Customer
{
CustomerId*
CustomerName
}
Below are two possible alternatives to solve an insertion (similarly, there are two alternatives to update and delete).
1. A direct insertion using the New command (this code can only be included in a Procedure Source):
Procedure Rules:
Parm(&CustomerId,&CustomerName);
Procedure Source:
New
CustomerId = &CustomerId
CustomerName = &CustomerName
Endnew
2. An insertion using the business components concept (this code can be included in a Procedure Source and/or in other GeneXus objects in their events section):
Procedure Rules:
Parm(&CustomerId,&CustomerName);
Procedure Source:
&Customer.CustomerId = &CustomerId
&Customer.CustomerName = &CustomerName
&Customer.Save() //&Customer is a variable based on the Transaction Customer defined as a Business Component
Commit
The question is, which of these two methods is better?
The answer, as often happens, is that it depends! From the point of view of performance, the first method is preferred, since there are no controls involved and the generated SQL sentence will be optimized for bulk updates. On the other hand, from the point of view of consistency, the second method is best, since all the controls will be enforced independently if data comes from a screen or a Procedure.
So, a good rule of thumb would be to always use Business Components unless performance is critical.
Business Components - Differences between the Save method and the Insert and Update methods
Error handling in Business Components