MainframeMaster

COBOL Tutorial

SWITCH - Configuration Flags and Environment

Progress0 of 0 lessons

What is a switch/flag?

A simple on/off or enumerated setting that changes program behavior at runtime: enable tracing, choose TEST vs PROD endpoints, toggle features during rollout.

🔀 Analogy

Like light switches in a room—flip them on/off to change what’s active without rewiring the house.

Ways to Provide Switches

Environment Variables

cobol
1
2
3
4
ACCEPT ENABLE-TRACE FROM ENVIRONMENT 'APP_TRACE' IF ENABLE-TRACE = 'Y' PERFORM TRACE-INIT END-IF

JCL PARM / PROC Symbols

jcl
1
2
//STEP1 EXEC PGM=MYPROG,PARM='TRACE=Y,ENDPOINT=TEST' //MYCONF DD DISP=SHR,DSN=TEAM.CONFIG(MYAPP)

Program reads PARM or a control dataset to set flags.

Configuration Dataset (key=value)

plaintext
1
2
3
TRACE=Y ENDPOINT=TEST RETRIES=3

Read once at startup; store in WORKING-STORAGE. Log effective config.

Central Config Module

cobol
1
2
3
4
5
6
7
8
01 ENABLE-TRACE PIC X VALUE 'N'. 01 TARGET-ENV PIC X(4) VALUE 'PROD'. ... IF TARGET-ENV = 'TEST' MOVE 'https://test.api' TO API-URL ELSE MOVE 'https://prod.api' TO API-URL END-IF

Expose simple flags. Hide parsing/IO behind initialization routine.

Testing and Safety

  • Print effective config at startup for auditability
  • Provide safe defaults (e.g., TRACE=N)
  • Validate flag values; fall back when invalid

Quick Reference

SourceHowExample
ENVACCEPT FROM ENVIRONMENTAPP_TRACE
JCLPARM / SymbolsPARM='TRACE=Y'
DatasetRead key=valueTRACE=Y

Test Your Knowledge

1. Are switches a COBOL verb?

  • Yes
  • No

2. Where should flags be defined?

  • Scattered IFs
  • Central configuration module
  • Inside each paragraph
  • Linkage only

3. How to load runtime values?

  • Hardcode always
  • Environment/JCL/config files
  • Random
  • Operator REPLY only

Frequently Asked Questions

Related Pages