*& Form ENVIA_EMAIL
*&---------------------------------------------------------------------*
FORM envia_email .
DATA: cl_send_request TYPE REF TO cl_bcs,
cl_document TYPE REF TO cl_document_bcs,
cl_sender TYPE REF TO cl_sapuser_bcs,
cl_recipient TYPE REF TO if_recipient_bcs,
cl_bcs_exception TYPE REF TO cx_bcs.
DATA: li_text TYPE bcsy_text,
li_bin_cont TYPE solix_tab.
DATA: lv_sent_to_all TYPE os_boolean,
lv_filename TYPE string,
lv_texto TYPE string,
lv_texto_aux TYPE string,
lv_length TYPE sood-objlen,
lv_size TYPE so_obj_len,
lv_title TYPE sood-objdes.
CHECK p_email = 'X'.
TRY.
* -------- create persistent send request ------------------------
cl_send_request = cl_bcs=>create_persistent( ).
lv_title = text-005.
* -------- create and set document -------------------------------
APPEND text-006 TO li_text.
lv_length = STRLEN( text-006 ).
cl_document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = li_text
i_length = lv_length
i_subject = lv_title ).
LOOP AT it_files INTO wa_files.
REFRESH li_text.
CLEAR: lv_length, li_bin_cont, lv_texto.
OPEN DATASET wa_files-fullname FOR INPUT
IN TEXT MODE ENCODING NON-UNICODE.
DO.
READ DATASET wa_files-fullname INTO lv_texto_aux.
IF sy-subrc = 0.
IF lv_texto IS INITIAL.
CONCATENATE lv_texto_aux cl_bcs_convert=>gc_crlf INTO lv_texto.
ELSE.
CONCATENATE lv_texto lv_texto_aux cl_bcs_convert=>gc_crlf
INTO lv_texto.
ENDIF.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET wa_files-fullname.
TRY.
cl_bcs_convert=>string_to_solix(
EXPORTING
iv_string = lv_texto
iv_codepage = '4103' "suitable for MS Excel, leave empty
iv_add_bom = 'X' "for other doc types
IMPORTING
et_solix = li_bin_cont
ev_size = lv_length ).
CATCH cx_bcs.
MESSAGE e445(so).
ENDTRY.
lv_title = wa_files-filename.
CALL METHOD cl_document->add_attachment
EXPORTING
i_attachment_type = 'CSV'
i_attachment_subject = lv_title
i_attachment_size = lv_length
i_att_content_hex = li_bin_cont.
ENDLOOP.
CALL METHOD cl_send_request->set_document( cl_document ).
* --------- set sender -------------------------------------------
* note: this is necessary only if you want to set the sender
* different from actual user (SY-UNAME). Otherwise sender is
* set automatically with actual user.
cl_sender = cl_sapuser_bcs=>create( sy-uname ).
CALL METHOD cl_send_request->set_sender
EXPORTING
i_sender = cl_sender.
* --------- add recipient (e-mail address) -----------------------
* create recipient - please replace e-mail address !!!
DATA: lv_email TYPE ad_smtpadr.
LOOP AT s_email.
lv_email = s_email-low.
cl_recipient = cl_cam_address_bcs=>create_internet_address(
lv_email ).
* add recipient with its respective attributes to send request
CALL METHOD cl_send_request->add_recipient
EXPORTING
i_recipient = cl_recipient
i_express = 'X'.
ENDLOOP.
cl_send_request->send_request->set_link_to_outbox( 'X' ).
* ---------- send document ---------------------------------------
CALL METHOD cl_send_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = lv_sent_to_all ).
IF lv_sent_to_all = 'X'.
WRITE text-009.
"Elimino arquivo do diretório se foi enviado corretamente
DELETE DATASET wa_files-fullname.
ENDIF.
COMMIT WORK.
* -----------------------------------------------------------
* * exception handling
* -----------------------------------------------------------
* * replace this very rudimentary exception handling
* * with your own one !!!
* -----------------------------------------------------------
CATCH cx_bcs INTO cl_bcs_exception.
WRITE: text-007.
WRITE: text-008, cl_bcs_exception->error_type.
EXIT.
ENDTRY.
ENDFORM. " ENVIA_EMAIL
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ENVIADO PDF POR SMARTFORMS
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
DATA: lw_output_info TYPE ssfcrescl.
DATA: lw_output_options TYPE ssfcompop,
lw_control_parameters TYPE ssfctrlop.
lw_control_parameters = VALUE #(
"DEVICE = 'LOCL'
no_dialog = abap_true
preview = abap_false
GETOTF = ABAP_TRUE
"LANGU
).
lw_output_options = VALUE #( tddest = 'LOCL' ).
BREAK-POINT.
CALL FUNCTION '/1BCDWB/SF00000019'
EXPORTING
* ARCHIVE_INDEX =
* ARCHIVE_INDEX_TAB =
* ARCHIVE_PARAMETERS =
control_parameters = lw_control_parameters
* MAIL_APPL_OBJ =
* MAIL_RECIPIENT =
* MAIL_SENDER =
output_options = lw_output_options
user_settings = ''
it_romaneio = lt_romaneio_print
iw_info_transp = ztbsd_roma03
I_TIPO_IMP = '1'
IMPORTING
* DOCUMENT_OUTPUT_INFO =
job_output_info = lw_output_info
* JOB_OUTPUT_OPTIONS =
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF sy-subrc <> 0.
EXIT.
* Implement suitable error handling here
ENDIF.
BREAK-POINT.
CHECK lw_output_info-otfdata IS NOT INITIAL.
DATA: lt_lines TYPE TABLE OF tline.
DATA: lv_bin_filesize TYPE so_obj_len,
lv_bin_file TYPE xstring.
DATA: lt_text TYPE bcsy_text,
lt_bin_cont TYPE solix_tab.
DATA: lv_sent_to_all TYPE os_boolean,
lv_filename TYPE string,
lv_texto TYPE string,
lv_texto_aux TYPE string,
lv_length TYPE sood-objlen,
lv_size TYPE so_obj_len,
lv_title TYPE sood-objdes.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
IMPORTING
bin_filesize = lv_bin_filesize
bin_file = lv_bin_file
TABLES
otf = lw_output_info-otfdata
lines = lt_lines
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 4
OTHERS = 5.
DATA: lt_binary_content TYPE solix_tab.
***Xstring to binary
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_bin_file
TABLES
binary_tab = lt_binary_content.
* CHECK p_email = 'X'.
TRY.
* -------- create persistent send request ------------------------
DATA(lo_send_request) = cl_bcs=>create_persistent( ).
lv_title = TEXT-005.
* -------- create and set document -------------------------------
APPEND 'teste' TO lt_text.
lv_length = strlen( |teste| ).
DATA(lo_document) = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = lt_text
i_length = lv_length
i_subject = lv_title ).
TRY.
cl_bcs_convert=>string_to_solix(
EXPORTING
iv_string = lv_texto
iv_codepage = '4103' "suitable for MS Excel, leave empty
iv_add_bom = 'X' "for other doc types
IMPORTING
et_solix = lt_bin_cont
ev_size = lv_length ).
CATCH cx_bcs.
MESSAGE e445(so).
ENDTRY.
lv_title = 'teste'.
CALL METHOD lo_document->add_attachment
EXPORTING
i_attachment_type = 'PDF'
i_attachment_subject = lv_title
i_attachment_size = lv_bin_filesize
i_att_content_hex = lt_binary_content.
CALL METHOD lo_send_request->set_document( lo_document ).
* --------- set sender -------------------------------------------
* note: this is necessary only if you want to set the sender
* different from actual user (SY-UNAME). Otherwise sender is
* set automatically with actual user.
DATA(lo_sender) = cl_sapuser_bcs=>create( sy-uname ).
CALL METHOD lo_send_request->set_sender
EXPORTING
i_sender = lo_sender.
* --------- add recipient (e-mail address) -----------------------
* create recipient - please replace e-mail address !!!
DATA: lv_email TYPE ad_smtpadr.
lv_email = 'ednszk@hotmail.com'.
DATA(lo_recipient) = cl_cam_address_bcs=>create_internet_address(
lv_email ).
* add recipient with its respective attributes to send request
CALL METHOD lo_send_request->add_recipient
EXPORTING
i_recipient = lo_recipient
i_express = 'X'.
lo_send_request->send_request->set_link_to_outbox( 'X' ).
* ---------- send document ---------------------------------------
CALL METHOD lo_send_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = lv_sent_to_all ).
IF lv_sent_to_all = 'X'.
WRITE TEXT-009.
ENDIF.
COMMIT WORK.
* -----------------------------------------------------------
* * exception handling
* -----------------------------------------------------------
* * replace this very rudimentary exception handling
* * with your own one !!!
* -----------------------------------------------------------
CATCH cx_bcs INTO DATA(lo_bcs_exception).
* WRITE: TEXT-007.
* WRITE: TEXT-008, lo_bcs_exception->error_type.
EXIT.
ENDTRY.
DATA: lw_output_options TYPE ssfcompop,
lw_control_parameters TYPE ssfctrlop.
lw_control_parameters = VALUE #(
"DEVICE = 'LOCL'
no_dialog = abap_true
preview = abap_false
GETOTF = ABAP_TRUE
"LANGU
).
lw_output_options = VALUE #( tddest = 'LOCL' ).
BREAK-POINT.
CALL FUNCTION '/1BCDWB/SF00000019'
EXPORTING
* ARCHIVE_INDEX =
* ARCHIVE_INDEX_TAB =
* ARCHIVE_PARAMETERS =
control_parameters = lw_control_parameters
* MAIL_APPL_OBJ =
* MAIL_RECIPIENT =
* MAIL_SENDER =
output_options = lw_output_options
user_settings = ''
it_romaneio = lt_romaneio_print
iw_info_transp = ztbsd_roma03
I_TIPO_IMP = '1'
IMPORTING
* DOCUMENT_OUTPUT_INFO =
job_output_info = lw_output_info
* JOB_OUTPUT_OPTIONS =
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF sy-subrc <> 0.
EXIT.
* Implement suitable error handling here
ENDIF.
BREAK-POINT.
CHECK lw_output_info-otfdata IS NOT INITIAL.
DATA: lt_lines TYPE TABLE OF tline.
DATA: lv_bin_filesize TYPE so_obj_len,
lv_bin_file TYPE xstring.
DATA: lt_text TYPE bcsy_text,
lt_bin_cont TYPE solix_tab.
DATA: lv_sent_to_all TYPE os_boolean,
lv_filename TYPE string,
lv_texto TYPE string,
lv_texto_aux TYPE string,
lv_length TYPE sood-objlen,
lv_size TYPE so_obj_len,
lv_title TYPE sood-objdes.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
IMPORTING
bin_filesize = lv_bin_filesize
bin_file = lv_bin_file
TABLES
otf = lw_output_info-otfdata
lines = lt_lines
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 4
OTHERS = 5.
DATA: lt_binary_content TYPE solix_tab.
***Xstring to binary
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_bin_file
TABLES
binary_tab = lt_binary_content.
* CHECK p_email = 'X'.
TRY.
* -------- create persistent send request ------------------------
DATA(lo_send_request) = cl_bcs=>create_persistent( ).
lv_title = TEXT-005.
* -------- create and set document -------------------------------
APPEND 'teste' TO lt_text.
lv_length = strlen( |teste| ).
DATA(lo_document) = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = lt_text
i_length = lv_length
i_subject = lv_title ).
TRY.
cl_bcs_convert=>string_to_solix(
EXPORTING
iv_string = lv_texto
iv_codepage = '4103' "suitable for MS Excel, leave empty
iv_add_bom = 'X' "for other doc types
IMPORTING
et_solix = lt_bin_cont
ev_size = lv_length ).
CATCH cx_bcs.
MESSAGE e445(so).
ENDTRY.
lv_title = 'teste'.
CALL METHOD lo_document->add_attachment
EXPORTING
i_attachment_type = 'PDF'
i_attachment_subject = lv_title
i_attachment_size = lv_bin_filesize
i_att_content_hex = lt_binary_content.
CALL METHOD lo_send_request->set_document( lo_document ).
* --------- set sender -------------------------------------------
* note: this is necessary only if you want to set the sender
* different from actual user (SY-UNAME). Otherwise sender is
* set automatically with actual user.
DATA(lo_sender) = cl_sapuser_bcs=>create( sy-uname ).
CALL METHOD lo_send_request->set_sender
EXPORTING
i_sender = lo_sender.
* --------- add recipient (e-mail address) -----------------------
* create recipient - please replace e-mail address !!!
DATA: lv_email TYPE ad_smtpadr.
lv_email = 'ednszk@hotmail.com'.
DATA(lo_recipient) = cl_cam_address_bcs=>create_internet_address(
lv_email ).
* add recipient with its respective attributes to send request
CALL METHOD lo_send_request->add_recipient
EXPORTING
i_recipient = lo_recipient
i_express = 'X'.
lo_send_request->send_request->set_link_to_outbox( 'X' ).
* ---------- send document ---------------------------------------
CALL METHOD lo_send_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = lv_sent_to_all ).
IF lv_sent_to_all = 'X'.
WRITE TEXT-009.
ENDIF.
COMMIT WORK.
* -----------------------------------------------------------
* * exception handling
* -----------------------------------------------------------
* * replace this very rudimentary exception handling
* * with your own one !!!
* -----------------------------------------------------------
CATCH cx_bcs INTO DATA(lo_bcs_exception).
* WRITE: TEXT-007.
* WRITE: TEXT-008, lo_bcs_exception->error_type.
EXIT.
ENDTRY.
Nenhum comentário:
Postar um comentário