0% found this document useful (0 votes)
2 views5 pages

How To Send A Smartform By Mail In the Function Module

The document outlines a function module (ZSD_FORM_SEND_MAIL) for sending a Smartform via email in SAP. It details the steps for creating the email body, attaching the Smartform as a PDF, and sending it to specified recipients. Error handling and status management are also included in the implementation.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
2 views5 pages

How To Send A Smartform By Mail In the Function Module

The document outlines a function module (ZSD_FORM_SEND_MAIL) for sending a Smartform via email in SAP. It details the steps for creating the email body, attaching the Smartform as a PDF, and sending it to specified recipients. Error handling and status management are also included in the implementation.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 5

How To Send A Smartform By Mail In the Function Module

FUNCTION ZSD_FORM_SEND_MAIL.
*"----------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(IV_VBELN) TYPE VBELN
*" TABLES
*" GT_MAIL STRUCTURE ZSD_TT_MAIL_FORM
*"---------------------------------------------------------

"Object References
DATA: lo_bcs TYPE REF TO cl_bcs,
lo_doc_bcs TYPE REF TO cl_document_bcs,
lo_recep TYPE REF TO if_recipient_bcs,
lo_sapuser_bcs TYPE REF TO cl_sapuser_bcs,
gv_status TYPE bcs_rqst,
lo_cx_bcx TYPE REF TO cx_bcs,
lt_binary_content TYPE solix_tab,
lt_text TYPE bcsy_text.

DATA : lv_fm_name TYPE rs38l_fnam,


ls_controls TYPE ssfctrlop,
ls_output_opt TYPE ssfcompop.

DATA: lv_bin_filesize TYPE so_obj_len,


lv_sent_to_all TYPE os_boolean,
lv_bin_xstr TYPE xstring,
lv_string_text TYPE string.

DATA: tab_otf_data TYPE ssfcrescl,


pdf_tab LIKE tline OCCURS 0 WITH HEADER LINE,
tab_otf_final TYPE itcoo OCCURS 0 WITH HEADER LINE,
file_size TYPE i,
bin_filesize TYPE i,
file_name TYPE string,
file_path TYPE string,
full_path TYPE string.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZSD_SF_PRODUCT_LABEL'
IMPORTING
fm_name = lv_fm_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.

ls_controls-getotf = 'X'.
ls_controls-no_dialog = abap_true.
ls_controls-preview = ' '.

ls_output_opt-tddest = 'LP01'.
ls_output_opt-tdnoprev = 'X'.
ls_output_opt-tdnoprint = 'X'.

CALL FUNCTION lv_fm_name


EXPORTING
* ARCHIVE_INDEX =
* ARCHIVE_INDEX_TAB =
* ARCHIVE_PARAMETERS =
control_parameters = ls_controls
* MAIL_APPL_OBJ =
* MAIL_RECIPIENT =
* MAIL_SENDER =
output_options = ls_output_opt
user_settings = ''
siparis_belgesi = iv_vbeln
* IMPORTING
* DOCUMENT_OUTPUT_INFO =
job_output_info = tab_otf_data
* JOB_OUTPUT_OPTIONS =
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
tab_otf_final[] = tab_otf_data-otfdata.

CALL FUNCTION 'CONVERT_OTF'


EXPORTING
format = 'PDF'
max_linewidth = 132
IMPORTING
bin_filesize = bin_filesize
bin_file = lv_bin_xstr
TABLES
otf = tab_otf_final[]
lines = pdf_tab
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 4
OTHERS = 5.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'


EXPORTING
buffer = lv_bin_xstr
TABLES
binary_tab = lt_binary_content.
TRY.
lo_bcs = cl_bcs=>create_persistent( ).
"Create Email Body
"First line
CONCATENATE ‘’ cl_abap_char_utilities=>newline
INTO lv_string_text.

APPEND lv_string_text TO lt_text.


CLEAR lv_string_text.
"Second line
CONCATENATE 'Smartform has been attached.’
cl_abap_char_utilities=>newline INTO lv_string_text.

APPEND lv_string_text TO lt_text.


CLEAR lv_string_text.

lo_doc_bcs = cl_document_bcs=>create_document(
i_type = 'RAW'
i_subject = 'Order Printout'
i_length = '20'
i_text = lt_text ).

CALL METHOD lo_doc_bcs->add_attachment


EXPORTING
i_attachment_type = 'PDF'
i_attachment_subject = 'Order Form Printout'
i_attachment_size = lv_bin_filesize
i_att_content_hex = lt_binary_content.

"Add document to send request


CALL METHOD lo_bcs->set_document( lo_doc_bcs ).

LOOP AT gt_mail INTO DATA(ls_mail).

lo_recep = cl_cam_address_bcs=>create_internet_address( ls_mail-


smtp_addr ).

CALL METHOD lo_bcs->add_recipient


EXPORTING
i_recipient = lo_recep
i_express = 'X'.
ENDLOOP.
"Set Send Immediately
CALL METHOD lo_bcs->set_send_immediately
EXPORTING
i_send_immediately = 'X'.
"Send the email
CALL METHOD lo_bcs->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = lv_sent_to_all ).

IF lv_sent_to_all IS NOT INITIAL.


COMMIT WORK.
ENDIF.
gv_status = 'N'.
CALL METHOD lo_bcs->set_status_attributes
EXPORTING
i_requested_status = gv_status.

"EXCEPTION HANDLING
CATCH cx_bcs INTO lo_cx_bcx.
* WRITE: 'Exception: ', lo_cx_bcx->error_type.
ENDTRY.

ENDFUNCTION.

Thank you for reading and for your interest.

Batuhan ARGUN 23.01.2025

You might also like