Directive
In mainframe programming, a directive is an instruction embedded within source code that guides a compiler, assembler, or preprocessor on how to process the code, rather than being an executable instruction itself. It influences the compilation or assembly process, affecting aspects like code generation, data allocation, or conditional processing. In the context of mainframe programming, a **directive** is a non-executable instruction embedded within source code that provides specific guidance or commands to a compiler, assembler, or preprocessor. These instructions influence how the source code is processed, translated, or linked, rather than performing operations at runtime.
Key Characteristics
-
- Non-executable: Directives are processed at compile-time or assembly-time by a language processor, not during program execution.
- Tool-specific: They are interpreted by specific language processors such as the COBOL compiler, HLASM assembler, or C/C++ preprocessor.
- Syntax: Often identified by special keywords, prefixes (like
#in C/C++), or specific statement types (e.g.,PROCESSin COBOL,DC/DSin Assembler). - Influence on Output: Directives control aspects like compiler options, data area definitions, conditional code inclusion, external file inclusion, or macro expansion.
- Language-dependent: The exact syntax, functionality, and available directives vary significantly between programming languages (COBOL, PL/I, Assembler, C/C++).
Use Cases
-
- COBOL Compiler Options: Using
PROCESSstatements (e.g.,PROCESS CICS, DYNAM, NORES) within a COBOL program to specify compiler options, potentially overriding those set in the JCL. - HLASM Data Definition: Employing assembler directives like
DC(Define Constant) andDS(Define Storage) to allocate and initialize storage for data within an assembly language program. - C/C++ Preprocessing: Utilizing
#includeto incorporate header files (e.g.,,) or#defineto create symbolic constants or macros in z/OS UNIX System Services applications. - Conditional Compilation: Implementing directives (e.g.,
CBL PROCESS OPT(1)in COBOL,IF/ELSE/ENDIFin Assembler macros,#ifdefin C/C++) to include or exclude specific sections of code based on defined conditions. - PL/I Preprocessor: Using
%INCLUDEto incorporate common declarations or%DCLto define preprocessor variables for conditional compilation or text substitution.
- COBOL Compiler Options: Using
Related Concepts
Directives are fundamental components of source code and are directly interpreted by language processors (compilers, assemblers, preprocessors) during the build process. They dictate how the source code is transformed into object modules or load modules, influencing the final executable program's structure, size, and behavior. While JCL provides control statements for the operating system and utility programs, directives operate at a more granular level, specific to the programming language and its associated tools, guiding the internal processing of the source code itself.
- Clarity and Readability: Use directives judiciously to enhance code clarity and maintainability. Document complex conditional compilation logic thoroughly.
- Consistency: Maintain consistent use of directives across a project or organization, especially for standard compiler options, data definitions, or common include files.
- Performance Optimization: Leverage appropriate directives (e.g., specific compiler optimization options) to fine-tune the generated code for performance or resource utilization, always verifying the impact through testing.
- Maintainability: Avoid excessive or overly nested conditional compilation that can make code difficult to read, debug, and maintain. Consider alternative approaches like separate modules or configuration files when appropriate.
- Standardization: Adhere to organizational standards for directive usage, particularly for common data areas or system interfaces, to ensure consistency and reduce errors.