{"id":40,"date":"2018-08-20T21:07:23","date_gmt":"2018-08-20T21:07:23","guid":{"rendered":"http:\/\/www.sapforbeginners.com\/blog\/?p=40"},"modified":"2018-08-20T21:07:23","modified_gmt":"2018-08-20T21:07:23","slug":"send-internal-tables-in-an-e-mail-as-excel-attachments-using-function-module","status":"publish","type":"post","link":"https:\/\/www.sapforbeginners.com\/blog\/send-internal-tables-in-an-e-mail-as-excel-attachments-using-function-module\/","title":{"rendered":"Send Internal Tables in an e-Mail as Excel attachments using Function Module"},"content":{"rendered":"\r\n\r\n<strong>Introduction:<\/strong>\r\n\r\n\r\n\r\n\r\n\r\nWe are going to create a program that uses \u201cSO_NEW_DOCUMENT_ATT_SEND_API1\u201d function module to send two internal tables in an e-mail as separate excel attachments.\r\n\r\n\r\n\r\n\r\n\r\n<strong>Explanation:<\/strong>\r\n\r\n\r\n\r\n\r\n\r\nI am abstaining from writing any explanations on below snippet as it is a simple program and easy to understand. We build couple of internal tables and attach the two internal tables \u201cIT_ITAB1\u201d &amp; \u201cIT_ITAB2\u201d as two separate excel attachments in the e-mail. The only part that you might be wondering is the use of the program &#8220;RSCONN01&#8221; and the program queues the email. Please feel free to comment below if you have any queries or issues in following the post.\r\n<pre class=\"lang:default decode:true\">*&amp;---------------------------------------------------------------------*\r\n*&amp; Report  Z_ITAB_MAIL\r\n*&amp;\r\n*&amp;---------------------------------------------------------------------*\r\n*&amp;\r\n*&amp;\r\n*&amp;---------------------------------------------------------------------*\r\n\r\nREPORT  z_itab_mail.\r\n\r\n*Global Top\r\nCLASS: cl_abap_char_utilities DEFINITION LOAD.\r\nDATA: docdata            TYPE sodocchgi1,\r\n      gs_objpack         TYPE sopcklsti1,\r\n      it_objpack         TYPE STANDARD TABLE OF sopcklsti1,\r\n      it_objtxt          TYPE STANDARD TABLE OF solisti1,\r\n      it_objbin1         TYPE STANDARD TABLE OF solisti1,\r\n      it_objbin2         TYPE STANDARD TABLE OF solisti1,\r\n      it_objbin_final    TYPE STANDARD TABLE OF solisti1,\r\n      it_reclist         TYPE STANDARD TABLE OF somlreci1,\r\n      gs_objtxt          TYPE solisti1,\r\n      gs_objbin1         TYPE solisti1,\r\n      gs_objbin2         TYPE solisti1,\r\n      gs_objbin_final    TYPE solisti1,\r\n      gs_reclist         TYPE somlreci1,\r\n      tab_lines          TYPE sy-tabix.\r\n\r\nDATA: gd_sender_type  TYPE so_adr_typ.\r\nDATA: c_tab           TYPE c            VALUE cl_abap_char_utilities=&gt;horizontal_tab,\r\n      c_ret           TYPE c            VALUE cl_abap_char_utilities=&gt;cr_lf.\r\nDATA: c_dev TYPE sy-sysid.\r\nTYPES: BEGIN OF i_data,\r\n      a(20),\r\n      b(20),\r\n      END OF i_data.\r\nTYPES: BEGIN OF st,\r\n      f1(2) TYPE c,\r\n      f2(2) TYPE n,\r\n      END OF st.\r\nDATA: it_itab1 TYPE STANDARD TABLE OF st,\r\n      gs_itab1 TYPE                   st,\r\n      it_itab2 TYPE STANDARD TABLE OF st,\r\n      gs_itab2 TYPE                   st.\r\nDATA: n TYPE i.\r\n\r\n\r\n*Selection Screen\r\nPARAMETER: p_email1 TYPE so_recname\r\n                    DEFAULT 'admin@sapforbeginners.com',\r\n           p_sender LIKE somlreci1-receiver.\r\n\r\n*Start of Selection\r\nSTART-OF-SELECTION.\r\n\r\n*Begin of preparing two internal tables with random data\r\n  gs_itab1-f1 = 'Row1 Column1'.\r\n  gs_itab1-f2 = 'Row1 Column2'.\r\n  APPEND gs_itab1 TO it_itab1.\r\n  CLEAR gs_itab1.\r\n\r\n  gs_itab1-f1 = 'Row2 Column1'.\r\n  gs_itab1-f2 = 'Row2 Column2'.\r\n  APPEND gs_itab1 TO it_itab1.\r\n  CLEAR gs_itab1.\r\n\r\n  gs_itab1-f1 = 'Row3 Column1'.\r\n  gs_itab1-f2 = 'Row3 Column2'.\r\n  APPEND gs_itab1 TO it_itab1.\r\n  CLEAR gs_itab1.\r\n\r\n  gs_itab2-f1 = 'Row1 Column1'.\r\n  gs_itab2-f2 = 'Row1 Column2'.\r\n  APPEND gs_itab2 TO it_itab2.\r\n  CLEAR gs_itab2.\r\n\r\n  gs_itab2-f1 = 'Row2 Column1'.\r\n  gs_itab2-f2 = 'Row2 Column2'.\r\n  APPEND gs_itab2 TO it_itab2.\r\n  CLEAR gs_itab2.\r\n\r\n  gs_itab2-f1 = 'Row3 Column1'.\r\n  gs_itab2-f2 = 'Row3 Column2'.\r\n  APPEND gs_itab2 TO it_itab2.\r\n  CLEAR gs_itab2.\r\n*End of internal table data\r\n\r\n\r\n  LOOP AT it_itab1 INTO gs_itab1.\r\n    CONCATENATE gs_itab1-f1 gs_itab1-f2 INTO gs_objbin1 SEPARATED BY c_tab.\r\n    CONCATENATE c_ret gs_objbin1 INTO gs_objbin1.\r\n    APPEND gs_objbin1 TO it_objbin1.\r\n  ENDLOOP.\r\n  CLEAR: gs_objbin1, gs_itab1.\r\n\r\n  LOOP AT it_itab2 INTO gs_itab2.\r\n    CONCATENATE gs_itab2-f1 gs_itab2-f2 INTO gs_objbin2 SEPARATED BY c_tab.\r\n    CONCATENATE c_ret gs_objbin2 INTO gs_objbin2.\r\n    APPEND gs_objbin2 TO it_objbin2.\r\n  ENDLOOP.\r\n  CLEAR: gs_objbin2, gs_itab2.\r\n\r\n  LOOP AT it_objbin1 INTO gs_objbin1.\r\n    MOVE gs_objbin1-line TO gs_objbin_final-line.\r\n    APPEND gs_objbin_final TO it_objbin_final.\r\n  ENDLOOP.\r\n  CLEAR: gs_objbin_final, gs_objbin1.\r\n\r\n  LOOP AT it_objbin2 INTO gs_objbin2.\r\n    MOVE gs_objbin2-line TO gs_objbin_final-line.\r\n    APPEND gs_objbin_final TO it_objbin_final.\r\n  ENDLOOP.\r\n  CLEAR: gs_objbin2, gs_objbin_final.\r\n\r\n  PERFORM process_email.\r\n\r\n  c_dev = sy-sysid.\r\n  IF sy-sysid = c_dev.\r\n    WAIT UP TO 5 SECONDS.\r\n    SUBMIT rsconn01 WITH mode = 'INT'\r\n    WITH output = 'X'\r\n    AND RETURN.\r\n  ENDIF.\r\n  IF sy-subrc = 0.\r\n    WRITE: \/ 'Email succesfilly delivered'.\r\n  ELSE.\r\n    WRITE: \/ 'Email could not be delivered'.\r\n  ENDIF.\r\n\r\n<\/pre>","protected":false},"excerpt":{"rendered":"<p>Introduction: We are going to create a program that uses \u201cSO_NEW_DOCUMENT_ATT_SEND_API1\u201d function module to send two internal tables in an e-mail as separate excel attachments. Explanation: I am abstaining from writing any explanations on below snippet as it is a simple program and easy to understand. We build couple of internal tables and attach the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[9],"class_list":["post-40","post","type-post","status-publish","format-standard","hentry","category-abap","tag-email"],"_links":{"self":[{"href":"https:\/\/www.sapforbeginners.com\/blog\/wp-json\/wp\/v2\/posts\/40","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sapforbeginners.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sapforbeginners.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sapforbeginners.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sapforbeginners.com\/blog\/wp-json\/wp\/v2\/comments?post=40"}],"version-history":[{"count":5,"href":"https:\/\/www.sapforbeginners.com\/blog\/wp-json\/wp\/v2\/posts\/40\/revisions"}],"predecessor-version":[{"id":45,"href":"https:\/\/www.sapforbeginners.com\/blog\/wp-json\/wp\/v2\/posts\/40\/revisions\/45"}],"wp:attachment":[{"href":"https:\/\/www.sapforbeginners.com\/blog\/wp-json\/wp\/v2\/media?parent=40"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sapforbeginners.com\/blog\/wp-json\/wp\/v2\/categories?post=40"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sapforbeginners.com\/blog\/wp-json\/wp\/v2\/tags?post=40"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}