Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determine input File size and MAX Record length

Status
Not open for further replies.

tuipeatau

Programmer
Oct 20, 2002
6
AU
Hi All,

I need to determine the size of an input file which contains variable records. The goal is to split this input file into smaller files of 2megs in size.

For instance, if we get a file of 10meg in size then my COBOL module should be able to split this file into say... 5 different output files of 2megs in size.

Now, Microfocus NetExpress has CBL_routines that can determine a file size which I can easily use to determine whether or not the file needs to be split... Now, if I know the file size is say 4megs, then I would assume that 2 files will need to be created... but just not too sure how to split the VARIABLE length records into output files with a size <= 2megs.

 
Hi tuipeatau,

The answer depends on whether you want the long or the short ans. If the division of the file can be approximate, the short ans will do. Let's start w/that.

In the FD for the variable i/p file code:

RECORD VARYING FROM 1 TO xxx DEPENDING ON WS-REC-LEN

along w/the other rec def clauses you need.
The FD 01 level rec descr should be:
Code:
01  FD-VAR-IP-REC.
    O5 FILLER OCCURS 1 TO xxx DEPENDING ON
                       WS-REC-LEN  PIC X.
Do the same thing for your O/P files.

In WS code:
01  WS-REC-LEN  PIC 9(004).
After every read of FD-VAR-IP-FILE WS-REC-LEN will contain the length of the rec just read. Add that to an accumulator after each WRITE to one of your O/P files. If the accum is >= 2Meg close it, open the other O/P file, and zero the accum.

There are a few things wrong w/this solution:

1) You'll have to include FDs, opens, closes, etc. for as many O/p files as you can expect. Later versions of COBOL support dynamic file allocation; that would eliminate this disadvantage.

2) If you write less o/p files than you've allocated, you'll have to devise a way of recognizing and eliminating the empty files. Dynamic file allocation also eliminates this disadvantage.

3) If the division of the files must be exact, then the Block and Record Descriptor words in the file must be part of calculating the accumulation. BDWs and RDWs are 4 bytes in length.

One BDW precedes each block of data in a variable file.
One RDW precedes each record in a variable file.

You could add 4 to the accum as well after you add WS-REC-LEN. Determining when to add the BDW length is a little more problematic.

HTH, Jack.
 
Thanks for your prompt reply slade/Jack....

Here are a few more info...

1.I am using Merant NetExpress Microfocus COBOL I think that the Select filename-1 assign to DYNAMIC is available. That helps!

2. The division of the files does not have to be exact however it is critical that the messages contained within these files are not lost (hence, whole records). These files contains Comma Separated Values......

eg. name,age,addy,postcode

I guess I am also a little confused with the COBOL file structure. The input file will contain a header record and trailer records. However the detail messages are of variable length and the maximum record length that we can get is not known (just an approximation) at this point... This is why I am leaning towards defining the FD as VARYING from 1 to XXX as you've suggested.

Appreciate your input.
Rgds
Tuipeatau
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top