cancel
Showing results for 
Search instead for 
Did you mean: 

PI - PDF files as attachments from XML

Former Member
0 Kudos

Hello,

I have a requirement where in I will be receiving a order document as XML along with a PDF attachment, I need to load this order in to R/3 through an IDoc and along with that I need to load the PDF as attachment to the actual Sales order document. My questions is on handling the PDF attachment, I have been reading about options to load the PDF as string in the IDoc and load it in to the Sales Order via IDoc processing module?

is there a better way to achive this?

If this could be done this way through IDoc can you please outline how do I efficiently convert PDF as string and send it in the IDoc from PI.

Thank you.

Let me know if you have any further questions.

Larry.

Accepted Solutions (1)

Accepted Solutions (1)

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Larry,

This is usually the code via UDF to convert attachment(s) to string:


String Content = "";

String AttachmentID ="";

GlobalContainer globalContainer = container.getGlobalContainer();

InputAttachments inputAttachments = globalContainer.getInputAttachments();

if(inputAttachments.areAttachmentsAvailable())

{

     Collection<String> CollectionIDs = inputAttachments.getAllContentIds(true);

     Object[] arrayObj = CollectionIDs.toArray();

     int attachmentCount = arrayObj.length;

     for(int i =0;i<attachmentCount;i++)

     {

            AttachmentID =(String) arrayObj<i>;

              Attachment attachments =inputAttachments.getAttachment(AttachmentID);

          Content = Content + attachments.getContent().toString();

      }

}

return Content;

You need to check keep attachments (if it is allowed) in your sender adapter. Another option would be to go Abap proxy as receiver.

Regards,

Mark

Former Member
0 Kudos

Thanks Mark, While converting to String and then to PDF in R/3 will there be any loss to the existing attachment format or data?

Larry

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Larry,

Just tried it today and I have a little POC. I have created an inbound proxy with the following message type:

I have just made it into string but not base64, the reason is that somehow xsd:base64 does not work for me (e.g different values in the backend).

Here is the code for the provider class:

Test:

I have encoded Resume.pdf as it would be in XI when sent as an attachment, the resulting output is attached.

This output will be the one we will use in testing the proxy.

Execute the proxy and below is a screenshot of the resulting PDF

PS: Although your scenario is idoc, make sure that the idoc field is a string. Then you can use the code

in the proxy class I provided.

Hope this helps,

Mark

Answers (0)