Infor XA IBM i SQL Services Health Query Generator
This generator writes five Db2 for i queries that use IBM i SQL services to check the health of an Infor XA system: largest files, reorganise candidates, inactive users, active XA jobs and history file sizes. Fill in your library and thresholds, then paste the SQL into Run SQL Scripts in IBM i Access Client Solutions.
Fill in
Upper case, as stored in the catalog
Leave blank for all profiles
Leave blank to list jobs in all subsystems
1. Largest files in AMFLIB
-- Largest physical files in the XA library by data space size
SELECT TABLE_NAME,
NUMBER_ROWS,
NUMBER_DELETED_ROWS,
DEC(DATA_SIZE / 1048576.0, 15, 1) AS DATA_MB,
LAST_CHANGE_TIMESTAMP
FROM QSYS2.SYSTABLESTAT
WHERE TABLE_SCHEMA = 'AMFLIB'
ORDER BY DATA_SIZE DESC
FETCH FIRST 25 ROWS ONLY;2. RGZPFM candidates (deleted rows above 20%)
-- Files where deleted records exceed the threshold, with the CL command to run
-- Run RGZPFM only when the file is not in use (XA users and batch stopped, backup taken)
SELECT TABLE_NAME,
NUMBER_ROWS,
NUMBER_DELETED_ROWS,
DEC(NUMBER_DELETED_ROWS * 100.0
/ NULLIF(NUMBER_ROWS + NUMBER_DELETED_ROWS, 0), 7, 2) AS DELETED_PCT,
DEC(DATA_SIZE / 1048576.0, 15, 1) AS DATA_MB,
'RGZPFM FILE(' CONCAT TRIM(TABLE_SCHEMA) CONCAT '/'
CONCAT TRIM(SYSTEM_TABLE_NAME) CONCAT ')' AS RGZ_COMMAND
FROM QSYS2.SYSTABLESTAT
WHERE TABLE_SCHEMA = 'AMFLIB'
AND NUMBER_DELETED_ROWS * 100.0
/ NULLIF(NUMBER_ROWS + NUMBER_DELETED_ROWS, 0) > 20
ORDER BY NUMBER_DELETED_ROWS DESC;
-- Example CL for one file:
-- RGZPFM FILE(AMFLIB/IMHIST)3. IBM i user list report: profiles not signed on in 90 days
-- IBM i profiles (prefix '[User profile prefix filter]') with no sign-on in the last 90 days
SELECT AUTHORIZATION_NAME,
STATUS,
PREVIOUS_SIGNON,
TEXT_DESCRIPTION,
GROUP_PROFILE_NAME
FROM QSYS2.USER_INFO
WHERE AUTHORIZATION_NAME LIKE '[User profile prefix filter]%'
AND (PREVIOUS_SIGNON IS NULL
OR PREVIOUS_SIGNON < CURRENT TIMESTAMP - 90 DAYS)
ORDER BY PREVIOUS_SIGNON;4. Active jobs in the XA subsystem
-- Active jobs, highest CPU first (CPU_TIME is in milliseconds)
-- An empty SUBSYSTEM_LIST_FILTER returns jobs in all subsystems
SELECT JOB_NAME,
SUBSYSTEM,
AUTHORIZATION_NAME,
JOB_STATUS,
CPU_TIME,
ELAPSED_CPU_PERCENTAGE
FROM TABLE(QSYS2.ACTIVE_JOB_INFO(
SUBSYSTEM_LIST_FILTER => '[XA subsystem name]')) X
ORDER BY CPU_TIME DESC;5. XA history file sizes
-- Row counts and size of the main XA history files
SELECT TABLE_NAME,
NUMBER_ROWS,
NUMBER_DELETED_ROWS,
DEC(DATA_SIZE / 1048576.0, 15, 1) AS DATA_MB,
LAST_CHANGE_TIMESTAMP
FROM QSYS2.SYSTABLESTAT
WHERE TABLE_SCHEMA = 'AMFLIB'
AND TABLE_NAME IN ('IMHIST', 'MOHMST', 'MOHDTA', 'MOHRTG', 'MOHTRN',
'POHSTM', 'POHISTI', 'MBFBREP', 'MBDRREP')
ORDER BY DATA_SIZE DESC;Needs IBM i 7.2 or later with a current Db2 for i group PTF (SF99xxx) so that QSYS2.SYSTABLESTAT, QSYS2.USER_INFO and QSYS2.ACTIVE_JOB_INFO are present; check column names in IBM Docs for your release. QSYS2.USER_INFO can be slow on systems with many profiles. ELAPSED_CPU_PERCENTAGE is measured from a baseline, so the first run in a connection is not meaningful; run the query twice. Query 3 reports IBM i profiles; XA application users are also defined in AMFLIB/MZF0REP and need their own review.
Get your XA health results reviewed
Send us the output of these five queries and we will point out the files to purge or reorganise first and the profiles worth reviewing.
Optional. The tool and every export work without this. No spam.
How to use it
Set the data library to the XA environment you want to check, normally AMFLIB, in upper case. Choose how many files to list, the deleted-row percentage above which a file is worth reorganising, and the number of days without sign-on that makes a profile inactive. Enter the subsystem your XA interactive and batch jobs run in, or leave it blank to see every active job. Run the queries from Run SQL Scripts with a profile that has read access to the catalog; query 3 needs authority to see other user profiles, which in practice means a security administrator profile. Save the output with the date so you can compare month to month.
What the queries read
QSYS2.SYSTABLESTAT returns one row per table or physical file with NUMBER_ROWS, NUMBER_DELETED_ROWS, DATA_SIZE in bytes and LAST_CHANGE_TIMESTAMP. Deleted records still take space until the file is reorganised with RGZPFM or the space is reused because the file has REUSEDLT(*YES). QSYS2.USER_INFO returns one row per user profile with STATUS, PREVIOUS_SIGNON and GROUP_PROFILE_NAME. QSYS2.ACTIVE_JOB_INFO is a table function; SUBSYSTEM_LIST_FILTER takes up to 25 subsystem names separated by commas, and CPU_TIME is reported in milliseconds.
- Deleted percent = deleted rows x 100 / (rows + deleted rows)
- DATA_MB = DATA_SIZE / 1,048,576
- Profiles that never signed on have a null PREVIOUS_SIGNON and are included
Reading the results
In most XA systems the top of query 1 is dominated by history: IMHIST, MOHTRN and the CO history files. A history file with a high deleted percentage usually means a purge has run but no reorganise followed, so the disk space has not come back. Schedule RGZPFM for those files in a maintenance window with XA users and batch stopped, and take a backup first. In query 3, check each inactive profile against the XA user file before disabling it: a service profile used by an integration can look inactive if it only connects through ODBC with a different profile. Query 4 shows which jobs are using CPU right now.
Version notes and gotchas
SQL services are delivered through the Db2 for i group PTF, so a system that is behind on PTFs may be missing a column or the whole view. If a column is rejected, check IBM Docs for your release and drop it. File names in query 5 come from the XA 9.2.0 definition list; if your site has purged or renamed history, adjust the list. This tool reports IBM i profiles only. XA has its own user file (MZF0REP) and security file (MZGUCPP), and a full user review covers both. For a single-file extract of business data use the separate XA SQL extract generator.
Frequently Asked Questions
How do I get a user list report for Infor XA?
For IBM i profiles, query QSYS2.USER_INFO as in block 3: it returns each profile with status, previous sign-on, description and group profile. XA application users are also held in AMFLIB/MZF0REP, so compare the two lists. Profiles that exist in only one place are the first ones to review.
How do I find which XA files need RGZPFM?
Query QSYS2.SYSTABLESTAT for the XA library and compare NUMBER_DELETED_ROWS with NUMBER_ROWS. Files where deleted rows are more than about 20 percent of the total are worth reorganising. Block 2 builds the RGZPFM command for each one. Run it only with the file not in use, after a backup.
Which IBM i release do these queries need?
IBM i 7.2 or later with a current Db2 for i group PTF. SYSTABLESTAT has existed for a long time, while USER_INFO and ACTIVE_JOB_INFO have gained columns and parameters over several PTF levels. If a query fails with an unknown column, apply the latest group PTF or remove that column.
Is it safe to run these queries during the working day?
Yes, they only read catalog and system information, but QSYS2.USER_INFO can take a while on systems with thousands of profiles and ACTIVE_JOB_INFO adds a short burst of work. Run them from a single session, not from a dashboard that refreshes every few seconds.
If you want these checks run on a schedule and explained in plain English by an assistant on your own IBM i network, we can set that up.
Related Tools
Infor XA History File Growth and Purge Retention Simulator
Estimate how big your XA inventory, MO and CO history files are today, how big they settle at for a chosen retention period, and how much disk a purge plus RGZPFM gives back.
Other ERPsInfor XA (MAPICS) AMFLIB Database File Reference
The core Infor XA 9.x/10 physical files in AMFLIB with application area, what one record holds and the usual join partner, so you can find the right table before you write a query.
Developer ToolsInfor XA DB2 for i SQL Extract Generator
Fill in library, file, columns and filter to get a limited SELECT, a row count check and a CPYTOIMPF command to produce a CSV.
Compliance & ContractsInfor XA (MAPICS) User Access Review Worksheet
Review each user profile, last sign-on, role and conflicting duties, with a days inactive figure and review decision.
Other ERPsIBM i Commands for Infor XA Administrators Reference
A lookup of common IBM i CL commands for jobs, output, libraries, objects, data and backups, with what each is for.
More Developer Tools tools
See all- Infor XA Integration Options Reference (System-Link, IDF, Triggers, ION)
- 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
Keep exploring
Free tools
- Infor XA DB2 for i SQL Extract GeneratorFill in library, file, columns and filter to get a limited SELECT, a row count check and a CPYTOIMPF command to produce a CSV.
- Db2 for i SQL Services Query GeneratorFill in a library, object type and subsystem and get a set of QSYS2 SQL services queries for sizes, row counts, jobs, locks and user profiles.
- Infor XA Private AI Layer Blueprint GeneratorFill in your Infor XA version, database, hosting and use cases and get a shareable architecture plan for a private AI layer.
ERP fixes and how-tos
- How to add a private AI layer to Infor XA on-premReference architecture to add AI to Infor XA on-prem: read-only data path, retrieval, permissions, local GPUs, write-back control and rollout.
- Infor XA REST API: expose XA through IBM i Integrated Web Services or IONHow to expose Infor XA (MAPICS) data and functions as REST on IBM i using Integrated Web Services or ION, with an example call and the safety rules for writes.
- How to Add AI to MAPICS and Infor XA on IBM i Without Leaving Your NetworkHow to give MAPICS and Infor XA on IBM i a private AI assistant: DB2 for i access, journal-based change capture, local GPU model, authority mapping and rollout.
Guides
- Setting Up System Health Monitoring for SyteLineSet up comprehensive system health monitoring for Infor SyteLine covering SQL Server, IIS, application server, and business process KPIs with alerting thresholds.
- MAPICS to SyteLine Migration Planning GuidePlan your MAPICS XA or MAPICS AS/400 migration to Infor SyteLine or CloudSuite Industrial. Data mapping, timeline, and risk mitigation strategies.
Integrations
- How to add AI agents to Infor XA on IBM iHow to add AI agents to Infor XA on IBM i: a tool layer over Db2 for i and RPG programs, approval gates, on-prem models, and realistic expedite and exception flows.
- How to add an AI chatbot to Infor XAHow to add an AI chatbot to Infor XA on IBM i: grounded answers from Db2 for i, internal and customer portals, role-based access, and a fully on-prem option.