You are on page 1of 6

Cdigo abap/4

WEB: http://codigoabap4.wordpress.com/2011/04/25/mandar-un-email-por-sap-adjunta
ndo-un-adobe-form-pdf/
Un lugar donde la imaginacin de todos los abapers es posible
Inicio
Funciones
Adobe Form
Query
Reports
ALV
Tablas
Transacciones tiles
Web Dynpro
Inicio > Reports
> Mandar un email por sap adjuntando un adobe form (PDF
)
Mandar un email por sap adjuntando un adobe form (PDF)
25 abril, 2011 Santi
Deja un comentario Ir a los comentarios
Programa que lanza la ejecucin de un adobe form y su resultado lo adjunta en un p
df para enviarlo por correo
El programa a partir del nmero de un empleado, lanza la ejecucin del adobe form ZE
NVIO_MAIL para recuperar sus datos de liquidacin. Una vez obtenidos lo adjuntamos
en un correo y lo enviamos a un buzn genrico.
Para luego ver lo que nos ha lanzado nos vamos a la transaccin SOST
El cdigo del programa es el siguiente:
REPORT Zmail_pdf.
tables: pa0001.
data:
l_fm_name
l_formname
fp_docparams
FP_FORMOUTPUT
fp_outputparams
data:
t_att_content_hex

TYPE
TYPE
TYPE
TYPE
TYPE

rs38l_fnam,
fpname VALUE ZENVIO_MAIL
sfpdocparams,
FPFORMOUTPUT,
sfpoutputparams.

Nombre de mi Adobe FORM,

type SOLIX_TAB.

parameters: p_pernr like pa0001-pernr.


START-OF-SELECTION.
* Recuperamos el nombre del adobe form y lo ejecutamos
PERFORM get_function_module.
* Recuperamos el nombre del adobe form y lo ejecutamos
PERFORM convert_pdf_binary.
PERFORM mail_attachment.
*&
*
*&
Form GET_FUNCTION_MODULE
*&
FORM GET_FUNCTION_MODULE .

data: nombre_justif type pa0001-ename,


d_text_pernr(100),
d_bukrs type bukrs,
d_name_bukrs type butxt.
CALL FUNCTION FP_FUNCTION_MODULE_NAME
EXPORTING
i_name
= l_formname
IMPORTING
e_funcname = l_fm_name.
fp_outputparams-nodialog = X .
fp_outputparams-getpdf = X .
CALL FUNCTION FP_JOB_OPEN
CHANGING
ie_outputparams = fp_outputparams
EXCEPTIONS
cancel
= 1
usage_error
= 2
system_error
= 3
internal_error = 4
OTHERS
= 5.
IF sy-subrc <> 0.
CASE sy-subrc.
WHEN OTHERS.
ENDCASE.
ENDIF.
fp_docparams-langu = sy-langu.
fp_docparams-country = ES .

CASE sy-subrc

clear: d_text_pernr.
select single ename bukrs
from pa0001
into (nombre_justif, d_bukrs)
where pernr eq p_pernr.
select single butxt from T001 into d_name_bukrs
where BUKRS = d_bukrs.
concatenate text-001 p_pernr nombre_justif into d_text_pernr SEPARATED BY space.
CALL FUNCTION l_fm_name
EXPORTING
/1bcdwb/docparams = fp_docparams
empleado_txt
= d_text_pernr
sociedad_t
= d_name_bukrs
empleado
= p_pernr
sociedad
= d_bukrs
IMPORTING
/1BCDWB/FORMOUTPUT = FP_FORMOUTPUT
EXCEPTIONS
usage_error
= 1
system_error
= 2
internal_error
= 3
OTHERS
= 4.
IF sy-subrc <> 0.
CASE sy-subrc.
WHEN OTHERS.
ENDCASE.

CASE sy-subrc

ENDIF.
IF sy-subrc <> 0
CALL FUNCTION FP_JOB_CLOSE
* IMPORTING
*
E_RESULT
= result
EXCEPTIONS
usage_error
= 1
system_error
= 2
internal_error
= 3
OTHERS
= 4
.
IF sy-subrc <> 0.
CASE sy-subrc.
WHEN OTHERS.
ENDCASE.
CASE sy-subrc
ENDIF.
IF sy-subrc <> 0.
ENDFORM.
GET_FUNCTION_MODULE
*&
*
*&
Form CONVERT_PDF_BINARY
*&
FORM CONVERT_PDF_BINARY .
CALL FUNCTION SCMS_XSTRING_TO_BINARY
EXPORTING
BUFFER
= FP_FORMOUTPUT-pdf
* APPEND_TO_TABLE
=
* IMPORTING
* OUTPUT_LENGTH
=
TABLES
BINARY_TAB
= t_att_content_hex .
ENDFORM.
CONVERT_PDF_BINARY
*&
*
*&
Form MAIL_ATTACHMENT
*&
FORM MAIL_ATTACHMENT .
CLASS cl_bcs DEFINITION LOAD.
DATA:
lo_send_request TYPE REF TO cl_bcs VALUE IS INITIAL.
lo_send_request = cl_bcs=>create_persistent( ).
* Message body and subject
DATA:
lt_message_body TYPE bcsy_text VALUE IS INITIAL,
lo_document TYPE REF TO cl_document_bcs VALUE IS INITIAL.
APPEND Dear, TO lt_message_body.
append
to lt_message_body.
APPEND Please fill the attached form and send it back to us.
TO lt_message_body.
append
to lt_message_body.
APPEND Thank You, TO lt_message_body.
lo_document = cl_document_bcs=>create_document(
i_type = RAW
i_text = lt_message_body
i_subject = Personnel Information Form ).
DATA: lx_document_bcs TYPE REF TO cx_document_bcs VALUE IS INITIAL.
TRY.
lo_document->add_attachment(
EXPORTING
i_attachment_type = PDF
i_attachment_subject = Personnel Information Form
* I_ATTACHMENT_SIZE =
* I_ATTACHMENT_LANGUAGE = SPACE
* I_ATT_CONTENT_TEXT =

* I_ATTACHMENT_HEADER =
i_att_content_hex = t_att_content_hex ).
CATCH cx_document_bcs INTO lx_document_bcs.
ENDTRY.
* Add attachment
* Pass the document to send request
lo_send_request->set_document( lo_document ).
* Create sender
DATA:
lo_sender TYPE REF TO if_sender_bcs VALUE IS INITIAL,
l_send type ADR6-SMTP_ADDR value mail_sender@prueba.es ,
l_dest type ADR6-SMTP_ADDR value mail_destino@prueba.es .
lo_sender = cl_cam_address_bcs=>create_internet_address( l_send ).
* lo_sender = cl_sapuser_bcs=>create( sy-uname ).
* Set sender
lo_send_request->set_sender(
EXPORTING
i_sender = lo_sender ).
* Create recipient
DATA:
lo_recipient TYPE REF TO if_recipient_bcs VALUE IS INITIAL.
* lo_recipient = cl_sapuser_bcs=>create( sy-uname ).
lo_recipient = cl_cam_address_bcs=>create_internet_address( l_dest ).
** Set recipient
lo_send_request->add_recipient(
EXPORTING
i_recipient = lo_recipient
i_express = X ).
* lo_send_request->add_recipient(
* EXPORTING
* i_recipient = lo_recipient
* i_express = X' ).
* Send email
DATA: lv_sent_to_all(1) TYPE c VALUE IS INITIAL.
lo_send_request->send(
EXPORTING
i_with_error_screen = X
RECEIVING
result = lv_sent_to_all ).
COMMIT WORK.
ENDFORM.
MAIL_ATTACHMENT
Share this:
Share
Like this:
Like
Be the first to like this post.
Categoras:Reports Etiquetas: adobe form, attachment, mail, pdf
Comentarios (0) Trackbacks (0) Deja un comentario Trackback
An no hay comentarios.
An no hay trackbacks
Deja una respuesta
Enter your comment here...
Guest
Acceder
Acceder
Acceder

Correo electrnico (Not published)


Nombre
Web
Please log in to WordPress.com to post a comment to your blog.

You are commenting using your Twitter account. ( Log Out )


You are commenting using your Facebook account. ( Log Out )
Cancelar
Connecting to %s
Recibir siguientes comentarios por correo.
Recibir nuevas entradas por email.

Programa de generacin y ejecucin de programas a partir de ficheros locales Upload/


Download de tablas
RSS feed
Google
Youdao
Xian Guo
Zhua Xia
My Yahoo!
NewsGator
Bloglines
iNezha
Translate

Buscar por:
Categoras
Funciones (4)
Adobe Form (2)
Query (1)
Reports (8)
ALV (2)
Tablas (1)
Transacciones tiles (1)
Web Dynpro (1)
About me
Santiago Hoyas
Enlaces en espaol
Abap y Sap
Abap.es
Blogdefloren
MundoSap

Programacin abap
Recursos y tutoriales en castellano
TodoSap
Enlaces en ingls
Sapdocs
SapLab
Social Sapdocs
Linkedin
Mapa de visitantes
Estadsticas personales

Etiquetas
abapdocu abap zip adobe adobe form alv asignar transaccin attachment autorizacin b
adi's bte buscador user-exits chequeos cl_salv_table create zip descarga de tabl
as documentacin abap ejecucin dinamica factory funciones funcin funcin alv gene impo
rte bruto importe neto mail pdf programas dinamicos punto de ampliacin query rela
cin entre tablas saltar autorizacin sap sap table relationship tablas transaccin ab
ap transaccin para query upload/download Webdynpro Webdynpro performance zip
Arriba WordPress
Copyright 2011 Cdigo abap/4
Blog de WordPress.com. Theme: INove by NeoEase.
Follow
Follow Cdigo abap/4
Get every new post delivered to your Inbox.

Powered by WordPress.com

You might also like