Dynamic can-find, how can I do this?

Emma

Member
I have a table that holds label text in one field, and then a program name and table name in the second field, comma seperated

What i need to do is as follows:


IF CAN-FIND(FIRST tablename WHERE tablename.field = cField)
THEN "Y"
ELSE "".

where tablename is the entry 2 value returned from the second database field.

How can i build up the can-find dynamically, so that it pulls the values from the database table to build up the code?

Thanks,

Emma.
 
Hi Emma,

Here is a nice function (can-find-dynamic) that you can use just like this:
Code:
if can-find-dynamic("tablename", "tablename.field='" + cfield + "'")
then do:
    ....
end.

You just have to watch that cfield dosn't contain a close quote character.
I usually do a replace(cfield, "'", "~~'") on the value, you could even put this in the can-find-dynamic function if you like!

Code:
FUNCTION can-find-dynamic RETURNS LOGICAL
  (ipc_table as char, ipc_where as char) :
    def var lh_buffer as handle no-undo.
    def var lh_query as handle no-undo.
    def var ll_status as logical no-undo.

    def var ll_return as logical no-undo.

    create buffer lh_buffer for table ipc_table buffer-name "lb_table".
    create query lh_query.
    lh_query:set-buffers(lh_buffer).
    ll_status = lh_query:query-prepare(
        "for each lb_table no-lock " + if ipc_where <> ''
            then 'where ' + ipc_where
            else '') no-error.
    if error-status:error or ll_status = false
    then do:
        delete object lh_buffer.
        delete object lh_query.
        return false.
    end.

    lh_query:query-open.
    lh_query:get-first().
    ll_return = lh_buffer:available.

    lh_query:query-close().
    lh_buffer:buffer-release().
    delete object lh_query.
    delete object lh_buffer.

    return ll_return.

END FUNCTION.
 
Actually the code does not do the same thing.

Can-find looks for a record but does not return it over the network (client-server) which is a big bonus.

The function you have written will return the record over the network and fetch it into the buffer pool etc.

ie. not the same functionality.

Progress needs to do its own dynamic can-find.
 
Top