Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How to fetch records KSDS VSAM with Altenate Index in COBOL

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: How to fetch records KSDS VSAM with Altenate Index in COBOL
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. http://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: 3158
Location: Tucson AZ

PostPosted: Thu Mar 29, 2007 9:40 pm    Post subject:
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    Post subject: Re: How to fetch records KSDS VSAM with Altenate Index in CO
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    Post subject:
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: 3158
Location: Tucson AZ

PostPosted: Thu Mar 29, 2007 10:29 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. Cobol GUI (like Editor) Kala Mainframe COBOL Programming 14 Wed May 10, 2017 12:30 pm
No new posts IMS T-Pipe queue counts in a COBOL Pr... Siva NKK Kothamasu IMS DB/DC 0 Tue May 09, 2017 6:31 pm
No new posts Check if any Detail records and extra... V S Amarendra Reddy SYNCSORT 19 Mon May 08, 2017 8:54 pm
No new posts COBOL Code Parsers and Lineage Establ... balimanja COBOL Programming 2 Tue May 02, 2017 3:30 am
No new posts Cobol upgrade - source code missing f... gthmrj IBM Tools 1 Wed Apr 26, 2017 6:04 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us