[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Reading Cobol Data files in Delphi

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month18 days, 5 hours left to enroll

830 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