{"id":43,"date":"2023-05-03T09:53:07","date_gmt":"2023-05-03T09:53:07","guid":{"rendered":"https:\/\/sapabap.dwimansolution.com\/?p=43"},"modified":"2023-05-03T09:53:07","modified_gmt":"2023-05-03T09:53:07","slug":"simple-send-email-with-excel-attachment","status":"publish","type":"post","link":"https:\/\/sapabap.dwimansolution.com\/index.php\/2023\/05\/03\/simple-send-email-with-excel-attachment\/","title":{"rendered":"Simple Send Email with Excel Attachment"},"content":{"rendered":"\n<p>Berikut contoh program untuk mengirim email dengan menyertakan attachment berupa file excel<\/p>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;htmlmixed&quot;,&quot;mime&quot;:&quot;text\/html&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;showPanel&quot;:false,&quot;language&quot;:&quot;HTML&quot;,&quot;modeName&quot;:&quot;html&quot;}\">*---------------------------------------------------------------------*\n* Report ZTEST_SYB_10\n*---------------------------------------------------------------------*\n*\n*---------------------------------------------------------------------*\nREPORT ztest_syb_10.\nDATA: lt_mailrecipients TYPE STANDARD TABLE OF somlrec90 WITH HEADER LINE,\n      lt_mailtxt        TYPE STANDARD TABLE OF soli      WITH HEADER LINE,\n      lt_attachment     TYPE STANDARD TABLE OF solisti1  WITH HEADER LINE,\n      lt_mailsubject    TYPE sodocchgi1,\n      lt_packing_list   TYPE STANDARD TABLE OF sopcklsti1 WITH HEADER LINE,\n      gv_cnt            TYPE i.\n\n&quot;&quot;Add Recipients\nlt_mailrecipients-rec_type  = 'U'.\nlt_mailrecipients-com_type  = 'INT'.\nlt_mailrecipients-receiver  = 'someone@gmail.com'.\nAPPEND lt_mailrecipients .\nCLEAR lt_mailrecipients .\n\n&quot;&quot;Put in the Mail Contents\n\nlt_mailtxt = 'Hi How are you'.      APPEND lt_mailtxt. CLEAR lt_mailtxt.\nlt_mailtxt = 'Here is a test mail'. APPEND lt_mailtxt. CLEAR lt_mailtxt.\nlt_mailtxt = 'Thanks'.              APPEND lt_mailtxt. CLEAR lt_mailtxt.\n\n&quot;&quot;Create the attachment\n\nDATA: BEGIN OF lt_po_data_cons OCCURS 0,\n        ebeln LIKE ekpo-ebeln,\n        ebelp LIKE ekpo-ebelp,\n      END OF lt_po_data_cons.\n\nSELECT ebeln ebelp INTO TABLE lt_po_data_cons\nUP TO 10 ROWS\nFROM ekpo.\n\nCLASS cl_abap_char_utilities DEFINITION LOAD.\nCONCATENATE 'PO' 'PO Line' INTO lt_attachment SEPARATED BY cl_abap_char_utilities=&gt;horizontal_tab.\nAPPEND lt_attachment. CLEAR lt_attachment.\n\nLOOP AT lt_po_data_cons.\n  CONCATENATE lt_po_data_cons-ebeln lt_po_data_cons-ebelp INTO lt_attachment SEPARATED BY cl_abap_char_utilities=&gt;horizontal_tab.\n\n  CONCATENATE cl_abap_char_utilities=&gt;newline lt_attachment INTO lt_attachment.\n\n  APPEND lt_attachment. CLEAR lt_attachment.\nENDLOOP.\n\n\n&quot;&quot;Pack the mail contents and attachment\n\nlt_packing_list-transf_bin  = space.\nlt_packing_list-head_start  = 1.\nlt_packing_list-head_num    = 0.\nlt_packing_list-body_start  = 1.\nlt_packing_list-body_num    = lines( lt_mailtxt ).\nlt_packing_list-doc_type    = 'RAW'.\nAPPEND lt_packing_list. CLEAR lt_packing_list.\n\nlt_packing_list-transf_bin  = 'X'.\nlt_packing_list-head_start  = 1.\nlt_packing_list-head_num    = 1.\nlt_packing_list-body_start  = 1.\nlt_packing_list-body_num    = lines( lt_attachment ).\nlt_packing_list-doc_type    = 'XLSX'. &quot; You can give RAW incase if you want just a txt file.\nlt_packing_list-obj_name    = 'data.xlsx'.\nlt_packing_list-obj_descr   = 'data.xlsx'.\nlt_packing_list-doc_size    = lt_packing_list-body_num * 255.\nAPPEND lt_packing_list. CLEAR lt_packing_list.\n\nlt_mailsubject-obj_name     = 'MAILATTCH'.\nlt_mailsubject-obj_langu    = sy-langu.\nlt_mailsubject-obj_descr    = 'Test Email'.\nlt_mailsubject-sensitivty   = 'F'.\ngv_cnt = lines( lt_attachment ).\nlt_mailsubject-doc_size     = ( gv_cnt - 1 ) * 255 + strlen(\nlt_attachment ).\n\n&quot;send the mail out. Just call the function module to send the mail out.\n\nCALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'\n  EXPORTING\n    document_data              = lt_mailsubject\n  TABLES\n    packing_list               = lt_packing_list\n    contents_bin               = lt_attachment\n    contents_txt               = lt_mailtxt\n    receivers                  = lt_mailrecipients\n  EXCEPTIONS\n    too_many_receivers         = 1\n    document_not_sent          = 2\n    document_type_not_exist    = 3\n    operation_no_authorization = 4\n    parameter_error            = 5\n    x_error                    = 6\n    enqueue_error              = 7\n    OTHERS                     = 8.\nIF sy-subrc EQ 0.\n  COMMIT WORK.\n  SUBMIT rsconn01 WITH mode = 'INT' AND RETURN.\nENDIF.<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Berikut contoh program untuk mengirim email dengan menyertakan attachment berupa file excel<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/sapabap.dwimansolution.com\/index.php\/wp-json\/wp\/v2\/posts\/43"}],"collection":[{"href":"https:\/\/sapabap.dwimansolution.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sapabap.dwimansolution.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sapabap.dwimansolution.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sapabap.dwimansolution.com\/index.php\/wp-json\/wp\/v2\/comments?post=43"}],"version-history":[{"count":5,"href":"https:\/\/sapabap.dwimansolution.com\/index.php\/wp-json\/wp\/v2\/posts\/43\/revisions"}],"predecessor-version":[{"id":68,"href":"https:\/\/sapabap.dwimansolution.com\/index.php\/wp-json\/wp\/v2\/posts\/43\/revisions\/68"}],"wp:attachment":[{"href":"https:\/\/sapabap.dwimansolution.com\/index.php\/wp-json\/wp\/v2\/media?parent=43"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sapabap.dwimansolution.com\/index.php\/wp-json\/wp\/v2\/categories?post=43"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sapabap.dwimansolution.com\/index.php\/wp-json\/wp\/v2\/tags?post=43"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}