Change Oracle password without recompile
How can I change my Oracle password without having to recompile my COBOL programs?
Propose using environment variables and having COBOL access those.
Since Unix jobs are started by a shell, you can use this to your advantage when connecting to an Oracle database.
Your programs will run under your userid or they will have their own userid. If your userid is warren, then that userid is defined in your .profile file and it exists in your environment as $USER.
Lets assume that warren is the same userid that you use to connect to Oracle.
Now we need your Oracle password. Suppose it is braveheart. You would manually connect to Oracle as warren/braveheart.
You can create an environment variable for the Oracle password. We do that from the Unix command line by typing: export ORA_PASS=braveheart
Now that is in your environment as $ORA_PASS. Now that these variables exist in your environment, you can have your COBOL program access them by using the COBOL syntax:
1) DISPLAY UPON ENVIRONMENT-NAME.
2) ACCEPT FROM ENVIRONMENT-VALUE.
Here is a demo COBOL program that demonstrates how to do this:
IDENTIFICATION DIVISION. PROGRAM-ID. ERR114. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. DATA DIVISION. FILE SECTION. WORKING-STORAGE SECTION. 01 WS-USER-FIELD PIC X(15) VALUE SPACES. 01 WS-PASS-FIELD PIC X(15) VALUE SPACES. ***************************************************************** PROCEDURE DIVISION. DISPLAY "USER" UPON ENVIRONMENT-NAME. ACCEPT WS-USER-FIELD FROM ENVIRONMENT-VALUE. DISPLAY WS-USER-FIELD. DISPLAY "ORA_PASS" UPON ENVIRONMENT-NAME. ACCEPT WS-PASS-FIELD FROM ENVIRONMENT-VALUE. DISPLAY WS-PASS-FIELD. STOP RUN.
Explanation: The statement: DISPLAY "USER" UPON ENVIRONMENT-NAME causes COBOL to select the environment variable named $USER
The statement: ACCEPT WS-USER-FIELD FROM ENVIRONMENT-VALUE causes COBOL to write the value stored in environment variable $USER into the COBOL variable WS-USER-FIELD
The statement: DISPLAY "ORA_PASS" UPON ENVIRONMENT-NAME causes COBOL to select the environment variable named $ORA_PASS
The statement: ACCEPT WS-PASS-FIELD FROM ENVIRONMENT-VALUE causes COBOL to write the value stored in $ORA_PASS into the COBOL variable WS-PASS-FIELD
Now you have the Oracle userid stored in WS-USER-FIELD and the ORACLE password stored in WS-PASS-FIELD.
Next you can move these values to the Oracle host variable that you will use in the CONNECT statement.
In the future, when you change your Oracle password, you change the value stored in your environment variable from the Unix command line by typing: export ORA_PASS=stagehand
The next time the program runs, it reads in the new value without requiring a recompile.