Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Variable length records

1 view
Skip to first unread message

Roberto Barsallo

unread,
Nov 13, 1999, 3:00:00 AM11/13/99
to
Dear all:

I am newbie to COBOL. I am using DEC COBOL on OpenVMS in an Alpha
Server. What I am intending to do is opening an 8-field record file
delimited by tabs, searching for certain field's condition and, if met,
move that record into another record file.
My main problems are two: first, the input file record's length is
variable, i.e, one record can have 50 characters and the next one could
have 75 characters, but always 8 fields; this is because of a couple of
fields having variable length. I would like to move every record into a
temporary record, padding each field with spaces when needed, and then
moving this fixed-length record to the final record file; but, how do I
declare the input file length? Can I go further the average length?,
like:

01 Input-Record PIX X(100)

or am I enable to not declare the input record's length?, like:

01 Input-Record

Secondly, when sorted out the declaration, how do I search for tabs
delimeters? I am trying to unstring the record using:

UNSTRING Input-Record DELIMITED BY X'09'

but to no avail. If this is the right way, then can someone say for
sure which is the exact syntax for the Tab character in COBOL and how
to represent it - say it is hexadecimal or EBDC? Otherwise, how do I
search for Tabs?

I will definitely praise your help and support. Thanks, guys.

Bar.


Sent via Deja.com http://www.deja.com/
Before you buy.

Ken Foskey

unread,
Nov 14, 1999, 3:00:00 AM11/14/99
to
Roberto Barsallo wrote:
>
> Secondly, when sorted out the declaration, how do I search for tabs
> delimeters? I am trying to unstring the record using:
>
> UNSTRING Input-Record DELIMITED BY X'09'
>

The tab character is X'08' in ascii and x'05' in Ebcdic.

Ken

pgr...@dynasty.net

unread,
Nov 14, 1999, 3:00:00 AM11/14/99
to
Ken Foskey <war...@zip.com.au> wrote:

It's been so long ago (or not long enough), I don't know about EBCDIC,
but ASCII tab is X'09'

Phil


Richard Plinston

unread,
Nov 14, 1999, 3:00:00 AM11/14/99
to
In comp.lang.cobol Ken Foskey <war...@zip.com.au> wrote:
:>
:> UNSTRING Input-Record DELIMITED BY X'09'

: The tab character is X'08' in ascii and x'05' in Ebcdic.

No, x"08" is BS (Backspace), x"09" is HT (Horizontal Tab).


--

Warren Porter

unread,
Nov 15, 1999, 3:00:00 AM11/15/99
to

Roberto Barsallo <roberto...@hotmail.com> wrote in message
news:80jspd$j9h$1...@nnrp1.deja.com...

> I am using DEC COBOL on OpenVMS in an Alpha
> Server. What I am intending to do is opening an 8-field record file
> delimited by tabs, searching for certain field's condition and, if met,
> move that record into another record file.
> My main problems are two: first, the input file record's length is
> variable, i.e, one record can have 50 characters and the next one could
> have 75 characters, but always 8 fields; this is because of a couple of
> fields having variable length. I would like to move every record into a
> temporary record, padding each field with spaces when needed, and then
> moving this fixed-length record to the final record file; but, how do I
> declare the input file length?

One option might be to define your file as having a record length of 1 and
then build your record into an array from a loop, counting (looking for) tab
stops or other delimiters. If your file has a Block Descriptor Word (BDW)
or Record Descriptor Word (RDW) you could read the word to know how many
bytes to expect. We do this all the time reading files created by telephone
switches.

Nige

unread,
Nov 15, 1999, 3:00:00 AM11/15/99
to
Warren Porter wrote:
> One option might be to define your file as having a record length of 1 and
> then build your record into an array from a loop, counting (looking for) tab
> stops or other delimiters. If your file has a Block Descriptor Word (BDW)
> or Record Descriptor Word (RDW) you could read the word to know how many
> bytes to expect. We do this all the time reading files created by telephone
> switches.

I still think UNSTRING is the best way to separate the fields. I'm
not sure how to read variable length records though. (Do the records
have a terminating TAB?)

Cheers
Nige
--
Remove the zeds to reply by email

Warren Porter

unread,
Nov 15, 1999, 3:00:00 AM11/15/99
to

Nige <ni...@wg.zicl.co.zuk> wrote in message
news:38302CBC...@wg.zicl.co.zuk...

Others had already mentioned the UNSTRING statement as a way to separate the
fields, but no one at that time discussed reading variable length records--a
prerequisite to reading the fields. If the records are separated by a line
feed and/or carriage return, defining the file as LINE SEQUENTIAL would
work. If the file is all data separated by tab stops, reading in one byte
at a time until the right number of tab stops were found would be the way to
go. With a RDW present, read in the number of bytes promised in that field.
Without knowing the exact format of the data, all I can do is suggest
options. Once a record has been identified and read in, I have no problem
using UNSTRING.

Alistair Maclean

unread,
Nov 16, 1999, 3:00:00 AM11/16/99
to
If the records are always either 50 bytes or 75 bytes long, and if there
is no record descriptor word, then the file could be defined as a 25
byte record length and then either two or three records could be read
(depending upon the number of tabs found) to reconstitute the 50 or 75
byte records respectively.

In article <TOWX3.12780$YI2.6...@typ11.nn.bcandid.com>, Warren Porter
<warre...@netdoor123.com> writes

--
Alistair Maclean

As a solid rock is not shaken by the wind,
even so the wise are not ruffled by praise or blame. - Dhammapada 6

People are like teabags - you have to put them in to hot water before you find
out how strong they are.

Alex

unread,
Nov 17, 1999, 3:00:00 AM11/17/99
to
In article <SIVX3.12720$YI2.6...@typ11.nn.bcandid.com>,
warre...@netdoor123.com says...

>
> Roberto Barsallo <roberto...@hotmail.com> wrote in message
> news:80jspd$j9h$1...@nnrp1.deja.com...
> > I am using DEC COBOL on OpenVMS in an Alpha
> > Server. What I am intending to do is opening an 8-field record file
> > delimited by tabs, searching for certain field's condition and, if met,
> > move that record into another record file.
> > My main problems are two: first, the input file record's length is
> > variable, i.e, one record can have 50 characters and the next one could
> > have 75 characters, but always 8 fields; this is because of a couple of
> > fields having variable length. I would like to move every record into a
> > temporary record, padding each field with spaces when needed, and then
> > moving this fixed-length record to the final record file; but, how do I
> > declare the input file length?
>
> One option might be to define your file as having a record length of 1 and
> then build your record into an array from a loop, counting (looking for) tab
> stops or other delimiters. If your file has a Block Descriptor Word (BDW)
> or Record Descriptor Word (RDW) you could read the word to know how many
> bytes to expect. We do this all the time reading files created by telephone
> switches.
>
>
>
I am doing this using my PARSE function. I put parse in my home page, but
only MF Cobol. If you're interested in source for VMS, please contact me.

Url to that page is http://www.zag.si/~romaniuk/download/cobol.html


Dirk Munk

unread,
Nov 17, 1999, 3:00:00 AM11/17/99
to
First of all the record has to be specified for the maximum record
length or more, if not you will certainly get a RMS error from the file
system.

In the FD entry for this file you will have to enter the following code:

record contains xxx to yyy characters depending on YOUR-COUNTER

Your-counter is a entry in the working storage, en this way you know
exactly how long every record is (it is updated after every read).

If you want to know the maximum record length in the file, the first way
to try is to use DIR /FULL My-File. It depends on how the file was
created if it will give you the true (!) maximum record length. If it is
a normal value than it is ok, but if you get something like 32676 than
you can be almost sure that is not the real maximum record length.

In that case, or if no maximum record length is returned, use Analyze
/RMS /FDL my-file to get a full specification of the file. You can type
or edit the resulting My-File.FDL to get the maximum record length.

The record area is filled by RMS (the file system), but only for as much
as actualy is in the record !! The rest of the record area contains data
from previous reads !
So suppose you have this record description for a variable length
record:

FD My-file
record contains 1 to 10 characters depending on my-file-lenght.
01 My-File-Record pic x(10).

If the first record you read is 10 characters long and contains
AAAAAAAAAA. and the second you read contains BBBBB, then after the
second read My-File-Record contains BBBBAAAA.

You can clear My-File-Record before a read by using Initialize
My-File-Record, and if you want to you can do it with any character you
like by adding Replacing Alphanumeric Data By some-character.

The Tab character can by defined two ways, the most elegant way (my
view) is in the Special-Names part of the Environment Division. This is
a example:

Special Names.
Symbolic Characters TAB LF FF CR ESC
are 10 11 13 14 28
.....

The value points to the position in the ASCII table , and is
subsequently always 1 higher than the ASCII value of the character
itself. Keep in mind that the DEC Multinational Character Set is used
unless you define another character set, but the first 127 Dec MCS
characters are more or less standard ASCII.

You can use TAB as any normal character, so the Initialize .. statement
could contain Replacing .. by TAB.

A Unstring statement can also be done by using TAB as a delimiter.

The second way to define TAB is this:

01 TAB-NUM PIC 9(3) computational value 9.
01 TAB REDEFINES TAB-NUM PIC X.

I hope this may help you in solving your problems.

Regards,

Dirk

Roberto Barsallo wrote:
>
> Dear all:
>

> I am newbie to COBOL. I am using DEC COBOL on OpenVMS in an Alpha


> Server. What I am intending to do is opening an 8-field record file
> delimited by tabs, searching for certain field's condition and, if met,
> move that record into another record file.
> My main problems are two: first, the input file record's length is
> variable, i.e, one record can have 50 characters and the next one could
> have 75 characters, but always 8 fields; this is because of a couple of
> fields having variable length. I would like to move every record into a
> temporary record, padding each field with spaces when needed, and then
> moving this fixed-length record to the final record file; but, how do I

> declare the input file length? Can I go further the average length?,
> like:
>
> 01 Input-Record PIX X(100)
>
> or am I enable to not declare the input record's length?, like:
>
> 01 Input-Record
>

> Secondly, when sorted out the declaration, how do I search for tabs
> delimeters? I am trying to unstring the record using:
>

> UNSTRING Input-Record DELIMITED BY X'09'
>

0 new messages