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.
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.
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.
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.
"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.
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.
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).
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.