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.
The tab character is X'08' in ascii and x'05' in Ebcdic.
Ken
It's been so long ago (or not long enough), I don't know about EBCDIC,
but ASCII tab is X'09'
Phil
: 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).
--
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
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.
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.
Url to that page is http://www.zag.si/~romaniuk/download/cobol.html
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'
>