Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Create Attachment within Graphical Mapping using UDF

Hi!

We want to create an attachment witihn a graphical mapping using an UDF function.

I use that function:

public String addAttachment(String filename, String mimeType, String content, Container container) throws StreamTransformationException{
	BASE64Decoder decoder=new BASE64Decoder();
	try {
		GlobalContainer globalContainer = container.getGlobalContainer();
		OutputAttachments outputAttachments = globalContainer.getOutputAttachments(); 
		Attachment attachments = outputAttachments.create(filename, mimeType,decoder.decodeBuffer(content)); 
		outputAttachments.setAttachment(attachments);

		return "Adde1: "+filename;
	} catch (Exception e) {
		return e.toString();
	}
}

(SDN helped me much in creating that

This function has no compiling errors, anything workes fine:

It takes 3 input-parameters, see also: http://help.sap.com/javadocs/pi/SP3/xpi/com/sap/aii/mapping/api/OutputAttachments.html

filename (ok, more or less contentID)

mimeType (more or less contentType)

content: Base64-encoded String which should be set as content

In my sample I use the following constants for that function:

filename = "fn1.txt"

mimeType="application/xml"

content = "UG9seWZvbiB6d2l0c2NoZXJuZCBhw59lbiBNw6R4Y2hlbnMgVsO2Z2VsIFLDvGJlbiwgSm9naHVydCB1bmQgUXVhcms=" --> cames directly from http://de.wikipedia.org/wiki/Base64

When using the message, I got this error within SXMB_MONI:

<SAP:AdditionalText>com.sap.engine.interfaces.messaging.api.exception.MessagingException: Could not queue receive for
 message 0022642d-b106-02df-8e8c-f41c243bd112(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()</SAP:AdditionalText> 

This looks pretty much the same as Add Attachment from ABAP Mapping but this tread is also not answered.

Adding attachment from PI level looks also in that direction, again, no answer.

So, I was wondering if someone has solved such problem?

Former Member
Not what you were looking for? View more on this topic or Ask a question