Business Components - Differences between the Save method and the Insert and Update methods

Official Content
This documentation is valid for:

While the Save method takes into account the current mode of the variable based on the business component to which it is applied, the Insert and Update methods don't take it into account to determine if an addition or an update has to be performed in the database. The Insert and Update methods directly perform the operations indicated by their names.

In addition, the Update method does not require the use of the Load method, as opposed to the Save method when it is used to update the database. This is advantageous because the Load method produces an access to the database and it can be avoided.

So, the first code is more performant than the second, even though the result of both of them is the same:

1) 

&Customer=new()   //in this case the new operator can be omitted, but if several customers are updated, it must be used
&Customer.CustomerId = 8    
&Customer.CustomerEmail = !'marybrown@gmail.com'
If &Customer.Update()
   commit
else
   rollback
endif   

 

2) 

&Customer.Load(8)
&Customer.CustomerEmail = !'marybrown@gmail.com'
&Customer.Save()
if &Customer.Success()
  commit
else
  rollback
endif

 

Note: If the above codes are inside a loop, by using the Load() method, you don't need to use the New operator (because the variable is reloaded every time regardless if you are using the Save or the Update method). On the other hand, if you decide to assign the primary key attribute(s) value(s), you have to precede that assignment with the New operator.


Was this page helpful?
What Is This?
Your feedback about this content is important. Let us know what you think.