Consultor Eletrônico



Kbase P60774: How to achieve an updatable calculated field/cell in a Dyn S
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   29/12/2003
Status: Unverified

GOAL:

How to achieve an updatable calculated field/cell in a Dyn SDB?

FACT(s) (Environment):

Dynamics 2.1A

CAUSE:

Reference to written documentation:
Progress Solution P42492 Dynamics: How to add a calculated Field for a DynSDO

FIX:

Dynamics handles very well an updatable calculated field, however you have to handle the update process by yourself.

The following has been tested successfully in 2.1A, with both client server or AppServer session types, and only the calculated field as updatable in the SDB:

In the source SDO, define a calculated field (called 'updcf' in the examples bellow) See Progress Solution P42492 Dynamics: How to add a calculated Field for a DynSDO

Make this calculated field updatable by checking the 'updatable' toggle-box in the column editor of the SDO. (Dynamics accepts a calc field to be updatable)


In the SDB, enable the calculated field (check the 'enable' toggle-box)

Have Table-IO and Update links between the SDB and respectivelly Toolbar and SDO.

When you save an updated record, you will be able to update your calculated field cell and catch the updated value in writePreTransValidate or writeBeginTransValidate of the Data Logic Procedure of the SDO with b_<tableName>.<CalcFieldName>.  However, note that the calculated field will be recalculated and redisplayed inthe browse, so the updated value will be lost.

Such a calculated field could be use to select records or to request to perform an action on the server side or UI side, so loosing the updated value might not be an issue.  However, if you also want to keep the updated values on the UI, you might achieve the following, which saves the updated value in a temp-table to be used in the Calculate<CalcFieldName> function:



/* In def block */
DEF TEMP-TABLE kc NO-UNDO /*keep CalculcatedFieldValue */
FIELD rowIdent AS CHAR /* keep track of the record */
FIELD v AS CHAR /* keep the updated value */
INDEX rowIdent IS PRIMARY rowIdent.

[...]

PROCEDURE writeBeginTransValidate:
/*change it to YES if you want to see we can catch it*/
IF NO
THEN MESSAGE PROGRAM-NAME(1) "in" THIS-PROCEDURE:FILE-NAME
SKIP b_arm_customer.updcf
VIEW-AS ALERT-BOX INFO BUTTONS OK TITLE "Debug message".

FIND FIRST kc WHERE kc.rowIdent = b_arm_customer.rowIdent NO-ERROR.
IF NOT AVAIL kc THEN DO:
CREATE kc.
ASSIGN
kc.RowIdent = b_arm_customer.rowIdent
kc.v = b_arm_customer.updcf.
END.
END PROCEDURE.


FUNCTION CalculateUpdcf
RETURNS CHARACTER
( /* parameter-definitions */ ) :
DEFINE VARIABLE v AS CHARACTER NO-UNDO.
DEFINE VARIABLE hRowObject AS HANDLE NO-UNDO.
DEFINE VARIABLE hRowIdent AS HANDLE NO-UNDO.

v = STRING(ETIME). /* example to start with */

hRowObject = DYNAMIC-FUNCTION('getRowObject':U IN TARGET-PROCEDURE).
hRowIdent = hRowObject:BUFFER-FIELD('RowIdent':U).

FIND FIRST kc WHERE kc.rowIdent = hRowIdent:BUFFER-VALUE NO-ERROR.
IF AVAIL kc THEN v = kc.v.

RETURN v. /* Function return value. */