?
Solved

Reading Cobol Data files in Delphi

Posted on 1997-12-04
2
Medium Priority
?
1,195 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 400 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month10 days, 8 hours left to enroll

765 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