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

syntax for index file with multiple keys and each key have multiple columns

 
sureshso
Occasional Contributor

syntax for index file with multiple keys and each key have multiple columns

Hi,

i have index file with 100 columns and 3 keys. each key have mulltiple columns at random positions from file.

example: index.dat K1, K2 and K3. columns: C1,C2,C3,C4....C100.

K1 - C10,C11,C12,C13 K2 - C9,C10,C11,C12,C13,C14  K3 - C5,C40

i tried to read this index file thru COBOL program as below:

I-O section: SELECT index orgnaization is indexed record key is K1 alternate key is K2 alternate key is K3

Data section:

FD index. 

01 k1.

05 C10

05 C11

05 C12

05 C13

01 k2

    05 C9

    05 C10

     05 C11 ---

01 K3 

   05 C5

   05 C40

01 index-rec

    05 c1

    05 c2 .....

or

I-O section: SELECT index orgnaization is indexed record key is C10,C11,C12.. alternate key is C9,C10... alternate key is C9, C40

Data section:

FD index. 

 

01 index-rec

    05 c1

    05 c2 .....

i am getting error in both cases with error as " attempting to open indexed file index.dat whose actuals keys don't match" while opening file statement in debug the code.

i tried to find syntax or example in multiple websites but most of them has single key or multiple key also with each key has one column and that too first rows not from random columns.

Please help me how to resolve this issue and help in delcaration on file?

Thanks in advance.

 

 

1 REPLY 1
Hein van den Heuvel
Honored Contributor

Re: syntax for index file with multiple keys and each key have multiple columns

Just do not specify the alternate keys if you do not need the,

If you specify them, then Cobol ensures they are matching the file.

If you leave them out, there is nothing to check, nothing to fail.

If you are just processing from first to last (as suggested by other posts here) then you casn probably even leave of the primary key if my recollection is correct. 

Most importantly you do NOT specify those K1 and K2 thingies. Those are just names/labels for a collection of columns.

Get rid of...

FD index. 

01 k1.

05 C10...

 

Only use...

01 index-rec

    05 c1

    05 c2 .....

 

 

Or... do NOTHING, after CONVERTING the file to sequential as per other topic

(CONVERT/FDL=NL: /STAT idx.dat seq.dat)

The bits/record-layout will be the same, just no indexes, and just read as a sequential file.

And oh.... RTFM : 

for example: HP COBOL UserManual Order Number: AA–Q2G1H–TK January 2005

Processing Files and Records 6.3 Creating and Processing Files

Example 6–26 Creating and Populating an Indexed File

 

Good luck!

Hein.