Problem while passing db name as a parameter to internal procedure

sharika_ganju

New Member
Hi All,
I had a small doubt. I have a program as follows :

define variable v_database as character no-undo.
mainloop.
repeat :
run p_sample (input v_database).
end.

procedure p_sample:
define input parameter v_database as character no-undo.
for each v_database.vd_mstr no-lock:
display v_database.vd_mstr.vd_addr.
end.
end.
The problem that I am facing is how to execute "v_database.vd_mstr", which gives a progress error. Is there any way in a internal procedure where the database name can be taken as an input and used for querying a table ? Please advice.
Thanks in advance.
 
Try using an alias.

create alias mydb for database value (ldbname (1)).
run sample.p.

sample.p:
for each mydb.vd_mstr no-lock:
display mydb.vd_mstr.vd_addr.
end.
 
Hi All,
I had a small doubt. I have a program as follows :

define variable v_database as character no-undo.
mainloop.
repeat :
run p_sample (input v_database).
end.

procedure p_sample:
define input parameter v_database as character no-undo.
for each v_database.vd_mstr no-lock:
display v_database.vd_mstr.vd_addr.
end.
end.
The problem that I am facing is how to execute "v_database.vd_mstr", which gives a progress error. Is there any way in a internal procedure where the database name can be taken as an input and used for querying a table ? Please advice.
Thanks in advance.

You can only resolve this problem using dynamic query's.

define variable v_database as character no-undo.
mainloop.
repeat :
run p_sample (input v_database).
end.

procedure p_sample:
define variable hQuery as handle no-undo.
define variable hBuffer as handle
 
Hi All,
I had a small doubt. I have a program as follows :

define variable v_database as character no-undo.
mainloop.
repeat :
run p_sample (input v_database).
end.

procedure p_sample:
define input parameter v_database as character no-undo.
for each v_database.vd_mstr no-lock:
display v_database.vd_mstr.vd_addr.
end.
end.
The problem that I am facing is how to execute "v_database.vd_mstr", which gives a progress error. Is there any way in a internal procedure where the database name can be taken as an input and used for querying a table ? Please advice.
Thanks in advance.

You can only resolve this problem using dynamic query's.

something like this, typed from the head.

define variable v_database as character no-undo.
mainloop.
repeat :
run p_sample (input v_database).
end.

procedure p_sample:
define input parameter pcDatabase as character no-undo.
define variable hQuery as handle no-undo.
define variable hBuffer as handle no-undo.

create query hQuery.
create buffer hBuffer for table pcDatabase + ".vd_mstr".

hQuery:set-buffers(hBuffer).
hQuery:query-prepare("FOR EACH " + pcDatabase + ".vd_mstr NO-LOCK").

hQuery:query-open.
hQuery:get-first.

do while not hQuery:query-off-end:
display hBuffer:buffer-field("vd_addr"):buffer-value.
hQuery:get-next.
end.

delete query hQuery.
delete buffer hBuffer.
end procedure.
 
Try using an alias.

create alias mydb for database value (ldbname (1)).
run sample.p.

sample.p:
for each mydb.vd_mstr no-lock:
display mydb.vd_mstr.vd_addr.
end.


The alias will not work in an internal procedure.
 
Thanks a lot for all your inputs. They were really useful. I tried both the solutions. The alias method did not work for me. But the dynamic query approach should solve my problem.
 
Back
Top