Can I use vaiables in a FOR EACH?

In 4gl.
How can i put a variable in a FOR EACH statement?

Like this...

DEFINE variable as CHAR.

variable = "master".

FOR EACH variable NO-LOCK:
DISPLAY variable
WITH FRAME frame1.


(the above doesn't work by the way)
thanks
rbender@rosina.com
 
What you need to do is build a dynamic query. Here is an example bit of code that may get you started.

In your question you wanted to display all fields with the "display variable" statement. To achieve this you will need loop through lh_buffer:num-fields through the buffer object handle. Check the online help on:

query object handle (lh_query)
buffer object handle (lh_buffer)
buffer-field object handle (lh_field)

Hope this gets you started.

Code:
def var lh_buffer as handle no-undo.
def var lh_query as handle no-undo.
def var lh_field as handle no-undo.

def var ll_status as logical no-undo.

def var lc_table as char no-undo.
def var lc_where as char no-undo.
assign
    lc_table = "master"
    lc_where = "master.masterkey = '101'".

create buffer lh_buffer for table lc_Table buffer-name lc_table.
    
create query lh_query.
    
lh_query:set-buffers(lh_buffer).
    
ll_status = lh_query:query-prepare("for each " + lc_table + " no-lock" +
        if lc_where <> ''
        then " where " + lc_where
        else "") no-error.
    
if not ll_status or error-status:error
then do:
    message "ERROR:" + error-status:get-message(1) view-as alert-box.
    return.
end.
    
lh_query:query-open.
lh_query:get-next().
    
do while not lh_query:query-off-end:
    lh_field = lh_buffer:buffer-field(3).
    message "Field " lh_field:name "has value of " lh_field:buffer-value
        view-as alert-box.
    lh_query:get-next().
end.

delete object lh_query.
delete object lh_buffer.
 
Top