[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Reading Cobol Data files in Delphi

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

650 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