Friday, 23 October 2009

Mail with Attachments from Transaction Monitor (CRM_DNO_MONITOR)

The implementation of mail with attachment-button starts the same as the print-button implementation.

First with function SSF_FUNCTION_MODULE_NAME the functionname is determined for IP_SMARTFORM = Z_NEWCOL_PRINTFORM.

The LV_OBJECT_ID is read from table CT_REPORT_LIST for the selected line and the LV_OBJECT_GUID is read from table CRMD_ORDERADM_H.

With function CRM_OUTPUT_SINGLE_READ followed by CRM_ORDER_READ the order data is read for the selected entry.

With a CALL FUNCTION FUNCTION_NAME the form is created, sent to spool and printed immediately.

For mailing the form with attachments the print dialog is suppressed with the line:
control_parameters-no_dialog = 'X'.

The following parameters make sure the form is not printed and not deleted:
ls_output_options-immed = ' '. "Print Immediately
ls_output_options-tddelete = ' '. "Delete After Printing


Now the spool_id can be selected from table TSP01 and with this spool_id a pdf is created in the background with function CONVERT_OTFSPOOLJOB_2_PDF.

This function is newly delivered with OSS-Note: 1320163 – Incorrect PDF data Unicode Conversion. Together with the new example program BCS_EXAMPLE_8 from OSS-Note 1324547 – Sending a spool requerst as PDF via e-mail it is possible to create the mail request and add the attachments with the CL_BCS Class (Business Communication Service).


CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
EXPORTING src_spoolid = f_rqident
no_dialog = 'X'
pdf_destination = 'X'
no_background = 'X'
IMPORTING
pdf_bytecount = bin_size
bin_file = pdf_xstring
EXCEPTIONS
err_no_abap_spooljob = 1

The function CONVERT_OTFSPOOLJOB_2_PDF can now create a PDF_XSTRING (this was not possible with the previous version) and the xtring can be added to the mail object directly as attachments with the lines:

pdf_content = cl_document_bcs=>xstring_to_solix( pdf_xstring ).

document->add_attachment( i_attachment_type = 'PDF'
i_attachment_subject = lv_pdf_subject
i_attachment_size = pdf_size
i_att_content_hex = pdf_content ).

The other attachments are selected from table SKWG_BREL:

SELECT * FROM skwg_brel INTO TABLE lt_attach_guid WHERE instid_a = lv_object_guid.

With the following function the attachment is read:

CALL FUNCTION 'CRM_IM_ATTACHMENTS_CONTENT_GET'
EXPORTING
is_doc_id = ls_skwf
IMPORTING
et_content = lv_bcsy
et_content_bin = lt_solix
ev_attach_type = lv_attype
ev_attach_size = lv_size
ev_attach_subject = lv_subject.


And the following method from Class CL_BCS adds the attachment to the mail request:

CALL METHOD document->add_attachment
EXPORTING
i_attachment_type = lv_attype
i_attachment_subject = lv_subject
i_attachment_size = lv_size
i_att_content_text = lv_bcsy
i_att_content_hex = lt_solix
EXCEPTIONS
OTHERS = 1.

At the end the mail request is sent:

w_sent_all = send_request->send( i_with_error_screen = 'X' ).

And the spoolrequest is deleted:

CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'
EXPORTING
spoolid = l_spoolid.


No comments: