cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with RFC Lookup udf in XI 7.0

Former Member
0 Kudos

Hello everyone,

I am using the below udf for RFC lookup in my mapping. the message is processed successfully but the problem is i am not getting the exact response what i need. Can anyone please suggest what would be the reason. Instead i am getting some xml data in output field.

   //write your code here

String content = "";

MappingTrace importanttrace;

importanttrace = container.getTrace();

String m = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns0: function Module xmlns:ns0=\"urn:sap-com:document:sap:rfc:functions\">";

m = m + "<ZZ_XI_Sysid>" + Sysid + "</ZZ_XI_Sysid>";

m = m + "<ZZ_Product_ID>" + PROD_ID + "</ZZ_Product_ID>";

m = m + "</ns0:Function module>";

RfcAccessor accessor = null;

ByteArrayOutputStream out = null;

try

{

Channel channel = LookupService.getChannel("Busines system","Receiver channel");

accessor = LookupService.getRfcAccessor(channel);

InputStream inputStream = new ByteArrayInputStream(m.getBytes());

XmlPayload payload = LookupService.getXmlPayload(inputStream);

Payload result = accessor.call(payload);

InputStream in = result.getContent();

out = new ByteArrayOutputStream(1024);

byte[] buffer = new byte[1024];

for (int read = in.read(buffer); read > 0; read = in.read(buffer)) {

out.write(buffer, 0, read);

}

content = out.toString();

}

catch(LookupException e)

{

importanttrace.addWarning("Error while writing " + e.getMessage() );

}

catch(IOException e)

{

importanttrace.addWarning("Error " + e.getMessage() );

}

finally

{

if (out!=null) {

try {

out.close();

} catch (IOException e) {

importanttrace.addWarning("Error while closing stream " + e.getMessage() );

}

}

if (accessor!=null) {

try {

accessor.close();

} catch (LookupException e) {

importanttrace.addWarning("Error while closing accessor " + e.getMessage() );

}

}

}

//returning the result u2013 RFC-XML.response

return content;

Thanks & Regards

Swetha

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

HI all,

By using the above udf i am getting empty response and also i no need to hard code the Receiver Business system in the above code. can anyone please suggest.

Thanks,

Swetha

Former Member
0 Kudos

as you don't want to hardcode in mapping, try to use parameterised mapping in ID

also in the trace check what is the value you are getting for Sender

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Arvind,

Parameterized mappings are not available until 7.1

Regards,

Mark

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Swetha,


the message is processed successfully but the problem is i am not getting the exact response what i need. Can anyone please suggest what would be the reason. Instead i am getting some xml data in output field.

In your code you parsed the whole response that is why the output is in xml. If you are looking for a specific field in the response, you need to add logic after this code


content = out.toString();

Regards,

Mark

Former Member
0 Kudos

Hi Mark,

I have added the code but now i am getting empty as response.

And also i no need to Hard code the Receiver system in the code.

can u please suggest how can i do this

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Swetha,

Can you paste the rfc lookup response here and the field that you need to get?


And also i no need to Hard code the Receiver system in the code.

can u please suggest how can i do this

If the system where you are performing the rfc lookup is your actual receiver, all you have to do is to use the receiver function under constants in message mapping.

Regards,

Mark

Former Member
0 Kudos

Hi Mark,

below is the code i am using.

   //write your code here

String content = "";

String resVal = "";

String ReceiverSystem = "";

MappingTrace importanttrace;

importanttrace = container.getTrace();

String m = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns0:Z_R_GET_PRODUCT_DETAILS xmlns:ns0=\"urn:sap-com:document:sap:rfc:functions\">";

m = m + "<I_ZZ_XI_SYSID>" + Sysid + "</I_ZZ_XI_SYSID>";

m = m + "<I_ZZ_PRODUCT_ID>" + PROD_ID + "</I_ZZ_PRODUCT_ID>";

m = m + "</ns0:Z_R_GET_PRODUCT_DETAILS>";

RfcAccessor accessor = null;

ByteArrayOutputStream out = null;

try

{

Channel channel = LookupService.getChannel( "KD2200","CC_RFC_CAR_RECEIVER");

accessor = LookupService.getRfcAccessor(channel);

InputStream inputStream = new ByteArrayInputStream(m.getBytes());

XmlPayload payload = LookupService.getXmlPayload(inputStream);

Payload result = accessor.call(payload);

InputStream in = result.getContent();

out = new ByteArrayOutputStream(1024);

byte[] buffer = new byte[1024];

for (int read = in.read(buffer); read > 0; read = in.read(buffer)) {

out.write(buffer, 0, read);

}

content = out.toString();

int Start_Index , End_Index;

Start_Index = out.toString().indexOf("<O_ZZ_DESCRIPTION>") + 18  ;  ///Find in output string the tag that I want to extract (ex. <ZZ_Description>) adding at length value 2 that represent the tags <>

End_Index = Start_Index + (out.toString().indexOf("</O_ZZ_DESCRIPTION>")  - (out.toString().indexOf("<O_ZZ_DESCRIPTION>") + 18  ) );  ///the end of the field is found searching the end tag of the field

resVal = out.toString().substring(Start_Index , End_Index);

}

catch(LookupException e)

{

importanttrace.addWarning("Error while writing " + e.getMessage() );

}

catch(IOException e)

{

importanttrace.addWarning("Error " + e.getMessage() );

}

finally

{

if (out!=null) {

try {

out.close();

} catch (IOException e) {

importanttrace.addWarning("Error while closing stream " + e.getMessage() );

}

}

if (accessor!=null) {

try {

accessor.close();

} catch (LookupException e) {

importanttrace.addWarning("Error while closing accessor " + e.getMessage() );

}

}

}

//returning the result u2013 RFC-XML.response

return resVal;

now i am getting output as empty.

Below is the mapping logic which i am using

Former Member
0 Kudos

My actual receiver is different from this RFC receiver channel.

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Swetha,

Try adding traces for these lines:

1. content = out.toString();

2. after start index logic

3. after end index logic

4. resVal = out.toString().substring(Start_Index , End_Index);

run the lookup again and then get back to us.

You can maintain value mapping entries for the RFC receiver.

Regards,

Mark

Former Member
0 Kudos

Hi Mark,

I am getting the response now, when i am using constant(with Sysid) instead of sender in mapping logic. But i no need to hard code the sysid and also Receiver sys name in udf.

can u please suggest.

Thanks in Advance

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Swetha,

You can use value mapping for your requirement

Regards,

Mark