Mastering PowerBuilder

HomePrevious Lesson: Report Service
Next Lesson: Linkage Service

Multiple Table DataWindow Update Service

As explained earlier in the Advanced DataWindows session, it is tedious 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. 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 of all, we are enabling the multiple table update service by calling the of_SetMultiTable() function. Then, we are calling the 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 updateable columns in that table. You need to call the of_AddToUpdate() function once for each table.

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

Remember, of_AddToUpdate() function is overloaded.
HomePrevious Lesson: Report Service
Next Lesson: Linkage Service