Blue Theme Orange Theme Green Theme Red Theme
 
Team Foundation Server Hosting
Home | Forums | ASP.NET 2.0 Tutorials | Web Services | How Do I...? | Class Browser | WPF Quick Starts | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Nevron Gauge for SharePoint
Search :       Advanced Search »
Home » COBOL .NET » ODBC usage in .NET

ODBC usage in .NET

This article will provide a template of how to represent a smallint, integer, decimal, varchar and other ODBC data types that are used in the SQL Server environment in COBOL.

Author Rank :
Page Views : 4120
Downloads : 32
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
ODBCinCobolNet.zip
 
 
Nevron Gauge for SharePoint
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 

COBOL and ODBC Data Types

This article will provide a template of how to represent a smallint, integer, decimal, varchar and other ODBC data types that are used in the SQL Server environment in COBOL. 

 The use of relational database systems is nothing new to COBOL. For years developers have utilized DB/2 on the IBM Mainframes as well as Oracle. On the Microsoft platforms, SQL Server is the prevalent database of choice. For COBOL programmers on a Windows platform the issue has always been how to create variables that represent a smallint, integer, decimal, varchar or other such data types that are used in the SQL Server environment.

Preparation

Our environment consisted of Visual Studio 2003 Enterprise Edition, SQL Server 2000 and Fujitsu NetCOBOL for .NET V2.0.  There is a backup of the sample database in the zip file. The backup file is named coboldata.bkp. We will not review how to create or restore a SQL Server database in this article. For assistance with this please consult with your local IT personnel or DBA.

You will need to perform the following steps:

  1. Unzip the zip file into a clean directory.
  2. Create a database in SQL Server called COBOLData.
  3. Restore the file coboldata.bkp to the database created in Step #1.
  4. Create an ODBC data source pointing to COBOLData and call it ODBCSample.
  5. Rebuild the solution.

We will not review the steps necessary to configure the Fujitsu NetCOBOL for .NET environment to enable it to access the database via ODBC. The necessary files have already been created for you and are contained with in the ZIP file. The ODBC interface file is called ODBCSamp.INF and the COBOL runtime file is called COBOL85.CBR. Both of these files are located in the \bin\debug directory. The steps necessary to create these files however are:

  1. Create an Interface file utilizing the NetCOBOL ODBC Setup Tool.
  2. Create a Runtime Initialize file using the NetCOBOL Run-Time Environment Setup Tool.
  3. Within the Runtime Environment Setup tool, set the variable @ODBC_INF to point to the INF file created in Step #1.
  4. Both of these Tools can be found under the TOOLS menu item.



The Hard Stuff

This article is about configuring COBOL data types to access ODBC data types. To begin with we have to have a table with variables in SQL Server. The table we will be using is CBLDatTbl within the COBOLData database. It is defined as follows:

Each of the data types we will be using in the sample is defined above. The naming convention used is 'db' and then the name of the data type, such as SmallInt, or Integer. For the CHAR and VCHAR data types we accepted the default size values of 10 and 50 respectively.

In NetCOBOL for .NET, the COBOL project created is a ConsoleApplication and is a standard COBOL program. The program utilizes ACCEPT/DISPLAY statements to interact with the user and embedded SQL statements to access the database. In the WORKING-STORAGE SECTION, the definition of the host variables is accomplished within the BEGIN DECLARE section as follows:

Notice each of the variables is also defined as the data type we are accessing with a 'WS-' preceding each name. Each of the names in the WORKING-STORAGE SECTION contain the same name as the database definition (except for the prefix), so it will make relating the two data definitions a bit easier.

This is really the core of the article, the definition of the variables within COBOL to access the ODBC data types. NetCOBOL for .NET will recognize the definitions within COBOL, and through marshalling determine how to access and format the data from the SQL Server table. Within the NetCOBOL documentation is a table representing the relationships and providing further detail. Utilizing the CONTENTS tab of the help system, navigate to the NetCOBOL for .NET References and there you will see an entry for Mapping ODBC Data to COBOL Data. A little hint, until you become familiar with the data mapping, print out this page of the documentation. The NetCOBOL documentation system contains a wealth of information. Spend some time searching through it and you'll find quite a few examples of how to accomplish a great many tasks.

Accessing the Data

We will not review the PROCEDURE DIVISION in great detail. The intent of the article was to present how to establish COBOL data types that will access ODBC data types and this is accomplished in the WORKING-STORAGE SECTION with the BEGIN DECLARE SECTION and the definition of the HOST variables. The PROCEDURE DIVISION performs the following tasks:

  1. Connects to the database
  2. Declares a CURSOR to retrieve the data
  3. Opens the cursor
  4. Executes an in-line PERFORM statement where a FETCH is done to retrieve the data from the SQL table.
  5. Disconnects from the database and then exits the program.

Within the PERFORM loop you will notice the FETCH statement returns the data INTO the host variables we defined. There is no further conversion work required. The only formatting of data is on the DECIMAL field to properly display the decimal point and values to the right of it.

Wrap Up

Accessing ODBC data from COBOL is a matter of proper definition. With the WORKING-STORAGE fields defined with the equivalent PIC clauses as the ODBC data types your programs should have no problems processing data. Feel free to utilize this sample to experiment with adding records, deleting records or updating data. And as mentioned before, spend some time with the NetCOBOL Documentation. There is a wealth of information there just waiting to help you.

Happy Coding!

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Rick Malek
Rick Malek is a Systems Engineer with Fujitsu Software based in Minot, North Dakota. While his primary duties are pre-sales support, Rick also does Consulting and Training. He has worked with COBOL since 1984, originally working on an IBM mainframe with CICS, VSAM and DB2.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
 Comments

 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.