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

how to handle if input file is empty


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

Active User


Joined: 19 Feb 2005
Posts: 112
Location: chennai

PostPosted: Tue Jan 03, 2006 2:00 pm
Reply with quote

Hi,

My requirement is:

my program is reading and file and after doing some manipulations and writing into a output file.

I dont want to abend the program even if the input file is empty.......

means my input file is empty but I dont want to abend the program....how to handle this condition......

thx in advance............

pavan
Back to top
View user's profile Send private message
gowtham_1982
Warnings : 1

Active User


Joined: 02 Dec 2005
Posts: 109

PostPosted: Tue Jan 03, 2006 2:14 pm
Reply with quote

hai pavan,

hope this logic helps you. after reading the input file just check the file status. if it is not zero( in your case if there are no records the file status after the first read will be 10) move zero to the return code register. this is the way to save the job from abend.

like:

if ws-inpfile-fs not = 0

move zero to return-code

else
continue

end-if.


corrections welcomed..

gowtham
Back to top
View user's profile Send private message
Rupesh.Kothari

Member of the Month


Joined: 27 Apr 2005
Posts: 463

PostPosted: Tue Jan 03, 2006 3:15 pm
Reply with quote

Hi,

Quote:
my input file is empty but I dont want to abend the program....how to handle this condition......


This can be done by two ways
First one as Gowtham_1982 mentioned

Second you can use following Code to check is file empty? IF yes yhen do not run the step ( Program) else run.

Code:
//STP0010  EXEC PGM=IDCAMS                               
//SYSPRINT DD SYSOUT=*                                   
//IFILE    DD DSN=fILE NAME
//SYSIN    DD *                                         
 PRINT INFILE(IFILE) COUNT(1)                           
//*   
//IF STP0010.RC EQ 00 THEN                                                     
PROGRAM STEP
//IFMAFEND ENDIF


Hope this helps

Regards
Rupesh
Back to top
View user's profile Send private message
i413678
Currently Banned

Active User


Joined: 19 Feb 2005
Posts: 112
Location: chennai

PostPosted: Tue Jan 03, 2006 5:01 pm
Reply with quote

Hi ,

Thank you rupesh and gowtham.

one more thing I want to clear whether this technique works for VSAM files also.......

cheers............

pavan
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1448
Location: Chicago, IL

PostPosted: Tue Jan 03, 2006 5:41 pm
Reply with quote

Quote:
one more thing I want to clear whether this technique works for VSAM files also.......


Yes.

Regards,

Priyesh.
Back to top
View user's profile Send private message
gowtham_1982
Warnings : 1

Active User


Joined: 02 Dec 2005
Posts: 109

PostPosted: Tue Jan 03, 2006 5:57 pm
Reply with quote

i413678 wrote:
Hi ,

Thank you rupesh and gowtham.

one more thing I want to clear whether this technique works for VSAM files also.......

cheers............

pavan



hai pavan.

yes this logic can also work for VSAM files...

corrections welcomed...

gowtha
Back to top
View user's profile Send private message
i413678
Currently Banned

Active User


Joined: 19 Feb 2005
Posts: 112
Location: chennai

PostPosted: Tue Jan 03, 2006 6:33 pm
Reply with quote

Hi Rupesh,


//SYSIN DD *
PRINT INFILE(IFILE) COUNT(1)
//*
//IF STP0010.RC EQ 00 THEN
PROGRAM STEP
//IFMAFEND ENDIF

I am not clear these control cards..........

in SYSIN we are printing......will it return 0 if file is empty

and if this return code is 0 no need to proceed otherwise we have to prroceed......

is my understanding is right.....let me know.....

thx once again......

pavan
Back to top
View user's profile Send private message
Rupesh.Kothari

Member of the Month


Joined: 27 Apr 2005
Posts: 463

PostPosted: Tue Jan 03, 2006 7:08 pm
Reply with quote

Hi,

Code:
/STP0010  EXEC PGM=IDCAMS                               
//SYSPRINT DD SYSOUT=*                                   
//IFILE    DD DSN=fILE NAME
//SYSIN    DD *                                         
PRINT INFILE(IFILE) COUNT(1)                           
//*   
//IF STP0010.RC EQ 00 THEN                                                     
PROGRAM STEP
//IFMAFEND ENDIF


If File name contain atleast 1 record (i.e. Non empty) then Steo will return 0 and you can run your program else not.

Hope this is clear now.

Regards
Rupesh
Back to top
View user's profile Send private message
i413678
Currently Banned

Active User


Joined: 19 Feb 2005
Posts: 112
Location: chennai

PostPosted: Tue Jan 03, 2006 9:03 pm
Reply with quote

Hi Rupesh,

thank you once again

ok, then normally for VSAM files we will insert one low level record and we will run the job in order not to abend the job......

in that case there will be 1 record......but there is no actual data records....then if we use this logic the program will execute...

how to handle this condition

am i clear

pavan
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Tue Jan 03, 2006 10:58 pm
Reply with quote

i413678,

For the VSAM file, when you create the VSAM file, it is in a non initialized state, and you will get an abend if you try to read from it. Inserting the 'dummy' record puts it into an initialized state. You can Delete the dummy record and the VSAM file will then be in an Initialized, Empty state. A read from this will get you a not found status '23' (EOF).

In our shop, when an empty file in encountered, we simply perform the EOF routine for that file, the program does not abend. We need to put special coding in the program to abend if the first read attempt is an EOF, if an abend is desired.
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 How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts Access to non cataloged VSAM file JCL & VSAM 18
No new posts Need help for File Aid JCL to extract... Compuware & Other Tools 23
Search our Forums:

Back to Top