associate field name with table name

Posted by Admin on 23-Jan-2007 04:42

Hi,

def var fieldname as char no-undo.

fieldname = "custname".

for first customer no-lock:

disp custname.

end.

If I want to display the data in the field fieldname (this can be any valid field like custname, custaddr, etc), how do i give the disp statement?

Thanks,

S

All Replies

Posted by kevin_saunders on 23-Jan-2007 05:11

You would need to do it dynamically. Something like this should get you started:

DEFINE VARIABLE hB AS HANDLE NO-UNDO.

DEFINE VARIABLE hBf AS HANDLE NO-UNDO.

DEFINE VARIABLE cField AS CHARACTER NO-UNDO.

CREATE BUFFER hB FOR TABLE "Customer".

UPDATE cField.

ASSIGN hBf = hB:BUFFER-FIELD(cField).

hB:FIND-FIRST().

DISPLAY hBf:BUFFER-VALUE.

Of course, you would need to check that the value of cField is a valid field in the table in question..

Kevin

Posted by Admin on 23-Jan-2007 06:04

Thanks a lot for your help.

Posted by Admin on 23-Jan-2007 11:27

You can also use the static buffer in the loop, so

def var fieldname as char NO-UNDO INITIAL "custname".

def var fieldHandle as handle no-undo.

ASSIGN fieldHandle = BUFFER customer:HANDLE:BUFFER-FIELD(fieldname).

for first customer no-lock:

disp fieldHandle:BUFFER-VALUE.

end.

This thread is closed