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 encoding UTF-8

Former Member
0 Likes
12,767

Hello Everyone,

I have developed an extract program which extracts a space separated text file to the application server and this file is picked by another schedule job from the operating system and posted to our SFTP site. The problem which I have is when our partners try to open the file in Notepad++ they are seeing a u201Cnullu201D character in the middle of all the fields. I have solved the issue by manually changing the format of the file to UFT-8 format and it works fine. When I tried to do the same electronically I could not able to achieve it, I donu2019t understand why? Could someone help me with the code below?

  • Open output file.

OPEN DATASET wf_file FOR OUTPUT IN TEXT MODE ENCODING UTF-8.MESSAGE wf_msg.

This is the code I am using to extract a file with UTF-8 format but the file is in ANSI format.

Thanks,

Pradeep

1 ACCEPTED SOLUTION
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
6,490

Check this link

link:[http://help.sap.com/saphelp_NW70EHP1/helpdata/en/79/c554dcb3dc11d5993800508b6b8b11/content.htm]

link:[BYTE-ORDER MARK|http://help.sap.com/abapdocu_70/en/ABAPOPEN_DATASET_ENCODING.htm]

8 REPLIES 8
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
6,491

Check this link

link:[http://help.sap.com/saphelp_NW70EHP1/helpdata/en/79/c554dcb3dc11d5993800508b6b8b11/content.htm]

link:[BYTE-ORDER MARK|http://help.sap.com/abapdocu_70/en/ABAPOPEN_DATASET_ENCODING.htm]

Read only

0 Likes
6,490

I am sorry! I cannot find answers from your reply. Thanks for trying.

Read only

0 Likes
6,490

try this one

OPEN DATASET gv_file FOR INPUT IN TEXT MODE ENCODING NON-UNICODE

WITH SMART LINEFEED.

Read only

0 Likes
6,490

Just to be clear about my issue, I am extracting a file to the Application server with space in-between fields not a linefeed. I want the file to be extracted in UFT-8 format not in ANSI. That's my requirement.

Hope you have understood.

Thanks,

Read only

0 Likes
6,490

have you try this code OPEN DATASET gv_file FOR INPUT IN TEXT MODE ENCODING NON-UNICODE

first try and then give reply, this is for UTF-8 format onlyy...........

Read only

0 Likes
6,490

Hello Chenna,

I am 200% sure that to write to a file I have to use FOR OUTPUT in the syntax and non-Unicode means "Characters are represented in the file in the code page defined by the text environment current at the time a READ or TRANSFER command is executedu201D. Therefore I Kindly requests you to, not to waste your time and mine.

Thanks,

Read only

0 Likes
6,490

Hi!

I solved the same problem reading the responses above but looking for the appropriate tools

Use the converter object but for output format : cl_abap_conv_out_ce.

The code should look like this :


DATA : lo_conv      TYPE REF TO cl_abap_conv_out_ce,
             lv_xstring   TYPE xstring.

* Encoding format
lo_conv = cl_abap_conv_out_ce=>create( encoding  = 'UTF-8' ).

TRY. "For BOM if needed
        lo_conv->write( EXPORTING data   = cl_abap_char_utilities=>byte_order_mark_utf8 ).
    CATCH cx_sy_codepage_converter_init .
    CATCH cx_sy_conversion_codepage .
    CATCH cx_parameter_invalid_type .
    CATCH cx_parameter_invalid_range .
ENDTRY.

*here data is a string table but you can use structure with another method
LOOP AT data_table  INTO data_line.
    TRY.
          lo_conv->write( EXPORTING data   = data_line ).
        CATCH cx_sy_codepage_converter_init .
        CATCH cx_sy_conversion_codepage .
        CATCH cx_parameter_invalid_type .
        CATCH cx_parameter_invalid_range .
    ENDTRY.
*   next line!
    TRY.
          lo_conv->write( EXPORTING data   = cl_abap_char_utilities=>cr_lf ).
        CATCH cx_sy_codepage_converter_init .
        CATCH cx_sy_conversion_codepage .
        CATCH cx_parameter_invalid_type .
        CATCH cx_parameter_invalid_range .
    ENDTRY.
ENDLOOP.

*get full content in one xstring 
lv_xstring = lo_conv->get_buffer( ).

* et voila!! 
OPEN DATASET lv_filename FOR OUTPUT IN BINARY MODE.
IF sy-subrc EQ 0.
  TRANSFER lv_xline TO lv_filename.
  CLOSE DATASET lv_filename.
ENDIF.

Hope this help!!

Edited by: LRookie on Feb 4, 2010 1:46 PM

Edited by: LRookie on Feb 5, 2010 9:41 AM

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
6,490

This link:[Download File in UTF-8 encoding |http://wiki.sdn.sap.com/wiki/display/ABAP/DownloadFileinUTF-8encoding]says how to download in presentation server.

Jus add BOM in front of the first record.

Follow the same method and add it in your code.

Its clearly mentioned in the link i provided.