IBM i: The SQL Way

Practical IBM i tasks, investigated through SQL.

IBM i native commands remain essential. SQL services give us another way to query the platform, sort the results, isolate outliers, build reports, and turn one-time troubleshooting into reusable automation.

The goal is not to replace native IBM i commands.

The goal is to understand when SQL can help us reach the answer faster and make that knowledge reusable.

SQL Way #15 min read

Find Active IBM i Jobs Consuming the Most Temporary Storage

Use QSYS2.ACTIVE_JOB_INFO to find and rank active IBM i jobs by temporary-storage usage, then decide where the investigation should continue.

Native optionWRKACTJOB SEQ(*TMPSTG)
IBM iSQLDb2 for iACTIVE_JOB_INFOTemporary Storage
SQL Way #27 min read

Find IBM i Object Locks and the Jobs Holding Them

Use QSYS2.OBJECT_LOCK_INFO to identify jobs holding or waiting for IBM i object locks, inspect the lock state, and continue the investigation safely.

Native optionWRKOBJLCK OBJ(MYLIB/MYFILE) OBJTYPE(*FILE)
IBM iSQLDb2 for iOBJECT_LOCK_INFOObject Locks
SQL Way #35 min read

Find and Analyze IBM i SQL Errors with SQL_ERROR_LOG

Use the SQL Error Logging Facility and QSYS2.SQL_ERROR_LOG to capture, group, and investigate recurring Db2 for i errors with the failing statement, program, job, and call-stack context.

Native optionACS Run SQL Scripts > SQL Error Logging Facility
IBM iDb2 for iSQLSQL_ERROR_LOGSELF
SQL Way #44 min read

Validate an IBM i CL Command Without Running It

Use SYSTOOLS.CHECK_COMMAND_SYNTAX to verify the syntax of an IBM i CL command from SQL before storing, scheduling, or conditionally executing it.

Native optionQCMDCHK — Check Command Syntax API
IBM iSQLCLCHECK_COMMAND_SYNTAXQCMDCHK
SQL Way #53 min read

Query IBM i CVEs with SQL

Use SYSTOOLS.CVE_INFO to retrieve current IBM security bulletins for an IBM i release, filter critical and recent CVEs, and build a repeatable vulnerability-review process.

Native optionIBM Navigator for i > Security > CVE Information
IBM iSecuritySQLCVE_INFOCVE
SQL Way #64 min read

Check IBM i Group PTF Currency with a Local XML Feed

Use SYSTOOLS.GROUP_PTF_CURRENCY_LOCAL to compare installed IBM i Group PTF levels with IBM service data from a controlled local XML file.

Native optionWRKPTFGRP — Work with PTF Groups
IBM iPTFSQLGROUP_PTF_CURRENCY_LOCALSystem Administration
SQL Way #74 min read

URL-Encode API Parameters with Db2 for i

Use the Db2 for i URL_ENCODE scalar function to safely encode query-string values such as spaces, ampersands, plus signs, and non-ASCII text before calling an HTTP API.

Native optionApplication URL-encoding library
IBM iDb2 for iSQLURL_ENCODEHTTP
SQL Way #84 min read

Convert an Internal IBM i System Timestamp to an SQL Timestamp

Use FROM_SYSTEM_TIMESTAMP to convert an eight-byte internal IBM i system timestamp into a readable SQL TIMESTAMP value.

Native optionInterpret the eight-byte internal system timestamp in application code
IBM iDb2 for iSQLFROM_SYSTEM_TIMESTAMPTimestamp
SQL Way #93 min read

Convert an SQL Timestamp to an Internal IBM i System Timestamp

Use TO_SYSTEM_TIMESTAMP to convert an SQL date or timestamp into the eight-byte internal timestamp format used by selected IBM i interfaces.

Native optionBuild the eight-byte internal timestamp in application code
IBM iDb2 for iSQLTO_SYSTEM_TIMESTAMPTimestamp
SQL Way #103 min read

Parse a Qualified IBM i Job Name with SQL

Use SYSTOOLS.JOB_NAME, JOB_USER, JOB_NUMBER, and JOB_NAME_DETAILS to split a qualified IBM i job name into reusable SQL columns.

Native optionParse job-number/job-user/job-name in application code
IBM iSQLJOB_NAMEJOB_USERJOB_NUMBER
SQL Way #114 min read

Create a Data Journal Reader for an IBM i Table

Use QSYS2.CREATE_DATA_JOURNAL_READER to generate a table function that returns journaled record images as individual columns instead of an unparsed entry-data value.

Native optionDSPJRN or QSYS2.DISPLAY_JOURNAL
IBM iSQLJournalingCREATE_DATA_JOURNAL_READERDISPLAY_JOURNAL
SQL Way #124 min read

Monitor IBM i Geographic Mirroring with SQL

Use QSYS2.GEOGRAPHIC_MIRRORING_INFO to review IASP mirror roles, copy state, synchronization progress, out-of-sync data, tracking space, and replication transport.

Native optionPowerHA and geographic mirroring management interfaces
IBM iSQLPowerHAGeographic MirroringIASP
SQL Way #133 min read

Find All IBM i File Overrides in the Current Job

Use SYSTOOLS.OVERRIDE_INFO_ALL to list every database, display, and printer file override active at the current call level of an IBM i job.

Native optionDSPOVR FILE(*ALL)
IBM iSQLOVERRIDE_INFO_ALLFile OverridesDSPOVR
SQL Way #143 min read

View IBM i Service Tools Server Configuration Entries with SQL

Use QSYS2.SERVICE_TOOLS_SERVER_CONFIGURATION_ENTRY_INFO to review stored partition-specific STS LAN configuration entries used during IPL recovery scenarios.

Native optionSTRSST or DST — Configure Service Tools Server LAN Adapter
IBM iSQLService Tools ServerSERVICE_TOOLS_SERVER_CONFIGURATION_ENTRY_INFORemote Key Agent
SQL Way #153 min read

Add an IBM i Service Tools Server Configuration Entry with SQL

Use QSYS2.ADD_SERVICE_TOOLS_SERVER_CONFIGURATION_ENTRY to store a partition-specific STS LAN configuration for alternate-hardware IPL and Remote Key Agent recovery scenarios.

Native optionSTRSST or DST — Configure Service Tools Server LAN Adapter
IBM iSQLADD_SERVICE_TOOLS_SERVER_CONFIGURATION_ENTRYService Tools ServerRemote Key Agent
SQL Way #163 min read

Change an IBM i Service Tools Server Configuration Entry with SQL

Use QSYS2.CHANGE_SERVICE_TOOLS_SERVER_CONFIGURATION_ENTRY to update a stored partition-specific STS LAN recovery configuration without changing the currently active server.

Native optionSTRSST or DST — Configure Service Tools Server LAN Adapter
IBM iSQLCHANGE_SERVICE_TOOLS_SERVER_CONFIGURATION_ENTRYService Tools ServerRemote Key Agent
SQL Way #173 min read

Remove an IBM i Service Tools Server Configuration Entry with SQL

Use QSYS2.REMOVE_SERVICE_TOOLS_SERVER_CONFIGURATION_ENTRY to delete an obsolete partition-specific STS LAN recovery configuration by UUID.

Native optionSTRSST or DST — Configure Service Tools Server LAN Adapter
IBM iSQLREMOVE_SERVICE_TOOLS_SERVER_CONFIGURATION_ENTRYService Tools ServerRemote Key Agent
SQL Way #183 min read

Inspect an IBM i External Key Manager Configuration with SQL

Use QSYS2.EKM_INFO to read the type, IAM endpoint, service endpoint, and instance ID stored in an IBM i external key manager description file.

Native optionDSPEKMD — Display EKM Description
IBM iSQLEKM_INFOExternal Key ManagementIBM Key Protect
SQL Way #194 min read

Run IBM i CL Commands from SQL and Control Job-Log Output

Use the QSYS2.QCMDEXC scalar function to execute a CL command from SQL, check its return value, and control whether the command text is written to the job log.

Native optionQCMDEXC API or CALL QSYS2.QCMDEXC
IBM iSQLCLQCMDEXCJob Log
SQL Way #205 min read

Generate Excel, CSV, ODS, and Text Files from IBM i SQL

Use SYSTOOLS.GENERATE_SPREADSHEET to export an IBM i table or SQL query to CSV, XLSX, XLS, ODS, or text files in the IFS, including current update and positioning options.

Native optionACS Data Transfer or CLDownload
IBM iSQLGENERATE_SPREADSHEETExcelCSV
SQL Way #214 min read

Find Db2 for i Tables, Indexes, and Views with SQL

Use QSYS2.SYSTABLES, QSYS2.SYSINDEXES, and QSYS2.SYSVIEWS to identify database objects, map long SQL names to IBM i system names, and troubleshoot object-name collisions.

Native optionWRKOBJ and DSPFD
IBM iDb2 for iSQLSYSTABLESSYSINDEXES
SQL Way #225 min read

Inspect IBM i Objects with QSYS2.OBJECT_STATISTICS

Use QSYS2.OBJECT_STATISTICS to query native IBM i objects, connect long SQL names to system object names, filter by object type, and troubleshoot objects that are difficult to locate through SQL catalogs alone.

Native optionWRKOBJ, DSPOBJD, and DSPFD
IBM iSQLQSYS2OBJECT_STATISTICSObject Management
SQL Way #235 min read

Diagnose Db2 for i Cross-Reference Problems with QSYS.QADBXREF

Use QSYS.QADBXREF to compare Db2 for i long and system file names, identify suspicious cross-reference entries, and use RCLDBXREF safely when catalog metadata becomes inconsistent.

Native optionRCLDBXREF OPTION(*CHECK)
IBM iDb2 for iSQLQADBXREFRCLDBXREF