Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

alternate key 3

Status
Not open for further replies.

claudeb

Programmer
Nov 23, 2000
140
CA
Hi,
I would like to know how a could read my file with a partial key.
01 file-key
05 key-1
05 key-2
05 key-3
i would like to be able to read my file with key-2
I TRIED THIS
SELECT DATA-FILE ASSIGN TO SYS0000
ORGANIZATION IS INDEXED
ACCESS MODE IS RANDOM
RECORD KEY IS FILE-KEY
ALTERNATE RECORD KEY IS KEY-2
FILE STATUS IS DATA-FILE-STATUS.
i tried many combination but...
i get error 35 if i put THE ALTERNATE KEY, and my file can't be opened
if i remove the alternate key, i can open my file , but no data is read.
in case of alternate key, i read my file in this way.
move my-field to file-key.
read data-file key is key-2.
since the file is not opened, i don't get to this stage yet.

thanks
 
Let me ask you just a few questions.

Do you want to use a generic key i.e. if the record layout is:

01 KEY.
05 PRIMARY-KEY.
10-FIRST-NAME PIC X(10).
10-LAST-NAME PIC X(10).
05 REST-OF-FIELDS.
10 FIRST-FIELD PIC X(1).
10 SECOND-FIELD PIC X(2).
10 THIRD-FIELD PIC X(3).

And you want your program to read ALL records with, let's say, the primary key value would be "JOE". Whether the secondary key is "SMITH" or "BLOW" or "JONES" or whatever?

If so, you can set up your file like this:

SELECT DATA-FILE ASSIGN TO SYS0000
ORGANIZATION IS INDEXED
ACCESS MODE IS RANDOM
RECORD KEY IS PRIMARY-KEY
FILE STATUS IS DATA-FILE-STATUS.

Then when you do your READ, place "JOE" into "FIRST-NAME". Place spaces into "LAST-NAME".

And if it's random access, then I assume that it's some sort of VSAM or other random-access type of file. So you need a START command.

Do the START Command like this:

START DATA-FILE KEY IS GREATER THAN FIRST-NAME.

I'm not entirely positive about the syntax, though I'm looking at my IBM COBOL manual in Bookmanager. If you want all the "JOE"s, even those where the secondary key (LAST-NAME) is blank, then use GREATER THAN OR EQUAL TO FIRST-NAME.

Then you do your READ. It will pick up all the "JOES"s.

I'm not sure that this is what you want, but hope it helps.

Nina Too
 
Ooops. I believe I misled you.

The syntax for the START command would be:

START DATA-FILE KEY IS GREATER THAN PRIMARY-KEY.

This way, you'll pick up all the last names whose first name is "JOE."

Nina Too

 
Thanks Nina,
from what i see, key-1 is empty all the time and key-2 is the real key.
the real situation is that my program used to read an IDEAL table. This table has been split into 2 tables. Initially the program read the table with a key like key-1 (at far most left).
With the new table, the "real key" is key-2 after 5 blank positions.
I am just wondering if this is what causes the problem.
if i understand correctly, when the key is as specified, the open-input is successful, but it reads the file as
" aaaa ", and no record is matched.
the key in the old version would be just "aaaa".
do you think that executing START would solve my problem ?
 
Was the file created with the alternate key or did you have an existing file with a primary key and then just changed the program to add the alternate key? If so, you will have to create the file with all appropriate keys prior to using the alternate key for reading.

Ted

 
Hi Claude,

It sounds like you don't have a good idea of what the data looks like. Why not read the file sequentially and DISPLAY the recs or write them to a flat file and have a look at them. When I display something I usually bracket it, e.g.:

DISPLAY '>' WS-REC '<'

This lets you know if the rec begins/ends w/spaces od non-printable chars. Once you know what you're dealing with, you can begin to solve the problem. Let us know what you see.

HTH, Jack.

 
Hi,

the manual about file-status 35:

|_______|______________|_______|____________________________________________|
| 3 | Permanent | 0 | No further information |
| | error |_______|____________________________________________|
| | condition | 4 | A permanent error exists because of a |
| | | | boundary violation; an attempt was made to |
| | | | write beyond the externally-defined |
| | | | boundaries of a sequential file. |
| | |_______|____________________________________________|
| | | 5 | An OPEN statement with the INPUT, I-O, or |
| | | | EXTEND phrase was attempted on a |
| | | | non-optional file that was not present. |
| | |_______|____________________________________________|


To avoid these kind of problems, I use the following solution:

003670 OPEN-FI01 SECTION.
003680 OPEN I-O FI01.
003690 IF FI01-STATUS IS NOT EQUAL TO ZERO
003700 OPEN OUTPUT FI01
003710 PERFORM CHECK-STATUS-FI01
003720 CLOSE FI01
003730 PERFORM CHECK-STATUS-FI01
003740 OPEN I-O FI01
003750 PERFORM CHECK-STATUS-FI01
003760 END-IF.
003770 CHECK-STATUS-FI01 SECTION.
003780 IF FI01-STATUS NOT = ZERO
003790 PERFORM DISPLAY-ERROR-FI01
003800 STOP RUN.

I hope this helps,

Crox
 
Hi,

another thing, you are perhaps working on the mainframe. How did you allocate your files?

Here is some code from the IBM manual.

Regards,

Crox

Code:
From:
COBOL for OS/390 & VM
Programming Guide
Version 2 Release 2
Document Number SC26-9049-05


1.9.6.2.1 Example: entries for alternate indexes




The following example maps the relationships between the COBOL
| FILE-CONTROL entry and the DD statements or environment variables for a VSAM
indexed file with two alternate indexes.


Using JCL:




     //MASTERA     DD   DSNAME=clustername,DISP=OLD      (1)
     //MASTERA1    DD   DSNAME=path1,DISP=OLD            (2)
     //MASTERA2    DD   DSNAME=path2,DISP=OLD            (3)


Using environment variables:




 |   export MASTERA=DSN(clustername),OLD                 (1)
 |   export MASTERA=DSN(path1),OLD                       (2)
 |   export MASTERA=DSN(path2),OLD                       (3)
     . . .
     FILE-CONTROL.
       SELECT MASTER-FILE ASSIGN TO MASTERA              (4)
           RECORD KEY IS EM-NAME
           PASSWORD IS PW-BASE                           (5)
           ALTERNATE RECORD KEY IS EM-PHONE              (6)
               PASSWORD IS PW-PATH1
           ALTERNATE RECORD KEY IS EM-CITY               (7)
               PASSWORD IS PW-PATH2.



  (1)
  The base cluster name is clustername.


  (2)
  The name of the first alternate index path is path1.


  (3)
  The name of the second alternate index path is path2.



  | (4)
  The ddname or environment variable name for the base cluster is specified with
  the ASSIGN clause.


  (5)
  Passwords immediately follow their indexes.


  (6)
  The key EM-PHONE relates to the first alternate index.


  (7)
  The key EM-CITY relates to the second alternate index.




related tasks
&quot;Creating alternate indexes&quot; in topic 1.9.6.2
 
You wrote:
--------------------
from what i see, key-1 is empty all the time and key-2 is the real key.
-------------------
I still think that the way I set up the file would work.

You would set it up like this:

01 KEY.
05 PRIMARY-KEY.
10 KEY-1 PIC X(10).
10 KEY-2 PIC X(10).
05 REST-OF-FIELDS.
10 FIRST-FIELD PIC X(1).
10 SECOND-FIELD PIC X(2).
10 THIRD-FIELD PIC X(3).

Then, before you do your START command, initialize KEY-1 and then code it:

START DATA-FILE KEY IS GREATER THAN PRIMARY-KEY.

All the KEY-1 records will be blank, in this particular case, as you specified. And the READ will begin where you have data in KEY-2 and pick up all these records.

Hope this helps, Nina Too

 
hello,
every thing works fine now. key-2 was supposed to be declared as secondary key in the ideal table. but &quot;someone&quot; forgot to do it. i had my share of mistakes too. i didn't pass the right file lenght.
with the new settings the job is fine
01 file-key
05 key-1
05 key-2
05 key-3
SELECT DATA-FILE ASSIGN TO SYS0000
ORGANIZATION IS INDEXED
ACCESS MODE IS RANDOM
RECORD KEY IS FILE-KEY-2
FILE STATUS IS DATA-FILE-STATUS
Thanks you all. I certainly learned a lot with this problem.
Every input helped me to understand more about the subject. i know that in the future, i will have to use key-1 or key-2 as keys. the info about alternate key and start will come handy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top