Skip to Content
1
Former Member
Aug 21, 2015 at 05:59 PM

Sending Email with pdf-attachment from Adobe Interactive spool job

381 Views

Hi I'm trying to send an email with a pdf attached. The PDF is created with Adobe Interactive. All ways i try lead to the problem, that the attached pdf is corrupt. I'm using the exporting parameter /1bcdwb/formoutput of the Adobe FM. I'm wondering because just its component xml is filled with hexadecimal content. When I'm calling transaction sp01 I can see that the spool job is created sucessful and I can also open the created pdf. The content of pdf is ok there.

I think my use of FM SCMS_XSTRING_TO_BINARY or of amethod add_attachment is wrong.

Maybe you can give me a hint, what I'm doing wrong. Thanks for your help in advance.

This is my code:

* Get function module for Adobe form

TRY.

CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'

EXPORTING

i_name = lv_form

IMPORTING

e_funcname = lv_fm_name.

CATCH cx_fp_api_repository

cx_fp_api_usage

cx_fp_api_internal

INTO lo_cx.

MESSAGE s004(/scwm/print)

DISPLAY LIKE 'E'

WITH lv_form.

RETURN.

ENDTRY.

* Open the spool job

CALL FUNCTION 'FP_JOB_OPEN'

CHANGING

ie_outputparams = ls_outputparams

EXCEPTIONS

cancel = 1

usage_error = 2

system_error = 3

internal_error = 4

OTHERS = 5.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno

DISPLAY LIKE 'E'

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

RETURN.

ENDIF.

* call Adobe Form

CALL FUNCTION lv_fm_name

EXPORTING

/1bcdwb/docparams = ls_docparams

pickinglist_data = ls_pickinglist_data

IMPORTING

/1bcdwb/formoutput = ls_formoutput

EXCEPTIONS

usage_error = 1

system_error = 2

internal_error = 3

OTHERS = 4.

IF sy-subrc <> 0.

CALL FUNCTION 'FP_GET_LAST_ADS_ERRSTR'

IMPORTING

e_adserrstr = lf_adserrstr.

MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno

DISPLAY LIKE 'E'

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

MESSAGE lf_adserrstr TYPE 'I'.

RETURN.

ENDIF.

* Close the spool job

CALL FUNCTION 'FP_JOB_CLOSE'

IMPORTING

e_result = ls_joboutput

EXCEPTIONS

usage_error = 1

system_error = 2

internal_error = 3

OTHERS = 4.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

EXPORTING

BUFFER = ls_FORMOUTPUT-xml

* APPEND_TO_TABLE = ' '

* IMPORTING

* OUTPUT_LENGTH =

TABLES

BINARY_TAB = lt_att_content_hex .

ATA: lt_email_text TYPE bcsy_text,

ls_email_text TYPE soli,

lv_email_subject TYPE so_obj_des.

* ls_address TYPE SDPRT_ADDR_S.

ls_email_text-line = 'hello'.

lv_email_subject = 'Test'.

APPEND ls_email_text TO lt_email_text.

lo_send_request = cl_bcs=>create_persistent( ).

CALL METHOD cl_document_bcs=>create_document

EXPORTING

i_type = 'TXT'

i_subject = 'Picklist'

* I_LENGTH =

i_language = sy-langu

i_text = lt_email_text

RECEIVING

result = lo_bcs_document.

lv_buf = ls_formoutput-xml.

DO.

ls_bcs_pdf-line = lv_buffer.

APPEND ls_bcs_pdf TO lt_bcs_pdf.

SHIFT lv_buffer LEFT BY 255 PLACES.

IF lv_buffer IS INITIAL.

EXIT.

ENDIF.

ENDDO.

CALL METHOD lo_bcs_document->add_attachment

EXPORTING

i_attachment_type = 'PDF'

i_attachment_size = lv_pdf_size

i_attachment_subject = lv_email_subject

i_attachment_language = sy-langu

i_att_content_hex = lt_att_content_hex."lt_bcs_pdf.

CALL METHOD cl_cam_address_bcs=>create_internet_address

EXPORTING

i_address_string = 'mailadress@mail.com'

RECEIVING

result = lo_recipient.

CALL METHOD lo_send_request->set_document( lo_bcs_document ).

*--- Add the sender

CALL METHOD lo_send_request->set_sender

EXPORTING

i_sender = lo_sender.

*--- Add the recipient

CALL METHOD lo_send_request->add_recipient

EXPORTING

i_recipient = lo_recipient.

*--- Send the document

DATA EV_SEND_TO_ALL TYPE OS_BOOLEAN.

CALL METHOD lo_send_request->send

EXPORTING

i_with_error_screen = abap_true

RECEIVING

result = ev_send_to_all.