SELECT
  RTRIM(ASCOMP) AS ascomp,
  RTRIM(ASCUST) AS ascust,
  RTRIM("ASINV#") AS "asinv#",
  RTRIM(ASITYP) AS asityp,
  CASE WHEN ASIDAT IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE ASIDAT END AS asidat,
  CASE WHEN ASTDAT IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE ASTDAT END AS astdat,
  CASE WHEN ASDDAT IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE ASDDAT END AS asddat,
  RTRIM(ASTRTP) AS astrtp,
  ASINAM AS asinam,
  ASDIS AS asdis,
  ASADJ AS asadj,
  ASPAY AS aspay,
  ASDUAM AS asduam,
  ASDWO AS asdwo,
  ASDED AS asded,
  ASHLD AS ashld,
  CASE WHEN ASHDAT IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE ASHDAT END AS ashdat,
  CASE WHEN ASPDAT IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE ASPDAT END AS aspdat,
  RTRIM("ASCHQ#") AS "aschq#",
  ASCPAM AS ascpam,
  RTRIM(ASCURA) AS ascura,
  ASEXRT AS asexrt,
  ASFSYR AS asfsyr,
  ASFSPR AS asfspr,
  RTRIM(ASBCHQ) AS asbchq,
  RTRIM(ASTRDS) AS astrds,
  RTRIM("ASCOM#") AS "ascom#",
  RTRIM(ASARAC) AS asarac,
  RTRIM(ASSLMN) AS asslmn,
  RTRIM(ASTERR) AS asterr,
  ASBTCH AS asbtch,
  ASBTAM AS asbtam,
  ASTPST AS astpst,
  ASTFST AS astfst,
  ASTCST AS astcst,
  ASODIS AS asodis,
  RTRIM(ASORIN) AS asorin,
  RTRIM("ASBOL#") AS "asbol#",
  ASINVN AS asinvn,
  ASBOLN AS asboln,
  ASHQCO AS ashqco,
  ASHQBT AS ashqbt,
  RTRIM(ASFUT1) AS asfut1,
  RTRIM(ASFUT2) AS asfut2,
  RTRIM(ASFUT3) AS asfut3,
  RTRIM(ASFUT4) AS asfut4,
  RTRIM(ASFUT5) AS asfut5,
  ASFUT6 AS asfut6,
  RTRIM(ASFLG1) AS asflg1,
  RTRIM(ASFLG2) AS asflg2,
  RTRIM(ASFLG3) AS asflg3,
  RTRIM(ASFLG4) AS asflg4,
  RTRIM(ASFLG5) AS asflg5,
  ASWTCN AS aswtcn,
  ASWTCD AS aswtcd,
  RTRIM(ASCPON) AS ascpon,
  RTRIM(ASCRTY) AS ascrty,
  ASSTTM AS assttm,
  CASE WHEN ASSTTD IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE ASSTTD END AS assttd,
  ASTRMP AS astrmp,
  RTRIM(ASSREF) AS assref,
  RTRIM(ASPJNM) AS aspjnm,
  ASDSPR AS asdspr,
  RTRIM(ASFUT7) AS asfut7,
  RTRIM(ASFUT8) AS asfut8,
  RTRIM(ASFUT9) AS asfut9,
  RTRIM(ASFUT10) AS asfut10,
  RTRIM(ASFUT11) AS asfut11,
  RRN(T) AS src_rrn
FROM LGDAT.AROHT T
WHERE RRN(T) > {aroht_rrn}
