IBM i (AS/400) DB2 SQL Data Extraction Script Generator
Anyone who has had to move data off an IBM i knows the first problems: what columns does the file have, how many rows are there, and what does that Julian date mean? This generator produces the DB2 for i SQL for those first steps, with JD Edwards style Julian date handling built in.
Fill in
The library that holds the physical file.
For example a JD Edwards World file.
A date stored as a CYYDDD number, century offset then day of year.
124001 is 1 January 2024. Add 100 per century digit: 1 means 20xx.
124366 covers the full leap year 2024.
1. Confirm the file and list its columns
SELECT COLUMN_NAME, DATA_TYPE, LENGTH, NUMERIC_SCALE, COLUMN_TEXT FROM QSYS2.SYSCOLUMNS WHERE TABLE_SCHEMA = 'PRODDTA' AND TABLE_NAME = 'F0911' ORDER BY ORDINAL_POSITION;
2. Count rows
SELECT COUNT(*) AS TOTAL_ROWS FROM PRODDTA.F0911;
3. Count rows in the date range
SELECT COUNT(*) AS ROWS_IN_RANGE FROM PRODDTA.F0911 WHERE GLDGJ BETWEEN 124001 AND 124366;
4. Test extract with a converted date
SELECT GLDOC, GLDCT, GLDGJ, GLAID, GLAA, GLEXA,
CASE WHEN GLDGJ > 0
THEN DATE(CHAR(1900000 + GLDGJ))
ELSE NULL END AS CALENDAR_DATE
FROM PRODDTA.F0911
WHERE GLDGJ BETWEEN 124001 AND 124366
ORDER BY GLDGJ
FETCH FIRST 1000 ROWS ONLY;5. Reconcile row counts by month (optional)
SELECT MONTH(DATE(CHAR(1900000 + GLDGJ))) AS MONTH_NO,
COUNT(*) AS ROW_COUNT
FROM PRODDTA.F0911
WHERE GLDGJ BETWEEN 124001 AND 124366
GROUP BY MONTH(DATE(CHAR(1900000 + GLDGJ)))
ORDER BY MONTH_NO;Run in Run SQL Scripts (ACS), STRSQL or a JDBC client. Verify library, file and column names on your release, as World file layouts differ between versions and local modifications. JD Edwards money fields are usually stored without a decimal point, so check the data dictionary for the implied decimals before using amounts. Always test with a row limit and use a read-only user.
Optional help with a full data extraction
If you need to extract and reconcile years of IBM i data, we can discuss a controlled, read-only approach.
Optional. The tool and every export work without this. No spam.
How to use the generator
Enter the library and file name, the Julian date column, the date range and the columns you want. The tool fills five scripts: a column list from QSYS2.SYSCOLUMNS, a total row count, a count for the date range, a test extract with a calendar date added, and a monthly count for reconciliation. Copy them into Run SQL Scripts in IBM i Access Client Solutions, or into any JDBC client. Run the count queries first so you know the size before you extract.
How the Julian date works
JD Edwards stores many dates as a number in CYYDDD format. C is a century offset from 1900, YY is the year and DDD is the day of the year. So 124001 is the first day of 2024 and 099365 is the last day of 1999. To convert, add 1900000 to get a seven digit year plus day number, such as 2024001, which DB2 for i accepts as a Julian date string. The script guards against zero so that empty dates do not raise errors.
- C = 0 for 19xx, 1 for 20xx
- 124001 = 2024, day 1
- A value of 0 means no date
Common mistakes
People most often forget the implied decimals on amount fields, so a value of 12550 may be 125.50. They also run a heavy extract during the batch window, or against a production library without a row limit. Another mistake is exporting without reconciling: compare row counts and control totals by period against the source before and after the move. Use the monthly count script for that. For very large files, extract in date slices and keep the same selection rules for each run.
Frequently Asked Questions
How do I convert a JDE Julian date in SQL?
Add 1900000 to the CYYDDD value and cast the result to a character string, then pass it to DATE. For example, DATE(CHAR(1900000 + GLDGJ)). Guard against zero values, which represent blank dates.
Where do I run these queries?
In IBM i Access Client Solutions Run SQL Scripts, in STRSQL on a 5250 session, or through a JDBC or ODBC client. Use a user with read-only authority to the data library for safety.
Why are my amounts wrong by a factor of 100?
JD Edwards stores amounts as integers with implied decimals, often two. Check the file definition or the data dictionary for the decimal places and divide accordingly in your extract.
Can I export the result to CSV?
Yes. Run SQL Scripts can save results to a file, and many tools can write CSV from a JDBC connection. For large volumes, use a scripted export in slices and verify counts against the source.
If you need an extraction pipeline for a full migration, with reconciliation and a read-only approach, Netray can discuss it. These scripts work without contact.
Related Tools
JD Edwards World Key File Reference Table
A searchable lookup of widely used JD Edwards World files with the module, purpose and key field prefix, useful for queries, reports and migration mapping.
ERP Migration & SelectionJDE World to E1 Migration Readiness Assessment
Ten questions that show how complicated a JD Edwards World to E1 (or other ERP) move will be, based on customization, data, interfaces and people.
OracleJDE World DREAM Writer Version Documentation Template
Document a DREAM Writer program version, its processing options, data selection, sequencing and output in a form that survives staff changes and migration projects.
ERP OperationsIBM i (AS/400) System Health Check Checklist
A practical weekly and monthly health check for IBM i partitions running ERP such as JD Edwards World, covering storage, jobs, patches, security and recovery.
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