cancel
Showing results for 
Search instead for 
Did you mean: 

RFC Lookup Input stream

Former Member
0 Kudos

Hi all,

I'm working on RFC Lookup.

While writing the UDF in graphical editor, I need to create the XML Payload using the Input Stream, for RFC Accessor. Here I want to know, how can I create the XML inputstream representing the function module request message.

Please response asap.

Thanks

Krishna.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Krishna,

Just have a look.

//write your code here

final String CHANNEL_NAME = " File_In_1",

VALNOTFOUND = "VALUE_NOT_FOUND",

SAPRFCNS = "urn:sap-com:document:sap:rfc:functions",

TAG_FM = "Z_FI_RFC_COST_CENTER",

TAG_QFL1 = "I_UNIT_LOC";

TAG_QFL2 = "I_DATE";

TAG_QFL3= "I_SOURC_REF";

//String service;

//String cc = "";

java.util.Map map;

map = container.getTransformationParameters();

service = (String) map.get(StreamTransformationConstants.RECEIVER_SERVICE);

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder = null;

factory.setNamespaceAware(false);

factory.setValidating(false);

try {

builder = factory.newDocumentBuilder();

} catch (Exception e) {

}

Document docReq = null;

try {

// Building up RFC Request Document

docReq = builder.newDocument();

Node root = docReq.appendChild(docReq.createElementNS(SAPRFCNS, TAG_FM));

root.appendChild(docReq.createElement(TAG_QFL1)).appendChild(docReq.createTextNode(I_UNIT_LOC [0]));

root.appendChild(docReq.createElement(TAG_QFL2)).appendChild(docReq.createTextNode(I_DATE [0]));

root.appendChild(docReq.createElement(TAG_QFL3)).appendChild(docReq.createTextNode(I_SOURC_REF [0]));

} catch (Exception e) {

}

// trace.addInfo("RFC Request XML: " + docReq.toString());

// Lookup

Payload result1 = null;

try {

//Channel channel = LookupService.getChannel(service,cc);

Channel channel = LookupService.getChannel("LYNX_SSP_3RD_D_UK ", " File_In_1");

RfcAccessor accessor = LookupService.getRfcAccessor(channel);

InputStream is = new ByteArrayInputStream(docReq.toString().getBytes());

XmlPayload payload = LookupService.getXmlPayload(is);

result1 = accessor.call(payload);

} catch (LookupException e) {

}

// Parsing RFC Response Document

Document docRsp = null;

try {

docRsp = builder.parse(result1.getContent());

} catch (Exception e) {

}

//trace.addInfo("RFC Response XML: " + docRsp.toString());

String res = "";

try {

res = //docRsp.getElementsByTagName("A").item(0).getFirstChild().getNodeValue();

docRsp.getElementsByTagName("O_COST_CENTRE").item(0).getFirstChild().getNodeValue();

} catch (Exception e) {

}

result.addValue(res);

Regards,

Sarvesh

***Reward points, if found helpful.

former_member189387
Active Contributor
0 Kudos

Hi ,

I am giving you the Complete sample code for RFC Look up . Hope it will be helpful

package com.sic.nw.xi.mapping.valudf;

import java.io.ByteArrayInputStream;

import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;

import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.*;

import com.sap.aii.mapping.api.AbstractTrace;

import com.sap.aii.mapping.lookup.*;

public class LookupHandler3 {

public static String RFCLookup(

String BALREF,

// sample input strings [ xml node ]

// String NAME_DRVR,

String SERVICETXAMT,

String SERVICETXPER,

// to know the trace information

AbstractTrace trace,

String service) {

// theValue=LookupHandler.RFCLookup(Table[0],KeyNames,KeyValues,ResultFieldName[0],container.getTrace(),"Myr3system");

// theValue=LookupHandler.RFCLookup(delchno[0],container.getTrace(),"SAPR3System");

final String CHANNEL_NAME = "CC_RFC_LUKUP3",

VALNOTFOUND = "VALUE_NOT_FOUND",

SAPRFCNS = "urn:sap-com:document:sap:rfc:functions",

TAG_FM = "ZVALIDATE",

TAG_IP = "BALREF",

// here assign the values

// TAG_QFL = "QUERY_FIELD",

TAG_RES = "RESULTDESC";

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder = null;

factory.setNamespaceAware(false);

factory.setValidating(false);

try {

builder = factory.newDocumentBuilder();

} catch (Exception e) {

trace.addWarning(

"Error creating DocumentBuilder - " + e.getMessage());

return null;

}

Document docReq = null;

try {

// Building up RFC Request Document

docReq = builder.newDocument();

Node root =

docReq.appendChild(docReq.createElementNS(SAPRFCNS, TAG_FM));

root.appendChild(docReq.createElement(TAG_IP)).appendChild(

docReq.createTextNode(BALREF));

} catch (Exception e) {

trace.addWarning("Error while building RFC Request - " + e);

return null;

}

trace.addInfo("RFC Request XML: " + docReq.toString());

// Lookup

Payload result = null;

try {

Channel channel = LookupService.getChannel(service, CHANNEL_NAME);

RfcAccessor accessor = LookupService.getRfcAccessor(channel);

InputStream is =

new ByteArrayInputStream(docReq.toString().getBytes());

XmlPayload payload = LookupService.getXmlPayload(is);

result = accessor.call(payload);

} catch (LookupException e) {

trace.addWarning("Error during lookup - " + e);

return null;

}

// Parsing RFC Response Document

Document docRsp = null;

try {

docRsp = builder.parse(result.getContent());

} catch (Exception e) {

trace.addWarning(

"Error when parsing RFC Response - " + e.getMessage());

return null;

}

trace.addInfo("RFC Response XML: " + docRsp.toString());

String res = "";

try {

res =

docRsp

.getElementsByTagName(TAG_RES)

.item(0)

.getFirstChild()

.getNodeValue();

} catch (Exception e) {

trace.addWarning("Result value not found in DOM - " + e);

return VALNOTFOUND;

}

return res;

}

}

        • Assign Points if you found helpful

Regards.,

V.Rangarajan