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!

Read from file varying lines 1

Status
Not open for further replies.

MarcinD

Programmer
Feb 17, 2007
1
PL
Hi,

How to define FD struct if app has to read line from file but ... length of that line is varying e.g. can be 4 chars or can be 100 chars but can be more too - it's not limited.

Of course file is with line sequential organization.

Marcin Domaslawski
 
in IBM environment you can use RECORD 0 to read any recordlength in a sequential file that is not variable, but to have the complete recordlength available, you should define the longest record possible in your FD.

In pc environment with for example REALIA, is works automatically using a sequential definition and a long record.

Regards,

Crox
 
The trick is to know the length of the rec just read.

In the MFame env code "record varying from n1 to n2 depending on ws-len" where ws-len is defined as pic 9(n).

After the read the read rec's len is in ws-len. When WRITEing make sure ws-len contains the desired length.

Not sure about the line seq, but it should work w/that too.

Regards, Jack.

"A problem well stated is a problem half solved" -- Charles F. Kettering
 
In COBOL you must know the length of the longest record, else you will get a file status code of 44 when reading a record longer than you have specified in the FD. Of course, if you specify a maximum length that is greater than the actual longest record, there is no problem. On IBM mainframes, there is no such thing as a line sequential file, so the question does not apply, I don't know how you could read a file in any language when a record may be longer that you can anticipate.

As for finding out the langth of a record just read, if the records are specified as variable length, the LENGTH OF function will return that.
 
use a read into and the data is padded with blancs.

In the pc-environment with ascii lines, it happens automatically in my programming environment.

On the mainframe, it happens automatically with record 0 and fixed input of any lenght. RTFM.

 
Marcin,

As you can see from so many different responses, the correct answer will require you to tell us the COBOL compiler you are using, and also on what computing environment.

Tom Morrison
 
I wrote:

"record varying from n1 to n2 depending on ws-len"

I should have added:

where n1 is <= the shortest rec expected in the file
n2 is >= the longest rec expected in the file

not including the 4 byte RDW.

webrabbit, FYI:

From Enterprise COBOL for z/OS and OS/390
Language Reference
Version 3 Release 2
Document Number SC27-1408-01


4.2.5.1.4 Line-sequential organization

In a line-sequential file, each record contains a sequence of characters ending with a record delimiter. The delimiter is not counted in the length of the record.

Upon writing, any trailing blanks are removed prior to adding the record delimiter. The characters in the record area from the first character up to and including the added record delimiter constitute one record and are written to the file.

Full details in link below:






Regards, Jack.

"A problem well stated is a problem half solved" -- Charles F. Kettering
 
webrabbit,

PS - As I recall LENGTH OF returns the length of the defined variable, not the length of the delimited string within the variable.

Regards, Jack.

"A problem well stated is a problem half solved" -- Charles F. Kettering
 
Normally, LENGTH OF does return the length of the defined record, but in the specific case of a variable length record in the FD, it returns the length read. But the record must be defined as variable length, not just be one of a set of defined records under the FD. i.e., the record itself must contain an OCCURS DEPENDING ON clause in one of its subordinate fields. This is true at least in Micro Focus COBOL.

I haven't worked on mainframes for several years, so I was not aware thar line sequential records had been added in that environment. Thanks for the heads up.
 
One way to possibly do this is to have a record-type variable so you know what kind of record you are looking at.
Then you can read the record into a different part of working storage depending on the record type. We always used "read input-record into xyz-storage-area" with a differetnt copybook for each record type. Mostly I saw this used for files when the record length got too long. We had 9 different record types for HR, but we did not always use them all for each employee.

If you do not like my post feel free to point out your opinion or my errors.
 
This might help!

010100 FD CFMIN-FILE
010200 VALUE OF DEPENDENTSPECS IS TRUE
010300 VALUE OF TITLE IS WS-CFMIN-FILE-ID
010400 RECORD IS VARYING IN SIZE FROM 100 TO 700 CHARACTERS
010500 DEPENDING ON CFMI-FILE-SIZE
010600 BLOCK CONTAINS 90 RECORDS.
010700 01 CFMIN-REC PIC X(700).
010800 01 CFMIN-REC1 PIC X(100).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top