Generic Object Read

SOLVED

I need to create a generic function to read an object in X3.  I'm thinking some of the standard object functionality could be used, or maybe even a dynamic query, but I'm not completely sure how to approach it.

For example, I want to pass a table name, select field, and compare field:

TABLE = "BPCUSTOMER"

SELFLD = "BPCNUM"

CMPFLD = "NA009"

And it would return the customer from BPCUSTOMER where BPCNUM="NA009".

I have done queries with dynamic select criteria, but I'm not sure how to make the entire query/read statement dynamic.

Read [F:BPC]BPC0=CMPFLD

or

For [F:BPC] Where BPCNUM=CMPFLD

Has anybody done anything like this?