cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in RFC Lookup UDF in getting MessageID

GabrielSagaya
Active Contributor
0 Kudos

Hi,

I am using UDF and I am having difficulty in getting the correct "message id" imported into the RFC. All the other mappings are working, the PO number, Message Date and Message Time all work as expected.

I've tried changing the data type of I_MESSAGEID. Using this message id and the following data types I get different results:

I_MESSAGEID should look like this: 4989D6DBCE5B4C85E10000000A5060AC

but when...

I_MESSAGEID is set to CHAR(32): Ó倃၏טℶ፝㓓

I_MESSAGEID is set to RAW(16): E3DF01DB7D03DB6E3ADF9E84135D34D3

I_MESSAGEID is set to RAW(32): E3DF01DB7D03DB6E3ADF9E84135D34D3

I_MESSAGEID is set to String: ######n:ߞ##]4#

Source MT

************

PONumber(XSD:String)

CreationDateTime(XSD:DateTime)

TargetMT

**********

Message_ID(XSD:base64Binary)

Mapping

**********

PONumber----

-


CreationDateTime-SubString(0,8)--


Create_ZTOR_Rec----->Message_ID

CreationDateTime-SubString(9,15)--

-


Constant(4989D6DBCE5B4C85E10000000A5060AC)---

I have written the UDF according to the following article

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

My UDF Code

****************

public String Create_ZTOR_Rec(String MsgID,String MsgDate,String MsgTime,String PONum,Container container){

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:ZTEST_FUNC xmlns:ns0="urn:sap-com:document:sap:rfc:functions">";

importanttrace.addWarning("Your MessageID"MsgID);+

+m = m + "";+

RfcAccessor accessor = null;

ByteArrayOutputStream out = null;

try

{

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

Channel channel = LookupService.getChannel("DEV_ECC","RECEIVER_CC");

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

//InputStreamReader isr = new InputStreamReader(m);

//BufferedReader br = new BufferedReader (isr);

//importanttrace.addWarning("Buffered Data "br.readLine());+

importanttrace.addWarning("Input in Bytes "m.getBytes());+

importanttrace.addWarning("Input Stream: "inputStream);+

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

}

}

}

return content;

}

I am able to get the correct Message ID using JCO CALL in UDF.

But I am not able to get correct Msg ID using RFC Lookup.

Is there any module key required for communication channel??

regards

Gabriel

Accepted Solutions (1)

Accepted Solutions (1)

shweta_walaskar2
Contributor
0 Kudos

Hi Gabriel,

I have done the same in one of my scenarios where I wanted to retrieve the status of IDoc posted by XI .

In this case,Message ID in XI is the archive key in IDoc

So in my mapping,function flow is:

getMsgID -> getIDocStatus

getMsgID(No parameter passed)

Import java.util.Map;

public String getMSGID(Container container){

String headerField;

// get runtime constant map

java.util.Map map;

map = container.getTransformationParameters();

String key = "MessageId";

// get value of header field by using variable key

//headerField = message.getCorrelationHeader() .getRefToMessageID();

headerField = (String) map.get(key);

return headerField;

getIDocStatus(Msg ID passed as parameter)

try{

Thread.sleep(3600);

Channel channel = LookupService.getChannel("ABCCLNT020","CC_RFC_Receiver_Edifact_Orders");

RfcAccessor accessor = LookupService.getRfcAccessor(channel);

String rfcxml ="<ns0:Z_ZBXI_GET_IDOC_STATUS xmlns:ns0=\"urn:sap-com:document:sap:rfc:functions\">" +

"<I_MSGID>"+ MSGID + "</I_MSGID>" +

"</ns0:Z_ZBXI_GET_IDOC_STATUS> " ;

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

XmlPayload payload = LookupService.getXmlPayload(inputStream);

Payload rfcOutPayload = accessor.call(payload);

InputStream in = rfcOutPayload.getContent();

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

}

String content = out.toString();

int Start_Index , End_Index ;

Start_Index = out.toString().indexOf("<E_STATUS>") + 10;

End_Index = out.toString().indexOf("</E_STATUS>") ;

String STATUS = out.toString().substring(Start_Index , End_Index);

return STATUS;

}

catch(Exception e)

{

throw new RuntimeException("IDoc not found: "+e);

}

RFC ZXI_GET_IDOC_STATUS

FUNCTION Z_ZBXI_GET_IDOC_STATUS.

*"----


""Local Interface:

*" IMPORTING

*" VALUE(I_MSGID) TYPE IDOCCARKEY

*" EXPORTING

*" VALUE(E_STATUS) TYPE EDI_STATUS

*"----


DATA: lv_arckey(52) type c,

lv_status TYPE EDI_STATUS,

lv_key like edidc-arckey,

lv_sys_id like sy-sysid,

lv_des_id type char10.

lv_sys_id = sy-sysid.

lv_arckey = i_msgid.

CALL FUNCTION 'Z_ZBXI_GET_PRE_MSG_ID'

destination lv_des_id

EXPORTING

I_CURRMSGID = lv_arckey

IMPORTING

E_PREMSGID = lv_arckey.

lv_key = lv_arckey.

shift lv_key by 20 places right.

select single STATUS from EDIDC into lv_status where ARCKEY = lv_key.

if sy-subrc = 0.

e_status = 0.

else.

e_status = 1.

endif.

ENDFUNCTION.

I hope ,I have understood your problem correctly.

Can you please try it out and let us know if it works.

Thanks.

Regards,

Shweta

GabrielSagaya
Active Contributor
0 Kudos

Hi Shwetha,

Since I changed the data type for Message Id IDOCCARKEY instead of RAW(16) in Function Module,

its started working fine.

Thanks a lot

regards

Gabriel

Former Member
0 Kudos

Very useful answer.

Instead of doing multipal things.

Answers (0)