
During one of our requirement I found ABAP Consumer proxy class doesn't create the attachment method like Java consumer proxy. We need to insert the attachment at runtime using WS protocol. Here I am going to explain the steps and code.
Assumption:
<sapattahnd:Enabled xmlns:sapattahnd="http://www.sap.com/710/features/attachment/">true</sapattahnd:Enabled>
2. Web service is consumed and proxy class is activated
3. Create a Z class, method and use the code below
METHOD set_proposal.
* Author: Amaresh Pani
DATA: lcl_obj TYPE REF TO zca_co_customerproposal,
ls_request TYPE zca_send_customer_proposal_re4,
ls_response TYPE zca_send_customer_proposal_re3.
TRY.
CREATE OBJECT lcl_obj.
CATCH cx_ai_system_fault INTO lx_fault.
gv_msg = lx_fault->get_text( ).
ENDTRY.
*----------------------------------------------------------------------------------------**
DATA: lo_attachments TYPE REF TO if_wsprotocol_attachments.
DATA: g_attachment TYPE REF TO if_ai_attachment,
g_attachments TYPE prx_attach, "Internal table for attachment
g_attach_xstring TYPE xstring. "variable of xstring type.
* binary xstring file stored in Z table
SELECT SINGLE value FROM zzupld INTO g_attach_xstring WHERE filename = 'CUST'.
TRY.
lo_attachments ?= lcl_obj->get_protocol( if_wsprotocol=>attachments ).
g_attachment = lo_attachments->get_attachment_from_binary(
data = g_attach_xstring " File content
type = if_ai_attachment=>c_mimetype_pdf " MIME type
name = 'CustomerProposal' ). " Name of PDF to be uploaded
APPEND g_attachment TO g_attachments.
lo_attachments->set_attachments( g_attachments ).
CATCH cx_ai_system_fault INTO lx_fault.
gv_msg = lx_fault->get_text( ).
ENDTRY.
*----------------------------------------------------------------------------------------**
ls_request-send_customer_proposal_request-document-opprotunity_id-content = '7117941'. " Defaulted content of proxy
TRY.
lcl_obj->send_customer_proposal(
EXPORTING
send_customer_proposal_request = ls_request
IMPORTING
send_customer_proposal_respons = ls_response ).
CATCH cx_ai_system_fault INTO lx_fault.
gv_msg = lx_fault->get_text( ).
CATCH cx_ai_application_fault INTO lx_fault1.
gv_msg = lx_fault->get_text( ).
ENDTRY.
ENDMETHOD.
Content in Z table zzupld
Remember to set attachment "YES" while creating the endpoint.
Execute the method to trigger the web service with attachment. Enable payload trace in SRT_UTIL to see the file attachment.
SOAP creates tag MULTIPART. PART_1 contains the general SOAP xml content. PART_2 contains the attachment as above.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
3 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |