0% found this document useful (0 votes)
270 views5 pages

PDF To Mail

The document describes converting an ABAP spool to a PDF file, attaching the PDF to an email, and sending it. Key steps include: 1) Creating an ALV grid to display spool data and convert the spool to a PDF file. 2) Appending the PDF data to a BCS document object and adding it as an attachment. 3) Creating a recipient object for the inbox user and adding it to the document. 4) Sending the email with the attached PDF file.

Uploaded by

Jackson Borsatto
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
270 views5 pages

PDF To Mail

The document describes converting an ABAP spool to a PDF file, attaching the PDF to an email, and sending it. Key steps include: 1) Creating an ALV grid to display spool data and convert the spool to a PDF file. 2) Appending the PDF data to a BCS document object and adding it as an attachment. 3) Creating a recipient object for the inbox user and adding it to the document. 4) Sending the email with the attached PDF file.

Uploaded by

Jackson Borsatto
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

* convert spool to pdf = RSTXPDFT4 CONSTANTS CONSTANTS CONSTANTS CONSTANTS CONSTANTS c_container TYPE c LENGTH 30 VALUE 'CC'.

c_col1 TYPE c LENGTH 2 VALUE ' ~'. c_col2 TYPE c LENGTH 2 VALUE '~ '. c_255 TYPE i VALUE 255. p_recpnt TYPE syuname VALUE 'GEORGE'.

DATA gt_final TYPE TABLE OF t000. DATA: lv_buffer TYPE string, lv_spool_nr TYPE tsp01-rqident, lt_mess_att TYPE TABLE OF solisti1 , ls_mess_att TYPE solisti1. TYPES: ty_t_pdf TYPE STANDARD TABLE OF tline. DATA: lt_pdf_output TYPE ty_t_pdf, ls_pdf_output TYPE tline, l_ref_bcs TYPE REF TO cl_bcs, l_ref_document TYPE REF TO cl_document_bcs, l_ref_recipient TYPE REF TO if_recipient_bcs, l_ref_bcs_exception TYPE REF TO cx_bcs, lv_sent_to_all TYPE os_boolean, lv_filesize TYPE so_obj_len, lv_doclines TYPE i, lv_last_line TYPE i, lv_text TYPE so_obj_des, lv_data TYPE bcsy_text, lv_size TYPE i, gt_fcat TYPE lvc_t_fcat. DATA:g_ref_container TYPE REF TO cl_gui_custom_container, g_ref_grid TYPE REF TO cl_gui_alv_grid, gv_off TYPE int4, gs_print TYPE lvc_s_prnt, * g_ref_rec TYPE REF TO lcl_event_receiver, gs_variant TYPE disvariant, gs_layo TYPE lvc_s_layo. * Create alv grid along WITH printer settings for background execution purpose. ** custom container IF g_ref_container IS NOT BOUND. ** offline method check required for background execution CALL METHOD cl_gui_alv_grid=>offline RECEIVING e_offline = gv_off. IF gv_off IS INITIAL. CREATE OBJECT g_ref_container EXPORTING container_name = c_container. ENDIF. ** instance of alv grid. IF g_ref_grid IS NOT BOUND. CREATE OBJECT g_ref_grid EXPORTING i_parent = g_ref_container. ENDIF. ** build field catalog PERFORM build_fieldcat1 CHANGING gt_fcat. ** layout gs_layo-cwidth_opt = 'X'. "OPTIMUM WIDTH OF THE COLUMN gs_layo-zebra = 'X'. "Alternate line coloring

** Set Print Parameters (Required If The ALV Output has Length more than 255) CALL FUNCTION 'SET_PRINT_PARAMETERS' EXPORTING destination = 'LOCL' " Printer layout = 'X_65_512/2' "Format line_count = '65' "Line Count line_size = '1024'. "Line Size gs_print-print = 'X'. CALL METHOD g_ref_grid->set_table_for_first_display EXPORTING i_save = 'A' is_layout = gs_layo "Layout is_print = gs_print "For Creating Spool CHANGING it_outtab = gt_final "Final Internal Table Containing Data to Display it_fieldcatalog = gt_fcat "Fieldcatalog EXCEPTIONS invalid_parameter_combination = 1 program_error = 2 too_many_lines = 3 OTHERS = 4. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 symsgv3 sy-msgv4. ENDIF. *convert spool to pdf and send as attachment to sap inbox. MOVE sy-spono TO lv_spool_nr. CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF' EXPORTING src_spoolid = lv_spool_nr "Spool Number no_dialog = space dst_device = 'LOCL' "Printer Name importingpdf_bytecount = lv_size "Output Size tablespdf = lt_pdf_output "Spool data in PDF Format exceptionserr_no_abap_spooljob = 1 err_no_spooljob = 2 err_no_permission = 3 err_conv_not_possible = 4 err_bad_destdevice = 5 user_cancelled = 6 err_spoolerror = 7 err_temseerror = 8 err_btcjob_open_failed = 9. IF sy-subrc EQ 0. LOOP AT lt_pdf_output INTO ls_pdf_output. TRANSLATE ls_pdf_output USING c_col1. CONCATENATE lv_buffer ls_pdf_output INTO lv_buffer. CLEAR ls_pdf_output. ENDLOOP. TRANSLATE lv_buffer USING c_col2. DO. ls_mess_att = lv_buffer. APPEND ls_mess_att TO lt_mess_att. SHIFT lv_buffer LEFT BY c_255 PLACES. IF lv_buffer IS INITIAL. EXIT. ENDIF. CLEAR ls_mess_att.

ENDDO. ENDIF. *--create reference object TRY. l_ref_bcs = cl_bcs=>create_persistent( ). lv_text = 'Mail Subject' . APPEND 'Mail Content' TO lv_data. l_ref_document = cl_document_bcs=>create_document( i_type = 'RAW' i_text = lv_data i_subject = lv_text ). * *--create document reference lv_filesize = lv_size. CALL METHOD l_ref_document->add_attachment EXPORTING i_attachment_type = 'PDF' i_attachment_size = lv_filesize i_attachment_subject = lv_text i_att_content_text = lt_mess_att[]. * set the document l_ref_bcs->set_document( l_ref_document ). * create recipient * p_recpnt = sap INBOX user ID to WHICH the ATTACHMENT is SENT. l_ref_recipient = cl_sapuser_bcs=>create( p_recpnt ). *adding recipient in to section l_ref_bcs->add_recipient( l_ref_recipient ). * send mail CALL METHOD l_ref_bcs->send( EXPORTING i_with_error_screen = 'X' RECEIVING result = lv_sent_to_all ). IF lv_sent_to_all = 'X'. ENDIF. CATCH cx_bcs INTO l_ref_bcs_exception. IF l_ref_bcs_exception IS NOT INITIAL. CLEAR l_ref_bcs_exception. ENDIF. ENDTRY. COMMIT WORK. ENDIF. ---------------------------------------------------------------form user_command using r_ucomm like sy-ucomm rs_selfield type slis_selfield. data: lv_filename type string, lv_path type string, lv_fullpath type string, lv_user_action type i, lv_spool type tsp01-rqident, lv_pdf_bytecount type i, li_pdf type tlinetab, lwa_params type pri_params, lwa_report type zfs_ap_benefit_inkind_report, li_slopt type standard table of rsparams. "#EC CALLED

if r_ucomm eq '%PDF'. *-- for change the file name and extension file to PDF call method cl_gui_frontend_services=>file_save_dialog exporting default_file_name = '*.pdf' file_filter = '*.pdf' changing filename = lv_filename path = lv_path fullpath = lv_fullpath user_action = lv_user_action EXCEPTIONS cntl_error = 1 error_no_gui = 2 not_supported_by_gui = 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. *-- If button cancel not clicked then download pdf. if lv_user_action <> '9'. *---- Get parameters from select option call function 'RS_REFRESH_FROM_SELECTOPTIONS' exporting curr_report = sy-repid tables selection_table = li_slopt. *---- Get print parameters call function 'GET_PRINT_PARAMETERS' exporting destination = 'LOCL' immediately = ' ' line_count = '65' line_size = '255' no_dialog = 'X' cover_page = '' importing out_parameters = lwa_params. *---- Submit the transcation to spool submit <name_of_your_program> with selection-table li_slopt to sap-spool spool parameters lwa_params without spool dynpro and return. *---- Get created spool number from tsp01 select max( rqident ) into lv_spool from tsp01 where rqclient = sy-mandt and rqowner = sy-uname. call function 'CONVERT_ABAPSPOOLJOB_2_PDF' exporting src_spoolid = lv_spool no_dialog = ' '

importing pdf_bytecount = lv_pdf_bytecount tables pdf = li_pdf. *---- Download to local call function 'GUI_DOWNLOAD' exporting bin_filesize = lv_pdf_bytecount filename = lv_fullpath filetype = 'BIN' tables data_tab = li_pdf. endif. endif. endform.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy