Smartform导出为PDF并且作为附加资料进行邮件发送.docx

上传人:b****7 文档编号:10251962 上传时间:2023-02-09 格式:DOCX 页数:17 大小:18.64KB
下载 相关 举报
Smartform导出为PDF并且作为附加资料进行邮件发送.docx_第1页
第1页 / 共17页
Smartform导出为PDF并且作为附加资料进行邮件发送.docx_第2页
第2页 / 共17页
Smartform导出为PDF并且作为附加资料进行邮件发送.docx_第3页
第3页 / 共17页
Smartform导出为PDF并且作为附加资料进行邮件发送.docx_第4页
第4页 / 共17页
Smartform导出为PDF并且作为附加资料进行邮件发送.docx_第5页
第5页 / 共17页
点击查看更多>>
下载资源
资源描述

Smartform导出为PDF并且作为附加资料进行邮件发送.docx

《Smartform导出为PDF并且作为附加资料进行邮件发送.docx》由会员分享,可在线阅读,更多相关《Smartform导出为PDF并且作为附加资料进行邮件发送.docx(17页珍藏版)》请在冰豆网上搜索。

Smartform导出为PDF并且作为附加资料进行邮件发送.docx

Smartform导出为PDF并且作为附加资料进行邮件发送

Smartform导出为PDF并且作为附件进行邮件发送

1、首先获取Smartform生成的功能函数,

CALLFUNCTION'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname=c_formname

IMPORTING

fm_name=v_fm_name

EXCEPTIONS

no_form=1

no_function_module=2

OTHERS=3.

2、调用该函数并且在参数中设定获取OTF数据

st_control_parameters-no_dialog='X'.

st_control_parameters-getotf='X'.

CALLFUNCTIONv_fm_name

EXPORTING

control_parameters=st_control_parameters

output_options=st_output_options

IMPORTING

document_output_info=st_document_output_info

job_output_info=st_job_output_info

job_output_options=st_job_output_options

TABLES

pt_data=gt_data

EXCEPTIONS

formatting_error=1

internal_error=2

send_error=3

user_canceled=4

OTHERS=5.

3、将OTF数据转换成PDF文件

CALLFUNCTION'CONVERT_OTF'

EXPORTING

format='PDF'

IMPORTING

bin_filesize=v_bin_filesize

bin_file=g_binfile

TABLES

otf=st_job_output_info-otfdata

*doctab_archive=it_docs

lines=it_lines

EXCEPTIONS

err_max_linewidth=1

err_format=2

err_conv_not_possible=3

err_bad_otf=4

OTHERS=5.

IFg_binfileISNOTINITIAL.

CALLFUNCTION'SCMS_XSTRING_TO_BINARY'

EXPORTING

buffer=g_binfile

IMPORTING

output_length=v_bin_filesize

TABLES

binary_tab=gt_record.

ENDIF.

4、处理邮件主题,附件,收件人,发件人(默认会是登陆用户配置的邮箱)

APPENDLINESOFGT_recordTOi_objbin.

*MailBody

i_objtxt-line='邮件正文'.

APPENDi_objtxt.

DESCRIBETABLEi_objtxtLINESv_lines_txt.

wa_doc-obj_langu=SY-LANGU.

wa_doc-obj_name='smartform'.

wa_doc-expiry_dat=sy-datum+10.

wa_doc-obj_descr='邮件标题题题题题题题题题'.

wa_doc-sensitivty='F'.

wa_doc-doc_size=v_lines_txt*255+v_bin_filesize.

*MainText

CLEARi_objpack-transf_bin.

i_objpack-head_start=1.

i_objpack-head_num=0.

i_objpack-body_start=1.

i_objpack-body_num=v_lines_txt.

i_objpack-doc_type='RAW'.

APPENDi_objpack.

*Attachment(pdf-Attachment)

CLEARv_lines_bin.

i_objpack-transf_bin='X'.

i_objpack-head_start=1.

i_objpack-head_num=1.

i_objpack-body_start=1.

DESCRIBETABLEi_objbinLINESv_lines_bin.

i_objpack-doc_size=v_bin_filesize.

i_objpack-body_num=v_lines_bin.

i_objpack-doc_type='PDF'.

i_objpack-obj_name='smart'.

i_objpack-obj_descr='PDF'.”这里是附件名

APPENDi_objpack.

CLEARi_reclist.

i_reclist-rec_type='U'.

i_reclist-receiver='xxx@'.“收件人地址

APPENDi_reclist.

5、调用发送邮件的函数

CALLFUNCTION'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data=wa_doc

put_in_outbox=''

commit_work='X'

TABLES

packing_list=i_objpack

*object_header=wa_objhead

contents_bin=i_objbin

contents_txt=i_objtxt

receivers=i_reclist

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.

邮件发送后可在sost中查看到、

6、如果需要保存PDF到本地

*........................GETTHEFILENAMETOSTORE....................*

*CONCATENATE'smrt''.pdf'INTOv_name.

*CREATEOBJECTv_guiobj.

*CALLMETHODv_guiobj->file_save_dialog

*EXPORTING

*default_extension='pdf'

*default_file_name=v_name

*file_filter=v_filter

*CHANGING

*filename=v_name

*path=v_path

*fullpath=v_fullpath

*user_action=v_uact.

*IFv_uact=v_guiobj->action_cancel.

*EXIT.

*ENDIF.

**..................................DOWNLOADASFILE....................*

*

*MOVEv_fullpathTOv_filename.

*CALLFUNCTION'GUI_DOWNLOAD'

*EXPORTING

*bin_filesize=v_bin_filesize

*filename=v_filename

*filetype='BIN'

*TABLES

*data_tab=it_lines

*EXCEPTIONS

*file_write_error=1

*no_batch=2

*gui_refuse_filetransfer=3

*invalid_type=4

*no_authority=5

*unknown_error=6

*header_not_allowed=7

*separator_not_allowed=8

*filesize_not_allowed=9

*header_too_long=10

*dp_error_create=11

*dp_error_send=12

*dp_error_write=13

*unknown_dp_error=14

*access_denied=15

*dp_out_of_memory=16

*disk_full=17

*dp_timeout=18

*file_not_found=19

*dataprovider_exception=20

*control_flush_error=21

*OTHERS=22.

 

完整代码请见下面:

*&---------------------------------------------------------------------*

*&ReportZTEST_MAIL3*

*&*

*&---------------------------------------------------------------------*

*&*

*&*

*&---------------------------------------------------------------------*

REPORTztest_mail3.

TYPES:

BEGINOFty_data.

TYPES:

matklTYPEmara-matkl,

wgbezTYPEt023t-wgbez,

matnrTYPEmara-matnr,

maktxTYPEmakt-maktx,

ebelnTYPEekko-ebeln,

ebelpTYPEekpo-ebelp,

ekgrpTYPEekko-ekgrp,

bukrsTYPEekko-bukrs,

werksTYPEekpo-werks,

lifnrTYPEekko-lifnr,

netprTYPEekpo-netpr,

normtTYPEmara-normt,

groesTYPEmara-groes,

kdatbTYPEekko-kdatb,

kdateTYPEekko-kdate,

jiaohuo(30),

waibu(30),

*增加物料基本单位,订单单位

meins(3),

bstme(3),

*BOC2014080601增加车间和生产线

labor_t(30),

spart_t(20),

*EOC2014080601增加车间和生产线

*BOC2014082101增加物料长文本,规格型号,供应商描述,采购订单文

*beizhu(100),

*zeinr(22),

*lifnr_d(35),

*caigou(100),

*EOC2014082101增加车间和生产线

ENDOFty_data.

DATA:

gt_dataTYPETABLEOFty_dataWITHHEADERLINE.

DATA:

g_binfileTYPExstring,

gt_recordTYPETABLEOFsolisti1WITHHEADERLINE.

*Internaltabledeclaration

DATA:

it_otfTYPESTANDARDTABLEOFitcoo,

it_docsTYPESTANDARDTABLEOFdocs,

it_linesTYPESTANDARDTABLEOFtlineWITHHEADERLINE.

*Declarationoflocalvariables.

DATA:

st_job_output_infoTYPEssfcrescl,

st_document_output_infoTYPEssfcrespd,

st_job_output_optionsTYPEssfcresop,

st_output_optionsTYPEssfcompop,

st_control_parametersTYPEssfctrlop,

v_len_inTYPEso_obj_len,

v_languageTYPEsflanguVALUE'E',

v_e_devtypeTYPErspoptype,

v_bin_filesizeTYPEi,

v_nameTYPEstring,

v_pathTYPEstring,

v_fullpathTYPEstring,

v_filterTYPEstring,

v_uactTYPEi,

v_guiobjTYPEREFTOcl_gui_frontend_services,

v_filenameTYPEstring,

v_fm_nameTYPErs38l_fnam.

CONSTANTSc_formnameTYPEtdsfnameVALUE'ZPVNP21_CN01'.

DATAwa_bufferTYPEstring."Toconvertfrom132to255

DATA:

i_recordTYPETABLEOFsolisti1WITHHEADERLINE,

wa_docTYPEsodocchgi1,

i_reclistTYPETABLEOFsomlreci1WITHHEADERLINE,

*Objectstosendmail.

i_objpackTYPETABLEOFsopcklsti1WITHHEADERLINE,

i_objtxtTYPETABLEOFsolisti1WITHHEADERLINE,

i_objbinTYPETABLEOFsolisti1WITHHEADERLINE,

*WorkAreadeclarations

wa_objheadTYPEsoli_tab,

*Variablesdeclarations

*v_len_inTYPEsood-objlen,

v_lines_txtTYPEi,

v_lines_binTYPEi.

CALLFUNCTION'SSF_GET_DEVICE_TYPE'

EXPORTING

i_language=v_language

i_application='SAPDEFAULT'

IMPORTING

e_devtype=v_e_devtype.

st_output_options-tdprinter=v_e_devtype.

st_control_parameters-no_dialog='X'.

st_control_parameters-getotf='X'.

*.................GETSMARTFORMFUNCTIONMODULENAME.................*

CALLFUNCTION'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname=c_formname

IMPORTING

fm_name=v_fm_name

EXCEPTIONS

no_form=1

no_function_module=2

OTHERS=3.

*...........................CALLSMARTFORM............................*

CALLFUNCTIONv_fm_name

EXPORTING

control_parameters=st_control_parameters

output_options=st_output_options

IMPORTING

document_output_info=st_document_output_info

job_output_info=st_job_output_info

job_output_options=st_job_output_options

TABLES

pt_data=gt_data

EXCEPTIONS

formatting_error=1

internal_error=2

send_error=3

user_canceled=4

OTHERS=5.

*.........................CONVERTTOOTFTOPDF.......................*

CALLFUNCTION'CONVERT_OTF'

EXPORTING

format='PDF'

IMPORTING

bin_filesize=v_bin_filesize

bin_file=g_binfile

TABLES

otf=st_job_output_info-otfdata

*doctab_archive=it_docs

lines=it_lines

EXCEPTIONS

err_max_linewidth=1

err_format=2

err_conv_not_possible=3

err_bad_otf=4

OTHERS=5.

IFg_binfileISNOTINITIAL.

CALLFUNCTION'SCMS_XSTRING_TO_BINARY'

EXPORTING

buffer=g_binfile

IMPORTING

output_length=v_bin_filesize

TABLES

binary_tab=gt_record.

ENDIF.

APPENDLINESOFGT_recordTOi_objbin.

*i_objbin[]=GT_record[].

*MailBody

i_objtxt-line='邮件正文'.

APPENDi_objtxt.

DESCRIBETABLEi_objtxtLINESv_lines_txt.

wa_doc-obj_langu=SY-LANGU.

wa_doc-obj_name='smartform'.

wa_doc-expiry_dat=sy-datum+10.

wa_doc-obj_descr='邮件标题'.

wa_doc-sensitivty='F'.

wa_doc-doc_size=v_lines_txt*255+v_bin_filesize.

*MainText

CLEARi_objpack-transf_bin.

i_objpack-head_start=1.

i_objpack-head_num=0.

i_objpack-body_start=1.

i_objpack-body_num=v_lines_txt.

i_objpack-doc_type='RAW'.

APPENDi_objpack.

*Attachment(pdf-Attachment)

CLEARv_lines_bin.

i_objpack-transf_bin='X'.

i_objpack-head_start=1.

i_objpack-head_num=1.

i_objpack-body_start=1.

DESCRIBETABLEi_objbinLINESv_lines_bin.

i_objpack-doc_size=v_bin_filesize.

i_objpack-body_num=v_lines_bin.

i_objpack-doc_type='PDF'.

i_objpack-obj_name='smart'.

i_objpack-obj_descr='PDF'.

APPENDi_objpack.

CLEARi_reclist.

i_reclist-rec_type='U'.

i_reclist-to_answer='X'.

i_reclist-notif_read='X'.

i_reclist-notif_del='X'.

i_reclist-notif_ndel='X'.

i_reclist-receiver='xxx@'.

APPENDi_reclist.

CALLFUNCTION'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data=wa_doc

put_in_outbox=''

commit_work='X'

TABLES

packing_list=i_objpack

*object_header=wa_objhead

contents_bin=i_objbin

contents_txt=i_objtxt

receivers=i_reclist

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.

IFsy-subrc=0.

*startSAPconnectprocessimmediately

*SUBMITrsconn01WITHmodeEQ'INT'ANDRETURN.

*

*COMMITWORK.

ENDIF.

 

*......................

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > PPT模板 > 其它模板

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1