Mastering PowerBuilder

HomePrevious Lesson: Course 3:: Session 24 :: Page 360
Next Lesson: Course 3:: Session 24 :: Page 380
Multiple Table DataWindow Update Service

As explained earlier in the Advanced DataWindows session, you know how tedious it is to update multiple table DataWindows. You need to call Modify() function a lot of times with tilde characters and so on.

PFC makes this easy for you. you just need to call couple of functions with no tilde characters headache. The following code is for updating a DataWindow that has product_master and trans tables.

String       ls_table, ls_KeyCols[], ls_UpdatableCols[]
dw_product.of_SetMultiTable( TRUE )
// Register Update Characteristics for
//"product_master" Table
ls_table = "product_master"
ls_KeyCols[1] = "product_no"
ls_UpdatableCols[1] = "product_balance"
this.inv_MultiTable.of_AddToUpdate (ls_table, &
           ls_KeyCols, ls_UpdatableCols[] ) 
// Register Update Characteristics for "trans" Table
ls_table = "trans"
ls_KeyCols[1] = "tran_no"
ls_KeyCols[2] = "tran_serial_no"
ls_UpdatableCols[1] = "tran_date"
ls_UpdatableCols[2] = "tran_type"
ls_UpdatableCols[3] = "tran_item_no"
ls_UpdatableCols[4] = "tran_qty"
this.inv_MultiTable.of_AddToUpdate (ls_table, &
            ls_KeyCols, ls_UpdatableCols[] )

First, we are enabling the multiple table update service by calling of_SetMultiTable() function. Then we are calling of_AddToUpdate() function with three parameters. First one being the table name, second one is an array of key columns for that table and the third one is an array of updatable columns in that table. You need to call of_AddToUpdate() function once for each table.

If you call the function in above format, PFC uses "Delete & Insert" and "only Key values in the WHERE clause". If you want to use different values like "UpdateInPlace", other options (you can see available options in the DataWindow painter by selecting Rows/Update Characteristics from the menu) for the WHERE clause with the following format.

of_AddToUpdate( TableName, KeyCols[], UpdatableCols[],&
Key_Modification_Flag, WHERE_Cluase_option )

Remember, of_AddToUpdate() function is overloaded.

HomePrevious Lesson: Course 3:: Session 24 :: Page 360
Next Lesson: Course 3:: Session 24 :: Page 380