Consultor Eletrônico



Kbase P5840: How To Assign A Value To A Temp-Table Field When The Field N
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   1/27/2003
Status: Unverified

GOAL:

How to assign a value to a temp table field when the field name is in a variable?

FIX:

The following sample code shows how to update a field in a temp-table when the actual name of the field is stored in a variable. Please note that this sample code is not very realistic (i.e. the temp-table doesn't have any data in it).

DEFINE TEMP-TABLE DummyTable NO-UNDO
FIELD Key AS INTEGER
FIELD Data AS CHARACTER.

DEFINE VARIABLE hBuffer AS HANDLE NO-UNDO.
DEFINE VARIABLE hField AS HANDLE NO-UNDO.
DEFINE VARIABLE iOldValue AS INTEGER NO-UNDO LABEL 'Enter Old Key Value'.
DEFINE VARIABLE iNewValue AS INTEGER NO-UNDO LABEL 'Enter New Key Value'.

UPDATE iOldValue iNewValue.

FIND FIRST DummyTable WHERE Key = iOldValue NO-LOCK NO-ERROR.

IF AVAILABLE(DummyTable) THEN
DO:
CREATE BUFFER hBuffer FOR TABLE 'DummyTable'.
hBuffer:FIND-BY-ROWID(ROWID(DummyTable),EXCLUSIVE-LOCK,NO-WAIT).
IF hBuffer:AVAILABLE THEN
DO:
hField = hBuffer:BUFFER-FIELD('Key').
hField:BUFFER-VALUE = iNewValue.
hBuffer:BUFFER-RELEASE().
END.
END.
ELSE
MESSAGE 'Could Not Find Record With Key Value Of ' iOldValue VIEW-AS ALERT-BOX.

DELETE OBJECT hBuffer.