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

Problem in outputting a string into a file

Former Member
0 Likes
833

Hi guys,

I tried to output a string to a file. The string is 'Size : 30u201D X 13 ½u201D X17 ¾u201D(H)'.

However, with this code :

l_file = '/erp/reports/testgk.txt'.

l_str = 'Size : 30u201D X 13 ½u201D X17 ¾u201D(H)'.

OPEN DATASET l_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

TRANSFER l_str TO l_file.

It returned me a weird string: 'Size : 30M-bM-@M-] X 13 M-BM-=M-bM-@M-] X17 M-BM->M-bM-@M-](H)'

Would you please let me know how to solve this problem?

Thanks, gk

Hi guys,

I tried to output a string to a file. The string is 'Size : 30u201D X 13 ½u201D X17 ¾u201D(H)'.

However, with this code :

l_file = '/erp/reports/testgk.txt'.

l_str = 'Size : 30u201D X 13 ½u201D X17 ¾u201D(H)'.

OPEN DATASET l_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

TRANSFER l_str TO l_file.

It returned me a weird string: 'Size : 30M-bM-@M-] X 13 M-BM-=M-bM-@M-] X17 M-BM->M-bM-@M-](H)'

Would you please let me know how to solve this problem?

Thanks, gk

5 REPLIES 5
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
787

Hello gk,

I tried this code & works fine for me though:

DATA: v_data TYPE string VALUE ' 30u201D X 13 ½u201D X17 ¾u201D(H)',
      v_file TYPE string VALUE
              '\glbwi720InterfaceID2100I_MB_207INsdn.txt'.

OPEN DATASET v_file FOR OUTPUT
IN TEXT MODE 
ENCODING DEFAULT.
IF sy-subrc = 0.
  TRANSFER v_data TO v_file.
  CLOSE DATASET v_file.
ENDIF.

Looks like the "usual" ENCODING problem

BR,

Suhas

Read only

Former Member
0 Likes
787

Hi Suhas, thanks for trying. I think it only works if you download the file to Windows. If you download the file into a Unix environment, then the same problem will occur. Thanks.

Read only

Former Member
0 Likes
787

Hi,

Have you written the code as below :

data : filename(50) value './test.txt'.

data : str(80) value 'Size : 30u201D X 13 ½u201D X17 ¾u201D(H)'.

open dataset filename for output in text mode encoding default.

if sy-subrc = 0.

transfer str to filename.

endif.

close dataset filename.

This code is working properly.

Read only

0 Likes
787

Hi Sonal, yes - i have tried it. Still got the same problem. What was outputted on the file is :

'Size : 30M-bM-@M-] X 13 M-BM-=M-bM-@M-] X17 M-BM->M-bM-@M-](H)'

Thanks.

Read only

Former Member
0 Likes
787

Hi,

I can't decode what is your Unix environment encoding, but I am sure that non-ascii characters are encoded to multi-byte strings. Try to change "ENCODING DEFAULT" to proper encoding name and it should work.

Pavel