0% found this document useful (0 votes)
2K views6 pages

ALV PDF Generation and Emailing

The document contains code to generate PDF files from SAP spool requests, add them to an email as attachments along with body text, and send the email. It loops through customer records, converts any spool requests to PDF, adds them and recipient details to variables, and calls a function to send the email. It also handles a case for customers without an email address, building a body listing them and sending a separate notification email.

Uploaded by

Pankaj Mittal
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)
2K views6 pages

ALV PDF Generation and Emailing

The document contains code to generate PDF files from SAP spool requests, add them to an email as attachments along with body text, and send the email. It loops through customer records, converts any spool requests to PDF, adds them and recipient details to variables, and calls a function to send the email. It also handles a case for customers without an email address, building a body listing them and sending a separate notification email.

Uploaded by

Pankaj Mittal
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

FORM DISPLAY2 . data : t_final_temp type table of ty_final with header line. sort t_final by kunnr. t_final_temp[] = t_final[].

delete t_final where email = ''. delete t_final_temp where email <> ''. loop at t_final. move-corresponding t_final to t_final1. * t_final1-name1 = 'Hello'. append t_final1. at end of kunnr. PERFORM header. types : begin of ty_spool, kunnr type kna1-kunnr, name1 type kna1-name1, email type adr6-smtp_addr, spool_no type tsp01-rqident, end of ty_spool. DATA:w_print TYPE slis_print_alv, pdf LIKE tline OCCURS 0, g_spool TYPE tsp01-rqident, w_FULL_PATH TYPE string , W_PATH(256) TYPE c, i_spool type table of ty_spool with header line. w_print-print = 'X'. DATA: lwa_params TYPE pri_params, lv_valid TYPE c. CLEAR: lwa_params, lv_valid. CALL FUNCTION 'GET_PRINT_PARAMETERS' EXPORTING in_parameters = lwa_params layout = 'X_65_132' line_count = 65 line_size = 132 no_dialog = 'X' IMPORTING out_parameters = lwa_params valid = lv_valid EXCEPTIONS archive_info_not_found = 1 invalid_print_params = 2 invalid_archive_params = 3 OTHERS = 4. MOVE-CORRESPONDING lwa_params TO w_print-print_ctrl-pri_params. w_print-print_ctrl-pri_params-pdest = 'LP01'. " your printr device NEW-PAGE PRINT ON PARAMETERS lwa_params NO DIALOG. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING * I_BYPASSING_BUFFER = 'X' I_CALLBACK_PROGRAM = SY-REPID

IT_FIELDCAT = FIELDCAT[] I_DEFAULT = 'X' I_SAVE = 'X' is_print = w_print it_events = i_events TABLES T_OUTTAB = T_FINAL1 EXCEPTIONS PROGRAM_ERROR = 1 OTHERS = 2. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. NEW-PAGE PRINT OFF. REFRESH:T_FINAL1. IF sy-subrc EQ 0. if sy-spono is not initial. i_spool-kunnr = t_final-kunnr. i_spool-name1 = t_final-name1. i_spool-email = t_final-email. i_spool-spool_no = sy-spono. append i_spool. endif. endif. endat. endloop. if i_spool[] is not initial. *CALL function 'TMP_GUI_BROWSE_FOR_FOLDER' *EXPORTING *WINDOW_TITLE = 'Select A File Folder' *INITIAL_FOLDER = 'C:\' *IMPORTING *SELECTED_FOLDER = W_PATH. *CONDENSE W_PATH. loop at i_spool. CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF' EXPORTING src_spoolid = i_spool-spool_no TABLES pdf = pdf. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ELSE. *clear w_full_path. *concatenate W_PATH '\' i_spool-kunnr '_' sy-datum '.pdf' into w_FULL_PATH. *CALL FUNCTION 'GUI_DOWNLOAD' *EXPORTING *filename = w_full_path *filetype = 'BIN' *TABLES *data_tab = pdf.

*ENDIF. data: wa_doc_data type SODOCCHGI1, i_objpack type table of SOPCKLSTI1 with header line, i_invpdf type table of SOLISTI1 with header line, i_objtxt type table of SOLISTI1 with header line, i_reclist type table of SOMLRECI1 with header line, g_tab_lines(5) type n. * To change table line width from 132char to 255char CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE' EXPORTING line_width_dst = '255' TABLES content_in = pdf"i_lines content_out = i_invpdf EXCEPTIONS err_line_width_src_too_long = 1 err_line_width_dst_too_long = 2 err_conv_failed = 3 OTHERS = 4. * Prepare the body for Invoice email CLEAR g_tab_lines. CONCATENATE 'Dear Customer' ',' INTO i_objtxt. APPEND i_objtxt. CLEAR i_objtxt. APPEND i_objtxt. CONCATENATE 'Please find the attached file of your despatch' '.' INTO i_objtxt. APPEND i_objtxt. CLEAR i_objtxt. APPEND i_objtxt. CONCATENATE 'JK Cement Ltd' '.' INTO i_objtxt. APPEND i_objtxt. DESCRIBE TABLE i_objtxt LINES g_tab_lines. READ TABLE i_objtxt INDEX g_tab_lines. * Fill with document data and prepare the Subject for Invoice email CLEAR wa_doc_data. wa_doc_data-doc_size = ( g_tab_lines - 1 ) * 255 + STRLEN( i_objtxt ). wa_doc_data-obj_langu = sy-langu. CONCATENATE 'JK Cement Despatch Detail' '....' INTO wa_doc_data-obj_descr SEPARATED BY space. wa_doc_data-sensitivty = 'F'. * Fill with body & attachment details CLEAR i_objpack. i_objpack-transf_bin = space. i_objpack-head_start = 1. i_objpack-head_num = 0. i_objpack-body_start = 1. i_objpack-body_num = g_tab_lines. i_objpack-doc_type = 'RAW'. APPEND i_objpack. CLEAR: i_objpack, g_tab_lines.

DESCRIBE TABLE i_invpdf LINES g_tab_lines. READ TABLE i_invpdf INDEX g_tab_lines. CLEAR i_objpack. i_objpack-transf_bin = 'X'. i_objpack-head_start = 1. i_objpack-head_num = 1. i_objpack-body_start = 1. i_objpack-body_num = g_tab_lines. i_objpack-doc_type = 'PDF'. concatenate 'JK Cement' '_' i_spool-kunnr '_' sy-datum into i_objpackobj_descr." SEPARATED BY space. i_objpack-doc_size = ( g_tab_lines - 1 ) * 255 + STRLEN( i_invpdf ). APPEND i_objpack. CLEAR: i_objpack, g_tab_lines. * Fill with recipient details CLEAR i_reclist. REFRESH i_reclist. i_reclist-receiver = i_spool-email."'pankajmittal84@[Link]'."gv_mai l_id. i_reclist-rec_type = 'U'. i_reclist-com_type = 'INT'. i_reclist-notif_del = 'X'. i_reclist-notif_ndel = 'X'. APPEND i_reclist. CLEAR i_reclist. * Send email using the Payer's email ID CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1' EXPORTING document_data = wa_doc_data put_in_outbox = 'X' commit_work = 'X' TABLES packing_list = i_objpack contents_bin = i_invpdf * contents_hex = lt_mime 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. refresh:pdf,i_objpack[],i_invpdf[],i_objtxt[],i_reclist[]. clear:wa_doc_data. endif. endloop. endif. ****Sending mail whose email id are not maintained. if t_final_temp[] is not initial. * Prepare the body for Invoice email

CONCATENATE 'Please maintain the Email-id of Following Customers' ':' INTO i_objtxt. APPEND i_objtxt. CLEAR i_objtxt. APPEND i_objtxt. loop at t_final_temp. at end of kunnr. * Prepare the body for Invoice email CONCATENATE t_final_temp-kunnr t_final_temp-name1 INTO i_objtxt separa ted by space. APPEND i_objtxt. CLEAR i_objtxt. endat. endloop. CLEAR g_tab_lines. DESCRIBE TABLE i_objtxt LINES g_tab_lines. READ TABLE i_objtxt INDEX g_tab_lines. * Fill with document data and prepare the Subject for Invoice email CLEAR wa_doc_data. wa_doc_data-doc_size = ( g_tab_lines - 1 ) * 255 + STRLEN( i_objtxt ). wa_doc_data-obj_langu = sy-langu. CONCATENATE 'Email ID not Maintained' '....' INTO wa_doc_data-obj_descr SEPARATED BY space. wa_doc_data-sensitivty = 'F'. * Fill with body & attachment details CLEAR i_objpack. i_objpack-transf_bin = space. i_objpack-head_start = 1. i_objpack-head_num = 0. i_objpack-body_start = 1. i_objpack-body_num = g_tab_lines. i_objpack-doc_type = 'RAW'. APPEND i_objpack. CLEAR: i_objpack, g_tab_lines. * Fill with recipient details CLEAR i_reclist. REFRESH i_reclist. i_reclist-receiver = 'pankajmittal84@[Link]'."gv_mail_id. i_reclist-rec_type = 'U'. i_reclist-com_type = 'INT'. i_reclist-notif_del = 'X'. i_reclist-notif_ndel = 'X'. APPEND i_reclist. CLEAR i_reclist. * Send email using the Payer's email ID CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1' EXPORTING document_data = wa_doc_data put_in_outbox = 'X' commit_work = 'X' TABLES

* *

packing_list contents_bin contents_hex contents_txt receivers EXCEPTIONS too_many_receivers document_not_sent document_type_not_exist operation_no_authorization parameter_error x_error enqueue_error OTHERS

= i_objpack = i_invpdf = lt_mime = i_objtxt = i_reclist = = = = = = = = 1 2 3 4 5 6 7 8.

refresh:pdf,i_objpack[],i_invpdf[],i_objtxt[],i_reclist[]. clear:wa_doc_data. endif. ENDFORM. " DISPLAY2

You might also like