Consultor Eletrônico



Kbase P117532: 4GL/ABL: How to construct a query PREPARE-STRING that includes a field, a variable and the LOOKUP fu
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   12/31/2008
Status: Verified

GOAL:

4GL/ABL: How to construct a query PREPARE-STRING that includes a field, a variable and the LOOKUP function?

GOAL:

How to create a dynamic query with a WHERE clause that invokes the LOOKUP function to lookup for a field in character list?

GOAL:

How to create a dynamic query to return records based on a set of values for a given table field?

FACT(s) (Environment):

Progress 9.x
OpenEdge 10.x
All Supported Operating Systems

FIX:

The following code demonstrates how to construct a query's PREPARE-STRING whose WHERE clause includes a field (City), a variable (cVariable ) and the LOOKUP function. Notice that the resulting query PREPARE-STRING will be: 'FOR EACH Customer NO-LOCK WHERE LOOKUP(City, "Boston,Paris,London") > 0' and the query will return all customers whose City is in the list "Boston, Paris, London".
DEFINE VARIABLE hQuery AS HANDLE NO-UNDO.
DEFINE VARIABLE cVariable AS CHARACTER NO-UNDO.
DEFINE VARIABLE cQueryString AS CHARACTER NO-UNDO.
DEFINE QUERY myquery FOR Customer.
ASSIGN
cVariable = "Boston, Paris, London"
cQueryString = "FOR EACH Customer NO-LOCK WHERE LOOKUP(City," + QUOTER(cVariable ) + ") > " + STRING (0).
hQuery = QUERY myquery:HANDLE.
hQuery:QUERY-PREPARE(cQueryString).
hQuery:QUERY-OPEN().
MESSAGE hQuery:PREPARE-STRING
VIEW-AS ALERT-BOX INFO BUTTONS OK.
REPEAT:
hQuery:GET-NEXT().
IF hQuery:QUERY-OFF-END THEN LEAVE.
MESSAGE Cust-num Name
VIEW-AS ALERT-BOX INFO BUTTONS OK.
END.