take three fileds as akey in ksds



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

take three fileds as akey in ksds

Postby Deepak kumar25 » Thu Oct 10, 2013 1:50 pm

Dear dick scherrer..
I am having confusion can we take more than one fields of ksds as a key...

Example.

S.no Name Rollno SSn Pin
Like i want to take key on sno, rollno and pin... can it is possilbe.....
As i know ksds has one primary key and other alternate key. bt Restriction is that we can not use alternate key.




Regards
Deepak kumar
Deepak kumar25
 
Posts: 34
Joined: Mon Jan 10, 2011 10:51 am
Has thanked: 0 time
Been thanked: 0 time

Re: take three fileds as akey in ksds

Postby Robert Sample » Thu Oct 10, 2013 3:08 pm

As long as the fields are contiguous in the file, you can create a primary KSDS key from them. If the fields are not contiguous, you cannot create a KSDS key from them.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: take three fileds as akey in ksds

Postby Deepak kumar25 » Thu Oct 10, 2013 3:34 pm

thanks for reply
Deepak kumar25
 
Posts: 34
Joined: Mon Jan 10, 2011 10:51 am
Has thanked: 0 time
Been thanked: 0 time

Re: take three fileds as akey in ksds

Postby Deepak kumar25 » Sat Oct 12, 2013 9:48 am

@robert sample
can you show me a example.
Deepak kumar25
 
Posts: 34
Joined: Mon Jan 10, 2011 10:51 am
Has thanked: 0 time
Been thanked: 0 time

Re: take three fileds as akey in ksds

Postby Robert Sample » Sat Oct 12, 2013 5:41 pm

Untested code:
FD  VSAM-INPUT ...
01  VSAM-INPUT-RECORD.
     05  VIR-KEY.
         10  VIR-SNO       PIC X(10).
         10  VIR-ROLLNO    PIC 9(05).
         10  VIR-PIN       PIC 9(04).
and in your IDCAMS DEFINE, you would put KEYS(19 0) since you are defining a 19-byte key starting in the first byte. As I stated earlier, if you have fields intermingled between SNO, ROLLNO, and PIN then you either have to physically change the file so the key fields are contiguous as I show or accept that you CANNOT create a VSAM file from that data using those fields for your key -- one or the other.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: take three fileds as akey in ksds

Postby dick scherrer » Mon Oct 14, 2013 3:14 am

Hello,

Something that is very often done is to locate the field(s) for the key at the beginning of the record. Then follow with the remainder of the fields (as Robert has done)
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: take three fileds as akey in ksds

Postby Deepak kumar25 » Tue Oct 15, 2013 1:38 pm

Thanks dick

bt can it is possible to take key like below.
1 field, 3 field, 6 field

means key is not contiguous.
Deepak kumar25
 
Posts: 34
Joined: Mon Jan 10, 2011 10:51 am
Has thanked: 0 time
Been thanked: 0 time

Re: take three fileds as akey in ksds

Postby BillyBoyo » Tue Oct 15, 2013 1:43 pm

No. See Robert's first response.

I guess knowledge of what a VSAM key is was missing in the File Design.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post