Send An Internal Table Via Excel File As An Attachment of E-mail

Hi,
I've sent my internal table via Excel file as an attachment of email but all records of internal table are in a row of sended excel file.
How can i send an internal table via excel file , records of internal table for each rows of excel file,as an attachment of email correctly?
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     "   t_packing_list-doc_type   =  'XLS'.
            contents_bin               = pit_attach " this is a normal internal table.
            contents_txt               = pit_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.

Hi,
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.
      LOOP AT T_FINAL INTO WA_T_FINAL.
        CONCATENATE WA_T_FINAL-PERNR
                    WA_T_FINAL-NAME
                    WA_T_FINAL-LEVEL
                    WA_T_FINAL-POS
                    WA_T_FINAL-JOB
                    WA_T_FINAL-SECTION
                    WA_T_FINAL-DEPT
                    WA_T_FINAL-GROUP
                    WA_T_FINAL-EX_HEAD
                    WA_T_FINAL-SUPID
                    WA_T_FINAL-SUPNM
                    WA_T_FINAL-FHRNM
                    WA_T_FINAL-VACID
                    WA_T_FINAL-VAC_SECTION
                    WA_T_FINAL-VAC_DEPT
                    WA_T_FINAL-VAC_GROUP
                    WA_T_FINAL-VAC_EX_HEAD
                    WA_T_FINAL-VAC_FHRNM
        INTO T_FINAL3 SEPARATED BY CON_TAB.
        CONCATENATE CON_CRET T_FINAL3 INTO T_FINAL3.
        APPEND T_FINAL3.
      ENDLOOP.
*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 = 'REPORT'.
  W_DOC_DATA-OBJ_DESCR = LD_MTITLE . "mail description
  W_DOC_DATA-SENSITIVTY = 'F'.
*Fill the document data and get size of attachment
  CLEAR W_DOC_DATA.
  READ TABLE T_FINAL1 INDEX W_CNT.
  W_DOC_DATA-DOC_SIZE =
  ( W_CNT - 1 ) * 255 + STRLEN( T_FINAL1 ).
  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[] = PT_FINAL1[].
*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 1st 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 = 'Application 1'.
  T_PACKING_LIST-OBJ_NAME = 'Application 1'.
  T_PACKING_LIST-DOC_SIZE = T_PACKING_LIST-BODY_NUM * 255.
  APPEND T_PACKING_LIST.
  CLEAR 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.
Edited by: Rahul Ghosh on Apr 6, 2009 6:42 AM

Similar Messages

  • Conversion of internal table into excel file format &put it on app server

    Hi,
    My requirement is to convert the internal table into excel file format and I have to store it on application server so that administrator can send the file thr e-mail attachment.
    So, please let me know how to convert the records of internal table and store it on application server in Excel file format.
    TIA,
    Nitin

    Hi,
      Use FM GUI_DOWNLOAD to download the data from inernal table to excel sheet.
    Then Using tcode CG3Z u can transfer file to application server.
    *&      Form  sub_download
          text
    -->  p1        text
    <--  p2        text
    FORM sub_download.
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
        BIN_FILESIZE                    =
          filename                        = p_path
         filetype                        = 'ASC'
        APPEND                          = ' '
         write_field_separator           = 'X'
        HEADER                          = '00'
        TRUNC_TRAILING_BLANKS           = ' '
        WRITE_LF                        = 'X'
        COL_SELECT                      = ' '
        COL_SELECT_MASK                 = ' '
        DAT_MODE                        = ' '
        CONFIRM_OVERWRITE               = ' '
        NO_AUTH_CHECK                   = ' '
        CODEPAGE                        = ' '
        IGNORE_CERR                     = ABAP_TRUE
        REPLACEMENT                     = '#'
        WRITE_BOM                       = ' '
        TRUNC_TRAILING_BLANKS_EOL       = 'X'
        WK1_N_FORMAT                    = ' '
        WK1_N_SIZE                      = ' '
        WK1_T_FORMAT                    = ' '
        WK1_T_SIZE                      = ' '
      IMPORTING
        FILELENGTH                      =
        TABLES
          data_tab                        = it_final
        FIELDNAMES                      =
      EXCEPTIONS
        FILE_WRITE_ERROR                = 1
        NO_BATCH                        = 2
        GUI_REFUSE_FILETRANSFER         = 3
        INVALID_TYPE                    = 4
        NO_AUTHORITY                    = 5
        UNKNOWN_ERROR                   = 6
        HEADER_NOT_ALLOWED              = 7
        SEPARATOR_NOT_ALLOWED           = 8
        FILESIZE_NOT_ALLOWED            = 9
        HEADER_TOO_LONG                 = 10
        DP_ERROR_CREATE                 = 11
        DP_ERROR_SEND                   = 12
        DP_ERROR_WRITE                  = 13
        UNKNOWN_DP_ERROR                = 14
        ACCESS_DENIED                   = 15
        DP_OUT_OF_MEMORY                = 16
        DISK_FULL                       = 17
        DP_TIMEOUT                      = 18
        FILE_NOT_FOUND                  = 19
        DATAPROVIDER_EXCEPTION          = 20
        CONTROL_FLUSH_ERROR             = 21
        OTHERS                          = 22
      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.                    " sub_download
    Otherwise use OPEN DATASET and TRANSFER statement to download data from internal table to direct application server
    Regards,
    Prashant

  • Adapter Module Error-Sending excel file as an attachment of the mail

    Hi ,
    My scenario is as follows
    1)I am sending an excel file as an attachment of the mail.I need to read that excel attachment as a payload.
    So mail adapter is used in sender side.
      To configure this, have used standard PayloadSwapBean  module with proper module key.
      Next to convert excel to XML another custom adapter module is being used.
    Both this adapter module , I configured into the CC of sender mail adapter.
    The order in which adapter modules are being used in the sender CC are as follows
    1)localejbs/AF_Modules/PayloadSwapBean
    2)localejbs/MDPExcelToXMLConversion
    3)sap.com/com.sap.aii.adapter.mail.app/XIMailAdapterBean
    MDPExcelToXMLConversion-Custom adapter module written to convert excel to xml.
    I am getting the following error
    exception caught during processing mail message [4899]com.sap.aii.af.lib.mp.module.ModuleException
    And also,
    no messages in coming MONI of PI.
    Pls suggest what to do.
    Thanks
    Ayan

    Shabarish,
    Will the ordering in which the adapter modules(In this case there are two-PayloadSwapBean & MDPExcelToXML) are appearing into Module tab of sender adapter matter?
    Firstly, what is happenning
    1)If I take out the custom  adapter module MDPExcelToXML and put only PayloadSwapBean  then it is successfully converting mail attachment into the main Payload i.e PayloadSwapBean   module is working.
    2)Nextly, my local code( i.e java code without including standard Module specific method like ejbActivate(),ejbPassivate(),process()  etc etc.)) for MDPExcelToXML is successfuly converting the excel file into the XML file.Then I am making the local code into adapter module specific code and deploying that.
    A few question arises here,
    Do I need to do any specific configurations here in PI for this particular things.Maybe both the adapter module is clashing with each other.
    And also using tracing and logging into my custom adapter module code.Getting the following error,
    java.io.IOException: Unable to read entire header; 116 bytes read; expected 512 bytes#
    Thanks
    Ayan

  • Function module to get data into internal table from Excel file sheets

    Hi,
    I have to upload customers from excel file.
    we are donloading customer data excel file sheets.
    Customer data in 1 sheet, tax data the other sheet of same excel file, Customer master-Credit data in other sheet of same excel file.
    so i have 3-4 sheet in one excel file.
    now my requirement is to get the data from excel file into internal table.
    is there any function module.
    Thanks & Regards

    I am sending you the idea with an example how you can upload data from an EXCEL file into an internal table. I am not sure if you can take data from different sheet in the same EXCEL file. I think that this is not possible (try it )
    Upload the data into an internal table, like the way that I am describing in the above:
      DATA: L_MAX_COL_NB TYPE I.
      DATA: l_file_name LIKE RLGRAP-FILENAME.
    Just to be sure that is the correct type for the FM.
      l_file_name = P_FILE_NAME.
      L_MAX_COL_NB = 58.  "Maximum nb of colums that the FM can read.
      CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
           EXPORTING
                FILENAME                = l_file_name
                I_BEGIN_COL             = 1
                I_BEGIN_ROW             = 2
                I_END_COL               = L_MAX_COL_NB
                I_END_ROW               = 9999
           TABLES
                INTERN                  = PT_EXCEL
           EXCEPTIONS
                INCONSISTENT_PARAMETERS = 1
                UPLOAD_OLE              = 2
                OTHERS                  = 3.
      IF SY-SUBRC <> 0.
      ENDIF.
    Now you should upload the data into your own itab. The Function Module will return to you all the an itab
    from all fields and columns. Define the structure of the uploading file into SE11 - Data Dictionary. Then read the fieldcatalog of this structure. In the code that I am sending to you, I am insearting an empty line into the internal table and then I am assigning this line into a corresponding field-symbol. Then I am able to change the working area - so and the line of the itab. Propably you could you the statement APPEND INITIAL LINE TO (your_table_name) ASSIGNING <your_field_symbol>, but the example was written in an old SAP version.
      FIELD-SYMBOLS:
                     <F_REC> LIKE WA_UPLOAD_FILE,      "working are of the uploading file
                     <F_FIELD> TYPE ANY.
      DATA: COLUMN_INT TYPE I,
            C_FIELDNAME(30) TYPE C.
      PERFORM GET_FIELDCATOLG TABLES FIELDCAT
                               USING 'ZECO_CHARALAMBOUS_FILE'.
      LOOP AT PT_EXCEL.
        AT NEW ROW.
          ASSIGN WA_UPLOAD_FILE TO <F_REC>.
        ENDAT.
        COLUMN_INT = PT_EXCEL-COL.
        READ TABLE FIELDCAT INTO WA_FIELDCAT INDEX COLUMN_INT.
        CONCATENATE '<F_REC>-' WA_FIELDCAT-FIELDNAME INTO C_FIELDNAME.
        ASSIGN (C_FIELDNAME) TO <F_FIELD>.
        <F_FIELD> = PT_EXCEL-VALUE.
        AT END OF ROW.
          APPEND WA_UPLOAD_FILE TO GT_UPLOAD_FILE.
          CLEAR WA_UPLOAD_FILE.
        ENDAT.
      ENDLOOP.
    With Regards
    George
    Edited by: giorgos michaelaris on Mar 4, 2010 3:44 PM

  • How to attach an internal table as excel file in wf container.

    Hi all, I have a task that is attaching an xml file in wf container, but I need to attach as excel file, how can I convert this xml to excel ?
    my currento code is like this:
    * Call Transformation to generate XSTRING of the generated data      *
      TRY .
          CALL TRANSFORMATION ztr_wf_excel
                       SOURCE appl_stat = li_data2
                       RESULT XML pi_attach.
        CATCH cx_st_error INTO lo_exception.
          lv_text = lo_exception->get_text( ).
      ENDTRY.
      IF lv_text IS INITIAL.
        pi_header-file_type      = 'B'.
        pi_header-file_name      = 'Data'.
        pi_header-file_extension = 'XLS'.
        pi_header-language       = 'E'.
          CALL FUNCTION 'SAP_WAPI_ATTACHMENT_ADD'
            EXPORTING
              workitem_id = lw_worklist-wi_id
              att_header  = pi_header
              att_bin     = pi_attach
              do_commit   = 'X'
            IMPORTING
              att_id      = lw_att_id.
    this code is working fine, but I need to attach an excel file instead an xml file
    How can I do that?
    Regards

    hi ,
    Follow this approach :
    You can use following funcntions. First one to create internal table to string and second FM SCMS_STRING_TO_XSTRING to convert String to XSTRING. Then this XSTRING value you can pass to CL_WD_RUNTIME_SERVICES=>ATTACH_FILE_TO_RESPONSE.
    data: tab_str type string.
      data: begin of it_tab1,
           name(20),
           age(10) ,
          end of it_tab1.
    data : lv_name type xstring.
             data it_tab like STANDARD TABLE OF it_tab1.
             data: wa like line of it_tab.
             wa-name = 'naresh'.
             wa-age = '30'.
             append wa to it_tab.
             wa-name = 'naresh1'.
             wa-age = '31'.
             append wa to it_tab.
    CALL FUNCTION 'SOTR_SERV_TABLE_TO_STRING'
    IMPORTING
       TEXT                      = tab_str
      TABLES
        TEXT_TAB                  = it_tab
    CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
      EXPORTING
        TEXT           = tab_str
    IMPORTING
       BUFFER         = lv_name
    CALL METHOD CL_WD_RUNTIME_SERVICES=>ATTACH_FILE_TO_RESPONSE
      EXPORTING
        I_FILENAME      = 'c:\test.txt'
        I_CONTENT       = lv_name
        I_MIME_TYPE     = 'TXT'
    Refer below links. This has been discussed many times :
    Re: download a file

  • Export internal table to Excel file pressing a new button created in ALV

    Hello, I am trying to implement the functionality to export to excel file inside a button that i have created into my ALV. I don't want to use FileDownload UI.
    The code I have set for event handler of this button is the following:
    METHOD attach_files .
      TYPES:
        BEGIN OF tipo_alv_tab,
          tipod    TYPE objid,
          descd   TYPE p1000-stext,
          begda   TYPE begdatum,
          endda   TYPE enddatum,
          pernr     TYPE pernr_d,
          nombre  TYPE ad_namefir,
          email     TYPE ad_smtpadr,
          posicion TYPE p1000-stext,
          uodesc   TYPE p1000-stext,
        END OF tipo_alv_tab.
      DATA:
        i_alv_tab    TYPE TABLE OF tipo_alv_tab,
        conv_out     TYPE REF TO cl_abap_conv_out_ce,
        content      TYPE xstring,
        lv_filename  TYPE string,
        xml_out      TYPE string.
    Fill values from memory
      IMPORT name1 TO i_alv_tab  FROM MEMORY ID 'ZCA'.
    Build XML file with internal table information
      CALL TRANSFORMATION ('ID') SOURCE tab = i_alv_tab[] RESULT XML xml_out.
    Build XSTRING with XML
      CALL FUNCTION 'CRM_IC_XML_STRING2XSTRING'
        EXPORTING
          instring   = xml_out
        IMPORTING
          outxstring = content.
    Format XSTRING
      conv_out = cl_abap_conv_out_ce=>create( encoding = 'UTF-8'  ).
    Convert data
      conv_out->convert( EXPORTING data = xml_out IMPORTING buffer = content ).
    Save file
      CALL METHOD cl_wd_runtime_services=>attach_file_to_response
        EXPORTING
          i_filename      = 'Excel File.xls'
          i_content       = content
          i_mime_type     = 'application/msexcel'
          i_in_new_window = i_in_new_window
          i_inplace       = i_inplace.
    ENDMETHOD.
    When pressing the button, the file created is without extension, and with a rare name. When trying to open the file, it seems to be corrupted.
    Does anyone know what am I doing wrong???
    Please, help is really really appreciated!!!!

    Hi Jorge,
    The export data to excel functionality is available inbuilt in ALV and you dont have to write any implementation. However, if you want to create your own button for it, you can do so as below.
    data:
    lr_button type ref to cl_salv_wd_fe_button,
    lr_function type ref to cl_salv_wd_function.
    CREATE OBJECT lr_button.
    lr_button->set_text( 'Export to excel' ).
    lr_button->set_tooltip( 'Export data to excel' ).
    lr_function = l_alv_model->if_salv_wd_function_settings~create_function( id = 'EXCEL' ).
    lr_function->set_function_std( IF_SALV_WD_C_STD_FUNCTIONS=>EXPORT_EXCEL ).
    lr_function->set_editor( lr_button ).
    Now, you have created your own button, created a user defined function for the ALV and set this button as editor for the function. And using the set_function_std method, we have just mapped the functionality of your new button to the existing export to excel functionality in ALV.
    Hope this is what you are looking for.
    Regards
    Nithya

  • Reg: Downloading the internal table into excel file.

    Hi,
    My requirement is i am collecting data in the internal table and i have to download the contents in an excel file and i have declared like this.
    PARAMETERS : x_test    TYPE string
                          DEFAULT 'C:\temp\file.txt'.
    I have given the default file path  like this and i am using the function module .
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
      BIN_FILESIZE                    =
          FILENAME                      = OUTPUT_PATH
          FILETYPE                      = 'DAT'
    IMPORTING
      FILELENGTH                      =
        TABLES
          DATA_TAB                        = INT_INPUT
      FIELDNAMES                      =
       EXCEPTIONS
         FILE_WRITE_ERROR                = 1
         NO_BATCH                        = 2
         GUI_REFUSE_FILETRANSFER         = 3
         INVALID_TYPE                    = 4
         NO_AUTHORITY                    = 5
         UNKNOWN_ERROR                   = 6
         HEADER_NOT_ALLOWED              = 7
         SEPARATOR_NOT_ALLOWED           = 8
         FILESIZE_NOT_ALLOWED            = 9
         HEADER_TOO_LONG                 = 10
         DP_ERROR_CREATE                 = 11
         DP_ERROR_SEND                   = 12
         DP_ERROR_WRITE                  = 13
         UNKNOWN_DP_ERROR                = 14
         ACCESS_DENIED                   = 15
         DP_OUT_OF_MEMORY                = 16
         DISK_FULL                       = 17
         DP_TIMEOUT                      = 18
         FILE_NOT_FOUND                  = 19
         DATAPROVIDER_EXCEPTION          = 20
         CONTROL_FLUSH_ERROR             = 21
         OTHERS                          = 22.
    My requirement is i dont want to change my extension as .txt from .exl to my parameter addition and in the function module the file type should be 'dat' only and in the runtime i want to change the file name which i have given in the .
    PARAMETERS : x_test    TYPE string
                          DEFAULT 'C:\temp\file.txt' this file.txt into datas.xls.
    it would be grateful if some one share some valuable views to wards this query
    Thanks and Regards,
    Keny

    Hi,
    Use this code.
    It will ask for the file name...there u can change.
      data : l_filename type string,
             l_filetype type char10,
             l_path type string,
             l_fullpath type string.
      l_filetype = 'DAT'.
    *Get the file name
      CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
        EXPORTING
          FILE_FILTER          = '*.DAT'
          INITIAL_DIRECTORY    = 'C:\'
        CHANGING
          FILENAME             = l_filename
          PATH                 = l_path
          FULLPATH             = l_fullpath
        EXCEPTIONS
          CNTL_ERROR           = 1
          ERROR_NO_GUI         = 2
          NOT_SUPPORTED_BY_GUI = 3
          others               = 4.
      IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      check l_fullpath is not initial.
    *Download file
      CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD
        EXPORTING
          FILENAME                = l_fullpath
          FILETYPE                = l_filetype
        CHANGING
          DATA_TAB                = t_data_sum[]
        EXCEPTIONS
          FILE_WRITE_ERROR        = 1
          NO_BATCH                = 2
          GUI_REFUSE_FILETRANSFER = 3
          INVALID_TYPE            = 4
          NO_AUTHORITY            = 5
          UNKNOWN_ERROR           = 6
          HEADER_NOT_ALLOWED      = 7
          SEPARATOR_NOT_ALLOWED   = 8
          FILESIZE_NOT_ALLOWED    = 9
          HEADER_TOO_LONG         = 10
          DP_ERROR_CREATE         = 11
          DP_ERROR_SEND           = 12
          DP_ERROR_WRITE          = 13
          UNKNOWN_DP_ERROR        = 14
          ACCESS_DENIED           = 15
          DP_OUT_OF_MEMORY        = 16
          DISK_FULL               = 17
          DP_TIMEOUT              = 18
          FILE_NOT_FOUND          = 19
          DATAPROVIDER_EXCEPTION  = 20
          CONTROL_FLUSH_ERROR     = 21
          NOT_SUPPORTED_BY_GUI    = 22
          ERROR_NO_GUI            = 23
          others                  = 24.
      IF sy-subrc NE 0.
        MESSAGE e398(00) WITH sy-subrc ' Error downloading file' '' ''.
      ENDIF.
    Regards
    Sandeep REddy

  • Downloading internal table in excel file on application server

    Hi,
        I am trying to download ITAB into excel file on my application server . I am using FM 'SAP_CONVERT_TO_XLS_FORMAT' for that .
        When I run the report I can see file getting generated on APP server but no ITAB data is saved in that excel.
        After debugging I found that error code  'SAVE_DOCUMENT_FAILED'  is retuned in above FM.
        Could any one please suggest how to go about this?
    Regards,
    Ganesh

    Hi ganesh,
    Please have a look into the below link
    [Link1|How to Upload Excel file to Application Server]
    [Link2|Error in Downloading the Text file on Application Server]
    Hope this will be Helpful
    Thanks
    Kalyan

  • Function Module to Download Internal table in EXCEL

    Hi All,
    I need a Function Module to download the Internal table to Excel File.
    I Have used SAP_CONVERT_TO_XLS_FORMAT,
    but this function modules are using GUI_Download indirectly.
    I dont want to use GUI_DOWNLOAD as i am going to call this Function Module in Portal.
    So pls anybody has this type of function module.
    Thanks & Regards,
    Dhruv Shah

    Hello Dhruv.
    In Agreement with Deniz.
    It is required to Export the query as an excel file.
    [SAP HELP Library - Standard Reference - Exporting as a CSV File / MS Excel 2000 File|http://help.sap.com/saphelp_nw04/helpdata/en/d2/11a28fc26d4042a6d230a9783152f2/content.htm]
    [SDN - Reference - Error in "Export to Microsoft Excel" from Portal|Error in "Export to Microsoft Excel" from Portal;
    Hope this works out well.
    Good Luck & Regards.
    Harsh Dave

  • Download Internal table to Excel with different Tabs -  ole2_object

    Hi All,
    I am using  ole2_object to download the data from internal table to Excel file. As per different values in sorting key, data will be downloading in different tab in same Excel file.
    In my internal table one field is of character type and some times contains number as value.
    e.g.  itab-code = ‘000002’.
    While downloading to Excel, Excel consider this value as numeric and remove the leading zero.
    Any suggestions for how to set format property as ‘Text’ for this cell, will highly appreciated.
    Sample  code -
       data: gs_excel type ole2_object,
             gs_wbooklist type ole2_object,
             gs_application type ole2_object,
             gs_wbook type ole2_object,
             gs_activesheet type ole2_object,
             gs_sheets type ole2_object,
             gs_newsheet type ole2_object,
             gs_cell type ole2_object.
       create object gs_excel 'EXCEL.APPLICATION'.
       get property of gs_excel 'workbooks' = gs_wbooklist.
       get property of gs_wbooklist 'Application' = gs_application.
       set property of gs_application 'SheetsInNewWorkbook' = 1.
       call method of gs_wbooklist 'Add' = gs_wbook.
       get property of gs_application 'ActiveSheet' = gs_activesheet.
       set property of gs_activesheet 'Name' = datasheet_name.
      call method of gs_excel 'Cells' = gs_cell exporting #1 = v_row           
                                              #2 = v_col.
      set property of gs_cell 'value' = <f>.
    GET PROPERTY OF gs_cell 'Font' = gs_Font.
    SET PROPERTY OF gs_Font 'Bold' = 1 .
    Thanks.
    Regards,
    Meenakshi.

    Hello,
    Just concatenate ' infont of the fields, which you want to treat as a text.
    Like,
    itab-code = '00002'.
    concatenate '''' itab-code  into itab-code.
    modify itab.
    You can also set the text properties of the cell by,
      SET PROPERTY OF gs_cell 'NumberFormat' = '@' .
    but, it will remove the leading zeros and set the format as text.
    Regards,
    Naimesh

  • Downloading table to excel-file obeying special conditions

    hi all.
    i download the internal table to excel file. the excel file is not initial, it has a header line (names of fields). I need to add the data from the table to the file, overwriting the previous data(if it was), but saving the header line. one more requirement: i need to be able to set visible length of each field. is it possible to do using standard function 'GUI_DOWNLOAD'?
    thanks all in advance.

    With GUI_DOWNLOAD, you could only append (and not an actual XLS file, but a DAT or TXT file)
    You should try to use OLE instructions, look at <a href="http://www.sap-img.com/abap/download-to-excel-with-format-border-color-cell-etc.htm">Download a report to excel with format (border, color cell, etc)</a> for a sample program using OLE.
    Regards

  • Download Internal Table to Excel

    Hi All,
    I m new to Webdynpro for ABAP and i m trying to download the data as it is in the Internal Table to excel file using FM 'CRM_IC_XML_STRING2XSTRING' ( to convert string to xstring) and CLASS 'cl_wd_runtime_services=>attach_file_to_response' ( to attach the content in excel).
    The export is working fine, but it also has some extra rows and columns with data "/asx:abap".
    Also the header is appended with data like "/@version/#agg".
    The columns were sorted by its name and gets interchanged and sometimes repeated too.
    Is there a way to get the header formatted and trim the unwanted rows and columns appearing.
    Thanks in advance,
    Raju J

    Hi Vankat,
    In last thread i have posted that creating an XLST for the xml will solve the problem. But still it was working fine in MS Excel 2007 and not in the older versions in my case.
    Again, i thought of following the method adviced by Radhika(in the previous post).
    Loop your internal table and concatenate the content to a string variable SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
    Then convert the string to XSTRING using the below FM.
    CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
            EXPORTING
              text   = l_outstream "Concatenated string
            IMPORTING
              buffer = l_content.  "Resulted xstring
    Then call the cl_wd_runtime_services as mentioned below.
    cl_wd_runtime_services=>attach_file_to_response(
          i_filename = 'filename.xls'
          i_content = l_content            "Resulted xstring
          i_mime_type = 'EXCEL'
          i_in_new_window = abap_true ).
    This is one way and the other is,
    If you want to do it using
    CALL TRANSFORMATION ZXSLT    "While creating ZXSLT select the prog. type as XSLT program.
    SOURCE tab = internal_table[]
    RESULT XML l_outstream.
    Then convert the l_outstream to xstring and attach to cl_wd_runtime_services.
    ZXSLT will contain code like this,
    <xsl:transform version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:asx="http://www.sap.com/abapxml"
      xmlns:x="urn:schemas-microsoft-com:office:excel">
    <xsl:strip-space elements="*"/>
    <xsl:template match="asx:abap/asx:values/TAB">
    <items>
    <xsl:for-each select  = "item">
    <it>
    <OBJECT_ID><xsl:value-of select="OBJECT_ID"/></OBJECT_ID>
    <DESCRIPTION><xsl:value-of select="DESCRIPTION"/></DESCRIPTION>
    </it>
    </xsl:for-each>
    </items>
    </xsl:template>
    </xsl:transform>
    I think this will solve your problem.
    Regards,
    Raju J

  • Send an internal table as a PDF file by mail

    Hello all.
    I want to send an internal table that was created in the
    program by mail. i wand that it will be in a PDF format.
    Can anyone help me?
    Thanks.

    hiii
    you can use following FM
    DATA: "t_line            LIKE tline OCCURS 0 WITH HEADER LINE,
            t_objcont         LIKE soli  OCCURS 0 WITH HEADER LINE,
            d_doc_size(12)    TYPE c,
            d_fle1(2)         TYPE p,
            d_fle2(2)         TYPE p,
            d_off1            TYPE p,
            d_hltlines        TYPE i,
            d_hfeld(500)      TYPE c,
            w_indx            LIKE sy-tabix.
      CLEAR: t_line, t_objcont, d_off1.
      REFRESH: t_line, t_objcont.
    * Check/set DEFAULT Desired-type attachment...
      IF d_desired_type IS INITIAL.        " Entered Desired type?
        d_desired_type = 'PDF'.            " NO  - default to PDF
      ENDIF.                               "
      CALL FUNCTION 'CONVERT_OTF'
        EXPORTING
          format                = d_desired_type
        IMPORTING
          bin_filesize          = d_doc_size
        TABLES
          otf                   = t_itcoo
          lines                 = t_line
        EXCEPTIONS
          err_max_linewidth     = 1
          err_format            = 2
          err_conv_not_possible = 3
          OTHERS                = 4.
      IF sy-subrc > 0.
        RAISE otf_convert_failed.
      ENDIF.
    then you can use following FM for sending mail
    * Send the EMAIL out with SAP function...
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        EXPORTING
          document_data              = h_doc_data
          put_in_outbox              = 'X'
    *      commit_work                = 'X'
        TABLES
          packing_list               = t_pak_list
          contents_bin               = t_con_bin
          contents_txt               = t_con_text
          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.
    regards
    twinkal

  • Create key mapping using import manager for lookup table FROM EXCEL file

    hello,
    i would like create key mapping while importing the values via excel file.
    the source file containing the key, but how do i map it to the lookup table?
    the properties of the table has enable the creation of mapping key. but during the mapping in import manager, i cant find any way to map the key mapping..
    eg
    lookup table contains:
    Material Group
    Code
    excel file contain
    MatGroup1  Code   System
    Thanks!
    Shanti

    Hi Shanti,
    Assuming you have already defined below listed points
    1)  Key Mapping "Yes" to your lookup table in MDM Console
    2) Created a New Remote System in MDM console
    3) proper rights for your account for updating the remote key values in to data manager through import manager.
    Your sample file can have Material Group and Code alone which can be exported from Data Manager by File-> Export To -> Excel, if you have  data already in Data Manager.
    Open your sample file through Import Manager by selecting  the remote system for which you want to import the Key mapping.
    (Do Not select MDM as Remote System, which do not allows you to maintain key mapping values) and also the file type as Excel
    Now select your Soruce and Destination tables, under the destination fields you will be seeing a new field called [Remote Key]
    Map you source and destination fields correspondingly and Clone your source field code by right clicking on code in the source hierarchy and map it to Remote Key if you want the code to be in the remote key values.
    And in the matching criteria select destination field code as a Matching field and change the default import action to Update NULL fields or UPDATED MAPPED FIELDS as required,
    After sucessfull import you can check the Remote Key values in Data Manager.
    Hope this helps
    Thanks
    Sowseel

  • How to download internal table to excel sheet

    I have a requirement to download nearly 8 to 10 internal tables to excel sheets(for each internal table one excel sheet) without displaying the diolog box showing open and save buttons.
    scenario :
      I will enter the path name like this -   C:\myfolder\Custom_programs.xls.
                                                            C:\myfolder\Custom_tables.xls.
                                                            (File name does not exit..it has to created inside the    
                                                                specified folder)
      in submit button I populate 2 internal tables say it1 and it2. then I need to move the tables contents to the path I have specified above.
    attach_file_to_response method is not working for the above reqt since it is showing the dialog box.
    Please provide a suitable solution...

    Please ignore all the responders that are stating that you can use GUI_DOWNLOAD from Web Dynpro ABAP.  As you found out, this absolutely will not work, since this function module and other download logic like it depends upon a connection to the SAPGUI. People posting to use the GUI_DOWNLOAD from WDA need to learn a little more about the architecture of WDA before they go posting incorrect repsonses in the forum. I have little tollerance for people posting outright incorrect information in the WDA Forum.
    What you want to do - download silent - is not easily done from WDA.  There are rules about how web applications must behave in a browser.  Normal HTML/JavaScript does not allow silent downloads for security reasons.  Obviously there are many untrustworthy websites on the internet that you wouldn't want to allow to directly access your local machine.  WDA must live within these same browser limitations.
    SAP has done some work using a Java Applet to get around some of these security issues.  This funcitonality comes in NetWeaver 7.01.  It is the AcfUpDownload UI element:
    http://help.sap.com/saphelp_nw70ehp1/helpdata/en/47/b9157c878a2d67e10000000a42189c/frameset.htm
    However it is designer for usage with the Content or KPro server - so even it might not meet your needs.

Maybe you are looking for