View previous topic :: View next topic
|
Author |
Message |
amitha
New User
Joined: 04 Nov 2008 Posts: 8 Location: Banglore
|
|
|
|
Hi,,
I have file with more than one field contributing for the primary key and alternate keys. Say I have Key1 and Key2 as primary key and at the same I have key2, key3 and key4 as alternate key. I would like to know how I can declare in the 'Select ... Assign' statement of the cobol program.
For eg,
file-control.
select stu-file assign to disk
organization is indexed
access mode is random
record key is rno -- how do i specify in my case
alternate record key is name --how do i specify this in my case.
Thanks in advance. |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
Does it not give any examples in the fine manuals ?
Have you tried google ? |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10888 Location: italy
|
|
|
|
since the vsam key must be is a contiguous string of bytes
the subdivision in fields is arbitrary and depends only on the program specification..
You can map/divide the vsam key in more than one field, but that' s not a vsam concern ( and they must be contiguous ) |
|
Back to top |
|
|
amitha
New User
Joined: 04 Nov 2008 Posts: 8 Location: Banglore
|
|
|
|
I tried in the google and could find any example. |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
amitha wrote: |
I tried in the google and could find any example. |
Really ? You DO surprise me
And here was I, only 10 seconds on google and came up with THIS topic which was not only on google but on this very forum too.
Along with thousands of other examples and leads from google. |
|
Back to top |
|
|
amitha
New User
Joined: 04 Nov 2008 Posts: 8 Location: Banglore
|
|
|
|
Thank enrico..
So in my case, i am confused how can I have it as continuous, since a single feild is being part of both primary and alternate key??
Do we have different format of 'RECORD KEY IS ' and 'ALTERNATE KEY IS'?
Please guys, help me with this doubt. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10888 Location: italy
|
|
|
|
it would be better to review Your understanding of VSAM KSDS organization...
what do You see for the key when You define a vsam ksds...
quoting for the help from define
Quote: |
))KEYS('LENGTH' 'OFFSET')
- Specifies that information about the key field for
key-sequenced data follows.
'LENGTH' - Length of the key.
'OFFSET' - Offset of the key.
REQUIRED - 'LENGTH' and 'OFFSET' |
/repeat on
so Your program/application might consider the vsam key as composed of
two parts, but that' s strictly application logic not VSAM
I do not speak CObOLESE but the applroach could be
some_level KEY
some_level+1 part_one_of_the_key
some_level+1 part_two_of_the_key
and in the file stuff COBOL/VSAM expect You to refer only to the KEY |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10888 Location: italy
|
|
|
|
why don' t You use a bit of imagination
let' s suppose that all the key components are 5 bytes long
primary key token1,2
altern key token2,3,4
the token should be contiguos in the file layout
and the definition would be
PRIMARY ==> KEYS(10,0)
ALTERNAT ==> KEYS(15,5)
simple isn' t it |
|
Back to top |
|
|
amitha
New User
Joined: 04 Nov 2008 Posts: 8 Location: Banglore
|
|
|
|
Hey guys,
I got your point. Let me dig more on this and I will come back on this.
Thanks a lot guys for your valuable inputs. |
|
Back to top |
|
|
amitha
New User
Joined: 04 Nov 2008 Posts: 8 Location: Banglore
|
|
|
|
I am not sure how can we declare the file structure for the above case. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10888 Location: italy
|
|
|
|
again... I DO NOT SPEAK COBOLESE but ....
something like for the record layout
Code: |
01 RECORD.
05 KEY_PART_1 PIC X(5).
05 KEY_PART_2 PIC X(5).
05 KEY_PART_3 PIC X(5).
05 KEY_PART_4 PIC X(5).
05 ... the rest of the record
|
something like for the keys for direct access
Code: |
xx PRIMARY_KEY .
yy KEY_PART_1 PIC X(5).
yy KEY_PART_2 PIC X(5).
xx ALTERNAT_KEY.
yy KEY_PART_2 PIC X(5).
yy KEY_PART_3 PIC X(5).
yy KEY_PART_4 PIC X(5).
|
|
|
Back to top |
|
|
amitha
New User
Joined: 04 Nov 2008 Posts: 8 Location: Banglore
|
|
|
|
Hey cool!!
Someone can help with VSAM embedded in COBOL program.
I suppose the keys neeed to be declared under file section of the data division in COBOL.
When I say
RECORD KEY IS <primary-key>
ALTERNATE KEY IS <alternate-key> , will COBOL not expect the <primary-key> and <alternate-key> to be defined in the File Section? If I declare it as mentioned in the above reply under file section, the field (which is part of both primary and alternate) will be repeated which may make file inconsistent. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
What prevents you from declaring
Code: |
SELECT VSAM-FILE ASSIGN TO VSAMFILE
RECORD KEY VR-KEY
ALTERNATE RECORD KEY VR-ALT-KEY
ORGANIZATION INDEXED
ACCESS DYNAMIC
FILE STATUS IS VSAM-FILE-FS
VSAM-FILE-FULL
. |
and then
Code: |
FILE SECTION.
FD VSAM-FILE.
01 VSAM-RECORD-01.
05 VR-KEY PIC X(08).
05 FILLER PIC X(72).
01 VSAM-RECORD-02.
05 FILLER PIC X(04).
05 VR-ALT-KEY PIC X(08).
05 FILLER PIC X(68).
WORKING-STORAGE SECTION.
01 WS-VARIABLES.
05 VSAM-FILE-FS PIC 9(02).
05 VSAM-FILE-FULL.
10 VF-RETURN PIC S9(04) COMP.
10 VF-FUNCTION PIC S9(04) COMP.
10 VF-FEEDBACK PIC S9(04) COMP.
|
As far as I know, there is no requirement that the RECORD KEY and ALTERNATE RECORD KEY clauses reside in the same 01 under the FD. As long as both are defined in the FD, they can be placed however you need them.
And yes I tested this code -- got 00 file status on open of the file. |
|
Back to top |
|
|
amitha
New User
Joined: 04 Nov 2008 Posts: 8 Location: Banglore
|
|
|
|
Thanks Buddy, for your patience in trying out and helping me. I have used something similar with the use of 'REDEFINES' statements. And that too worked. Since it was too late , i could not reply it here...
Thanks a lot for all of you for sharing the valuable ideas..
Happy Posting!! |
|
Back to top |
|
|
|