Page 1 of 1

take three fileds as akey in ksds

PostPosted: Thu Oct 10, 2013 1:50 pm
by Deepak kumar25
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

Re: take three fileds as akey in ksds

PostPosted: Thu Oct 10, 2013 3:08 pm
by Robert Sample
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.

Re: take three fileds as akey in ksds

PostPosted: Thu Oct 10, 2013 3:34 pm
by Deepak kumar25
thanks for reply

Re: take three fileds as akey in ksds

PostPosted: Sat Oct 12, 2013 9:48 am
by Deepak kumar25
@robert sample
can you show me a example.

Re: take three fileds as akey in ksds

PostPosted: Sat Oct 12, 2013 5:41 pm
by Robert Sample
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.

Re: take three fileds as akey in ksds

PostPosted: Mon Oct 14, 2013 3:14 am
by dick scherrer
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)

Re: take three fileds as akey in ksds

PostPosted: Tue Oct 15, 2013 1:38 pm
by Deepak kumar25
Thanks dick

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

means key is not contiguous.

Re: take three fileds as akey in ksds

PostPosted: Tue Oct 15, 2013 1:43 pm
by BillyBoyo
No. See Robert's first response.

I guess knowledge of what a VSAM key is was missing in the File Design.