cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in RFC Lookup

Former Member
0 Kudos

Hi,

I am performing RFC lookup using Communication Channel.

I have used a function called "Z_MATERIAL_DETAILS".

Input to this function is "MATERIALID" and Output of the function is "MATNR".

I am using the following code in my UDF for performing lookup::

//write your code here

final String CHANNEL_NAME = "CC_RFC_LookUp",

VALNOTFOUND = "VALUE_NOT_FOUND",

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

TAG_FM = "Z_MATERIAL_DETAILS",

// TAG_QTB = "QUERY_TABLE",

TAG_QFL = "UOMCODE"; //UOMCODE

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());

result.addValue(e.toString());

}

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_QFL)).appendChild(docReq.createTextNode(resultFieldName[0]));

} catch (Exception e) {

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

result.addValue(e.toString());

}

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

// Lookup

Payload result1 = null;

try {

Channel channel = LookupService.getChannel("EC1CLNT800", "CC_RFC_LookUp");

RfcAccessor accessor = LookupService.getRfcAccessor(channel);

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

XmlPayload payload = LookupService.getXmlPayload(is);

result1 = accessor.call(payload);

} catch (LookupException e) {

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

result.addValue(e.toString());

}

// Parsing RFC Response Document

Document docRsp = null;

try {

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

} catch (Exception e) {

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

result.addValue(e.toString());

}

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

String res = "";

try {

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

} catch (Exception e) {

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

result.addValue(e.toString()+VALNOTFOUND);

}

result.addValue(res);

Code in Z_MATERIAL_DETAILS ::

*"----


""Local Interface:

*" IMPORTING

*" VALUE(UOMCODE) LIKE MARA-MFRPN OPTIONAL

*" EXPORTING

*" VALUE(UOMTEXT) LIKE MARA-MATNR

*" EXCEPTIONS

*" val_not_found

*"----


<b>select single matnr from mara into uomtext where mfrpn = uomcode.</b>

if sy-subrc <> 0.

raise val_not_found.

endif.

ENDFUNCTION.

<b>When i send three material ids the function module will access the R/3 system thrice which will give rise to PERFORMANCE ISSUE.

So,is there any way to send all the materialids at one time to Function module and similarly receive all the MATNR from Function at once,so that we need to access R/3 system only once.</b>

Accepted Solutions (0)

Answers (3)

Answers (3)

STALANKI
Active Contributor
0 Kudos

Nilima,

Try taking the material numbers at a single shot using advacced cache option and have them as tables parameters.

One more option is to better use a value mapping replication.Check value mapping section in the blog /people/sravya.talanki2/blog/2006/12/26/aspirant-to-learn-sap-xiyou-won-the-jackpot-if-you-read-this-part-ii

Former Member
0 Kudos

Hi,

there are two steps here.

1. the code in your RFC to return the details of more then one material.

If you have maintained tables for this then it shoudl work.

Work with your RFC code independently and check if you get the response.

2. Call this in the mapping now.

If you are not getting multiple replies then it's because of the way the call is being made.

if you have done one to one mapping on that particular field then there will be one material going in.

You have to work with cotext change for this to work

Regards

Vijaya

Former Member
0 Kudos

HI,

Check this link for passing table parameter in JCO call.

http://www.sapdevelopment.co.uk/java/jco/jco_callfunc.htm

Following is the code for retrieving table parameter in JCO call to function BAPI_PO_CREATE.

JCO.Table return_tab = function.getTablesParameterList().getTable("RETURN");

if (return_tab.getNumRows()) > 0 {

// Output the error messages

return_tab.firstRow();

do {

System.out.println(return_tab.getString("MESSAGE");

while (return_tab.nextRow());

} else {

String PO_NUM = function.getExportParametersList().getString("PURCHASEORDER");

System.out.println("Purchase order " + PO_NUM + " created");

}

Thanks and Regards,

Sandeep Maurya.

bhavesh_kantilal
Active Contributor
0 Kudos

Hi,

Am not an ABAP expert, but this can surely be achieved.

You can raise a similar query on the ABAP forum with your ABAP code and ask them for inputs, you will surely find answer to this!

Regards

Bhavesh

Former Member
0 Kudos

HI,

If you see the function module there you find options such as import,export,source code,exception and Table.

By using Table option you can achieve your requirement.

Thanks,

Sandeep

bhavesh_kantilal
Active Contributor
0 Kudos

Hi,

You will need to make a few changes,

1. Make a change in the RFC to handle multiple Inputs and return Multiple Outputs.

2. Make your User Defined Function an Adavnced User Defined Function that will take multiple MATERIALID's as inputs using a CACHE or a QUEUE and then construct the corresponding request with this multiple Inputs and get the response back which will again be multiple responses.

Build the logic of the UDF for the same and it should work fine.

Regards,

Bhavesh

Former Member
0 Kudos

Hi Bhavesh,

I have tried a lot for doing this RFC lookup using multiple values.

But I am unable to get the appropriate answer.

in the Function module I am making use of Internal Tables to get the request as well as to send the response.

Please provide some help regarding code that I can use in my User Defined Function.

Waiting for your response.

Thanks & Reguards,

Nililma Rodrigues