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

How to Read Empty VSAM file in a cobol program


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

New User


Joined: 18 Feb 2009
Posts: 4
Location: India

PostPosted: Thu Mar 12, 2009 12:05 pm
Reply with quote

If the VSAM file is opened in I-O mode and it is newly created by the JCL we submit..then a read is being performed in cobol program to check whether it has existing records then the program fails as there are no records in the VSAM file..plz suggest how to handle this situation.
How the status codes should be managed to do a successful first time read of empty file...sample read statements are given below

Code:
 READ VSAM-FILE                                   
                                                 
 IF RECORD-FOUND                                 
    ADD +1                        TO XXX
    REWRITE VSAM-FILE-RECORD                           
 ELSE                                             
    IF RECORD-NOT-FOUND                           
       MOVE AAA               
                                  TO   BBB
       MOVE  1                    TO   XXX
       WRITE VSAM-FILE-RECORD                           
    END-IF                                       
 END-IF
Back to top
View user's profile Send private message
Mathiv Anan

Active User


Joined: 23 Jul 2008
Posts: 106
Location: USA

PostPosted: Thu Mar 12, 2009 2:01 pm
Reply with quote

If you are usig that VSAM file for first time in cobol, please have a dummy progam to just open that file in I-O mode and close the file.

Next time, you can use it in your program for processing and start writing the file and the job should not abend.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Mar 12, 2009 4:49 pm
Reply with quote

From the COBOL Programming Guide (link at the top of the page):
Quote:
1.10.3.2.1 Opening an empty file

To open a file that has never contained records (an empty file), use a form of the OPEN statement.

Depending on the type of file that you are opening, use one of the following statements:

* OPEN OUTPUT for ESDS files.

* OPEN OUTPUT or OPEN EXTEND for KSDS and RRDS files. (Either coding has the same effect.) If you coded the file for random or dynamic access and the file is optional, you can use OPEN I-O.

Optional files are files that are not necessarily available each time a program is run. You can define files opened in INPUT, I-O, or OUTPUT mode as optional by defining them with the SELECT OPTIONAL clause in the FILE-CONTROL paragraph.
An empty VSAM file needs to be opened for OUTPUT (or EXTEND) before opening for INPUT or I-O. If you do SELECT OPTIONAL and open it for I-O, there can be performance implications.
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 FTP VB File from Mainframe retaining ... JCL & VSAM 8
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts Using API Gateway from CICS program CICS 0
Search our Forums:

Back to Top