cancel
Showing results for 
Search instead for 
Did you mean: 

Message Mapping - To Retrieve IDoc No. using Meesage ID

Former Member
0 Kudos

Hi Experts,

In a scenario where in File will be sent from Third Party to SAP which contains a Message ID, which is in reference to the acknowledgement of IDOC sent from SAP to Third Party.

Now what I need to find out is using this Message ID I need to Retrieve IDOC no. from the payload which was sent to third party in order to update the status of IDOC in SAP. So I suppose I need to write some user defined function and which will fetch the information from SAP PI tables.

So can you please guide me on what are the tables I can refer to have the IDoc No. from the payload and as I am not aware of writing UDF, it will be very useful if you provide me sample code for the same which I can refer in similar kind of case.

Please let me know if you need any clarification

Regards,

Nitin Patil

Accepted Solutions (0)

Answers (1)

Answers (1)

shweta_walaskar2
Contributor
0 Kudos

Hi Nitin,

You can create a UDF with following code.Pass Msgid as an input to this UDF.

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

RfcAccessor accessor = LookupService.getRfcAccessor(channel);

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

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

"</ns0:Z_ZBXI_GET_IDOC_NUM> " ;

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_DOCNUM>") + 10;

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

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

return DOCNUM;

}

catch(Exception e)

{

throw new RuntimeException("Exception : "+e);

}

This FM has to be created in R/3:

FUNCTION Z_ZBXI_GET_IDOC_NUM.

*"----


""Local Interface:

*" IMPORTING

*" VALUE(I_MSGID) TYPE IDOCCARKEY

*" EXPORTING

*" VALUE(E_DOCNUM) TYPE EDI_DOCNUM

*"----


DATA: lv_arckey(52) type c,

lv_docnum TYPE EDI_DOCNUM,

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.

if lv_sys_id = 'ABCDev'.

lv_des_id = 'DEVCLNT010'.

elseif lv_sys_id = 'ABCTest'.

lv_des_id = 'TSTCLNT010'.

elseif lv_sys_id = 'ABCPrd'.

lv_des_id = 'PRDCLNT010'.

Endif.

shift lv_arckey by 20 places right.

select single DOCNUM from EDIDC into lv_docnum where ARCKEY = lv_arckey.

if sy-subrc = 0.

e_docnum = 0.

else.

e_docnum = 1.

endif.

ENDFUNCTION.

Let us know if it works.

Thanks.

Regards,

Shweta