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

XML encoding=utf-8 vs. encoding=UTF-8

Former Member
0 Likes
1,547

Hey experts,

at the moment I'm working with XML-files. And I found out, that there is a strange behaviour of the SAP system regarding the codepage.

Within the original XML-file the codepage is written in capital letters: UTF-8

But when I import the file and display the content (for example via function module DISPLAY_XML_STREAM) then the codepage is changed automatically into small letters: utf-8

My problem is, that I have to change the content of the file. And if I save the "new" file to a directory, the codepage is than written with the small letters.

Has anybody an idea why this happens? And does anybody know if it is a problem?

Thank you in advance! 🙂

Best regards,

Eva

I attached two screenshots. One ist the file content, displayed in AL11. And the other is the displayed file content within my test report.

And here is my sample code:

*&---------------------------------------------------------------------*

*& Report  ZET_TEST_XML_BASE

*&

*&---------------------------------------------------------------------*

REPORT  zet_test_xml_base.

TYPE-POOLS: abap.

DATA:

   lr_document_base           TYPE REF TO cl_xml_document_base,

   lr_node                    TYPE REF TO if_ixml_node,

   ld_nodename                TYPE string,

   ld_value                   TYPE string,

   ld_xml_data                TYPE xstring,

   ld_string                  TYPE string,

   ld_xstring                 TYPE xstring,

   ld_subrc                   TYPE sysubrc.

SELECTION-SCREEN BEGIN OF BLOCK selection WITH FRAME.

PARAMETERS: p_disp         TYPE xfeld RADIOBUTTON GROUP one.

PARAMETERS: p_change       TYPE xfeld RADIOBUTTON GROUP one.

SELECTION-SCREEN END OF BLOCK selection.

START-OF-SELECTION.

   OPEN DATASET '/usr/sapio/RDF/xml/SEPA-190713.XML' FOR INPUT IN BINARY MODE.

   READ DATASET '/usr/sapio/RDF/xml/SEPA-190713.XML' INTO ld_xml_data.

   CLOSE DATASET '/usr/sapio/RDF/xml/SEPA-190713.XML'.

   CREATE OBJECT lr_document_base.

   lr_document_base->parse_xstring( ld_xml_data ).

   IF p_disp = abap_true.

*    display the file

     CALL SCREEN 100.

     RETURN.

   ENDIF.

*  change the content of the file

   lr_node = lr_document_base->find_node( name   = 'Cd' ).

   IF lr_node IS INITIAL.

     RETURN.

   ELSE.

     ld_nodename = lr_node->get_name( ).

     IF ld_nodename = 'Cd'.

       ld_value = lr_node->get_value( ).

       IF ld_value = 'SEPA'.

         lr_node->set_value( 'URGP' ).

       ELSEIF ld_value = 'URGP'.

         lr_node->set_value( 'SEPA' ).

       ENDIF.

     ENDIF.

   ENDIF.

*lr_document_base->render_2_string( EXPORTING pretty_print = abap_false

*                                   IMPORTING  retcode = ld_subrc

*                                              stream = ld_string ).

   lr_document_base->render_2_xstring( EXPORTING pretty_print = abap_false

                                       IMPORTING retcode = ld_subrc

                                                 stream = ld_xstring ).

*  save the "new" file

   OPEN DATASET '/usr/sapio/RDF/xml/SEPA-190713-2.XML' FOR OUTPUT IN BINARY MODE.

   TRANSFER ld_xstring TO '/usr/sapio/RDF/xml/SEPA-190713-2.XML'.

   CLOSE DATASET '/usr/sapio/RDF/xml/SEPA-190713-2.XML'.

*  display the "new" file

   CALL SCREEN 100.

*&---------------------------------------------------------------------*

*&      Module  USER_COMMAND_0100  INPUT

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

MODULE user_command_0100 INPUT.

   LEAVE TO SCREEN 0.

ENDMODULE.                 " USER_COMMAND_0100  INPUT

*&---------------------------------------------------------------------*

*&      Module  STATUS_0100  OUTPUT

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

MODULE status_0100 OUTPUT.

   SET PF-STATUS '100'.

   SET TITLEBAR '100'.

   DATA:

     lr_gui_container         TYPE REF TO cl_gui_custom_container,

     lr_html_view             TYPE REF TO cl_gui_html_viewer,

     lt_xml                   TYPE swxmlcont,

     ld_data_size             TYPE int4,

     ld_url                   TYPE char255.

*  --- get gui-container ---

   CREATE OBJECT lr_gui_container

     EXPORTING

        container_name          = 'GUI_CONTAINER_X'

        lifetime                = cl_gui_container=>lifetime_dynpro

        repid                   = sy-repid

        dynnr                   = sy-dynnr

*       NO_AUTODEF_PROGID_DYNNR = 'X'

     EXCEPTIONS

        OTHERS = 99.

*  --- init html contol ---

   CREATE OBJECT lr_html_view

     EXPORTING

       parent = lr_gui_container

     EXCEPTIONS

       OTHERS = 99.

*  --- move xml into html contol ---

   CALL METHOD lr_document_base->render_2_table

     EXPORTING

      pretty_print = abap_true

     IMPORTING

*   retcode      =

      table        = lt_xml

      size         = ld_data_size.

   CALL METHOD lr_html_view->load_data

     EXPORTING

       subtype      = 'xml'

       size         = ld_data_size

     IMPORTING

       assigned_url = ld_url

     CHANGING

       data_table   = lt_xml.

   CALL METHOD lr_html_view->show_data

     EXPORTING

       url = ld_url.

ENDMODULE.                 " STATUS_0100  OUTPUT

3 REPLIES 3
Read only

Former Member
0 Likes
1,049

I cannot see that being a problem. Its still a perfectly valid code page. I would guess it depends on the source system that is reading it but I cannot see it being an issue.

Have you tried loading the file using encoding UTF-8? i.e.

Open dataset yyyy for input encoding utf-8.

I also noticed you could set the abap pretty print to abap_true. Tried that?

Read only

0 Likes
1,049

Hi Adam,

thank you for your answer! 🙂

No, I haven't tried it with ENCODING UTF-8 because I do not want to change the Codepage of the file. And I'm reading it in BINARY MODE, so I can't use ENCODING (you can only use it with TEXT MODE).

But never the less, I don't want to change the codepage.

And the pretty print doesn't help, too.

So I hope it's no problem that it's written in small letters... I searched via google and the only thing I found was that it should be written in capital letters.

Best regards,

Eva

Read only

0 Likes
1,049

That is a good point! I didnt try your code out and without the aid of auto complete I had forgot that.

I dont see it being a problem as I have a few Java programs that I have developed that use XML. I changed UTF-8 from and two upper case and it made no effect. I guess It might fail validation checks but these are always over egged anyway so who really cares.

Cheers,