Solved

Reading Cobol Data files in Delphi

Posted on 1997-12-04
2
1,183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
anilms earned 100 total points
ID: 1352915
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
ID: 1352916
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

691 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