Application Development 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: 

Handling dataset dumps

Former Member
0 Kudos
111

Hello all,

How can we handle dumps in open dataset statements.

For eg: open dataset pa_upld for input in text mode.

if it's successful, then only open the file. Or else it will dump.

Now how can we handle this without going to dump if file does not exist.

Regards

1 ACCEPTED SOLUTION

Former Member
0 Kudos
90

write the simple query

open dataset p_file for output in text mode .

if sy-subrc ne 0.

message E000(zsd) with 'File not found'.

endif.

10 REPLIES 10

Former Member
0 Kudos
91

write the simple query

open dataset p_file for output in text mode .

if sy-subrc ne 0.

message E000(zsd) with 'File not found'.

endif.

Former Member
0 Kudos
90

Hi,

If the file is not there..Then it will not dump..It will set the sy-subrc to greater than zero..

Check this ex..



OPEN DATASET '/tmp/test.txt' FOR INPUT IN TEXT MODE.

* Check the return code..
IF sy-subrc <> 0.
  MESSAGE E208(00) WITH 'File not found.'.
ENDIF.
 

Thanks,

Naren

Former Member
0 Kudos
90

Hi Kesi ,

Check the value of SY-SUBRC after the open dataset statement and it the value is not equal to 0 , then raise an error message , thus stopping the execution of the program.

Regards

Arun

0 Kudos
90

Hello,

I was going through this code gallery, in which it states if file is present it will set subrc to 0 else it will dump. Now i am bit confused with that when you say subrc will set to 8.

Now i will checking for subrc only after the open dataset statement. If it goes to dump as soon as with open dataset statement, how can i check for subrc ( which will be next statemnt).

Link to code gallery---https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/reading%2bfile%2bcontents

Regards

0 Kudos
90

HI Kesi ,

I dont think the program dumps is the file is not present, it just sets SY-SUBRC as 8 , so please check it in your system.

I tested it in my system and it set SY-SUBRC as 8.

Do respond with the result which you get.

Regards

Arun

0 Kudos
90

Hello Arun,

Thanks for the reply. Now that was my understanding to and that was my answer in the interview which i faced recently. ut the person was rrelunctant to accept that and said that system will go to dump. He said that we need to handle that for which i did not had any answer.

When i checked in the code gallery (in the link i provided in same post), there was this statement...

  • if it's successful, then only open the file. Or else it will dump.

if sy-subrc = 0.

.....

.....

Now i realy want to get a clearcut answer for this.

Regards

0 Kudos
90

Hi Kesi ,

The best answer you get when you try it out and see what happens in real .

So why dont you try it in your system and see what happens.

Here is the code which i tried out

OPEN DATASET '/tmp/test.txt' FOR INPUT IN TEXT MODE.

* Check the return code..
IF sy-subrc <> 0.
break-point.
*  MESSAGE E208(00) WITH 'File not found.'.
ENDIF.

It is not necessary thet every thing said during interview is correct in all situations , it is just based on the perception and observations of the person involved in it.

Regards

Arun

Former Member
0 Kudos
90

Hi,

If you satisfy with the answers, please reward & close the thread.

Regards,

donepudi

Former Member
0 Kudos
90

using sy-subrc..

after the fopen dataset statement .

if sy-subrc = 4.

error message.

endif .

Reward points if it is usefull ..

Girish

Former Member
0 Kudos
90

Thanks all