dynamic assign

j4n

Member
win 9.1c


i have got 2 tables with nearly the same structure. i want to compare both the following way:

i grab the _file with the name of my first table. then i grab the _field of _file. now i've got all fields which i store in a temp table with a numeric counter.
eg:
1 name
2 adress
3 email

for 'better' :sleepy: unterstanding:

FOR EACH _file
WHERE _file._file-name = "table1":
FOR EACH _field of _file:
create ttFields.
assign
ttFields.counter = 1 /* 2,3,4 etc. */
ttFields.name = _field._field-name
.
END.
END.

now i have to find the value of the field table1.name. is it possible to get the value of a field when you get the name as string?
i tried with dynamic temptables...
 

jongpau

Member
Hi,

When you say "nearly the same structure" does that mean that the fields in the two tables you want to compare have the same field names and data types? If so, there is probably a much easier (dynamic) way to compare (without having to go to _file and _field).

To dynamically access a database table/field:

CREATE BUFFER bufferHandle FOR TABLE <TableName>.

(bufferHandle = variable of type HANDLE, <TableName> is either a quoted string or a variable (or database/temp-table field) that specifies the table name).

For instance: CREATE BUFFER lhBuffer FOR TABLE "Customer":U.

Next (to dynamically get a field value from the buffer):
fieldHandle = bufferHandle:BUFFER-FIELD(<FieldName>).
MESSAGE fieldHandle:BUFFER-VALUE.
(fieldHandle is a variable of type HANDLE. <FieldName> is either a quoted string or a variable (or database/temp-table field) that specifies the field name).

For instance:
lhField = lhBuffer:BUFFER-FIELD("CustNo":U).
MESSAGE lhField:BUFFER-VALUE.

AND don't forget to delete the buffer handle when you are finished with it. Otherwise you will most probably create a "memory leak":
DELETE OBJECT lhBuffer.

I hope this helps and that I understood what you were after. If not please tell a bit more about what it is you want to do...
 
Top