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
 

 

What is the use of START keyword in accessing VSAM Files?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
muhammad

New User


Joined: 25 Oct 2007
Posts: 19
Location: hyderabad

PostPosted: Thu Sep 25, 2008 7:44 pm    Post subject: What is the use of START keyword in accessing VSAM Files?
Reply with quote

OPEN INPUT VSAMF1.


MOVE LOW-VALUES TO VFI-KEY.
MOVE 'S' TO VFI-TYPE.


START VSAMF1 KEY > VFI-KEY.

IF VSAM-STATUS NOT = ZERO
ABORT PROGRAM.

-------------------------------------------------

tHE lAYOUT FOR THE INPUT FILE VSAMF1 IS
01 VSAMREC.
05 VFI-KEY
10 VFI-TYPE
10 VFI-NBR
10 VFI-ACCT
10 VFI-NBR
10 VFI-DATE
10 VFI-INBR
10 VFI-MNBR
05 VFI-AMOUNT
05 VFI-VNBR
05 ARI-PNBR

---------------------------------------

The program fails if the VSAM file is empty(has one record with spaces fully)... I am not sure what exactly is the use of START keyword... If i fill 0 in all fields and run the pgm with one single record in VSAM, it runs fine...

What is the use of START?
How to handle if the VSAM is empty?
Back to top
View user's profile Send private message

CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Thu Sep 25, 2008 8:06 pm    Post subject:
Reply with quote

23 - An attempt was made to randomly access a record that does not exist in the file, or a START or random READ statement was attempted on an optional input file that was not present.
The file status of 23 is a valid one and should be checked for and when found, treated as normal.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8055
Location: East Dubuque, Illinois, USA

PostPosted: Thu Sep 25, 2008 8:22 pm    Post subject:
Reply with quote

START establishes a location in the file for the next READ to occur at.

You need to distinguish between an empty VSAM file, which has no records in it, and an initialized VSAM file, which you say has a record with all spaces in it.

Your program is failing because your program attempts to locate the first record key that starts with an 'S' followed by LOW-VALUES (or greater: T123 would succeed as well) -- but a space is less than 'S' in the collating sequence so the START fails. If you want the START to succeed in all cases, you'll need to change
Code:
MOVE 'S' TO VFI-TYPE
into
Code:
MOVE SPACE TO VFI-TYPE
If you really want to read keys starting with 'S' then you need to change your program logic to not abort if the START fails since all you've determined is that there are no keys starting with 'S' or higher in the collating sequence -- there could be many records in the file even though none of the keys start with an 'S' or greater in the collating sequence.
Back to top
View user's profile Send private message
vasanthvazz

New User


Joined: 12 Jul 2005
Posts: 2
Location: Chennai

PostPosted: Fri Sep 26, 2008 11:41 am    Post subject:
Reply with quote

You can handle the empty file by checking the end of file condition , condition code is 10 .
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Fri Sep 26, 2008 7:34 pm    Post subject:
Reply with quote

Hello Vasanth and welcome to the forums,

Thank you for participating.

Do keep in mind that this particular question does not nvolve an empty file, though.
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Sat Sep 27, 2008 4:41 am    Post subject:
Reply with quote

Quote:
this particular question does not nvolve an empty file
I think..it does ..
muhammad wrote:
How to handle if the VSAM is empty?
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Sat Sep 27, 2008 4:47 am    Post subject:
Reply with quote

Hi Anuj,

Quote:
I think..it does ..
Yes, from the question, one might think so. Unfortunately for understanding:
Quote:
The program fails if the VSAM file is empty(has one record with spaces fully)...

This is not a really empty file. . . Providing "solutions" to dealing with an "empty file" are not the correct solutions.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8055
Location: East Dubuque, Illinois, USA

PostPosted: Sat Sep 27, 2008 5:08 am    Post subject:
Reply with quote

I think part of the problem is this from the original post:
Quote:

The program fails if the VSAM file is empty(has one record with spaces fully)
because the VSAM file is not empty if it has one record of spaces in it. If it is truly empty, it does not have any records.

However, this is irrelevant to the original poster's problem. If you do a START VSAMF1 KEY > VFI-KEY where VFI-KEY is set to 'S', the manual indicates when an invalid key condition is raised:
Quote:
If the comparison is not satisfied by any record in the file, an invalid key condition exists; the position of the file position indicator is undefined, and (if specified) the INVALID KEY imperative-statement is executed.


NOTE: INVALID key for START KEY > VFI-KEY absolutely says nothing about how many records are in the file. There could be thousands or even millions of records loaded into the VSAM file, but as long as none of their keys start with an S, T, U, ... then the INVALID KEY condition is raised. You can handle the INVALID KEY condition, or change the key for the START, but the code per se is not wrong -- COBOL and VSAM are working as designed in this case.
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Sat Sep 27, 2008 5:12 am    Post subject:
Reply with quote

Hi Dick,

Ok, point taken.. icon_smile.gif . One needs to distinguish between an empty VSAM file, which has no records in it, and an initialized VSAM file, which has a record with all spaces in it.. I missed the blue part of my sentence in my earlier post, Hope I don't bother you..one mistake in a single day should be forgiven.. icon_smile.gif

@OP

The START command is used read other than the next VSAM record. A value must be moved into the RECORD KEY. The KEY clause is optional, but it can be used to specify a relational (equal, less than, etc.) operator.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Sat Sep 27, 2008 9:06 am    Post subject:
Reply with quote

Hello,

As Robert has mentioned (a couple of times) there is quite a difference between an empty file and an invalid key on a start.
Quote:
There could be thousands or even millions of records loaded into the VSAM file, but as long as none of their keys start with an S, T, U, ...
Had the record contained high-values, the start would have been successful, but the result would probably still have been undesirable for the OP.

Quote:
one mistake in a single day should be forgiven..
One-a-day doesn't need forgiveness icon_smile.gif
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
No new posts Unable to create multiple files using... mbattu COBOL Programming 3 Fri May 05, 2017 5:35 pm
This topic is locked: you cannot edit posts or make replies. Merge two files and update Trailer re... Yashashri JCL & VSAM 1 Thu May 04, 2017 12:54 pm
No new posts Accessing first bit of PD value rajatbagga DFSORT/ICETOOL 11 Wed May 03, 2017 6:03 am
No new posts VSAM Space Allocation mrgnndhmk JCL & VSAM 7 Sat Apr 22, 2017 12:42 am
No new posts Dynamic split of files under groups sril.krishy DFSORT/ICETOOL 4 Mon Apr 17, 2017 1:09 pm


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