Formularios y Mails
Webinar
CÓDIGO FUENTE
Formularios y Mails
Webinar
1
Formularios y Mails
Webinar
Contenido
1. Diccionario de Datos – Creación de Objetos ....................................................................... 3
2. Formulario Smartform – Configuración Global ................................................................... 4
3. Formulario Smartform – Logo .............................................................................................. 5
4. Formulario Smartform – Header .......................................................................................... 8
5. Formulario Smartform - Tabla Registros ............................................................................. 9
6. Código QR - Creación .......................................................................................................... 12
7. Formulario Smartform - Creación Estilos ........................................................................... 14
8. Formulario Smartform - Footer .......................................................................................... 16
9. Plantilla email - SAP Standard Text .................................................................................... 19
10. Implementación de clase ABAP. .................................................................................... 20
11. Ampliación Código Estándar .......................................................................................... 27
12. Test email ........................................................................................................................ 28
2
Formularios y Mails
Webinar
1. Diccionario de Datos – Creación de Objetos
Estructura
Tipo Tabla
3
Formularios y Mails
Webinar
2. Formulario Smartform – Configuración Global
Transacción SMARTFORMS
4
Formularios y Mails
Webinar
3. Formulario Smartform – Logo
Transacción SE78
5
Formularios y Mails
Webinar
6
Formularios y Mails
Webinar
7
Formularios y Mails
Webinar
4. Formulario Smartform – Header
8
Formularios y Mails
Webinar
5. Formulario Smartform - Tabla Registros
Header
Item | Product | Plant | Region | Quantity | Unit
9
Formularios y Mails
Webinar
10
Formularios y Mails
Webinar
11
Formularios y Mails
Webinar
6. Código QR - Creación
Transacción SE73
12
Formularios y Mails
Webinar
13
Formularios y Mails
Webinar
7. Formulario Smartform - Creación Estilos
Transacción - SMARTFORMS
14
Formularios y Mails
Webinar
15
Formularios y Mails
Webinar
8. Formulario Smartform - Footer
16
Formularios y Mails
Webinar
17
Formularios y Mails
Webinar
18
Formularios y Mails
Webinar
9. Plantilla email - SAP Standard Text
Transacción SO10 - Standard Text
19
Formularios y Mails
Webinar
10. Implementación de clase ABAP.
CLASS zftf_sales_order DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
TYPES ty_komp TYPE TABLE OF komp.
METHODS send_mail_customer IMPORTING iv_vbeln TYPE vbeln
iv_kunnr TYPE kunnr
it_komp TYPE ty_komp.
PROTECTED SECTION.
PRIVATE SECTION.
* Customer
DATA : mv_email TYPE adr6-smtp_addr,
mv_name TYPE name1_gp.
* Smartform
CONSTANTS :
gc_format TYPE so_obj_tp VALUE 'PDF',
gc_formname TYPE tdsfname VALUE 'ZTFORDERS'.
* PDF
DATA: mv_pdf_content TYPE solix_tab,
mv_pdf_size TYPE so_obj_len.
* Sales Document
DATA : mv_vbeln TYPE vbeln,
mv_kunnr TYPE kunnr,
mt_items TYPE ztft_orders.
METHODS: get_customer_data IMPORTING iv_kunnr TYPE kunnr,
create_pdf,
send_mail.
ENDCLASS.
CLASS ZFTF_SALES_ORDER IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------
------------------------------+
* | Instance Private Method ZFTF_SALES_ORDER->CREATE_PDF
* +-------------------------------------------------------------------
------------------------------+
* +-------------------------------------------------------------------
-------------------</SIGNATURE>
METHOD create_pdf.
20
Formularios y Mails
Webinar
DATA : lt_job_output_info TYPE ssfcrescl,
lv_fm_name TYPE rs38l_fnam,
lv_size TYPE i,
lt_lines TYPE TABLE OF tline.
* Getting Function Module name based on the Smartform name
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = gc_formname " Form name
IMPORTING
fm_name = lv_fm_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
"Disabled Dialog and get OTF of SMARTFORM
DATA(ls_control_parameters) = VALUE ssfctrlop( no_dialog = abap_tr
ue
preview = space
getotf = abap_tr
ue ).
"Disabled preview SMARTFORM
DATA(ls_output_options) = VALUE ssfcompop( tdnoprev = abap_true ).
"Text into QR Code
* DATA(lv_qr) = |{ mv_vbeln }|.
DATA lv_qr TYPE string.
SELECT SINGLE FROM zqrcode
FIELDS qr_code
WHERE qr_id EQ 'ORD'
INTO @lv_qr.
* Generating the Smartform
CALL FUNCTION lv_fm_name
EXPORTING
control_parameters = ls_control_parameters
output_options = ls_output_options
iv_doc_number = mv_vbeln
iv_cust_id = mv_kunnr
iv_qrcode = lv_qr
IMPORTING
job_output_info = lt_job_output_info
TABLES
it_items = mt_items
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
21
Formularios y Mails
Webinar
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* Convert OTF to PDF XString
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = gc_format
IMPORTING
bin_filesize = lv_size
TABLES
otf = lt_job_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.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
"PDF
FIELD-SYMBOLS <l_xline> TYPE x.
LOOP AT lt_lines INTO DATA(ls_lines).
ASSIGN ls_lines TO <l_xline> CASTING.
CONCATENATE pdf_xstring <l_xline> INTO DATA(pdf_xstring) IN BYTE
MODE.
ENDLOOP.
* PDF XString to Solix
* Wrapper Class for Office Documents - BCS Business Communication Serv
ice
mv_pdf_size = xstrlen( pdf_xstring ).
mv_pdf_content = cl_document_bcs=>xstring_to_solix( ip_xstring = p
df_xstring ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------
------------------------------+
* | Instance Private Method ZFTF_SALES_ORDER->GET_CUSTOMER_DATA
* +-------------------------------------------------------------------
------------------------------+
* | [--->] IV_KUNNR TYPE KUNNR
* +-------------------------------------------------------------------
-------------------</SIGNATURE>
METHOD get_customer_data.
SELECT SINGLE FROM kna1 AS kn
JOIN adr6 AS ad
22
Formularios y Mails
Webinar
ON kn~adrnr = ad~addrnumber
FIELDS name1, smtp_addr
WHERE kn~kunnr = @iv_kunnr
INTO (@mv_name, @mv_email).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------
------------------------------+
* | Instance Private Method ZFTF_SALES_ORDER->SEND_MAIL
* +-------------------------------------------------------------------
------------------------------+
* +-------------------------------------------------------------------
-------------------</SIGNATURE>
METHOD send_mail.
CONSTANTS : lc_htm TYPE char03 VALUE 'HTM'.
DATA : lv_id TYPE tdid VALUE 'ST',
lv_name TYPE tdobname VALUE 'ZTFTMAIL',
lv_object TYPE tdobject VALUE 'TEXT',
lv_subject TYPE so_obj_des,
lv_att_title TYPE so_obj_des.
DATA : lt_lines TYPE TABLE OF tline,
ls_header TYPE thead.
lv_subject = |New Sales Document { mv_vbeln } created|.
"Read email template
CALL FUNCTION 'READ_TEXT'
EXPORTING
client = sy-mandt
id = lv_id
language = sy-langu
name = lv_name
object = lv_object
IMPORTING
header = ls_header
TABLES
lines = lt_lines
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
23
Formularios y Mails
Webinar
*****Replacing variables in template*******
"Initialize the text symbols
CALL FUNCTION 'INIT_TEXTSYMBOL'.
"Set dynamic text symbol
CALL FUNCTION 'SET_TEXTSYMBOL'
EXPORTING
name = '&TEXT_NAME&'
value = mv_name
replace = abap_true.
CALL FUNCTION 'SET_TEXTSYMBOL'
EXPORTING
name = '&TEXT_ORDER&'
value = mv_vbeln
replace = abap_true.
* DESCRIBE TABLE lt_lines LINES DATA(lv_count).
DATA(lv_count) = lines( lt_lines ).
"Replace text symbol in the long text
CALL FUNCTION 'REPLACE_TEXTSYMBOL'
EXPORTING
endline = lv_count
startline = 1
TABLES
lines = lt_lines.
********************************************
* Convert Text to HTML - Email BODY
DATA :
lt_html_text TYPE TABLE OF htmlline,
lt_body_email TYPE soli_tab.
CALL FUNCTION 'CONVERT_ITF_TO_HTML'
EXPORTING
i_header = ls_header
i_title = 'Título'
TABLES
t_itf_text = lt_lines
t_html_text = lt_html_text
EXCEPTIONS
syntax_check = 1
replace = 2
illegal_header = 3
OTHERS = 4.
lt_body_email[] = lt_html_text[].
"Create send request
TRY.
*************Email Subject and Body************************
DATA(lo_send_request) = cl_bcs=>create_persistent( ).
24
Formularios y Mails
Webinar
"Add sender to send request
lo_send_request-
>set_sender( i_sender = cl_sapuser_bcs=>create( sy-
uname ) ). "Email FROM.
"Add recipient to send request
lo_send_request-
>add_recipient( i_recipient = cl_cam_address_bcs=>create_internet_addr
ess( mv_email ) "Email to.
i_express = abap_true ).
"Email BODY
DATA(lo_document) = cl_document_bcs=>create_document( i_type
= lc_htm
i_text
= lt_body_email
i_subjec
t = lv_subject ).
**************Email Document Attached
lv_att_title = |{ mv_vbeln }-{ sy-datum }.pdf|.
lo_document-
>add_attachment( i_attachment_type = gc_format " Document C
lass for Attachment
i_attachment_subject = lv_att_tit
le " Attachment Title
i_att_content_hex = mv_pdf_con
tent ). " Content (Binary)
"Add document to send request
lo_send_request->set_document( lo_document ).
"Send email
lo_send_request->send(
EXPORTING
i_with_error_screen = abap_true
RECEIVING
result = DATA(lv_sent_to_all) ).
"Commit to send email
CHECK lv_sent_to_all = abap_true.
COMMIT WORK.
CATCH cx_bcs INTO DATA(lo_bcs_exception). "Exception handling
WRITE : |Type: { lo_bcs_exception-
>error_type } / Message { lo_bcs_exception->get_text( ) }|.
ENDTRY.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------
------------------------------+
25
Formularios y Mails
Webinar
* | Instance Public Method ZFTF_SALES_ORDER->SEND_MAIL_CUSTOMER
* +-------------------------------------------------------------------
------------------------------+
* | [--->] IV_VBELN TYPE VBELN
* | [--->] IV_KUNNR TYPE KUNNR
* | [--->] IT_KOMP TYPE TY_KOMP
* +-------------------------------------------------------------------
-------------------</SIGNATURE>
METHOD send_mail_customer.
mv_vbeln = iv_vbeln.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = mv_vbeln " Any ABAP field
IMPORTING
output = mv_vbeln. " External INPUT display, C field
mv_kunnr = iv_kunnr.
mt_items[] = CORRESPONDING #( it_komp[] ).
me->get_customer_data( iv_kunnr = iv_kunnr ).
me->create_pdf( ).
me->send_mail( ).
ENDMETHOD.
ENDCLASS.
26
Formularios y Mails
Webinar
11. Ampliación Código Estándar
En la transacción SE38 buscar el Include MV45AFZZ.
UserExit - USEREXIT_SAVE_DOCUMENT
27
Formularios y Mails
Webinar
12.Test email
Transacción SOST
28
Formularios y Mails
Webinar
29