Special registers are session values that SQL can read and, for many of them, SET. This page covers the DB2 for z/OS registers that control how dynamic SQL behaves: application compatibility (function levels), application encoding, debug defaults for SQL routines, DECFLOAT rounding, query parallelism, EXPLAIN capture, locales for case conversion, optimization hints, decimal precision, native SQL procedure versions, and SQLRULES. Client, schema, datetime, and accelerator registers live on their own pages in this section.
Think of a Db2 session as a workbench. Bind options nail down static SQL at BIND time. Special registers are the knobs you can still turn for dynamic SQL after the package is allocated. The initial value of most registers comes from a bind option, a CREATE/ALTER routine option, or a subsystem parameter (ZPARM). SET statements then change the value for later statements in that application process. Inside a stored procedure or user-defined function, inheritance follows the INHERIT SPECIAL REGISTERS versus DEFAULT SPECIAL REGISTERS rules.
You can display a register with VALUES, SELECT from SYSIBM.SYSDUMMY1, or SET into a host variable. Changing a register is not under transaction control: ROLLBACK does not undo a SET CURRENT DEGREE.
123456SELECT CURRENT APPLICATION COMPATIBILITY, CURRENT DEGREE, CURRENT RULES, CURRENT PRECISION, CURRENT EXPLAIN MODE FROM SYSIBM.SYSDUMMY1;
| Register | Data type | SET statement | What it controls |
|---|---|---|---|
| CURRENT APPLICATION COMPATIBILITY | VARCHAR(10) | SET CURRENT APPLICATION COMPATIBILITY | Dynamic SQL function-level / release behavior |
| CURRENT APPLICATION ENCODING SCHEME | CHAR(8) | SET CURRENT APPLICATION ENCODING SCHEME | CCSID used for dynamic SQL data |
| CURRENT DEBUG MODE | VARCHAR(8) | SET CURRENT DEBUG MODE | Default DEBUG MODE for CREATE/ALTER of SQL routines and advanced triggers |
| CURRENT DECFLOAT ROUNDING MODE | VARCHAR(128) | SET CURRENT DECFLOAT ROUNDING MODE | Default rounding for DECFLOAT arithmetic |
| CURRENT DEGREE | CHAR(3) | SET CURRENT DEGREE | Dynamic query parallelism (1 vs ANY) |
| CURRENT EXPLAIN MODE | VARCHAR(128) | SET CURRENT EXPLAIN MODE | Capture EXPLAIN for dynamic SQL (NO, YES, EXPLAIN) |
| CURRENT LOCALE LC_CTYPE | CHAR(50) | SET CURRENT LOCALE LC_CTYPE | Locale for LCASE, UCASE, and one-argument TRANSLATE |
| CURRENT OPTIMIZATION HINT | VARCHAR(128) | SET CURRENT OPTIMIZATION HINT | PLAN_TABLE OPTHINT name for dynamic access paths |
| CURRENT PRECISION | CHAR(5) | SET CURRENT PRECISION | DEC15 vs DEC31 decimal arithmetic for dynamic SQL |
| CURRENT ROUTINE VERSION | VARCHAR(64) | SET CURRENT ROUTINE VERSION | Override native SQL procedure version on CALL with a host variable name |
| CURRENT RULES | CHAR(3) | SET CURRENT RULES | Db2 vs SQL standard ('DB2' / 'STD') statement rules |
CURRENT APPLICATION COMPATIBILITY (data type VARCHAR(10)) specifies the application compatibility level for dynamic SQL in packages. You can write APPLCOMPAT as an abbreviation when setting or referencing the register. The initial value for a package is the APPLCOMPAT bind option. For a user-defined function or stored procedure it is inherited. For advanced triggers the initial value is V12R1.
Application compatibility is how Db2 continuous delivery lets the subsystem move forward while each application still sees a chosen SQL language level. New SQL syntax and some incompatible behaviors are gated by this level. The subsystem function level can be higher than the application; the application does not get the new SQL until APPLCOMPAT (static) or this register (dynamic) says so.
| Value | Meaning |
|---|---|
| V13R1M5nn | Compatibility with a Db2 13 function level (for example V13R1M509). That function level or higher must be activated. |
| V12R1M5nn | Compatibility with a Db2 12 function level. |
| V12R1 | Same as V12R1M500 (Db2 12 function level 500). |
| V11R1 | Compatibility with Db2 11 new-function mode behavior. |
| V10R1 | Compatibility with DB2 10 new-function mode behavior. |
You cannot SET the register higher than the APPLCOMPAT of the allocated package. If the package is bound APPLCOMPAT(V12R1M503), SET CURRENT APPLICATION COMPATIBILITY = 'V12R1M505' fails even if the group is already at function level 505. You can SET a lower level, which is useful when a higher APPLCOMPAT package must still run an older DDL behavior (for example creating a traditional segmented table space after that syntax was restricted).
If a workstation tool returns SQLCODE -4743, check SYSPACKAGE.APPLCOMPAT for the IBM Data Server Driver packages it is using (often collection NULLID). Rebind those packages to the level you need; you cannot SET the register above the package.
12SET CURRENT APPLICATION COMPATIBILITY = 'V12R1M500'; SET :CS = CURRENT APPLICATION COMPATIBILITY;
CURRENT APPLICATION ENCODING SCHEME tells Db2 which encoding scheme to use when processing data for dynamic statements. The data type is CHAR(8). You may SET the register to ASCII, EBCDIC, or UNICODE, but what is stored is the character form of the corresponding numeric CCSID, padded on the right with blanks to 8 bytes. Use the CCSID_ENCODING scalar function if you need the name ASCII, EBCDIC, or UNICODE back from a CCSID.
This register is not supported in REXX applications or REXX stored procedures. For stored procedures and UDFs, the initial value comes from the ENCODING bind option of the associated package, or from the APPLICATION ENCODING SCHEME clause on CREATE/ALTER FUNCTION or PROCEDURE for compiled SQL functions and native SQL procedures. If that option was omitted, the DEFAULT APPLICATION ENCODING SCHEME field on installation panel DSNTIPF is used. Basic triggers start at Unicode; advanced triggers start at the DSNTIPF default.
Mismatched encoding is a common reason a dynamic INSERT “looks almost right” in QMF or a JDBC client. Set the register to match the CCSID of the host variables or the application encoding you actually send.
12VALUES (CURRENT APPLICATION ENCODING SCHEME) INTO :HV1; SET CURRENT APPLICATION ENCODING SCHEME = 'EBCDIC';
CURRENT DEBUG MODE (VARCHAR(8)) supplies the default DEBUG MODE option when you create or alter certain SQL objects: a new version of an SQL scalar function, a new version of a native SQL procedure, a new version of an advanced trigger, CREATE FUNCTION for an SQL scalar function, CREATE PROCEDURE for a Java procedure, CREATE PROCEDURE for a native SQL procedure, and CREATE TRIGGER (advanced).
| Value | Meaning |
|---|---|
| ALLOW | The routine or advanced trigger can run in debugging mode. |
| DISALLOW | Cannot run in debugging mode now, but a later ALTER can change DEBUG MODE. Initial value outside UDFs, procedures, and triggers. |
| DISABLE | Can never run in debugging mode. A later ALTER cannot turn debugging back on. |
DISALLOW is the initial value outside UDFs, procedures, and triggers. DISABLE is the strong choice for production objects you never want in the Unified Debugger. ALLOW is for development. Changing the register does not alter existing objects; it only defaults the next CREATE or ALTER that omits an explicit DEBUG MODE clause.
12SET CURRENT DEBUG MODE = 'DISALLOW'; VALUES CURRENT DEBUG MODE INTO :DEBUG_MODE_OPT;
CURRENT DECFLOAT ROUNDING MODE (VARCHAR(128)) is the default rounding mode for DECFLOAT values. The initial value is the ROUNDING bind option or native SQL procedure option; if that is omitted, DEF DECFLOAT ROUND MODE on DSNTIPF is used.
| Mode | What it does |
|---|---|
| ROUND_CEILING | Round toward positive infinity. |
| ROUND_DOWN | Round toward zero (truncate discarded digits). |
| ROUND_FLOOR | Round toward negative infinity. |
| ROUND_HALF_EVEN | Nearest value; ties round to an even last digit (IEEE-friendly default in many shops). |
| ROUND_HALF_UP | Nearest value; ties round away from zero. |
| ROUND_HALF_DOWN | Nearest value; ties round toward zero. Not in the IEEE floating-point standard — avoid for portable apps. |
| ROUND_UP | Round away from zero. Also not IEEE-standard — avoid for portable apps. |
Rounding matters when a DECFLOAT result must be shortened to fit a target precision. ROUND_HALF_EVEN is the usual IEEE-style choice. ROUND_HALF_DOWN and ROUND_UP are documented as not recommended for portable applications because they are not in the IEEE floating-point standard. SET the register before dynamic statements that mix DECFLOAT with other numeric types if you need a specific policy.
1SET CURRENT DECFLOAT ROUNDING MODE = 'ROUND_CEILING';
CURRENT DEGREE specifies the degree of parallelism for queries that are dynamically prepared by the application process. The data type is CHAR(3). The only valid values are 1 (padded on the right with two blanks) and ANY.
The initial value comes from the CDSSRDEF subsystem parameter (CURRENT DEGREE field on DSNTIP8). The IBM default is 1 unless your shop changed it. CURRENT DEGREE is a register at the database server; it applies to queries dynamically prepared there and to queries dynamically prepared on another Db2 through a private connection from that server.
Use 1 when you need a predictable, single-task plan (online transactions, tight CPU caps). Use ANY for large dynamic reporting when Sysplex query parallelism or CPU parallelism can help. Static SQL uses the DEGREE bind option instead of this register.
12SET CURRENT DEGREE = '1'; SET CURRENT DEGREE = 'ANY';
CURRENT EXPLAIN MODE (VARCHAR(128)) controls whether eligible dynamic SQL statements write EXPLAIN information into the EXPLAIN tables. The initial value is NO. Prepared statements are not saved in the dynamic statement cache when the value is YES or EXPLAIN.
| Value | Meaning |
|---|---|
| NO | EXPLAIN facility off for this register. Initial value. Dynamic SQL runs normally with no extra EXPLAIN inserts from this register. |
| YES | Insert EXPLAIN information for eligible dynamic SQL after prepare and execute. The statement still runs. Prepared statements are not saved in the dynamic statement cache. |
| EXPLAIN | Capture EXPLAIN information after prepare, but do not execute the dynamic statement (SET statements still execute). Also skips the dynamic statement cache. |
Prerequisites: PLAN_TABLE and DSN_STATEMENT_CACHE_TABLE must exist, qualified with the current SQLID used when the application runs, the dynamic statement cache must be enabled, and the application must contain explainable statements. The privilege set for the underlying statement must be allowed to use EXPLAIN. When the EXPLAIN privilege is in effect and the register is EXPLAIN, an SQLCODE from that privilege overrides an SQLCODE that would otherwise come from the register itself.
YES is the “run it and also capture the path” setting. EXPLAIN is the “show me the path but do not change data” setting, which is safer in production-like copies. Static SQL still uses the EXPLAIN bind option; if that option is ALL and this register is NO, dynamic SQL can still be explained at run time from the bind option. If this register is not NO, the EXPLAIN bind option is ignored for that interaction.
1234SET CURRENT EXPLAIN MODE = EXPLAIN; -- Prepare and "run" a SELECT; the SELECT itself is not executed SELECT EMPNO, LASTNAME FROM HR.EMPLOYEE WHERE WORKDEPT = 'A00'; SET CURRENT EXPLAIN MODE = NO;
CURRENT LOCALE LC_CTYPE (CHAR(50), blank-padded) is the LC_CTYPE locale used when SQL runs a built-in function that consults a locale. LCASE, UCASE, and TRANSLATE with a single argument use this register.
The initial value is the LOCALE LC_CTYPE field on DSNTIPF (blank unless your shop changed it). If UCASE of a name with accents looks “wrong,” the register is probably still blank. Do not SET UNI_* when the expression is EBCDIC.
12SET CURRENT LOCALE LC_CTYPE = 'En_US'; SELECT UCASE(LASTNAME) FROM HR.EMPLOYEE;
CURRENT OPTIMIZATION HINT (VARCHAR(128)) names the user-defined optimization hint Db2 should use when it builds the access path for dynamic statements. The value matches rows in owner.PLAN_TABLE whose OPTHINT column equals the register. An empty string or all blanks means normal optimization; hints are ignored. If the register contains non-blank characters and the subsystem was installed with optimization hints disabled (OPTIMIZATION HINTS on DSNTIP8), you get a warning.
The initial value is the OPTHINT bind option or native SQL procedure option. Hints are a last resort after statistics, indexes, and REOPT. A stale hint can freeze a bad plan after a Db2 upgrade. Prefer updating RUNSTATS and rewriting SQL before pinning a path.
123SET CURRENT OPTIMIZATION HINT = :NOHYB; -- empty string returns to normal optimization SET CURRENT OPTIMIZATION HINT = '';
CURRENT PRECISION (CHAR(5)) chooses the decimal arithmetic rules used when both operands in a decimal operation have precision 15 or less. It affects dynamic SQL only. If either operand already has precision greater than 15, DEC31 rules are always used.
12SET CURRENT PRECISION = 'DEC31'; SET CURRENT PRECISION = 'D31.3';
CURRENT ROUTINE VERSION (VARCHAR(64)) is the version identifier used when you CALL a native SQL procedure and the procedure name is supplied by a host variable. An empty string (the initial value outside UDFs and procedures) means no override: Db2 uses the currently active version from the catalog. If you SET a version that exists for that procedure, that version runs; if the procedure has no matching version, the active catalog version still runs.
This is how shops test a new native SQL procedure version in one session without activating it for everyone. CALL statements that use a literal procedure name do not use this register the same way; the host-variable form is the documented case.
123SET CURRENT ROUTINE VERSION = 'V2'; CALL :PROC-NAME; VALUES CURRENT ROUTINE VERSION INTO :ROUTINE_VER;
CURRENT RULES (CHAR(3)) chooses whether SQL statements follow Db2 rules or the SQL standard. Valid values are DB2 and STD. At a remote server that is not the local Db2, the initial value is DB2. Locally, the initial value is the SQLRULES bind option.
123SET CURRENT RULES = 'STD'; -- later ALTER TABLE check constraints follow SQL standard enforcement SET CURRENT RULES = 'DB2';
SET these registers in a controlled place: a front-end stored procedure, a JDBC specialRegisters connection property, or a well-known setup module. Do not scatter SET CURRENT DEGREE = 'ANY' through random dynamic SQL. Document which packages rely on APPLCOMPAT versus the special register. After a function-level activate, raise package APPLCOMPAT in a planned wave; the register cannot leapfrog the bind option.
These registers are stickers on your homework folder. One sticker says “use the old spelling rules” (application compatibility). Another says “write in block letters or cursive” (encoding). Another says “you may use ten helpers or only yourself” (degree). Another says “show your work but do not actually hand in the paper” (EXPLAIN mode). The teacher (Db2) looks at the stickers before grading each new sentence you write (dynamic SQL). Printed worksheets from last year (static SQL) already have their stickers from when they were copied (BIND).
1. Can SET CURRENT APPLICATION COMPATIBILITY raise a package above its APPLCOMPAT bind value?
2. What are the valid values of CURRENT DEGREE?
3. What does CURRENT EXPLAIN MODE = EXPLAIN do that YES does not?
4. How do CURRENT RULES values DB2 and STD differ for a missing object name?
5. Which CURRENT PRECISION value allows decimal arithmetic up to 31 digits when both operands have precision 15 or less?