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 OUTPUT

Former Member
0 Likes
3,208

Hello Guru's

I am having dificulties with OPEN DATASET OUTPUT. When I run my report I am not getting any output.

I have the following piece of code:

OPEN DATASET filename FOR OUTPUT IN TEXT MODE MESSAGE D_MSG_TEXT ENCODING DEFAULT.

IF sy-subrc <> 0.

write: 'file could not be opened, reason:' D_MSG_TEXT.

exit.

endif.

Loop at itab.

transfer itab-field to filename.

endloop.

Close dataset filename.

Sy-subrc = 0 so the file could be opened/created but there is no data being transfered and the itab contains data. Does anybody know why it doen't work?

Best regards,

Guido

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,700

Hi Gowri

I have tried it, but it doesn't make any difference wheter I use a workarea or not.

Thnx though.

Anyone else any idea's?

Hi Gowri

I have tried it, but it doesn't make any difference wheter I use a workarea or not.

Thnx though.

Anyone else any idea's?

8 REPLIES 8
Read only

Former Member
0 Likes
2,700

Hi

If you're sure the table is filled are u sure the file was created?

Max

Read only

0 Likes
2,700

Hi,

I checked sy-subrc = 0 and this was the case, so the file is created then, right?

Guido

Read only

Former Member
0 Likes
2,700

Hi

Use like this....



OPEN DATASET filename FOR OUTPUT IN TEXT MODE MESSAGE D_MSG_TEXT ENCODING DEFAULT.
IF sy-subrc ne 0.
write: 'file could not be opened, reason:' D_MSG_TEXT.
exit.
endif.
Loop at itab into <workarea>.
transfer <workarea>-field to filename.
endloop.
Close dataset filename.

Hope it will helps

Read only

former_member404244
Active Contributor
0 Likes
2,700

Hi,

Check the below link..

http://www.sapdev.co.uk/file/file_downloadsap.htm

Regards,

Nagaraj

Read only

Former Member
0 Likes
2,701

Hi Gowri

I have tried it, but it doesn't make any difference wheter I use a workarea or not.

Thnx though.

Anyone else any idea's?

Read only

0 Likes
2,700

Try opening in UPDATE mode:

OPEN DATASET file FOR UPDATE ...

Read only

0 Likes
2,700

Hi

Try to check the sap server in order to know if the file was created: if SY-SUBRC is equal to 0 the file should be created so it's very strange u can't see any data there.

If you had authorization problem the OPEN DATASET would fail.

Max

Read only

Former Member
0 Likes
2,700

Hi guido,

We use the following and it works fine. The one thing we did have an issue with initially was the permissions on the directory we were trying to write to, since the file goes to the application server. Talk to your network guys if you are still having problems.


DATA: dsn(40) VALUE '/usr/filename.txt'.
DATA: wa_itab like line of itab.

OPEN DATASET dsn FOR APPENDING IN TEXT MODE ENCODING DEFAULT.
IF SY-SUBRC = 0.
  LOOP AT ITAB INTO wa_itab.
    TRANSFER wa_itab TO dsn.
  ENDLOOP.
ENDIF.
CLOSE DATASET dsn.

Good Luck

-SL