pipekit/config/modules/ocrs.sql
Paul Trowbridge 890f10cbab Catch order status changes via an open-order hot set
Hold/release rewrites OCRH.DCSTAT and DCHREA without touching any date
column, so no watermark could see it. A full-table row diff of LGDAT.OCRH
vs cms.ocrh (468,823 rows both sides) found 168 drifted rows, 0 missing,
0 extra -- and 159 of them changed with no date moving at all (checked
dcudat/dcodat/dccdat/dcmdat/dchdat/dcxdat/dcsdat/dcmxdt). 155 of the
drifts were DCSTAT, 4 DCHREA.

Every drifted row was still open (DCSTAT in A/N/H/B); none had reached
'C'. Only ~2,044 of 468,823 orders are open, so re-pulling the whole open
set each run is cheap and catches 100% of the observed drift. Applied to
ocrh and to the two modules that read its changed-set, ocri and ocrs.

Result: drift 168 -> 11 rows, DCSTAT 155 -> 3.

No invoice-driven branch: tested against LGDAT.OCRHT (CMS's header change
log, keyed DC3TMSP-leading via logical OCRHTX1) over the live watermark
window -- 1,107 headers changed, 65 missed by the date branches, 0 missed
by dates+open, and a 5- or 30-day invoiced-orders branch added exactly 0.
Closing an order writes dcudat/dccdat, so the date window covers the flip.

Also evaluated LGDAT.OCRIT (the order-line change log) as a replacement
for the open-order branch and rejected it: at the live 8-day watermark it
reports 0 changed orders not already caught, at ~12x the predicate cost,
and its lower row count means it declines to pull 18k lines the open set
would -- safe only if CMS's logging is complete, which is unverified.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-11 11:02:57 -04:00

29 lines
1013 B
SQL

WITH changed AS (
SELECT dcord# FROM lgdat.ocrh WHERE dcudat BETWEEN '{ocrs_wm}' AND CURRENT_DATE
UNION SELECT dcord# FROM lgdat.ocrh WHERE dcodat BETWEEN '{ocrs_wm}' AND CURRENT_DATE
UNION SELECT dcord# FROM lgdat.ocrh WHERE dccdat BETWEEN '{ocrs_wm}' AND CURRENT_DATE
UNION
-- status flips (hold/release) move no date column; ~2k open orders
SELECT dcord# FROM lgdat.ocrh WHERE RTRIM(DCSTAT) <> 'C'
-- No invoice-driven branch on purpose -- see ocrh. Measured against
-- LGDAT.OCRHT: the two predicates above catch 100% of changed headers.
)
SELECT
"FFORD#" AS "fford#",
"FFITM#" AS "ffitm#",
"FFDIS#" AS "ffdis#",
RTRIM(FFDISC) AS ffdisc,
RTRIM(FFDDES) AS ffddes,
RTRIM(FFDRCR) AS ffdrcr,
RTRIM(FFBANT) AS ffbant,
FFPERC AS ffperc,
FFDAMT AS ffdamt,
RTRIM(FFAPER) AS ffaper,
FFDEXT AS ffdext,
RTRIM(FFAUNT) AS ffaunt,
RTRIM(FFRTEF) AS ffrtef,
FFRNDD AS ffrndd,
RTRIM(FFAPLY) AS ffaply
FROM LGDAT.OCRS
WHERE "FFORD#" IN (SELECT dcord# FROM changed)