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

Issue with BYTE ORDER MARK file

former_member212705
Active Participant
0 Likes
4,470


Hi experts,

I am facing one issue. My user wants file with UTF8 with byte order mark. I am working on SAP 4.7

so syntex 'Open dataset..encoding UTF-8... with byte order mark' is giving error. so what i did

i just converted the string to Xsring , i added byte order mark in starting and again converted that xstring to string.

below is my code

  app_type = 'text/plain; charset=utf-8'.

    LOOP AT i_server INTO lw_server.

**************************************

      CLEAR xs_content.

      CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

        EXPORTING

          text     lw_server-string

          mimetype = app_type

        IMPORTING

          buffer   = xs_content.

      CONCATENATE  cl_abap_char_utilities=>byte_order_mark_utf8

      xs_content            INTO xs_content IN BYTE MODE.

      CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'

        EXPORTING

         from_codepage       = '4110'

          in_xstring          = xs_content

*   OUT_LEN             =

       IMPORTING

         out_string          = text_buffer

                .

transfer text_bueffer to l_server.

endloop.

now issue is that string should be like this

4260#1001300029#####;#;#;#;#  (here # - space)

but it is coming like that

4  260#1001300029#####;#;#;#;#

automatically space type thing is getting inserted between.

May be this is due to byte order mark. its very strange.

if anybody has any idea please help me.

Regards,

Ashish

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,510

hi,

use below logic to convert UTF8 format

  DATA:

  v_string TYPE string,

  v_xsrting TYPE xstring,

  v_len TYPE i,

  rc TYPE i VALUE 0,

  v_encoding TYPE abap_encoding.

* Get the LOGON Encoding for the particular user

  CALL METHOD cl_gui_frontend_services=>get_saplogon_encoding

    CHANGING

      rc                            = rc

      file_encoding                 = v_encoding

    EXCEPTIONS

      cntl_error                    = 1

      error_no_gui                  = 2

      not_supported_by_gui          = 3

      cannot_initialize_globalstate = 4

      OTHERS                        = 5.

  IF sy-subrc NE 0 OR

  v_encoding = 0.

    CLEAR v_encoding.

  ENDIF.                                         " IF sy-subrc NE 0 OR ......

  CHECK v_encoding IS NOT INITIAL.

* Attribute for UTF-8 format

  v_xsrting = cl_abap_char_utilities=>byte_order_mark_utf8.

  DATA: v_conv TYPE REF TO cl_abap_conv_in_ce.

* Create a Conversion Instance

  v_conv = cl_abap_conv_in_ce=>create(

  encoding = v_encoding

  input = v_xsrting ).

  v_conv->read( IMPORTING data = v_string ).

  LOOP AT t_file_output INTO fs_file_output.

    CONCATENATE v_string fs_file_output-line INTO li_data_line-line.

    APPEND li_data_line TO li_data.

  ENDLOOP. 

            

4 REPLIES 4
Read only

Former Member
0 Likes
2,511

hi,

use below logic to convert UTF8 format

  DATA:

  v_string TYPE string,

  v_xsrting TYPE xstring,

  v_len TYPE i,

  rc TYPE i VALUE 0,

  v_encoding TYPE abap_encoding.

* Get the LOGON Encoding for the particular user

  CALL METHOD cl_gui_frontend_services=>get_saplogon_encoding

    CHANGING

      rc                            = rc

      file_encoding                 = v_encoding

    EXCEPTIONS

      cntl_error                    = 1

      error_no_gui                  = 2

      not_supported_by_gui          = 3

      cannot_initialize_globalstate = 4

      OTHERS                        = 5.

  IF sy-subrc NE 0 OR

  v_encoding = 0.

    CLEAR v_encoding.

  ENDIF.                                         " IF sy-subrc NE 0 OR ......

  CHECK v_encoding IS NOT INITIAL.

* Attribute for UTF-8 format

  v_xsrting = cl_abap_char_utilities=>byte_order_mark_utf8.

  DATA: v_conv TYPE REF TO cl_abap_conv_in_ce.

* Create a Conversion Instance

  v_conv = cl_abap_conv_in_ce=>create(

  encoding = v_encoding

  input = v_xsrting ).

  v_conv->read( IMPORTING data = v_string ).

  LOOP AT t_file_output INTO fs_file_output.

    CONCATENATE v_string fs_file_output-line INTO li_data_line-line.

    APPEND li_data_line TO li_data.

  ENDLOOP. 

            

Read only

0 Likes
2,510

Thanks Naga , i am trying, will let you know

Read only

0 Likes
2,510

Hi Ashish,

  if usefully please add the points.

Read only

former_member212705
Active Participant
0 Likes
2,510

Other way to solve this issue. first write all you data into one single string. and then convert that string to XSTRING . Then add byte order mark at first place. Then again convert into string.

But i believe ECC6 user will never face this issue, there is already syntex Open dataset....with byte order mark...

Thank you all