View previous topic :: View next topic
|
Author |
Message |
muhammad
New User
Joined: 25 Oct 2007 Posts: 19 Location: hyderabad
|
|
|
|
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 |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
vasanthvazz
New User
Joined: 12 Jul 2005 Posts: 2 Location: Chennai
|
|
|
|
You can handle the empty file by checking the end of file condition , condition code is 10 . |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Hi Dick,
Ok, point taken.. . 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..
@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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
Back to top |
|
|
|