A COBOL program can call another program by writing CALL "PAYCALC" or by putting the program name in a data item and using CALL WS-PROGRAM-NAME. The DYNAM compiler option mainly affects the first form: CALL with a literal program name.
What is the COBOL DYNAM compiler option?
DYNAM tells Enterprise COBOL to load separately compiled, nonnested programs dynamically when they are called with CALL literal. IBM documents the default as NODYNAM. The abbreviation is DYN, and NODYN is the abbreviation for NODYNAM.
With NODYNAM, a literal call is normally resolved through the link-edit step. With DYNAM, the called program is loaded at run time, and a later CANCEL can delete it from the run unit.
DYNAM vs NODYNAM
| Option | CALL literal behavior | Good fit |
|---|---|---|
NODYNAM |
The called program name is resolved through the link step. | High-volume calls, stable subprograms, and programs where call path length matters. |
DYNAM |
The called program is loaded dynamically at run time. | Shared subprograms that change independently, optional routines, and cases where CANCEL is used to free storage. |
CALL literal example
This is the form affected by DYNAM. The subprogram name is written directly in the source code.
CBL DYNAM
PROCEDURE DIVISION.
CALL "TAXCALC" USING WS-INVOICE
WS-TAX-AMOUNT
END-CALL
GOBACK.
Compiled with DYNAM, this literal call is treated as a dynamic load at run time. Compiled with NODYNAM, the call is normally resolved when the program is linked.
CALL identifier is already dynamic
IBM documents that CALL identifier always results in a runtime load of the target program and is not affected by the DYNAM option. This is easy to miss when reviewing old code.
01 WS-PROGRAM-NAME PIC X(8) VALUE "TAXCALC".
PROCEDURE DIVISION.
CALL WS-PROGRAM-NAME USING WS-INVOICE
WS-TAX-AMOUNT
END-CALL.
If a program already uses a data-name in the CALL statement, changing NODYNAM to DYNAM does not make that specific call more dynamic. It was already resolved by name at run time.
ON EXCEPTION with DYNAM
ON EXCEPTION can matter when a called program is missing from the runtime search path. IBM notes that for CALL literal, the exception condition can occur only when DYNAM is in effect. With NODYNAM, a missing statically resolved subprogram is usually caught earlier in the build or link process.
CALL "TAXCALC" USING WS-INVOICE
WS-TAX-AMOUNT
ON EXCEPTION
MOVE 16 TO WS-RETURN-CODE
END-CALL.
Do not use ON EXCEPTION as a substitute for proper deployment checks. It is a runtime safety path, not a reason to leave load libraries unclear.
Why use DYNAM?
DYNAM can make maintenance easier for common subprograms. If several applications call the same utility routine, a site may update that routine without relinking every caller, subject to local load library, binder, and change-control rules.
It can also help storage control in long-running programs. If a called program is no longer needed, CANCEL can remove the dynamically loaded program from the run unit.
Why keep NODYNAM?
NODYNAM is often better for call-heavy code. IBM performance guidance notes that DYNAM adds a longer path because the call goes through a library routine. The exact cost depends on the program and how often the call runs.
If a job calls the same small validation routine once for every input record, test carefully before switching to DYNAM. A call inside a ten-million-record loop is very different from a setup call that runs once.
Restrictions and cases to check
IBM documents restrictions for DYNAM. Do not use it for COBOL programs processed by the CICS translator or the CICS compiler option. IBM also documents restrictions for programs with EXEC SQL statements in certain environments, including CICS and Db2 call attach facility cases.
DLL use is another area to check. IBM states that if COBOL programs call programs linked as dynamic link libraries, the caller should be compiled with NODYNAM and DLL, not DYNAM.
Compile option example
Many shops set this option in a compile procedure rather than in the source. A source-level example is still useful when reading compiler listings or test programs.
CBL NODYNAM
IDENTIFICATION DIVISION.
PROGRAM-ID. PAYMAIN.
Before changing the option, check the compiler listing. The listing is the clean evidence of whether DYNAM or NODYNAM was in effect for the program you are testing.
Load library checks
Dynamic calls depend on the runtime search path. In batch, review the STEPLIB, job library setup, and site runtime libraries. In online regions, review the region procedure and program management rules used by the support team.
A common production problem is simple: the caller was compiled with DYNAM, but the called module was not in the expected library at execution time. The source code looked correct, but the runtime environment could not find the program.
Testing checklist
- List every
CALL literalandCALL identifierin the program. - Check whether the called program is linked with the caller or loaded from a runtime library.
- Confirm CICS, SQL, CAF, DLL, and site standards before changing the option.
- Run a missing-subprogram test if the application depends on
ON EXCEPTION. - Compare CPU time and elapsed time for call-heavy programs.
- Check load library order in the job or region where the program runs.
Migration review points
When moving older COBOL programs to a newer compiler, do not copy the old DYNAM setting blindly. Review how each called module is packaged, whether the program uses CICS or SQL, whether DLL rules apply, and whether the call sits inside a hot record loop.
For a high-volume batch driver, test one compile option change at a time. Keep the old listing, new listing, binder output, job statistics, and load-library evidence together so the next support person can see why the option was changed.
Common mistakes
Expecting DYNAM to affect CALL identifier
CALL WS-PROGRAM-NAME is already dynamic. The DYNAM option is mainly about nonnested, separately compiled programs called through CALL literal.
Changing the option without checking CICS or SQL
A batch test may work, but that does not prove the option is valid for a CICS or SQL environment. Check the actual execution environment before compiling production code.
Ignoring call frequency
A dynamic call in setup code may be harmless. A dynamic call inside a record loop can be expensive. Count the calls before arguing about the option.
Related Mainframe Forum guides
For nearby topics, read COBOL CALL statement examples, COBOL static call, COBOL COPY vs CALL, COBOL RENT compiler option, COBOL THREAD compiler option, and COBOL performance tuning tips.
External references
IBM documents the DYNAM compiler option, DYNAM performance considerations, and the COBOL CALL statement.
FAQ
What is the default for the COBOL DYNAM option?
IBM documents the default as NODYNAM.
Does DYNAM affect CALL identifier?
No. IBM documents that CALL identifier always causes a runtime load of the target program and is not affected by DYNAM.
When should I use NODYNAM?
Use NODYNAM when literal calls should be resolved through the link step, when call overhead matters, or when CICS, SQL, DLL, or site rules require it.
Can CANCEL unload a dynamically called program?
Yes. With dynamic calls, CANCEL can delete the called program from the run unit when it is no longer needed.