I have an internal table populated with start and end dates for each type of period. I want to use this internal table in a WHERE clause of an SQL query to select items whose start and end dates are within the open period of their respective type.
TYPES: BEGIN OF s_openprd,
TETXT TYPE TETXT,
fromdate TYPE d,
todate TYPE d,
END OF s_openprd.
DATA: it_openprd TYPE TABLE OF s_openprd WITH KEY TETXT.
SELECT * FROM FPLT
INNER JOIN @it_openprd AS OP ON FPLT~TETXT = OP~TETXT
WHERE FPLT~FKDAT BETWEEN OP~fromdate AND OP~todate
AND FPLT~NFDAT BETWEEN OP~fromdate AND OP~todate
However I get the error saying that OP~fromdate should be of a compatible type to be used as an operator with BETWEEN. The types listed include the date type d.
I've tried replacing BETWEEN with regular >= and <= operators:
SELECT * FROM FPLT
INNER JOIN @it_openprd AS OP ON FPLT~TETXT = OP~TETXT
WHERE FPLT~FKDAT >= OP~fromdate AND FPLT~FKDAT <= OP~todate
AND FPLT~NFDAT >= OP~fromdate AND FPLT~NFDAT <= OP~todate
But the query returns incorrect results.
I assume the ABAP type d is incompatible with SQL type d ? How can I use an internal table to restrict the selection in this way ?