Skip to main content

Getting the Data

The data required for this was the forecast data of both my forecasts and IBP forecasts from earlier, and the current inventory data which was fetched with the SQL query:

SELECT
m1.material_id as SKU,
mm.<brand name> as brand,
m1.plant_id,
CAST(SUM(m1.<inventory>) AS INTEGER) as inventory
FROM
<inventory table> m1
JOIN <plant table> mp on m1.plant_id = mp.plant_id
JOIN <material table> mm on m1.material_id = mm.material_id
JOIN <product line table> mpld on mm.<product line> = mpld.<product line>
LEFT JOIN (
SELECT
material_id,
batch_cid,
<expiration date>
FROM
<plant inventory table>
GROUP BY
material_id,
batch_cid,
<expiration_date>
) m2 ON m1.material_id = m2.material_id
AND m1.batch_cid = m2.batch_cid
WHERE
m1.source_system_cde = <SAP>
AND NOT(<plant> IS <obsolete>)
AND m1.<inventory> IS NOT NULL
AND mpld.product_line IN <relevant product lines>
AND mp.country = 'IN'
AND mm.record_type = 'CP'
AND mm.<product> != <obsolete>
GROUP BY
1,
2,
3