Assign a value to a field using variable

raptor

New Member
I have the following problem using Progress 9.1D:
I have a variable (f.e. l-field1) which contains a field-name. Now, I have to assign a value to this field.

Of course
Code:
assign l-field1 = xyz
assigns the value to the variable instead of the field. How to assign the value to the field? Or is there a better way to assemble a field-name with a counter (f.e. 'field' + 1 -> 'field1')?


Thank you for your help.
 
Check out dynamic queries (which are kind of like dynamic SQL in Java and .NET). Something like this (below). This is iterating through a whole table, you could change it to find a specific record easily enough.

Code:
DEF VAR p_table AS C NO-UNDO INIT "your_table".
DEF VAR h_bh AS HANDLE NO-UNDO.
DEF VAR h_qh AS HANDLE NO-UNDO.
CREATE QUERY h_qh.
CREATE BUFFER h_bh FOR TABLE p_table.
h_qh:SET-BUFFERS(h_bh).
h_qh:QUERY-PREPARE("FOR EACH " + p_table).
h_qh:QUERY-OPEN.
REPEAT:
    h_qh:GET-NEXT.
    IF h_qh:QUERY-OFF-END
    THEN LEAVE.
    h_bh:BUFFER-FIELD("your_field") = "your_value".
END.
DELETE OBJECT h_bh NO-ERROR.
DELETE OBJECT h_qh NO-ERROR.
 
Not tried the code, but shouldn't

h_bh:BUFFER-FIELD("your_field") = "your_value".
be
h_bh:BUFFER-FIELD("your_field"):BUFFER-VALUE = "your_value".

?
 
Back
Top