Regarding Excel Download in Block list ALV

Hi Abaper's,
I am facing with one problem during downloading of the BlockList ALV.
<b>If I click on the standart toolbar  'local file button '( ctrl + shift + F9) it is downloading the ALV data into the excel file but the ALV header information starts from column 1 and ALV data information starts from the 2nd column.</b>
Please suggest me is it the expected functionality of the Block List ALV or I have written wrong code. Please suggest me.

I think there is something wrong with the output...maybe you should check your fieldcatalog wheter it matches to the structure of your internal table of data you want to show.
Normally you should get an output per column with the fieldnames in the first line starting with 1st column and the data starting in 2nd line starting with 1st col.
hope that helps you off, please award if useful!
Clemens

Similar Messages

  • How to download a Block List based ALV report to PDF file?

    Hi Everyone,
    I need to display a report in block list alv format using REUSE_ALV_BLOCK_LIST_DISPLAY... I have done this. But my problem comes next.
    1. I need to download this report to a pdf file in the user given directory - in presentation server. How can I download this in PDF format.
    2. My report has TOP_OF_LIST and END_OF_LIST events. The body of the report contains a table with some material data. There should be 1 table for each material no. There are around 50 records for each material no. So I am looping at the material no. and calling REUSE_ALV_BLOCK_LIST_APPEND.
    Now my problem is that I should have only 20 records in each page. How can I determine this? How do I put a page-break?
    Please anyone help me.

    Hi Anwesha
    You can send the report output to spool using the IS_PRINT parameter of REUSE_ALV_BLOCK_LIST_DISPLAY FM. Then read the spool number generated and pass it to CONVERT_ABAPSPOOLJOB_2_PDF to get the pdf content which could be downloaded to presentation server.
    The splitting of records on count could be done by calling above method with different internal table filtered as per your requirement.
    Regards
    Ranganath

  • Top of page in Block list ALV

    HI,
    I have a Requirement where i have a Block list ALV . I have 4 blocks to be Displayed in the output and the output has to be transfered to the PDF.
    I am able to get the 4 blocks in the output and the Top of Page for the Report in each page.
    But the Problem is when i download the output containing the top of page of output with 4 blocks into a PDF.
    I want the Top of page of Report to be the Top of Page of the PDf also.
    In PDF the Top of page of Report is coming in the center of the PDF also in some other places also.
    How to make sure the Top of page of Report comes in the top of the PDf
    Can you kinldy help me in this.
    Thanks,
    Gokul

    Duplicate post.
    Reported.

  • Regarding Excel Downloading

    Hi,
       I have one problem related to Excel Downloads. When I download my ALV LIST to Excel File(using Excel Button in Application Toolbar), the Order of the Header of my Alv List are changed in Excel File.
       How can i get the Excel File on the Same Order as per the ALV List.
      In My ALVlist the Headers are
              OrderNo  Material No Material Desc Inspection LotNo Issed Qty  UOM  Packedcontainers DispensedQty Stores Remarks.
    But in My Excel File the header(and Details) appears as
               OrderNo MaterialNo MaterialDesc Packedcontainers  Remarks  DispensedQty Stores InspectionNo IssuedQty 
       How can i correct the Problem?
    With Regards,
    Neptune.M

    Hi Selvan,
    U need to define a new pf status and add new button to download to excel.
    In the coding you need to call fuction 'ALV_XXL_CALL'.
    Regards,
    Suresh P

  • Regarding excel download from ALV report tree

    Hi Experts,
    I have a ALV report tree program. In that i need the functionality to download report output in excel file.
    Can any body suggest how can i achieve download to excel functionality in it.
    Any useful suggestion will be appreciated.
    Thanks in advance,
    Akash

    The data for the tree exist in the NODE table in a different format. So, even you download that table, it will not be downloaded in the TREE format. So, the user will not be able to understand the data unlike the case of a ALV GRID.
    Whether it is a TREE / GRID, ultimately its the data of a internal table, that gets downloaded. But in case a TREE, we don't have the data in a straight forward way . i thnk it is not possible . i am not sure too for this .

  • Block List ALV Output Send As Email Attachment

    Hi,  All The ABAP Gurus,
    I have made a block ALV Report. I want that this output should be converted into .xls with HTML format and this should be send in email as attachment. This all will be made in a background job which will be scheduled daily.
    How can I achieve this? I know that the output of classical report can be attached as pdf in email.But I want in Block ALV.
    Thanks in Advance.
    Regards,
    Bharti Jain
    Edited by: Bharti Jain on Jun 28, 2011 10:20 AM

    Hi
    Not 100 percent sure what you want to do here.  I am confused by the .xls in html format.   If you want the output in html you can submit the program and export the list to memory,  Then retrieve the list and convert it to html.  i have done this with the program 1sdbf12l/rv14akzy . see code below.  This converts the output to html, you are left with a binary itab and size at the end of the routine and this can be attached to an email.
    Submit Program and export the list to Memory
    SUBMIT /1sdbf12l/rv14akzy USING SELECTION-SCREEN '1000'
      WITH SELECTION-TABLE lt_params_new EXPORTING LIST TO MEMORY AND RETURN.
      CALL FUNCTION 'LIST_FROM_MEMORY'
        TABLES
          listobject = lt_list
        EXCEPTIONS
          not_found  = 1
          OTHERS     = 2.
    Convert the List to html
      IF sy-subrc = 0.
        DATA: it_html TYPE TABLE OF bapihtml WITH HEADER LINE,
              it_html_out TYPE TABLE OF bapihtml WITH HEADER LINE,
              lt_html TYPE TABLE OF bapihtml WITH HEADER LINE,
              lv_html LIKE LINE OF it_html,
              lv_html_out TYPE string.
        DATA: lv_html_tab_wide(50000) TYPE c.
        DATA: lineno TYPE i, length TYPE i, size TYPE i.
        DATA: gui_codepage(4) TYPE n,        " added for message 500824
              is_unicode TYPE rststype-sel_ok.
        DATA: convert_output TYPE xstring,
              convert_buffer TYPE xstring.
        CALL FUNCTION 'LIST_FREE_MEMORY'
          TABLES
            listobject = lt_list.
        CALL FUNCTION 'WWW_HTML_FROM_LISTOBJECT'
             EXPORTING
                  REPORT_NAME   =
                  template_name = 'WEBREPORTING_REPORT'
             TABLES
                  html          =  it_html
                  listobject    =  lt_list.
        DESCRIBE TABLE it_html LINES lineno .
        DESCRIBE FIELD it_html LENGTH length IN BYTE MODE.
        size = length * lineno.
        CALL 'CUR_LCL' ID 'GUICP'  FIELD gui_codepage.
        CALL FUNCTION 'SCP_GET_CODEPAGE_PROPERTIES'
          EXPORTING
            codepage         = gui_codepage
          IMPORTING
            can_unicode      = is_unicode
          EXCEPTIONS
            codepage_unknown = 1.
        IF sy-subrc <> 0.
          CLEAR gui_codepage.
        ENDIF.
        IF is_unicode EQ 'X'.         "in case of unicode, always use utf-8
          gui_codepage = '4110'.
        ENDIF.
        CLEAR: convert_output, convert_buffer.
        LOOP AT it_html INTO lv_html.
          REPLACE ALL OCCURRENCES OF c_bg_def IN lv_html WITH c_bg_white.
          CALL FUNCTION 'SCP_TRANSLATE_CHARS'
            EXPORTING
              inbuff           = lv_html
              outcode          = gui_codepage
              csubst           = 'X'
              substc_space     = 'X'
            IMPORTING
              outbuff          = convert_output
            EXCEPTIONS
              invalid_codepage = 1
              internal_error   = 2
              cannot_convert   = 3
              fields_bad_type  = 4
              OTHERS           = 5.
          IF sy-subrc <> 0.
           message i020 raising download_error.
          ENDIF.
          CONCATENATE convert_buffer convert_output INTO convert_buffer IN
          BYTE MODE.
          CONCATENATE lv_html_out lv_html INTO lv_html_out.
        ENDLOOP.
        ev_html_string = lv_html_out.
        i = 0.
        DESCRIBE FIELD html_tab_converted LENGTH tablength IN BYTE MODE.
        WHILE i < XSTRLEN( convert_buffer ).
          dummy = XSTRLEN( convert_buffer ) - i.
          IF tablength > dummy.
            html_tab_converted-line = convert_buffer+i(dummy).
          ELSE.
            html_tab_converted-line = convert_buffer+i(tablength).
          ENDIF.
          i = i + tablength.
          APPEND html_tab_converted.
        ENDWHILE.
        et_bin[] = html_tab_converted[].
        ev_bin_size = size.

  • Issue in Block list ALV

    Hi All,
    I want output in below format
    ***************************Page Heading****************
    List heading 1********************
                     LIST 1
    List Footer 1**********************
    List heading 2********************
                     LIST 2
    List Footer 2**********************
    List heading 3********************
                     LIST 3
    List Footer 3**********************
    I am trying with below code for two list but the order of Page heading and List heading 1 is interchanged. Please tell me whats the problem or please correct the part of code cuz of with the order is not coming correct.
    <b>code :</b>
    *& Report  ZTEST_IZHAR
    REPORT  ZTEST_IZHAR.
    Declarations for BLOCK ALV DISPLAY
    *--type pools
    TYPE-POOLS:slis.
    DATA:x_layout TYPE slis_layout_alv,
    t_field TYPE slis_t_fieldcat_alv,
    *--field catalog
    x_fldcat LIKE LINE OF t_field,
    *--to hold all the events
    t_events TYPE slis_t_event,
    x_events TYPE slis_alv_event,
    t_sort TYPE slis_t_sortinfo_alv,
    x_sort LIKE LINE OF t_sort ,
    *--Print Layout
    x_print_layout TYPE slis_print_alv.
    *----Macro to add field catalog.
    *field "text "length "tech "COL_POS "DATATYPE "DDIC_OUTPUTLEN
    DEFINE add_catalog.
      clear x_fldcat.
      x_fldcat-fieldname = &1.
      x_fldcat-seltext_m = &2.
      x_fldcat-outputlen = &3.
      x_fldcat-tech = &4.
      x_fldcat-col_pos = &5.
      x_fldcat-no_zero = 'X'.
      x_fldcat-ddictxt = 'M'.
      x_fldcat-datatype = &6.
      x_fldcat-ddic_outputlen = &7.
      if &6 = 'N'.
        x_fldcat-lzero = 'X'.
      endif.
    *--build field catalog
      append x_fldcat to t_field.
    END-OF-DEFINITION.
    *----- data declerations.
    data: v_repid like sy-repid.
    data: begin of itab occurs 0,
    matnr like mara-matnr,
    ernam like mara-ernam,
    meins like mara-meins,
    end of itab.
    data: begin of jtab occurs 0,
    matnr like makt-matnr,
    maktx like makt-maktx,
    end of jtab.
    select matnr ernam meins
    up to 20 rows
    from mara
    into table itab.
    select matnr maktx
    up to 20 rows
    from makt
    into table jtab.
    v_repid = sy-repid.
    *DISPLAY alv
    Initialize Block
    call function 'REUSE_ALV_BLOCK_LIST_INIT'
      EXPORTING
        i_callback_program = v_repid.
    *Block 1:
    *INITIALIZE
    refresh t_field. clear t_field.
    refresh t_events.
    *field "text "length "tech "COL_POS "DATATYPE "DDIC_OUTPUTLEN
    add_catalog:
    'MATNR' 'Material' '18' '' '1' 'C' '18',
    'ERNAM' 'Created By' '12' '' '2' 'C' '12',
    'MEINS' 'Unit' '5' '' '3' 'C' '3'.
    *--build table for events TOP OF PAGE.
    x_events-form = 'TOP_OF_PAGE'.
    x_events-name = slis_ev_top_of_page.
    append x_events to t_events.
    *--build table for events TOP OF LIST1.
    x_events-form = 'TOP_OF_LIST1'.
    x_events-name = slis_ev_top_of_list.
    append x_events to t_events.
    *--build table for events END OF LIST1.
    x_events-form = 'END_OF_LIST1'.
    x_events-name = slis_ev_end_of_list.
    append x_events to t_events.
    call function 'REUSE_ALV_BLOCK_LIST_APPEND'
      EXPORTING
        is_layout                  = x_layout
        it_fieldcat                = t_field
        i_tabname                  = 'ITAB'
        it_events                  = t_events
        it_sort                    = t_sort
      TABLES
        t_outtab                   = itab
      EXCEPTIONS
        program_error              = 1
        maximum_of_appends_reached = 2
        others                     = 3.
    if sy-subrc <> 0.
      message id sy-msgid type sy-msgty number sy-msgno
      with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    endif.
    *--BLOCK 2(SUMMARY REPORT)
    *INITIALIZE
    refresh t_field. clear t_field.
    refresh t_events.
    *field "text "length "tech "COL_POS "DATATYPE "DDIC_OUTPUTLEN
    add_catalog:
    'MATNR' 'Material' '20' '' '1' 'C' '18',
    'MAKTX' 'Description' '40' '' '2' 'C' '40'.
    *--build table for events TOP OF LIST2.
    x_events-form = 'TOP_OF_LIST2'.
    x_events-name = slis_ev_top_of_list.
    append x_events to t_events.
    *--build table for events END OF LIST2.
    x_events-form = 'END_OF_LIST2'.
    x_events-name = slis_ev_end_of_list.
    append x_events to t_events.
    Append table block.
    call function 'REUSE_ALV_BLOCK_LIST_APPEND'
      EXPORTING
        is_layout                  = x_layout
        it_fieldcat                = t_field
        i_tabname                  = 'JTAB'
        it_events                  = t_events
      TABLES
        t_outtab                   = jtab
      EXCEPTIONS
        program_error              = 1
        maximum_of_appends_reached = 2
        others                     = 3.
    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 FM TO DISPLAY THE BLOCK REPORT.
    call function 'REUSE_ALV_BLOCK_LIST_DISPLAY'
    exporting
    is_print = x_print_layout
    exceptions
    program_error = 1
    others = 2.
    if sy-subrc <> 0.
      message id sy-msgid type sy-msgty number sy-msgno
      with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    endif.
    *&      Form  top_of_PAGE
          text
    form top_of_page.
    skip 1.
      WRITE: / '*******************************************'.
      WRITE : /10 'TOP OF PAGE'.
      WRITE: / '*******************************************'.
      skip 1.
      perform sub_display_heading.
      format reset.
    endform.                    "top_of_list2
    *&      Form  top_of_list1
          text
    form top_of_list1.
    skip 3.
      write: /5 'TOP OF LIST 1'.
      skip 1.
      format reset.
    endform.                    "top_of_list1
    *&      Form  end_of_list2
          text
    form end_of_list1.
      skip 1.
      write: /5 'END OF LIST 1'.
      skip 1.
      format reset.
    endform.                    "top_of_list2
    *&      Form  top_of_list2
          text
    form top_of_list2.
      skip 1.
      write: /5 'TOP OF LIST 2'.
      skip 1.
      format reset.
    endform.                    "top_of_list2
    *&      Form  end_of_list2
          text
    form end_of_list2.
      skip 1.
      WRITE:  /5 'END OF LIST 2'.
      skip 1.
      format reset.
    endform.                    "top_of_list2
    *&      Form  sub_display_heading
          text
    FORM sub_display_heading .
    ENDFORM.                    " sub_display_heading

    Hi ABAP related,
    Why dont you debug and see the scene yourself?
    Do not accumulate with this record.
    Total Questions:  77 (37 unresolved) 
    Cheers

  • ALV Block List Excel download

    Hi,
    I am using 'REUSE_ALV_BLOCK_LIST_APPEND' and 'REUSE_ALV_BLOCK_LIST_DISPLAY' to output 2 reports (Header and Item) on the same screen.
    Since, SAP does not give Excel icon for Block List by default, I added an icon and used 'GUI_DOWNLOAD' function to download 2 separate excel files. Is it possible to combine both the reports into 1 file?

    In second call to GUI_DOWNLOAD use same path, and set function output parameter APPEND to X. Lines of second table, will be appended to file created with first table lines.
    Regards.

  • Max. no of columns in ALV Excel download

    I've a problem regarding the download of data from alv report's that have more than 99 columns.
    I have searched the forum but couldn't find a right answer.
    It is being done by standard option and not by custom functionality is there any way where we can increase this limitation.

    I don't know if there is a way it for more columns using that function.     But I suggest you to use excel inplace tool. With excel inplace users directly display and maintain values in SAP screen and they can save final document without any limits I think. Just go to change layout-> view and choose microsoft excel. To be able to display excel using this option macro security in installed MS Excel should be in low and VB script execution must be on.

  • Displaying dynamic No. of blocks in alv

    hi experts,
    i have a blocked alv list and the blocks are displayed with respect to the department...i want to display the block alv but i dont know the number of departments so the number of blocks would be dynamic that i will get from the internal table..
    i tried to use append block in loop with respect to the department but could not display it..can any one guide me..
    with thanks in advance,
    syed

    thanks again,
    My problem is not displaying the Block ALV but to Display it dynamically.. that is  i will not know how many blocks i will need until runtime..so i cannot predefine my no of blocks as in the Code you provide..
    for example...if i have 4 departments i need to have four blocks for 4 departments and if 5 means 5 departments
    below is my code.
    CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
      EXPORTING
        i_callback_program      = SY-REPID
        i_callback_user_command = 'USER_COMMAND'.
    LOOP AT IPUT INTO WPUT.
          ASSIGN COMPONENT SY-INDEX OF STRUCTURE WPUT TO <OUTTAB>.
          APPEND <OUTTAB> TO OUTTABLE.
    ON CHANGE OF WPUT-DEPARTMENT."i need to find the no. of blocks with respect to the number of department
    PERFORM APPEND_BLOCK."when there is a change in department a block has to be added..
    REFRESH OUTTABLE.CLEAR OUTTABLE."here the value is getting refreshed as it should but if i call reuse alv block list alv before refreshing the the first block appeara then when i click back the 2nd block apperas twice. and 3rd and 4th as such..
    ENDON.
    CLEAR WPUT.
      ENDLOOP.
      CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
      EXPORTING
        i_interface_check = ' '
      EXCEPTIONS
        program_error     = 1
        OTHERS            = 2.
    "perform append _block
    CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
      EXPORTING
        it_fieldcat                = gt_fieldcatcH[]
        is_layout                  = t_layout
        i_tabname                  = 'OUTTABLE'
        it_events                  = t_event
      TABLES
        t_outtab                   = OUTTABLE
      EXCEPTIONS
        program_error              = 1
        maximum_of_appends_reached = 2
        OTHERS                     = 3.
    thanks in advance,
    syed

  • Excel download for ALV Block report (List- export- spreadsheet)

    Dear friends,
    I want to download the output into Excel...
    I am using all SAP standards and using the ALV Block list
    Ex: List->export->local file..  is anable from here i can download to excell .....but the same there is anothere option : List->export->spreadsheet...( this one inactive.)
    I want to activate the  List->export->spreadsheet option.
    how to do this???
    Thanks,
    Sridhar.

    hi Sridhar,
    there is already an option to download in spreadsheet format when saving to local file...then why do you want to activate List->export->spreadsheet ????
    regards,
    madhu

  • Blocked ALV Excel Download Issue

    Hi Experts,
    My customers requirement is to download the output of Quotation Comparison Report with exact alignments as how it displays on Screen.
    When I tried to download from Standard SAP Save options, like List->save.... Export.. Spreadsheet........, I am not getting the same format into the Excel Sheet.
    I went into the program to check and found that it is a Blocked ALV.
    I have 3 Blocks in the Outputs.
    I am missing the alignment of Second Block having "Quoted" "Negotiated" to left side.
    Kindly help me in downloading this as it is.
    Regards,
    G.V.S Praveen Kumar

    Hi Sumeet,
    DATA: lv_exit   TYPE char1,                               "#EC NEEDED
             lwa_exit  TYPE slis_exit_by_user,                   "#EC NEEDED
             lt_excl   TYPE slis_t_extab,
             lwa_event TYPE slis_alv_event.
       DATA: lwa_layout1 TYPE slis_layout_alv,
             lwa_layout2 TYPE slis_layout_alv,
             lwa_layout3 TYPE slis_layout_alv,
             lt_events   TYPE slis_t_event.
    FIELD-SYMBOLS: <t_block1> TYPE STANDARD TABLE,
                    <t_block2> TYPE STANDARD TABLE,
                    <t_block3> TYPE STANDARD TABLE,
                    <w_block>  TYPE any.
    * Initializing the Block List
       CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
         EXPORTING
           i_callback_program       = sy-repid
           i_callback_pf_status_set = 'PF_STATUS'
           i_callback_user_command  = 'USER_COMMAND'
           it_excluding             = lt_excl.
    CONSTANTS:slis_ev_top_of_list TYPE slis_formname VALUE 'TOP_OF_LIST'.
       lwa_event-name = slis_ev_top_of_list.
       lwa_event-form = 'HEADER_TOP_OF_LIST'.
       APPEND lwa_event TO lt_events.
       CLEAR  lwa_event.
       lwa_layout1-no_colhead = 'X'.
       lwa_layout1-zebra = 'X'.
    * Appending the block data for header to the list
       CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
         EXPORTING
           is_layout                  = lwa_layout1
           it_fieldcat                = t_fld1
           i_tabname                  = '<T_BLOCK1>'
           it_events                  = lt_events
         TABLES
           t_outtab                   = <t_block1>
         EXCEPTIONS
           program_error              = 1
           maximum_of_appends_reached = 2
           OTHERS                     = 3.
       IF sy-subrc <> 0.
         MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
       ENDIF.
       REFRESH lt_events.
       lwa_event-name = slis_ev_top_of_list.
       lwa_event-form = 'ITEM_TOP_OF_LIST'.
       APPEND lwa_event TO lt_events.
       CLEAR  lwa_event.
       lwa_layout2-no_colhead = 'X'.
       lwa_layout2-zebra = 'X'.
    * Appending the block data for item to the list
       CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
         EXPORTING
           is_layout                  = lwa_layout2
           it_fieldcat                = t_fld2
           i_tabname                  = '<T_BLOCK2>'
           it_events                  = lt_events
         TABLES
           t_outtab                   = <t_block2>
         EXCEPTIONS
           program_error              = 1
           maximum_of_appends_reached = 2
           OTHERS                     = 3.
       IF sy-subrc <> 0.
         MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
       ENDIF.
       lwa_layout3-no_colhead = 'X'.
       lwa_layout3-zebra = 'X'.
       REFRESH lt_events.
    * Appending the block data for item to the list
       CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
         EXPORTING
           is_layout                  = lwa_layout3
           it_fieldcat                = t_fld3
           i_tabname                  = '<T_BLOCK3>'
           it_events                  = lt_events
         TABLES
           t_outtab                   = <t_block3>
         EXCEPTIONS
           program_error              = 1
           maximum_of_appends_reached = 2
           OTHERS                     = 3.
       IF sy-subrc <> 0.
         MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
       ENDIF.
    * Displaying the block list
       CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
         EXPORTING
           i_screen_start_column   = 0
           i_screen_start_line     = 0
           i_screen_end_column     = 0
           i_screen_end_line       = 0
         IMPORTING
           e_exit_caused_by_caller = lv_exit
           es_exit_caused_by_user  = lwa_exit
         EXCEPTIONS
           program_error           = 1
           OTHERS                  = 2.
       IF sy-subrc <> 0.
         MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
       ENDIF.

  • Download Hierarchial List ALV  to excel

    Hi all,
    Please provide me the solution on using download button in Hierarchial List ALV to download to excel.The output of excel need to be exacted as the output of ALV (All header and items details).
    Please suggest the solution and sample code ASAP.
    Thanks and Regards.

    Hello,
    Find the code where method set_table_for_first_display of tree object (CL_GUI_ALV_TREE) used in your program,
    and learn  table of tree from there :
    CALL METHOD g_tree->set_table_for_first_display
    EXPORTING
      i_structure_name    = g_structname
      is_hierarchy_header = g_hierarchy_header
    CHANGING
      it_fieldcatalog     = g_fieldcat
      it_outtab           = it_result .   "<-- this table contains hierarchical data
    And than download this table using class CL_GUI_FRONTEND_SERVICES
    and methods FILE_SAVE_DIALOG and GUI_DOWNLOAD or function GUI_DOWNLOAD
    you can find too many of examples in forum.

  • Regarding Downloading of Report[List] output into Excel Sheet

    Hi All,
    Hi i have written one Classical report. I got the output Correctly.
    Now i want to download that data into Excel Sheet in excatly the way it displayed in List[Report] output.
    I had followed the path <b>System->List->Save->LocalFile->Spread Sheet</b> and tried to download the same.
    Though it is downloaded it has not come in exact format.
    Now what i want is to add a button above that report & write a program in that to download that data into Excel Sheet.
    Can anybody tell me how can solve this issue. If i follow above procedure will the data[List Output] be downloaded into exact format into excel.
    If anybody knows other way please sujjest.
    Thanks in advance.
    Thanks & Regards,
    Prasad.

    Hi Prasad,
    I have done a program which downloads the output in the excel sheet in the correct format.
    Just check the program. The code given in bold is what you have to use.
    REPORT zexp MESSAGE-ID f4  LINE-SIZE 195.
        Tables Used    ***********************************
    TABLES : bseg, bkpf, bsak, lfa1, payr .
    Declaring Internal Tables  **************************
    DATA :
    Internal table to hold header data  *************
    BEGIN OF header OCCURS 0,
          ext_date(10) TYPE c,
          delimit(1)   TYPE c,
          ext_time(8)  TYPE c,
    END OF header,
    Internal table to hold detail info  **************
    BEGIN OF i_data OCCURS 0,
        belnr LIKE bsak-belnr,
        gjahr LIKE bsak-gjahr,
        bukrs LIKE bsak-bukrs,
        bldat LIKE bsak-bldat,
        xblnr LIKE bsak-xblnr,
        blart LIKE bsak-blart,
        augdt LIKE bsak-augdt,
        augbl LIKE bsak-augbl,
        wrbtr LIKE bsak-wrbtr,
        shkzg LIKE bsak-shkzg,
        lifnr LIKE bsak-lifnr,
        name1 LIKE lfa1-name1,
        chect LIKE payr-chect,
        status(1) TYPE c,
    END OF i_data,
    Internal table to to collect  *****************
    BEGIN OF i_data1 OCCURS 0,
         belnr LIKE bsak-belnr,
         gjahr LIKE bsak-gjahr,
         bukrs LIKE bsak-bukrs,
         bldat LIKE bsak-bldat,
         xblnr LIKE bsak-xblnr,
         blart LIKE bsak-blart,
         augdt LIKE bsak-augdt,
         augbl LIKE bsak-augbl,
         wrbtr LIKE bsak-wrbtr,
       shkzg LIKE bsak-shkzg,
         lifnr LIKE bsak-lifnr,
         name1 LIKE lfa1-name1,
         sortl LIKE lfa1-sortl,
         chect LIKE payr-chect,
         status(1) TYPE c,
    END OF i_data1,
    String variables for formatting file data *************
        fidoc_year   TYPE string,
        comp_code    TYPE string,
        check_numbr  TYPE string,
        vendor       TYPE string,
        inv_date     TYPE string,
        inv_nbr      TYPE string,
        paid_dat     TYPE string,
        inv_amt      TYPE string,
        status       TYPE string,
        ref_doc      TYPE string,
    ************Internal table to store the file contents **************
    BEGIN OF i_final_file OCCURS 0,
        record(300) TYPE c,
    END OF i_final_file,
    Internal table to store the list of allowed document types ****
      BEGIN OF i_doctype OCCURS 0,
             blart LIKE bsak-blart,
      END OF i_doctype,
    Internal table to hold vendor information ************
      BEGIN OF i_lfa1 OCCURS 0,
         lifnr LIKE lfa1-lifnr,
         name1 LIKE lfa1-name1,
         sortl LIKE lfa1-sortl,
      END OF i_lfa1,
    Internal table to hold check information *************
      BEGIN OF i_payr OCCURS 0,
         chect LIKE payr-chect,
         vblnr LIKE payr-vblnr,
         gjahr LIKE payr-gjahr,
         zbukr LIKE payr-zbukr,
      END OF i_payr.
      Data declarations  **************************
    DATA : ws_stblg     TYPE bkpf-stblg,
           todate       TYPE bsak-augdt,
           fromdate     TYPE bsak-augdt,
           w_day        LIKE dtresr-weekday,
           day          LIKE scal-indicator,
           d            TYPE n,
           e_date       LIKE sy-datum,
           e_time       LIKE sy-uzeit,
           dd(2)        TYPE c,
           mm(2)        TYPE c,
           yy(4)        TYPE c,
           hh(2)        TYPE c,
           min(2)       TYPE c,
           sec(2)       TYPE c.
    DATA : wa_filepath(50)    TYPE c,
           wa_filename(50)    TYPE c,
           wa_c_filename(100) TYPE c,
           arch_path(50)      TYPE c.
    <b>* Data for downloading to list
    DATA : list LIKE TABLE OF abaplist WITH HEADER LINE.
    DATA : BEGIN OF list_asc OCCURS 0,
    msg(300) TYPE c,
    END OF list_asc.
    DATA: BEGIN OF i_invoiceheader OCCURS 0,
    name(30) TYPE c,
    END OF i_invoiceheader.
    RANGES dates FOR bkpf-budat.</b>
      Selection Screen  ************************
    SELECTION-SCREEN SKIP 2.
    SELECT-OPTIONS:
             s_bukrs     FOR  bkpf-bukrs ,
             s_blart     FOR  bkpf-blart ,
             s_augdt     FOR  bsak-augdt. " memory id todat TO fromdat.
    PARAMETERS :submit  AS CHECKBOX DEFAULT ' '  .
    <b>* Download list to file.
    AT USER-COMMAND.
      CASE sy-ucomm.
        WHEN 'LIST'.
          PERFORM download.
        WHEN 'BACK'.
          EXIT.
      ENDCASE.</b>
    <b>----
          FORM download                                                 *
    FORM download.
    if s_augdt is initial.
    dates-sign = 'I'.
    dates-option = 'BT'.
    dates-low = '20050901'.
    dates-high = '20050920'.
    APPEND dates.
    else.
      dates = s_augdt.
      append dates.
    endif.
    /* Submit the same program .
      SUBMIT zexp WITH s_augdt IN dates
       EXPORTING LIST TO MEMORY
       AND RETURN.
      CALL FUNCTION 'LIST_FROM_MEMORY'
           TABLES
                listobject = list
           EXCEPTIONS
                not_found  = 1.
      CALL FUNCTION 'LIST_TO_ASCI'
    EXPORTING
    LIST_INDEX = -1 "LIST_INDEX SY-LSIND.
      TABLES
      listasci = list_asc
      listobject = list.
      PERFORM download_file.
    ENDFORM.
          FORM download_file                                            *
    FORM download_file.
      DATA fname TYPE rlgrap-filename VALUE 'c:\audit_report.xls'.
      DATA ftype TYPE rlgrap-filetype VALUE 'DAT'.
      DATA numeric_data(10) TYPE c VALUE '0123456789'.
    *Table structure should match with list output.
      DATA : BEGIN OF i_data1 OCCURS 0,
           belnr(12) TYPE c,
           gjahr(6) TYPE c,
           bukrs(8) TYPE c,
           chect(13) TYPE c,
           lifnr(12) TYPE c,
           name1(37) TYPE c,
           bldat(14) TYPE c,
           xblnr(18) TYPE c,
           augdt(14) TYPE c,
           wrbtr(17) TYPE c,
           status(4) TYPE c,
           augbl(18) TYPE c,
           sortl(17) TYPE c,
       END OF i_data1.
    Header record of the excel sheet.
      PERFORM fill_header.
      LOOP AT list_asc.
    Reads lines starting from the first record in the report. All informatory statements in the report are not read.
        IF list_asc+1(10) CO numeric_data.
          i_data1 = list_asc .
          APPEND i_data1.
        ENDIF.
      ENDLOOP.
    Call the download function.
    CALL FUNCTION 'DOWNLOAD'
           EXPORTING
                filename = fname
                filetype = ftype
           TABLES
                data_tab = i_data1
                FIELDNAMES = i_invoiceheader.
    ENDFORM.
          FORM fill_header                                              *
    FORM fill_header.
      i_invoiceheader-name = 'Doc Number'.
      APPEND i_invoiceheader.
      i_invoiceheader-name = 'Fsc Year'.
      APPEND i_invoiceheader.
      i_invoiceheader-name = 'Cmp Code'.
      APPEND i_invoiceheader.
      i_invoiceheader-name = 'Check No'.
      APPEND i_invoiceheader.
      i_invoiceheader-name = 'Vendor No'.
      APPEND i_invoiceheader.
      i_invoiceheader-name = 'Entered by'.
      APPEND i_invoiceheader.
      i_invoiceheader-name = 'Doc Date'.
      APPEND i_invoiceheader.
      i_invoiceheader-name = 'Ref Doc No'.
      APPEND i_invoiceheader.
      i_invoiceheader-name = 'Clearing Date'.
      APPEND i_invoiceheader.
      i_invoiceheader-name = 'Amount'.
      APPEND i_invoiceheader.
      i_invoiceheader-name = 'Status'.
      APPEND i_invoiceheader.
      i_invoiceheader-name = 'Clearing Doc No'.
      APPEND i_invoiceheader.
      i_invoiceheader-name = 'Sort field'.
      APPEND i_invoiceheader.
    ENDFORM.                    " fill_header</b>
       Initialization   *************************
    INITIALIZATION.
    To initialize the date parameter on the selection screen.
    The date by default ranges from previous Monday to Sunday.
      todate = sy-datum.
      CALL FUNCTION 'DATE_COMPUTE_DAY'
           EXPORTING
                date = todate
           IMPORTING
                day  = day.
      d = day.
      if d < 4.
        todate = sy-datum - d - 4 .
      else.
        todate = sy-datum - d + 3 .
      endif.
      fromdate = todate - 6.
      MOVE: 'BT'       TO s_augdt-option,
            fromdate   TO s_augdt-low,
            todate     TO s_augdt-high.
      APPEND s_augdt.
    Start of Selection  **************************
    START-OF-SELECTION.
    Checking the validity of the inputted dates ****************
      IF s_augdt-low > sy-datum OR s_augdt-high > sy-datum.
        MESSAGE i999 WITH 'You cannot input future date'.
        EXIT.
      ENDIF.
      IF NOT s_bukrs IS INITIAL.
    MESSAGE i999 WITH 'Program will run with input parameters in screen!!'.
      ENDIF.
    Initialize the header data ***********************
      e_time = sy-uzeit.
      MOVE e_time+0(2) TO hh.
      MOVE e_time+2(2) TO min.
      MOVE e_time+4(2) TO sec.
      CONCATENATE hh min sec INTO header-ext_time SEPARATED BY ':'.
      e_date = sy-datum.
      MOVE e_date+0(4) TO yy.
      MOVE e_date+4(2) TO mm.
      MOVE e_date+6(2) TO dd.
      CONCATENATE mm dd yy INTO header-ext_date SEPARATED BY '/'.
      header-delimit = '~'.
      APPEND header.
    List allowed document types **********************
      PERFORM fill_doc_types.
    **To select the documents within the range of week or as inputted **
      IF s_augdt IS INITIAL.
        MOVE: 'I' TO s_augdt-sign,
              'BT'       TO s_augdt-option,
              fromdate   TO s_augdt-low,
              todate     TO s_augdt-high.
        APPEND s_augdt.
      ENDIF.
    Selecting the records from the database ****************
      IF s_bukrs IS INITIAL AND s_blart IS INITIAL.
      Select all documents of company code 1000, *********
      4200 and 8000, and allowed document types  *********
        SELECT belnr gjahr augdt augbl bukrs
            blart bldat xblnr lifnr wrbtr shkzg
            FROM bsak INTO CORRESPONDING FIELDS OF TABLE i_data
            FOR ALL ENTRIES IN i_doctype
            WHERE blart EQ i_doctype-blart
            AND augdt IN s_augdt
            AND ( bukrs = '1000' OR bukrs ='4200'  OR
                ( bukrs = '8000' AND blart NE 'ZP' ) ).
       loop at i_data.
    Exclude reversed documents
          select single stblg into ws_stblg
                 from   bkpf
                 where  bukrs = i_data-bukrs
                   and  gjahr = i_data-gjahr
                   and  belnr = i_data-belnr.
          if not ws_stblg is initial.
             delete i_data.
          endif.
       endloop.
      ELSEIF s_blart IS INITIAL.
      Select all documents of allowed document types ******
           and inputted company code           ************
        SELECT belnr gjahr augdt augbl bukrs
           blart bldat xblnr lifnr wrbtr shkzg
           FROM bsak INTO CORRESPONDING FIELDS OF TABLE i_data
           FOR ALL ENTRIES IN i_doctype
           WHERE blart EQ i_doctype-blart
             AND augdt IN s_augdt
             AND bukrs IN s_bukrs .
        LOOP AT i_data.
    Exclude documents of type ZP
    for company code 8000.
          IF i_data-bukrs = '8000' AND i_data-blart = 'ZP'.
            DELETE i_data.
            continue.
          ENDIF.
      Exclude reversed documents
          select single stblg into ws_stblg
                 from   bkpf
                 where  bukrs = i_data-bukrs
                   and  gjahr = i_data-gjahr
                   and  belnr = i_data-belnr.
          if not ws_stblg is initial.
             delete i_data.
             continue.
          endif.
        ENDLOOP.
        READ TABLE i_data INDEX 1.
        IF sy-subrc NE 0.
          MESSAGE i999 WITH 'No records have been selected'.
          EXIT.
        ENDIF.
      ELSE.
      Select the documents matching the company codes  *****
    and document types inputted in the selection screen ****
        SELECT belnr gjahr augdt augbl bukrs bldat xblnr
           blart lifnr  wrbtr shkzg
           FROM bsak INTO CORRESPONDING FIELDS OF TABLE i_data
           WHERE bukrs IN s_bukrs AND blart IN s_blart
             AND augdt IN s_augdt.
        SORT i_data BY blart.
        LOOP AT i_data.
      Filtering the records selected
      based on the document type
          READ TABLE i_doctype WITH KEY blart = i_data-blart.
          IF sy-subrc NE 0.
            DELETE i_data.
            continue.
          ENDIF.
      Exclude documents of type ZP
      for company code 8000.
          IF i_data-bukrs = '8000' AND i_data-blart = 'ZP'.
            DELETE i_data.
            continue.
          ENDIF.
      Exclude reversed documents.
          select single stblg into ws_stblg
                 from   bkpf
                 where  bukrs = i_data-bukrs
                   and  gjahr = i_data-gjahr
                   and  belnr = i_data-belnr.
          if not ws_stblg is initial.
             delete i_data.
             continue.
          endif.
        ENDLOOP.
        READ TABLE i_data INDEX 1.
        IF sy-subrc NE 0.
          MESSAGE i999 WITH 'No records have been selected'.
          EXIT.
        ENDIF.
      ENDIF.
      IF sy-subrc NE 0.
        MESSAGE i999 WITH 'No records have been selected'.
        EXIT.
      ENDIF.
    credit/debit identification ***********************
      LOOP AT i_data.
        IF i_data-shkzg EQ 'H'.
          i_data-wrbtr = i_data-wrbtr * 1.
        ELSEIF i_data-shkzg EQ 'S'.
          i_data-wrbtr = i_data-wrbtr * -1.
        ENDIF.
        MODIFY i_data.
      ENDLOOP.
    for summarizing ******************************
      LOOP AT i_data.
        MOVE-CORRESPONDING  i_data TO i_data1.
        COLLECT i_data1.
      ENDLOOP.
    Vendor informations and Check Informations *****************
      SELECT lifnr name1 sortl
             FROM lfa1
             APPENDING CORRESPONDING FIELDS OF TABLE i_lfa1
             FOR ALL ENTRIES IN i_data1
             WHERE lifnr = i_data1-lifnr.
      SELECT chect vblnr gjahr zbukr FROM payr APPENDING CORRESPONDING
                                FIELDS OF TABLE i_payr FOR ALL ENTRIES
                                IN  i_data1   WHERE vblnr = i_data1-augbl
                                AND gjahr = i_data1-augdt(4)
                                AND zbukr = i_data1-bukrs.
      SORT i_data1 BY augbl gjahr bukrs lifnr.
      SORT i_payr  BY vblnr gjahr zbukr.
      SORT i_lfa1  BY lifnr.
      LOOP AT i_data1.
        READ TABLE i_payr WITH KEY vblnr = i_data1-augbl
                                   gjahr = i_data1-gjahr
                                   zbukr = i_data1-bukrs.
        IF sy-subrc EQ 0.
          i_data1-chect = i_payr-chect.
        ENDIF.
        READ TABLE i_lfa1 WITH KEY lifnr = i_data1-lifnr.
        IF sy-subrc EQ 0.
          i_data1-name1 = i_lfa1-name1.
          i_data1-sortl = i_lfa1-sortl.
        ENDIF.
        i_data1-status = 'X'.
        MODIFY i_data1.
      ENDLOOP.
    **The records are sorted by clearing date, check number and doc type**
      SORT i_data1 BY augdt chect blart.
    **********The header record is outputted on the screen****************
      PERFORM write_header.
    ********Data is moved to internal table in the file format *************
      PERFORM move_data.
    Line items are outputted on the screen *********************
      PERFORM write_output.
    *&                   Form  write_header                             &*
    *&        This outputs the header information to screen             &*
    FORM write_header.
      SKIP.
       SET PF-STATUS 'LIST'.
    Outputting the header information *********************
      WRITE : / 'Extraction Date : ' , header-ext_date.
      WRITE : / 'Extraction Time : ' , header-ext_time.
      FORMAT COLOR 1." INTENSIFIED.
      SKIP.
      ULINE AT 0(190) NO-GAP.
    Outputting line level information **********************
      WRITE:/  sy-vline NO-GAP,
            (10) 'DOC NUMBER',
              sy-vline NO-GAP,
             (4) 'F-YR',
               sy-vline NO-GAP,
             (6) 'C-CODE',
              sy-vline NO-GAP,
             (10) 'CHECK NUM',
              sy-vline NO-GAP,
             (10) 'VENDOR NUM',
              sy-vline NO-GAP,
             (35) 'VENDOR NAME',
               sy-vline NO-GAP,
             (12) 'INVOICE DATE',
              sy-vline NO-GAP,
             (16) 'INVOICE NUMBER',
              sy-vline NO-GAP,
             (12) 'PAID DATE',
               sy-vline NO-GAP,
             (15) 'INVOICE AMOUNT',
              sy-vline NO-GAP,
             (2) 'SC',
              sy-vline NO-GAP,
             (16) 'REFERENCE FI DOC',
               sy-vline NO-GAP,
             (15) 'SORT FIELD',
               sy-vline NO-GAP.
      ULINE AT 0(190) NO-GAP.
    ENDFORM.                    " write_header
    *&                      FORM  MOVE_DATA                             &*
    *&    Formats data in internal table as is required in the file     &*
    FORM move_data.
      LOOP AT i_data1.
    Document number and fiscal year should be separted by '|' *****
        CONCATENATE i_data1-belnr i_data1-gjahr INTO fidoc_year
                    SEPARATED BY '|'.
        MOVE i_data1-bukrs TO comp_code.
        MOVE i_data1-chect TO check_numbr.
    Vendor number and vendor name should be separted by '|' *****
        CONCATENATE i_data1-lifnr i_data1-name1 INTO vendor
          SEPARATED BY '|'.
        SHIFT vendor LEFT DELETING LEADING '0'.
        SHIFT vendor RIGHT DELETING TRAILING space.
    Date fields converted to MM/DD/YYYY format ****************
        MOVE i_data1-bldat+0(4) TO yy.
        MOVE i_data1-bldat+4(2) TO mm.
        MOVE i_data1-bldat+6(2) TO dd.
        CONCATENATE mm dd yy INTO inv_date SEPARATED BY '/'.
        MOVE i_data1-xblnr TO inv_nbr.
        SHIFT inv_nbr RIGHT DELETING TRAILING space.
        MOVE i_data1-augdt+0(4) TO yy.
        MOVE i_data1-augdt+4(2) TO mm.
        MOVE i_data1-augdt+6(2) TO dd.
        CONCATENATE mm dd yy INTO paid_dat SEPARATED BY '/'.
        MOVE i_data1-wrbtr TO inv_amt.
        CONDENSE inv_amt.
       SHIFT inv_amt RIGHT DELETING TRAILING space.
        MOVE i_data1-status TO status.
        MOVE i_data1-augbl TO ref_doc.
        CONCATENATE fidoc_year
                    comp_code
                    check_numbr
                    vendor
                    inv_date
                    inv_nbr
                    paid_dat
                    inv_amt
                    status
                    ref_doc
           INTO i_final_file-record SEPARATED BY '~'.
        APPEND i_final_file.
      ENDLOOP.
    ENDFORM.                    " MOVE_DATA
    *&                      Form  write_output                          &*
    *&                  Outputs all data to screen                      &*
    FORM write_output.
      LOOP AT i_data1.
        FORMAT COLOR 2 INTENSIFIED.
    Outputting line level information *******************
        WRITE :  /  sy-vline NO-GAP,
                 (10) i_data1-belnr,
                   sy-vline NO-GAP,
                (4) i_data1-gjahr,
                   sy-vline NO-GAP,
                 (6) i_data1-bukrs,
                   sy-vline NO-GAP,
                (10) i_data1-chect,
                  sy-vline NO-GAP,
                  (10) i_data1-lifnr,
                 sy-vline NO-GAP,
                 (35) i_data1-name1,
                   sy-vline NO-GAP,
                 (12) i_data1-bldat MM/DD/YYYY,
                   sy-vline NO-GAP,
                 (16)  i_data1-xblnr,
                   sy-vline NO-GAP,
                 (12) i_data1-augdt MM/DD/YYYY,
                   sy-vline NO-GAP,
                 (15) i_data1-wrbtr,
                   sy-vline NO-GAP,
                 (2) i_data1-status,
                   sy-vline NO-GAP,
                 (16) i_data1-augbl,
                   sy-vline NO-GAP,
                 (15) i_data1-sortl,
                 sy-vline NO-GAP.
      ENDLOOP.
      ULINE AT 0(190) NO-GAP.
    ENDFORM.                    " write_output
    In the program, I am downloading only the list.. The description of report outputted in the beginning of the report is not downloaded to excel.
    What has to be taken into consideration is that, the structure of the table i_data1 which contains the data to be downloaded to the table.
    I hope that this will help you.
    Regards,
    Susmitha

  • Download the output into Excel...(List- export- spreadsheet)

    Dear friends,
    I want to download the output into Excel...
    I am using all SAP standards and using the ALV Block list
    Ex: List->export->local file.. is anable from here i can download to excell .....but the same there is anothere option : List->export->spreadsheet...( this one inactive.)
    I want to activate the List->export->spreadsheet option.
    how to do this???
    Thanks,
    Sridhar.

    Hi
       Use the Function Module:
    EXCEL_OLE_STANDARD_DAT
    For your purpose.
    But by default you can get the option to download into several formats including your desired one.
    Regards,
    Sreeram

Maybe you are looking for