cancel
Showing results for 
Search instead for 
Did you mean: 

RFC Lookup code for Multiple export parameters

Former Member
0 Kudos

Hi all,

I have a requirement to call an RFC in my mapping which returns multiple export parameters. Each of the returned export parameters have to be mapped to different targets. Could anyone provide the UDF code for this scenario where in a single call i need multiple parameters to be returned and to be mapped to the respective targets.

regards,

Sherin Jose P

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi Jose,

If you use pi 7.1 then you can send the input to rfc as an internal table and you can get back as internal table where you may have multiple entires. Based upon taht you can do in mappng and in 7.1 you can map this result to multiple fields or segments also.

Regards,

---Satish

Former Member
0 Kudos

Sherin,

Each of the returned export parameters have to be mapped to different targets

What do you mean by different targets? Are you required to use these export values in different mappings or in the same mapping, you have different structures?

If they are to be used in different mappings, are these mappings in the same scenario?

You can use Signature option to retrieve this export value in the integration process and use it in the transformation. But all the mappings should be in the under the same scenario.

Regards,

Neetesh

Former Member
0 Kudos

Sorry, I can't seem to work out the formatting for the message I posted earlier. It posts as a single line although I arranged it nicely while typing.

Former Member
0 Kudos

Thanks for that Glenn .

Will take some time for me to check this.

Former Member
0 Kudos

Hi Sherin,

First, create a Global String Parameter in the "Java Sections" of your message mapping. Then create the UDF with the code below (make sure you have created the relevant RFC comm channel in the Integration Directory).

Imports: java.io.;com.sap.aii.mapping.lookup.;

public String getMatDesc(String a,Container container){

String content = "";

MappingTrace importanttrace;

importanttrace = container.getTrace();

// filling the string with our RFC-XML (with values)

String m = "<insert BAPI xml here>";

RfcAccessor accessor = null;

ByteArrayOutputStream out = null;

try

{

// 1. Determine a channel (Business system, Communication channel)

Channel channel = LookupService.getChannel("<business service>","<comm channel>");

// 2. Get a RFC accessor for a channel.

accessor = LookupService.getRfcAccessor(channel);

// 3. Create a xml input stream representing the function module request message.

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

// 4. Create xml payload

XmlPayload payload = LookupService.getXmlPayload(inputStream);

// 5. Execute lookup.

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 lookup " + 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() );

}

}

// 7. close the accessor in order to free resources.

if (accessor!=null) {

try {

accessor.close();

} catch (LookupException e) {

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

}

}

}

//returning the result u2013 RFC-XML.response

Create a UDF "getValue" that gets the result from the the lookup UDF and saved it to the global variable "Value".

Create a third UDF "returnValue" that returns the result from the global variable "Value". This will then be used for the target field mappings.

Create multiple UDFs that parses each field of the XML output in the "Value" global parameter that you want to have as an output, example "outputDesc":

Imports: javax.xml.transform.stream.StreamResult;com.sap.aii.mapping.lookup.;javax.xml.transform.dom.DOMSource;javax.xml.parsers.;javax.xml.transform.;org.w3c.dom.;org.xml.sax.*;

public String parseMatDesc(String a,Container container){

String value="";

try{

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

// create DOM structure from input XML

DocumentBuilder builder = factory.newDocumentBuilder();

ByteArrayInputStream bais=new ByteArrayInputStream(a.getBytes());

Document document = builder.parse(bais);

// look for the tag '<name of xml tag>'

NodeList list = document.getElementsByTagName("<name of xml tag>");

Node node = list.item(0);

if (node != null) {

// if found, look for the value of 'MATL_DESC'

node = node.getFirstChild();

}

if (node != null) {

value = node.getNodeValue();

}

}

catch(Exception e){

}

return value;

the mapping for the target fields will then be:

returnValue >> getValueXXX >> targetfield

Hope that helps!

Glenn

former_member190389
Active Contributor
0 Kudos

hi,

cud u post a sample of your requirement?