cancel
Showing results for 
Search instead for 
Did you mean: 

Code Sample: Easy RFC Lookup From XSLT Mappings Using a Java Helper Class

0 Kudos

Hi everyone,

This is just a shameless plug for my article: <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/05a3d62e-0a01-0010-14bc-adc8efd4ee14">Easy RFC Lookup From XSLT Mappings Using a Java Helper Class</a>. I hope you're interested in reading it, and I welcome your comments in this thread.

Kind regards,

Thorsten

Accepted Solutions (0)

Answers (6)

Answers (6)

Former Member
0 Kudos

I have the same behavior. After Calling the Lookup (Lookup is working fine). The Input Param seems to be empty and I am not able to access the single values. If I turn off the Lookup all values are transfered.

former_member190389
Active Contributor
0 Kudos

Hi ,

Here's mine which is pure java mapping.

http://knowhowsapxi.synthasite.com/rfc-loolup.php

Former Member
0 Kudos

Hi Thorsten!

Very informative blog. I am working in PI 7.1 and try to make it work. However, I am experiencing problems. When I call the function as follows:

<xsl:template name="lookupAccount">

<xsl:param name="accountNo"/>

<xsl:variable name="request">

<rfc:ZATJ_ACCOUNT_LOOKUP>

<ACCOUNT_IN><xsl:value-of select="$accountNo"/></ACCOUNT_IN>

</rfc:ZATJ_ACCOUNT_LOOKUP>

</xsl:variable>

<xsl:variable name="response"

xmlns:lookup="java:com.logica.xi.mapping.lookup.RfcLookup"

select="lookup:execute($request, $ReceiverService, 'CC_rfc_rcv_lookup', $inputparam)"/>

<xsl:choose>

<xsl:when test="$response//ACCOUNT_OUT != ''">

<xsl:value-of select="$response//ACCOUNT_OUT"/>

</xsl:when>

</xsl:choose>

</xsl:template>

I get errors when testing it from the Operation Mapping. It's a Java error saying that it can't find the communication channel. Are you able to test this from the Operation Mapping, I mean will the constant $ReceiverService have a value.

Do you have any idea if things have changed in PI 7.1 that will effect your blog?

Any input would be greatly appreciated.

/Patrik

stefan_grube
Active Contributor
0 Kudos

In PI 7.1 you have to check "use sapxmltoolkit" in the operation mapping.

Regards

Stefan

Former Member
0 Kudos

Hi Stefan. Thanks for your post. I have already done that. It still does not work. As a base for my java helper class I have usesd Thorstens code.

The problem is quite confusing. I will try to ouline both issues here.

First of all, when try to test from within the Operation Mapping, I always get a java error saying it cannot find the communication channel (it is there and working because I have tested it with the RFCLookup in graphical mapping). I have found a way to work around this, and that is to uncheck the "Use SAP XMLToolkit" checkbox --> switch to test tab, enter my ReceiverService in the parameter tab (header parameter) --> switch back to Definition tab, check the "Use SAP XMLToolkit" checkbox --> switch to Test tab and run the test. Then the XSLT and call to java helper class will work. Of course this is not really something you want to do all the time. Maybe there is a bug.

Secondly, it never works when I try to do it "live". I am using a file adapter to pick up one file, convert it and a file adapter to drop the converted file. I get the following error code in SXMB_MONI.

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

<!-- Request Message Mapping -->

<SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="">

<SAP:Category>Application</SAP:Category>

<SAP:Code area="MAPPING">TRANSFORMER_CONF_EX</SAP:Code>

<SAP:P1>ATJ_Accounting2XML_Accounting.xsl</SAP:P1>

<SAP:P2>http://rd.accounting.logica.com</SAP:P2>

<SAP:P3>fd552c30-bad9-11dd-9761-c21dac1b818c</SAP:P3>

<SAP:P4>-1</SAP:P4>

<SAP:AdditionalText />

<SAP:Stack>TransformerConfigurationException triggered while loading XSLT mapping ATJ_Accounting2XML_Accounting.xsl; http://rd.accounting.logica.comfd552c30-bad9-11dd-9761-c21dac1b818c-1</SAP:Stack>;

<SAP:Retry>M</SAP:Retry>

</SAP:Error>

Using an XSLT without a call to a java helper class, works just fine.

I am totally at a loss here. Any more input would be much appreciated.

/Patrik

Former Member
0 Kudos

Hello,

I'm using the helper class and it works nice except...

I experience strange problem when executing the lookup in XSLT:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:rfc="urn:sap-com:document:sap:rfc:functions" xmlns:a="http://sap.com/xi/XI/Mail/30" xmlns:b="http://xxxxx.com/srm/" xmlns:java="com.xxxxx.sap.pi.MappingFunctions">
	<xsl:param name="SenderService" />
	<xsl:param name="inputparam" />
	<xsl:template match="/">
	<xsl:variable name="varRequest">
	<!--Build the request for RFC call-->
  	  <rfc:BAPI_EMPLOYEE_GETDATA>
	       <EMPLOYEE_ID><xsl:value-of select="b:Root/Pernr"/></EMPLOYEE_ID>
	  </rfc:BAPI_EMPLOYEE_GETDATA>
                     </xsl:variable>
		<!--Execute the RFC call-->
		<xsl:variable name="varResponse" select="java:lookup($varRequest, $SenderService, 'RFC_ADAPTER_Rcv', $inputparam)"/>
    <xsl:variable name="employee" select="string($varResponse/ORG_ASSIGNMENT/item/NAME)"/>
<a:Mail>
.....
<!-- accessing source-document not possible anymore from here -->
<field><xsl:value-of select="b:Root/Pernr"/></field>
</a:Mail>
</xsl:template>
</xsl:stylesheet>

After executing the java call (succesfully) i'am not able to acces the source document anymore. This seems to me a bug in the SAP XSLT processor.

We're using PI 7.1 SP8

Anybody a clue??

Thanks Emile.

Edited by: Emile Hermans on Jan 5, 2010 12:09 PM

Former Member
0 Kudos

Hello,

As a workaround i now use the following:

I store the complete document in a variable and access a single field of the variable 1 time.

After doing this the source document is accessible again....

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:rfc="urn:sap-com:document:sap:rfc:functions" xmlns:a="http://sap.com/xi/XI/Mail/30" xmlns:b="http://xxxxx.com/srm/" xmlns:java="com.xxxxx.sap.pi.MappingFunctions">
	<xsl:param name="SenderService" />
	<xsl:param name="inputparam" />
	<xsl:template match="/">
	<xsl:variable name="varRequest">
	<xsl:variable name="varDocument" select="//*"/>
	<!--Build the request for RFC call-->
  	  <rfc:BAPI_EMPLOYEE_GETDATA>
	       <EMPLOYEE_ID><xsl:value-of select="b:Root/Pernr"/></EMPLOYEE_ID>
	  </rfc:BAPI_EMPLOYEE_GETDATA>
                     </xsl:variable>
		<!--Execute the RFC call-->
		<xsl:variable name="varResponse" select="java:lookup($varRequest, $SenderService, 'RFC_ADAPTER_Rcv', $inputparam)"/>
    <xsl:variable name="employee" select="string($varResponse/ORG_ASSIGNMENT/item/NAME)"/>
<a:Mail>
.....
<!-- Access the variable containing the sourcedocument -->
		<xsl:comment>
		<xsl:value-of select="$document/b:Root/Pernr"/>
		</xsl:comment>

<!-- accessing source-document now possible again -->
<field><xsl:value-of select="b:Root/Pernr"/></field>
</a:Mail>
</xsl:template>
</xsl:stylesheet>

If some-one can explain this behaviour...

Thanks,

Emile

Edited by: Emile Hermans on Jan 6, 2010 3:07 PM

Former Member
0 Kudos

Hi Thorsten, i read and implemented your guide. I must say you've done a great work.

Although your example worked good for me, i needed to make some changes due to the structure of my target message.

In my scenario, the lookup has to be done more than once and that's when i get an AttayIndexOutOfBoundsException.

Do you have any clue about what's wrong?

<b>Here's a part of the stack trace</b>

avax.xml.transform.TransformerException: java.lang.ArrayIndexOutOfBoundsException: 360 
at com.sap.engine.lib.jaxp.TransformerImpl.transform(TransformerImpl.java:245) 
at com.sap.aii.ibrep.server.mapping.ibrun.RepMappingTransformer.transform(RepMappingTransformer.java:150) 
at com.sap.aii.ibrep.server.mapping.ibrun.RepXSLTMapping.execute(RepXSLTMapping.java:81) 
at com.sap.aii.ibrep.server.mapping.ibrun.RepMappingHandler.run(RepMappingHandler.java:80) 
at com.sap.aii.ibrep.server.mapping.rt.MappingHandlerAdapter.run(MappingHandlerAdapter.java:107) 
at com.sap.aii.ibrep.server.mapping.ServerMapService.transformInterfaceMapping(ServerMapService.java:127) 
at com.sap.aii.ibrep.server.mapping.ServerMapService.transform(ServerMapService.java:104) 
at com.sap.aii.ibrep.sbeans.mapping.MapServiceBean.transform(MapServiceBean.java:40) 
at com.sap.aii.ibrep.sbeans.mapping.MapServiceRemoteObjectImpl0.transform(MapServiceRemoteObjectImpl0.java:167)

Former Member
0 Kudos

hi Thorsten,

I was trying the sample code & I got error on inputParam variable in XSLT given. I guess the variable needs to be initialized. Let me know if I am using the sample code correctly.

sachin.

0 Kudos

Hi Sachin,

Please provide exact details of the error you are getting.

Regards,

Thorsten

Former Member
0 Kudos

hi Thorsten,

the pdf mentions xslt with following parameter,

<xsl:param name="inputParam"/>

I guess this parameter would carry MappingTrace instance inside java.util.Map object, which I see missing. correct me if I am wrong.

I get following error 'xslt parameter not initialized' when using test tool of integration directory.

regards,

sachin.

0 Kudos

Hi Sachin,

I'm not sure, but I think the parameter name is case sensitive. Try changing your code to:

<xsl:param name="inputparam">

(lowercase p)

Regards,

Thorsten

Former Member
0 Kudos

Great!

it worked. You are right the parameter is case sensitive!

sachin.

PS: How do I reward you some points?

Message was edited by: sachin kotalwar

former_member184154
Active Contributor
0 Kudos

Nice job at glance.

Have you seen my stuff <a href="/people/alessandro.guarneri/blog/2006/03/27/sap-xi-lookup-api-the-killer?

If you can figure out a suitable and reasonable way, you might want to write a short blog to integrate the two things... That could be interesting.

Take care,

Alex

0 Kudos

Thanks Alex. Yes, I did read your nice blog as well. My colleague Morten Wittrock has also recently done a <a href="/people/morten.wittrock/blog/2006/03/30/wrapping-your-mapping-lookup-api-code-in-easy-to-use-java-classes">piece on the Lookup API</a>. All in all I think we've covered quite a lot of ground, so perhaps a short blog to tie it all together would be worthwhile.

Cheers,

Thorsten

former_member184154
Active Contributor
0 Kudos

Definitely.

Often lot o' stuff is wirtten unintelligently twice

Contact me by email if u feel we could write some 4 or 6 hands killer-article on the subject...

Alex