Performance Tuning
Use SMF records and job statistics (CPU, EXCPs), IBM Application Performance Analyzer, BMC/Compuware Strobe, DB2 accounting traces and EXPLAIN, CICS statistics and monitoring (CMF).
32.1 Data-level techniques
Use COMP-3 for arithmetic fields, COMP/COMP-5 for subscripts and counters
Avoids repeated conversion from zoned decimal Use odd digit counts for COMP-3 (S9(7)V99)
Fills bytes exactly; no extra padding instructions Use signed numeric fields (S)
Unsigned fields require sign-fixing instructions Use indexes (INDEXED BY) instead of subscripts in hot loops Indexes are already displacements Use SEARCH ALL on large sorted tables O(log n) instead of O(n)
Avoid mixing data types in one COMPUTE Each conversion costs instructions
Avoid OCCURS DEPENDING ON in hot paths Variable-length addressing is costlier
Don't INITIALIZE huge tables repeatedly Initialize once; track a used-count instead
32.2 I/O techniques
Block your files: BLOCK CONTAINS 0 RECORDS with system-determined block size; I/O is usually the dominant cost in batch.
Increase buffers: BUFNO for QSAM, BUFND/BUFNI (or AMP= in JCL) and SMB for VSAM; use sequential access for sequential processing of VSAM.
Open files once per run, not per record. Sort with DFSORT in a separate step when no COBOL logic is needed; use DFSORT INCLUDE/OMIT to filter early.
For DB2: select only needed columns, use indexes, multi-row FETCH, commit periodically in batch, avoid row-by-row processing where set-based SQL works.
32.3 Compiler options for production (IBM)
OPTIMIZE(2) for production; OPTIMIZE(0) while debugging. ARCH(n) set to the oldest machine that will run the code (higher levels unlock newer instructions, e.g., decimal-floating-point and vector instructions on z14+).
NUMPROC(PFD) if you can guarantee preferred signs; TRUNC(OPT) only if binary values never exceed their PICTURE.
Decide deliberately whether runtime-checking options (SSRANGE, NUMCHECK) stay on in production — they add CPU cost. Debug data from TEST can usually be kept in Enterprise COBOL 6.x builds with little runtime impact, which keeps production problems debuggable.
Recompiling old COBOL with a modern Enterprise COBOL release and current ARCH often yields significant CPU savings with no source changes.
32.4 Measuring
Use SMF records and job statistics (CPU, EXCPs), IBM Application Performance Analyzer, BMC/Compuware Strobe, DB2 accounting traces and EXPLAIN, CICS statistics and monitoring (CMF). On Linux, GnuCOBOL programs can be profiled like C programs (perf, gprof with -O2 -g). Always measure before and after a change.