Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

CATCH SYSTEM-EXCEPTIONS file_access_errors

Former Member
0 Likes
1,645

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

12 REPLIES 12
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,361

That is not a system exception. There is a list of [system exceptions, this is as of 46c|http://wiki.sdn.sap.com/wiki/x/Y4BMCg].

In your cases, you would just check sy-subrc.


OPEN DATASET par_file FOR INPUT IN TEXT MODE.
if sy-subrc = 8 ....
endif.

Regards,

Rich Heilman

Read only

0 Likes
1,361

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

Read only

0 Likes
1,361

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

Read only

Former Member
0 Likes
1,361

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

Read only

0 Likes
1,361

You might be able to use the system exception....

Catch system-exception DATASET_CANT_OPEN = 1

.

Regards,

Rich Heilman

Read only

0 Likes
1,361

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ö

Read only

0 Likes
1,361

Of course, as soon as i posted last, my program does work and i am now getting the system exception.

Regards,

Rich Heilman

Read only

0 Likes
1,361

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

Read only

0 Likes
1,361

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

Read only

0 Likes
1,361

Wow!

Thanks a lot.

BR

Michael

Read only

0 Likes
1,361

No problem, Again, I never did it this way before, but definitly will in the future. Thanks for teaching me something new.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,361

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