How to add a date condition to for each loop in Progress 4GL query?

Viewed 1185

I have difficulties with a query I have to change to limit the data I export from a Progress database. I export "myorderdate" to a text file. However, I have to limit the data to only orders after year 2012.

OUTPUT STREAM s1 TO VALUE(exportFileStringDirectory).
FOR EACH poTable NO-LOCK WHERE
 ponum = 1 AND
 /* this doesn't work -->*/
 /*myorderdate.YEAR >= DATE("2012").YEAR AND*/
 conum = 1:

 PUT STREAM s1 UNFORMATTED
    ISO-DATE(myorderdate)
 SKIP. 
END.
OUTPUT STREAM s1 CLOSE.

I'm new to Progress 4GL databases and work with databases altogether. All I have to do is a small change to the code so please forgive me if the description lacks some vital information.

2 Answers

I would code it like this:

FOR EACH poTable NO-LOCK WHERE
 ponum = 1 AND conum = 1 and 
 myorderdate >= 1/1/2012:

That way you avoid having to evaluate the YEAR() function with every iteration of the loop.

Use YEAR function. YEAR() function takes input as date and returns year value of the date as an integer.

So, replace

myorderdate.YEAR >= DATE("2012").YEAR

with:

YEAR(myorderdate) >= 2012
Related