Author: name as link to Business Card
Submitted: <date>
Related Links:
- <link>
<How to send Internal Table to E_Mail address>
<Place the tutorial link to content location on community network or actual tutorial here >SPAN
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'*&---------------------------------------------------------------------* *& Report YKC_E_MAIL *& *&---------------------------------------------------------------------* *& This prog teaches how one can send intenal table data as CSV to *& e_mail *& Author: Krishna Date creation 6 Nov 2008 *&---------------------------------------------------------------------* REPORT ykc_e_mail . TABLES: mara. DATA: BEGIN OF it_tab OCCURS 0, matnr LIKE mara-matnr, ersda LIKE mara-ersda, "creation date ernam LIKE mara-ernam, "person created pstat LIKE mara-pstat, "maint stat lvorm LIKE mara-lvorm, "flg for deletion mtart LIKE mara-mtart, "mat type meins LIKE mara-meins, "uom END OF it_tab. DATA: w_matnr(19) TYPE c, w_ersda(15) TYPE c, w_ernam(15) TYPE c, w_pstat(20) TYPE c, w_lvorm(20) TYPE c, w_mtart(20) TYPE c, w_meins(20) TYPE c. DATA: w_filename(27) TYPE c. *---------------------------------------------------------------------* * S E L E C T I O N - S C R E E N. *---------------------------------------------------------------------* *SELECTION-SCREEN BEGIN OF BLOCK bl1 WITH FRAME TITLE text-bl1. PARAMETERS: p_email(50) TYPE c. PARAMETERS: p_bdoc(20) TYPE c OBLIGATORY. "for name of file to send *SELECTION-SCREEN END OF BLOCK bl1. *---------------------------------------------------------------------* * S T A R T - O F - S E L E C T I O N. *---------------------------------------------------------------------* START-OF-SELECTION. PERFORM get_data. PERFORM p_send_email. *&---------------------------------------------------------------------* *& Form get_data *&---------------------------------------------------------------------* * text : getting data into internal table *----------------------------------------------------------------------* FORM get_data . SELECT matnr ersda ernam pstat lvorm mtart meins INTO TABLE it_tab FROM mara WHERE lvorm = 'X'. ENDFORM. " get_data *&---------------------------------------------------------------------* *& Form p_send_email *&---------------------------------------------------------------------* * text :sending internal table to e_mail address *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM p_send_email . FIELD-SYMBOLS: <field> TYPE ANY. DATA : BEGIN OF i_dload OCCURS 0 , dload(1000) , END OF i_dload , it_receivers LIKE somlreci1 OCCURS 1 WITH HEADER LINE, w_object_content LIKE solisti1 OCCURS 1 WITH HEADER LINE, w_doc_data LIKE sodocchgi1 OCCURS 0 WITH HEADER LINE, w_rsnum(10), w_bdmng(14), w_meins(4), *---for e_mail address ws_email LIKE adr6-smtp_addr, *--Internal table declaration it_objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE, it_objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE, it_objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE, it_objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE, it_reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE, doc_chng LIKE sodocchgi1, tab_lines LIKE sy-tabix, w_longtext(255) TYPE c, v_date(10) TYPE c, text(200) TYPE c, w_text(50) TYPE c, *---declaration for diaplaying msg in the body of mail. w_msga(18) TYPE c, w_msgb(22) TYPE c, w_msgc(27) TYPE c. *--Get receipient address CLEAR it_reclist. *---passing e_mail address ws_email = p_email. *---setting name of file for csv w_filename = p_bdoc. IF p_email IS NOT INITIAL. * build body of message CONCATENATE 'Display Message' ' ' INTO it_objtxt SEPARATED BY space. APPEND it_objtxt. CLEAR it_objtxt. it_reclist-receiver = ws_email. it_reclist-rec_type = 'U'. it_reclist-express = ' '. it_reclist-com_type = 'INT'. APPEND it_reclist. *--Set title of object and email CLEAR: w_text. doc_chng-obj_descr = 'Testing Message display'. doc_chng-obj_name = 'INBOUND'. DESCRIBE TABLE it_objtxt LINES tab_lines. READ TABLE it_objtxt INDEX tab_lines. doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( it_objtxt ). *--Move the Report Name as the Heading line for email file CLEAR: w_longtext. w_longtext = 'name of report for testing'. it_objbin = w_longtext. APPEND it_objbin. CLEAR it_objbin. *--Append Blank Lines APPEND it_objbin. CLEAR it_objbin. APPEND it_objbin. CLEAR it_objbin. **--User name CLEAR text. MOVE: 'User:' TO text, sy-uname TO text+6. it_objbin = text. APPEND it_objbin. CLEAR it_objbin. * ---appending heading to Internal table of Email CLEAR: w_matnr, w_ersda , w_ernam, w_pstat, w_lvorm, w_mtart, w_meins. w_matnr = 'Mat No.'. w_ersda = 'Creation Dt'. w_ernam = 'Person Created'. w_pstat = 'Maint Stat'. w_lvorm = 'Flg for Del'. w_mtart = 'Mat Type'. w_meins = 'UOM'. CONCATENATE w_matnr w_ersda w_ernam w_pstat w_lvorm w_mtart w_meins INTO w_longtext SEPARATED BY ','. it_objbin = w_longtext. APPEND it_objbin. CLEAR it_objbin. LOOP AT it_tab. DO. ASSIGN COMPONENT sy-index OF STRUCTURE it_tab TO <field>. IF sy-subrc <> 0. EXIT. ENDIF. * Look for Commas in the field value. If it exists, put quotes around * value so that the file opens correctly with all the columns aligned * in Excel. SEARCH <field> FOR ',' IN CHARACTER MODE. * If search for commas are successful. IF sy-subrc = 0. CONCATENATE '"' <field> '"' INTO <field> IN CHARACTER MODE. ENDIF. IF sy-index = 1. i_dload-dload = <field>. SHIFT: i_dload-dload LEFT DELETING LEADING space. ELSE. * Put Comma as a separator for values in IT_DLOAD internal table SHIFT: i_dload-dload LEFT DELETING LEADING space. CONCATENATE i_dload-dload <field> INTO i_dload-dload SEPARATED BY ',' IN CHARACTER MODE. ENDIF. ENDDO. it_objbin = i_dload-dload. APPEND it_objbin. CLEAR it_objbin. ENDLOOP. ENDIF. * ENDIF. *Convert to correct format CALL FUNCTION 'SO_RAW_TO_RTF' TABLES objcont_old = it_objbin objcont_new = it_objbin. * create the control table entry for the main email DESCRIBE TABLE it_objtxt LINES tab_lines. CLEAR it_objpack-transf_bin. it_objpack-head_start = 1. it_objpack-head_num = 0. it_objpack-body_start = 1. it_objpack-body_num = tab_lines. it_objpack-doc_type = 'RAW'. APPEND it_objpack. DESCRIBE TABLE it_objbin LINES tab_lines. it_objpack-head_start = 1. it_objpack-head_num = 0. it_objpack-body_start = 1. it_objpack-body_num = tab_lines. it_objpack-transf_bin = 'X'."'C'. it_objpack-doc_type = 'CSV'. it_objpack-obj_descr = w_filename. it_objpack-obj_name = 'BILLING'. it_objpack-doc_size = tab_lines * 255. APPEND it_objpack. CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1' EXPORTING document_data = doc_chng * PUT_IN_OUTBOX = c_x commit_work = 'X' TABLES packing_list = it_objpack * object_header = it_objhead contents_bin = it_objbin contents_txt = it_objtxt receivers = it_reclist EXCEPTIONS too_many_receivers = 1 document_not_sent = 2 operation_no_authorization = 4 OTHERS = 99. IF sy-subrc <> 0. WRITE: / 'failure in sending mail'. ELSE. WRITE: / 'Success in sending mail'. ENDIF. ENDFORM. " p_send_email