2016 Nov 02 2:58 PM
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?
2016 Nov 02 4:20 PM
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"
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?
2016 Nov 02 4:20 PM
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"
2016 Nov 03 9:00 AM
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.
2016 Nov 03 5:17 PM
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>
2016 Nov 07 1:22 PM
That does the trick. Thank you very much. That bothered me a lot longer than it should have.
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |