Skip to Content
-1
Aug 22, 2023 at 03:17 PM

send adobe form output in mail attachment

66 Views Last edit Aug 22, 2023 at 12:07 PM 2 rev

mail is going successfully, pdf appears in attechment section, but when I want to download and open it, it says that the file is damaged, I think there is a problem in the data conversion process, but I could not solve it.

thanks


 METHOD send_approval_mail. 

DATA: go_gbt TYPE REF TO cl_gbt_multirelated_service,
go_bcs TYPE REF TO cl_bcs,
go_doc_bcs TYPE REF TO cl_document_bcs,
go_recipient TYPE REF TO if_recipient_bcs,
gt_soli TYPE TABLE OF soli,
gs_soli TYPE soli,
gv_status TYPE bcs_rqst,
gv_content TYPE string,
gv_attachment_size TYPE sood-objlen,
gt_att_content_hex TYPE solix_tab,
gv_att_content TYPE string,
gv_att_line TYPE string,
gs_DOCPARAMS TYPE sfpdocparams,
gs_FORMOUTPUT TYPE fpformoutput,
gs_outputparams TYPE sfpoutputparams,
gv_name TYPE fpname,
gv_funcname TYPE funcname,
gv_output_length TYPE i.



gv_content = '<!DOCTYPE HTML >'
&& '<HTML>'
&& '<head>'
&& ' <meta charset = "utf-8"'
&& ' </head>'
&& ' <body>'
&& ' <h1 style = "color:red" >Hi, your login request has been approved.Entry card is available as an e-mail attachment.</h1>'
&& ' <table border="10" style =" color :blue">'
&& ' <tr>'
&& ' <th style = "color:yellow">Car Plate</th>'
&& ' <th style = "color:yellow">Driver Name</th>'
&& ' <th style = "color:yellow">Driver Surname</th>'
&& ' <th style = "color:yellow">Cargo</th>'
&& ' <th style = "color:yellow">Officer </th>'
&& ' <th style = "color:yellow ">Shıft Date</th>'
&& ' <th style = "color:yellow" >Shıft Hour</th>'
&& ' </tr>'.


go_alv->get_selected_rows( IMPORTING et_index_rows = lt_selected_rows ).
IF lt_selected_rows IS NOT INITIAL.
LOOP AT lt_selected_rows INTO ls_selected_row.
READ TABLE gt_entry INTO ls_report_row INDEX ls_selected_row-index.
IF sy-subrc = 0.
APPEND ls_report_row TO lt_report_data.
ENDIF.
ENDLOOP.
ENDIF.

LOOP AT lt_selected_rows INTO ls_selected_row.
READ TABLE gt_entry INTO ls_report_row INDEX ls_selected_row-index.
IF sy-subrc = 0.
APPEND ls_report_row TO lt_report_data.
gv_content = gv_content
&& ' <tr>'
&& ' <td>' && ls_report_row-car_plate && '</td>'
&& ' <td>' && ls_report_row-driver_name && '</td>'
&& ' <td>' && ls_report_row-driver_surname && '</td>'
&& ' <td>' && ls_report_row-cargo && '</td>'
&& ' <td>' && gs_officer-officer_id && '</td>'
&& ' <td> ' && gs_officer-shift_date && ' </td>'
&& ' <td> ' && gs_officer-shift_hour && ' </td> '
&& ' </tr>'.
ENDIF.
ENDLOOP.

gv_content = gv_content && ' <table> '
&& ' </body>'
&& ' <html>'.

gt_soli = cl_document_bcs=>string_to_soli( gv_content ).

CALL METHOD go_gbt->set_main_html
EXPORTING
content = gt_soli.

go_doc_bcs = cl_document_bcs=>create_from_multirelated(
i_subject = 'approval mail'
i_multirel_service = go_gbt ).

fp_outputparams-preview = ''.
fp_outputparams-nodialog ='X'.
fp_outputparams-dest = 'LP01'.
fp_outputparams-getpdf = 'X'.


CALL FUNCTION 'FP_JOB_OPEN'
CHANGING
ie_outputparams = fp_outputparams.

IF sy-subrc = 0.

CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
EXPORTING
i_name = 'ZYO_SF007'
IMPORTING
e_funcname = fname.

CALL FUNCTION fname
EXPORTING
gt_table = lt_report_data
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3
OTHERS = 4.

CALL FUNCTION 'FP_JOB_CLOSE'
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3
OTHERS = 4.

gv_attachment_size = gv_output_length .
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = gs_formoutput-pdf
IMPORTING
output_length = gv_output_length
TABLES
binary_tab = gt_att_content_hex.

go_doc_bcs->add_attachment(
EXPORTING
i_attachment_type = 'pdf'
i_attachment_subject = 'attachment_name'
i_attachment_size = gv_attachment_size
i_att_content_hex = gt_att_content_hex
).

go_recipient = cl_cam_address_bcs=>create_internet_address(

i_address_string = 'asdfasdf@gmail.com' ).


go_bcs = cl_bcs=>create_persistent( ).
go_bcs->set_document( i_document = go_doc_bcs ).
go_bcs->add_recipient( i_recipient = go_recipient ).
gv_status = 'N'.
CALL METHOD go_bcs->set_status_attributes
EXPORTING
i_requested_status = gv_status.
go_bcs->send( ).
COMMIT WORK.
IF sy-subrc EQ 0.
MESSAGE 'e-mail sent' TYPE 'I' DISPLAY LIKE 'S'.
ENDIF.
ENDIF.
ENDMETHOD.