BPCS and Infor LX SQL Query Generator for Reports on AS400
This generator writes Db2 for i SQL for the BPCS and Infor LX reports asked for most often: open order lines, on-hand by location, inventory history by transaction type and a volume check on ITH. Every field name is an input, because names vary by release and site, and the last block shows you how to confirm them.
Fill in
Library holding the BPCS or LX data files
YYYYMMDD or CYYMMDD depending on release
1. Open customer order lines (ECH, ECL, IIM)
-- Open customer order lines with item description.
SELECT H.HORD AS ORDER_NO,
L.LLINE AS LINE_NO,
L.LPROD AS ITEM,
I.IDESC AS ITEM_DESC,
L.LQORD AS QTY_ORDERED,
L.LQSHP AS QTY_SHIPPED,
L.LQORD - L.LQSHP AS QTY_OPEN
FROM BPCSF.ECH H
JOIN BPCSF.ECL L
ON L.LORD = H.HORD
LEFT JOIN BPCSF.IIM I
ON I.IPROD = L.LPROD
WHERE L.LQORD - L.LQSHP > 0
ORDER BY H.HORD, L.LLINE
FETCH FIRST 100 ROWS ONLY;2. On-hand by location from ILI (verify formula)
-- VERIFY FORMULA: opening balance + receipts + adjustments - issues.
-- Confirm the balance fields and their sign convention on your release before using this for counts.
SELECT B.LPROD AS ITEM,
B.LWHS AS WAREHOUSE,
B.LLOC AS LOCATION,
B.LOPB + B.LRCT + B.LADJ - B.LISS AS ON_HAND
FROM BPCSF.ILI B
WHERE TRIM(B.LWHS) = '1'
AND (TRIM('[Item (blank for all)]') = '' OR B.LPROD = '[Item (blank for all)]')
ORDER BY B.LPROD, B.LLOC
FETCH FIRST 100 ROWS ONLY;3. ITH transactions since a date, by transaction type
-- Movement summary by transaction type for one item (or all items if blank).
SELECT T.TTYPE AS TRAN_TYPE,
COUNT(*) AS TRAN_COUNT,
SUM(T.TQTY) AS TOTAL_QTY
FROM BPCSF.ITH T
WHERE T.TTDTE >= 20250101
AND TRIM(T.TWHS) = '1'
AND (TRIM('[Item (blank for all)]') = '' OR T.TPROD = '[Item (blank for all)]')
GROUP BY T.TTYPE
ORDER BY T.TTYPE;4. ITH volume check by year (run before any big extract)
-- ITH is usually the largest file in BPCS. Check volume first.
-- For YYYYMMDD dates this returns the year; for CYYMMDD it returns CYY (e.g. 125 = 2025).
SELECT INTEGER(T.TTDTE / 10000) AS TRAN_YEAR,
COUNT(*) AS ROW_COUNT
FROM BPCSF.ITH T
GROUP BY INTEGER(T.TTDTE / 10000)
ORDER BY TRAN_YEAR DESC
FETCH FIRST 30 ROWS ONLY;
-- If this is slow, check for an existing logical file keyed on item and date (DSPDBR FILE(BPCSF/ITH))
-- and ask your administrator before creating a new index on a production library.5. Confirm field names before you run anything
-- CL command (IBM i command line): list fields of ECL to an outfile
DSPFFD FILE(BPCSF/ECL) OUTPUT(*OUTFILE) OUTFILE(QTEMP/ECLFLD)
-- SQL alternative using the catalog
SELECT COLUMN_NAME, COLUMN_TEXT, DATA_TYPE, LENGTH, NUMERIC_SCALE
FROM QSYS2.SYSCOLUMNS
WHERE TABLE_SCHEMA = 'BPCSF'
AND TABLE_NAME IN ('ECH', 'ECL', 'IIM', 'ILI', 'ITH')
ORDER BY TABLE_NAME, ORDINAL_POSITION;File names (ECH, ECL, IIM, ILI, ITH) are standard BPCS and LX names. The default field names are those commonly used on BPCS 6.x but could not be confirmed against a published reference for every release, so treat them as placeholders until you have checked each one with block 5. Field names differ between BPCS 4.05, 6.x and LX 8.x, and date fields are numeric YYYYMMDD or CYYMMDD depending on release. Warehouse and item are compared as text after TRIM. Run against a copy or off-peak, never in a tight loop on production.
Get these queries checked against your release
Send us your DSPFFD output for ECH, ECL, ILI and ITH, and we will return the queries with your real field names and date format.
Optional. The tool and every export work without this. No spam.
How to use it
First run block 5 against your data library. It lists the real columns of ECH, ECL, IIM, ILI and ITH with their text descriptions. Compare them to the defaults and correct any field that differs, for example if your release stores the order number under another name. Then set the warehouse, an optional item and the from-date in the format your release stores. Copy a block into ACS Run SQL Scripts, STRSQL or your query tool and run it. Each block uses SQL naming (LIBRARY.FILE). If your tool uses system naming, change the period to a slash.
- Block 1: open order lines from ECH and ECL with item description
- Block 2: on-hand by location from ILI
- Block 3: ITH movement summary by transaction type
- Block 4: ITH row count by year before a large extract
- Block 5: field list via DSPFFD or QSYS2.SYSCOLUMNS
The logic behind each query
An open order line is one where ordered quantity minus shipped quantity is greater than zero. Block 1 joins header to lines on the order number, and IIM is a left join so lines are still listed when an item record is missing. Block 2 assumes ILI keeps an opening balance plus period receipts, adjustments and issues, which gives on-hand as opening + receipts + adjustments - issues. That is why it is labelled verify formula: confirm the fields and signs on your release, then check a few items against the on-screen inquiry. Block 3 groups ITH by transaction type so you can see receipts, issues and adjustments at a glance.
Worked example
A planner wants open orders and the on-hand position for one item in warehouse 1. Set item to the part number, leave the from-date at 20250101 and the limit at 100. Block 1 returns each open line with its open quantity. Block 2 returns one row per location and lot with a computed on-hand figure. Block 3 then shows what moved since January: if issues are far higher than receipts while open orders are growing, the item needs a buyer's attention. Before you share the numbers, compare the block 2 total for the item with the warehouse balance on the standard inventory inquiry screen.
Version differences and gotchas
BPCS 4.05, 6.x and LX 8.x share file names but not always field names or lengths. Many sites also add custom fields or run modified programs. Dates are numeric. Older releases often use CYYMMDD, where 1250101 means 1 January 2025, so a YYYYMMDD from-date will silently return nothing or everything. Warehouse fields are usually short character fields, so compare them as text. Block 1 does not filter on line status, so add your site's status field if cancelled lines carry open quantities. Finally, never run block 3 or 4 without filters at month-end, when ITH is busiest.
Frequently Asked Questions
How do I write a BPCS open order report in SQL?
Join ECH to ECL on the order number field and keep lines where ordered quantity minus shipped quantity is greater than zero. Left join IIM for the item description, and filter on line status if your site keeps cancelled lines. Confirm every field name with DSPFFD or QSYS2.SYSCOLUMNS before running, because names vary by release.
Can I query BPCS on AS400 with normal SQL?
Yes. BPCS and Infor LX files are Db2 for i physical files, so you can read them with SQL from ACS Run SQL Scripts, STRSQL, ODBC or JDBC clients. Use read-only access, the correct library, and row limits on large files such as ITH.
What date format do BPCS files use?
Dates are stored as numbers, not SQL DATE values. Depending on release and file, the format is YYYYMMDD or CYYMMDD, where C is the century digit. Check a few sample rows before filtering, and convert explicitly if you need real dates in a report.
Is the ILI on-hand formula official?
No. Opening balance plus receipts plus adjustments minus issues is the common practitioner approach to reading ILI. It is labelled verify formula because field names and signs can differ. Check the result against the standard inventory inquiry for several items before relying on it.
If you would rather your team asked LX or BPCS these questions in plain English, running on your own IBM i data with every query shown, we can set that up.
Related Tools
Infor LX / BPCS Core Database File Reference
The core BPCS and Infor LX physical files on IBM i, with what one record represents, the related files and the size warnings that matter when you query them.
Other ERPsInfor LX MRP Run Window Calculator (Regeneration vs Net Change)
Take one measured MRP run, scale it to more items or deeper bills, and see whether full regeneration and net change still fit the overnight window.
Other ERPsInfor LX / BPCS IBM i OS Release Upgrade Checklist
A step-by-step checklist for upgrading the IBM i operating system under Infor LX 8.x or BPCS 6.x, from compatibility checks to sign-off.
More Developer Tools tools
See all- SAP Sales Order ABAP SELECT Generator (VBAK, VBAP, VBFA)
- SAP Sales Order Create BAPI ABAP Generator (BAPI_SALESORDER_CREATEFROMDAT2)
- SAP ABAP Open Items SELECT Generator
- SAP ACDOCA SQL Query Generator
- SAP QM Inspection Lot ABAP SELECT Generator
- SAP Quality Notification Pareto SQL Query Generator
- SAP QM Usage Decision BAPI Skeleton
- ABAP Custom Exception Class Generator
- ABAP Unit Test Class Generator
Keep exploring
Free tools
- Infor LX / BPCS Private AI Layer Blueprint GeneratorFill in your Infor LX / BPCS version, database, hosting and use cases and get a shareable architecture plan for a private AI layer.
- Infor LX / BPCS AI Assistant Sizing and Value CalculatorSize the GPUs and estimate the monthly value and payback of an on-prem AI assistant for Infor LX / BPCS users.
- Infor LX / BPCS Core Database File ReferenceThe core BPCS and Infor LX physical files on IBM i, with what one record represents, the related files and the size warnings that matter when you query them.