cancel
Showing results for 
Search instead for 
Did you mean: 

Add Attachment from ABAP Mapping

Former Member
0 Kudos

Hi Gurus,

is it possible to add an attachment during a ABAP mapping? Like it is possible for proxy!

I want to attach a jpg file during the mapping. I found also class interface CL_MAPPING_ATTACHMENTS with a

few method e.g. SET_ATTACHMENT but it does not wotk.

Anyone of you knows some solutions or hinds?

Thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Michael,

is it possible to add an attachment during a ABAP mapping? Like it is possible for proxy!

Yes, it is possible.

I had worked on similar scenario and I had used - Interface "IF_XMS_MESSAGE" ... here you can find lots of methods for attachments like "GETATTACHMENTBYNAME", GETATTACHMENTSBYTYPE", "GETATTACHMENTS" etc.

This should help resolving your issue.

Regards,

Neetesh

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Neetesh Raj ,

thank you for the.

Could you please explain a little bit more? I haven't tried it yet but for me it would be logical to use

IF_XMS_RESOURCESETBINARYDATA to set the attachment and afterwards IF_XMS_MESSAGEADDATTACHMENT.

Do you mean it like this?

Thank You!

Former Member
0 Kudos

Michael,

It depends on what your requirement is. I will give you an example, which you can use as a sample. Suppose you are getting multiple attachments with the message.

So, follow these steps :-

1. get the number of attachments with "numberofattachments";

2. get each attachment using "getattachmentatindex";

3. get attachment type using "GETTYPE";

4. determine the attachment kind (Binary or text) using "GETKIND";

5. If Binary, then use "GETBINARYDATA" .. OR if text, use "GETTEXTDATA".

You can use Try and Catch for all these, you can do the catch with interface "CX_XMS_EXCEPTION" for each of these.

Hope this answers your question.

Regards,

Neetesh

Former Member
0 Kudos

Hi,

maybe you missunderstood me. I don't want to read attachments from the source message. I want to add an attachment to the target message.

In my scenario i have an binary data which is an jpg picture which should be appended to the payload.

Tnaks

Former Member
0 Kudos

oops ... sorry for the confusion

You can use ADD_ATTACHMENT (it creates an attachment) or ADD_DOCUMENT_AS_ATTACHMENT (add existing document as an attachment) method of interface CL_DOCUMENT_BCS.

Let us know if this works for you.

Former Member
0 Kudos

HI,

I found an other solution or lets say I found an error in my interface call. IF_MAPPING_ATTACHMENTS -> set_attachment is working, sorry!!!

TRY.

CALL METHOD attachments->set_attachment

EXPORTING

content_id = '1.jpg'

content_type = if_xms_resource=>mimetype_jpeg

content = l_data.

CATCH cx_xms_system_error .

ENDTRY.

The Attachment is in the Payload, but now I get an error from the adapter, when I use file or mail receiver adapter! For a little test I used http receiver and there it is working!?

"com.sap.engine.interfaces.messaging.api.exception.MessagingException: Could not queue receive for message df9cc710-62c9-85f1-b25f-005056c00008(INBOUND). Reason: java.lang.NullPointerException: while trying to invoke the method com.sap.aii.af.sdk.xi.lang.Binary.getBytes() of an object returned from com.sap.aii.af.sdk.xi.mo.xmb.XMBPayload.getContent() "

I get it in FILE and EMAIL Adapter!? Do you know the reason? I'm still looking for it.

Edited by: Michael Kulak on Jul 30, 2010 8:50 PM

Edited by: Michael Kulak on Jul 30, 2010 9:04 PM

Former Member
0 Kudos

Receiver File adapters do not support attachments, only the sender adapter supports.

You can use the Axis adapter in file mode, this supports attachment :

http://help.sap.com/saphelp_nw04/helpdata/en/45/a3c48c87cd0039e10000000a11466f/frameset.htm

Another way around is that you use two receivers for the message, one writes the file and the second one handles the attachment.

For receiver mail adapter - if you want to forward XI attachments in e-mail attachments, then set the Keep Attachments indicator.

Hope this helps.

Regards,

Neetesh

Former Member
0 Kudos

Hi,

sounds bad. Because I have to transfer additional pictures for a payload through the file (ftp) adapter. I tried it also with the Axis Adapter but it is not working either.

How do you mean to use two receivers?

Thanks

edit: Ok now I know what you mean with two receivers! One for the payload and one for the attachment.

But I tried something different. For testing reasons I created a proxy and a report to send the attachment. In the file adapter (receiver) I zip the payload. And the everything is fine, I get the picture zipped. (This option can't be used in my scenario!)

I think the problem is caused by the adapter engine itself, maybe I have to set additional values in my mapping!? I also found a SAP Note(1422354), but it does not solve the problem.

Edited by: Michael Kulak on Aug 2, 2010 2:11 PM

Former Member
0 Kudos

Found the reason why following error occurs:

"com.sap.engine.interfaces.messaging.api.exception.MessagingException: Could not queue receive for message df9cc710-62c9-85f1-b25f-005056c00008(INBOUND). Reason: java.lang.NullPointerException: while trying to invoke the method com.sap.aii.af.sdk.xi.lang.Binary.getBytes() of an object returned from com.sap.aii.af.sdk.xi.mo.xmb.XMBPayload.getContent() "

It is because of the content_id in the following call:

CALL METHOD attachments->set_attachment

EXPORTING

content_id = '1.jpg'

content_type = if_xms_resource=>mimetype_jpeg

content = l_data.

It has to be empty! Then the scenario works but without a filename. And that is a problem because I can have multiple attachments. Any Idea?

Former Member
0 Kudos

Hi Michael,

I have got the exactly same problem with multiple attachments. Have you got any solution?

Thanks,

Pavel.

Edited by: Pavel Korinek on Aug 27, 2010 11:32 AM

martin_pichlo
Participant
0 Kudos

Hi Michael, hi Pavel

Have you found any solution for setting the content_id? I've the same problem, too.

Regards

Martin