Difference between revisions of "Cobol and PostgreSQL"

From PostgreSQL_wiki
Jump to: navigation, search
(Practical introduction to GixSQL)
(gixsql precompilation)
 
(47 intermediate revisions by the same user not shown)
Line 1: Line 1:
GixSQL is a way in which Cobol programs are able to use modern database management systems in a Linux environment. A setup with a '''Cobol''' '''PostgreSQL''' program and a simple compilation workflow are below.
+
This chapter contains the description of a complete working example of a '''Cobol''' '''PostgreSQL''' program, the setup, source code and a simple compilation workflow are below.
  +
* Program name: pgcobol
  +
* Source code: pgcobol.cbl
  +
* Intermediate preprocessed source code file: pgcobol.cbsql
  +
* Cobol compiler output: pgcobol.out
  +
* Database: Employee, with table emptable
  +
* pgcobol print output file: pgcobol.prt
  +
GixSQL is a way in which Cobol programs are able to use modern database management systems in a Linux environment.
 
== Cobol ==
 
== Cobol ==
 
Cobol has been around for more than 60 years and will stay around for the foreseeable future, estimates are that there are about 800 billion lines of Business Cobol code around. The programs are heavily used, servicing about 80% of all financial and business transactions world wide.<br /><br />
 
Cobol has been around for more than 60 years and will stay around for the foreseeable future, estimates are that there are about 800 billion lines of Business Cobol code around. The programs are heavily used, servicing about 80% of all financial and business transactions world wide.<br /><br />
Line 9: Line 16:
 
== GixSQL links PostgreSQL and Cobol ==
 
== GixSQL links PostgreSQL and Cobol ==
 
PostgreSQL is getting more and more traction around the world, also in the big enterprises. Big enterprises have ample reason to stick to their Cobol program stack, in which they invested huge amounts of money. So if PostgreSQL is to make it to the business applications of the big enterprises, it has to find a way to interact in a reliable manner with Cobol. Enter the [https://github.com/mridoni/gixsql GixSQL] SQL preprocessor for Cobol.
 
PostgreSQL is getting more and more traction around the world, also in the big enterprises. Big enterprises have ample reason to stick to their Cobol program stack, in which they invested huge amounts of money. So if PostgreSQL is to make it to the business applications of the big enterprises, it has to find a way to interact in a reliable manner with Cobol. Enter the [https://github.com/mridoni/gixsql GixSQL] SQL preprocessor for Cobol.
  +
=== An SQL statement in Cobol ===
  +
This is the way the SQL code is embedded in the Cobol program:
  +
<pre>
  +
EXEC SQL
  +
CONNECT TO :DATASRC AS cobol_sql USER :DBUSR USING :DBPWD
  +
END-EXEC.
  +
</pre>
  +
The example shows the program making a connection to the database with the variables DATASRC, DBUSR and DBPWD.
   
 
= Practical introduction to GixSQL =
 
= Practical introduction to GixSQL =
This chapter provides guidance to set up a working GixSQL for PostgreSQL development environment.
+
This chapter provides guidance to set up a working GixSQL for GNUCobol with PostgreSQL development environment.
 
== Prerequisites ==
 
== Prerequisites ==
 
* Debian 12
 
* Debian 12
 
* GnuCobol4
 
* GnuCobol4
 
* libmariadb-dev libmariadb-dev-compat libpq5 unixodbc libfmt9
 
* libmariadb-dev libmariadb-dev-compat libpq5 unixodbc libfmt9
* GixSQL
+
* GixSQL, find the link below
 
* optionally the PostgreSQL database server on the same machine.
 
* optionally the PostgreSQL database server on the same machine.
You obtain GixSQL here; [https://github.com/mridoni/gixsql/releases/download/v1.0.21dev/gixsql-debian-12-x64-1.0.21dev-1.deb GixSQL].
+
GixSQL is available here: [https://github.com/mridoni/gixsql/releases/download/v1.0.21dev/gixsql-debian-12-x64-1.0.21dev-1.deb GixSQL].
Just install the software in the sequence above and the system is ready to go.
+
Just install the software in the sequence as described above and the system is ready to go.<br />
  +
For reasons of convenience add the follow lines to /etx/profile:
  +
<pre>
  +
LD_DIRECTORY_PATH="/usr/local/src/gix/gixisql/runtime/libgixsql:/usr/local/src/gix/gixsql/common:/usr/local/src/gix/gixsql/common"
  +
export LD_DIRECTORY_PATH
  +
</pre>
   
 
== Workflow ==
 
== Workflow ==
Line 29: Line 49:
 
# Inspect the compilation listing
 
# Inspect the compilation listing
 
# Run the program
 
# Run the program
  +
== Simple Workflow script ==
  +
The python script [[gixc.py]] implements the GixSQL Cobol compilation workflow. It is invoked with a single parameter, being the program_name suffixed by either 'cbl or 'cob'. People that like to get their hands dirty follow the two steps below.
 
=== gixsql precompilation ===
 
=== gixsql precompilation ===
 
The command invoking the precompile process is as follows:<br/>
 
The command invoking the precompile process is as follows:<br/>
 
<pre>
 
<pre>
/usr/bin/gixsql cobolpostgresql.cbl cobolpostgresql.cbsql -S -I . -e ".,*.cpy,*.CPY"
+
/usr/bin/gixsql pgcobol.cbl pgcobol.cbsql -S -I . -e ".,*.cpy,*.CPY"
  +
</pre>
  +
The input file is pgcobol.cbl, the preprocessing output file is [[pgcobol.cbsql]]. It is very important to leave the cbsql file as is, because meddling with the file easily leads to errors in the next step of the workflow.<br /><br />
  +
The result of the precompile step of the SQL stement above looks like this:
  +
<pre>
  +
GIXSQL* EXEC SQL
  +
GIXSQL* CONNECT :DBUSR IDENTIFIED BY :DBPWD USING :DATASRC
  +
GIXSQL* CONNECT TO :DATASRC AS cobol_sql USER :DBUSR USING :DBPWD
  +
GIXSQL* CONNECT TO "pgsql://localhost:5432/cobol_gixsql"
  +
GIXSQL* USER :DBUSR USING :DBPWD
  +
GIXSQL* END-EXEC.
  +
GIXSQL CALL STATIC "GIXSQLConnect" USING
  +
GIXSQL BY REFERENCE SQLCA
  +
GIXSQL BY REFERENCE DATASRC
  +
GIXSQL BY VALUE 64
  +
GIXSQL BY REFERENCE "cobol_sql" & x"00"
  +
GIXSQL BY VALUE 0
  +
GIXSQL BY REFERENCE x"00"
  +
GIXSQL BY VALUE 0
  +
GIXSQL BY REFERENCE DBUSR
  +
GIXSQL BY VALUE 64
  +
GIXSQL BY REFERENCE DBPWD
  +
GIXSQL BY VALUE 64
  +
GIXSQL END-CALL.
 
</pre>
 
</pre>
The input file is cobolpostgresql.cbl, the preprocessing output file is cobolpostgresql.cbsql. It is very important to leave the cbsql file as is, because meddling with the file easily leads to errors in the next step of the workflow.
 
   
 
=== The cobc GNUCobol compilation ===
 
=== The cobc GNUCobol compilation ===
 
The command invoking the precompile process is as follows:
 
The command invoking the precompile process is as follows:
 
<pre>
 
<pre>
/usr/bin/cobc -x cobolpostgresql.cbsql -l:libgixsql.so -T cobolpostgresql.out
+
/usr/bin/cobc -x pgcobol.cbsql -l:libgixsql.so -T pgcobol.out
 
</pre>
 
</pre>
This results in the executable program file '''cobolpostgresql''' and the compilation listing cobolpostgresql.out.
+
This results in the executable program file '''pgcobol''' and the compilation listing [[pgcobol.out]].
   
 
== Sample Program ==
 
== Sample Program ==
The sample program makes use of the sample database: [[cobolpostgresql.cbl]].
+
The sample program [[pgcobol.cbl]] makes use of the sample database: employee. When executed pgcobol puts out the file [[pgcobol.prt]].<br />
  +
The pgcobol program file is available for download here: [https://wiki.webhuis.nl/images/pgcobol.cbl pgcobol.cbl ].
   
 
== Sample database ==
 
== Sample database ==
 
The [[employee database]] is a very simple database, with one table containing three lines. The pg_dump file is in the link.
 
The [[employee database]] is a very simple database, with one table containing three lines. The pg_dump file is in the link.
 
== Simple Workflow script ==
 
The python script [[gixc.py]] implements the GixSQL Cobol compilation workflow. It is invoked with a single parameter, being the program_name suffixed by either 'cbl or 'cob'.
 
 
<hr/>
 
<hr/>
 
Back to: [[voorpagina]]
 
Back to: [[voorpagina]]

Latest revision as of 21:37, 7 November 2025

This chapter contains the description of a complete working example of a Cobol PostgreSQL program, the setup, source code and a simple compilation workflow are below.

  • Program name: pgcobol
  • Source code: pgcobol.cbl
  • Intermediate preprocessed source code file: pgcobol.cbsql
  • Cobol compiler output: pgcobol.out
  • Database: Employee, with table emptable
  • pgcobol print output file: pgcobol.prt

GixSQL is a way in which Cobol programs are able to use modern database management systems in a Linux environment.

Cobol

Cobol has been around for more than 60 years and will stay around for the foreseeable future, estimates are that there are about 800 billion lines of Business Cobol code around. The programs are heavily used, servicing about 80% of all financial and business transactions world wide.

The reason behind this endurance lies in the fact that Cobol is a standardised language, a program written in 1974 can be compiled today with a modern compiler. The resulting executable program still runs today, without the need of adaptation. This very fact is of high value to enterprises, their investments are safe and well protected on the long term.

Traditionally Cobol programs have their application in big business mainframe environments. These large enterprises, however, are shifting more and more of their applications to the Linux platform. The broad adoption of Linux in the enterprise environment started around 2010. So, it is no wonder that Cobol gradually is being made available for the Linux platform, enter GNUCobol.

GNUCobol

Is an Open Source Cobol compiler, the project originally started in 2002 GNUCobol as OpenCobol. GNUCobol now is a full blown Cobol compiler.

GixSQL links PostgreSQL and Cobol

PostgreSQL is getting more and more traction around the world, also in the big enterprises. Big enterprises have ample reason to stick to their Cobol program stack, in which they invested huge amounts of money. So if PostgreSQL is to make it to the business applications of the big enterprises, it has to find a way to interact in a reliable manner with Cobol. Enter the GixSQL SQL preprocessor for Cobol.

An SQL statement in Cobol

This is the way the SQL code is embedded in the Cobol program:

           EXEC SQL
              CONNECT TO :DATASRC AS cobol_sql USER :DBUSR USING :DBPWD
           END-EXEC.

The example shows the program making a connection to the database with the variables DATASRC, DBUSR and DBPWD.

Practical introduction to GixSQL

This chapter provides guidance to set up a working GixSQL for GNUCobol with PostgreSQL development environment.

Prerequisites

  • Debian 12
  • GnuCobol4
  • libmariadb-dev libmariadb-dev-compat libpq5 unixodbc libfmt9
  • GixSQL, find the link below
  • optionally the PostgreSQL database server on the same machine.

GixSQL is available here: GixSQL. Just install the software in the sequence as described above and the system is ready to go.
For reasons of convenience add the follow lines to /etx/profile:

LD_DIRECTORY_PATH="/usr/local/src/gix/gixisql/runtime/libgixsql:/usr/local/src/gix/gixsql/common:/usr/local/src/gix/gixsql/common"
export LD_DIRECTORY_PATH

Workflow

Once the editing of the program is finished, the program has to be compiled. This is done in various steps, but this can also be done by using the Python script below.
The steps are:

  1. The precompile process
  2. Inspect (but do not edit the output)
  3. The compilation process
  4. Inspect the compilation listing
  5. Run the program

Simple Workflow script

The python script gixc.py implements the GixSQL Cobol compilation workflow. It is invoked with a single parameter, being the program_name suffixed by either 'cbl or 'cob'. People that like to get their hands dirty follow the two steps below.

gixsql precompilation

The command invoking the precompile process is as follows:

/usr/bin/gixsql pgcobol.cbl pgcobol.cbsql -S -I . -e ".,*.cpy,*.CPY"

The input file is pgcobol.cbl, the preprocessing output file is pgcobol.cbsql. It is very important to leave the cbsql file as is, because meddling with the file easily leads to errors in the next step of the workflow.

The result of the precompile step of the SQL stement above looks like this:

GIXSQL*    EXEC SQL
GIXSQL*       CONNECT :DBUSR IDENTIFIED BY :DBPWD USING :DATASRC
GIXSQL*       CONNECT TO :DATASRC AS cobol_sql USER :DBUSR USING :DBPWD
GIXSQL*       CONNECT TO "pgsql://localhost:5432/cobol_gixsql"
GIXSQL*                USER :DBUSR USING :DBPWD
GIXSQL*    END-EXEC.
GIXSQL     CALL STATIC "GIXSQLConnect" USING
GIXSQL         BY REFERENCE SQLCA
GIXSQL         BY REFERENCE DATASRC
GIXSQL         BY VALUE 64
GIXSQL         BY REFERENCE "cobol_sql" & x"00"
GIXSQL         BY VALUE 0
GIXSQL         BY REFERENCE x"00"
GIXSQL         BY VALUE 0
GIXSQL         BY REFERENCE DBUSR
GIXSQL         BY VALUE 64
GIXSQL         BY REFERENCE DBPWD
GIXSQL         BY VALUE 64
GIXSQL     END-CALL.

The cobc GNUCobol compilation

The command invoking the precompile process is as follows:

/usr/bin/cobc -x pgcobol.cbsql -l:libgixsql.so -T pgcobol.out

This results in the executable program file pgcobol and the compilation listing pgcobol.out.

Sample Program

The sample program pgcobol.cbl makes use of the sample database: employee. When executed pgcobol puts out the file pgcobol.prt.
The pgcobol program file is available for download here: pgcobol.cbl .

Sample database

The employee database is a very simple database, with one table containing three lines. The pg_dump file is in the link.


Back to: voorpagina