Skip to content

Oracle

COBOL-IT’s COBOL-IT® Compiler Suite has been certified for use with Oracle Pro*COBOL, and the Oracle Database 11g Enterprise Edition, allowing users to embed SQL statements into their COBOL programs, and retrieve, manage, and manipulate corporate data stored in their Oracle database.

COBOL/ESQL operations that have been written and tested in proprietary mainframe environments do not need to be re-engineered, thereby lowering the costs and risks associated with Enterprise Application Modernization. The Oracle Pro*COBOL precompiler takes these COBOL-IT programs containing ESQL statements as input, and produces as output COBOL programs in which the ESQL statements have been translated into calls to functions in Oracle libraries. These COBOL programs can then be compiled by the COBOL-IT Compiler, with the result being object code that has access to the Oracle database.

This chapter describes the different steps needed to link Oracle(tm) with a COBOL-IT program.

We suppose that Oracle Client is installed in $ORACLE_HOME and $ORACLE_HOME/bin is in your PATH.

In our example below, we examine the different steps in handling a program called testsql.cbl, which contains ESQL COBOL statements designed to interact with the Oracle database.

The first case we will examine follows the normal course of actions, which are:

  • Precompile the COBOL source program with procob, Oracle’s ESQL/COBOL precompiler. The process of precompiling commands out all ESQL statements and replaces them with CALL's to routines provided by Oracle, in a new output file. Topics covered include:

  • Initiating the precompiler from within a script (Linux/Unix), or batch file (Windows). There may be some advantages to separating the Precompile step from the Compile step.

  • Invoking the precompiler on the command line, using the -preprocess=cmd compiler flag.

  • Compile the output file with cobc. Structure the compile line such that it links in the necessary libraries provided by Oracle, to ensure that the CALL's will be resolved.

Topics covered also include:

  • Constructing a compiler command with link commands for Oracle libraries.
  • Changes to Compiler Configuration Flags.
  • Running the compiled object with cobcrun.

Then, we will examine debugging considerations. Topics covered include:

  • Relinking the Deet debugger with Oracle libraries.
  • How to debug original source
  • How to debug precompiled source

-preprocess=cmd

To provide greater compatibility with other COBOL compilers, COBOL-IT provides the ability to invoke a precompiler on the command line, using the –preprocess=cmd compiler flag.

If your preference in debugging is to debug original source, as opposed to debugging precompiled source, you should make use of –preprocess=cmd, which provides this capability.

Note that if, while debugging original source, you need a finer level of tracing on the Exec SQL Statements in your code, you can also use the –fdebug-exec compiler flag for extra tracing capabilities.

For details on the use of -preprocess=cmd, see Guidelines for use of –preprocess=cmd. LINK?

Precompile the COBOL source program with procob

You may have scripts which separate the precompilation step from the compilation/link steps. In these cases, you would not need to use the -preprocess=cmd compiler flag.

First precompile the embedded SQL:

In Linux/Unix:

>procob iname=procobdemo.pco oname=procobdemo.cbl

In Windows:

Run: precomp procobdemo.pco procobdemo.cbl

       precomp.bat

       set ICHOME=C:\COBOL\INSTANTCLIENT_11_2
       set PCBCFG=%ICHOME%\precomp\admin\pcbcfg.cfg
       set PROCOB=%ICHOME%\sdk\procob.exe
       %PROCOB% iname=%1 config=%PCBCFG% ireclen=132 oname=%2

Changes to Compiler Configuration Flags

Then, make changes to the Compiler Configuration File:

The Oracle Pro*COBOL runtime requires binary field to be stored on 2, 4 or 8 bytes.
The Micro Focus IBMCOMP compiler flag corresponds to the binary size setting of 2-4-8.

binary-size: 2-4-8

Another problem with Oracle Pro*COBOL runtime is the fact that Oracle provides SQLCA structures declared with fields described as USAGE COMP.

By default COMP is Big-Endian on all platforms.

On Little-Edian platform, while those fields are declared as USAGE COMP, the Pro*COBOL runtime expects “native binary fields” to be stored in Little-Endian format, which should be declared as USAGE COMP-5.

There are two possible solutions:

Solution 1

You can set the binary-byteorder entry in the compiler configuration file to native.

       # Value: 'native', 'big-endian'
       binary-byteorder: native

Doing this causes all fields described as USAGE BINARY, USAGE COMPUTATIONAL or USAGE COMP to be stored as USAGE COMP-5, (Platform native format).

Note

This option is not recommended when you are operating on a Little-Endian platform, and using a file that has been generated on a Big-Endian platform, such as a Mainframe.

Solution 2

You use the -makesyn ”COMP=COMP 5” compiler flag when compiling preprocessed source. Note that when using this solution, you are making the declaration USAGE COMP synonymous with the declaration USAGE COMP 5. This usage of the -makesyn compiler flag would have no effect on data items declared as USAGE COMPUTATIONAL.

Note that in the COBOL-IT implementation of the -makesyn compiler flag, the first word becomes a synonym of the second word.

This is similar to the MAKESYN directive implemented by Micro Focus. The same result in Micro Focus, would be declared as: MAKESYN"COMP-5"="COMP". Note that in this implementation, the second word becomes a synonym of the first word.

Any changes that have been made to the compiler configuration file should be SAVE’d in a new configuration file called oraconf.conf. This will prevent the settings from being overwritten when you install an update to your compiler.

To have your compiler reference the new configuration file (for example, oraconf.conf), add the compiler flag –conf=oraconf.conf to your compile string.

Note

You can name this configuration file whatever you want, provided it has a .conf extension, and provided that it is saved in the $COBOLITDIR/config directory (Linux/Unix) or %COBOLITDIR%\config (Windows).

Creating native executables

Then compile the generated source testsql.cbl and link Oracle libraries:

In Linux/Unix:

       >cobc
       conf=oraconf.conf x testsql.cbl
       $ORACLE_HOME/precomp/lib/cobsqlintf.o L $ORACLE_HOME/lib/ l
       clntsh

Note

This example was done on Linux SLES 10 , other platforms may require additional system library.

In Windows:

       >set ICHOME=C:\INSTANTCLIENT_11_2
       >set ICLIBHOME=%ICHOME%\sdk\lib\msvc
       >set PCBCFG=%ICHOME%\precomp\admin\pcbcfg.cfg
       >set SQLLIB_lib=orasql11.lib
       >cobc -conf=myconf.conf -c procobdemo.cbl -o procobdemo.obj
       >cobc -x procobdemo.obj %ICLIBHOME%\%SQLLIB_lib%

Building a new cobcrun

In Linux/Unix environments, if your preference is to use cobcrun to launch compiled objects which need to access the Oracle database, then you will need to build a new cobcrun, with commands that link the necessary Oracle libraries with cobcrun.

To build your own cobcrun that includes an Oracle CALL entry point:

In Linux/Unix:

       $ cobc -x -flink only -o cobcrun  
       $COBOLITDIR/lib/cobol it/cobcrun.o  
       $ORACLE_HOME/precomp/lib/cobsqlintf.o -L $ORACLE_HOME/lib/
       -lclntsh  

Replace the existing cobcrun with the newly created cobcrun, and make sure it is in your PATH.

In Windows:
Note that in Windows, it is not necessary to create a new cobcrun. Windows commands for creating shared objects, and running with cobcrun:

       >set ICHOME=C:\COBOL\INSTANTCLIENT_11_2
       >set ICLIBHOME=%ICHOME%\sdk\lib\msvc
       >set PCBCFG=%ICHOME%\precomp\admin\pcbcfg.cfg
       >set SQLLIB_lib=orasql11.lib
       >cobc -conf=oraconf.conf -c procobdemo.cbl -o procobdemo.obj
       >cobc -b procobdemo.obj %ICLIBHOME%\%SQLLIB_lib%

Run the compiled object (native executable)

In Linux/Unix:

./procobdemo

In Windows:

>procobdemo.exe

Run the compiled object (shared object)

In Linux/Unix/Windows:

cobcrun procobdemo

In summary

You can combine the compile and run commands above into scripts (Linux/Unix) or batch files (Windows) as follows:

In Linux/Unix:

       >procob iname=procobdemo.pco ireclen=132 oname=procobdemo.cbl  
       >cobc -conf=oraconf.conf -x procobdemo.cbl $ORACLE_HOME/precomp/
       lib/cobsqlintf.o -L $ORACLE_HOME/lib/ -l clntsh
       >./procobdemo

In Windows:

       >set ICHOME=C:\INSTANTCLIENT_11_2
       >set ICLIBHOME=%ICHOME%\sdk\lib\msvc
       >set PCBCFG=%ICHOME%\precomp\admin\pcbcfg.cfg
       >set SQLLIB_lib=orasql11.lib
       >set PROCOB=%ICHOME%\sdk\procob.exe
       >%PROCOB% iname=%1 config=%PCBCFG% ireclen=132 oname=%2
       >cobc -conf=myconf.conf -c procobdemo.cbl -o procobdemo.obj
       >cobc -x procobdemo.obj %ICLIBHOME%\%SQLLIB_lib%
       >procobdemo.exe

The output from procobdemo is:

       CONNECTED TO ORACLE AS USER:       scott

       SALESPERSON   SALARY        COMMISSION
       -----------   ----------     ----------
       ALLEN         1600.00       300.00
       WARD          1250.00       500.00
       MARTIN        1250.00       1400.00
       TURNER        1500.00       0.00

       HAVE A GOOD DAY.

Debugging considerations: Build a cobcdb debugger with Oracle runtime

On Linux/Unix machines, debugger access to Oracle subroutines requires that Oracle libraries be re-linked with cobcdb.

Note

To debug a COBOL executable that has been linked with Oracle libraries, you need to link the same Oracle libraries into the debugger launcher (cobcdb).

To build your own cobcdb including an Oracle CALL entry point:

In Linux/Unix:

       >cobc -x -flink-only -o cobcdb 
       $COBOLITDIR/lib/cobol-it/cobcdb.o -lcitsupport  
       $ORACLE_HOME/precomp/lib/cobsqlintf.o -L $ORACLE_HOME/lib/
       -lclntsh

Replace the existing cobcdb with the newly created cobcdb, and make sure it is in your PATH.

Using cobcrun and cobcdb with Oracle (Windows)

In Windows environments, the CALL statements generated by the precompiling process are resolved in calls to DLLs, which are provided by Oracle and installed on the Oracle client workstation. In Windows environments, it is not necessary to rebuild cobcrun, and cobcdb, as the CALL statements are resolved dynamically.

Using cobcdb with applications that make CALL's to Oracle libraries:

In Windows environments, generate a single dynamically loadable module (DLL) that includes the SQL library
(orasql11.lib for Oracle 11) provided by Oracle, as in the example below.

The following script creates procobdemo.dll, which can then be executed with the command cobcdb procobdemo. This example presumes that procobdemo.pco has already been precompiled, producing procobdemo.cbl as the output file.

       >set ICHOME=C:\INSTANTCLIENT_11_2 
       >set ICLIBHOME=%ICHOME%\sdk\lib\msvc  
       >set SQLLIB_lib=orasql11.lib 
       >cobc -g -conf=myconf.conf -c procobdemo.cbl -o procobdemo.obj  
       >cobc -b procobdemo.obj %ICLIBHOME%\%SQLLIB_LIB%
       >cobcdb procobdemo

cobcdb procobdemo using –preprocess –fdebug-exec

Using –preprocess causes the debugger to display original source, and not the translations to CALL statements produced by the precompiler.

Building a new rtsora

When using Oracle in Linux/Unix environments, you may need to rebuild rtsora. First ensure that you have a link to cobmf (MF Command line emulator).

In Linux/Unix:

       >ln -s $COBOLITDIR/bin/cobmf $COBOLITDIR/bin/cobc  
       >cd $ORACLE_HOME/precomp/lib/  
       >export RTSPORTFLAGS="$COBOLITDIR/lib/cobol-it/cobcrun.c -CIT 
       -fno-main"  
       >make -f ins_precomp.mk relink EXENAME=rtsora 

This command creates the new executable in the $ORACLE_HOME/precomp/lib directory, and then moves it to the $ORACLE_HOME/bin directory.

To create the new executable without moving it to the $ORACLE_HOME/bin directory, enter the following command:

>make -f ins_precomp.mk rtsora

About the Oracle® sample program procobdemo.pco

In order to run the Oracle® sample program procobdemo.pco, you need to download the Client software, and the Instant Client, in addition to the Oracle Database. Oracle Database and Client software needs to be installed. The Instant Client package then can be unzipped into the directory of your choice. The Oracle® precompiler procob is contained in the Instant Client package, as is the demo program procobdemo.pco, along with sample scripts for running it. We include the following observations we made about compiling and running procobdemo.

The sample program procobdemo.pco makes CALL's to ORASQL8.DLL. ORASQL8.DLL is located in %ORACLE_HOME% client_1 BIN directory, as is ORASQL11.DLL, which must be substituted for ORASQL8.DLL in order to run the sample procobdemo.pco.

To substitute ORASQL11.DLL for ORASQL8.DLL:

       >ren ORASQL8.DLL ORASQL8.DLL.BAK
       >copy ORASQL11.DLL ORASQL8.DLL

Note

Administrator privileges are required to rename ORASQL11.DLL to ORASQL8.DLL.

We also observed when running the sample program, that when running procobdemo, we initially received the error:

Error: ORA-28000 - the account is locked

This is a well documented issue. To resolve this, first run SQLPLUS, and then following command:

       SQL>CONNECT sys/(PASSWORD) AS SYSDBA;  
       SQL>ALTER USER scott IDENTIFIED BY tiger ACCOUNT UNLOCK;
Back to top