Excel attachment in mail

Hi all,
        I have an issue in sending mail as an excel attachment .
i am getting some records in the excel sheet as single line and some are coming correctly. here is the sample code.
ie. some records coming line by line, but some record for eg the 6th and 7th record is coming in the 6th line only .here is the coding part for that
CONCATENATE ' '
                    I_SHIP_HEAD-TKNUM
                    L_DATEB
                    VD
                    I_SHIP_HEAD-EXTI1
                    I_SHIP_HEAD-TPBEZ
                    I_SHIP_HEAD-SIGNI
                    I_SHIP_HEAD-EXTI2
                    L_NETWR
                    L_DMBTR
                    I_SHIP_HEAD-TNDR_TRKID
                    MODE
                    L_ALLOWED_TWGT
                    I_INV-VBELN
                    L_INVDAT
                    I_INV-VSTEL
                    I_INV-KUNRG
                   L_ETADATE
                    I_INV-SPART
                    I_INV-MATNR
                    I_INV-ARKTX
                   I_INV-MATKL
                    L_FKIMG
                    L_WT
                    L_VOL
                    L_DIFFVAL
                    CON_CRET
                    INTO I_BIN SEPARATED BY CON_TAB.
        APPEND I_BIN .
        CLEAR I_BIN.
suggest me a solution.
Thanks & Regards
Magesh Anandan

Hi,
check the following sample program and also its easy to understand.
REPORT  zvenkat_mail_xls_attach.
"  Data retrieval related declarations
TYPES:
     BEGIN OF t_emp_dat,
       pernr TYPE pa0001-pernr,
       persg TYPE pa0001-persg,
       persk TYPE pa0001-persk,
       plans TYPE pa0001-plans,
       stell TYPE pa0001-stell,
     END OF t_emp_dat.
DATA:
     w_emp_data TYPE t_emp_dat.
DATA:
     i_emp_data TYPE STANDARD TABLE OF t_emp_dat.
"  Mail related declarations
"Variables
DATA :
     g_sent_to_all   TYPE sonv-flag,
     g_tab_lines     TYPE i.
"Types
TYPES:
     t_document_data  TYPE  sodocchgi1,
     t_packing_list   TYPE  sopcklsti1,
     t_attachment     TYPE  solisti1,
     t_body_msg       TYPE  solisti1,
     t_receivers      TYPE  somlreci1.
"Workareas
DATA :
     w_document_data  TYPE  t_document_data,
     w_packing_list   TYPE  t_packing_list,
     w_attachment     TYPE  t_attachment,
     w_body_msg       TYPE  t_body_msg,
     w_receivers      TYPE  t_receivers.
"Internal Tables
DATA :
     i_document_data  TYPE STANDARD TABLE OF t_document_data,
     i_packing_list   TYPE STANDARD TABLE OF t_packing_list,
     i_attachment     TYPE STANDARD TABLE OF t_attachment,
     i_body_msg       TYPE STANDARD TABLE OF t_body_msg,
     i_receivers      TYPE STANDARD TABLE OF t_receivers.
"Start-of-selection.
START-OF-SELECTION.
  PERFORM get_data.
  PERFORM build_xls_data_table.
  "End-of-selection.
END-OF-SELECTION.
  PERFORM send_mail.
  "Form  get_data from PA0001
FORM get_data.
  SELECT pernr
         persg
         persk
         plans
         stell
   FROM pa0001
   INTO CORRESPONDING FIELDS OF TABLE i_emp_data
   UP TO 4 ROWS.
ENDFORM.                    " get_data
"Form  build_xls_data_table
FORM build_xls_data_table.
  "If you have Unicode check active in program attributes then
  "you will need to declare constants as follows.
  CLASS cl_abap_char_utilities DEFINITION LOAD.
  CONSTANTS:
      con_tab  TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,
      con_cret TYPE c VALUE cl_abap_char_utilities=>cr_lf.
  CONCATENATE 'PERNR' 'PERSG' 'PERSK' 'PLANS' 'STELL'
         INTO  w_attachment
SEPARATED BY  con_tab.
  CONCATENATE con_cret
              w_attachment
         INTO w_attachment.
  APPEND w_attachment TO i_attachment.
  CLEAR  w_attachment.
  LOOP AT i_emp_data INTO w_emp_data.
    CONCATENATE w_emp_data-pernr
                w_emp_data-persg
                w_emp_data-persk
                w_emp_data-plans
                w_emp_data-stell
           INTO w_attachment
   SEPARATED BY con_tab.
    CONCATENATE con_cret w_attachment
           INTO w_attachment.
    APPEND w_attachment TO i_attachment.
    CLEAR  w_attachment.
  ENDLOOP.
ENDFORM.                    "build_xls_data_table
"Form  send_mail
"PACKING LIST
"This table requires information about how the data in the
"tables OBJECT_HEADER, CONTENTS_BIN and CONTENTS_TXT are to
"be distributed to the documents and its attachments.The first
"row is for the document, the following rows are each for one
"attachment.
FORM send_mail .
  "Subject of the mail.
  w_document_data-obj_name  = 'MAIL_TO_HEAD'.
  w_document_data-obj_descr = 'Regarding Mail Program by SAP ABAP'.
  "Body of the mail
  PERFORM build_body_of_mail
    USING:space,
          'Hi,',
          'I am fine. How are you? How are you doing ? ',
          'This program has been created to send simple mail',
          'with Subject,Body with Address of the sender. ',
          'Regards,',
          'Venkat.O,',
          'SAP HR Technical Consultant.'.
  "Write Packing List for Body
  DESCRIBE TABLE i_body_msg LINES g_tab_lines.
  w_packing_list-head_start = 1.
  w_packing_list-head_num   = 0.
  w_packing_list-body_start = 1.
  w_packing_list-body_num   = g_tab_lines.
  w_packing_list-doc_type   = 'RAW'.
  APPEND w_packing_list TO i_packing_list.
  CLEAR  w_packing_list.
  "Write Packing List for Attachment
  w_packing_list-transf_bin = 'X'.
  w_packing_list-head_start = 1.
  w_packing_list-head_num   = 1.
  w_packing_list-body_start = 1.
  DESCRIBE TABLE i_attachment LINES w_packing_list-body_num.
  w_packing_list-doc_type   = 'XLS'.
  w_packing_list-obj_descr  = 'Excell Attachment'.
  w_packing_list-obj_name   = 'XLS_ATTACHMENT'.
  w_packing_list-doc_size   = w_packing_list-body_num * 255.
  APPEND w_packing_list TO i_packing_list.
  CLEAR  w_packing_list.
  "Fill the document data and get size of attachment
  w_document_data-obj_langu  = sy-langu.
  READ TABLE i_attachment INTO w_attachment INDEX g_tab_lines.
  w_document_data-doc_size = ( g_tab_lines - 1 ) * 255 + STRLEN(
w_attachment ).
  "Receivers List.
  w_receivers-rec_type   = 'U'.  "Internet address
  w_receivers-receiver   = '[email protected]'.
  w_receivers-com_type   = 'INT'.
  w_receivers-notif_del  = 'X'.
  w_receivers-notif_ndel = 'X'.
  APPEND w_receivers TO i_receivers .
  CLEAR:w_receivers.
  "Function module to send mail to Recipients
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = w_document_data
      put_in_outbox              = 'X'
      commit_work                = 'X'
    IMPORTING
      sent_to_all                = g_sent_to_all
    TABLES
      packing_list               = i_packing_list
      contents_bin               = i_attachment
      contents_txt               = i_body_msg
      receivers                  = i_receivers
    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.
  IF sy-subrc = 0 .
    MESSAGE i303(me) WITH 'Mail has been Successfully Sent.'.
  ELSE.
    WAIT UP TO 2 SECONDS.
    "This program starts the SAPconnect send process.
    SUBMIT rsconn01 WITH mode = 'INT'
                 WITH output = 'X'
                 AND RETURN.
  ENDIF.
ENDFORM.                    " send_mail
"      Form  build_body_of_mail
FORM build_body_of_mail  USING l_message.
  w_body_msg = l_message.
  APPEND w_body_msg TO i_body_msg.
  CLEAR  w_body_msg.
ENDFORM.                    " build_body_of_mail
I hope that it helps you something.
Regards,
Venkat.O

Similar Messages

  • Send an Excel Attachment as mail to a list of recipients

    Hello Everyone,
    I am trying to send an email with an excel attachment. My code has been activated successfully. But I haven't received any mail.
    Kindly help.
    My code is as below.
    FORM Z_SENDMAIL .
      DATA lv_receiver type SOMLRECI1-RECEIVER.
      TYPES: BEGIN OF LTS_CHARFINAL,
        matnr(18) type c,
        maktx(40) type c,
        idnlf(35) type c,
        ltsnr(6) type c,
        werks(4) type c,
        ltsbz(20) type c,
        ernam(12) type c,
        verpr(11) type c,
        soh_qty(13) TYPE c,
        int_qty(13) TYPE c,
        ext_soh(11) TYPE c,
        hol_qty(13) TYPE c,
        all_qty(13) TYPE c,
        bac_qty(13) TYPE c,
        ext_ttl(11) TYPE c,
        END OF LTS_CHARFINAL.
      DATA: WA_CHARFINAL TYPE LTS_CHARFINAL.
      lv_receiver = '[email protected]'.
      CONCATENATE 'ITEM_TRIM'
                  'DESCRIPTION'
                  'VEND_ITEM'
                  'PLNRCODE'
                  'LOCATION'
                  'SITE'
                  'PLANNER'
                  'AVERAGE_COST'
                  'SOH_QTY'
                  'INTRANS_QTY'
                  'EXT_COST_SOH'
                  'HOLD_QTY'
                  'ALLOC_QTY'
                  'BACKORD_QTY'
                  'EXT_COST_TTL_INVEN'
             INTO IT_ATTACH SEPARATED BY CON_TAB.
      CONCATENATE CON_CRET IT_ATTACH  INTO IT_ATTACH.
      APPEND  IT_ATTACH.
      LOOP AT GIT_FINAL INTO GWA_FINAL.
        wa_charfinal-matnr = gwa_final-matnr.
        wa_charfinal-maktx = gwa_final-maktx.
        wa_charfinal-idnlf = gwa_final-idnlf.
        wa_charfinal-ltsnr = gwa_final-ltsnr.
        wa_charfinal-werks = gwa_final-werks.
        wa_charfinal-ltsbz = gwa_final-ltsbz.
        wa_charfinal-ernam = gwa_final-ernam.
        wa_charfinal-verpr = gwa_final-verpr.
        wa_charfinal-soh_qty = gwa_final-soh_qty.
        wa_charfinal-int_qty = gwa_final-int_qty.
        wa_charfinal-ext_soh = gwa_final-ext_soh.
        wa_charfinal-hol_qty = gwa_final-hol_qty.
        wa_charfinal-all_qty = gwa_final-all_qty.
        wa_charfinal-bac_qty = gwa_final-bac_qty.
        wa_charfinal-ext_ttl = gwa_final-ext_ttl.
        CONCATENATE wa_charfinal-matnr
                    wa_charfinal-maktx
                    wa_charfinal-idnlf
                    wa_charfinal-ltsnr
                    wa_charfinal-werks
                    wa_charfinal-ltsbz
                    wa_charfinal-ernam
                    wa_charfinal-verpr
                    wa_charfinal-soh_qty
                    wa_charfinal-int_qty
                    wa_charfinal-ext_soh
                    wa_charfinal-hol_qty
                    wa_charfinal-all_qty
                    wa_charfinal-bac_qty
                    wa_charfinal-ext_ttl
               INTO IT_ATTACH SEPARATED BY CON_TAB.
        CONCATENATE CON_CRET IT_ATTACH  INTO IT_ATTACH.
        APPEND  IT_ATTACH.
      ENDLOOP.
        PERFORM Z_BUILD_MESSAGE.
        PERFORM Z_SEND_FILE_ATTACHMENT
                                   TABLES IT_MESSAGE
                                          IT_ATTACH
                                    USING lv_receiver
                                          'Example .xls documnet attachment'
                                          'XLS'
                                          'filename'
                                 CHANGING GD_ERROR
                                          GD_RECIEVER.
    ENDFORM.
    FORM Z_BUILD_MESSAGE .
      REFRESH IT_MESSAGE.
      IT_MESSAGE = 'Please find the attached document'.
      APPEND IT_MESSAGE.
    ENDFORM.                    " Z_BUILD_MESSAGE
    FORM Z_SEND_FILE_ATTACHMENT  TABLES   P_IT_MESSAGE
                                          P_IT_ATTACH STRUCTURE IT_ATTACH
                                 USING    P_lv_receiver
                                          P_MTITLE
                                          P_FORMAT
                                          P_FILENAME
                                          P_ATTDESCRIPTION
                                          P_SENDER_ADDRESS
                                          P_SENDER_ADDRES_TYPE
                                 CHANGING P_ERROR
                                          P_RECIEVER.
    DATA: LD_ERROR    TYPE SY-SUBRC,
            LD_RECIEVER TYPE SY-SUBRC,
            LD_MTITLE LIKE SODOCCHGI1-OBJ_DESCR,
            LD_EMAIL LIKE  SOMLRECI1-RECEIVER,
            LD_FORMAT TYPE  SO_OBJ_TP ,
            LD_ATTDESCRIPTION TYPE  SO_OBJ_NAM ,
            LD_ATTFILENAME TYPE  SO_OBJ_DES ,
            LD_SENDER_ADDRESS LIKE  SOEXTRECI1-RECEIVER,
            LD_SENDER_ADDRESS_TYPE LIKE  SOEXTRECI1-ADR_TYP,
            LD_RECEIVER LIKE  SY-SUBRC.
      LD_EMAIL   = P_LV_RECEIVER.
      LD_MTITLE = P_MTITLE.
      LD_FORMAT              = P_FORMAT.
      LD_ATTDESCRIPTION      = P_ATTDESCRIPTION.
      LD_ATTFILENAME         = P_FILENAME.
      LD_SENDER_ADDRESS      = P_SENDER_ADDRESS.
      LD_SENDER_ADDRESS_TYPE = P_SENDER_ADDRES_TYPE.
    * Fill the document data.
      W_DOC_DATA-DOC_SIZE = 1.
    * Populate the subject/generic message attributes
      W_DOC_DATA-OBJ_LANGU = SY-LANGU.
      W_DOC_DATA-OBJ_NAME  = 'SAPRPT'.
      W_DOC_DATA-OBJ_DESCR = LD_MTITLE .
      W_DOC_DATA-SENSITIVTY = 'F'.
    * Fill the document data and get size of attachment
      CLEAR W_DOC_DATA.
      READ TABLE IT_ATTACH INDEX W_CNT.
      W_DOC_DATA-DOC_SIZE =
         ( W_CNT - 1 ) * 255 + STRLEN( IT_ATTACH ).
      W_DOC_DATA-OBJ_LANGU  = SY-LANGU.
      W_DOC_DATA-OBJ_NAME   = 'SAPRPT'.
      W_DOC_DATA-OBJ_DESCR  = LD_MTITLE.
      W_DOC_DATA-SENSITIVTY = 'F'.
      CLEAR T_ATTACHMENT.
      REFRESH T_ATTACHMENT.
      T_ATTACHMENT[] = P_IT_ATTACH[].
    * Describe the body of the message
      CLEAR T_PACKING_LIST.
      REFRESH T_PACKING_LIST.
      T_PACKING_LIST-TRANSF_BIN = SPACE.
      T_PACKING_LIST-HEAD_START = 1.
      T_PACKING_LIST-HEAD_NUM = 0.
      T_PACKING_LIST-BODY_START = 1.
      DESCRIBE TABLE IT_MESSAGE LINES T_PACKING_LIST-BODY_NUM.
      T_PACKING_LIST-DOC_TYPE = 'RAW'.
      APPEND T_PACKING_LIST.
    * Create attachment notification
      T_PACKING_LIST-TRANSF_BIN = 'X'.
      T_PACKING_LIST-HEAD_START = 1.
      T_PACKING_LIST-HEAD_NUM   = 1.
      T_PACKING_LIST-BODY_START = 1.
    DESCRIBE TABLE T_ATTACHMENT LINES T_PACKING_LIST-BODY_NUM.
      T_PACKING_LIST-DOC_TYPE   =  LD_FORMAT.
      T_PACKING_LIST-OBJ_DESCR  =  LD_ATTDESCRIPTION.
      T_PACKING_LIST-OBJ_NAME   =  LD_ATTFILENAME.
      T_PACKING_LIST-DOC_SIZE   =  T_PACKING_LIST-BODY_NUM * 255.
      APPEND T_PACKING_LIST.
    * Add the recipients email address
      CLEAR T_RECEIVERS.
      REFRESH T_RECEIVERS.
      T_RECEIVERS-RECEIVER = LD_EMAIL.
      T_RECEIVERS-REC_TYPE = 'U'.
      T_RECEIVERS-COM_TYPE = 'INT'.
      T_RECEIVERS-NOTIF_DEL = 'X'.
      T_RECEIVERS-NOTIF_NDEL = 'X'.
      APPEND T_RECEIVERS.
      CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
           EXPORTING
                DOCUMENT_DATA              = W_DOC_DATA
                PUT_IN_OUTBOX              = 'X'
                SENDER_ADDRESS             = LD_SENDER_ADDRESS
                SENDER_ADDRESS_TYPE        = LD_SENDER_ADDRESS_TYPE
                COMMIT_WORK                = 'X'
           IMPORTING
                SENT_TO_ALL                = W_SENT_ALL
           TABLES
                PACKING_LIST               = T_PACKING_LIST
                CONTENTS_BIN               = T_ATTACHMENT
                CONTENTS_TXT               = IT_MESSAGE
                RECEIVERS                  = T_RECEIVERS
           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.
    * Populate zerror return code
      LD_ERROR = SY-SUBRC.
    * Populate zreceiver return code
      LOOP AT T_RECEIVERS.
        LD_RECEIVER = T_RECEIVERS-RETRN_CODE.
      ENDLOOP.
    ENDFORM.                    " Z_SEND_FILE_ATTACHMENT
    -Regards
    Monica

    Hi Monica,
    Please check with your BASIS team if all the required configurations are there to send mail.
    You can check in SOST transaction if you have an entry there for your mail.
    Another relevant transaction in SCOT.
    Regards,
    Santanu.

  • Excel attachment in mailing program

    Hi,
    I am sending excel attachment in the mailing program.
    The attachment contains 56 lines, but the problem is the attachment which is coming with 22 line only in mail .
    What may be the problem?
    Regards,

    Please debug and check the internal table before the Mail FM, whether all lines are there.

  • Arabic text in excel attachment in mail

    my requirement is to mail the excel file so I used the internal table
    to create an excel and used FM SO_NEW_DOCUMENT_ATT_SEND_API1, While the
    excel file is created but however the arabic is not downloaded
    correctly. It is downloaded with junk characters.
    CONSTANTS:y_k_con_tab TYPE c VALUE
    cl_abap_char_utilities=>horizontal_tab,
    y_k_con_cret TYPE c VALUE
    cl_abap_char_utilities=>cr_lf.
    LOOP AT lt_output INTO ls_output.
    MOVE ls_output-zdate_changed TO lv_datechanged.
    MOVE ls_output-zdate_created TO lv_datecreated.
    CONCATENATE ''''
    lv_datechanged
    INTO lv_datechanged.
    CONCATENATE ''''
    lv_datecreated
    INTO lv_datecreated.
    *Concatenate text fields to send the email in the r=uired format.
    CONCATENATE ls_output-zexcess
    ls_output-zbranch
    ls_output-znotes
    ls_output-zstatus
    lv_datechanged
    ls_output-zdate_changed
    ls_output-zemp_changed
    ls_output-zinitial_status
    lv_datecreated
    ls_output-zdate_created
    ls_output-zemp_created
    ls_output-zproduct_name
    ls_output-zministry_name
    ls_output-zentity_name
    ls_output-zposting_date
    ls_output-zservice_id
    INTO y_wa_htop_new SEPARATED BY y_k_con_tab .
    CONCATENATE y_k_con_cret
    y_wa_htop_new
    INTO y_wa_htop_new .
    APPEND y_wa_htop_new TO y_i_htop_new.
    CLEAR: y_wa_htop_new.
    ENDLOOP.
    *ENDLOOP.
    i_attachment] = y_i_htop_new[.
    SUBJECT OF THE MAIL.
    w_document_data-obj_name = 'MAIL_TO_HEAD'.
    w_document_data-obj_descr = text-001.
    BODY OF THE MAIL
    w_body_msg = text-002.
    APPEND w_body_msg TO i_body_msg.
    CLEAR w_body_msg.
    w_body_msg = space.
    APPEND w_body_msg TO i_body_msg.
    CLEAR w_body_msg.
    w_body_msg = text-003.
    APPEND w_body_msg TO i_body_msg.
    CLEAR w_body_msg.
    w_body_msg = space.
    APPEND w_body_msg TO i_body_msg.
    CLEAR w_body_msg.
    w_body_msg = text-004.
    APPEND w_body_msg TO i_body_msg.
    CLEAR w_body_msg.
    w_body_msg = space.
    APPEND w_body_msg TO i_body_msg.
    CLEAR w_body_msg.
    w_body_msg = text-005.
    APPEND w_body_msg TO i_body_msg.
    CLEAR w_body_msg.
    WRITE PACKING LIST FOR BODY
    DESCRIBE TABLE i_body_msg LINES g_tab_lines.
    *describe table i_attachment lines g_tab_lines.
    w_packing_list-head_start = 1.
    w_packing_list-head_num = 0.
    w_packing_list-body_start = 1.
    w_packing_list-body_num = g_tab_lines.
    w_packing_list-doc_type = 'RAW'.
    APPEND w_packing_list TO i_packing_list.
    CLEAR w_packing_list.
    WRITE PACKING LIST FOR ATTACHMENT
    w_packing_list-transf_bin = 'X'.
    w_packing_list-head_start = 1.
    w_packing_list-head_num = 1.
    w_packing_list-body_start = 1.
    DESCRIBE TABLE i_attachment LINES w_packing_list-body_num.
    w_packing_list-doc_type = 'XLS'.
    w_packing_list-obj_descr = 'Service_Details'.
    w_packing_list-obj_name = 'Service_Details'.
    w_packing_list-OBJ_LANGU = 'A'.
    w_packing_list-doc_size = w_packing_list-body_num * 255.
    APPEND w_packing_list TO i_packing_list.
    CLEAR w_packing_list.
    FILL THE DOCUMENT DATA &GET SIZE OF ATTACHMENT
    w_document_data-obj_langu = sy-langu.
    READ TABLE i_attachment INTO w_attachment INDEX g_tab_lines.
    w_document_data-doc_size = ( g_tab_lines - 1 ) * 255 + STRLEN(
    w_attachment ).
    RECEIVERS LIST.
    w_receivers-rec_type = 'U'. "Internet address
    w_receivers-receiver = y_lv_emailid.
    w_receivers-com_type = 'INT'.
    w_receivers-notif_del = 'X'.
    w_receivers-notif_ndel = 'X'.
    APPEND w_receivers TO i_receivers .
    CLEAR:w_receivers.
    SEND MAILS TO RECIPIENTS
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
    document_data = w_document_data
    put_in_outbox = 'X'
    commit_work = 'X'
    IMPORTING
    sent_to_all = g_sent_to_all
    TABLES
    packing_list = i_packing_list
    contents_bin = i_attachment
    contents_txt = i_body_msg
    receivers = i_receivers
    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.
    IF sy-subrc = 0 .
    *MESSAGE s WITH 'Mail has been Successfully Sent.'.
    ENDIF.
    Kindly suggest how will I get arabic downloaded and sent as attachment
    in email. Can I write a file to application server and send that
    particular file as attachement? Can I use BCS class for mailing excel
    file? Will it support arabic text?

    with Excel it is always a good idea to encode your data in UTF-16 LE.
    to do so, take your internal table in SOLI format and call
    CL_BCS_CONVERT=>TXT_TO_SOLIX
    with iv_codepage = 4103 and iv_add_bom = 'X'.
    you will get a binary table SOLIX as a result and just have to attach it to your message

  • Add Excel-attachment in Mail

    Hi,
    I have done a script within Automator that does take filtered information in one Excel-file and copy it to another and close it. I choose a name for it and saves it. Could I get it to automatically attach this file inside a mail document in Mail.app and let me send it manually?
    I also would like it to automatically uncheck 1904 Date option inside Excel prefs.

    If you know the name of the workbook, then add this applescript to the workflow, while the file is still open.on run {input, parameters}
    tell application "Microsoft Excel"
    set the date 1904 of workbook "Sheet1" to not the date 1904 of workbook "Sheet1"
    send mail workbook "Sheet1"
    end tell
    return input
    end runSubstitute the name of the workbook for Sheet1
    I couldn't get any of the excel actions to pass the name into the Applescript action.
    As for emailing, I can't get Excel to pass any of it's action results onto anything but it's own actions. They don't seem to be very well written. Normally, you'd just add a "New Mail Message" action after something and the output from the previous action would be the content for the new mail message.
    Due to Microsoft's shortcomings, there doesn't seem to be a way to do that without using the "send mail" function in Excel's Applescript dictionary.
    If you need to do more Applescripting of Excel (or Office), see the [VBA to Applescript Transition Guide|http://www.mactech.com/vba-transition-guide>. It is geared towards converting from VBA to Applescript, but it has many examples of how to automate various tasks.
    Message was edited by: Barney-15E

  • Query regarding Excel attachment to mail

    Hi all,
         I am passing spool no. and download path to 'RSPO_DOWNLOAD_SPOOLJOB' to the function module. I am getting the file stored at specified path in 'RAW' format. Now using GUI_UPLOAD to get the excel file data into internal table i_texts.
         This excel gets attached to the mail. Since data is in RAW format, I have to pick line by line data. So I am not able to get the data column by column and data appended to the attached mail as line by line. So data redability at column level is not there.
         If someone has worked on this type of requirement to get the spool no. data convertd to excel format and attached as an mail.
         Please suggest your solutions regarding this...
    regards,
    Brijesh Patel

    hi,<b>
    first save the excel file as tabdelimited file </b> 
    Try using GUI_UPLOAD in this way
      V_FILENAME = P_FILE.
      CALL FUNCTION 'GUI_UPLOAD'
           EXPORTING
                FILENAME                = V_FILENAME
                FILETYPE                = 'ASC'
                HAS_FIELD_SEPARATOR     = '|'
           TABLES
                DATA_TAB                = ITAB
           EXCEPTIONS
                FILE_OPEN_ERROR         = 1
                FILE_READ_ERROR         = 2
                NO_BATCH                = 3
                GUI_REFUSE_FILETRANSFER = 4
                INVALID_TYPE            = 5
                NO_AUTHORITY            = 6
                UNKNOWN_ERROR           = 7
                BAD_DATA_FORMAT         = 8
                HEADER_NOT_ALLOWED      = 9
                SEPARATOR_NOT_ALLOWED   = 10
                HEADER_TOO_LONG         = 11
                UNKNOWN_DP_ERROR        = 12
                ACCESS_DENIED           = 13
                DP_OUT_OF_MEMORY        = 14
                DISK_FULL               = 15
                DP_TIMEOUT              = 16
                OTHERS                  = 17.
    Regards,
    Santosh
    Message was edited by: Santosh

  • Read Excel attachment from mail

    Hi,
    Will be happy to know the inputs for the below specific requirement,
    Step 1 : User will get an email into SAPinbox with an excel or text file as attachment.
    Step 2 : Then a background <b>(automatic)</b> program should read the mail including the attached file.
    Step 3 : Program should extract and data from excel file then execute some business process.
    Any inputs will be highly helpful.
    Regards
    Manohar

    Hi Manohar,
    The mail which comes into SAP Inbox with say .xls file, when the attachment is selected, SAP downloads that .xls file to your presentation server and the same is opened through EXCEL.
    If the path and filename is fixed, you can write a program which calls FM SO_OBJECT_UPLOAD, get the data, and do the processing of the same.
    Regards,
    Raj

  • Long text in mail as excel attachment

    Hi Experts,
    I am sending internal table as excel attachment in mail through Function Module -  SO_DOCUMENT_SEND_API1.
    But there is one field with long text. Pls help me how to send long text in excel sheet as mail attachment.
    Regards,
    Reny Richard

    Hi,
    And do your self a favor and use CL_BCS instead of SO_DOCUMENT_SEND_API1 .
    See Send email from ABAP with class CL_BCS - Code Gallery - SCN Wiki
    See Re: Excel formating in email attachment without using XML.
    Use "where use" for class CL_BCS .
    Regards.

  • Sending Excel attachment in E-mail

    Hi All,
    I am sending excel attachment in mail, when I see in SO01 tcode I am able to see the attachment in outbox, but getting 'Error during send Process' in sent status and not getting any mails to my e-mail id.
    Could you any one help me in this?
    Thanks in advance.
    Vijaya.

    Hi,
    data: p_email   type somlreci1-receiver
                          value 'Mail ID'.
    data: begin of it001 occurs 0,
          bukrs type t001-bukrs,
          butxt type t001-butxt,
          end of it001.
    data:   imessage type standard table of solisti1 with header line,
            iattach type standard table of solisti1 with header line,
            ipacking_list like sopcklsti1 occurs 0 with header line,
            ireceivers like somlreci1 occurs 0 with header line,
            iattachment like solisti1 occurs 0 with header line.
    start-of-selection.
      select bukrs butxt into table it001 from t001.
      Populate table with detaisl to be entered into .xls file
      perform build_xls_data .
    Populate message body text
      clear imessage.   refresh imessage.
      imessage = 'Please find attached excel file'.
      append imessage.
    Send file by email as .xls speadsheet
      perform send_email_with_xls tables imessage
                                          iattach
                                    using p_email
                                          'Example Excel Attachment'
                                          'XLS'
                                          'TestFileName'
                                          'CompanyCodes'.
         Form  BUILD_XLS_DATA
    form build_xls_data .
    constants: con_cret type x value '0D',  "OK for non Unicode
                con_tab type x value '09'.   "OK for non Unicode
    *If you have Unicode check active in program attributes thnen you will
    *need to declare constants as follows
    *class cl_abap_char_utilities definition load.
    constants:
        con_tab  type c value cl_abap_char_utilities=>horizontal_tab,
        con_cret type c value cl_abap_char_utilities=>cr_lf.
      concatenate 'BUKRS' 'BUTXT'
             into iattach separated by con_tab.
      concatenate con_cret iattach into iattach.
      append  iattach.
      loop at it001 .
        concatenate it001-bukrs it001-butxt
               into iattach separated by con_tab.
        concatenate con_cret iattach  into iattach.
        append  iattach.
      endloop .
    endform.
         Form  SEND_EMAIL_WITH_XLS
    form send_email_with_xls tables pit_message
                                              pit_attach
                                        using p_email
                                              p_mtitle
                                              p_format
                                              p_filename
                                              p_attdescription.
      data: xdocdata like sodocchgi1,
            xcnt type i.
    Fill the document data.
      xdocdata-doc_size = 1.
    Populate the subject/generic message attributes
      xdocdata-obj_langu = sy-langu .
      xdocdata-obj_name  = 'SAPRPT' .
      xdocdata-obj_descr = p_mtitle .
    Fill the document data and get size of attachment
      clear xdocdata.
      read table iattach index xcnt.
      xdocdata-doc_size =
         ( xcnt - 1 ) * 255 + strlen( iattach ).
      xdocdata-obj_langu  = sy-langu.
      xdocdata-obj_name   = 'SAPRPT'.
      xdocdata-obj_descr  = p_mtitle.
      clear iattachment.  refresh iattachment.
      iattachment[] = pit_attach[].
    Describe the body of the message
      clear ipacking_list.  refresh ipacking_list.
      ipacking_list-transf_bin = space.
      ipacking_list-head_start = 1.
      ipacking_list-head_num = 0.
      ipacking_list-body_start = 1.
      describe table imessage lines ipacking_list-body_num.
      ipacking_list-doc_type = 'RAW'.
      append ipacking_list.
    Create attachment notification
      ipacking_list-transf_bin = 'X'.
      ipacking_list-head_start = 1.
      ipacking_list-head_num   = 1.
      ipacking_list-body_start = 1.
      describe table iattachment lines ipacking_list-body_num.
      ipacking_list-doc_type   =  p_format.
      ipacking_list-obj_descr  =  p_attdescription.
      ipacking_list-obj_name   =  p_filename.
      ipacking_list-doc_size   =  ipacking_list-body_num * 255.
      append ipacking_list.
    Add the recipients email address
      clear ireceivers.  refresh ireceivers.
      ireceivers-receiver = p_email.
      ireceivers-rec_type = 'U'.
      ireceivers-com_type = 'INT'.
      ireceivers-notif_del = 'X'.
      ireceivers-notif_ndel = 'X'.
      append ireceivers.
      call function 'SO_DOCUMENT_SEND_API1'
           exporting
                document_data              = xdocdata
                put_in_outbox              = 'X'
                commit_work                = 'X'
           tables
                packing_list               = ipacking_list
                contents_bin               = iattachment
                contents_txt               = imessage
                receivers                  = ireceivers
           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.
    endform.
    Check this Sample code.
    Thanks,
    Durai.V

  • How to handle more than 250 characters in excel attachment

    hi,
    i lokesh, actually i am sending a excel attachment through mail. i am using " SO_DOCUMENT_SEND_API1" function module, one problem what i facing is , this function module handle only 250 characters, i need to display more than 250 characters. pls any one knows about this, pls let me know.
    regards
    lokesh t

    Hi,
    Xls allows only 250 char.
    Cheers

  • Email with excel attached

    Hello,
    I have to send an email in a workflow step with a excel attach from an internal table, Does anyone have any sugestion ?
    Thanks,
    Diego

    Hi,
    Check this [thread1|send excel attachment as email; [thread2|Re: Excel attachment in SO_DOCUMENT_SEND_API1; & [thread3|Help needed for the Excel attachment to mail;.
    Regards,
    Surjith

  • To send output of report to the mails ids as an excel attachment

    Hi all,
    I have a requirement that I have created a report using classes. Now I have to send output of my report to the particular mailids as an excel attachment.
    Can anybody help me?
    Regards,
    Azra.

    Hi,
    Refer Below links.
    Re: Formatting Excel Attachment output in SO_DOCUMENT_SEND_API1
    Information Broadcasting with Excel Report as attachment
    Zip the excel and send as mail attachment
    Regards
    Md.MaahboobKhan

  • Issue in sending e mails with Excel attachment

    Hi,
    I am facing an issue with one function module - SO_DOCUMENT_SEND_API1. We were using this for sending mails to diff destination with excel sheet attachment contains sales data. This system has been migrated from 4.5B to ECC 5. Now this process is not working like the old one and the excel attachment is not properly formatted. All the data is being written into one cell of excel sheet and it seems only one line is present in output and is corrupted.
    Can you please let me know what might be the issue here, any alternate option available or something to be modified in new version with this function module?
    Thanks in advance,
    Ullas

    Hi Ullas,
    check this once.
    REPORT  ZLAXMI_ALVMAIL4                         .
    TABLES: EKKO.
    PARAMETERS: P_EMAIL   TYPE SOMLRECI1-RECEIVER
                                      DEFAULT '[email protected]'.
    TYPES: BEGIN OF T_EKPO,
      EBELN TYPE EKPO-EBELN,
      EBELP TYPE EKPO-EBELP,
      AEDAT TYPE EKPO-AEDAT,
      MATNR TYPE EKPO-MATNR,
    END OF T_EKPO.
    DATA: IT_EKPO TYPE STANDARD TABLE OF T_EKPO INITIAL SIZE 0,
          WA_EKPO TYPE T_EKPO.
    TYPES: BEGIN OF T_CHAREKPO,
      EBELN(10) TYPE C,
      EBELP(5)  TYPE C,
      AEDAT(8)  TYPE C,
      MATNR(18) TYPE C,
    END OF T_CHAREKPO.
    DATA: WA_CHAREKPO TYPE T_CHAREKPO.
    DATA:   IT_MESSAGE TYPE STANDARD TABLE OF SOLISTI1 INITIAL SIZE 0
                    WITH HEADER LINE.
    DATA:   IT_ATTACH TYPE STANDARD TABLE OF SOLISTI1 INITIAL SIZE 0
                    WITH HEADER LINE.
    DATA:   T_PACKING_LIST LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE,
            T_CONTENTS LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,
            T_RECEIVERS LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE,
            T_ATTACHMENT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,
            T_OBJECT_HEADER LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,
            W_CNT TYPE I,
            W_SENT_ALL(1) TYPE C,
            W_DOC_DATA LIKE SODOCCHGI1,
            GD_ERROR    TYPE SY-SUBRC,
            GD_RECIEVER TYPE SY-SUBRC.
    *START_OF_SELECTION
    START-OF-SELECTION.
      Retrieve sample data from table ekpo
      PERFORM DATA_RETRIEVAL.
      Populate table with detaisl to be entered into .xls file
      PERFORM BUILD_XLS_DATA_TABLE.
    *END-OF-SELECTION
    END-OF-SELECTION.
    Populate message body text
      PERFORM POPULATE_EMAIL_MESSAGE_BODY.
    Send file by email as .xls speadsheet
      PERFORM SEND_FILE_AS_EMAIL_ATTACHMENT
                                   TABLES IT_MESSAGE
                                          IT_ATTACH
                                    USING P_EMAIL
                                          'Example .xls documnet attachment'
                                          'XLS'
                                          'filename'
                                 CHANGING GD_ERROR
                                          GD_RECIEVER.
      Instructs mail send program for SAPCONNECT to send email(rsconn01)
      PERFORM INITIATE_MAIL_EXECUTE_PROGRAM.
    *&      Form  DATA_RETRIEVAL
          Retrieve data form EKPO table and populate itab it_ekko
    FORM DATA_RETRIEVAL.
      SELECT EBELN EBELP AEDAT MATNR
       UP TO 10 ROWS
        FROM EKPO
        INTO TABLE IT_EKPO.
    ENDFORM.                    " DATA_RETRIEVAL
    *&      Form  BUILD_XLS_DATA_TABLE
          Build data table for .xls document
    FORM BUILD_XLS_DATA_TABLE.
    CONSTANTS: con_cret TYPE x VALUE '0D',  "OK for non Unicode
                con_tab TYPE x VALUE '09'.   "OK for non Unicode
    *If you have Unicode check active in program attributes thnen you will
    *need to declare constants as follows
    *class cl_abap_char_utilities definition load.
    CONSTANTS:
        CON_TAB  TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB,
        CON_CRET TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>CR_LF.
      CONCATENATE 'EBELN' 'EBELP' 'AEDAT' 'MATNR'
             INTO IT_ATTACH SEPARATED BY CON_TAB.
      CONCATENATE CON_CRET IT_ATTACH  INTO IT_ATTACH.
      APPEND  IT_ATTACH.
      LOOP AT IT_EKPO INTO WA_CHAREKPO.
        CONCATENATE WA_CHAREKPO-EBELN WA_CHAREKPO-EBELP
                    WA_CHAREKPO-AEDAT WA_CHAREKPO-MATNR
               INTO IT_ATTACH SEPARATED BY CON_TAB.
        CONCATENATE CON_CRET IT_ATTACH  INTO IT_ATTACH.
        APPEND  IT_ATTACH.
      ENDLOOP.
    ENDFORM.                    " BUILD_XLS_DATA_TABLE
    *&      Form  SEND_FILE_AS_EMAIL_ATTACHMENT
          Send email
    FORM SEND_FILE_AS_EMAIL_ATTACHMENT TABLES PIT_MESSAGE
                                              PIT_ATTACH
                                        USING P_EMAIL
                                              P_MTITLE
                                              P_FORMAT
                                              P_FILENAME
                                              P_ATTDESCRIPTION
                                              P_SENDER_ADDRESS
                                              P_SENDER_ADDRES_TYPE
                                     CHANGING P_ERROR
                                              P_RECIEVER.
      DATA: LD_ERROR    TYPE SY-SUBRC,
            LD_RECIEVER TYPE SY-SUBRC,
            LD_MTITLE LIKE SODOCCHGI1-OBJ_DESCR,
            LD_EMAIL LIKE  SOMLRECI1-RECEIVER,
            LD_FORMAT TYPE  SO_OBJ_TP ,
            LD_ATTDESCRIPTION TYPE  SO_OBJ_NAM ,
            LD_ATTFILENAME TYPE  SO_OBJ_DES ,
            LD_SENDER_ADDRESS LIKE  SOEXTRECI1-RECEIVER,
            LD_SENDER_ADDRESS_TYPE LIKE  SOEXTRECI1-ADR_TYP,
            LD_RECEIVER LIKE  SY-SUBRC.
      LD_EMAIL   = P_EMAIL.
      LD_MTITLE = P_MTITLE.
      LD_FORMAT              = P_FORMAT.
      LD_ATTDESCRIPTION      = P_ATTDESCRIPTION.
      LD_ATTFILENAME         = P_FILENAME.
      LD_SENDER_ADDRESS      = P_SENDER_ADDRESS.
      LD_SENDER_ADDRESS_TYPE = P_SENDER_ADDRES_TYPE.
    Fill the document data.
      W_DOC_DATA-DOC_SIZE = 1.
    Populate the subject/generic message attributes
      W_DOC_DATA-OBJ_LANGU = SY-LANGU.
      W_DOC_DATA-OBJ_NAME  = 'SAPRPT'.
      W_DOC_DATA-OBJ_DESCR = LD_MTITLE .
      W_DOC_DATA-SENSITIVTY = 'F'.
    Fill the document data and get size of attachment
      CLEAR W_DOC_DATA.
      READ TABLE IT_ATTACH INDEX W_CNT.
      W_DOC_DATA-DOC_SIZE =
         ( W_CNT - 1 ) * 255 + STRLEN( IT_ATTACH ).
      W_DOC_DATA-OBJ_LANGU  = SY-LANGU.
      W_DOC_DATA-OBJ_NAME   = 'SAPRPT'.
      W_DOC_DATA-OBJ_DESCR  = LD_MTITLE.
      W_DOC_DATA-SENSITIVTY = 'F'.
      CLEAR T_ATTACHMENT.
      REFRESH T_ATTACHMENT.
      T_ATTACHMENT[] = PIT_ATTACH[].
    Describe the body of the message
      CLEAR T_PACKING_LIST.
      REFRESH T_PACKING_LIST.
      T_PACKING_LIST-TRANSF_BIN = SPACE.
      T_PACKING_LIST-HEAD_START = 1.
      T_PACKING_LIST-HEAD_NUM = 0.
      T_PACKING_LIST-BODY_START = 1.
      DESCRIBE TABLE IT_MESSAGE LINES T_PACKING_LIST-BODY_NUM.
      T_PACKING_LIST-DOC_TYPE = 'RAW'.
      APPEND T_PACKING_LIST.
    Create attachment notification
      T_PACKING_LIST-TRANSF_BIN = 'X'.
      T_PACKING_LIST-HEAD_START = 1.
      T_PACKING_LIST-HEAD_NUM   = 1.
      T_PACKING_LIST-BODY_START = 1.
      DESCRIBE TABLE T_ATTACHMENT LINES T_PACKING_LIST-BODY_NUM.
      T_PACKING_LIST-DOC_TYPE   =  LD_FORMAT.
      T_PACKING_LIST-OBJ_DESCR  =  LD_ATTDESCRIPTION.
      T_PACKING_LIST-OBJ_NAME   =  LD_ATTFILENAME.
      T_PACKING_LIST-DOC_SIZE   =  T_PACKING_LIST-BODY_NUM * 255.
      APPEND T_PACKING_LIST.
    Add the recipients email address
      CLEAR T_RECEIVERS.
      REFRESH T_RECEIVERS.
      T_RECEIVERS-RECEIVER = LD_EMAIL.
      T_RECEIVERS-REC_TYPE = 'U'.
      T_RECEIVERS-COM_TYPE = 'INT'.
      T_RECEIVERS-NOTIF_DEL = 'X'.
      T_RECEIVERS-NOTIF_NDEL = 'X'.
      APPEND T_RECEIVERS.
      CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
           EXPORTING
                DOCUMENT_DATA              = W_DOC_DATA
                PUT_IN_OUTBOX              = 'X'
                SENDER_ADDRESS             = LD_SENDER_ADDRESS
                SENDER_ADDRESS_TYPE        = LD_SENDER_ADDRESS_TYPE
                COMMIT_WORK                = 'X'
           IMPORTING
                SENT_TO_ALL                = W_SENT_ALL
           TABLES
                PACKING_LIST               = T_PACKING_LIST
                CONTENTS_BIN               = T_ATTACHMENT
                CONTENTS_TXT               = IT_MESSAGE
                RECEIVERS                  = T_RECEIVERS
           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.
    Populate zerror return code
      LD_ERROR = SY-SUBRC.
    Populate zreceiver return code
      LOOP AT T_RECEIVERS.
        LD_RECEIVER = T_RECEIVERS-RETRN_CODE.
      ENDLOOP.
    ENDFORM.
    *&      Form  INITIATE_MAIL_EXECUTE_PROGRAM
          Instructs mail send program for SAPCONNECT to send email.
    FORM INITIATE_MAIL_EXECUTE_PROGRAM.
      WAIT UP TO 2 SECONDS.
      SUBMIT RSCONN01 WITH MODE = 'INT'
                    WITH OUTPUT = 'X'
                    AND RETURN.
    ENDFORM.                    " INITIATE_MAIL_EXECUTE_PROGRAM
    *&      Form  POPULATE_EMAIL_MESSAGE_BODY
           Populate message body text
    FORM POPULATE_EMAIL_MESSAGE_BODY.
      REFRESH IT_MESSAGE.
      IT_MESSAGE = 'Please find attached a list test ekpo records'.
      APPEND IT_MESSAGE.
    ENDFORM.                    " POPULATE_EMAIL_MESSAGE_BODY
    Regards,
    Laxmi.

  • Problem in excel format while sending mail with excel attachment.

    Hi Gurus ,
    I am sending a email with Excel attachment using FM SO_DOCUMENT_SEND_API1 or SO_NEW_DOCUMENT_ATT_SEND_API1.
    I am able to send a mail with excel attachment with a piece of code which I got from SDN itself.
    But the problem is when I am trying to open the attachment, <b>A pop up comes which says that it is not in recognizable format. Would you like to open it?
    and several other lines of caution.</b>
    When i choose to open it, i get the correct data in one excel sheet. Certain vertical lines of the excel sheet is missing. <b>But no data is missing. </b>
    I am attaching the code below. Can any one please tell me where is the problem in this code ?
    Thanx in advance
    types: begin of t_mara,
    matnr type mara-matnr,
    matkl type mara-matkl,
    mtart type mara-mtart,
    meins type mara-meins,
    end of t_mara.
    data: gt_mara type table of t_mara,
    wa_mara like line of gt_mara,
    it_packing_list type table of SOPCKLSTI1,
    wa_packing_list like line of it_packing_list,
    it_receivers type table of SOMLRECI1,
    wa_receivers like line of it_receivers,
    it_mailbody type table of SOLISTI1,
    wa_mailbody like line of it_mailbody,
    it_attachment type table of SOLISTI1,
    wa_attachment like line of it_attachment.
    data: la_doc type SODOCCHGI1.
    constants:
    con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB,
    con_cret type c value cl_abap_char_utilities=>CR_LF.
    * get material
    select matnr matkl mtart meins
    into table gt_mara
    from mara
    up to 25 rows.
    * Populate the subject/generic message attributes
    la_doc-obj_langu = sy-langu.
    la_doc-obj_descr = 'Material Details' . "Mail Header
    la_doc-sensitivty = 'F'.
    la_doc-doc_size = 1.
    * Add the recipients email address
    CLEAR wa_receivers.
    REFRESH it_receivers.
    wa_receivers-receiver = 'PCSDEVL'.
    wa_receivers-rec_type = 'U'.
    wa_receivers-com_type = 'INT'.
    wa_receivers-notif_del = 'X'.
    wa_receivers-notif_ndel = 'X'.
    APPEND wa_receivers to it_receivers.
    * Mail Body
    CLEAR wa_mailbody.
    REFRESH it_mailbody.
    wa_mailbody-line = 'Please find the attachment'.
    APPEND wa_mailbody to it_mailbody.
    * Mail attachmwnt
    CLEAR wa_attachment.
    REFRESH it_attachment.
    CONCATENATE 'MATNR' 'MATKL' 'MTART' 'MEINS'
    INTO wa_attachment SEPARATED BY con_tab.
    CONCATENATE con_cret wa_attachment INTO wa_attachment.
    APPEND wa_attachment to it_attachment.
    LOOP AT gt_mara INTO wa_mara.
    CONCATENATE wa_mara-matnr wa_mara-matkl
    wa_mara-mtart wa_mara-meins
    INTO wa_attachment SEPARATED BY con_tab.
    CONCATENATE con_cret wa_attachment INTO wa_attachment.
    APPEND wa_attachment to it_attachment.
    ENDLOOP.
    * Describe the body of the message
    CLEAR wa_packing_list.
    REFRESH it_packing_list.
    wa_packing_list-transf_bin = space.
    wa_packing_list-head_start = 1.
    wa_packing_list-head_num = 0.
    wa_packing_list-body_start = 1.
    wa_packing_list-body_num = 1.
    wa_packing_list-doc_type = 'RAW'.
    APPEND wa_packing_list to it_packing_list.
    * Create attachment notification
    wa_packing_list-transf_bin = 'X'.
    wa_packing_list-head_start = 1.
    wa_packing_list-head_num = 1.
    wa_packing_list-body_start = 1.
    DESCRIBE TABLE it_attachment LINES wa_packing_list-body_num.
    wa_packing_list-doc_type = 'XLS'. " To word attachment change this as 'DOC'
    wa_packing_list-obj_descr = ' '.
    concatenate wa_packing_list-doc_type 'file' into wa_packing_list-OBJ_DESCR
    separated by space.
    wa_packing_list-doc_size = wa_packing_list-body_num * 255.
    APPEND wa_packing_list to it_packing_list.
    CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
    EXPORTING
    document_data = la_doc
    PUT_IN_OUTBOX = 'X'
    * SENDER_ADDRESS = SY-UNAME
    * SENDER_ADDRESS_TYPE = 'B'
    COMMIT_WORK = 'X'
    * IMPORTING
    * SENT_TO_ALL =
    * NEW_OBJECT_ID =
    * SENDER_ID =
    tables
    packing_list = it_packing_list
    * OBJECT_HEADER =
    CONTENTS_BIN = it_attachment
    CONTENTS_TXT = it_mailbody
    * CONTENTS_HEX =
    * OBJECT_PARA =
    * OBJECT_PARB =
    receivers = it_receivers
    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
    IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif.

    REPORT  Zex5 LINE-SIZE 255 LINE-COUNT 255 .
    class CL_ABAP_CHAR_UTILITIES definition load. "-->
    TABLES : vbap.
    SELECT-OPTIONS: s_vbeln FOR vbap-vbeln.
    DATA : BEGIN OF itab OCCURS 1,
           vbeln LIKE vbap-vbeln,
           posnr LIKE vbap-posnr,
           matnr LIKE vbap-matnr,
           END OF itab.
    parameters : p_email like somlreci1-receiver
    DATA: tlines type i.
    DATA: itmessage   LIKE solisti1 OCCURS 1 WITH HEADER LINE. "Ok
    DATA: itattach    LIKE solisti1 OCCURS 2 WITH HEADER LINE. "Ok
    DATA: itpacklist  LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE.
    DATA: itreclist   LIKE somlreci1 OCCURS 5 WITH HEADER LINE.
    data: itattachment like solisti1 OCCURS 2 WITH HEADER LINE.
    start-of-selection.
      SELECT vbeln posnr matnr
             FROM vbap
             INTO TABLE itab
             WHERE vbeln IN s_vbeln.
    **Make the internal table data to be compatible in excel format .
      PERFORM BUILD_XLS_FORMAT.
    **Populate message of body text.
      clear itmessage.
      refresh itmessage.
      itmessage = 'Please find attached Excel file'.
      append itmessage.
      PERFORM send_mail_as_xls_attachment tables itmessage
                                                 itattach
             using p_email 'Excel Attachment' 'TXT'    " 'XLS'
              using p_email 'TEXT Attachment' 'TXT'    " 'XLS'
                            'TestFileName'
                            'SalesOrders' .
    *&      Form  BUILD_XLS_FORMAT
          text
    -->  p1        text
    <--  p2        text
    form BUILD_XLS_FORMAT.
    previosuly we were using for unicode ..now replaced
    **Declare constants for the spacing .
    *Constants : con1 type x value '0D',
               con2 type x value '09'.
      Constants : con1 type c
            value CL_ABAP_CHAR_UTILITIES=>CR_LF,
            con2 type c
            value CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    **For the Header descriptions.
      Concatenate 'SalesORdNo'
                  'Item'
                  'Materialno' into itattach separated by con2.
      Concatenate con1 itattach into itattach.
      Append itattach.
    **Now align the items in the itab as above .
      Loop at Itab.
        concatenate itab-vbeln
                    itab-posnr
                    itab-matnr into itattach separated by con2.
        concatenate con1 itattach into itattach .
        Append itattach.
      endloop.
    endform.                    " BUILD_XLS_FORMAT
    *&      Form  send_mail_as_xls_attachment
          text
         -->P_ITMESSAGE  text
         -->P_ITATTACH  text
         -->P_P_EMAIL  text
         -->P_0116   text
         -->P_0117   text
         -->P_0118   text
         -->P_0119   text
    form send_mail_as_xls_attachment tables   p_itmessage
                                              p_itattach
                                     using    p_email
                                              p_mtitle
                                              p_format
                                              p_filename
                                              p_attdescription.
      Data : xdocdata like sodocchgi1,
             xcnt type i.
    *Fill the document data.
      xdocdata-doc_size = 1.
    *Populate the subject/generic message attributes.
      xdocdata-obj_name  = 'SAPRPT'.
      xdocdata-obj_langu = sy-langu.
      xdocdata-obj_descr = p_mtitle.
    *Fill the document data and fetch size of attachment.
      clear xdocdata.
      read table itattach index xcnt.
      xdocdata-doc_size = ( xcnt - 1 ) * 255 + strlen( itattach ).
    xdocdata-doc_size =  ( xcnt - 1 ) * 255.
      xdocdata-obj_name  = 'SAPRPT'.
      xdocdata-obj_langu = sy-langu.
      xdocdata-obj_descr = p_mtitle.
      clear itattachment. refresh itattachment.
         itattachment[] = p_itattach[].
    *Describe the body of the message.
      clear itpacklist. refresh itpacklist.
      itpacklist-transf_bin = 'X'.
      itpacklist-head_start = '1'.
      itpacklist-head_num = '0'.
      itpacklist-body_start = '1'.
      describe table itattachment lines itpacklist-body_num .
      itpacklist-doc_type = 'TXT'.
    itpacklist-doc_type = 'XLS'.
      append itpacklist.
    *Create attachment notification.
      itpacklist-transf_bin = 'X'.
      itpacklist-head_start = '1'.
      itpacklist-head_num = '1'.
      itpacklist-body_start = '1'.
      describe table itattachment lines itpacklist-body_num .
      itpacklist-doc_type = p_format.
      itpacklist-obj_name = p_filename.
      itpacklist-obj_descr = p_attdescription.
      itpacklist-doc_size = itpacklist-body_num * 255 .
      append itpacklist.
    *FIll the receivers list.
      Clear itreclist. refresh itreclist.
      itreclist-receiver = p_email.
      itreclist-rec_type = 'U'.
      itreclist-com_type = 'INT'.
      itreclist-notif_del = 'X'.
      itreclist-notif_ndel = 'X'.
    *itreclist-notif_read = 'X'.
      append itreclist.
    *CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
    EXPORTING
      document_data                    = xdocdata
      PUT_IN_OUTBOX                    = 'X'
      commit_work    = 'X'
      SENDER_ADDRESS                   = SY-UNAME
    tables
       packing_list                    = itpacklist
       CONTENTS_BIN                    = itattachment
       CONTENTS_TXT                    = itmessage
       receivers                       = itreclist
    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
    *IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    *ENDIF.
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        EXPORTING
          document_data              = xdocdata
          PUT_IN_OUTBOX              = 'X'
        TABLES
          packing_list               = itpacklist
          CONTENTS_BIN               = itattachment
          CONTENTS_TXT               = itmessage
          receivers                  = itreclist
        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.
      IF sy-subrc <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    endform.                    " send_mail_as_xls_attachment
    Just execute the above code and let me know.
    What is the sap version u r using .
    Vijay

  • Error in Sending Mail with excel attachment

    Hi All,
    While sending a mail with excel attachment it is getting successfully send but when i am opening the excel it gives a popup saying "The file is not in recognizable format", and when i click OK the data is getting displayed.
    So anybody has any idea of how to remove the popup??
    I am using SO_NEW_DOCUMENT_ATT_SEND_API1 FM for sending the mail.
    Can anybody help me regarding this.
    Thanks
    Salish

    Hi,
    I was facing the issue when I did not populate the parameters packing_list, object_header,contents_bin, contents_txt of the FM
    SO_NEW_DOCUMENT_ATT_SEND_API1 properly.
    Also the possible cause could be the configuration in SCOT, not very sure about this. Check with the BASIS guy.
    Regards,
    Sagar

Maybe you are looking for

  • How do my partner and I share our calendars on our iPhones?

    Hello.  I am completely new to all of this so I apologise if I don't follow any protocols correctly.  I would love some help to figure out the best way for my partner and I to share our calendars on our iPhones please.  I have done a lot of research

  • Mac Mini Fusion Drive constantly running...

    Hey does anyone have an experience similar to mine? Basically I can hear the mac mini constantly running, as in the hard drive is constantly reading/writing something. It is like a rhythmic reading/writing every 5 seconds or so. This also happens wit

  • Performance tuning

    Hi guys! I'll be always in favour to you if u could really help me this out.The program displays all the Sales order(RMA's) who's series starts with number 6 in our company ie for Return Manufacturing Authoriazation.What ever the orders which are ret

  • I need  a symbol to remain center screen on my web page no matter the screen resolution settings.

    Im trying to create an animation with functions inside a symbol. I need the symbol settings to remain seprate from the other settings of other items on the page such as "stage" and "background image" which are set to %  height.width,longitude,latitud

  • Looping HTML articles in Folio Builder Indesign CS6

    I've build a HTML folio using jQuery animations. Everything works great in Folio Builder (I can import the article and preview it on my devices etc.) But when I add a loop to my animations Folio Builder never completes the uploading process when I tr