Skip to Content
0

Error on XML Deserialization with DATS Datatype

Nov 02, 2016 at 02:58 PM

75

avatar image

Hello,

I'm using an XSLT Program to deserialize a XML-File. Inside the XSL I'm assigning the needed values to the fields of my structure. I have one field with the datatype DATS (length 8). Inside the XML File there is a tag which contains a date in the according format

YYYMMDD ( e.g. <DATE>20160522</DATE>).

Whenever I try to assign the value of Date to the structure field with the DATS type I am getting the CX_XSLT_DESERIALIZATION_ERROR.

For troubleshooting I changed the type of the field to a char32 which is working just fine.

How can I cast the value correctly to the dats field?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Sandra Rossi Nov 02, 2016 at 04:20 PM
1

Here are the accepted formats for "asXML" : http://help.sap.com/abapdocu_702/en/?url=abenabap_xslt_asxml_schema.htm

.

Excerpt:

XML Scheme Type XML Representation Domain ABAP Representation

xsd:date 2007-10-01 XSDDATE_D "20071001"

Show 3 Share
10 |10000 characters needed characters left characters exceeded

Thank you for your quick answer. I already saw the page for asXML types but that doesn't seem to help me much. Here is an example of how my code looks:

Input XML:

<?xml version="1.0" encoding="UTF-8"?><INVOIC02>
<IDOC BEGIN="1">
...
<E1EDK03 SEGMENT="1">
<IDDAT>012</IDDAT>
<DATUM>20160510</DATUM>
</E1EDK03>
...
</IDOC>
</INVOIC02>

So besides other values, I need to get the value of the <DATUM> tag into a variable of the ABAP type DATS. Here's my XSL-Transformation for that:

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl" version="1.0">
<xsl:strip-space elements="*"/>
<xsl:template match="/"> <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0"> <asx:values> <IDOC_GET> <xsl:apply-templates select="//IDOC"/> </IDOC_GET> </asx:values> </asx:abap> </xsl:template> <xsl:template match="IDOC"> <xsl:for-each select="E1EDK03"> <xsl:if test="IDDAT = 012"> <xsd:element name="DATUM" type="xsd:date"> <DOCDT> <xsl:value-of select="DATUM"/> </DOCDT> </xsd:element> </xsl:if> </xsl:for-each>
... </xsl:template> </xsl:transform>

As already mentioned, I am able to retrieve the date, when the corresponding ABAP-datatype for DOCDT is a character of according lenght. But since the type I need in this case is DATS the selection throws the error.

0

asxml requires format YYYY-MM-DD.

So, you must use something like:

<xsl:template match="IDOC">
<xsl:for-each select="E1EDK03">
<xsl:if test="string(IDDAT) = '012'">
<DOCDT><xsl:value-of select="concat(substring(DATUM,1,4), '-', substring(DATUM,5,2), '-', substring(DATUM,7,2))"/></DOCDT>
1

That does the trick. Thank you very much. That bothered me a lot longer than it should have.

0