• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2193
  • Last Modified:

Help on 4GL syntax

I'm very new to 4GL in Progress OpenEdge 10.1 very familiar with SQL92. My question is this. Is there a IN condition within a WHERE clause in 4GL?

I want to convert the following SQL statement into 4GL:
SELECT jc_job.kco, jc_job_num, jc_costcode.jcc_cost
FROM jc_job INNER JOIN ON jc_job.job_num = jc_costcode.job_num
WHERE kco IN (11,12,16,17)




0
marcorus
Asked:
marcorus
2 Solutions
 
Mark WillsTopic AdvisorCommented:
According to the manual you can... that is... using the SQL syntax - which is supported.

IN Predicate
The IN predicate can be used to compare a value with a set of values. If an IN predicate specifies
a query expression, then the result table it returns can contain only a single column.
This is the syntax for an in_predicate:
Syntax
expression [ NOT ] IN
{ (query_expression) | (constant , constant [ , ... ] ) }
address.state IN (MA, NH)

Have a look at : http://www.psdn.com/library/servlet/KbServlet/download/112-102-99/dmsrf.pdf

But you may want the APL reference...
0
 
Memnoch76Commented:
Solution 1: The CAN-DO() function can compare a field's value to a list of values to return only what you want and can be used as part of a where clause.  Be careful how you use this especially in large tables because this particular phrase won't participate in index selection and will rely on what the rest of your where clause is constructed of.  If this is a relatively small table <1000 records you probably wouldn't notice much of an impact if it was scanning the full index.

ex. ... WHERE CAN-DO("11,12,16,17",jc_job.kco) ...

Solution 2: Create a DO block around your FOR EACH statement stepping through each of the values of the list and assign that to a variable and then check that as an equality match in your where clause.

ex. (see code snippet)

It's also a good idea to always check what index(es) your queries are resolving to by using the COMPILE statement's XREF option and in the xref file verify that all the lines that execute a "SEARCH" contain a valid index and not "WHOLE-INDEX" to keep your queries as efficient as possible.

DEF VAR i AS INT NO-UNDO.
DEF VAR ii AS INT NO-UNDO.
DEF VAR c_kco_list AS CHAR INIT "11,12,16,17" NO-UNDO.
DEF VAR c_kco AS CHAR NO-UNDO.
 
ii = NUM-ENTRIES(c_kco_list).
 
DO i = 1 TO ii:
  kco = ENTRY(i,c_kco_list).
  FOR EACH jc_job NO-LOCK
    WHERE jc_job.kco = c_kco
    ...
    :
    ...
  END.
END.

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now