FUNCTION zf_send_email.
*"----------------------------------------------------------------------
*"*"Interface local:
*" IMPORTING
*" VALUE(IM_SPOOL) TYPE RSPOID OPTIONAL
*" VALUE(IM_EMAIL) TYPE AD_SMTPADR OPTIONAL
*"----------------------------------------------------------------------
* Bom dia Abapers, conforme prometido hoje vou mostrar uma função prática
* que envia o Spool em anexo para o email informado, os parametros de
* importação estão informadas acima, qualquer dúvida comentem e vamos
* aprendendo juntos, coloquei alguns Breaks no código para visualizarem
* o processo.
* A transação para saber o Spool é a SP01 / SP02.
DATA :
lt_lines TYPE TABLE OF tline,
lst_lines LIKE LINE OF lt_lines,
l_rspoid TYPE rspoid,
lst_tsp01 TYPE tsp01,
l_objtype TYPE rststype-type,
l_pdf_bytecount TYPE i,
l_pdf_spoolid TYPE tsp01-rqident,
l_btc_jobname TYPE tbtcjob-jobname,
l_btc_jobcount TYPE tbtcjob-jobcount,
l_xstring TYPE xstring,
lt_soli_tab TYPE TABLE OF soli, " soli_tab
lt_solix_tab TYPE TABLE OF solix, " solix_tab,
l_size TYPE sood-objlen,
lt_text TYPE TABLE OF solisti1,
lst_text LIKE LINE OF lt_text,
li_emails TYPE TABLE OF ad_smtpadr,
lst_email TYPE ad_smtpadr,
l_subject TYPE so_obj_des
.
DATA :
lo_document TYPE REF TO cl_document_bcs,
lo_bcs TYPE REF TO cl_bcs,
lo_recipient TYPE REF TO if_recipient_bcs,
lo_ex_bcs TYPE REF TO cx_bcs.
BREAK-POINT.
* Seleção para get dos detalhes do Spool Informado.
SELECT SINGLE * FROM tsp01 INTO lst_tsp01 WHERE rqident = im_spool.
IF sy-subrc IS INITIAL.
* Função para get dos atributos do Spool,
CALL FUNCTION 'RSTS_GET_ATTRIBUTES'
EXPORTING
* AUTHORITY = ' '
client = lst_tsp01-rqclient
name = lst_tsp01-rqo1name
IMPORTING
objtype = l_objtype
EXCEPTIONS
fb_error = 1
fb_rsts_other = 2
no_object = 3
no_permission = 4
OTHERS = 5.
IF sy-subrc IS INITIAL.
* Inicio - Conversão SPOOL -> PDF
IF l_objtype(3) = 'OTF'.
CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = lst_tsp01-rqident
no_dialog = space
IMPORTING
pdf_bytecount = l_pdf_bytecount
pdf_spoolid = l_pdf_spoolid
btc_jobname = l_btc_jobname
btc_jobcount = l_btc_jobcount
TABLES
pdf = lt_lines[]
EXCEPTIONS
err_no_otf_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_dstdevice = 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.
ELSE.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = lst_tsp01-rqident
no_dialog = space
IMPORTING
pdf_bytecount = l_pdf_bytecount
pdf_spoolid = l_pdf_spoolid
btc_jobname = l_btc_jobname
btc_jobcount = l_btc_jobcount
TABLES
pdf = lt_lines[]
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.
ENDIF.
*"----------------------------------------------------------------------
*"*"Interface local:
*" IMPORTING
*" VALUE(IM_SPOOL) TYPE RSPOID OPTIONAL
*" VALUE(IM_EMAIL) TYPE AD_SMTPADR OPTIONAL
*"----------------------------------------------------------------------
* Bom dia Abapers, conforme prometido hoje vou mostrar uma função prática
* que envia o Spool em anexo para o email informado, os parametros de
* importação estão informadas acima, qualquer dúvida comentem e vamos
* aprendendo juntos, coloquei alguns Breaks no código para visualizarem
* o processo.
* A transação para saber o Spool é a SP01 / SP02.
DATA :
lt_lines TYPE TABLE OF tline,
lst_lines LIKE LINE OF lt_lines,
l_rspoid TYPE rspoid,
lst_tsp01 TYPE tsp01,
l_objtype TYPE rststype-type,
l_pdf_bytecount TYPE i,
l_pdf_spoolid TYPE tsp01-rqident,
l_btc_jobname TYPE tbtcjob-jobname,
l_btc_jobcount TYPE tbtcjob-jobcount,
l_xstring TYPE xstring,
lt_soli_tab TYPE TABLE OF soli, " soli_tab
lt_solix_tab TYPE TABLE OF solix, " solix_tab,
l_size TYPE sood-objlen,
lt_text TYPE TABLE OF solisti1,
lst_text LIKE LINE OF lt_text,
li_emails TYPE TABLE OF ad_smtpadr,
lst_email TYPE ad_smtpadr,
l_subject TYPE so_obj_des
.
DATA :
lo_document TYPE REF TO cl_document_bcs,
lo_bcs TYPE REF TO cl_bcs,
lo_recipient TYPE REF TO if_recipient_bcs,
lo_ex_bcs TYPE REF TO cx_bcs.
BREAK-POINT.
* Seleção para get dos detalhes do Spool Informado.
SELECT SINGLE * FROM tsp01 INTO lst_tsp01 WHERE rqident = im_spool.
IF sy-subrc IS INITIAL.
* Função para get dos atributos do Spool,
CALL FUNCTION 'RSTS_GET_ATTRIBUTES'
EXPORTING
* AUTHORITY = ' '
client = lst_tsp01-rqclient
name = lst_tsp01-rqo1name
IMPORTING
objtype = l_objtype
EXCEPTIONS
fb_error = 1
fb_rsts_other = 2
no_object = 3
no_permission = 4
OTHERS = 5.
IF sy-subrc IS INITIAL.
* Inicio - Conversão SPOOL -> PDF
IF l_objtype(3) = 'OTF'.
CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = lst_tsp01-rqident
no_dialog = space
IMPORTING
pdf_bytecount = l_pdf_bytecount
pdf_spoolid = l_pdf_spoolid
btc_jobname = l_btc_jobname
btc_jobcount = l_btc_jobcount
TABLES
pdf = lt_lines[]
EXCEPTIONS
err_no_otf_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_dstdevice = 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.
ELSE.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = lst_tsp01-rqident
no_dialog = space
IMPORTING
pdf_bytecount = l_pdf_bytecount
pdf_spoolid = l_pdf_spoolid
btc_jobname = l_btc_jobname
btc_jobcount = l_btc_jobcount
TABLES
pdf = lt_lines[]
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.
ENDIF.