Skip to Content
0

PO 7.5: XSL map with Java functions

Oct 20, 2017 at 12:17 PM

91

avatar image

Dear experts,

We are moving to SAP PO 7.5 and have XSL maps that call java functions.

I looked at the following guidelines/threads:
https://help.sap.com/viewer/0b9668e854374d8fa3fc8ec327ff3693/7.5.8/de-DE/4bf40f2cc0c33de4e10000000a42189e.html
https://archive.sap.com/discussions/thread/3424360

I modified one of our XSL maps in the following way.
I added the namespace for xsltc from apache and also added the cast for the Tracer Class:

<xsl:stylesheet
xmlns:xsltc="http://xml.apache.org/xalan/xsltc"
...
>
...
<xsl:variable name="traceLog">
   <xsl:value-of select="concat('TU details of product',$Matnr,' are incomplete')"/>
</xsl:variable>
<!-- TRACE BEGIN -->
<xsl:variable name="__function" select="trace:warning(xsltc:cast('com.edi.eai.xslthelper.log.XSLTracer',$traceLog))"/>
<!-- TRACE END -->
<xsl:message terminate="yes">
   <xsl:value-of select="xsltc:cast('com.edi.eai.xslthelper.log.XSLTracer',$traceLog)"/>
</xsl:message>
...
</stylesheet>


The Java code itself looks like this:

package com.edi.eai.xslthelper.log;

import com.sap.aii.mapping.api.MappingTrace;
import java.util.Map;

public class XSLTracer
{
  private static final String MAPPING_TRACE = "MappingTrace";
  private static MappingTrace trace;
  
  public static void initTrace(Map inputparam)
  {
  trace = (MappingTrace)inputparam.get("MappingTrace");
  }
  
  public static void warning(String logString)
  {
  try
  {
  trace.addWarning(logString);
  }
  catch (Exception localException) {}
  }
}


However, when I run the scenario which is an outbound MATMAS IDoc it fails because details of the material are not maintained but I do not get the expected message "TU details of product 665445 are incomplete" in the message log.

Instead I get:
Cannot convert data-type 'result-tree' to 'com.edi.eai.xslthelper.log.XSLTracer'

Please help me to find out what I am doing wrong.
Did I miss something in the XSL map?

Thank you, Peter

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

1 Answer

Best Answer
avatar image
Former Member Oct 21, 2017 at 07:13 AM
0

I was reading the documentation.you need to cast when passing the objects to the method. In your class it is just string.

Here you are trying to convert string to type XSLtracer.can you check removing cast and pass only trace log.

<xsl:variable name="__function" select="trace:warning($traceLog)"/>
Show 4 Share
10 |10000 characters needed characters left characters exceeded

Hello,

Thank you.
I changed it to

<xsl:variable name="traceLog">
 <xsl:value-of select="concat('TU details of product',$Matnr,' are incomplete')"/>
</xsl:variable>
<!-- TRACE BEGIN -->
 <xsl:variable name="__function" select="trace:warning($traceLog)"/>
<!-- TRACE END -->
<xsl:message terminate="yes">
 <xsl:value-of select="xsltc:cast('com.edi.eai.xslthelper.log.XSLTracer',$traceLog)"/>
</xsl:message>

but now I am receiving the following error:
Cannot convert data-type 'result-tree' to 'com.edi.eai.xslthelper.log.XSLTracer'

Any other ideas?

Thank you, Peter

0
Former Member
<xsl:message terminate="yes">
 <xsl:value-of select="$traceLog"/>
</xsl:message>

I believe you have to change this too.

1

Hello,

It works well now - thank you. These 2 lines at
https://help.sap.com/viewer/0b9668e854374d8fa3fc8ec327ff3693/7.5.8/en-US/4bf40f2cc0c33de4e10000000a42189e.html
make the difference:

  • Access to complex objects used as parameters
  • Objects on which methods are called

Best regards, Peter

1
Former Member

super !!!

0