Skip to Content
Author's profile photo Aashish Sinha

Handle SOAP with Attachment in SAP PI 7.31

I came across with lots of questions related with SOAP with attachments in PI and can’t see many guides/blogs related to this. So I thought to clear the cloud on this with a Synchronous SOAP-PI-Proxy scenario.

In this scenario we will handle attachment in Synchronous proxy call. SOAP request will pushed through third party tool SOAPUI, where we will attach the payload in request.

Assumption –

  1. SLD configuration is with Technical System and Business System is done. Product and SWC is created in SLD.
  2. SWC is imported in ESR.
  3. Communication between ECC to PI and PI to Proxy is done.
  4. ABAP code will only include logic of How to read incoming attachment.
  5. SOAPUI is installed.

Below is the development done in PI side –

ESR Development

For testing purpose, I am taking few fields in source and target side. Main aim is to read attachment in inbound proxy.

Source Data Type – DT_Source


Target Data Type – DT_TARGET


Based on these data types, create Message type – MT_SOURCE and MT_TARGET.

Create Service Interface for Synchronous message flow.

Outbound Service Interface –


Inbound Service Interface-


Next step is to create Request and Response Message Mappings.

Request Message Mapping –


Response Message Mapping –


Now create operations mapping based on above request and response mapping.

Request Operation Mapping –


Response Operation Mapping –


Configuration – Integration Builder

For configuration of this scenario, we need to create 2 Communication channel (Sender and Receiver) and an ICO.

Sender Communication Channel – SOAP Sender for Proxy communication, which is able to hold attachment if we click on Keep Attachments under Conversion Parameters.


Receiver Communication Channel


Integrated Configuration

Create Integrated Configuration between sender and receiver with above communication channel with operations mapping.


Now, development is completed from PI side. We need to go to ECC and generated server proxy to implement the method to read attachment and send output file back.

In ECC, go to SPROXY transaction and generate proxy for Inbound Service Interface.


Double Click on provider class->Method Name to implement logic in inbound proxy class method.

ABAP Code –

METHOD zii_si_target~si_target.
  DATA: lt_attach    TYPE prx_attach,
        l_name       TYPE string,
        l_xstring    TYPE xstring,
        l_string     TYPE string,
        l_type       TYPE string,
        l_attachment TYPE REF TO if_ai_attachment.
  DATA:  lo_server_context   TYPE REF TO if_ws_server_context,
         lo_payload_protocol TYPE REF TO if_wsprotocol.
  DATA : l_kind TYPE sychar01.
      lo_server_context   = cl_proxy_access=>get_server_context( ).
      lo_payload_protocol = lo_server_context->get_protocol( if_wsprotocol=>payload ).
      DATA : lo_attachment_protocol TYPE REF TO      if_wsprotocol_attachments.

      lo_attachment_protocol ?=
           lo_server_context->get_protocol( if_wsprotocol=>attachments ).

      CALL METHOD lo_attachment_protocol->get_attachments
          attachments = lt_attach.
    CATCH cx_ai_system_fault.
  LOOP AT lt_attach INTO l_attachment.
    CALL METHOD l_attachment->get_kind
        p_kind = l_kind.
    IF l_kind NE space.
      CALL METHOD l_attachment->get_binary_data
          p_data = l_xstring.
      in_xstring  = l_xstring
*     IN_CODEPAGE = '4110'
*     EX_CODEPAGE = '0000'
*     UNMASK_CRLF = ''
      ex_string   = l_string
      error       = 1
      OTHERS      = 2.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  DATA : lt_record TYPE zdt_target_record_tab,
         lwa_record TYPE zdt_target_record.
  CLEAR lwa_record.
  lwa_record-id =  l_string.
  APPEND lwa_record TO lt_record.
  output-mt_target-record = lt_record.

Above code help to read incoming attachment in inbound proxy method in ABAP and then we can implement it as per our requirement. As of now, I have mapped incoming payload to one of the field (ID of data types mentioned earlier).

We are ready to test this scenario.

First step of testing is to download WSDL of this scenario.

Open Integrated Configuration ->Display WSDL -> Save to save the WSDL.

Open SOAPUI and give SOAP UI project name and browse WSDL path, downloaded in earlier step. Then double click on request 1 to send SOAP request to SAP. Add attachment to the message before sending any request. Also add authentication details in SOAPUI before posting request.


Below is the response received in SOAPUI.


Through this blog, I tried to give a simple solution about How to read an attachment in inbound proxy. There is possibility of different solution approach and above blog is in one of them. Hope this will help many people who stuck in SOAP with attachment scenario.

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Hi Aashish,

      What configurations we need to do in ID if attachment is coming only as a response for webservice request?

      Scenario is Webservicerequest(without attachment)> PI> Proxy>PI>Webservice Response(with attachment)?

      Author's profile photo Technical ABEAM
      Technical ABEAM

      I have same issue, did you get any solution?

      Author's profile photo Former Member
      Former Member

      Hello Aashish,

      Thanks for the document. It would be good if you could mention the T codes also, so that beginners like me can find it easy to follow.

      Author's profile photo Youri Catinat
      Youri Catinat

      Hi Aashish,

      In my case i need to work with Excel Attachment or PDF.

      No problem with PDF Attachment.

      I receive the Attachment in Binary (Soap With Attachment).

      No problem with Soap With Attachment, i did some tests with SoapUI.


      I can create the .xls file correctly.

      How to work with Excel Attachment ?

      Author's profile photo Former Member
      Former Member

      Hello Youri,

      I am also having a synchronous soap-pi-proxy call where I am getting response from ECC in the form of binary data, this binary data is extracted in PI through UDF and an attachment is created out of it. This attachment is excel file .

      I am using content type: application/msexcel  but it's still creating attachment.bin in soapUI.

      Also, I'm getting pop ups whne I try to open the file by changing extension of the attachment.

      Did you find solution to your problem??

      Please advise.


      Indu Khurana.

      Author's profile photo Hubery Yao
      Hubery Yao

      Hello All,

      I have a question about the size of attachment. I test the scenario in PI 7.11. The size of attachment is less than 5M, otherwise, it will be overtime. For PI 7.31, I am not sure whether the size of attachment is bigger.  Anyone knows the biggest size of attachment ?

      Thank you for your support.

      Many thanks & best regards,