Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
How to Read Empty VSAM file in a cobol program

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject:
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    Post subject:
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: 8200
Location: East Dubuque, Illinois, USA

PostPosted: Thu Mar 12, 2009 4:49 pm    Post subject:
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    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 ISSUE IN copying Sequential file reco... thesumitk JCL & VSAM 2 Wed Dec 13, 2017 3:07 pm
No new posts The same REXX program doesnt work for... jackzhang75 CLIST & REXX 5 Wed Dec 06, 2017 2:51 am
No new posts File Tailoring -- Temporary dataset i... samzee71 CLIST & REXX 3 Fri Dec 01, 2017 3:12 am
No new posts Rexx - File tailoring samzee71 CLIST & REXX 10 Thu Nov 30, 2017 10:47 pm
No new posts Compare VSAM files using DFSORT pshongal DFSORT/ICETOOL 5 Thu Nov 23, 2017 10:24 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us