Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
METHOD send.
DATA: ls_context TYPE zcl_hr_document=>mty_context,
lo_document TYPE REF TO zcl_hr_document,
lv_pdf TYPE xstring.
DATA: ls_output TYPE zmt_document,
lo_si_o_document TYPE REF TO zco_si_o_document,
lo_attch_protocol TYPE REF TO if_wsprotocol_attachments,
lo_attachment TYPE REF TO if_ai_attachment,
lt_attachments TYPE prx_attach,
lo_sys_exception TYPE REF TO cx_ai_system_fault,
lv_filename TYPE string.
* Заполним контекст для формирования pdf
ls_context-pernr = is_input-mt_document_request-doc-employee_id.
ls_context-year = is_input-mt_document_request-doc-year.
ls_context-month = is_input-mt_document_request-doc-month.
CREATE OBJECT lo_document
EXPORTING
is_context = ls_context.
* Получаем pdf документ в бинарном виде
lv_pdf = lo_document->get_document( ).
TRY.
CREATE OBJECT lo_si_o_document.
lo_attch_protocol ?= lo_si_o_document->get_protocol( if_wsprotocol=>attachments ).
lv_filename = get_filename( is_input ).
lo_attachment = lo_attch_protocol->get_attachment_from_binary( data = lv_pdf
type = if_ai_attachment=>c_mimetype_pdf
name = lv_filename ).
APPEND lo_attachment TO lt_attachments.
lo_attch_protocol->set_attachments( lt_attachments ).
* Здесь заполняем поля, которые будут отправлены в ответе вместе с pdf-файлом
ls_output = fill_other_fields( is_input ).
* Отправляем pdf и заполненные поля в XI/PI
lo_si_o_document->si_o_document( ls_output ).
CATCH cx_ai_system_fault INTO lo_sys_exception.
* Здесь может быть ваша обработка исключений
ENDTRY.
* Обязательно!
COMMIT WORK.
ENDMETHOD.
@victorizbitskiy

This comment has been minimized.

Copy link
Owner Author

@victorizbitskiy victorizbitskiy commented Nov 22, 2020

Implementation of ABAP Proxy with PDF attachment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.