Solved

Reading Cobol Data files in Delphi

Posted on 1997-12-04
2
1,145 Views
Last Modified: 2008-02-01
I need to read MS Cobol 2.0 data files in Delphi over a LAN. While I can easily read Line Sequential Files, I also have to read Sequential files and I just do not know how to read them. Moreover, the record length goes on varying in the Cobol data file. Could anybody tell me how to do this ?
0
Comment
Question by:zrogera
2 Comments
 
LVL 1

Accepted Solution

by:
anilms earned 100 total points
Comment Utility
First of all, let me explain how the Cobol data files are structured. Line Sequential files are like plain text files, with a CR LF at the end of every record. Therefore every record appears in a seperate line and you can directly read a line at a time in Delphi/Pascal. However, Sequential Files are different. In a sequential file, the records are just continuous. At the beginning of every record, there is a two byte integer which tells you what the record length is. So just read this two bytes first, find out the length of the record and read so many bytes. Also remember that the maxiumum record size is 65536 bytes. Keep on repeating this till you come to the end of the file. The code below should work properly for you :

var f:file;
    recsize,readsize:word;
    data:array[1..65536] of byte;

procedure process_seq_file;
begin
   {Assuming that you have already assigned the file name
    f- cobol sequential data file}
   reset(f,1);
   repeat
        blockread(f,recsize,2); // Read 2 bytes length
        blockread(f,data,recsize,readsize); //Read the data
        // Now your record is in the data array and the
        // data is available upto position recsize

        // Do your processing here
   until readsize=0;
   CloseFile(f)
end;
0
 

Author Comment

by:zrogera
Comment Utility
Wow, real quick answer. Tried it out. I suppose you can do the same with Relative files also ? (My data is mostly in Sequential and Line Sequential only) I had to write Cobol programs previously to convert from Sequential to Line Sequential. This stuff is really useful.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now