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: 

Problem in coverting XML data to Interal Table.

0 Kudos

Hello,

I have to write an application which converts an Internal Table Data to XML String and then from XML String to an Internal Table.

The reason for doing is that I am using an RFC Function module and the internal table is dynamically generated one.

But somehow the XML data is not getting converted to Internal Table.

The RFC returns Internal Table Data as XML and the Field Catalogue table

Now in the application which calls RFC, I am trying to convert XML data to a dynamic Internal table

CALL FUNCTION 'SAP_CONVERT_TO_XML_FORMAT'
  CALL FUNCTION 'SCMS_BINARY_TO_STRING'
.

Now convert XML String to Internal table

Using FMs 'SCMS_STRING_TO_XSTRING'

"Now XString to Binary

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

CALL FUNCTION 'TEXT_CONVERT_XML_TO_SAP'
    EXPORTING
      i_tab_raw_data             = lt_xml_data
      i_totalsize                = lv_file_size
    TABLES
      i_tab_converted_data       = <fst_dyn_table>
   EXCEPTIONS
     conversion_failed          = 1
     OTHERS                     = 2

In the FM 'TEXT_CONVERT_XML_TO_SAP' I am getting error Conversion failed.

Now I tried with transformations.

Here also my table is a dynamically created Internal table.

TRY.
      CALL TRANSFORMATION ('ID')
       SOURCE root = lt_zmt_tdm_fmap
          RESULT XML lv_output_str.

    CATCH cx_root INTO gs_rif_ex.

      gs_var_text = gs_rif_ex->get_text( ).
      MESSAGE gs_var_text TYPE 'I'.
  ENDTRY.

Now the lv_output_str gets populated with data

But when I call Transformation again to convert XML to internal table, it does not throw error, but does not return any data also.

TRY.
      CALL TRANSFORMATION ('ID')
      SOURCE XML = lv_output_str
      RESULT ref = <fst_dyn_table> .
    CATCH cx_root INTO gs_rif_ex.

      gs_var_text = gs_rif_ex->get_text( ).
      MESSAGE gs_var_text TYPE 'I'.
  ENDTRY.

How can this be resolved.

As pointed I am using RFC Function module, the parameters will be

1) XML String with Internal table data

2) Field Catalogue for Internal Table to be created dynamically.

Regards,

Vikas

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
0 Kudos

>

>


>       CALL TRANSFORMATION ('ID')
>       SOURCE XML = lv_output_str "<============ ERRONEOUS = HERE
>       RESULT ref = <fst_dyn_table> .
> 

Remove the "=" sign, this code will work :


      CALL TRANSFORMATION ('ID')
      SOURCE XML lv_output_str
      RESULT ref = <fst_dyn_table> .

3 REPLIES 3

Sandra_Rossi
Active Contributor
0 Kudos

>

>


>       CALL TRANSFORMATION ('ID')
>       SOURCE XML = lv_output_str "<============ ERRONEOUS = HERE
>       RESULT ref = <fst_dyn_table> .
> 

Remove the "=" sign, this code will work :


      CALL TRANSFORMATION ('ID')
      SOURCE XML lv_output_str
      RESULT ref = <fst_dyn_table> .

0 Kudos

Thanks Sandra,

I had resolved it , the changes were

to convert to XML

CALL TRANSFORMATION ('ID')
       SOURCE itab = <fst_dyn_table>
          RESULT XML lv_output_xml_str.

And then XML to internal table

CALL TRANSFORMATION ('ID')
       SOURCE XML lv_output_xml_str
          RESULT itab = <fst_dyn_table2>.

0 Kudos

So, the problem was exactly what I said. In respect to people who are looking for an answer. IN THE FUTURE, you'd better give full points to the person who replies right (rather than just say "helpful").

Note: try to keep coherent your code between the question and the answer, so that people who are looking for answers are not disturbed (here you replaced LV_OUTPUT_STR with LV_OUTPUT_XML_STR).