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

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


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
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

Moderator Emeritus


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

PostPosted: Mon Sep 17, 2007 6:43 am
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
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

Moderator Emeritus


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

PostPosted: Mon Sep 17, 2007 7:28 am
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

Superior Member


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

PostPosted: Mon Sep 17, 2007 1:39 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 3
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 Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
Search our Forums:

Back to Top