Operating System - OpenVMS
cancel
Showing results for 
Search instead for 
Did you mean: 

Defining an indexed FD for two different files.

 
Yyrkoon
Advisor

Defining an indexed FD for two different files.


Hi all,
I have a problem trying to define a FD indexed file. The problem is that I have two different systems and two different indexed files with diffent length, one on each system. I would like to developed a single program able to read from this file on both systems and I want to define just one FD.

I mean, something like (I am guessing 100%):

FD navigator
Organization is indexed
File status is file-stat
Record contains 15 OR 20 characters depending on wk-system
Access mode is dynamic.
01 wk-system1 pic X(15).
01 wk-system2 pic X(20).

Can I do this somehow?

Thanks in advance,

Yyrkoon.
4 REPLIES
Hein van den Heuvel
Honored Contributor

Re: Defining an indexed FD for two different files.

You need to use either
RECORD CONTAINS xxx TO xx CHARACTERS
or
RECORD IS VARYING IN SIZE FROM xx [ TO xx ] CHARACTERS DEPENDING on depending-name.

Next you declare your record with REDEFINE clause.
For files, you can NOT do those at 01 level.
If you'd try then you would get the message:

%COBOL-E-FILSECRED, REDEFINES clause invalid for 01 level data item in FILE SECTION - clause accepted

So you'll have to add a bonus level just for that.

The FD might end up looking something like:

FD THE-FILE external.
01 all-blah.
02 blah.
03 catch-all pic x(200).
02 redefines blah.
03 wk-system1 pic X(15).
02 redefines blah.
03 wk-system2 pic X(20).

For READING the depending on item will be SET, giving you an indication which flavor of record you read.

For WRITING you'll have to set the correct matching length.

More often than not there will be a flag field early in the record in indicate the flavor as well.

Hope this helps,
Hein
Yyrkoon
Advisor

Re: Defining an indexed FD for two different files.

Maybe I'm doing something wrong but I have a file stat 39 when I try to open the file, this file (on one server) is define as follows:

File organization: Indexed, Prolog: 3, Using 1 key
In 2 areas
Shelved state: Online
Caching attribute: Writethrough
File attributes: Allocation: 70, Extend: 12, Maximum bucket size: 12
Global buffer count: 0, No version limit
Contiguous best try
Record format: Fixed length 37 byte records


And the other is define exactly the same but "Fixed length 42 byte records" and they MUST be like this. Am I doing something wrong or it is simply not possible?
Hein van den Heuvel
Honored Contributor

Re: Defining an indexed FD for two different files.

>> Maybe I'm doing something wrong but I have a file stat 39 when I try to open the file

I suspect you are doing something wrong, but since you did not show relevant (fragments of the) code it is hard to guess what.

>> this file (on one server) is define as follows:

File organization: Indexed, Prolog: 3, Using 1 key
Record format: Fixed length 37 byte records

>> And the other is define exactly the same but "Fixed length 42 byte records" and they MUST be like this.

Must is such a seemingly strong word.
It probably just means "we don't understand enough of the system to change this", or "we can not jsutify the cost of changing that, just to resolve the current issue"

>> Am I doing something wrong or it is simply not possible?

It works for me, so my money is on the first choice.
Here is what works for me...

OpenVMS V8.2, Alpha DS20, Compaq COBOL V2.8-1286

:
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT THE-FILE
ASSIGN TO "TEST"
RECORD KEY IS THE-KEY
ACCESS MODE IS DYNAMIC
ORGANIZATION IS INDEXED
FILE STATUS IS FILE-STATUS.
:
FD THE-FILE
RECORD IS VARYING IN SIZE FROM 4 CHARACTERS DEPENDING on depending-name.
01 THE-RECORD.
03 THE-KEY PIC X(4).
03 SOME-DATA PIC X(66).
:
WORKING-STORAGE SECTION.
01 depending-name PIC 9(9) COMP.
01 FILE-STATUS PIC XX.
:
READ THE-FILE RECORD KEY IS THE-KEY.
DISPLAY depending-name WITH CONVERSION.

As input file I used:
$ conver tt: test.dat /fdl="file; org ind; rec; form fixed; size 70; key 0; seg0_l 4"/pad="7"
aap
mies
noot

and

$ conver tt: test.dat /fdl="file; org ind; rec; form fixed; size 60; key 0; seg0_l 4"/pad="6"
Created: 31-MAR-2010 06:29:22.40
Revised: 31-MAR-2010 06:29:45.43 (2)
$

The results report 70 and 60 for the size from Cobol and "7"s and "6"s to pad the data.

Directory shows:
Record format: Fixed length 70 byte records
and
Record format: Fixed length 60 byte records

Good luck,
Hein





Yyrkoon
Advisor

Re: Defining an indexed FD for two different files.

So I suppose that actually I'm doing something wrong, but however your resolution has given me a new idea to solve it, not actually as I wanted to but quite good. I will not explain it 'cause it's off topic but many thanks anyway.