StartWork function

Syntax

StartWork()

Description

Use the StartWork function to mark the start of a unit of work.

Once this function is executed, no updates to the database are allowed until a unit of work is completed. A unit of work is completed by an event completing (such as a FieldChange event) in which case all the Updates are saved.

A unit of work can also be completed using the CommitWork built-in function.

If a SQL failure occurs anytime during the unit of work, after the StartWork function has been called and before the unit of work completes, all updates are rolled back, up to when the StartWork function was executed.

This function can be used for nested component interface calls, such that if the lower level component interface fails, any database changes made by the calling component interface can be rolled back.

Parameters

None.

Returns

None.

Example

&oCI = &SESSION.GetCompIntfc(CompIntfc.CUSTOMER); 
   If &oCI <> Null Then       
      . 
      . 
      . 
      For &i = 1 To &rsCustomer.RowCount          
         &recCust = &rsCustomer(&Transaction).GetRecord(Record.CUSTOMER); 
         StartWork();          
         If &oCI.Create() Then 
             rem ***** Set CI Properties *****; 
      . 
         . 
         . 
             If Not &oCI.Save() Then 
                 rem ***** Error Handling *****; 
                 ..... 
             End-If; 
         End-If; 
         rem ***** CommmitWork ensures that all transactions between     *****; 
         rem ***** StartWork and CommitWork get committed to the database *****; 
         CommitWork(); 
 
         &oCI.Cancel(); 
      . 
      . 
      . 
      End-For; 
   End-If