OpenCOBOL Try 2

Cobol has been a thorn in my side for a long time. Working for software vendors, it’s not a given that Cobol is installed because they don’t always need to run payroll and don’t have production instances.

It’s been a while since I have played with OpenCOBOL. It’s been so long that they have renamed it to GnuCobol instead.

I’ve gotten closer so far, but I still can’t get past the database connection. Here’s my notes.

Setup

First, I added the eth1 interface. The PUM comes with a host only connect by default. I didn’t want to affect the host only connection, so I added a second interface to the Virtualbox machine settings.

Next, I added the Oracle yum repository to make installing required packages easier.

cd /etc/yum.repos.d
wget http://public-yum.oracle.com/public-yum-el5.repo
yum list

These are the prerequisites needed for building…

yum install gmp-devel libtool db4 db4-devel

Note: If you look ahead, you’ll also want to install ncurses-devel and subversion as well.

Install

I downloaded Open Cobol. Now, it is actually called Gnu Cobol.

cp gnu-cobol-2.0_rc-2.tar.gz /opt
cd /opt
tar -xzvf gnu-cobol-2.0_rc-2.tar.gz
cd gnu-cobol-2.0
./configure
make
make install

Note, I just ran it all as root. The last make install line you would need sudo in front of.

At this point, I got a compile error, and it didn’t install. This is the end of the make output:

libtool: compile:  gcc -std=gnu99 -DHAVE_CONFIG_H -I. -I.. -I.. -O2 -pipe -finline-functions -fsigned-char -Wall -Wwrite-strings -Wmissing-prototypes -Wno-format-y2k -U_FORTIFY_SOURCE -MT libcob_la-screenio.lo -MD -MP -MF .deps/libcob_la-screenio.Tpo -c screenio.c  -fPIC -DPIC -o .libs/libcob_la-screenio.o
screenio.c:2505: error: conflicting types for ‘cob_field_display’
../libcob/common.h:1562: error: previous declaration of ‘cob_field_display’ was here
screenio.c:2523: error: conflicting types for ‘cob_field_accept’
../libcob/common.h:1566: error: previous declaration of ‘cob_field_accept’ was here
screenio.c:2550: error: conflicting types for ‘cob_screen_accept’
../libcob/common.h:1559: error: previous declaration of ‘cob_screen_accept’ was here
make[2]: *** [libcob_la-screenio.lo] Error 1
make[2]: Leaving directory `/opt/gnu-cobol-2.0/libcob'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/opt/gnu-cobol-2.0'
make: *** [all] Error 2
[/sorucecode]

Fix: install ncurse development package:

yum install ncurses-devel

Ran configure and make again. It worked this time.

Compiling

Created compile script (using the script from the old post)

su - psadm1
cd $PS_HOME/setup
vi gnucbl.sh
chmod +x gnucbl.sh

Here’s the script that I have so far. I do need to change it to accomodate the PS_APP_HOME. Right now, it only compiles the COBOL in the PS_HOME.

#!/bin/sh

if [ ! -e "$PS_HOME" ]; then
    BASEDIR=$(dirname "$0")
    PSCONFIG="$BASEDIR/../psconfig.sh"
    if [ -e "$PSCONFIG" ]; then
        . $PSCONFIG
    fi
fi
if [ -e "$PS_HOME" ]; then
    echo "PS_HOME = $PS_HOME"
else
    echo "Error -- PS_HOME not set or does not exist"
fi
LOGDIR=$PS_HOME/cblout
OUTDIR=$PS_HOME/cblopen
if [ ! -e "$LOGDIR" ]; then
    mkdir "$LOGDIR"
fi
if [ ! -e "$OUTDIR" ]; then
    mkdir "$OUTDIR"
fi
cd $PS_HOME/src/cbl
rm $LOGDIR/success.txt
rm $LOGDIR/fail.txt
for cbl in $(ls *.cbl); do
    echo "Compiling $cbl..."
    BASENAME=$(echo "$cbl" | sed 's/\..*$//')
    cobc -std=mf $cbl  -o "$OUTDIR/$BASENAME.so" -t "$LOGDIR/$BASENAME.lis" > $LOGDIR/$BASENAME.out 2>&1
    if [ "$?" == 0 ]; then
        echo "$cbl" >> $LOGDIR/success.txt
        echo "    success"
    else
        echo "$cbl" >> $LOGDIR/fail.txt
        echo "    fail"
    fi
done

Updating

I found several compile errors with programs. As best I could tell, the fixes were coded but were not in the release. So, I decided to give the current development code a try. That seemed to fix the compile errors.

yum install subversion

svn checkout https://svn.code.sf.net/p/open-cobol/code/trunk open-cobol-code

The svn command downloads the code. I ran the configure, make, and make install commands the way I did earlier.

OS Info Issue

The next issue is that it wouldn’t compile the COBOL because of a CBL_GET_OS_INFO procedure. As best I can tell, that is something that Microfocus COBOL has. Here’s the error message:

libcob: Cannot find module 'CBL_GET_OS_INFO'

I found it in:

  • PTPNETRT.cbl
  • PTPSQLRT.cbl

To fix it, I just commented out the call.

vi $PS_HOME/src/cbl/PTPSQLRT.cbl

Updated to:

      *        Skp -- Removed to use with GnuCobol
      *        CALL 'CBL_GET_OS_INFO' USING   PRMOS

To test, I ran it with this:

cobcrun PTPDBTST ORACLE/HR92U022/PS/PS/TST/167916//0

Required Library Errors

My next error was this:

libcob: Cannot find module 'C_SQLCNC'

I searched for a COBOL program that matched, but I didn’t find one:

find ../src/cbl -exec grep -il C_SQLCNC {} \;

So, I created this script to find the library:

#!/bin/bash

function searchLib() {
   results=$(nm -D "$1" | grep -i "$2")
   found=$?
   if [ $found -eq 0 ]; then
   echo "Found: $1"
   echo "$results"
   echo 
   echo 
   fi
}


#searchLib ./bin/libpssqlapi.so "$1"

find $PS_HOME -name \*.so | while read line; do
  searchLib $line "$1" \;
done

Here was the output:

$ ./setup/libSearch.sh C_SQLCNC       
Found: /opt/oracle/psft/pt/ps_home8.55.14/bin/libpssqlapi.so
000000000000fb40 T C_SQLCNC


Found: /opt/oracle/psft/pt/ps_home8.55.14/bin/libpssqlapi_ansi.so
000000000000e4f0 T C_SQLCNC

I attempted to include that path on the library path environment

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:/opt/oracle/psft/pt/ps_home8.55.14/bin/

Next, I attempted to call the COBOL from a C program.
Here’s the source to gnurun.c (I put it into cblopen:

#include <libcob.h>

extern int PTPDBTST();

int
main(int argc, char **argv)
{
          int ret;

                cob_init(argc, argv);

                  ret = PTPDBTST();

                    return ret;
}

I added the code to the cblopen directory, compiled it, and linked it together.

vi gnurun.c
cc -c `cob-config --cflags` gnurun.c
cobc -x -o gnurun gnurun.o PTPDBTST.so
./gnurun ORACLE/HR92U022/PS/PS/TST/167916//0

I linked in the library that I found earlier:

cobc -x -o gnurun gnurun.o PTPDBTST.so /opt/oracle/psft/pt/ps_home8.55.14/bin/libpssqlapi_ansi.so
/opt/oracle/psft/pt/ps_home8.55.14/bin/libpssqlapi_ansi.so: undefined reference to `PS_sqlsil'

With that message, I searched for that library:

setup/libSearch.sh PS_sqlsil

It found this library:
/opt/oracle/psft/pt/ps_home8.55.14/bin/libpsora_ansi64.so

So, I tried to link it like this:

cobc -x -o gnurun gnurun.o PTPDBTST.so /opt/oracle/psft/pt/ps_home8.55.14/bin/libpssqlapi_ansi.so /opt/oracle/psft/pt/ps_home8.55.14/bin/libpsora_ansi64.so

I attempted these two environment variables as well. The first one worked great as far as making it so that I could run it from anywhere and not have to be in the “cblopen” directory where I had compiled the open cobol output. The 2nd variable didn’t help at all. I’m not sure why it wasn’t working.

COB_LIBRARY_PATH=/opt/oracle/psft/pt/ps_home8.55.14/cblopen
COB_PRE_LOAD=/opt/oracle/psft/pt/ps_home8.55.14/bin/libpssqlapi_ansi.so

After adding the libpsora_ansi64.so library to the link command, I got this error message:

Application Program Failed
 Action Type     : SQL CONNEC
 In Pgm Section  : SQLRT:GG100 SQL-CONNECT                             
 With Return Code: 09977 
 Error Message   : SQLRT: Attempting to use Ansi API for a Unicode DB
 
FAIL TO CONNECT
PTPDBTST: 
Application Program Failed
 In Pgm Section  : CONNECT FAILED                                      
 With Return Code: 09977 
 Error Message   : SQLRT: Attempting to use Ansi API for a Unicode DB

This fixed the problem:

cobc -x -o gnurun gnurun.o PTPDBTST.so /opt/oracle/psft/pt/ps_home8.55.14/bin/libpssqlapi.so /opt/oracle/psft/pt/ps_home8.55.14/bin/libpsora64.so

Running through Process Scheduler

To get it to run from the process scheduler, I had to create the PSRUN script. I put it into $PS_HOME/bin/PSRUN

#!/bin/sh

echo $* >> $PS_HOME/cblout.log
echo $*

export COB_LIBRARY_PATH=$PS_HOME/cblopen
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:$PS_HOME/cblopen
$PS_HOME/cblopen/gnurun $2 | tee -a $PS_HOME/cblout.log

I can run it from the command line like this:

$ ./PSRUN PTPDBTST ORACLE/HR92U022/PS/PS/TST/167916//0PTPDBTST ORACLE/HR92U022/PS/PS/TST/167916//0
 
Application Program Failed
 Action Type     : SQL CONNEC
 In Pgm Section  : SQLRT:GG100 SQL-CONNECT                             
 With Return Code: 01045 
 Error Message   : ORA-01045: user PS lacks CREATE SESSION privilege; logon denied
 
FAIL TO CONNECT
PTPDBTST: 
Application Program Failed
 In Pgm Section  : CONNECT FAILED                                      
 With Return Code: 01045 
 Error Message   : ORA-01045: user PS lacks CREATE SESSION privilege; logon denied

I haven’t figured this issue out yet!

Resources

Leave a Comment

Your email address will not be published. Required fields are marked *