From: map@sequent.com (Michael Perry)
Subject: Re: HELP !!! COBOL INDEXES
Organization: Sequent Computer Systems, Inc.
Date: Wed, 16 Dec 92 22:08:39 GMT

In article <segross.3@uci.edu> segross@uci.edu (STEVE GROSS) writes:
>In article <1992Dec16.135541.12409@dg-rtp.dg.com> cochran@spam.rtp.dg.com (A. Jing Hippy) writes:
>
>>In article <BzBAF0.BKK@ux1.cso.uiuc.edu>, edotto@ux1.cso.uiuc.edu (Ed Otto) writes:
>>|> dlittle@sscvx1.ssc.gov (DENNIS LITTLE) writes:
>>|> >> 
>>|> >>01 TESTRECORD.
>>|> >>   05 KEY-FIELD-1    PIC X(10).
>>|> >>   05 KEY-FIELD-2    PIC X(5).
>>|> >>   05 KEY-FIELD-3    PIC 99.
>>|> >>01 DATA-FIELDS.
>>|> >>   05 ......
>>|> >>   05 ......
>>|> >> 
>>|> >>I want to create two INDEXES :
>>|> >>   Index 1 on KEY-FIELD-1, KEY-FIELD-2, KEY-FIELD-3
>>|> >>   Index 2 on KEY-FIELD-3, KEY-FIELD-1, KEY-FIELD-2
>>|> >> 
>>|> 
>>|> >Check on the word "Alternate Index" in your manual and see if that's what
>>|> >you're looking for.  It sounds as though that will solve your problem.
>>|> 
>>|> Nope - the sort sequence is different...what he needs to do is to resort
>>|> the file and create TWO output files with the different sequences.
>
>>But that's what alternate indexes are FOR.  He should be able to do something
>>like:
>
>>01 TESTRECORD.
>>   05 KEY-FIELD-1    PIC X(10).
>>   05 KEY-FIELD-2    PIC X(5).
>>   05 KEY-FIELD-3    PIC 99.
>>01 TESTRECORD-ALT REDEFINES TESTRECORD.
>>   05 KEY-FIELD-3    PIC 99.
>>   05 KEY-FIELD-1    PIC X(10).
>>   05 KEY-FIELD-2    PIC X(5).
>
>>and then his SELECT statement would look something like:
>
>>    SELECT FILENAME ASSIGN TO DISK,
>>         RECORD KEY IS TESTRECORD,
>>         ALTERNATE RECORD KEY IS TESTRECORD-ALT.
>
>>It won't take any more space in the program because of the REDEFINES, and
>>every WRITE that is done to the file will automatically write the other
>>index as well.
>
>No way.
>Redefining the data doesn't change the values.

You are very correct...

>The only way I know to do this is:
>
>    SELECT FILENAME ASSIGN TO DISK
>        RECORD KEY IS TEST-KEY
>	ALTERNATE RECORD KEY IS TEST-ALT-KEY.
>
>01  TESTRECORD.
>    02  TEST-KEY.
>        05  KEY-FIELD-1                  PIC X(10).
>        05  KEY-FIELD-2                  PIC X(5).
>        05  KEY-FIELD-3                  PIC 99.
>    02  TEST-ALT-KEY.
>        05  ALT-FIELD-3                  PIC 99.
>        05  ALT-FIELD-1                  PIC X(10).
>        05  ALT-FIELD-2                  PIC X(5).
>
>and you have to make sure you move the "KEY" fields to the "ALT" fields
>before you write.

This will work, but at the expense of extra data.  What I'd use
is a segmented key [I don't have the manual here, but I think that's
what it's called]...  something like:

>    SELECT FILENAME ASSIGN TO DISK
>        RECORD KEY IS TEST-KEY
>	     ALTERNATE RECORD KEY IS KEY-FIELD-3, KEY-FIELD-2, KEY-FIELD-1
>
>01  TESTRECORD.
>    02  TEST-KEY.
>        05  KEY-FIELD-1                  PIC X(10).
>        05  KEY-FIELD-2                  PIC X(5).
>        05  KEY-FIELD-3                  PIC 99.
>

This is _not_ proper syntax, but _most_ compilers allow you to
make up a key that is two or more fields located in different parts
of the FD.  Look in the SELECT section of your compiler manual.

>Maybe someone else has something more clever (that works).
>
>Steve

Mike
-- 
    "Life's a bench, then you die!"