WITH changed AS (
    SELECT "DHINV#" FROM lgdat.oih WHERE DHIDAT BETWEEN '{ois_wm}' AND CURRENT_DATE
    UNION SELECT "DHINV#" FROM lgdat.oih WHERE DHPDAT BETWEEN '{ois_wm}' AND CURRENT_DATE
    UNION SELECT "DHINV#" FROM lgdat.oih WHERE DHPOST <> 'Y'
)
SELECT
  "FLINV#" AS "flinv#",
  "FLLIN#" AS "fllin#",
  "FLDIS#" AS "fldis#",
  RTRIM(FLDISC) AS fldisc,
  RTRIM(FLDDES) AS flddes,
  RTRIM(FLDRCR) AS fldrcr,
  RTRIM(FLBANT) AS flbant,
  FLPERC AS flperc,
  FLDAMT AS fldamt,
  RTRIM(FLAPER) AS flaper,
  FLDEXT AS fldext,
  RTRIM(FLAUNT) AS flaunt,
  RTRIM(FLRTEF) AS flrtef,
  FLRNDD AS flrndd
FROM LGDAT.OIS
WHERE "FLINV#" IN (SELECT "DHINV#" FROM changed)
