View previous topic :: View next topic
|
Author |
Message |
shitij
New User
Joined: 09 Sep 2005 Posts: 31 Location: Delhi
|
|
|
|
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 |
|
|
Devzee
Active Member
Joined: 20 Jan 2007 Posts: 684 Location: Hollywood
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
shitij
New User
Joined: 09 Sep 2005 Posts: 31 Location: Delhi
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
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 |
|
|
|