‎2005 Nov 15 5:56 PM
Hi,
I use this Exception for checking a file-open like this:
CATCH SYSTEM-EXCEPTIONS file_access_errors = 8.
OPEN DATASET par_file FOR INPUT IN TEXT MODE.
ENDCATCH.
if sy-subrc = 8 ....
But it doesn't work.
System: 4.6c.
I have heard, that these kind of exceptions won't work
in my release.
Is this true?
BR
Michael
‎2005 Nov 15 6:09 PM
‎2005 Nov 15 6:30 PM
Hi Rich,
Thanks a lot for your answer.
I have tried allready DATASET_CANT_OPEN and
DATASET_READ_ERROR and so on ...
But nothing works as it should.
Sy-subrc is allways 0!
And the point is!
If I try DATASET_CANT_OPEN I will get SY-subrc = 0.
So I am starting DO. ...READ... ENDDO
And when I try there to catch DATASET_READ_ERROR
during the loop a dump occurs! Of course SY_SUBRC == 0,
but in fact it isn't.
If I don't use CATCH/ENDCATCH sy-subrc = 8. Which is ok!
Maybe it is a release problem? (4.6c)
BR
Michael
‎2005 Nov 15 6:37 PM
I always just check sy-subrc when opening a file. It always works for me.
report zrich_0001.
data: begin of ifile occurs 0,
rec(150),
end of ifile.
parameters: path(99) type c lower case default '/QDLS/ALH/PACKS.DAT'.
open dataset path for input in text mode.
if sy-subrc <> 0.
write:/ 'File can not be opened'.
endif.
do.
read dataset path into ifile-rec.
if sy-subrc eq 0.
append ifile.
else.
exit.
endif.
enddo.
Regards,
Rich Heilman
‎2005 Nov 15 6:11 PM
If you do an F1 on 'CATCH', you'll what exceptions can be caught. I didn't see this in either our 4.6C or 4.7 system.
Rob
‎2005 Nov 15 6:14 PM
‎2005 Nov 15 6:37 PM
Hi Rob,
This was the first, what I hve done.
Otherwise I would'nt bother You
Anyway, I used all possible Exceptions include
File_access_errors (this was my last try)
I am using CATCH/ENDCATCH very often. And it works all the time; except the File-Accessing-Eceptions
BR
Michaeö
‎2005 Nov 15 6:39 PM
‎2005 Nov 15 6:42 PM
Ok, here is the modified code.
report zrich_0001.
data: begin of ifile occurs 0,
rec(150),
end of ifile.
parameters: path(99) type c lower case
default '/usr/sap/TST/SYS/Data1.txt'.
open dataset path for input in text mode.
if sy-subrc ne 0.
write:/ 'File can not be opened'.
else.
do.
read dataset path into ifile-rec.
if sy-subrc eq 0.
append ifile.
else.
exit.
endif.
enddo.
endif.
Regards,
Rich Heilman
‎2005 Nov 15 6:43 PM
This is now also working for me.
report zrich_0001.
data: begin of ifile occurs 0,
rec(150),
end of ifile.
parameters: path(99) type c lower case
default '/usr/sap/TST/SYS/Data1.txt'.
open dataset path for input in text mode.
<b>
catch system-exceptions dataset_cant_open = 1.</b>
do.
read dataset path into ifile-rec.
if sy-subrc eq 0.
append ifile.
else.
exit.
endif.
enddo.
<b>endcatch.</b>
<b>if sy-subrc = 1.
write:/ 'File could not be opened'.
endif</b>.
Put the CATCH around the do loop when reading the file.
Please make sure to award points for helpful answers and mark you posts as solved when answered completely. Thanks.
Regards,
Rich Heilman
Message was edited by: Rich Heilman
‎2005 Nov 15 6:50 PM
‎2005 Nov 15 6:51 PM
‎2005 Nov 15 6:40 PM
Hi Rich,
Thanks, I own You some points
Well, I agree to you, I will do it in the old fashioned way.
If sy-subrc ....
But it would be very interesting to know, why it doesn't work
BR
Michael