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

Call transforma​tion - special characters

Former Member
0 Likes
2,737
Hi all,
I'm using XSLT-ABAP transformation to convert a XML string to an internal table, but the special characters are being replaced by the "#" character. I think this is probably an encoding problem, but I don't know what am I missing.
My XSLT transformation looks like this:
  <xsl:template match="/">
    <asx:abap version="1.0">
      <asx:values>
        <DOCUMENTNUMBER>
          <xsl:value-of select="//ns0:CriaCodigoGuiaRemessaOutput/ns0:DocumentNumber"/>
        </DOCUMENTNUMBER>
        <ATDOCCODEID>
          <xsl:value-of select="//ns0:CriaCodigoGuiaRemessaOutput/ns0:ATDocCodeID"/>
        </ATDOCCODEID>
        <OUTTAB>
          <xsl:for-each select="//ns0:CriaCodigoGuiaRemessaOutput">
            <ERROR>
              <ERRORCODE>
                <xsl:value-of select="ns1:Error/ns1:errorCode"/>
              </ERRORCODE>
              <ERRORMESSAGE>
                <xsl:value-of select="ns1:Error/ns1:errorMessage"/>
              </ERRORMESSAGE>
              <EXTERNALERROR>
                <CODE>
                  <xsl:value-of select="ns1:Error/ns1:ExternalError/ns1:code"/>
                </CODE>
                <MESSAGE>
                  <xsl:value-of select="ns1:Error/ns1:ExternalError/ns1:message"/>
                </MESSAGE>
              </EXTERNALERROR>
            </ERROR>
          </xsl:for-each>
        </OUTTAB>
      </asx:values>
The XML string has encoding UTF-8.

Thanks in advance.
Best regards,
Sónia Gonçalves
Hi all,
I'm using XSLT-ABAP transformation to convert a XML string to an internal table, but the special characters are being replaced by the "#" character. I think this is probably an encoding problem, but I don't know what am I missing.
My XSLT transformation looks like this:
  <xsl:template match="/">
    <asx:abap version="1.0">
      <asx:values>
        <DOCUMENTNUMBER>
          <xsl:value-of select="//ns0:CriaCodigoGuiaRemessaOutput/ns0:DocumentNumber"/>
        </DOCUMENTNUMBER>
        <ATDOCCODEID>
          <xsl:value-of select="//ns0:CriaCodigoGuiaRemessaOutput/ns0:ATDocCodeID"/>
        </ATDOCCODEID>
        <OUTTAB>
          <xsl:for-each select="//ns0:CriaCodigoGuiaRemessaOutput">
            <ERROR>
              <ERRORCODE>
                <xsl:value-of select="ns1:Error/ns1:errorCode"/>
              </ERRORCODE>
              <ERRORMESSAGE>
                <xsl:value-of select="ns1:Error/ns1:errorMessage"/>
              </ERRORMESSAGE>
              <EXTERNALERROR>
                <CODE>
                  <xsl:value-of select="ns1:Error/ns1:ExternalError/ns1:code"/>
                </CODE>
                <MESSAGE>
                  <xsl:value-of select="ns1:Error/ns1:ExternalError/ns1:message"/>
                </MESSAGE>
              </EXTERNALERROR>
            </ERROR>
          </xsl:for-each>
        </OUTTAB>
      </asx:values>
The XML string has encoding UTF-8.

Thanks in advance.
Best regards,
Sónia Gonçalves
7 REPLIES 7
Read only

Former Member
0 Likes
1,890

I just tried a special character on my system, and internal table had correct character.

This was seen in debug mode.

If the value is printed using WRITE statement, special character would be replaced by #.

Could you share more data on where hash is being seen?

Read only

0 Likes
1,890

Hi Manish,

Thanks for your reply.

The hash occurs on the transformation result, which means, in the output table.

My code is like this:

  DATA: lv_response  TYPE string.

  TYPES: BEGIN OF ext ,
          code TYPE string,
          message TYPE string,
  END OF ext.

  TYPES: BEGIN OF return,
          errorcode    TYPE string,
          errormessage TYPE string,
          externalerror TYPE ext,
  END OF return .

  DATA: outtab TYPE return OCCURS 0 WITH HEADER LINE .

    TRY.
        CALL TRANSFORMATION (`ZCERTAT_LER_COD_AT_GR`)
        SOURCE XML lv_response
        RESULT outtab         = outtab[].

      CATCH cx_sy_conversion_base64
        cx_sy_conv_illegal_date_time
        cx_xslt_runtime_error
        cx_xslt_format_error.
    ENDTRY .

The data variable lv_response returns a string with special characters. When I convert it with the call transformation to the outtab[] internal table, the special characters in errormessage field are replaced by the # character.

The input looks like this:

<?xml version="1.0"encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header><v0:Header
xmlns:xs=http://www.w3.org/2001/XMLSchema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns="XXXXX " xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:v0="XXXXX" xmlns:v4="XXXXX"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><v0:referenceID>
2013-09-24T13:35:30.64894 </v0:referenceID><v0:timestamp>2013-09-24T13:35:30</v0:timestamp><v0:sourceSystem>SAP </v0:sourceSystem></v0:Header></SOAP-ENV:Header><SOAP-ENV:Body><ns0:CriaCodigoGuiaRemessaOutput xmlns:ns0="XXXXX"><ns0:DocumentNumber>9320015934</ns0:DocumentNumber><ns1:Error
xmlns:jms1=http://www.tibco.com/namespaces/tnt/plugins/jms xmlns:ns0="XXXXX" xmlns:ns1="XXXXX"><ns1:errorCode>EIL#0000</ns1:errorCode><ns1:errorMessage>Sucesso<

/ns1:errorMessage><ns1:errorType>F</ns1:errorType><ns1:ExternalError><ns1:code>-

  100</ns1:code><ns1:message>A data início de transporte é inferior à data atual, pelo que esta informação será considerada uma mera comunicação de dados à AT</ns1:message></ns1:ExternalError></ns1:Error></ns0:CriaCodigoGuiaRemessaOutput></SOAP-ENV:Body></SOAP-ENV:Envelope>

After the call transformation the result is:

outtab[1]-EXTERNALERROR-MESSAGE =

A data in#cio de transporte # inferior # data atual, pelo que esta informa##o se

r# considerada uma mera comunica##o de dados # AT

Thanks.

Best regards,

Sónia Gonçalves

Read only

Former Member
0 Likes
1,890

The samples do not work directly.

There are some spaces missing in xml input and transformation code is incomplete.

Could you post a set of samples that work directly?

It would be easier that way to analyze it.

EDIT: It would be better to edit the previous reply instead of posting new reply.

Read only

0 Likes
1,890

Hi,

I can't put the complete xml input here because of client's rules.

Do you have any hint considering this? Do you think is something in the XSLT transformation?

Thanks.

Best regards,

Sónia Gonçalves

Read only

0 Likes
1,890

You could try creating a fresh example with minimal data and try out different combinations.

I tried a tutorial program and used your name for special character testing.

During GUI_UPLOAD, I specified codepage 4110 which is SAP equivalent for UTF-8.

The XML file content was:

<?xml version="1.0" encoding="UTF-8" ?>

<CUSTOMERS>

  <PERSON>

    <customer_id>1</customer_id>

    <first_name>Jan</first_name>

    <last_name>Krohn</last_name>

  </PERSON>

  <PERSON>

    <customer_id>2</customer_id>

    <first_name>Sónia</first_name>

    <last_name>Gonçalves</last_name>

  </PERSON>

</CUSTOMERS>

XSLT transformation code:

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
   <xsl:strip-space elements="*"/>

   <xsl:template match="/">
     <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
       <asx:values>
         <IPERSON>
           <xsl:apply-templates select="//PERSON"/>
         </IPERSON>
       </asx:values>
     </asx:abap>
   </xsl:template>

   <xsl:template match="PERSON">
     <item>
       <CUST_ID>
         <xsl:value-of select="customer_id"/>
       </CUST_ID>
       <FIRSTNAME>
         <xsl:value-of select="first_name"/>
       </FIRSTNAME>
       <LASTNAME>
         <xsl:value-of select="last_name"/>
       </LASTNAME>
     </item>
   </xsl:template>

</xsl:transform>

ABAP data in list output.

Customer ID: 0001

First name : Jan

Last name  : Krohn

Customer ID: 0002

First name : Sónia

Last name  : Gonçalves

Read only

peter_langner
Active Contributor
0 Likes
1,890

Hi Sonia,

may be this helps you: http://scn.sap.com/thread/2026271.

Regards,

Peter

Read only

0 Likes
1,890

Hi all,

SAP Note 1017101 solved my issue. I used the workaround for problems with character-type variables described in this note, that basically removes the encoding from the XML input, before the transformation call, and it worked.

Thanks a lot for all your effort.

Best regards,

Sónia Gonçalves