Kbase 18495: How To Use Updateable Calculated Fields With SmartDataObjects in ADM2
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  31/07/2007 |
|
Status: Verified
GOAL:
How To Use Updateable Calculated Fields With SmartDataObjects in ADM2
FACT(s) (Environment):
Progress 9.x
FIX:
Updateable calculated fields may be defined in a SmartDataObject and will be enabled when placed onto a data visual SmartObject such as a SmartDataViewer or SmartDataBrowser.
An "updateable" field in a SmartDataObject means that the SmartDataObject can accept a value back from a visual object for that field and does not necessarily update the database with that value. Values passed back to a SmartDataObject for an updateable calculated field will not update the database. These updated values can be used by writing code to use them in the SmartDataObject, for example, in a RowValidateObject procedure or a submitRow function override.
Step by step details:
This example describes how to create an updateable calculated field in a SmartDataObject and use its changed value.
1) Create a SmartDataObject for the Customer table in the sports2000 sample database.
2) Add a calculated field in the SmartDataObject called calcNewLimit with the following code:
RowObject.CreditLimit + 500
Notice that an internal procedure called DATA.CALCULATE has been automatically created in the SmartDataObject with the following:
ASSIGN rowObject.calcNewLimit = STRING(RowObject.CreditLimit + 500).
This procedure is run from transferRowFromDB in data.i to populate the temp-table field, calcNewLimit.
3) Create a SmartDataViewer with the Customer SmartDataObject as its Data Source include calcNewLimit as one of its fields.
4) Create a submitRow override function in the SmartDataObject with the following code to access a changed value for the calcNewLimit field:
DEFINE VARIABLE iColNum AS INTEGER NO-UNDO.
DEFINE VARIABLE cColName AS CHARACTER NO-UNDO.
DEFINE VARIABLE changedCalc AS DECIMAL NO-UNDO.
DO iColNum = 1 TO NUM-ENTRIES(pcValueList,CHR(1)) BY 2:
cColName = ENTRY(iColNum, pcValueList,CHR(1)).
IF cColName = "calcNewLimit" THEN
changedCalc = DECIMAL(ENTRY(iColNum + 1, pcValueList,CHR(1))).
END.
RETURN SUPER( INPUT pcRowIdent, INPUT pcValueList ).
When the user submits a row, changedCalc will have the value for any changes made by the user to the calculated field for that row. You can then handle these changes appropriately in your code depending on the needs of your application.