cancel
Showing results for 
Search instead for 
Did you mean: 

How to Call Function Module from XI Mapping

Former Member
0 Kudos

Hi All,

I would like to call a function module that resides in ECC through XI mapping.

Can any one please through some light on how to proceed ?

Regards

Accepted Solutions (1)

Accepted Solutions (1)

Shabarish_Nair
Active Contributor
0 Kudos

expose the FM as a RFC enabled one and then you can use the RFC lookup concept to call it

Former Member
0 Kudos

Hello Shabarish,

Thanks for the reply, Actually i would like to do date validation using ISHMED_CHECK_DATE_TIME FM inside Mapping.

I would like to do this way, please let me know how good is this

1) Expose the FM as a RFC enabled one

2) Use the following UDF code inside Mapping

3) do i need to import the RFC enabled FM into our XI??

4) Do i required to create any Communication channel for this?

function RFC_LOOKUP_API

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

String content = "";

MappingTrace importanttrace;

importanttrace = container.getTrace();

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

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

m = m + "<I_MESSAGEID>" + MsgID + "</I_MESSAGEID>";

m = m + "<I_EBELN>" + PONum + "</I_EBELN>";

m = m + "<I_ERDAT>" + MsgDate + "</I_ERDAT>";

m = m + "<I_UZEIT>" + MsgTime + "</I_UZEIT>";

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

RfcAccessor accessor = null;

ByteArrayOutputStream out = null;

try

{

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

Channel channel = LookupService.getChannel("XI","GeneratedReceiverChannel_RFC");

// 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 Record Create.

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

}

}

// 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

return content;

Thanks & Regards

Vamsi

Shabarish_Nair
Active Contributor
0 Kudos

>

> 1) Expose the FM as a RFC enabled one

yes

> 2) Use the following UDF code inside Mapping

yes

> 3) do i need to import the RFC enabled FM into our XI??

not really

> 4) Do i required to create any Communication channel for this?

yes RFC receiver adapter is required.

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/a03e7b02-eea4-2910-089f-8214c6d1...

Former Member
0 Kudos

Hello Shab,

Thanks for replying, I understood the entire flow how it works by your link.

Now i have few doubts

1) The idea behind this is to validate the incoming date from XML whether it is valid or not

2) For this I would like to call ISHMED_CHECK_DATE_TIME funtion module (resides in R/3) in Mapping.

3) I would like to pass one argument(date) as input to this function module and if that date is valid means it returns the same date

Else it returns blank.

4) In mapping i will use Date transformation after this UDF, if date comes properly means i will pass it to Idoc else date comes as blank means, here it will fail because date transformation dont like blan as input.

So here my doubt is i would like to pass input to I_DATE and i would like to receive the response of E_DATE

In the example UDF code Michael gave PO number directly but i dont want to give the date here, i would like to pass it dynamically based on the runtime and get the E_DATE.

Could you please let me know how to pass the arguments and and how to Parse the response E_DATE

Regards

Former Member
0 Kudos

Hi,

You dont need to write a UDF for RFC lookup. PI provides configuration in message mapping where in you can call RFC look up dynamically.

you need to perform following steps:

1) define RFC channel to connect to ECC

2) In MM signature define parameter for rfcchannel

3) Between source and target date you can add RFCLookup from conversions. Then define properties where you add the FM name and communication channel to be used for RFC look up

4) In OM you need to define binding for the channel which you will also need to provide in ID for interface determination.

This will allow to check date dynamically.

Please refer to this /people/jin.shin/blog/2008/02/15/sap-pi-71-mapping-enhancements-series-graphical-support-for-jdbc-and-rfc-lookups

Hope this helps.

Regards,

Dipali

Former Member
0 Kudos
So here my doubt is i would like to pass input to I_DATE and i would like to receive the response of E_DATE

You can pass the input value to the RFC as shown below -

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

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

m = m + "<I_DATE>" + UDFInputDate + "</I_DATE>";

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

....................................

....................................

You can parse the output XML as shown below -

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder = factory.newDocumentBuilder();

Document document = builder.parse(in);

NodeList list = document.getElementsByTagName("E_DATE");

Node node = list.item(0);

if (node != null) {

node = node.getFirstChild();

if (node != null) {

UDFReturnValue = node.getNodeValue();

}

}

Former Member
0 Kudos

Hi all,

Thanks to every one,I have used the UDF to achieve this

public String DateValidation(String ddmmyyyy,Container container)

{

//write your code here

String inputDate = null;

try

{

int dd = Integer.parseInt(ddmmyyyy.substring(0, 2));

int mm = Integer.parseInt(ddmmyyyy.substring(2, 4));

int yyyy = Integer.parseInt(ddmmyyyy.substring(4, 7));

java.text.SimpleDateFormat dateFormat = new java.text.SimpleDateFormat("ddMMyyyy");

Date date = (Date) dateFormat.parse(ddmmyyyy);

int ndd = date.getDate();

int nmm = date.getMonth() + 1;

if( (dd == ndd) && (mm == nmm) )

{

inputDate = ddmmyyyy;

}

else

{

inputDate = "";

}

}

catch(Exception exp)

{

inputDate = "";

}

return inputDate;

}

Regards

Answers (0)