on 07-29-2015 12:36 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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
User | Count |
---|---|
89 | |
10 | |
9 | |
9 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.