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 to ABAP Conversion Error - CX_SY_CONVERSION_DATA_LOSS

Former Member
0 Likes
5,483

REPORT  y_rpt_test                              .
TYPE-POOLS sscr.
DATA: restrict TYPE sscr_restrict,
opt_list TYPE sscr_opt_list,
ass TYPE sscr_ass.
DATA: options TYPE STANDARD TABLE OF rfc_db_opt ,
fields TYPE STANDARD TABLE OF rfc_db_fld ,
meta TYPE STANDARD TABLE OF ywas_metadata ,
xml_out TYPE string .
data: xml_out_x type xstring.
DATA: wa_options LIKE LINE OF options,
wa_fields LIKE LINE OF fields ,
wa_meta LIKE LINE OF meta .
FIELD-SYMBOLS: <outtab> TYPE ANY TABLE,
<l_line> TYPE ANY,
<l_field> TYPE ANY.
DATA: new_table TYPE REF TO data.
DATA: new_line TYPE REF TO data.
DATA: xslt_error TYPE REF TO cx_xslt_exception ,
xslt_message TYPE string .
DATA: it_fieldcat TYPE lvc_t_fcat,
is_fieldcat LIKE LINE OF it_fieldcat.

TYPES: BEGIN OF s_text,
         partnum(18)     TYPE c,
         LONG_DESC(3000)    TYPE c,
       END OF s_text.
data: lt_outtab type standard table of s_text,
      is_outtab type s_text.
data: it_temp_text(1000)  TYPE c OCCURS 0 with header line.
data : l_file TYPE string value 'C:xmlload.xml'.

CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    filename                      = l_file
    FILETYPE                      = 'ASC'
  tables
    data_tab                      = it_temp_text.

loop at it_temp_text.
    concatenate xml_out it_temp_text into xml_out.
endloop.

    IF NOT xml_out IS INITIAL .
      TRY .
          CALL TRANSFORMATION (`ZTEST1`)
          SOURCE XML xml_out
          RESULT outtab = lt_outtab.
        CATCH cx_xslt_exception INTO xslt_error.
          xslt_message = xslt_error->get_text( ).
          WRITE:/ xslt_message .
      ENDTRY.
    ENDIF .
    break-point.
    write : / 'test'.

==========================================================

I am using above code to convert input XML file into internal table I am getting conversion error. My input XML file looks is as follows. It is throwing this error in call transformation. Appreciate your help in Advance.

<MODIFIED BY MODERATOR - RESPECT THE 2,500 CHAR LIMIT>

Code Formatted by: Alvaro Tejada Galindo on Jan 4, 2010 3:31 PM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,874

hi, how about your XSLT file 'ZTEST1', can you offer the content of it for us?

and you can also do a conversion test in the se80, when open a XSLT in the SE80, you have chance to test it.

You can research if the XSLT file can be used.

If it is ok in that test, then something is wrong when you call transformation.

Hope it will be helpful

thanks

4 REPLIES 4
Read only

Former Member
0 Likes
1,875

hi, how about your XSLT file 'ZTEST1', can you offer the content of it for us?

and you can also do a conversion test in the se80, when open a XSLT in the SE80, you have chance to test it.

You can research if the XSLT file can be used.

If it is ok in that test, then something is wrong when you call transformation.

Hope it will be helpful

thanks

Read only

0 Likes
1,874

Thanks for quick response.

I think the problem is with special characters in the input XML file. If I don't have special characters in XML file then it works fine.

Anyway here is the XSLT code. This is a generic XSLT code which I used from one of the examples

posted on this site.


<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:xa="urn:schemas-microsoft-com:xml-analysis:mddataset" xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<xsl:output method="xml" />
<xsl:variable name="fieldNames" select="//asx:abap/asx:values/FIELDCAT" />
<xsl:template match="/">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<!--FIELDCAT>
<xsl:apply-templates select="//YWAS_METADATA" />
</FIELDCAT-->
<OUTTAB>
<xsl:apply-templates select="//item" />
</OUTTAB>
</asx:values>
</asx:abap>
</xsl:template>
<xsl:template match="//YWAS_METADATA">
<item>
<xsl:for-each select="*">
<!--column ><xsl:apply-templates/></column-->
<xsl:copy>
<xsl:apply-templates select="@*|*|text()"/>
</xsl:copy>
</xsl:for-each>
</item>
</xsl:template>
<xsl:template match="//item">
<item>
<xsl:for-each select="*">
<!--column ><xsl:apply-templates/></column-->
<xsl:copy>
<xsl:apply-templates select="@*|*|text()"/>
</xsl:copy>
</xsl:for-each>
</item>
</xsl:template>
</xsl:stylesheet>

Read only

Former Member
0 Likes
1,874

hi, I have read your XSLT, and do some change on the original version, you can try the following version:


<?xml version="1.0" encoding="utf-16"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="no"/>
    <xsl:template match="/">
        <asx:abap version="1.0" xmlns:asx="http://www.sap.com/abapxml">
            <asx:values>
                <OUTTAB>
                    <xsl:apply-templates select="//item"/>
                </OUTTAB>
            </asx:values>
        </asx:abap>
    </xsl:template>
    <xsl:template match="//item">
        <item>
            <xsl:for-each select="*">
                <!--column ><xsl:apply-templates/></column-->
                <xsl:copy>
                    <xsl:apply-templates select="@*|*|text()"/>
                </xsl:copy>
            </xsl:for-each>
        </item>
    </xsl:template>
</xsl:stylesheet>

I have no server can test XSLT here, but I think your problem maybe on the <b>encoding=</b>, as your special character maybe not support in some encoding.

hope it will be helpful

thanks

Read only

0 Likes
1,874

i have taken same problem when calling abap web service.

CX_SY_CONVERSION_DATA_LOSS:XSLT exception.An error occurred when deserializing in the simple transformation program /1BCDWB/WSSEBA4FA109C974F9F3C7.Data loss occurred when converting Ahmet Çağan - Doğan Demir

what can i do for solve my problem? there is some turkish spesific characters so im facing the encoding problem

thanks all