If I understand what Srinivas "really" wants to do is this:
He wants the RPG program to "build" the query on the fly and retain the
query that has been created by the program.
Srinivas, is this what you are attempting to do?
If so, I do not think that is possible.