IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Having more than one field as VSAM key


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
amitha

New User


Joined: 04 Nov 2008
Posts: 8
Location: Banglore

PostPosted: Tue Nov 04, 2008 12:45 pm
Reply with quote

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
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8796
Location: Welsh Wales

PostPosted: Tue Nov 04, 2008 12:47 pm
Reply with quote

Does it not give any examples in the fine manuals ?

Have you tried google ?
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10886
Location: italy

PostPosted: Tue Nov 04, 2008 12:48 pm
Reply with quote

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
View user's profile Send private message
amitha

New User


Joined: 04 Nov 2008
Posts: 8
Location: Banglore

PostPosted: Tue Nov 04, 2008 12:51 pm
Reply with quote

I tried in the google and could find any example. icon_sad.gif
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8796
Location: Welsh Wales

PostPosted: Tue Nov 04, 2008 12:57 pm
Reply with quote

amitha wrote:
I tried in the google and could find any example. icon_sad.gif


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
View user's profile Send private message
amitha

New User


Joined: 04 Nov 2008
Posts: 8
Location: Banglore

PostPosted: Tue Nov 04, 2008 1:00 pm
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10886
Location: italy

PostPosted: Tue Nov 04, 2008 1:01 pm
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10886
Location: italy

PostPosted: Tue Nov 04, 2008 1:05 pm
Reply with quote

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
View user's profile Send private message
amitha

New User


Joined: 04 Nov 2008
Posts: 8
Location: Banglore

PostPosted: Tue Nov 04, 2008 1:12 pm
Reply with quote

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
View user's profile Send private message
amitha

New User


Joined: 04 Nov 2008
Posts: 8
Location: Banglore

PostPosted: Tue Nov 04, 2008 2:06 pm
Reply with quote

I am not sure how can we declare the file structure for the above case.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10886
Location: italy

PostPosted: Tue Nov 04, 2008 2:20 pm
Reply with quote

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
View user's profile Send private message
amitha

New User


Joined: 04 Nov 2008
Posts: 8
Location: Banglore

PostPosted: Tue Nov 04, 2008 2:36 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8700
Location: Dubuque, Iowa, USA

PostPosted: Tue Nov 04, 2008 6:16 pm
Reply with quote

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
View user's profile Send private message
amitha

New User


Joined: 04 Nov 2008
Posts: 8
Location: Banglore

PostPosted: Wed Nov 05, 2008 8:42 am
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Help required to reset decimal points... DFSORT/ICETOOL 8
No new posts Sorting Date Field DFSORT/ICETOOL 4
No new posts VSAM LISTCAT INFORMATION JCL & VSAM 2
No new posts Access to non cataloged VSAM file JCL & VSAM 18
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
Search our Forums:

Back to Top