OPT(2) tells IBM Enterprise COBOL to apply its highest documented optimization level to the generated object program. That setting can improve runtime performance, but it also assumes that the source, input data, and related compiler-option contracts are valid.
What does the COBOL OPTIMIZE compiler option do?
The COBOL OPTIMIZE compiler option controls how much work the compiler performs to reduce the runtime or storage cost of generated code. Current Enterprise COBOL syntax is OPTIMIZE(0), OPTIMIZE(1), or OPTIMIZE(2), abbreviated as OPT(0), OPT(1), and OPT(2).
This page focuses only on OPTIMIZE. For a wider option set, see COBOL compiler and runtime performance tips and the broader COBOL performance tuning checklist.
OPT(0), OPT(1), and OPT(2) compared
| Level | Compiler behavior | Typical use | Debug effect with TEST |
|---|---|---|---|
OPT(0) | Limited optimization and shortest compile time | Initial code changes, diagnosis, and unit testing | Full debug capabilities |
OPT(1) | Runtime-oriented transformations, basic inlining, local simplification, and value propagation | A measured middle level when build or debugging constraints matter | Most debug capabilities |
OPT(2) | More aggressive simplification, instruction scheduling, and interblock optimization | Regression-tested production builds | Some debug capabilities |
OPT(0) as the product default. Your installation can change or fix defaults, so use the compiler listing—not an assumption—to confirm the option that built a program.What OPT(1) can change
At OPT(1), the compiler can simplify control flow, reduce repeated computations, evaluate constant expressions during compilation, combine suitable contiguous moves, rearrange blocks, and remove unreachable code. When INLINE is also active, the compiler can consider inlining eligible PERFORM procedures.
Source code and generated instructions no longer have a simple one-to-one relationship. A debugger can still provide most capabilities with TEST at this level, but the execution path can reflect moved, combined, or removed work.
What OPT(2) adds
OPT(2) applies the OPT(1) work and adds more aggressive simplification and instruction scheduling. IBM also identifies interblock transformations such as global value propagation and loop-invariant code motion. IBM recommends OPT(2) as part of the best-performance option set for Enterprise COBOL 6.
That recommendation is a build target, not proof that every program will improve by a particular percentage. Measure the program with the same input volume and comparable system conditions before and after recompilation.
Legacy STD and FULL syntax mapping
The original post described OPTIMIZE(STD) and OPTIMIZE(FULL). Since Enterprise COBOL 5, IBM removed those forms but tolerates them for compatibility and maps them as follows:
| Legacy option | Current mapping |
|---|---|
NOOPTIMIZE | OPTIMIZE(0) |
OPTIMIZE | OPTIMIZE(2) |
OPTIMIZE(STD) | OPTIMIZE(2) |
OPTIMIZE(FULL) | OPTIMIZE(2) plus STGOPT |
Use the numbered form in maintained build standards. It states the intended level directly and avoids carrying old terminology into new compiler migrations.
How to specify OPTIMIZE in source
A PROCESS or CBL statement can specify most compiler options. It must appear before the IDENTIFICATION DIVISION header and before comment lines or other compiler-directing statements.
CBL OPT(2),ARCH(13),TUNE(13)
IDENTIFICATION DIVISION.
PROGRAM-ID. PAYCALC.
Do not copy the architecture values blindly. Select ARCH for the oldest processor on which the module can run, including disaster-recovery machines. Select TUNE for the processor used most often, and keep TUNE greater than or equal to ARCH.
How to specify OPTIMIZE in compile JCL
Compiler options can also be passed on the compiler invocation. The exact cataloged procedure varies by installation, but a direct compiler step can use a PARM string such as:
//COBOL EXEC PGM=IGYCRCTL,REGION=0M,
// PARM='OPT(2),ARCH(13),TUNE(13)'
If your site uses a compile procedure, place the option on the documented procedure symbol instead of assuming its parameter name. Review the listing to confirm the final resolved settings.
Compiler-option precedence under z/OS
For options that are not fixed, IBM documents this high-to-low precedence:
- Fixed installation defaults, which an application build cannot override.
- Certain batch-wide settings in effect for the first program.
PROCESSorCBLstatements in the source program.- Compiler invocation options, including the JCL PARM value.
- Nonfixed installation defaults.
If JCL requests OPT(2) but a source CBL statement requests OPT(0), the source setting normally wins unless the installation fixed the option. This is why the compiler listing belongs with the promoted load module.
OPTIMIZE and TEST debugging behavior
IBM documents full debug capabilities with TEST at OPT(0), most at OPT(1), and some at OPT(2). Higher optimization can move, combine, inline, or remove generated work, so a source statement might not correspond to a single executable instruction range.
Use the COBOL TEST compiler option guide for debug-build choices. For targeted condition-handler visibility, IBM prefers the VOLATILE clause over reducing optimization for an entire program where VOLATILE fits the design.
Use a two-step migration build
IBM recommends a two-step compile process when moving or changing Enterprise COBOL programs. A diagnostic build can use runtime checks and OPT(0):
OPT(0),SSRANGE,NUMCHECK,PARMCHECK,INITCHECK
After invalid-data and storage-reference problems are corrected, the QA and production candidate can remove the runtime checks and use:
OPT(2),NOSSRANGE,NONUMCHECK,NOPARMCHECK
Follow local standards and preserve a repeatable test record. The SSRANGE guide, NUMPROC guide, and ARITH guide explain related data and arithmetic choices.
Valid data matters more at higher optimization
The optimizer assumes the program and data comply with the selected compiler options. Invalid packed-decimal signs, invalid zoned-decimal digits, out-of-range subscripts, storage overlays, or a call-interface mismatch can appear to behave differently after an optimization-level or compiler-version change.
OPT(2), ARCH, and TUNE work together
IBM's best-performance set for Enterprise COBOL 6 is OPT(2), ARCH(x), and TUNE(y). OPT controls transformation depth. ARCH controls which processor instructions the generated module may use. TUNE guides instruction selection and scheduling for the processor used most often.
A build that selects an ARCH level newer than a disaster-recovery processor can produce a module that cannot run there. Record both production and recovery hardware requirements in the compiler-option standard.
When MAXPCF can reduce optimization
Enterprise COBOL calculates a program complexity factor for optimization control. If that value exceeds a nonzero MAXPCF threshold, a requested OPT(1) or OPT(2) can be reset to OPT(0) and the compiler issues a warning.
Do not assume that a requested option was applied to a very large program. Check the listing for the effective option, the complexity warning, compile return code, and available region or MEMLIMIT before changing MAXPCF.
Measure an OPT(2) rollout
- Capture the compiler version, all effective options, binder settings, and load-module identity.
- Run the old and new modules with the same representative input and output checks.
- Compare CPU time or service units, elapsed time, EXCP or I/O behavior, and storage only where the measurement source is reliable.
- Repeat enough runs to separate a code change from workload and system noise.
- Promote only after functional results match and rollback material is retained.
Compiler optimization cannot repair an inefficient SQL access path or excessive file I/O. The COBOL runtime performance-options guide covers other build and execution factors.
COBOL OPTIMIZE rollout checklist
- Replace tolerated STD/FULL syntax with an explicit numbered level in maintained standards.
- Confirm the effective setting in the compiler listing.
- Run diagnostic checks before moving a migrated application to OPT(2).
- Verify ARCH against every processor that might execute the program.
- Keep TUNE greater than or equal to ARCH.
- Investigate MAXPCF warnings and compiler storage failures.
- Compare functional output before evaluating runtime measurements.
Official IBM references
- IBM: Enterprise COBOL optimization
- IBM: Tuning compiler options for COBOL 6
- IBM: Compiling with Enterprise COBOL
- IBM: Specifying compiler options under z/OS
- IBM: MAXPCF option
COBOL OPTIMIZE FAQ
What is the default COBOL OPTIMIZE level?
IBM Enterprise COBOL documents OPTIMIZE(0) as the product default, but a site can change or fix installation defaults. Check the compiler listing to see the option actually in effect.
What is the difference between OPT(1) and OPT(2)?
OPT(1) applies runtime-oriented transformations such as basic inlining and local simplification. OPT(2) adds more aggressive simplification, instruction scheduling, and interblock work such as global value propagation and loop-invariant code motion.
What happened to OPTIMIZE(STD) and OPTIMIZE(FULL)?
Since Enterprise COBOL 5, those forms are removed but tolerated for compatibility. IBM maps OPTIMIZE(STD) to OPTIMIZE(2) and OPTIMIZE(FULL) to OPTIMIZE(2) with STGOPT.
Should every production program use OPT(2)?
IBM recommends OPT(2) for best performance, but each application still needs functional regression testing, valid-data checks, compatible ARCH and TUNE values, and before-and-after runtime measurement under representative workloads.
The compiler listing is the final authority for a build: it shows whether the requested optimization level survived source overrides, fixed site defaults, and MAXPCF processing.