Modernization Hub

Hard Coded

Enhanced Definition

In the mainframe context, a "hard-coded" value refers to data, parameters, or logic that is directly embedded within a program's source code or a JCL statement, rather than being supplied externally. This means the value is fixed at compile or assembly time and cannot be changed without modifying and recompiling/reassembling the program or JCL.

Key Characteristics

    • Values are explicitly written into the program's source code (e.g., COBOL VALUE clauses, literals in MOVE statements) or JCL (e.g., DSN= values, PARM= strings).
    • Requires modification of the source code or JCL and subsequent recompilation, reassembly, or re-submission to alter the embedded value.
    • Reduces program flexibility and adaptability, as the program's behavior is tightly coupled to these fixed values.
    • Can simplify initial development for truly invariant constants but often leads to significant maintenance challenges.
    • Makes programs less reusable across different environments (e.g., test vs. production) without code changes.

Use Cases

    • Defining mathematical constants (e.g., PI) or fixed system-wide values that are guaranteed not to change within a COBOL program.
    • Specifying literal strings for error messages, report headers, or fixed labels within application code.
    • Temporarily embedding test data, specific file names, or database identifiers during development or debugging before externalizing them.
    • In legacy COBOL programs, hard-coding file names, record lengths, or system IDs due to historical practices or lack of externalization mechanisms.
    • Occasionally, in JCL, hard-coding a DSN (Data Set Name) for a utility or a specific PARM value for a one-off, non-reusable execution.

Related Concepts

Hard coding stands in direct contrast to parameterization and externalization, which are crucial for flexible and maintainable mainframe applications. Instead of hard-coding, values are typically passed via JCL PARM parameters, read from SYSIN data sets, retrieved from PDS members (e.g., PARMLIB members), or stored in DB2 tables or IMS segments. It significantly impacts program maintainability, deployment strategies, and testing efficiency, as changes to hard-coded values necessitate a full change management cycle, unlike externalized parameters which can often be updated without recompilation.

Best Practices:
  • Avoid for Volatile Data: Never hard-code values that are likely to change between environments (e.g., test vs. production), over time, or based on business rules (e.g., file names, database connection strings, business thresholds, report titles).
  • Externalize Parameters: Utilize JCL PARM parameters, SYSIN data sets, DD statements, or dedicated configuration files (e.g., members in a PDS like SYS1.PARMLIB or application-specific PDS/E libraries) to supply variable data to programs.
  • Use Symbolic Constants: In COBOL, define symbolic constants using 01 level items with VALUE clauses in WORKING-STORAGE or CONSTANT sections for truly static values, making them easier to locate and modify if absolutely necessary, though still requiring recompilation.
  • Document Explicitly: If hard-coding is unavoidable for truly static and invariant values (e.g., specific bit masks, internal codes), document its presence and rationale clearly within the code comments.
  • Leverage Database for Configuration: For complex or frequently changing configuration data, store it in a database (DB2, IMS) and have programs retrieve it at runtime, providing maximum flexibility without code changes.