Skip to Content

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

Create Attachment within Graphical Mapping using UDF


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

		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:

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"


content = "UG9seWZvbiB6d2l0c2NoZXJuZCBhw59lbiBNw6R4Y2hlbnMgVsO2Z2VsIFLDvGJlbiwgSm9naHVydCB1bmQgUXVhcms=" --> cames directly from

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

<SAP:AdditionalText> Could not queue receive for
 message 0022642d-b106-02df-8e8c-f41c243bd112(INBOUND). Reason: java.lang.NullPointerException: while trying to
 invoke the method of an object returned from</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?

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