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

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


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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: 2146
Location: At my coffee table

PostPosted: Thu Sep 25, 2008 8:06 pm
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: 8697
Location: Dubuque, Iowa, USA

PostPosted: Thu Sep 25, 2008 8:22 pm
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
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

Moderator Emeritus


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

PostPosted: Fri Sep 26, 2008 7:34 pm
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

Superior Member


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

PostPosted: Sat Sep 27, 2008 4:41 am
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

Moderator Emeritus


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

PostPosted: Sat Sep 27, 2008 4:47 am
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: 8697
Location: Dubuque, Iowa, USA

PostPosted: Sat Sep 27, 2008 5:08 am
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

Superior Member


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

PostPosted: Sat Sep 27, 2008 5:12 am
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

Moderator Emeritus


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

PostPosted: Sat Sep 27, 2008 9:06 am
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts Write line by line from two files DFSORT/ICETOOL 7
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