Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Reading the file into WS variable - What if file empty?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
shitij

New User


Joined: 09 Sep 2005
Posts: 31
Location: Delhi

PostPosted: Mon Sep 17, 2007 5:28 am    Post subject: Reading the file into WS variable - What if file empty?
Reply with quote

Hi,

I am using :

READ MW-ATND-FILE INTO WS-CHK-FILE

Now my question is - if the file is empty, how can I know that???


My File -

MW-ATND-FILE PIC X(80).

01 WS-CHK-FILE.
05 FILLER PIC X(06).
05 WS-HDR-MSG PIC X(30).
05 FILLER PIC X(44).

In my code - I was chking WS-HDR-MSG and deciding whether to write the header or not.

Header once written would not be written again, but start of the day - my file (MW-ATND-FILE) would be empty - so when I read the empty file : I am not able to chk the conditions based on WS-HDR-MSG (as nothing is coming in WS-HDR-MSG).

May I know a solution to come out of this problem, would be highly obliged.


Thanks.
Back to top
View user's profile Send private message

Devzee

Active Member


Joined: 20 Jan 2007
Posts: 684
Location: Hollywood

PostPosted: Mon Sep 17, 2007 5:47 am    Post subject:
Reply with quote

Quote:
if the file is empty, how can I know that???

You can use EOF and decide what needs to be done.

READ filename
AT END set EOF flag
END READ
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Mon Sep 17, 2007 6:43 am    Post subject:
Reply with quote

Hello,

If you post the code you create to deal with this, we will be happy to review the code for you.
Back to top
View user's profile Send private message
shitij

New User


Joined: 09 Sep 2005
Posts: 31
Location: Delhi

PostPosted: Mon Sep 17, 2007 7:14 am    Post subject: Reply to: Reading the file into WS variable - What if file e
Reply with quote

Here is the code flow:

Code:
OPEN I-O     MW-ATND-FILE.       
READ MW-ATND-FILE INTO WS-CHK-FILE     
AT END MOVE 'Y'  TO EOF-FILE     
GO TO  1000-EXIT                 
END-READ.                   


Code:
IF WS-HDR-MSG = 'TRACKER AS OF :'
    SET WS-FLG-HDR-EXST-Y TO TRUE
ELSE                             
    SET WS-FLG-HDR-EXST-N TO TRUE
END-IF.           


Now when the file is empty, the logic :

Code:
IF WS-HDR-MSG = 'TRACKER AS OF :'
    SET WS-FLG-HDR-EXST-Y TO TRUE
ELSE                             
    SET WS-FLG-HDR-EXST-N TO TRUE
END-IF.


Does not work, tried to Display WS-HDR-MSG, but it does not (as the file is empty, I guess).

As my flags - WS-FLG-HDR-EXST-Y, WS-FLG-HDR-EXST-N are never set to true or false, therefore nothing gets written in the file.

As the writing in the file is based on the flags:

WS-FLG-HDR-EXST-N - Header does not exist (First write the header and then the detail record).

WS-FLG-HDR-EXST-Y - Header exists (then write the detail record only)



Do I have to write another program to enter an empty record (space) to the file - everyday - early morning (before my jobs run)..may be then I can check - if WS-HDR-MSG = SPACES (and can write accordingly).[/code]
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Mon Sep 17, 2007 7:28 am    Post subject:
Reply with quote

Hello,

Quote:

Do I have to write another program to enter an empty record (space) to the file
No, you just need to make this program process properly.

You need to make sure you actually have read a record before you try to use it. Before you check WS-HDR-MSG to determine if this is a hdr records, you need to check if the EOF-FILE has been set. If EOF-FILE has been set, you should proceed out of the program, doing whatever is needed to cleanly end the program.

When you post code, it is more readable if you use the "Code" tag near the top of the reply panel. When you are entering a post and use any of the bbtags, you can click Preview to see what your post will look like when it is seen by the forum. When you are satisfied with your your post appears, click Submit. If you look at yojr prior post, i've "Code"d some to show how it looks.
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


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

PostPosted: Mon Sep 17, 2007 1:39 pm    Post subject:
Reply with quote

Hi,

Where exactly you start writing your output report/file? When do you call your file 'empty'..when only header is there or nothing is there (i.e. no header & no detail records).

If you can post the input & the expected out put..hopefully I'll understand better.
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 Split file based on comparsion to 2 f... Div Grad DFSORT/ICETOOL 3 Thu Jul 27, 2017 9:16 pm
No new posts Extra character appears in file when ... Balu5491 All Other Mainframe Topics 1 Wed Jul 26, 2017 2:39 pm
No new posts SSH - known_hosts file configuration vasanthz All Other Mainframe Topics 2 Wed Jul 26, 2017 2:10 am
This topic is locked: you cannot edit posts or make replies. Fetching data from BAI File arunsoods JCL & VSAM 1 Wed Jul 19, 2017 4:28 pm
No new posts Write out NODUPS but just from one file Jay Villaverde DFSORT/ICETOOL 8 Fri Jul 14, 2017 12:44 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us