Migrating from Pro*COBOL
This chapter explains how to precompile and run with GixSQL programs written for Oracle Pro*COBOL, either on an Oracle database or on PostgreSQL.
Recommended settings
| Setting | Where | Why |
|---|---|---|
-N 2 |
gixpp | VARYING items with a 2-byte length (PIC S9(4) COMP), as Pro*COBOL |
--no-rec-code 1403 |
gixpp | SQLCODE of the “no record” condition, as Oracle, for WHENEVER NOT FOUND |
GIXSQL_NOREC_CODE=1403 |
environment | the same, at run time |
GIXSQL_AUTOCOMMIT=off |
environment | transactions are explicit with Pro*COBOL; on PostgreSQL, cursors need a transaction |
--code-end-col 512 |
gixpp | sources precompiled by procob with format=terminal ireclen=512, with code after column 72 |
A typical build is:
$ gixpp -e -S -N 2 --no-rec-code 1403 --code-end-col 512 \
-I /opt/gixsql/share/gixsql/copy -I copy -E ".,cpy,CPY" \
-i prog.pco -o prog.cob
$ cobc -x prog.cob -L /opt/gixsql/lib -lgixsql
$ export GIXSQL_NOREC_CODE=1403 GIXSQL_AUTOCOMMIT=off
$ export DATASRC=oracle://dbserver:1521/ORCLPDB1
$ ./prog
Connecting
Pro*COBOL programs connect with CONNECT :USR IDENTIFIED BY :PWD, optionally USING :DB-STRING with a SQL*Net alias. With GixSQL, the USING operand is a GixSQL connection string (Connection strings), not an Oracle alias.
Behavior of CONNECT ... IDENTIFIED BY without USING (mode 4 of the grammar is “unsupported”).
COMMIT WORK RELEASE and ROLLBACK WORK RELEASE end the transaction and close the connection.
Running on PostgreSQL
Programs written for Oracle can run on PostgreSQL, provided their SQL is compatible. The orafce extension provides many Oracle functions (NVL, DECODE, TO_DATE…). Its oracle schema must come before pg_catalog in the search path, so that oracle.to_date is used instead of the PostgreSQL to_date:
pgsql://dbserver/db?default_schema=myschema,oracle,pg_catalog,public
Common SQL differences: ROWNUM, outer joins (+), SYSDATE, empty strings and NULL, DUAL, sequences (seq.NEXTVAL).
Feature comparison
The table follows the chapters of the Pro*COBOL Programmer’s Guide.
| Pro*COBOL feature | GixSQL |
|---|---|
| Declare section | accepted, not required |
EXEC SQL INCLUDE |
supported |
Conditional precompilation (EXEC ORACLE IFDEF) |
not supported |
CONNECT ... IDENTIFIED BY, AT |
supported |
CONNECT :USR-PWD (user/password in one item) |
not supported |
COMMIT, ROLLBACK, SAVEPOINT, RELEASE |
supported |
SET TRANSACTION, LOCK TABLE |
passed to the database |
| Host variables, indicator variables | supported |
VARCHAR / VARYING variables (2-byte length) |
supported with -N 2 |
Datatype equivalencing (EXEC SQL VAR) |
partial: see Host variables and datatypes |
EXEC SQL TYPE |
not supported |
Universal ROWID |
fetched as character strings (Oracle) |
SELECT INTO, INSERT, UPDATE, DELETE |
supported |
Cursors, WHERE CURRENT OF |
supported |
Scrollable cursors (FETCH PRIOR, ABSOLUTE…) |
not supported |
Embedded PL/SQL blocks (EXEC SQL EXECUTE BEGIN ... END; END-EXEC) |
not supported |
| Host tables (arrays) | not supported |
| SQLCA | supported |
| ORACA | not supported |
WHENEVER (SQLERROR, SQLWARNING, NOT FOUND) |
supported |
WHENEVER ... DO, STOP |
not supported |
| Dynamic SQL methods 1, 2, 3 | supported |
| Dynamic SQL method 4 (SQLDA), ANSI dynamic SQL (descriptors) | not supported |
| Runtime contexts, multithreading | not supported |
| LOB statements | not supported |
| Precompiler options | see the correspondence below |
Each “not supported” line above, in particular SET TRANSACTION, EXEC SQL TYPE, scrollable cursors, WHENEVER ... DO, and the generic passthrough of unknown statements.
Precompiler options
procob option |
gixpp equivalent |
|---|---|
INAME, ONAME |
-i, -o |
INCLUDE |
-I |
FORMAT=TERMINAL, IRECLEN |
--code-end-col |
MODE=ANSI (SQLCODE 100 on “no record”) |
default |
MODE=ORACLE (SQLCODE 1403) |
--no-rec-code 1403 |
PICX=VARCHAR2 |
-P varchar |
PICX=CHARF |
-P charf (default) |
VARCHAR=YES |
level-49 groups are always recognized |
SQLCHECK, USERID |
no equivalent: no semantic checking |
RELEASE_CURSOR, HOLD_CURSOR, MAXOPENCURSORS |
no equivalent |
Check MODE and PICX against the Pro*COBOL documentation.