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

How to fetch records KSDS VSAM with Altenate Index in COBOL


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

New User


Joined: 12 Jan 2006
Posts: 29

PostPosted: Thu Mar 29, 2007 9:26 pm
Reply with quote

Hi All,

I have written few records in KSDS and want to fetch those records based on the Alternate key with duplicate. I am populating a value for alternate key which is present in the Vsam and reading the vsam for this key, but it satified the invalid key condition. The Return Codes & File status is 00.

My code:
Alternate key and tried reading the file. But it didnt work.
VSAM Def:
DEFINE CLUSTER(NAME(TEST.KSDS) -
TRACKS(45,15) -
RECORDSIZE(43,43) -
FREESPACE(10,15) -
KEYS(6,0) -
INDEXED) -
DATA(NAME(TEST.KSDS.DATA)) -
INDEX(NAME(TEST.KSDS.INDEX))

Alternate index def :
DEFINE ALTERNATEINDEX(NAME(TEST.KSDS.AIX) -
RELATE(TEST.KSDS) -
TRACKS(45,15) -
RECORDSIZE(43,43) -
FREESPACE(10,15) -
CONTROLINTERVALSIZE(4096) -
KEYS(5,6) -
NONUNIQUEKEY -
UPGRADE) -
DATA(NAME(TEST.KSDS.AIX.DATA)) -
INDEX(NAME(TEST.KSDS.AIX.INDEX))

Build Index def:
BLDINDEX -
INFILE(SOURCE) -
OUTFILE(TARGET)

Path def:
DEFINE PATH(NAME(TEST.KSDS.PATH) -
PATHENTRY(TEST.KSDS.AIX) -
UPDATE)

Cobol Code is:
In File Control of Environment Division.
SELECT OUTFILE ASSIGN TO OUTFL
FILE STATUS IS WS-OUTFILE-STATUS
ORGANIZATION IS INDEXED
ACCESS MODE IS DYNAMIC
RECORD KEY IS OT-C-ID
ALTERNATE RECORD KEY IS OT-C-NAME WITH DUPLICATES.

File section of data division:
01 OUT-REC.
05 OT-C-ID PIC X(06).
05 OT-C-NAME PIC X(05).
05 OT-C-ADDR1 PIC X(08).
05 OT-C-ADDR2 PIC X(08).
05 OT-C-ZIP PIC 9(06).
05 OT-C-PHONE.
10 OT-C-AREACODE PIC X(03).
10 OT-C-PREFIX PIC X(03).
10 OT-C-PHONENO PIC X(04).

In procedure division
READ-PARA.
INITIALIZE OUT-REC.
ACCEPT WS-NAME.
MOVE WS-NAME TO OT-C-NAME.
MOVE "Y" TO WS-FLAG.
OPEN INPUT OUTFILE.
DISPLAY "ENTER NAME TO VIEW : " OT-C-NAME.
START OUTFILE KEY IS EQUAL TO OT-C-NAME
INVALID KEY
DISPLAY "INVALID KEY!"
NOT INVALID KEY
PERFORM READ-OT-PARA.
READ-OT-PARA.
READ OUTFILE
INVALID KEY
DISPLAY "RECORD IS NOT FOUND !"
NOT INVALID KEY
DISPLAY "NUMBER : " OT-C-ID
DISPLAY "NAME : " OT-C-NAME.
DISPLAY 'READ STATUS IS:' WS-OUTFILE-STATUS.

What is happening here is. The START NOT invalid check is satisfied the goes to READ-OT-PARA and display Record not found. The Return Codes & File status is 00.
My Input Rec:
111111RAVI1ADDRESS1ADDRESS2600101044CHN9881
222222RAVI2ADDRESS2ADDRESS3600102044CHN9882
333333RAVI3ADDRESS3ADDRESS4600103044CHN9883
444444RAVI4ADDRESS4ADDRESS5600104044CHN9884
555555RAVI5ADDRESS5ADDRESS6600105044CHN9885
RAVI3

I have refered the link given in our forum but didnt know how and why read next was used. I tried with it and there was compilation error for it. ibmmainframes.com/viewtopic.php?t=18126&highlight=alternate+index

Thanks in Advance,
Ravikanth Chavali
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Thu Mar 29, 2007 9:40 pm
Reply with quote

You are missing the "NEXT" at the end of your READ line.....
Back to top
View user's profile Send private message
ravikanth

New User


Joined: 12 Jan 2006
Posts: 29

PostPosted: Thu Mar 29, 2007 9:43 pm
Reply with quote

To avoid misunderstanding. FYI:
The first five rec of My Input recs are the records which were written initially and the last i.e 6th rec i.e "RAVI3" is the Alternate index with which i want to fetch records.

Thanks,
Ravi
Back to top
View user's profile Send private message
ravikanth

New User


Joined: 12 Jan 2006
Posts: 29

PostPosted: Thu Mar 29, 2007 9:53 pm
Reply with quote

Thanks a Loooooot,

I did mention that i have tried NEXT but then i got a compilation error. The error was *IGYPS2119-S The "NEXT" phrase was specified with the "INVALID KEY" phrase. The "NEXT" phrase was discarded.*

So this time i removed Invalid Key statements and tried, It Worked.

Thank you once again for your time.

Could tell me how it worked with Read Next and not with Read alone.
Also why in my case was is going for the Invalid key condition when i have given Read alone.

Thanks,
Ravi
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Thu Mar 29, 2007 10:29 pm
Reply with quote

Just taking a guess, a keyed file in dynamic mode with a read without a next and a key, defaults to the primary key which did not have a valid value.
You might try and remove the next, move a known value into the primary key - not for the same record - and see if you get that one back.....
Start your adventure here: READ statement
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 Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Access to non cataloged VSAM file JCL & VSAM 18
No new posts Compare only first records of the fil... SYNCSORT 7
Search our Forums:

Back to Top