Ibmi reference

From Crapule421/tiger-team · View interactive version

Ibmi reference is an AI agent skill from the GitHub repository Crapule421/tiger-team. IBM i knowledge base - RPG ILE and free-form, CL, COBOL, Db2 for i, journaling, jobs and subsystems, spool and IFS, security, integration (data queues, MQ, JDBC, REST, CFT), HA, scheduling, CCSID pitfalls, review checklist.

How to use this skill

Skill file

IBM i reference

Baseline: IBM i 7.4 / 7.5 / 7.6. Support status (IBM lifecycle pages, October 2026): 7.3 - standard support ended 30 Sep 2023 (paid service extension to 30 Sep 2028); 7.4 - GA 21 Jun 2019, withdrawn from marketing 30 Apr 2026, standard support ended 30 Sep 2026 (extension offered to 30 Sep 2029); 7.5 - GA 10 May 2022, no end-of-support date announced; 7.6 - GA 18 Apr 2025. A customer still on 7.4 or 7.3 is on paid extension or unsupported: flag it. Many features arrive by Technology Refresh (TR) or PTF group: items flagged "verify against your release" must be checked (command prompt F4, DSPCMD, DSPSYSVAL, IBM Documentation). Never invent CL commands, keywords, system values or API parameters.

1. Object model and source

| Object type | What it is |

|---|---|

| *LIB | Library (flat, no nesting; QSYS is the root) |

| *FILE | Physical file (PF, SQL table), logical file (LF, SQL index/view), source PF, display (DSPF), printer (PRTF), save file (SAVF), DDM file |

| *MODULE, *PGM, *SRVPGM, *BNDDIR | ILE module, program, service program, binding directory |

| *CMD, *MSGF | Command, message file |

| *DTAARA, *DTAQ, *USRSPC | Data area, data queue, user space |

| *JOBD, *JOBQ, *OUTQ, *MSGQ, *SBSD, *CLS | Work management objects |

| *USRPRF, *AUTL | User profile, authorization list |

| *JRN, *JRNRCV | Journal, journal receiver |

Names are 10 characters (SQL long names map to system names). Source lives in source PFs (QRPGLESRC, QCLLESRC, QCBLLESRC, QDDSSRC; member types RPGLE, SQLRPGLE, CLLE, CBLLE, SQLCBLLE, PF, LF, DSPF, PRTF) or in IFS stream files (Git-friendly): the SRCSTMF parameter (exclusive with SRCFILE/SRCMBR) exists on CRTBNDRPG, CRTRPGMOD, CRTSQLRPGI, CRTBNDCL, CRTCLMOD, CRTBNDCBL and CRTCBLMOD (7.3/7.4 and later), but not on the DDS commands (CRTPF, CRTLF, CRTDSPF...), which still compile from a source member.

2. RPG IV / ILE RPG

2.1 Free-form evolution

| Level | Capability |

|---|---|

| V5R1+ | /FREE ... /END-FREE calculations; H/F/D/P specs still fixed |

| 7.1 TR7 / 7.2 (2013) | Free-form declarations: CTL-OPT, DCL-F, DCL-S, DCL-C, DCL-DS, DCL-PR, DCL-PI, DCL-PROC |

| 7.2 and 7.1 with PTFs (2015) | **FREE in column 1: fully free source, no column limits; fixed-form code only through /COPY |

| 7.3 / 7.4 | DATA-INTO (7.4 base, 7.2/7.3 with PTFs, 2018), DATA-GEN (7.4 and 7.3 with PTFs, 2019); later opcodes/BIFs arrive as PTFs listed on the IBM RPG Cafe page - check the compile and runtime PTF levels of your release |

2.2 Batch program skeleton (fictitious)

**FREE
ctl-opt dftactgrp(*no) actgrp(*caller) option(*srcstmt: *nodebugio)
        datfmt(*iso) timfmt(*iso);

dcl-pi *n;
  pProcDate char(8);   // processing date YYYYMMDD from the scheduler
  pRc       char(2);   // '00' = OK, otherwise error (CL wrapper turns it into an escape message)
end-pi;

dcl-s wDate date;
dcl-s wRows int(10);

exec sql set option commit = *chg, naming = *sys, datfmt = *iso, closqlcsr = *endmod;

*inlr = *on;
pRc = '99';
monitor;
  wDate = %date(pProcDate: *iso0);
on-error;
  return;                                   // invalid parameter -> error code
endmon;

exec sql update ECRITURE set STATUT = 'V'
          where DATE_TRT = :wDate and STATUT = 'A';
if %subst(sqlstate: 1: 2) <> '00' and %subst(sqlstate: 1: 2) <> '01'
   and sqlstate <> '02000';
  exec sql rollback;
  return;
endif;
exec sql get diagnostics :wRows = ROW_COUNT;   // log the count for reconciliation
exec sql commit;
pRc = '00';
return;

SET OPTION must be the first SQL statement in the source. Alternative to a return code: send an *ESCAPE message to the caller with the QMHSNDPM API.

2.3 ILE concepts

2.4 Error handling

| Mechanism | Scope / note |

|---|---|

| MONITOR / ON-ERROR / ENDMON | Block-level; ON-ERROR by status code, *FILE, *PROGRAM, *ALL |

| (E) extender + %ERROR, %STATUS | Single operation |

| *PSSR, INFSR | Legacy program/file exception subroutines |

| PSDS / INFDS | Program/file status (job name/user/number, status, last record) |

| SQLSTATE / SQLCODE / GET DIAGNOSTICS | After every EXEC SQL; class 00 OK, 01 warning, 02 no data |

| Unhandled exception | Inquiry message (RNQxxxx) -> batch job waits in MSGW unless a reply is configured |

2.5 RPG pitfalls

3. CL

3.1 Batch wrapper skeleton (fictitious)

PGM        PARM(&PDATE)
  DCL      VAR(&PDATE)   TYPE(*CHAR) LEN(8)
  DCL      VAR(&RC)      TYPE(*CHAR) LEN(2)
  DCL      VAR(&MSGID)   TYPE(*CHAR) LEN(7)
  DCL      VAR(&MSGDTA)  TYPE(*CHAR) LEN(256)
  DCL      VAR(&MSGF)    TYPE(*CHAR) LEN(10)
  DCL      VAR(&MSGFLIB) TYPE(*CHAR) LEN(10)
  MONMSG   MSGID(CPF0000 MCH0000) EXEC(GOTO CMDLBL(ERROR))

  CALL     PGM(CPTVAL01) PARM(&PDATE &RC)
  IF       COND(&RC *NE '00') THEN(SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) +
             MSGDTA('CPTVAL01 failed, RC=' *CAT &RC) MSGTYPE(*ESCAPE))
  RETURN

ERROR:
  RCVMSG   MSGTYPE(*EXCP) MSGDTA(&MSGDTA) MSGID(&MSGID) MSGF(&MSGF) SNDMSGFLIB(&MSGFLIB)
  MONMSG   MSGID(CPF0000)
  SNDPGMMSG MSGID(&MSGID) MSGF(&MSGFLIB/&MSGF) MSGDTA(&MSGDTA) MSGTYPE(*ESCAPE)
  MONMSG   MSGID(CPF0000)
ENDPGM

The escape message makes the job end abnormally, so the scheduler sees a failure.

3.2 CL pitfalls

4. COBOL on IBM i

5. DB2 for i

5.1 Naming and access

5.2 DDS vs SQL DDL

| Aspect | DDS PF/LF | SQL table/index/view |

|---|---|---|

| Data validation | On read (bad data surfaces later as decimal data errors) | On write |

| Deleted record reuse | REUSEDLT(*NO) default | Reuse by default (arrival-order assumptions break) |

| Constraints, identity, generated timestamps, RCAC, temporal | Limited (ADDPFCST for constraints) | Native |

| Select/omit | Logical files | Views; sparse indexes (CREATE INDEX ... WHERE, creatable since 6.1 and used by the optimizer since 7.1; the WHERE clause cannot reference a column with a field procedure) |

| Long names | No | Yes, with FOR SYSTEM NAME / RCDFMT |

| Record format level id | Changes on format change -> CPF4131 for programs compiled against the old format | Same mechanism for RLA programs over SQL tables |

DDS-to-DDL modernization: keep record format names (RCDFMT) and field names so RPG RLA programs keep working; recompile dependants; surrogate logical files technique for staged migration.

5.3 Journaling and commitment control

| SQL isolation | IBM i level | Note |

|---|---|---|

| NC (No Commit) | *NONE | No commitment control; no journaling required |

| UR | *CHG | Default for CRTSQLxxxI; requires journaling |

| CS | *CS | |

| RS | *ALL | |

| RR | *RR | Table-level locking effect |

Pitfalls: SQL7008 (object not valid for operation - typically not journaled under commitment control); long batch transactions holding locks during online hours; end of scope without explicit COMMIT: an activation-group-scoped commitment definition is committed implicitly when the activation group ends normally and rolled back when it ends abnormally, while the end of the default activation group and the end of a job with job-scoped commitment control roll back pending changes - always commit explicitly; commit every N rows with a restart key for restartable batch.

5.4 SQL services for operations and reviews

All services below exist on IBM i 7.3 and later (some via PTF group level); the IBM "IBM i Services (SQL)" page gives the exact level per release.

| Service | Use |

|---|---|

| QSYS2.ACTIVE_JOB_INFO, QSYS2.JOB_INFO, SYSTOOLS.ENDED_JOB_INFO | Active jobs / jobs on queues (e.g. find MSGW) / ended jobs from CPF1164 (7.4 TR, 7.5 TR, base 7.6) |

| QSYS2.JOBLOG_INFO, QSYS2.HISTORY_LOG_INFO | Job log, QHST history |

| QSYS2.SYSTABLES, SYSCOLUMNS, SYSINDEXES, SYSVIEWS | Catalog |

| QSYS2.OBJECT_STATISTICS, QSYS2.IFS_OBJECT_STATISTICS | Objects in libraries / IFS |

| QSYS2.USER_INFO, QSYS2.OBJECT_PRIVILEGES, QSYS2.FUNCTION_USAGE | Security review |

| QSYS2.SYSTEM_VALUE_INFO | System values |

| QSYS2.SCHEDULED_JOB_INFO | WRKJOBSCDE entries |

| QSYS2.OUTPUT_QUEUE_ENTRIES | Spooled files |

| QSYS2.NETSTAT_INFO | TCP/IP connections |

| QSYS2.SYSIXADV | Index advice |

| QSYS2.SEND_DATA_QUEUE / RECEIVE_DATA_QUEUE / DATA_QUEUE_INFO | Data queues from SQL (7.3 SF99703 level 16, 7.4 SF99704 level 4, base 7.5) |

Security/privacy features: Row and Column Access Control (CREATE PERMISSION, CREATE MASK, 7.2+; administered with the QIBM_DB_SECADM function usage), field procedures for encryption, temporal tables (7.3+) for audit history.

Performance: SQE optimizer, Visual Explain and index advisor in ACS, plan cache; prefer set-based SQL and views/procedures over row-level access from remote clients.

6. Work management

7. Spool and output queues

8. IFS

9. Security

10. Integration

| Mechanism | Use | Key points / pitfalls |

|---|---|---|

| JDBC (IBM Toolbox for Java / JTOpen jt400.jar) | Java apps, ETL, middleware | URL jdbc:as400://<host>; properties naming, libraries, secure=true (TLS), prompt=false, errors=full, date format, translate binary, transaction isolation; on-box native driver jdbc:db2:*local. Server jobs QZDASOINIT (TLS QZDASSINIT). |

| ODBC (IBM i Access ODBC driver, from ACS application packages) | Windows/Linux tools, BI | Same host server; set naming, default libraries, commit mode explicitly; protect with exit programs. |

| DRDA / DDM | IBM i to IBM i or other Db2 | RDB directory WRKRDBDIRE; port 446 (448 TLS); three-part names. |

| Data queues (CRTDTAQ; APIs QSNDDTAQ, QRCVDTAQ, QCLRDTAQ; SQL QSYS2.SEND_DATA_QUEUE / RECEIVE_DATA_QUEUE) | Low-latency signalling, request/response inside IBM i or via host server (JTOpen DataQueue/KeyedDataQueue) | FIFO/LIFO/keyed; not transactional, not guaranteed delivery; FORCE(*YES) writes each entry to disk before returning (fewer losses on abnormal end, slower); RECEIVE_DATA_QUEUE removes the entry, DATA_QUEUE_ENTRIES only peeks. |

| IBM MQ for IBM i | Guaranteed, transactional messaging with the rest of the IS | Queue manager CL commands (CRTMQM, STRMQM, WRKMQM, ...); MQI from RPG/COBOL; TLS channels; DLQ and poison-message handling. Two commit models: queue-manager-coordinated local units of work (MQCMIT/MQBACK, no job-level commitment definition), or IBM i commitment control as external syncpoint coordinator (STRCMTCTL LCKLVL(*ALL) CMTSCOPE(*JOB), commit with the CL COMMIT or the language commit; MQCMIT/MQBACK/MQBEGIN then fail with MQRC_ENVIRONMENT_ERROR; two-phase commit, WRKMQMTRN for in-doubt units). |

| IWS (Integrated Web Services server) | Expose RPG/COBOL programs and service programs as REST or SOAP services (PCML-based) | Admin via HTTP admin GUI; versioning, authentication, TLS; parameter size limits; keep business logic in service programs. |

| HTTP from SQL | Consume REST/JSON from DB2 for i | QSYS2.HTTP_GET / HTTP_POST (and _BLOB, _VERBOSE variants) run without a JVM and add HTTP authentication, proxy, redirection and SSL options; the older Java-based SYSTOOLS.HTTPGET* functions remain available but need HTTPS for basic authentication from 7.5 SF99950 level 8 / 7.4 SF99704 level 29. Pair with JSON_TABLE; certificate store, timeouts. |

| Open source in PASE | Node.js, Python, Java, OpenSSH, Git via RPM/yum | Call RPG via XMLSERVICE/itoolkit or ODBC; manage packages with ACS Open Source Package Management. |

| FTP | Legacy transfers | Plaintext credentials; NAMEFMT 0 (LIB/FILE.MBR) vs 1 (paths); ASCII vs binary mode drives EBCDIC conversion; guard with FTP exit points; prefer SFTP/MFT. |

| SFTP/SSH (PASE OpenSSH) | Secure file transfer | Key-based auth for a dedicated profile; known_hosts managed; batch mode (sftp -b); file CCSID handling explicit. |

| Transfer CFT (Axway) | MFT standard in many French banks; IBM i edition exists | Partners/flows defined with CFTUTIL; transcoding EBCDIC <-> ASCII configured per flow (verify parameters in the Axway documentation of your version); acknowledgments; scheduler waits on transfer end/ack, not on the send command. |

| Journal-based CDC | Feed data platforms without touching programs | IMAGES(*BOTH), receiver retention coordinated with HA/backup; commit boundaries respected. |

Host server ports (TLS in brackets): server mapper as-svrmap 449, central 8470 (9470), database 8471 (9471), data queue 8472 (9472), file 8473 (9473), network print 8474 (9474), remote command 8475 (9475), sign-on 8476 (9476); DRDA/DDM 446 (448); Telnet 23 (992). Values can be changed with WRKSRVTBLE.

11. High availability, DR, backup

| Approach | Mechanism | Watch points |

|---|---|---|

| PowerHA SystemMirror for IBM i | Clustering with IASP: geographic mirroring, storage replication (Metro/Global Mirror, FlashCopy, HyperSwap on supported storage) | Application data in the IASP; SYSBAS objects (profiles, system values, JOBDs, subsystems...) synchronized by the cluster administrative domain. |

| Db2 Mirror for i | Synchronous active-active between two nodes (7.4+) | Distance limits, licensing, application suitability. |

| Logical replication (journal-based) | Remote journal (ADDRMTJRN) + apply on target; commercial products (e.g. MIMIX, iTERA, Maxava, Quick-EDD - verify current vendor names) | Non-journaled objects, IFS, spool, user profiles/passwords, identity/sequence values at switchover, triggers/constraints on target, apply lag monitoring, regular role-swap tests. |

| Backup | SAVSYS, SAVLIB, SAVOBJ, SAVCHGOBJ, SAV (IFS), GO SAVE options 21/22/23, BRMS; save-while-active SAVACT | Restricted state for full saves; save window vs batch window; restore tests. |

12. Scheduling on IBM i

13. EBCDIC / CCSID pitfalls

| CCSID | Meaning |

|---|---|

| 37 / 1140 | EBCDIC US / with euro |

| 297 / 1147 | EBCDIC France / with euro |

| 500 / 1148 | EBCDIC International / with euro |

| 819 / 923 / 1252 | ISO-8859-1 / ISO-8859-15 / Windows-1252 |

| 1208 / 1200 / 13488 | UTF-8 / UTF-16 / UCS-2 |

| 65535 | *HEX: no conversion |

14. Common messages and SQLCODEs

| ID | Meaning |

|---|---|

| CPF9801 / CPF9802 / CPF9810 | Object not found / not authorized / library not found |

| CPF2103 | Library already in library list (monitor on ADDLIBLE) |

| CPF4131 | Level check on file |

| CPF5027 / CPF5032 | Record in use by another job (COBOL status 9D, RPG status 01218) |

| CPF1164 | Job ended (end code 0-90 in message data, see section 6) |

| CPF9898 | Generic message used for custom escape messages |

| MCH1202 / MCH3601 | Decimal data error / pointer not set |

| RNQxxxx / RNXxxxx | RPG runtime inquiry / escape messages (QRNXMSG; number = RPG status code) |

| SQL7008 | Object not valid for operation (often: not journaled) |

| SQLCODE 100 / -803 / -811 / -913 / -204 / -551 | No row / duplicate key / more than one row on SELECT INTO / row or object in use / object not found / not authorized |

Check second-level text with DSPMSGD (message file QCPFMSG, QRNXMSG, QSQLMSG).

15. Code review checklist

| Area | Check |

|---|---|

| Structure | Free-form or plan to convert; procedures in service programs; no dead code; copybooks for prototypes; binder source with signatures managed. |

| Error handling | Every SQL statement checked (SQLSTATE); MONITOR around risky operations; no unhandled exceptions in batch (no MSGW); CL resends escape messages; return codes propagated to the scheduler. |

| Data integrity | Commitment control where several updates must be atomic; files journaled; commit frequency and restart key for long batches; idempotent reruns. |

| Locking | Read-only access with (N)/FOR READ ONLY; short lock duration; WAITRCD and lock errors handled. |

| SQL | Set-based; parameter markers (no concatenated dynamic SQL); explicit naming and commit options; indexes for predicates; no SELECT * in programs. |

| Dates/numerics | Formats explicit; 2-digit years absent; overflow/truncation checked; packed data validated at boundaries. |

| Libraries | No hard-coded libraries; JOBD/library list controlled per environment; same behaviour in batch and remote access. |

| Security | No hard-coded credentials; adopted authority justified and limited; no QCMDEXC with external input; objects owned by an application owner profile, *PUBLIC *EXCLUDE on data. |

| Integration | CCSID handled explicitly; transfers acknowledged; data queues not used where guaranteed delivery is required; exit programs cover remote access. |

| Operations | Job log level adequate; messages meaningful; run book: restart procedure, dependencies, JOBD/JOBQ, expected duration. |

| Change | Source in Git (IFS) or controlled change management; recompile dependants after file changes; object ownership and authorities set at deployment. |

16. Sources

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.