cancel
Showing results for 
Search instead for 
Did you mean: 

RFC Call in Message Mapping

Former Member
0 Kudos

Hi there

I am trying to do a table lookup from XI in my message mapping by calling an remote RFC. The return values must return ALL the value for a specific column. The code I have here returns a blank value. Can someone see what my problem may be?

My variables for my UDF is:

public String UDF_RFC(String DBTABLE,String MATNR,String FIELDS,String businessSystem,String communicationChannel,Container container)

And my Code:

"My code appears to mess up my message structure, I will attach it in a responce..

Thanks,

Jan

Edited by: Jan de Lange on Sep 16, 2009 11:09 AM

Edited by: Jan de Lange on Sep 16, 2009 11:09 AM

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

first test you RFC function module .if it works fine then it will be better if you test your code for parsing the xml that is returned by RFC lookup in NWDS (with the expected xml

returned by RFC lookup)and then use it in message mapping

does ## use to add context change?

Former Member
0 Kudos

One of teh resons can be

if you create a UDF selecting VALUE then you can return only on string.

You have to use context while creating the UDF

Former Member
0 Kudos

At first it was only designed to return 1 value so I had to change it, now I append the values to a string:

returnValue += attrname + " = " + attrval + "##";

This string however is blank..

If I can get this to work I will change it to a context.

Former Member
0 Kudos
// declare parameters
String returnValue = "";
String rfcXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns0:ZINT_XI_GET_SITES xmlns:ns0=\"urn:sap-com:document:sap:rfc:functions\"><LT_SITES><item><WERKS></WERKS></item></LT_SITES></ns0:ZINT_XI_GET_SITES>";
AbstractTrace trace = container.getTrace();
RfcAccessor accessor = null;
ByteArrayOutputStream out = null;
try
{
// 1. Determine a communication channel (Business system + Communication channel)
Channel channel = LookupService.getChannel(businessSystem,communicationChannel);
// 2. Get a RFC accessor for the channel.
accessor = LookupService.getRfcAccessor(channel);
// 3. Create an XML input stream that represents the RFC request message.
InputStream inputStream = new ByteArrayInputStream(rfcXML.getBytes());
// 4. Create the XML Payload
XmlPayload payload = LookupService.getXmlPayload(inputStream);
// 5. Execute the lookup.
Payload result = null;
result = accessor.call(payload);
InputStream in = result.getContent();
// 6. Create a DOM structure from the input XML
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(in);


NodeList      nodelist = document.getElementsByTagName("*");
Node          node;
Element       element;
NamedNodeMap  nnm = null;

String attrname;
String attrval;
int    i, len;


len = nodelist.getLength();

for (int j=0; j < len; j++) {
            element = (Element)nodelist.item(j);
            System.out.println(element.getTagName() + ":");
            nnm = element.getAttributes();
        }

        if (nnm != null) {
            for (i=0; i<nnm.getLength(); i++) {
                node = nnm.item(i);
                attrname = node.getNodeName();
                attrval  = node.getNodeValue();
                returnValue += attrname + " = " + attrval + "##";
            }
        }



// 7. To free resources, close the accessor..
if (accessor!=null) {
try {
accessor.close();
} catch (LookupException e) {
trace.addWarning("Error while closing accessor " + e.getMessage() );
}
}
} catch (Exception e) {
trace.addWarning("Error" + e);
}
// 8. return a single id value to the message mapping
return returnValue;