HOME  NEWS  FORUM  DOWNLOAD  LINK
OpenCOBOL - an open-source COBOL compiler
Main Menu
Download
Documentation
Development
Who's Online
15 user(s) are online (10 user(s) are browsing Forum)

Members: 0
Guests: 15

more...
Powered by
SourceForge

Xoops

Creative Commons

OpenCOBOL Forum Index
   OpenCOBOL
     Open cobol and databases
Register To Post

Threaded | Newest First Previous Topic | Next Topic | Bottom
Poster Thread
norbertm
Posted on: 2010/7/26 16:14
Just popping in
Joined: 2010/7/22
From:
Posts: 3
Open cobol and databases
Hello,
i am working since 1980 with cobol, but the last 15 years, there were no possibilities to work with that language. So i m not on top of information. Is it possible to access Databases MS Access) with open cobol, and if yes, please give me an example
human
Posted on: 2010/7/26 19:46
Home away from home
Joined: 2007/5/15
From:
Posts: 967
Re: Open cobol and databases
You would need an ODBC wrapper for that (enabling you to use CALL xyz to access the files) and I'm not aware of something you could use out-of-the-box.

human
Franklin
Posted on: 2010/7/27 6:08
Not too shy to talk
Joined: 2006/6/22
From: Hamburg, Germany
Posts: 21
Re: Open cobol and databases
You could try the ESQL for ODBC for OpenCobol from Sergey,
you will find it here: http://www.kiska.net/opencobol/esql/
This consists of a precompiler for embedded SQL and a runtime library to actually access the ODBC database.

Franklin
norbertm
Posted on: 2010/7/28 8:13
Just popping in
Joined: 2010/7/22
From:
Posts: 3
Re: Open cobol and databases
ok thanks, i have found them. But how must this programms be installed in the cobol enviroment?
in former times cobol was running as sub program, f.e under dl1. The first statment was an entry 'dl1tocbl'. How found cobol nopw the link to the sql software?
wmklein
Posted on: 2010/7/28 10:11
Home away from home
Joined: 2008/12/27
From:
Posts: 243
Re: Open cobol and databases
For non-IBM people
dl1
tells me that this was (originally) an IBM, IMS program. I don't think anyone has tried to "integrate" any IMS emulator with OpenCOBOL, but I could be mistaken on that.

However, if your "database" program is ONLY SQL, then everything should be fine. If it is IMS, then I think this is a "new" area for research.
norbertm
Posted on: 2010/7/28 16:33
Just popping in
Joined: 2010/7/22
From:
Posts: 3
Re: Open cobol and databases
Sorry but you did'nt understand my intension. I don't want to get DL1 back. Time of this is over.
It is my inetrest, to understand, how the communication between cobol and sql-interface take place.
But first of all the inforamtion how to integrate the sql interface to open cobol.
Please give me an install guide.
THanks.
Franklin
Posted on: 2010/7/29 11:50
Not too shy to talk
Joined: 2006/6/22
From: Hamburg, Germany
Posts: 21
Re: Open cobol and databases
I'm sorry there is no installation guide for this.

I just wrote you a small sample program to get you on your way.

Create an Access Database called MYTESTDB.
The table definition can also be found in my sample code.
Setup an ODBC datasource to this database.
You can paste this code in to a file called "testsql.sqb"

Now precompile this file with the following command:

esqlOC -static testsql.sqb

After this you should be able to see the results in a file called "testsql.cob", this is the source that you can compile using OC.

I hope this helps you!

Franklin

       IDENTIFICATION DIVISION.
       PROGRAM-ID. TESTSQL.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
      *--------------------------------------------------*
      *   CREATE TABLE MYCONTACTS (
      *                FIRSTNAME CHAR(20) NOT NULL,
      *                LASTNAME  CHAR(20) NOT NULL,
      *                TELEPHONE CHAR(20) NOT NULL,
      *                EMAILADDR CHAR(80) NOT NULL )
      *--------------------------------------------------*
           EXEC SQL BEGIN DECLARE SECTION END-EXEC.

       01  HOSTVARS.
           05 DBNAME               PIC X(08) VALUE 'MYTESTDB'.
           05 FIRSTNAME            PIC X(20) VALUE SPACE.
           05 LASTNAME             PIC X(20) VALUE SPACE.
           05 TELEPHONE            PIC X(20) VALUE SPACE.
           05 EMAILADDR            PIC X(80) VALUE SPACE.

           EXEC SQL END DECLARE SECTION END-EXEC.
           EXEC SQL DECLARE C1 CURSOR FOR
                      SELECT FIRSTNAME,
                             LASTNAME,
                             TELEPHONE,
                             EMAILADDR
                        FROM MYCONTACTS
                    ORDER BY LASTNAME ASC,
                             FIRSTNAME ASC
           END-EXEC.
           EXEC SQL INCLUDE SQLCA       END-EXEC.

       PROCEDURE DIVISION.
       MAIN SECTION.

           PERFORM SQL-CONNECT
           PERFORM LIST-CONTACTS
           PERFORM SQL-DISCONNECT

           GOBACK
           .
      *--------------------------------------------------*
      * LIST THE CONTACTS FROM THE SQL TABLE CONTACTS
      *--------------------------------------------------*
       LIST-CONTACTS SECTION.

           EXEC SQL OPEN C1 END-EXEC.
           PERFORM SQLSTATE-CHECK

           PERFORM UNTIL SQLSTATE NOT = '00000'
                   EXEC SQL FETCH C1 INTO
                               :FIRSTNAME,
                               :LASTNAME,
                               :TELEPHONE,
                               :EMAILADDR
                   END-EXEC
                   IF SQLSTATE = '00000'
                      DISPLAY FIRSTNAME, LASTNAME, TELEPHONE, EMAILADDR
                   END-IF
           END-PERFORM

           EXEC SQL CLOSE C1 END-EXEC.
           PERFORM SQLSTATE-CHECK
           .
      *--------------------------------------------------*
      * CONNECT TO THE DATABASE
      *--------------------------------------------------*
       SQL-CONNECT SECTION.

           EXEC SQL CONNECT TO :DBNAME END-EXEC.
           PERFORM SQLSTATE-CHECK
           .

      *--------------------------------------------------*
      * DISCONNECT FROM THE DATABASE
      *--------------------------------------------------*
       SQL-DISCONNECT SECTION.

           EXEC SQL CONNECT RESET END-EXEC.
           PERFORM SQLSTATE-CHECK
           .

      *--------------------------------------------------*
      * CHECK SQLSTATE AND DISPLAY ERRORS IF ANY
      *--------------------------------------------------*
       SQLSTATE-CHECK SECTION.
           IF SQLSTATE NOT = '00000' AND SQLSTATE NOT = '02000'
                      DISPLAY 'SQLSTATE='  SQLSTATE,
                              ', SQLCODE=' SQLCODE
              IF SQLERRML > 0
                 DISPLAY 'SQL Error message:' SQLERRMC(1:SQLERRML)
              END-IF
           END-IF
           .
btiffin
Posted on: 2010/7/30 8:09
Home away from home
Joined: 2008/6/7
From: CANADA
Posts: 755
Re: Open cobol and databases
norbertm;

Take a look at

http://www.opencobol.org/modules/newbb/viewtopic.php?topic_id=575&forum=1#forumpost3089

for samples of how to go about such things. You'll likely need to write some C and definitely need to manage the cobc -I and -l (little ell) and -L. Usually -l libname gets the proper linkage for your calls, -L to point to the dll file path.

Cheers,
Brian
JohnnyMac
Posted on: 2010/8/31 13:51
Just popping in
Joined: 2010/8/31
From: Boston Mass
Posts: 3
Re: Open cobol and databases
Hi Franklin, I am new to using OC with CYGWIN, I'm trying to access a MS Access DB and successfully created testsql.cob my following your precompile instructions, after I execute the dos2unix and cobc compile, I run ./testsql but get error datasource not found, so I opened the testsql.con and noticed that the SQL statements were all commented out, did I miss a step ?

Thanks JohnnyMac poster 9:51am from Boston MA on 8/31/2010
human
Posted on: 2010/8/31 19:27
Home away from home
Joined: 2007/5/15
From:
Posts: 967
Re: Open cobol and databases
SQL-statements must be commented out by the pre-parser and there has to be some stuff (mainly calls) inserted (this is how SQL-pre-parser always work).

I guess you didn't create the ODBC data source named MYTESTDB pointing to you Access DB?

human
(1) 2 »
Threaded | Newest First Previous Topic | Next Topic | Top

Register To Post
 
Copyright (C) 2005 The OpenCOBOL Project. All rights reserved.
Powered by Xoops2 | PHP | MySQL | Apache
ocean-net