on 08-20-2009 9:16 AM
Hi everybody i'm trying to attach a smartform as a pdf file in a mail, but when i try to open the file it says that the file is corrupted.
Here is the code. Any ideas? Thanks
DATA: lv_name TYPE rs38l_fnam,
lv_tipcom TYPE char40,
lv_numbytes(100) TYPE i.
DATA: lw_control_parameters TYPE ssfctrlop,
lw_output_options TYPE ssfcompop,
lw_job_output_info TYPE ssfcrescl,
lw_document_output_info TYPE ssfcrespd,
lw_job_output_options TYPE ssfcresop.
DATA: li_otfdata TYPE tsfotf,
li_otf TYPE STANDARD TABLE OF itcoo,
li_doctab TYPE STANDARD TABLE OF docs,
li_pdf TYPE STANDARD TABLE OF tline,
li_ymm_mm03_0003 TYPE STANDARD TABLE OF ymm_mm03_0003.
TYPES: BEGIN OF ti_pdf2,
tline TYPE char255,
END OF ti_pdf2.
DATA: li_pdf2 TYPE STANDARD TABLE OF ti_pdf2.
DATA: v_e_devtype TYPE rspoptype.
data: pdf type fpformoutput-pdf.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'YMM_F_MM03_PETOF_CARTA'
IMPORTING
fm_name = lv_name.
Se indica que la salida será por mail
lw_control_parameters-no_dialog = 'X'.
lw_control_parameters-getotf = 'X'.
Se cambia el título del mensaje
lw_output_options-tdtitle = 'Prueba'.
lw_output_options-tdprinter = v_e_devtype.
lw_output_options-tdnoprev = 'X'.
MOVE-CORRESPONDING i_ymm_mm03_0003 TO i_ymm_mm03_0003p.
break nhera.
CALL FUNCTION lv_name
EXPORTING
control_parameters = lw_control_parameters
output_options = lw_output_options
pi_tipcompra = lv_tipcom
pi_mm_mm03_0003 = i_ymm_mm03_0003p
pi_mm_mm03_0001 = i_ymm_mm03_0001
IMPORTING
document_output_info = lw_document_output_info
job_output_info = lw_job_output_info
job_output_options = lw_job_output_options
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 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.
li_otf[] = lw_job_output_info-otfdata[].
CALL FUNCTION 'CONVERT_OTF_2_PDF'
EXPORTING
USE_OTF_MC_CMD = 'X'
ARCHIVE_INDEX =
IMPORTING
bin_filesize = lv_numbytes
TABLES
otf = li_otf
doctab_archive = li_doctab
lines = li_pdf
EXCEPTIONS
err_conv_not_possible = 1
err_otf_mc_noendmarker = 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.
*
CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
EXPORTING
LINE_WIDTH_SRC =
LINE_WIDTH_DST =
TRANSFER_BIN = ' '
TABLES
content_in = li_pdf
content_out = li_pdf2
EXCEPTIONS
ERR_LINE_WIDTH_SRC_TOO_LONG = 1
ERR_LINE_WIDTH_DST_TOO_LONG = 2
ERR_CONV_FAILED = 3
OTHERS = 4
.
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 = li_pdf.
po_contents_bin = li_pdf2.
Nombre del objeto
lw_document_data-obj_name = text-010.
lw_document_data-obj_descr = text-010.
lw_document_data-doc_size = ( sy-tfill - lc_uno ) * lc_valor_constante.
lw_document_data-doc_size = lc_valor_constante.
lw_packing_list-transf_bin = X.
clear lw_packing_list-transf_bin.
lw_packing_list-head_start = lc_uno.
lw_packing_list-head_num = lc_cero.
lw_packing_list-body_start = lc_uno.
lw_packing_list-body_num = sy-tfill.
describe table po_contents_bin lines lv_lines_bin.
read table po_contents_bin into wa_contents_bin index lv_lines_bin.
lw_packing_list-doc_size = lv_lines_bin * 255.
lw_packing_list-body_num = lv_lines_bin.
lw_packing_list-doc_type = lc_raw_document.
APPEND lw_packing_list TO li_packing_list.
Personas a las que se le envía el mail
PERFORM f_direcciones_correo CHANGING li_receivers.
IF li_receivers[] IS INITIAL.
MESSAGE e025(ymm_03).
No existen direcciones de e-mail
ENDIF.
Cuerpo del mail.
lw_contents_txt = 'Prueba del envío de mail del comparativo'.
APPEND lw_contents_txt TO li_contents_txt.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = lw_document_data
put_in_outbox = lc_marca
commit_work = lc_marca
IMPORTING
SENT_TO_ALL =
NEW_OBJECT_ID =
TABLES
packing_list = li_packing_list
OBJECT_HEADER =
contents_bin = po_contents_bin
contents_txt = li_contents_txt
receivers = li_receivers
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.
ENDFORM. "f_mail
Please be clear...!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'YMM_F_MM03_PETOF_CARTA'
IMPORTING
fm_name = lv_name.
Se indica que la salida será por mail
lw_control_parameters-no_dialog = 'X'.
fm_name = lv_name.
Se indica que la salida será por mail
lw_control_parameters-no_dialog = 'X'.
lw_control_parameters-getotf = 'X'.
Se cambia el título del mensaje
lw_output_options-tdtitle = 'Prueba'.
lw_output_options-tdprinter = v_e_devtype.
lw_output_options-tdnoprev = 'X'.
MOVE-CORRESPONDING i_ymm_mm03_0003 TO i_ymm_mm03_0003p.
break nhera.
CALL FUNCTION lv_name
lw_control_parameters-getotf = 'X'.
Se cambia el título del mensaje
lw_output_options-tdtitle = 'Prueba'.
lw_output_options-tdprinter = v_e_devtype.
lw_output_options-tdnoprev = 'X'.
MOVE-CORRESPONDING i_ymm_mm03_0003 TO i_ymm_mm03_0003p.
break nhera.
CALL FUNCTION lv_name
EXPORTING
control_parameters = lw_control_parameters
output_options = lw_output_options
pi_tipcompra = lv_tipcom
pi_mm_mm03_0003 = i_ymm_mm03_0003p
pi_mm_mm03_0001 = i_ymm_mm03_0001
IMPORTING
document_output_info = lw_document_output_info
job_output_info = lw_job_output_info
job_output_options = lw_job_output_options
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 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.
li_otf[] = lw_job_output_info-otfdata[].
ALL FUNCTION 'CONVERT_OTF_2_PDF'
EXPORTING
USE_OTF_MC_CMD = 'X'
ARCHIVE_INDEX =
IMPORTING
bin_filesize = lv_numbytes
TABLES
otf = li_otf
doctab_archive = li_doctab
lines = li_pdf
EXCEPTIONS
err_conv_not_possible = 1
err_otf_mc_noendmarker = 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.
CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
TABLES
content_in = li_pdf
content_out = li_pdf2
EXCEPTIONS
ERR_LINE_WIDTH_SRC_TOO_LONG = 1
ERR_LINE_WIDTH_DST_TOO_LONG = 2
ERR_CONV_FAILED = 3
OTHERS = 4
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT li_pdf2.
wa_contents_bin-line = li_pdf2-tline.
APPEND wa_contents_bin to po_contents_bin.
ENDLOOP.
po_contents_bin = li_pdf2.
Nombre del objeto
lw_document_data-obj_name = text-010.
lw_document_data-obj_descr = text-010.
lw_document_data-doc_size = ( sy-tfill - lc_uno ) * lc_valor_constante.
lw_document_data-doc_size = lc_valor_constante.
lw_packing_list-transf_bin = X.
CLEAR lw_packing_list-transf_bin.
lw_packing_list-head_start = lc_uno.
lw_packing_list-head_num = lc_cero.
lw_packing_list-body_start = lc_uno.
lw_packing_list-body_num = sy-tfill.
DESCRIBE TABLE po_contents_bin LINES lv_lines_bin.
READ TABLE po_contents_bin INTO wa_contents_bin INDEX lv_lines_bin.
lw_packing_list-doc_size = lv_lines_bin * 255.
lw_packing_list-body_num = lv_lines_bin.
lw_packing_list-doc_type = lc_raw_document.
APPEND lw_packing_list TO li_packing_list.
Personas a las que se le envía el mail
PERFORM f_direcciones_correo CHANGING li_receivers.
IF li_receivers[] IS INITIAL.
MESSAGE e025(ymm_03).
No existen direcciones de e-mail
ENDIF.
Cuerpo del mail.
lw_contents_txt = 'Prueba del envío de mail del comparativo'.
APPEND lw_contents_txt TO li_contents_txt.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = lw_document_data
put_in_outbox = lc_marca
commit_work = lc_marca
IMPORTING
SENT_TO_ALL =
NEW_OBJECT_ID =
TABLES
packing_list = li_packing_list
OBJECT_HEADER =
contents_bin = po_contents_bin
contents_txt = li_contents_txt
receivers = li_receivers
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.
Edited by: Jon Azkorra Olano on Aug 20, 2009 12:11 PM
Edited by: Jon Azkorra Olano on Aug 20, 2009 12:12 PM
hi
Check this link
http://www.abapcode.info/2007/06/smartform-to-mail-as-pdf-attachment.html
SMART form to PDF
https://wiki.sdn.sap.com/wiki/display/Snippets/ConvertSmartformtoPDFformat
smartform to MAIL
https://wiki.sdn.sap.com/wiki/display/Snippets/SmartformtoMailasPDF+attachment
http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm
surya
User | Count |
---|---|
86 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.