Excel attachment with SO_DOCUMENT_SEND_API1

Hello Everyone,
I am using SO_DOCUMENT_SEND_API1 for sending mail.
It works well with text attachment.
Whereas with excel attachment:
The fn module for sending mail ‘SO_DOCUMENT_SEND_API1’ gives return code zero.
The excel attachment mail can be seen in transaction SOST. But its process fails stating that it cannot be converted.
(Message : Message cannot be processed as it cannot be converted)
Can anyone suggest me what might be wrong ??

Hi
Please refer these sample progs to send an xcel attachment via mail...
http://www.sapdevelopment.co.uk/reporting/email/attach_xlsmod.htm
http://www.sapdevelopment.co.uk/reporting/email/attach_xls.htm
http://www.sapgenie.com/abap/code/abap31.htm
Regards,
Anjali

Similar Messages

  • Send Email with Excel attachment with formatting(bold, color) in Background

    Hi,
    I have requirement wherein I have to send an email with excel attachment with proper formatting of certain fields in the excel sheet like making it bold or setting different color. The data is available in an internal table. Just to to format it and send an email when the program is executed in background mode.
    Any pointers on this would be highly appreciated!
    Thanks,
    Anil.

    I  resolved my own problem using the BCS_EXAMPLE_7 program as sample.

  • Issue in Excel Attachment Extension SO_DOCUMENT_SEND_API1

    Dear Team,
    I am facing on unique Issue,When i am using FM:SO_DOCUMENT_SEND_API1,Mail is getting trigger properly with attachment but extension file is changed to some other format.please find attached herewith attachment.
    When I see in SOST it is showing in excel format but in mail it is showing without extension.
    Please find code piece of code for excel attachment.
    OBJPACK-DOC_TYPE   = 'XLS'.
      OBJPACK-OBJ_NAME   = 'Permit Exception List'.
    Regards,
    Santosh

    Hi Santhosh,
    Have you passed the document size correctly? I had used as follows:
    CLEAR WA_PACKING_LIST.
    WA_PACKING_LIST-TRANSF_BIN   = 'X'.
    WA_PACKING_LIST-HEAD_START  = 0.
    WA_PACKING_LIST-HEAD_NUM     = 1.
    WA_PACKING_LIST-BODY_START  = 1.
    DESCRIBE TABLE GT_ATTACH LINES WA_PACKING_LIST-BODY_NUM.
    WA_PACKING_LIST-DOC_TYPE      = 'XLS'.
    WA_PACKING_LIST-OBJ_DESCR    = ' '.
    WA_PACKING_LIST-OBJ_NAME      = 'AAA'.
    WA_PACKING_LIST-DOC_SIZE        = WA_PACKING_LIST-BODY_NUM * 255.
    APPEND WA_PACKING_LIST TO LT_PACKING_LIST.
    Try this way.
    Regards,
    Abijith

  • Email Excel attachment with a BOLD row

    hi!
    My requirement is that data in an internal table should be sent as an attachment in an email. There are a few records in the internal table which needs to be in bold(i have the logic to figure out whichones). I am using the below FM  .
    CALL FUNCTION 'SO_OBJECT_SEND'
       EXPORTING
         object_hd_change                 = wa_object_hd
         object_type                       = 'RAW'
       TABLES
         objcont                          = i_text
         receivers                        = i_recv
         packing_list                     = i_packing_list
         att_cont                         = i_att
    Does any body have any idea how to bold a few records in the excel attachment?
    I appreciate your suggestions.
    Thanks,
    manasa
    Message was edited by:
            manasa

    Hi Manasa,
    The Code below is for sending Excel attachment in email. Not sure for BOLD...
    You can copy and paste the following codes and execute..
    Hope this will help you..
    TYPE-POOLS: truxs.
    DATA t5 LIKE t005t OCCURS 0 WITH HEADER LINE.
    START-OF-SELECTION.
    SELECT * INTO TABLE t5
    FROM t005t
    WHERE spras = sy-langu.
    DATA wa_data TYPE truxs_t_text_data.
    CALL FUNCTION 'SAP_CONVERT_TO_TXT_FORMAT'
    EXPORTING
    i_line_header = 'X'
    TABLES
    i_tab_sap_data = t5
    CHANGING
    i_tab_converted_data = wa_data
    EXCEPTIONS
    conversion_failed = 1
    OTHERS = 2.
    DATA stmp(4096) TYPE c.
    DATA itmp TYPE i.
    LOOP AT wa_data INTO stmp.
    itmp = STRLEN( stmp ).
    stmp+itmp = cl_abap_char_utilities=>cr_lf.
    MODIFY wa_data FROM stmp.
    ENDLOOP.
    PERFORM send_email.
    *& Form send_email
    FORM send_email .
    DATA docs LIKE docs OCCURS 0 WITH HEADER LINE.
    DATA excelsize TYPE i.
    DATA excel LIKE solisti1 OCCURS 0 WITH HEADER LINE.
    DATA doc LIKE sodocchgi1.
    DATA excelln TYPE i.
    DATA int_objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
    DATA int_objhead LIKE solisti1 OCCURS 2 WITH HEADER LINE.
    DATA int_objtext LIKE solisti1 OCCURS 0 WITH HEADER LINE.
    DATA int_reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE.
    DATA bodyln LIKE sy-tabix.
    DATA output_data TYPE ssfcrescl.
    excel[] = wa_data[].
    excel table sizes
    DESCRIBE TABLE excel LINES excelln.
    Body Email
    int_objtext-line = 'Test Body'.
    APPEND int_objtext.
    DESCRIBE TABLE int_objtext LINES bodyln.
    READ TABLE int_objtext INDEX bodyln.
    CLEAR doc.
    doc-doc_size = ( bodyln - 1 ) * 255 + STRLEN( int_objtext ).
    doc-obj_name = ' '.
    doc-sensitivty = 'P'.
    doc-proc_syst = sy-sysid.
    doc-proc_clint = sy-mandt.
    CLEAR: int_objpack, int_objpack[].
    int_objpack-transf_bin = ' '.
    int_objpack-head_start = 1.
    int_objpack-head_num = 0.
    int_objpack-body_start = 1.
    int_objpack-body_num = bodyln.
    int_objpack-doc_type = 'RAW'.
    int_objpack-obj_descr = 'Test'.
    APPEND int_objpack.
    CLEAR: int_objhead, int_objhead[].
    int_objhead = 'Attachment'.
    APPEND int_objhead.
    int_objpack-transf_bin = 'X'.
    int_objpack-head_start = 1.
    int_objpack-head_num = 0.
    int_objpack-body_start = 1.
    int_objpack-body_num = excelln.
    int_objpack-doc_size = excelsize.
    int_objpack-doc_type = 'XLS'.
    int_objpack-obj_name = 'excel'.
    int_objpack-obj_descr = 'test.xls'. "File name
    APPEND int_objpack.
    Set Receiver
    int_reclist-receiver = 'SAPUSER'.
    int_reclist-rec_type = 'B'.
    int_reclist-notif_del = 'X'.
    int_reclist-notif_read = 'X'.
    int_reclist-notif_ndel = 'X'.
    int_reclist-express = 'X'.
    APPEND int_reclist.
    doc-obj_descr = 'Report in Excel'.
    Sending Email
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
    document_data = doc
    put_in_outbox = 'X'
    commit_work = 'X'
    TABLES
    packing_list = int_objpack
    object_header = int_objhead
    contents_bin = excel
    contents_txt = int_objtext "Body
    receivers = int_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.
    ENDFORM. " send_email
    Note:
    - If you are using FM SAP_CONVERT_TO_TXT_FORMAT you will not be able to execute this program in the background.
    - dont forget to change 'SAPUSER' to your SAP user ID
    - you can check the email by using tcode 'SBWP'.
    Reward points if this Helps.
    Manish

  • Send EXCEL attachment with garbage russia text

    Hello All - Good day!
    I have the same problem where non-english text like russian, and will appear garbage in the excel attachment after it was email.
    When I test it in english description/text it looks ok.
    I have tried the following FM, and got no luck.
    CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
    CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    Program is in Unicode.
    PLEASE help.

    Hello,
    Check the following SAP note in this regards:
      1151258 Error when sending Excel attachments
    Also, please check SAP note regarding SO_DOCUMENT_SEND_API1 interface:
       190669 Sending lists via SAPconnect
    Regards,
    David

  • Excel attachment using SO_DOCUMENT_SEND_API1

    Hi
    I am using FM SO_DOCUMENT_SEND_API1 to send .XLS attachment from ABAP program.
    I am using following code to calculate the size.
    DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
    t_packing_list-doc_size   =  t_packing_list-body_num * 255.
    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
    (I have posted only relevant code)
    This was working fine in 4.7. But since upgrade to 6.0, the attachment is transferred only half the actual size.
    i.e. if my internal table shows 4 records, the attachment in the mail shows only 2 records.
    What can be done in this case. A simple solution would be to multiply the size by 2.
    t_packing_list-doc_size   =  t_packing_list-body_num * 255 * 2.
    This works, but does seem like a work around.
    What could be the reason for this and what should be the solution?

    Hi,
    I am also using 6.0 and similar logic is working fine to calculate the size. I think there must be some problem some where else in the code. Can you put your code that you have used.
    Thanks & Regards
    Rocky

  • Send excel attachment with more than 255 characters in the internal table

    Hi,
    I need to send an attachment in the form of spreadsheet.
    But the internal table that is being used for sending attachment in mails can have only 255 characters in one row.
    Whereas my spreadsheet requires a greater width than 255 characters .

    Hi,
    I need to send an attachment in the form of spreadsheet.
    But the internal table that is being used for sending attachment in mails can have only 255 characters in one row.
    Whereas my spreadsheet requires a greater width than 255 characters .

  • 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

  • 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

  • Attachment with no extension using SO_DOCUMENT_SEND_API1

    Hi,
    anyone know if it is possible to create a txt file email attachement with SO_DOCUMENT_SEND_API1 but NOT to have the attachment name with the '.txt' extension?
    I would like the attachment to be 'filename.001' but when it is emailed it being sent as 'filename.001.txt'
    thanks.

    Hi,
    Have you tried like:
    t_packing_list-doc_type = 'RAW'.
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        EXPORTING
          document_data                    = w_doc_data
    *     PUT_IN_OUTBOX                    = ' '
         commit_work                      = 'X'
       IMPORTING
         sent_to_all                      = lv_flag
    *     NEW_OBJECT_ID                    =
        TABLES
          packing_list                     = t_packing_list

  • 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.

  • Sending email with excel attachment from an ABAP report

    Hello All,
    I am using the function module SO_DOCUMENT_SEND_API1 to send an e-mail with an excel attachment.
    The code works fine for  less than 255 characters in each row of excel file.But for more than 255 characters , the excel file received has data upto 255 characters only.
    Can someone please suggest how to send excel file with more than 255 characters in each row ?
    Regards,
    KK

    check below code
    FORM excelrep .
      DATA :l_syuzeit TYPE sy-uzeit,
            l_time(5) TYPE c,
            l_ampm(2) TYPE c,
            l_subject(255) TYPE c.
      CLEAR t_xls.
      REFRESH t_xls.
      l_syuzeit = sy-uzeit.
      IF t_final_data1[] IS NOT INITIAL.
        PERFORM fill_header.
        LOOP AT t_final_data1 WHERE status NE space.
          t_xls-jobname = t_final_data1-jobname.
          WRITE t_final_data1-act_start_date TO t_xls-act_start_date.
          WRITE t_final_data1-est_start_time TO t_xls-est_start_time.
          WRITE t_final_data1-act_start_time TO t_xls-act_start_time.
          WRITE t_final_data1-est_end_time TO t_xls-est_end_time.
          WRITE t_final_data1-act_end_time TO t_xls-act_end_time.
          t_xls-est_duration = t_final_data1-est_duration.
          t_xls-act_duration = t_final_data1-duration.
          t_xls-status = t_final_data1-comment.
          t_xls-process = t_final_data1-desc.
          t_xls-fill10 = c_0d.
          t_xls-fill1 = c_09.
          t_xls-fill2 = c_09.
          t_xls-fill3 = c_09.
          t_xls-fill4 = c_09.
          t_xls-fill5 = c_09.
          t_xls-fill6 = c_09.
          t_xls-fill7 = c_09.
          t_xls-fill8 = c_09.
          t_xls-fill9 = c_09.
          APPEND t_xls.
          CLEAR t_xls.
        ENDLOOP.
        l_ampm = c_am.
        IF l_syuzeit GT c_125959.
          l_syuzeit = l_syuzeit - c_120000.
          l_ampm = c_pm.
        ELSEIF l_syuzeit GT c_120000.
          l_ampm = c_pm.
        ELSEIF l_syuzeit LT c_010000.
          l_syuzeit = l_syuzeit + c_120000.
          l_ampm = c_am.
        ENDIF.
        WRITE l_syuzeit TO l_time USING EDIT MASK c_edmask.
        CONCATENATE text-070 l_time l_ampm INTO l_subject
                                      SEPARATED BY space.
        CLEAR w_doc_chng.
        w_doc_chng-obj_name = l_subject.
        w_doc_chng-obj_descr = l_subject.
        CLEAR t_objtxt.
        REFRESH t_objtxt.
        t_objtxt = text-068.
        APPEND t_objtxt.
        CLEAR t_objtxt.
        t_objtxt = space.
        APPEND t_objtxt.
        CLEAR t_objtxt.
        t_objtxt = text-069.
        APPEND t_objtxt.
        CLEAR t_objtxt.
        t_objtxt = space.
        APPEND t_objtxt.
        CLEAR t_objtxt.
        MOVE w_sysinfo TO t_objtxt.
        APPEND t_objtxt.
        CLEAR t_objtxt.
        t_objtxt = space.
        APPEND t_objtxt.
        CLEAR t_objtxt.
        CLEAR w_tab_lines.
        DESCRIBE TABLE t_objtxt LINES w_tab_lines.
        w_doc_chng-doc_size = w_tab_lines * c_255.
        CLEAR t_objpack.
        REFRESH t_objpack.
        t_objpack-body_start = c_1.
        t_objpack-body_num = w_tab_lines * c_255.
        t_objpack-doc_type = c_txt.
        APPEND t_objpack.
        CLEAR t_objpack.
        CLEAR t_objbin.
        REFRESH t_objbin.
        LOOP AT t_xls.
          t_objbin = t_xls.
          APPEND t_objbin.
          CLEAR t_objbin.
        ENDLOOP.
        CLEAR w_tab_lines.
        DESCRIBE TABLE t_objbin LINES w_tab_lines.
        CLEAR l_subject.
        CONCATENATE text-083 sy-datum l_time l_ampm INTO l_subject
                    SEPARATED BY c_uscore.
        CLEAR t_objhead.
        REFRESH t_objhead.
        t_objhead = l_subject.
        APPEND t_objhead.
        CLEAR t_objhead.
        t_objpack-transf_bin = c_x.
        t_objpack-head_start = c_1.
        t_objpack-head_num = c_1.
        t_objpack-body_start = c_1.
        t_objpack-body_num = w_tab_lines.
        t_objpack-doc_type = c_xls.
        t_objpack-obj_name = text-070.
        t_objpack-obj_descr = text-070.
        t_objpack-doc_size = w_tab_lines * c_255.
        t_objpack-mess_type =  space.
        APPEND t_objpack.
        CLEAR t_objpack.
        CLEAR t_reclist.
        REFRESH t_reclist.
        IF s_email[] IS NOT INITIAL.
          LOOP AT s_email.
            t_reclist-receiver = s_email-low.
            t_reclist-rec_type = c_u.
            APPEND t_reclist.
            CLEAR t_reclist.
          ENDLOOP.
        ENDIF.
        PERFORM mail_report.
      ELSE.
        MESSAGE e015 WITH text-072.
      ENDIF.
      CLEAR : w_doc_chng,
              t_objpack,
              t_objhead,
              t_objbin,
              t_objtxt.
      REFRESH : t_objpack,
                t_objhead,
                t_objbin,
                t_objtxt,
                t_reclist.
    ENDFORM.                    " excelrep_criticaljobs
    *&      Form  mail_report
          text
    -->  p1        text
    <--  p2        text
    FORM mail_report .
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        EXPORTING
          document_data              = w_doc_chng
          commit_work                = c_x
        TABLES
          packing_list               = t_objpack
          object_header              = t_objhead
          contents_bin               = t_objbin
          contents_txt               = t_objtxt
          receivers                  = t_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.
      IF sy-subrc NE 0.
        CASE sy-subrc.
          WHEN 1.
            MESSAGE i015 WITH text-071.
          WHEN 2.
            MESSAGE i015 WITH text-072.
          WHEN 4.
            MESSAGE i015 WITH text-073.
          WHEN OTHERS.
            MESSAGE i015 WITH text-074.
        ENDCASE.
      ELSE.
        MESSAGE s015 WITH text-081.
      ENDIF.
    ENDFORM.                    " mail_report

  • Send Excel as attachment with colors in coloums

    Hi,
    I need to send Excel as attachment and some particular columns should be coloured.
    I am sending Excel attachment using FM SO_DOCUMENT_SEND_API1 when report executed in foreground.
    Please help how to make columns coloured.
    Thanks,
    Phani

    hi,
    This report demonstrates how to send some ABAP data to an EXCEL sheet using OLE automation by this it makes EXCEL columns colorful.
    TYPE-POOLS OLE2 .
    * handles for OLE objects
    DATA: H_EXCEL TYPE OLE2_OBJECT,        " Excel object
           H_MAPL TYPE OLE2_OBJECT,         " list of workbooks
           H_MAP TYPE OLE2_OBJECT,          " workbook
           H_ZL TYPE OLE2_OBJECT,           " cell
           H_F TYPE OLE2_OBJECT,            " font
           H_C TYPE OLE2_OBJECT.            " color
    DATA: FILENAME LIKE RLGRAP-FILENAME.
    TABLES: SPFLI.
    DATA  H TYPE I.
    * table of flights
    DATA: IT_SPFLI LIKE SPFLI OCCURS 10 WITH HEADER LINE.
    *&   Event START-OF-SELECTION
    START-OF-SELECTION.
    * read flights
       SELECT * FROM SPFLI INTO TABLE IT_SPFLI.
    * display header
       ULINE (61).
       WRITE: /     SY-VLINE NO-GAP,
               (3)  'Flg'(001) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
               (4)  'Nr'(002) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
               (20) 'Von'(003) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
               (20) 'Nach'(004) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
               (8)  'Zeit'(005) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP.
       ULINE /(61).
    * display flights
       LOOP AT IT_SPFLI.
         WRITE: / SY-VLINE NO-GAP,
                  IT_SPFLI-CARRID COLOR COL_KEY NO-GAP, SY-VLINE NO-GAP,
                  IT_SPFLI-CONNID COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
                  IT_SPFLI-CITYFROM COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
                  IT_SPFLI-CITYTO COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
                  IT_SPFLI-DEPTIME COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP.
       ENDLOOP.
       ULINE /(61).
    * tell user what is going on
       CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
          EXPORTING
    *           PERCENTAGE = 0
                TEXT       = TEXT-007
            EXCEPTIONS
                 OTHERS     = 1.
    * start Excel
       CREATE OBJECT H_EXCEL 'EXCEL.APPLICATION'.
    *  PERFORM ERR_HDL.
       SET PROPERTY OF H_EXCEL  'Visible' = 1.
    *  CALL METHOD OF H_EXCEL 'FILESAVEAS' EXPORTING #1 = 'c:\kis_excel.xls'  .
    *  PERFORM ERR_HDL.
    * tell user what is going on
       CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
          EXPORTING
    *           PERCENTAGE = 0
                TEXT       = TEXT-008
            EXCEPTIONS
                 OTHERS     = 1.
    * get list of workbooks, initially empty
       CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.
       PERFORM ERR_HDL.
    * add a new workbook
       CALL METHOD OF H_MAPL 'Add' = H_MAP.
       PERFORM ERR_HDL.
    * tell user what is going on
       CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
          EXPORTING
    *           PERCENTAGE = 0
                TEXT       = TEXT-009
            EXCEPTIONS
                 OTHERS     = 1.
    * output column headings to active Excel sheet
       PERFORM FILL_CELL USING 1 1 1 200 'Carrier id'(001).
       PERFORM FILL_CELL USING 1 2 1 200 'Connection id'(002).
       PERFORM FILL_CELL USING 1 3 1 200 'City from'(003).
       PERFORM FILL_CELL USING 1 4 1 200 'City to'(004).
       PERFORM FILL_CELL USING 1 5 1 200 'Dep. Time'(005).
       LOOP AT IT_SPFLI.
    * copy flights to active EXCEL sheet
         H = SY-TABIX + 1.
         IF IT_SPFLI-CARRID CS 'AA'.
           PERFORM FILL_CELL USING H 1 0 000255000 IT_SPFLI-CARRID.
         ELSEIF IT_SPFLI-CARRID CS 'AZ'.
           PERFORM FILL_CELL USING H 1 0 168000000 IT_SPFLI-CARRID.
         ELSEIF IT_SPFLI-CARRID CS 'JL'.
           PERFORM FILL_CELL USING H 1 0 168168000 IT_SPFLI-CARRID.
         ELSEIF IT_SPFLI-CARRID CS 'LH'.
           PERFORM FILL_CELL USING H 1 0 111111111 IT_SPFLI-CARRID.
         ELSEIF IT_SPFLI-CARRID CS 'SQ'.
           PERFORM FILL_CELL USING H 1 0 100100100 IT_SPFLI-CARRID.
         ELSE.
           PERFORM FILL_CELL USING H 1 0 000145000 IT_SPFLI-CARRID.
         ENDIF.
         IF IT_SPFLI-CONNID LT 400.
           PERFORM FILL_CELL USING H 2 0 255000255 IT_SPFLI-CONNID.
         ELSEIF IT_SPFLI-CONNID LT 800.
           PERFORM FILL_CELL USING H 2 0 077099088 IT_SPFLI-CONNID.
         ELSE.
           PERFORM FILL_CELL USING H 2 0 246156138 IT_SPFLI-CONNID.
         ENDIF.
         IF IT_SPFLI-CITYFROM CP 'S*'.
           PERFORM FILL_CELL USING H 3 0 155155155 IT_SPFLI-CITYFROM.
         ELSEIF IT_SPFLI-CITYFROM CP 'N*'.
           PERFORM FILL_CELL USING H 3 0 189111222 IT_SPFLI-CITYFROM.
         ELSE.
           PERFORM FILL_CELL USING H 3 0 111230222 IT_SPFLI-CITYFROM.
         ENDIF.
         IF IT_SPFLI-CITYTO CP 'S*'.
           PERFORM FILL_CELL USING H 4 0 200200200 IT_SPFLI-CITYTO.
         ELSEIF IT_SPFLI-CITYTO CP 'N*'.
           PERFORM FILL_CELL USING H 4 0 000111222 IT_SPFLI-CITYTO.
         ELSE.
           PERFORM FILL_CELL USING H 4 0 130230230 IT_SPFLI-CITYTO.
         ENDIF.
         IF IT_SPFLI-DEPTIME LT '020000'.
           PERFORM FILL_CELL USING H 5 0 145145145 IT_SPFLI-DEPTIME.
         ELSEIF IT_SPFLI-DEPTIME LT '120000' .
           PERFORM FILL_CELL USING H 5 0 015215205 IT_SPFLI-DEPTIME.
         ELSEIF IT_SPFLI-DEPTIME LT '180000' .
           PERFORM FILL_CELL USING H 5 0 000215205 IT_SPFLI-DEPTIME.
         ELSE.
           PERFORM FILL_CELL USING H 5 0 115115105 IT_SPFLI-DEPTIME.
         ENDIF.
       ENDLOOP.
    * EXCEL FILENAME
       CONCATENATE SY-REPID '_' SY-DATUM+6(2) '_' SY-DATUM+4(2) '_'
                   SY-DATUM(4) '_' SY-UZEIT '.XLS' INTO FILENAME.
       CALL METHOD OF H_MAP 'SAVEAS' EXPORTING #1 = FILENAME.
       FREE OBJECT H_EXCEL.
       PERFORM ERR_HDL.
    *       FORM FILL_CELL                                                *
    *       sets cell at coordinates i,j to value val boldtype bold       *
    FORM FILL_CELL USING I J BOLD COL VAL.

  • Formatting Excel Attachment output in SO_DOCUMENT_SEND_API1

    Hi ABAPers,
    I'm hoping someone can get me started with a requirement.  I"m using SO_DOCUMENT_SEND_API1 to email a file as an excel attachment.  I'm required for a four digit code to show as (0003).  Instead, when I open the excel attachment, it displays as 3.  Would anyone know how to set the document to show all fields as text?  Any help would be appreciative.
    Thanks,
    Meezy

    Hi Venkat,
    The program is sending the 4 digit code perfectly through excel in debug mode.  However, when it's when I open the file that it get's cut off.  3000 shows up fine.  Only codes with leading 0's are cut off.  3000 shows as 3000 but 0003 shows as 3.
    Thanks,
    Meezy

  • Problem when sending mails with excel attached

    Hi
      I'm tryin to send mails via SAPOffice with attached excel documents. I'm using FM SO_NEW_DOCUMENT_ATT_SEND_API1. I have a problem with the code. Here I post it:
    DATA:  ti_objbin    LIKE solisti1   OCCURS 150 WITH HEADER LINE,
    ti_objhex    LIKE solix      OCCURS 150 WITH HEADER LINE.
    DATA: BEGIN OF i_excel,
    sobid(8) TYPE c,
    tab1 TYPE X VALUE 09, "tab code
    name(80) TYPE c,
    tab2 TYPE X VALUE 09, "tab code
    city(40) TYPE c,
    tab3 TYPE X VALUE 09, "tab code
    kostl(10) TYPE c,
    tab4 TYPE X VALUE 09, "tab code
    ktext(20) TYPE c,
    tab5 TYPE X VALUE 09, "tab code
    fasig(10) TYPE c,
    tab6 TYPE X VALUE 09, "tab code
    ruta(255) TYPE c,
    fin  TYPE X VALUE 13, "carriage return
    END OF i_excel.
    i_excel-sobid        = wa_datos-sobid.
    i_excel-name         = wa_datos-name.
    i_excel-city         = wa_datos-city.
    i_excel-kostl        = wa_datos-kostl.
    i_excel-ktext        = wa_datos-ktext.
    i_excel-fasig        = wa_datos-fasig.
    i_excel-ruta         = wa_datos-ruta.
    WRITE i_excel TO ti_objbin-line.
    APPEND ti_objbin.
    CLEAR  ti_objbin.
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
    document_data              = docdata
    put_in_outbox              = 'X'
    TABLES
    packing_list               = ti_objpack
    object_header              = ti_objhead
    contents_bin               = ti_objbin
    contents_txt               = ti_objtxt
    *      contents_hex               = ti_objhex
    receivers                  = ti_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.
    I have used this code before, in 4.6C release and it works fine, but now I'm on ECC5.0 and when i check the code, the next error message is generated: ""I_EXCEL" cannot be converted to a character-type field." If i try using MOVE i_excel TO i_objbin-line instead of WRITE, the error message changes to: ""TI_OBJBIN-LINE" and "I_EXCEL" are not mutually convertible in a Unicode program. program.". I have tried using ti_objhex table instead of ti_objbin in order to use 'context_hex' parameter (instead of 'context_bin') on FM, but i get the same result.
    I've been searching any other FM to do this, and i've found more FM of SOI1 function group but i didn´t get the expected result. So i need to send the message with the excel attached, using this FM or any other, but I need some help.  Anyone can help me?
    Thanks and Regards

    hi this is a simple example to send the excel sheet as a mail
    TABLES: ekko.
    PARAMETERS: p_email   TYPE somlreci1-receiver .
    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.
      data: ld_store(50) type c.  "Leading zeros
      CONSTANTS: con_cret(5) TYPE c VALUE '0D',  "OK for non Unicode
                 con_tab(5) TYPE c 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.
    *Modification to retain leading zeros
      inserts code for excell REPLACE command into ld_store
      =REPLACE("00100",1,5,"00100")
        concatenate '=REPLACE("' wa_charekpo-ebelp '",1,5,"'
                                 wa_charekpo-ebelp '")' into ld_store .
      concatenate ld_store into .xls file instead of actual value(ebelp)
        CONCATENATE wa_charekpo-ebeln ld_store  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,
    venkat.

Maybe you are looking for

  • Problems importing connections from a SAN directory

    Is anybody having a problem importing connections from a directory that's on a SAN? My network is setup so that the Application Data directory is out on a SAN and when SQL Developer opens up the file dialog, current directory is listed as C:\ and ent

  • Invalid Object when Calling Stored Procedure from JDBC Adapter

    JDBC Outbound adapter in XI 2.0 connected to SQL Server.  I've coded my mapping to format the XSL mapping properly but the Adapter appears to not be able to find the Stored Procedure.  Error message returned is "Invalid Object spStoredProcedureName".

  • Problems with value retorned by   FM: 'SPELL_AMOUNT' with language 'ES'

    Hi, I'm having problems with the FM 'SPELL_AMOUNT' with language 'ES'. When amount it's over 1 billion, the output is something like this: <b>Amount (NUM)</b>--<b>Actual output</b>-- <b>wanted output</b> 1.000.000.000, 00  - Un Millardo Millones - Un

  • Help System

    I am new to Authorware and I am working on my first piece. I have been trying to figure out how best to construct a help system in Authorware that is similar to the format used in Microsoft's HTML Help Workshop. This system allows you to search for h

  • Not enough memory message when opening excel and powerpoint

    I am running Mac OS X version 10.5.8. I installed Microsoft Office 2008 for Mac about a year ago and was running it without any trouble until about 3 months ago. I can still open Word, but receive a 'not enough memory' message when I try to open Exce