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: 

xml send to application server null character issue

crepmaster
Participant
0 Kudos
824

Hello expert, i'm facing an issue with xml file download on an application server and i went threw many threads such like like this one but i can't figure what i'am missing and why my file doesn't end with the last row.

i started building my file :

 lo_ixml = cl_ixml=>create( ).<br> lo_document = lo_ixml->create_document( ).<br>lo_header = lo_document->create_simple_element(<br> name = 'DHL-SHIPMENT-IMPORT'<br> parent = lo_document ).<br>*auth data<br> lo_auth_data = lo_document->create_simple_element(<br> name = 'AUTH_DATA'<br> parent = lo_header ).<br>lo_auth_group_id = lo_document->create_simple_element(<br> name = 'AUTH_GROUP_ID'<br> parent = lo_auth_data<br> value = 'Default group' ). etc...

then i make the transformation and transfert

  lo_stream_factory = lo_ixml->create_stream_factory( ).<br>  lo_encoding = lo_ixml->create_encoding( byte_order = 0<br>                                         character_set = 'UTF-8' ).<br>*document<br>  DATA b_xml TYPE xstring.<br>  DATA lo_ostream TYPE REF TO if_ixml_ostream.<br>  lo_ostream = lo_stream_factory->create_ostream_xstring( b_xml ).<br>  CALL METHOD lo_ostream->set_encoding<br>    EXPORTING<br>      encoding = lo_encoding.<br>  CALL METHOD lo_document->render<br>    EXPORTING<br>      ostream   = lo_ostream<br>      recursive = 'X'.<br>  DATA g_resize TYPE i.<br>  g_resize = lo_ostream->get_num_written_raw( ).<br>  DATA: ex_tab TYPE TABLE OF x255,<br>        ls_tab TYPE x255.<br>  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'<br>    EXPORTING<br>      buffer     = b_xml<br>    TABLES<br>      binary_tab = ex_tab.<br>*transfer file on the application server.<br>  READ TABLE a_lt_seg ASSIGNING <fs_seg> INDEX 1.<br>  CONCATENATE dset <fs_seg>-tknum '.xml' INTO dset.<br>  TRY.<br>      OPEN DATASET dset FOR OUTPUT IN BINARY MODE.<br>      LOOP AT ex_tab INTO ls_tab.<br>        g_resize = xSTRLEN( ls_tab ).<br>        TRANSFER ls_tab TO dset LENGTH g_resize.<br>      ENDLOOP.<br>    CATCH cx_root INTO lo_exception.<br>*     Gets error message<br>      CALL METHOD lo_exception->if_message~get_text<br>        RECEIVING<br>          result = l_message.<br>      MESSAGE l_message<br>         TYPE c_error.<br>  ENDTRY.<br>  CLOSE DATASET dset.
1 ACCEPTED SOLUTION

crepmaster
Participant
0 Kudos
678

i solved the issue by using FTP transfert

6 REPLIES 6

Harish_Vatsa
Active Contributor
678

Hello marco_sposa,

The null character issue may occur while transferring the XML file to the application server. To avoid this issue, you can convert the XML string to a binary string using the SCMS_XSTRING_TO_BINARY function. This function converts a string of type XSTRING to a table of type X255, which can be transferred to the application server without any null character issues.

In the code provided, this conversion is done using the following code:

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = b_xml
TABLES
binary_tab = ex_tab.

After the conversion, the binary data can be transferred to the application server using the TRANSFER statement with the LENGTH parameter to ensure that the entire binary string is transferred.

TRANSFER ls_tab TO dset LENGTH g_resize.

--

Kind Regards,

crepmaster
Participant
0 Kudos
678

sorry may be i'm getting you wrong but i'm already using it's why i'm wondering why i have the issue

  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = b_xml
TABLES
binary_tab = ex_tab.
*transfer file on the application server.


  READ TABLE a_lt_seg ASSIGNING <fs_seg> INDEX 1.
CONCATENATE dset <fs_seg>-tknum '.xml' INTO dset.
TRY.
OPEN DATASET dset FOR OUTPUT IN BINARY MODE.
LOOP AT ex_tab INTO ls_tab.
g_resize = xSTRLEN( ls_tab ).
TRANSFER ls_tab TO dset LENGTH g_resize.
ENDLOOP.
CATCH cx_root INTO lo_exception.
* Gets error message
CALL METHOD lo_exception->if_message~get_text
RECEIVING
result = l_message.

I

crepmaster
Participant
0 Kudos
679

i solved the issue by using FTP transfert

Sandra_Rossi
Active Contributor
0 Kudos
678

Be careful, your code was full of <br> so people might not do the effort of reading it. Your question, formatted correctly:

i started building my file :

lo_ixml = cl_ixml=>create( ).
lo_document = lo_ixml->create_document( ).
lo_header = lo_document->create_simple_element(
                 name   = 'DHL-SHIPMENT-IMPORT'
                 parent = lo_document ).
lo_auth_data = lo_document->create_simple_element(
                 name   = 'AUTH_DATA'
                 parent = lo_header ).
lo_auth_group_id = lo_document->create_simple_element(
                 name   = 'AUTH_GROUP_ID'
                 parent = lo_auth_data
                 value  = 'Default group' ).
...

then i make the transformation and transfert

  lo_stream_factory = lo_ixml->create_stream_factory( ).
  lo_encoding = lo_ixml->create_encoding( byte_order = 0
                                         character_set = 'UTF-8' ).
*document
  DATA b_xml TYPE xstring.
  DATA lo_ostream TYPE REF TO if_ixml_ostream.
  lo_ostream = lo_stream_factory->create_ostream_xstring( b_xml ).
  CALL METHOD lo_ostream->set_encoding
    EXPORTING
      encoding = lo_encoding.
  CALL METHOD lo_document->render
    EXPORTING
      ostream   = lo_ostream
      recursive = 'X'.
  DATA g_resize TYPE i.
  g_resize = lo_ostream->get_num_written_raw( ).
  DATA: ex_tab TYPE TABLE OF x255,
        ls_tab TYPE x255.
  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
    EXPORTING
      buffer     = b_xml
    TABLES
      binary_tab = ex_tab.
*transfer file on the application server.
  READ TABLE a_lt_seg ASSIGNING <fs_seg> INDEX 1.
  CONCATENATE dset <fs_seg>-tknum '.xml' INTO dset.
  TRY.
      OPEN DATASET dset FOR OUTPUT IN BINARY MODE.
      LOOP AT ex_tab INTO ls_tab.
        g_resize = xSTRLEN( ls_tab ).
        TRANSFER ls_tab TO dset LENGTH g_resize.
      ENDLOOP.
    CATCH cx_root INTO lo_exception.
*     Gets error message
      CALL METHOD lo_exception->if_message~get_text
        RECEIVING
          result = l_message.
      MESSAGE l_message
         TYPE c_error.
  ENDTRY.
  CLOSE DATASET dset.

Sandra_Rossi
Active Contributor
0 Kudos
678

When it's about writing an XSTRING variable to a file on the application server, as BINARY MODE, you can simply do:

  TRY.
      OPEN DATASET dset FOR OUTPUT IN BINARY MODE.
      IF sy-subrc = 0.
        TRANSFER b_xml TO dset.
        CLOSE DATASET dset.
NB: the error in your original code is in the 2 lines below, you use XSTRLEN on an X variable of length 255 bytes, which always return 255, even for the last line of EX_TAB, and consequently you write extra null bytes:
      LOOP AT ex_tab INTO ls_tab.
        g_resize = xSTRLEN( ls_tab ).

0 Kudos
678

Thank you Sandra for your help!