Skip to Content

How to set switches with isCOBOL

Estimated Reading Time: 2 Minutes

A common practice in COBOL programming is to manage switches to change the behavior of the program.
In isCOBOL there are four ways to accomplish this task:

  1. In your configuration file using the "iscobol.switches=" configuration variable

    You can pass switches to your program from the configuration file. For instance:
       iscobol.switches=1
    
    will activate only switch 1,
       iscobol.switches=3
    
    will activate only switch 3,
       iscobol.switches=1,3
    
    will activate switchs 1 and 3

    The runtime will set these switches when you pass the configuration file in your execution line. For instance:
       iscrun -c switch.properties MAIN
    
  2. In the command line using -J-D syntax

    The configuration variable in #1 above can also be set in your command line by prefacing the variable with "-J-D". For instance, to run a program called "MAIN";
       iscrun -J-Discobol.switches=1 MAIN
    
    will activate only switch 1
       iscrun -J-Discobol.switches=3 MAIN
    
    will activate only switch 3
       iscrun -J-Discobol.switches=1,3 MAIN
    
    will activate switchs 1 and 3
    
    
  3. Setting 'switches' in the environment

    Set the envrioment variabile from a system shell. In this case, you would remove the "iscobol." from the variable. For instance, on Windows;
       set switches=1
    
    will activate only switch 1
       set switches=3
    
    will activate only switch 3
       set switches=1, 3
    
    will activate switchs 1 and 3

    And in Linux, you would use the export command:
       export switches=1
    
    will activate only switch 1
       export switches=3
    
    will activate only switch 1
       export switches=1, 3
    
    will activate switchs 1 and 3

    With the switches set in the environment, you don't need to pass them to the runtime from the command line, so your command line is simply:
       iscrun MAIN
    
  4. In your COBOL program using the SET statement

    In your program you can write a set statement to turn on a switch.
    In the attached sample program, main.cbl, if switch 1 and 3 are on, this statement also sets switch 2 on before calling the CALLED program:
       set sw-2 to on
    

If you want to clear the switches at the end of the process, you can set the switches to blank or space. For example:

   set SWITCHES= 

Attached to this KB article is a .zip file containing two sample programs and a configuration file that show how to work with switches.
You can use them to test the 4 ways to set switches outlined above.
Unzip the files, and compile them with

   iscc *.cbl

How to set switches with isCOBOL
  • Attached Files
  • switches.zip (879 Bytes) 13