title: Using BETWEEN operator in a WHERE clause with dates from an internal table
body: <p>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.</p>
  <pre><code>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
  </code></pre>
  <p>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.</p>
  <p>I've tried replacing BETWEEN with regular &gt;= and &lt;= operators:</p>
  <pre><code>SELECT * FROM FPLT
  INNER JOIN @it_openprd AS OP ON FPLT~TETXT = OP~TETXT
  WHERE FPLT~FKDAT &gt;= OP~fromdate AND FPLT~FKDAT &lt;= OP~todate
  AND   FPLT~NFDAT &gt;= OP~fromdate AND FPLT~NFDAT &lt;= OP~todate
  </code></pre>
  <p>But the query returns incorrect results.</p>
  <p>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 ?</p>