Vous êtes sur la page 1sur 3

3/25/13

Welcome, Guest Login Register Getting Started Newsletters Store

SAP Community Network Wiki - Code Gallery - Smartform as a PDF to Mail id

Solutions Services & Support About SCN Downloads Industries Training & Education Partnership Developer Center Lines of Business University Alliances Events & Webinars Innovation

Smartform as a PDF to Mail id


Added by Shakti Agnihotri Mishra, last edited by Shakti Agnihotri Mishra on Mar 20, 2009

To send the smartform as a PDF attachment to Internal or External mail id. Below is the Sample Program. REPORT Z_SEND_MAIL. ********Variable Declarations **************************** DATA: gv_form_name TYPE rs38l_fnam, " Used to store the function module generated by Smartform gv_bin_filesize TYPE i, " Store the file size gv_pos TYPE i, gv_len TYPE i, gv_tab_lines TYPE i. *******Constants ****************************************** DATA : gc_text(11) TYPE c VALUE 'Form Output', gc_tst(3) TYPE c VALUE 'TST', gc_testing(7) TYPE c VALUE 'Testing'. ********Work Area Declarations **************************** DATA: gs_docdata TYPE sodocchgi1, " Data of an object w hich can be changed gs_ctrlop TYPE ssfctrlop, " Smart Forms: Control structure gs_outopt TYPE ssfcompop, " SAP Smart Forms: Smart Composer (transfer) options gs_otfdata TYPE ssfcrescl, " Smart Forms: Return value at end of form printing gs_reclist TYPE somlreci1, " SAPoffice: Structure of the API Recipient List gs_pdf_tab TYPE tline, " Workarea for SAP Script Text Lines gs_objbin TYPE solisti1, " SAPoffice: Single List w ith Column Length 255 gs_objpack TYPE sopcklsti1. " SAPoffice: Description of Imported Object Components ********Internal tables Declarations **************************** DATA: gt_reclist TYPE TABLE OF somlreci1, " SAPoffice: Structure of the API Recipient List gt_pdf_tab TYPE TABLE OF tline, " SAPscript: Text Lines gt_otf TYPE TABLE OF itcoo, " OTF Structure gt_objbin TYPE TABLE OF solisti1, " SAPoffice: Single List w ith Column Length 255 gt_objpack TYPE TABLE OF sopcklsti1. " SAPoffice: Description of Imported Object Components DATA: customer TYPE scustom, bookings TYPE ty_bookings, connections TYPE ty_connections. CLEAR : gv_form_name, gs_ctrlop, gs_outopt, gs_otfdata, gv_bin_filesize, gv_pos, gv_len, gv_tab_lines. START-OF-SELECTION. * Generate Function Module name CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' EXPORTING formname IMPORTING fm_name EXCEPTIONS no_form OTHERS IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. * Assigning values to Form Control Structure and Form Composer =1 = 3. no_function_module = 2 = gv_form_name = 'SF_EXAMPLE_01'

wiki.sdn.sap.com/wiki/display/Snippets/Smartform+as+a+PDF+to+Mail+id

1/3

3/25/13
gs_ctrlop-getotf = 'X'. gs_ctrlop-device = 'PRINTER'. gs_ctrlop-preview = ''. gs_ctrlop-no_dialog = 'X'. gs_outopt-tddest = 'LOCL'. * Getting the OTFDATA CALL FUNCTION gv_form_name EXPORTING control_parameters = gs_ctrlop output_options user_settings customer bookings connections IMPORTING job_output_info EXCEPTIONS formatting_error = 1 internal_error send_error user_canceled IF sy-subrc <> 0. =2 =3 = 4. = gs_otfdata = gs_outopt ='' = customer = bookings = connections

SAP Community Network Wiki - Code Gallery - Smartform as a PDF to Mail id

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. * Assigning the OTFDATA to OTF Structure table CLEAR gt_otf. gt_otf[] = gs_otfdata-otfdata[]. * Convert the OTF DATA to SAP Script Text lines CLEAR gt_pdf_tab. CALL FUNCTION 'CONVERT_OTF' EXPORTING format max_linew idth IMPORTING bin_filesize TABLES otf lines EXCEPTIONS err_max_linew idth err_format OTHERS IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. * Assigning the Description of the object sent in the mail CLEAR gs_docdata. gs_docdata-obj_name = gc_tst. gs_docdata-obj_descr = gc_testing. * Assigning the email id to Structure of the API Recipient List table CLEAR : gt_reclist, gs_reclist. * IF internal mail id gs_reclist-receiver = sy-uname. GS_RECLIST-REC_TYPE = 'B'. * if external mail id * gs_reclist-receiver = 'shakti.agnihotri@gmail.com'. * gs_reclist-rec_type = 'U'. APPEND gs_reclist TO gt_reclist. * Passing the SAP Script text lines to SAPoffice: Single List w ith Column Length 255 table CLEAR : gs_objbin, gs_pdf_tab. LOOP AT gt_pdf_tab INTO gs_pdf_tab. gv_pos = 255 - gv_len. IF gv_pos > 134. "length of pdf_table gv_pos = 134. ENDIF. gs_objbin+gv_len = gs_pdf_tab(gv_pos). gv_len = gv_len + gv_pos. IF gv_len = 255. "length of out (contents_bin) APPEND gs_objbin TO gt_objbin. CLEAR: gs_objbin, gv_len. IF gv_pos < 134. gs_objbin = gs_pdf_tab+gv_pos. gv_len = 134 - gv_pos. ENDIF. ENDIF. ENDLOOP. IF gv_len > 0. APPEND gs_objbin TO gt_objbin. ENDIF. * Filling the details in SAPoffice: Description of Imported Object Components table DESCRIBE TABLE gt_objbin LINES gv_tab_lines. =2 = 4. =1 = gt_otf = gt_pdf_tab = gv_bin_filesize = 'PDF' = 132

err_conv_not_possible = 3

wiki.sdn.sap.com/wiki/display/Snippets/Smartform+as+a+PDF+to+Mail+id

2/3

3/25/13
CLEAR gs_objbin.

SAP Community Network Wiki - Code Gallery - Smartform as a PDF to Mail id

READ TABLE gt_objbin INTO gs_objbin INDEX gv_tab_lines. IF sy-subrc = 0. gs_objpack-doc_size = ( gv_tab_lines - 1 ) * 255 + STRLEN( gs_objbin ). gs_objpack-transf_bin = 'X'. gs_objpack-head_start = 1. gs_objpack-head_num = 0. gs_objpack-body_start = 1. gs_objpack-body_num = gv_tab_lines. gs_objpack-doc_type = 'PDF'. gs_objpack-obj_name = 'ATTACHMENT'. gs_objpack-obj_descr = 'test'. APPEND gs_objpack TO gt_objpack. ENDIF. * Sending the Form Output in the PDF format to email CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1' EXPORTING document_data put_in_outbox commit_w ork TABLES packing_list contents_bin receivers EXCEPTIONS too_many_receivers document_not_sent document_type_not_exist parameter_error x_error enqueue_error OTHERS IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ELSE. WRITE 'Sent Successfully'. ENDIF. SUBMIT rsconn01 WITH mode EQ 'INT' AND RETURN. END-OF-SELECTION. =6 =7 = 8. =5 =1 =2 =3 = gt_objpack = gt_objbin = gt_reclist = gs_docdata = 'X' = 'X'

operation_no_authorization = 4

Follow SCN Contact Us SAP Help Portal Privacy Terms of Use Legal Disclosure Copyright

wiki.sdn.sap.com/wiki/display/Snippets/Smartform+as+a+PDF+to+Mail+id

3/3

Vous aimerez peut-être aussi