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: 

Error in OPEN DATASET OUTFILE FOR OUTPUT IN TEXT MODE

siongchao_ng
Contributor
0 Kudos

Hi all,

The sy-subrc after the open dataset statement is 4. What can I do to make the open dataset work? Thanks all.

Code snippet:

open dataset out_file for output in text mode ENCODING NON-UNICODE.

LOOP AT output_tab.

size = strlen( output_tab ).

insert_string = ''.

DO size TIMES.

offset = sy-index - 1.

try.

out_char = output_tab+offset(1).

IF out_char = SPACE.

CONCATENATE insert_string '' INTO insert_string SEPARATED BY SPACE.

ELSE.

CONCATENATE insert_string out_char INTO insert_string.

transfer insert_string to out_file NO END OF LINE .

insert_string = ''.

ENDIF.

catch CX_SY_CONVERSION_CODEPAGE.

insert_size = strlen( insert_string ) - 1.

insert_string = insert_string(insert_size).

endtry.

ENDDO.

transfer CL_ABAP_CHAR_UTILITIES=>NEWLINE TO out_file NO END OF LINE.

ENDLOOP.

close dataset out_file.

Edited by: Siong Chao on Sep 25, 2011 11:22 AM

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Use the addition [MESSAGE msg] in your OPEN DATASET statement to have an idea of what's happening. Your path is probably wrong.


DATA: msg(60) type c.
OPEN DATASET fname FOR OUTPUT MESSAGE msg.  

Kr,

Manu

7 REPLIES 7

Former Member
0 Kudos

Hi,

Use the addition [MESSAGE msg] in your OPEN DATASET statement to have an idea of what's happening. Your path is probably wrong.


DATA: msg(60) type c.
OPEN DATASET fname FOR OUTPUT MESSAGE msg.  

Kr,

Manu

0 Kudos

Hi Manu,

I tried this before and I got the message " File not open" " Path Not available".

I re-checked my path (somewhere on my desktop) and I am certain I got the file path correct.

Example. I right-click a folder named "chao" and found the location path is C:\Users\USER\Desktop

So the file path will be C:\Users\USER\Desktop\chao\abc.txt

Am I right with the path?

0 Kudos

Hi,

The file must be accessible from the application server. You cannot use OPEN DATASET to process files on the current presentation server (whether PC or workstation)....

To create a file on your desktop you should use the method GUI_DOWNLOAD of class CL_GUI_FRONTEND_SERVICES.

Kr,

m.

0 Kudos

Hi Manu,

Thanks for your reply. The requirement is I need to create the text file in the application server. So how do I get around the path app server?

0 Kudos

Well, you could check transaction AL11 and choose a valid SAP directory to put the file in...

Something like: //servername/directory/filename...

concrete example:


DATA: e_file like rlgrap-filename value '/usr/sap/tmp/file.txt'.

  open dataset e_file for output in text mode.
  lOOP AT it_datatab......
    transfer it_datatab to e_file.
  ENDLOOP.

Kr,

m.

Edited by: Manu D'Haeyer on Sep 25, 2011 12:13 PM

0 Kudos

Hi Siong Chao,

the application server is the SAP server - this is where your SAP system is running. The desktop is located on your presentation server. Only the SAPGUI is connected to the presentation server. That means GUI_DOWNLOAD is for fiel export to the (local) presentation server, i.e. your PC.

Open dataset can access the application server. This is independent from presebntation server and can be used for background jobs also. The I/O speed for datasets is hundreds or thousand times faster than GUI because no network is involved.

As soon as the requirement is clear, the solution is right araound the corner.

Regards

Clemens

0 Kudos

HI Manu,

I cannot acccess transaction AL11.

I am having trouble getting the in application server.

I tried goto local objects and create a test folder named 'Outbound'. Then I import a text file just to see the path. But I cannot find the path from the text file itself.

I right click on the text file then goto properties. Inside the properties, I looked up all the tabs of shares/properties/log.doc.properties/technical information, I still cannot get the path.

Edited by: Siong Chao on Sep 26, 2011 6:39 AM