Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

Change Oracle password without recompile

Change Oracle password without recompile

Problem:

How can I change my Oracle password without having to recompile my COBOL programs?

Resolution:

 

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.

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2014-12-16 13:54
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.