on 03-16-2009 10:44 AM
Hi there I have this UDF that calls a RFC, currently you can specify which table you want to read from and some input parameters. Could someone help me modify this so that I can specify which RFC to call? It only has to have 1 input parameter so not to worry about that. I am trying to change it to another RFC but it does not work. Heres the original UDF calling a static RFC with any table:
// declare parameters
String returnValue = "";
String rfcXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <ns0:RFC_READ_TABLE xmlns:ns0=\"urn:sap-com:document:sap:rfcfunctions\"><QUERY_TABLE>ZMAPPING_TABLE</QUERY_TABLE><DATA></DATA><FIELDS></FIELDS><OPTIONS><item><TEXT>EAN_UPC = '"EAN_UPC"'</TEXT></item></OPTIONS></ns0:RFC_READ_TABLE>";
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 list = document.getElementsByTagName("WA"); // The lookupValue is available as WA tag in the response
Node node = list.item(0);
if (node != null) {
node = node.getFirstChild();
if (node != null) {
returnValue = node.getNodeValue();
}
}
// 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;
And here is the one I have dynamically calling a RFC:
// declare parameters
String returnValue = "";
String rfcXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <ns0:" + RFC_NAME + " xmlns:ns0=\"urn:sap-com:document:sap:rfcfunctions\"><INPUT_PAR>Input_Value</INPUT_PAR></ns0:" + RFC_NAME + ">";
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 list = document.getElementsByTagName("WA"); // The lookupValue is available as WA tag in the response
Node node = list.item(0);
if (node != null) {
node = node.getFirstChild();
if (node != null) {
returnValue = node.getNodeValue();
}
}
// 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;
Thanks,
Jan
Hi, Thanks for all the help. I fixed the issue. It was thant WA, I just needed to specify the correct return parameter.
Thanks,
Jan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear Jan,
Wonder why do you want the UDF to call any RFC as you must be knowing beforehand only which RFC needs to be called.
Anyways if you want you can also pass RFC name in the source message or in the graphical mapping part before UDF and then use a variable inside UDF that will utilise that RFC name .
I hope this serves your purpose
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thats what I'm trying but it just don't return any results. For the 2nd RFC I use the exact same code, all I'm changing is the XML structure passing the input parameters. For the 1st RFC I have:
String rfcXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <ns0:RFC_READ_TABLE xmlns:ns0=\"urn:sap-com:document:sap:rfcfunctions\"><QUERY_TABLE>ZMAPPING_TABLE</QUERY_TABLE><DATA></DATA><FIELDS></FIELDS><OPTIONS><item><TEXT>EAN_UPC = '"EAN_UPC"'</TEXT></item></OPTIONS></ns0:RFC_READ_TABLE>";
The rfc is RFC_READ_TABLE and it has got these parameters QUERY_TABLE, DATA, FIELDS, OPTIONS & TEXT.. So My 2nd RFC I have
String rfcXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <ns0:SAP_TO_ISO_MEASURE_UNIT_CODE xmlns:ns0=\"urn:sap-com:document:sap:rfcfunctions\"><SAP_CODE>PAL</SAP_CODE></ns0:SAP_TO_ISO_MEASURE_UNIT_CODE>";
This RFC is, SAP_TO_ISO_MEASURE_UNIT_CODE and only has 1 input parameter SAP_CODE. obviously I'll change the "PAL" to be dynamic but the results are initial..
Hi,
Obviously the second dynamic code doesnt work, since you have to provide the dynamic request as expected by the dynamic RFC and you to parse Repsonse structure dynamically.
NodeList list = document.getElementsByTagName("WA"); // The lookupValue is available as WA tag in the response
The tag WA will/might not exist for other BAPI's............
Thanks,
- Gujjeti.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well I have 3 RFC's I need to call in my scenario and of the 3 only 1 of them works so far. So If I can specify the frc and the fields required by the rfc it would make things allot easier. Like for the 2nd example I gave, I have the rfc which only needs 1 input parameter, I made the changes in the input XML but apparently the 2nd part of the code is not working.
1)You can check the Second RFC Response Structure using SE37.
Check export structure using Display code.
2)Second way.......
Change the code here
if (node != null) {
returnValue = node.getNodeValue();
}
if (node != null) {
returnValue = node.getNodeValue();
}else
{
returnValue = "No WA tag in response";
}
Now execute the mapping using Test Tab. Now you should see "No WA tag in response" in the target structure for the mapped field.
Edited by: Praveen Gujjeti on Mar 16, 2009 5:26 PM
User | Count |
---|---|
101 | |
13 | |
13 | |
11 | |
11 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.