HP OpenVMS Systems Documentation

Content starts here

HP COBOL
User Manual


Previous Contents Index

1.5.2 Setting and Controlling Switches Externally

Switches that are set externally are handled differently on Tru64 UNIX and OpenVMS, as described in this section.

Switches on Tru64 UNIX

On Tru64 UNIX systems, to set switches from outside the image, use the SETENV command to change the status of program switches, as follows:


% setenv COBOL_SWITCHES "switch-list"

To remove switch settings:


% unsetenv COBOL_SWITCHES

To check switch settings, enter this command:


% printenv COBOL_SWITCHES          Shows switch settings.

The switch-list can contain up to 16 switches separated by commas. To set a switch on, specify it in the switch-list. A switch is off (the default) if you do not specify it in the switch-list.

For example:


% setenv COBOL_SWITCHES "1,5,13"   Sets switches 1, 5, and 13 ON.

% setenv COBOL_SWITCHES "9,11,16"  Sets switches 9, 11, and 16 ON.

% setenv COBOL_SWITCHES " "        Sets all switches OFF.

Following is a simple program that displays a message depending on the state of the environment variable COBOL_SWITCHES (on Tru64 UNIX systems:


IDENTIFICATION DIVISION.
PROGRAM-ID. TSW.

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES.
    SWITCH 12 IS SW12 ON IS SW12-ON OFF IS SW12-OFF.

PROCEDURE DIVISION.
01-S.
    DISPLAY "**TEST SWITCHES**".
    IF SW12-ON
       DISPLAY "SWITCH 12 IS ON".
    IF SW12-OFF
       DISPLAY "SWITCH 12 IS OFF".

    DISPLAY "**END**".
    STOP RUN.
END PROGRAM TSW.

To test this program on a Tru64 UNIX system, compile and link it and then type the following:


% setenv COBOL_SWITCHES 12
% tsw

The output is as follows:


**TEST SWITCHES**
SWITCH 12 IS ON
**END**        <>

Switches on OpenVMS

On OpenVMS systems, to set switches from outside the image or for a process, use the DCL DEFINE or ASSIGN command to change the status of program switches as follows:


$ DEFINE COB$SWITCHES "switch-list"

The switch-list can contain up to 16 switches separated by commas. To set a switch ON, specify it in the switch-list. A switch is OFF (the default) if you do not specify it in the switch-list.

For example:


$ DEFINE COB$SWITCHES "1,5,13"   Sets switches 1, 5, and 13 ON.

$ DEFINE COB$SWITCHES "9,11,16"  Sets switches 9, 11, and 16 ON.

$ DEFINE COB$SWITCHES " "        Sets all switches OFF.

The order of evaluation for logical name assignments is image, process, group, system. System and group assignments (including HP COBOL program switch settings) continue until they are changed or deassigned. Process assignments continue until they are changed, deassigned, or until the process ends. Image assignments end when they are changed or when the image ends.

You should know the system and group assignments for COB$SWITCHES unless you have defined them for your process or image. To check switch settings, enter this command:


$ SHOW LOGICAL COB$SWITCHES

Use the DCL DEASSIGN command to remove the switch-setting logical name from your process and reactivate the group or system logical name (if any):


$ DEASSIGN COB$SWITCHES

To change the status of external switches during execution, follow these steps:

  1. Interrupt the image with a STOP (literal-string) COBOL statement. (Refer to the HP COBOL Reference Manual for more information.)
  2. Use the DCL DEFINE command to change switch settings.
  3. Continue execution with the DCL CONTINUE command. Be sure not to force the interrupted image to exit by entering a command that executes another image.

For information about these DCL commands, refer to the OpenVMS DCL Dictionary.

Following is a simple program that displays a message depending on the state of the logical name COB$SWITCHES (on OpenVMS systems):


IDENTIFICATION DIVISION.
PROGRAM-ID. TSW.

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES.
    SWITCH 12 IS SW12 ON IS SW12-ON OFF IS SW12-OFF.

PROCEDURE DIVISION.
01-S.
    DISPLAY "**TEST SWITCHES**".
    IF SW12-ON
       DISPLAY "SWITCH 12 IS ON".
    IF SW12-OFF
       DISPLAY "SWITCH 12 IS OFF".

    DISPLAY "**END**".
    STOP RUN.
END PROGRAM TSW.

On OpenVMS, to test the previous program, compile and link it and then type the following:


$ DEFINE COB$SWITCHES 12
$ RUN TSW

The output is as follows:


**TEST SWITCHES**
SWITCH 12 IS ON
**END**        <>

1.6 Special Information for Year 2000 Programming

Even subsequent to the turn of the millennium, there still exist potential disruptions in previously problem-free software where there are instances of a two-digit year field that should be a four-digit field. Programmers need to correct all such fields, as Hewlett-Packard cannot prevent problems that originate in application code.

Two-digit year formats used in controlling fields, or as keys in indexed files, can cause program logic to become ambiguous. It is a fundamental rule to use four-digit years instead of two-digit years in areas where sequential operations are driven from these values or for comparison of these values.

HP COBOL provides programmer access to four-digit and two-digit year formats:

4-digit FUNCTION CURRENT-DATE
4-digit FUNCTION DATE-OF-INTEGER
4-digit FUNCTION DATE-TO-YYYYMMDD
4-digit FUNCTION DAY-OF-INTEGER
4-digit FUNCTION DAY-TO-YYYYDDD
4-digit FUNCTION INTEGER-OF-DATE
4-digit FUNCTION INTEGER-OF-DAY
4-digit FUNCTION TEST-DATE-YYYYMMDD
4-digit FUNCTION TEST-DAY-YYYYDDD
4-digit FUNCTION WHEN-COMPILED
4-digit FUNCTION YEAR-TO-YYYY
   
2-digit ACCEPT FROM DATE
2-digit ACCEPT FROM DAY
4-digit ACCEPT FROM DATE YYYYMMDD
4-digit ACCEPT FROM DAY YYYYDDD

HP COBOL offers date functions that can be used in program logic that makes decisions about year order. The full four-digit year handled by the six functions listed should be used in internal program logic decisions that are based on years. External displays of year information can continue to use two-digit formats when that is appropriate.

You should check program logic in code that uses ACCEPT, to verify that millennium transition dates are properly handled.

The use of two-digit years in applications does not automatically create a problem, but a problem could exist. Programmers need to inspect each of their applications for two-digit year dependencies and change any such instances to check the full four-digit year value.


Previous Next Contents Index