Vous êtes sur la page 1sur 4

FORM z_print_spool_pdf .

DATA: l_spono LIKE tsp01-rqident,


t_pdf LIKE tline OCCURS 0 WITH HEADER LINE,
l_buff TYPE string.
l_spono = sy-spono.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = l_spono
no_dialog = space
TABLES
pdf = t_pdf
EXCEPTIONS
err_no_abap_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_destdevice = 5
user_cancelled = 6
err_spoolerror = 7
err_temseerror = 8
err_btcjob_open_failed = 9
err_btcjob_submit_failed = 10
err_btcjob_close_failed = 11
OTHERS = 12.
PERFORM z_delete_spool USING l_spono.
* Transfer the 132-long strings to 255-long strings
LOOP AT t_pdf.
TRANSLATE t_pdf USING ' ~'.
CONCATENATE l_buff t_pdf INTO l_buff.
ENDLOOP.
TRANSLATE l_buff USING '~ '.
DO.
t_msg_att = l_buff.
APPEND t_msg_att.
SHIFT l_buff LEFT BY 255 PLACES.
IF l_buff IS INITIAL.
EXIT.
ENDIF.
ENDDO.
ENDFORM. " Z_PRINT_SPOOL_PDF
*&---------------------------------------------------------------------*
*& Form Z_DELETE_SPOOL
*&---------------------------------------------------------------------*
FORM z_delete_spool USING p_spono.
DATA: l_spool_nr TYPE tsp01_sp0r-rqid_char.
l_spool_nr = p_spono.
CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'
EXPORTING
spoolid = l_spool_nr.
ENDFORM. "z_delete_spool
*&---------------------------------------------------------------------*
*& Form Z_SEND_PDF_EMAIL
*&---------------------------------------------------------------------*
FORM z_send_pdf_email .
DATA: l_recsize TYPE i,
l_subject LIKE sodocchgi1-obj_descr,
l_cnt TYPE i,
l_sent_all TYPE c LENGTH 1,
l_doc_data LIKE sodocchgi1.
DATA: t_pck_lst TYPE STANDARD TABLE OF sopcklsti1 WITH HEADER LINE,
t_receivr TYPE STANDARD TABLE OF somlreci1 WITH HEADER LINE,
t_msg_txt TYPE STANDARD TABLE OF solisti1 WITH HEADER LINE.
* Monta a mensagem do e-mail
DESCRIBE TABLE t_msg_att LINES l_recsize.
CHECK l_recsize > 0.
REFRESH t_msg_txt.
t_msg_txt = 'Prezados,'.
APPEND t_msg_txt.
CLEAR: t_msg_txt.
APPEND t_msg_txt.
t_msg_txt = 'Segue anexo a relao dos contratos a vencer nos prximos 90 dias.'.
APPEND t_msg_txt.
CLEAR: t_msg_txt.
APPEND t_msg_txt.
t_msg_txt = 'Sds,'.
APPEND t_msg_txt.
CLEAR: t_msg_txt.
APPEND t_msg_txt.
CLEAR: t_msg_txt.
APPEND t_msg_txt.
t_msg_txt = 'Esta uma mensagem automtica por favor no responda'.
APPEND t_msg_txt.
READ TABLE t_msg_att INDEX l_cnt.
CLEAR l_doc_data.
l_doc_data-doc_size = ( l_cnt - 1 ) * 255 + STRLEN( t_msg_att ).
l_doc_data-obj_langu = sy-langu.
l_doc_data-obj_name = 'SAPRPT'.
l_doc_data-obj_descr = 'Contratos a vencer em 90 dias'.
l_doc_data-sensitivty = 'F'.
* Descreve o corpo da mensagem
CLEAR t_pck_lst.
REFRESH t_pck_lst.
t_pck_lst-transf_bin = space.
t_pck_lst-head_start = 1.
t_pck_lst-head_num = 0.
t_pck_lst-body_start = 1.
DESCRIBE TABLE t_msg_txt LINES t_pck_lst-body_num.
t_pck_lst-doc_type = 'RAW'.
APPEND t_pck_lst.
* Cria os anexos
t_pck_lst-transf_bin = 'X'.
t_pck_lst-head_start = 1.
t_pck_lst-head_num = 1.
t_pck_lst-body_start = 1.
DESCRIBE TABLE t_msg_att LINES t_pck_lst-body_num.
t_pck_lst-doc_type = 'PDF'.
t_pck_lst-obj_descr = 'FILE'.
t_pck_lst-obj_name = 'FILE'.
t_pck_lst-doc_size = t_pck_lst-body_num * 255.
APPEND t_pck_lst.
* Adiciona os destinatrios
CLEAR t_receivr.
REFRESH t_receivr.
t_receivr-rec_type = 'U'.
t_receivr-com_type = 'INT'.
t_receivr-notif_del = 'X'.
t_receivr-notif_ndel = 'X'.
PERFORM f_search_address CHANGING t_receivr-receiver.
APPEND: t_receivr.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = l_doc_data
put_in_outbox = 'X'
commit_work = 'X'
IMPORTING
sent_to_all = l_sent_all
TABLES
packing_list = t_pck_lst
contents_bin = t_msg_att
contents_txt = t_msg_txt
receivers = t_receivr
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
IF sy-subrc IS INITIAL.
WAIT UP TO 2 SECONDS.
*-- Call the RSCONN01 (SAPconnect: Start Send Process)
SUBMIT rsconn01 WITH mode = 'INT'
* WITH output = 'X'
AND RETURN.
MESSAGE 'Email enviado com sucesso.' TYPE 'S'.
ELSE.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " Z_SEND_PDF_EMAIL
*

Vous aimerez peut-être aussi