Issue In Dynamic query

Posted by Krishna Kumar on 06-Oct-2016 06:55


I need to write a program such that users can input table name and fields name and then display the values of given fields of the given table of records.

Note - User can enter multiple fields as well. Do use sports database

I'm almost done with the program however issue is whenever I'm display  fh:buffer-value   .It only displays last value of the field in the record. Also let me know can we display column name at the top . 

Suppose user enter following fields - name custnum country. It's only displaying country. rest of the fields are getting overlapped in the frame. Can you please help me out on this? 

Below is the program -

def var table1 as character no-undo.
def var field1 as character format "x(50)" no-undo.
def var qh as handle        no-undo.
def var bh as handle        no-undo.
def var fh as handle        no-undo.
def var ix as integer       no-undo.
define variable fieldex as character extent 20.
define variable fieldey as character extent 20.

define variable lcquerystring as character no-undo.

Set table1 field1.

FIND FIRST _file WHERE _file._File-Name EQ  table1  NO-LOCK NO-ERROR.
IF available(_file) then  do:
 ASSIGN  lcQueryString = "FOR EACH " + table1.
else do:

display "Table is not available".


create buffer bh for table table1.
create query qh.
qh:set-buffers( bh ).
qh:query-prepare( lcquerystring ).
display bh:name.

repeat WITH FRAME myFrame DOWN  : 

  qh:GET-NEXT( no-lock ).
do ix = 1 to num-entries(field1," "):
assign fieldex[ix] = entry(ix,field1," ").

    fh = bh:buffer-field(fieldex[ix]).
    display  fh:buffer-value  FORMAT "x(30)" .

delete object bh.
delete object qh .   


All Replies

Posted by Brian K. Maher on 06-Oct-2016 07:02

you get the column name by looking at fh:name.

Posted by Marco Mendoza on 06-Oct-2016 08:20


display  fh:buffer-value  FORMAT "x(30)" .



Posted by Andriy Kudelya on 06-Oct-2016 13:26

do ix = 1 to num-entries(field1," ") WITH FRAME a DOWN:

This thread is closed