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

open dataset in background problem

Former Member
0 Likes
3,793

Hi all,

When executing a program with an open dataset for output in background for the first time, I have no problems. After this, I move the file to the presentation server deleting the file on the application server (delete dataset). The next time I execute the program with the open dataset in background I get a "no such file or directory" error. I expect the program to create the file as it did the first time.

Any ideas for this problem?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,919

Hi,

I did use the message option (I forgot it in the code) and I get the message "no such file or directory". Error occurs only in background and only the second or third time I start the program.

Richard

11 REPLIES 11
Read only

Former Member
0 Likes
1,919

Hi

How do you re-open file?

I wrote this easy program and it runs fine:

PARAMETER: p_file(80),

p_dele AS CHECKBOX.

IF p_dele = space.

OPEN DATASET p_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc = 0.

TRANSFER 'CIAO' TO p_file.

ENDIF.

CLOSE DATASET p_file.

ELSE.

DELETE DATASET p_file.

ENDIF.

Max

Read only

Former Member
0 Likes
1,919

Did you CLOSE the DATASET? Here is the sequence of operations.

OPEN DATASET

TRANSFER RECORDS TO DATASET.

CLOSE DATASET.

COPY FILE TO PRESENTATION SERVER.

DELETE DATASET.

OPEN THE DATASET AGAIN AND REPEAT THE STEPS.

Read only

Former Member
0 Likes
1,919

Thanks for your replies,

When I put all the statements in one program it works fine, but the problem is this:

program 1: open dataset for output in a job => OK

program 2: delete dataset in foreground => OK

program 1: open dataset for output in a job => "No such file or directory"

The name for the dataset is the same everytime, and when I execute program 1 in the foreground (step 3), it works fine too.

Richard

Read only

0 Likes
1,919

Hi,

Please paste the code of your program 1.

Svetlin

Read only

Former Member
0 Likes
1,919

Svetlin,

I have no connection to SAP right now, but the code is like this:

  • Check whether the file already exists, an existing file may not be overwritten

open dataset ... for input in text mode encoding default.

if sy-subrc = 0.

message e... "file already exist

endif.

close dataset ...

Further on in the program I check whether the specified file can be written to (before I run the rest of the program):

open dataset ... for output in text mode encoding default.

if sy-subrc ne 0.

message e... "cannot write to ...

endif.

close dataset ...

delete dataset ...

This is also the part where it goes wrong. When I execute it in foreground, all is ok, but in background I get the error message (after the open dataset statement).

Richard

Read only

Former Member
0 Likes
1,919

You may be getting the wrong message . The message you are mentioning will always come from O/s and will happen only when you try to open a file in a non existing directory . If directory path is correct file will be created or overwritten or "Files exists " exception will be thrown.

Try this , it will capture correct O/s message

DATA: MESS(60).

open dataset DSN for output in text mode encoding default

message mess.

if sy-subrc ne 0.

write 😕 mess.

endif.

Cheers

Read only

Former Member
0 Likes
1,920

Hi,

I did use the message option (I forgot it in the code) and I get the message "no such file or directory". Error occurs only in background and only the second or third time I start the program.

Richard

Read only

0 Likes
1,919

This might help you .....Your problem seems to related with stmt in Bold. Check in SM51..

From one of my articles...all may not be relevant to you.

Did you check that the shared directory, being accessed in your program, is accessible from all the Servers ( Development, Test as well as Production )?

<b>

And did you also check that directory is accessible from all the Application Servers, in case there are multiple Application Servers in production?

</b>

Your customer reported that he is not able to download the file on configured directory and program is terminating with some message like ‘File could not be opened’ or ‘Directory not accessible’.

You tried from your side and everything is working fine.

So do you think that now your user is trying to irritate you like you did to him earlier?

Not really, just check out and there might be multiple Application Servers in production ( Use Transaction SM51 ) and probably the way you coded and configured file path, either you made it Application Server dependent or it is not accessible from all the application servers ( except from the central instance as this particular directory is only created on central application server ). e.g in FILE transaction, you have configured the file path as


< INSTANCE>\Outbound’ or ‘
< HOST>\Outbound’

Now, since as a developer, you generally login to central instance, you will not be able to see the problem unless you deliberately login to other instances. Ask the user to run it from central instance for the time being and then modify you program to make the file path instance independent.

Cheers,

Ram

Read only

Former Member
0 Likes
1,919

Hi Ram,

At the moment the problem is only in development, because we are still busy with the programs. I saw with SM51 that there are two application servers for development. I'm going to try to change the programs in the way you described.

Thank you very much for your reply, it seems very hopefull.

Greetings,

Richard

Read only

Former Member
0 Likes
1,919

Hi Ram,

I made the modification and it workes!!

Thank you all for your replies.

Richard

Read only

0 Likes
1,919

Hi Richard

I have same problem.

Could u suggest the way to improve coding to access input file?

I refer to server file like /inf/...in open dataset statement.

best regards,

Sasitha K.