Kbase P41550: How to dynamically set a value to a field using a field name
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  11/09/2003 |
|
Status: Unverified
GOAL:
How to dynamically set a value to a field using a field name from a field value of another table
FIX:
Use dynamic queries. Follow is a code sample on how this could be archived.
DEFINE VARIABLE bh AS WIDGET-HANDLE.
DEFINE VARIABLE qh AS WIDGET-HANDLE.
DEFINE VARIABLE fld1 AS HANDLE.
DEFINE TEMP-TABLE tt-a
FIELDS tCust LIKE customer.cust-num
FIELD tFieldName AS CHAR
FIELD tValue AS CHAR.
DO TRANSACTION:
CREATE tt-a.
ASSIGN tcust = 1
tFieldName = "name"
tValue = "teste".
END.
CREATE QUERY qh.
CREATE BUFFER bh FOR TABLE "Customer".
qh:SET-BUFFERS(bh).
FOR EACH tt-a NO-LOCK:
qh:QUERY-PREPARE("for each customer where cust-num = " + string(tt-a.tCust) + " NO-LOCK" ).
qh:QUERY-OPEN().
fld1 = bh:BUFFER-FIELD(tt-a.tFieldName).
qh:GET-FIRST().
DO TRANSACTION:
qh:GET-CURRENT(EXCLUSIVE-LOCK).
fld1:BUFFER-VALUE()= tt-a.tValue.
END.
DISP fld1:BUFFER-VALUE() FORMAT "x(10)".
END.