Download Alv into excel sheet according to variant fields

Hi All,
I have more than 100 fields in the ALV report, now i want to download the report according to the fields are choosen in the variant. I am getting all the fields in excel sheet but i need some fileds that is selected in the variant.
Thanks in advance.
Rudhir

use your own excel button and program this steps:

* Get the frontend fieldcatalog
CALL METHOD go_grid->get_frontend_fieldcatalog
IMPORTING
et_fieldcatalog = lt_fieldcat.
DELETE lt_fieldcat WHERE no_out EQ 'X'.

*create dynamic table with the frontend fieldcatalog
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt_fieldcat
IMPORTING
ep_table = lt_data
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc EQ 0.
ASSIGN lt_data->* TO <lt_table>.
ENDIF.
3° Fill the dynamic table
4° export to excel using
CALL FUNCTION 'XXL_SIMPLE_API'
TABLES
col_text = xmplt_v1
data = <lt_table>
online_text = xmplt_o1
print_text = xmplt_p1
EXCEPTIONS
dim_mismatch_data = 1
file_open_error       =2
file_write_error      = 3
inv_winsys            =4
inv_xxl                   =5
OTHERS                = 6.
Check the complete example here

Similar Messages

  • Formatting problem in download report into EXCEL Sheet

    I have requirement that the Column in the report have values as 1.50,1.5,3.50,when i'm downloading the report into Excel sheet,The values are rounded and appearing as 1.5,1.5,3.5.
    Can anyone please let me know how to resolve this requirement

    hi,
    1) Excel will not take zero's after decimal(1.50) it will roundup(1.5) the values.
    2) you can do like in formula section use CAST(column_name as CHAR) and download it to excel then u will get the zero i think...i didn't tried
    or Column properties--->Data format --> Select Number--->use 1000's Seperator for 1 decimal and save the report and download it
    but it should work!
    thanks,
    saichand.v
    Edited by: saichand on Oct 27, 2009 4:11 PM
    Edited by: saichand on Oct 27, 2009 4:12 PM

  • Download ALV into excel file

    Hi experts,
                   I used subtotals in ALV.first three columns I claculated based on the addition of individual column.In fourth column i calculated the value based on three calculated values ...It is  not problem.
              when i download this into excel file the original value is only coming .the calculated value i.e) calculated based on three values didnt get displayed in excel file..Help me please...
    Thank u,
    Manjula Devi.D

    Hi.
    I find that
    List > Export > Spreadsheet
    gives no subtotals, but
    List > Export > Local File and then Spreadsheet
    does give subtotals.
    I find that
    Views > Microsoft Excel
    followed by
    Save As
    does give subtotals.
    John

  • Download greater than 255 characters from alv into excel sheet

    Hi,
    I have an ALV grid display report where the last field contains close to 600 characters of text.
    When I use the Export -> Local File -> Spreadsheet option and save it in an excel sheet, only first 255 characters are getting downloaded into excelsheet and rest is not gettting downloaded.
    Solution I have is: Keep a button on the screen. If that button is clicked, use GUI_DOWNLOAD FM  and the entire text (all 600 chars) gets downloaded.
    Is there any other solution to the above problem?
    I tried downloading the alv report into XML format and opened as an excel document, but even then only first 255 characters are apearing in excel cell.
    The domain has length 2048 chars for the final internal table in alv, so there is no problem with data element or domain.
    OIn debugging mode, I am able to see all the 600 chars in the final internal table before alv display.
    It looks like there is a constraint in alv that is can display only 255 characters in a cell.
    ALso, I tried converting the grid display to list display and then download into excel , but the result is same.
    Please help.

    please search first:
    http://www.sdn.sap.com/irj/scn/advancedsearch;jsessionid=%28J2EE3417400%29ID0634234250DB10563517489488469157End?query=downloadmorethan255char

  • Download date into excel sheet without changing the properties of column

    Hi All,
    I am trying to download a date field from SAP to Excel sheet. But the date is getting downloaded successfully, but the format of the column is getting changed to DATE. Is there any way to restrict it?
    I am using GUI_DOWNLOAD for downloading the data.
    I have declared the date field as CHAR10  Eg (09/13/2011) and moving the data into excel.
    Result i need : data should be downlaoded as 09/13/2011 but format of the cell should not be changed.
    Regards
    Eswar.

    Hi Eswar,
    Change the date format type dats instead of char format or any standards like erdat from vbak.Then you can in proper format.
    Regards,
    Madhu.

  • Download report into excel sheet

    Hi
    I have  requirement like, in report output I want a button, if I press that button it has to ask where I have to save that output list in excel sheet format.
    Plz help me out
    Thanks in advance
    Regards
    Rao

    Pls do like...
    START-OF-SELECTION.
    * Select and Process the data .
      PERFORM select_and_process_data.
    * Display Records.
      PERFORM display_result.
    * Set the pf-status and user command.
      SET PF-STATUS '110_VAL'.   " create yr button here
    AT USER-COMMAND.
    * Download result to spreadsheet.
      PERFORM download_to_spreadsheet.
    END-OF-SELECTION
    FORM download_to_spreadsheet .
      DATA:
        l_filefilter  TYPE string,
        l_filename    TYPE string,
        l_path        TYPE string,
        l_fullpath    TYPE string,
        l_user_action TYPE i.
      IF sy-ucomm = 'DLOAD'.  " Button name (Function code)
        l_filefilter = 'EXCEL Files (*.XLS)|*.XLS|Text Files (*.TXT)|*.TXT|All files (*.*)|*.*||'.
        CALL FUNCTION 'GUI_FILE_SAVE_DIALOG'
          EXPORTING
            file_filter       = l_filefilter
            default_extension = 'xls'
          IMPORTING
            filename          = l_filename
            path              = l_path
            fullpath          = l_fullpath
            user_action       = l_user_action.
        IF l_user_action = 1 OR l_user_action = 0.
          CALL FUNCTION 'GUI_DOWNLOAD'
            EXPORTING
              filename                = l_fullpath
              filetype                = 'ASC'
            TABLES
              data_tab                = o_file
            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.
        ELSEIF l_user_action = 2.
          CALL FUNCTION 'GUI_DOWNLOAD'
            EXPORTING
              append                  = 'X'
              filename                = l_fullpath
              filetype                = 'ASC'
              trunc_trailing_blanks   = 'X'
            TABLES
              data_tab                = o_file
            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.
        ENDIF.
      ENDIF.
    ENDFORM.                    " download_to_spreadsheet
    " Note : Give the path according yr requirement.
    Regards,
    RH

  • Download Logo into excel sheet

    Hi all,
    Is there any method to import a logo into excel file from execution of a report program?
    Or any possibilities to uplaod a logo into list.
    Suggess.
    Points will be sured.
    Thanks
    Sanket sethi

    Hi Sanket
    Try the below code.
    Pls reward pts if help.
    Regards
    Deepanker.
    REPORT YMS_EXCISE MESSAGE-ID E4 NO STANDARD PAGE HEADING LINE-SIZE 350. .
    TABLES : J_1IEXCHDR, " header table
    J_1IEXCDTL, " item table
    J_1IPART2, " Excise Part II details
    LFA1, " vendor master table
    J_1IMOVEND, " vendor excise details table
    MSEG, " Document Segment: Material
    MKPF, " Header: Material Document
    DD07T, " domain text table
    T001W. " Plant and Branch Details
    DATA : BEGIN OF IT_CHDR OCCURS 100,
    DOCNO LIKE J_1IEXCHDR-DOCNO,
    DOCYR LIKE J_1IEXCHDR-DOCYR,
    EXNUM LIKE J_1IEXCHDR-EXNUM,
    EXDAT LIKE J_1IEXCHDR-EXDAT,
    WERKS LIKE J_1IEXCHDR-WERKS,
    EXBED LIKE J_1IEXCHDR-EXBED,
    EXCCD LIKE J_1IEXCHDR-EXCCD,
    ECS LIKE J_1IEXCHDR-ECS,
    END OF IT_CHDR.
    DATA : BEGIN OF IT_CDTL OCCURS 100,
    DOCYR LIKE J_1IEXCDTL-DOCYR,
    DOCNO LIKE J_1IEXCDTL-DOCNO,
    EXNUM LIKE J_1IEXCDTL-EXNUM,
    EXDAT LIKE J_1IEXCDTL-EXDAT,
    LIFNR LIKE J_1IEXCDTL-LIFNR,
    MATNR LIKE J_1IEXCDTL-MATNR,
    MAKTX LIKE J_1IEXCDTL-MAKTX,
    CHAPID LIKE J_1IEXCDTL-CHAPID,
    EXBAS LIKE J_1IEXCDTL-EXBAS,
    EXBED LIKE J_1IEXCDTL-EXBED,
    ECS LIKE J_1IEXCDTL-ECS,
    MENGE LIKE J_1IEXCDTL-MENGE,
    MEINS LIKE J_1IEXCDTL-MEINS,
    RDOC2 LIKE J_1IEXCDTL-RDOC2,
    END OF IT_CDTL.
    DATA TEXT(10).
    DATA : BEGIN OF IT_OUT OCCURS 0,
    SERIALNO LIKE J_1IPART2-SERIALNO,
    TEXT1 LIKE TEXT,
    EXNUM LIKE J_1IEXCDTL-EXNUM,
    EXDAT LIKE J_1IEXCDTL-EXDAT,
    NAME LIKE LFA1-NAME1,
    DDTEXT LIKE DD07T-DDTEXT,
    EXCCD LIKE J_1IEXCHDR-EXCCD,
    BUDAT LIKE MKPF-BUDAT,
    EXBAS LIKE IT_CDTL-EXBAS,
    EXBED LIKE IT_CDTL-EXBED,
    ECS LIKE IT_CDTL-ECS,
    MATNR LIKE IT_CDTL-MATNR,
    MAKTX LIKE IT_CDTL-MAKTX,
    CHAPID LIKE IT_CDTL-CHAPID,
    MENGE LIKE IT_CDTL-MENGE,
    MEINS LIKE IT_CDTL-MEINS,
    DEL_IND(1),
    END OF IT_OUT.
    DATA IT_PART2 LIKE J_1IPART2 OCCURS 0 WITH HEADER LINE.
    DATA S_NO(4) .
    DATA DB_CNT LIKE SY-TABIX.
    DATA EBELN_T LIKE MSEG-EBELN .
    TYPE-POOLS : SLIS.
    DATA : AFIELD TYPE SLIS_FIELDCAT_ALV.
    DATA : LIST_HEADER TYPE SLIS_T_LISTHEADER,
    FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
    LS_FTCAT TYPE LVC_S_FCAT,
    SORTCAT TYPE SLIS_T_SORTINFO_ALV,
    SORTCAT_LN LIKE LINE OF SORTCAT,
    G_REPID LIKE SY-REPID,
    G_BACK_GROUND(70), "like bapibds01-objkey,
    GS_VARIANT LIKE DISVARIANT,
    G_SAVE ,
    GT_EVENTS TYPE SLIS_T_EVENT,
    ALV_EVENT TYPE SLIS_ALV_EVENT,
    EVENTCAT TYPE SLIS_T_EVENT,
    EVENTCAT_LN LIKE LINE OF EVENTCAT,
    LAYOUT_IN TYPE SLIS_LAYOUT_ALV,
    LAYOUT_IN1 TYPE SLIS_LAYOUT_ALV.
    CONSTANTS : GC_FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE
    'TOP_OF_PAGE',
    GC_FORMNAME_USER_COMMAND TYPE SLIS_FORMNAME VALUE
    'USER_COMMAND',
    GC_FORMNAME_BEFORE_OUTPUT TYPE SLIS_FORMNAME VALUE
    'BEFORE_OUTPUT'.
    ALV_EVENT TYPE SLIS_ALV_EVENT,
    DATA EX_NO LIKE IT_CHDR-EXNUM VALUE 0.
    DATA REGTYP_1 LIKE J_1IPART2-REGTYP.
    SELECTION-SCREEN BEGIN OF BLOCK B WITH FRAME.
    PARAMETERS WERKS TYPE J_1IEXCHDR-WERKS.
    SELECT-OPTIONS : BUDAT FOR J_1IEXCHDR-EXDAT.
    PARAMETERS : R1 RADIOBUTTON GROUP GRP DEFAULT 'X',
    R2 RADIOBUTTON GROUP GRP.
    SELECTION-SCREEN END OF BLOCK B.
    INITIALIZATION.
    G_REPID = SY-REPID.
    G_SAVE = 'A'.
    PERFORM BUILD_EVENT USING GT_EVENTS[].
    PERFORM ALV_EVENT_INIT.
    AT SELECTION-SCREEN.
    REFRESH LIST_HEADER.
    PERFORM TOP_OF_PAGE_LIST_HEADER USING LIST_HEADER.
    START-OF-SELECTION.
    PERFORM ALV_EVENT_INIT.
    G_REPID = SY-REPID.
    G_BACK_GROUND = ' ' .
    IF R1 = 'X'.
    CLEAR R2. CLEAR : REGTYP_1.
    REGTYP_1 = 'A'.
    set titlebar 'BALAJI' with DB_CNT.
    ELSEIF R2 = 'X'.
    CLEAR R1.CLEAR : REGTYP_1.
    REGTYP_1 = 'C'.
    set titlebar 'BALAJI1' with DB_CNT.
    ENDIF.
    SELECT * FROM J_1IPART2
    INTO CORRESPONDING FIELDS OF TABLE IT_PART2
    WHERE REGTYP = REGTYP_1 AND
    TRNTYP = 'GRPO' AND
    BUDAT IN BUDAT.
    DOCYR = IT_CDTL-DOCYR AND
    DOCNO = IT_CDTL-DOCNO.
    LOOP AT IT_PART2.
    SELECT SINGLE * FROM J_1IEXCHDR
    INTO CORRESPONDING FIELDS OF IT_CHDR
    WHERE TRNTYP = 'GRPO' AND
    DOCYR = IT_PART2-DOCYR AND
    DOCNO = IT_PART2-DOCNO AND
    WERKS = WERKS AND
    exdat IN BUDAT.
    ORDER BY EXDAT.
    IF SY-SUBRC = 0.
    APPEND IT_CHDR.
    ELSE.
    CONTINUE.
    ENDIF.
    IF SY-SUBRC <> 0.
    MESSAGE E084.
    ENDIF.
    ENDLOOP.
    LOOP AT IT_CHDR.
    SELECT * FROM J_1IEXCDTL
    INTO CORRESPONDING FIELDS OF IT_CDTL
    FOR ALL ENTRIES IN IT_CHDR
    WHERE
    TRNTYP = 'GRPO' AND
    DOCNO = IT_CHDR-DOCNO AND
    DOCYR = IT_CHDR-DOCYR AND
    EXNUM = IT_CHDR-EXNUM AND
    EXDAT = IT_CHDR-EXDAT AND
    WERKS = IT_CHDR-WERKS.
    IF SY-SUBRC = 0.
    APPEND IT_CDTL.
    ELSE.
    CONTINUE.
    ENDIF.
    ENDSELECT.
    ENDLOOP.
    LOOP AT IT_CDTL.
    CLEAR TEXT.
    DB_CNT = DB_CNT + 1.
    READ TABLE IT_CHDR WITH KEY EXNUM = IT_CDTL-EXNUM.
    READ TABLE IT_PART2 WITH KEY DOCNO = IT_CDTL-DOCNO .
    IT_OUT-SERIALNO = IT_PART2-SERIALNO.
    SELECT SINGLE NAME1 FROM LFA1
    INTO IT_OUT-NAME
    WHERE LIFNR = IT_CDTL-LIFNR.
    SELECT SINGLE * FROM LFA1
    WHERE LIFNR = IT_CDTL-LIFNR.
    IF LFA1-LAND1 EQ 'IN'.
    TEXT = 'INVOICE'.
    IT_OUT-TEXT1 = TEXT.
    ELSE.
    TEXT = 'BOE'.
    IT_OUT-TEXT1 = TEXT.
    ENDIF.
    SELECT SINGLE * FROM J_1IMOVEND
    WHERE LIFNR = IT_CDTL-LIFNR.
    SELECT SINGLE * FROM DD07T
    INTO IT_OUT-DDTEXT
    WHERE DOMNAME = 'J_1IVTYP' AND
    DDLANGUAGE = 'EN' AND
    DOMVALUE_L = J_1IMOVEND-J_1IVTYP.
    IF DD07T-DDTEXT = 'First Stage Dealer of indigenous excisable goods'
    OR
    DD07T-DDTEXT = 'Second Stage Dealer of indigenous excisablegoods'.
    DD07T-DDTEXT = 'Dealer'.
    ENDIF.
    IT_OUT-DDTEXT = DD07T-DDTEXT.
    ELSEIF DD07T-DDTEXT = 'Second Stage Dealer of indigenous excisable
    *goods'.
    DD07T-DDTEXT =
    CLEAR EBELN_T.
    SELECT SINGLE LFBNR FROM MSEG
    INTO EBELN_T
    WHERE MBLNR = IT_CDTL-RDOC2 .
    SELECT SINGLE * FROM MSEG
    WHERE BWART = '106' AND
    LFBNR = EBELN_T ."and
    ebeln = ebeln_t.
    IF SY-SUBRC = 0.
    IT_OUT-DEL_IND = 'X'.
    ELSE.
    IT_OUT-DEL_IND = ' '.
    ENDIF.
    SELECT SINGLE BUDAT FROM MKPF
    INTO IT_OUT-BUDAT
    WHERE MBLNR = EBELN_T ."MSEG-LFBNR.
    IT_OUT-EXNUM = IT_CDTL-EXNUM.
    IT_OUT-EXDAT = IT_CDTL-EXDAT.
    IT_OUT-EXCCD = IT_CHDR-EXCCD.
    IT_OUT-EXBAS = IT_CDTL-EXBAS.
    IT_OUT-EXBED = IT_CDTL-EXBED.
    IT_OUT-ECS = IT_CDTL-ECS.
    IT_OUT-MATNR = IT_CDTL-MATNR.
    IT_OUT-MAKTX = IT_CDTL-MAKTX.
    IT_OUT-CHAPID = IT_CDTL-CHAPID.
    IT_OUT-MENGE = IT_CDTL-MENGE.
    IT_OUT-MEINS = IT_CDTL-MEINS.
    APPEND IT_OUT.
    EX_NO = IT_CDTL-EXNUM.
    ENDLOOP.
    Title Portion
    IF REGTYP_1 = 'A'.
    SET TITLEBAR 'BALAJI' WITH DB_CNT.
    ELSEIF REGTYP_1 = 'C'.
    SET TITLEBAR 'BALAJI1' WITH DB_CNT.
    ENDIF.
    AFIELD-COL_POS = 1.
    AFIELD-FIELDNAME = 'SERIALNO'.
    AFIELD-SELTEXT_L = 'INPUTS'.
    AFIELD-JUST = 'L'.
    APPEND AFIELD TO FIELDCAT.
    AFIELD-COL_POS = 2.
    AFIELD-FIELDNAME = 'TEXT1'.
    AFIELD-SELTEXT_L = 'TYPE OF DOC'.
    AFIELD-JUST = 'L'.
    AFIELD-DECIMALS_OUT = '0'.
    AFIELD-NO_ZERO = 'X'.
    APPEND AFIELD TO FIELDCAT.
    AFIELD-COL_POS = 3.
    AFIELD-FIELDNAME = 'EXNUM'.
    AFIELD-SELTEXT_L = 'DOC.NO'.
    AFIELD-JUST = 'L'.
    APPEND AFIELD TO FIELDCAT.
    AFIELD-COL_POS = 4.
    AFIELD-FIELDNAME = 'EXDAT'.
    AFIELD-SELTEXT_L = 'DOC.DATE'.
    AFIELD-JUST = 'C'.
    APPEND AFIELD TO FIELDCAT.
    AFIELD-COL_POS = 5.
    AFIELD-FIELDNAME = 'NAME'.
    AFIELD-SELTEXT_L = 'NAME OF THE SUPPLIER'.
    AFIELD-NO_ZERO = 'X'.
    AFIELD-JUST = 'L'.
    APPEND AFIELD TO FIELDCAT.
    AFIELD-COL_POS = 6.
    AFIELD-FIELDNAME = 'DDTEXT'.
    AFIELD-SELTEXT_L = 'TYPE-OF-SUPPLIER'.
    AFIELD-JUST = 'L'.
    APPEND AFIELD TO FIELDCAT.
    AFIELD-COL_POS = 7.
    AFIELD-FIELDNAME = 'EXCCD'.
    AFIELD-SELTEXT_L = 'ECC OF THE SUPPLIER'.
    AFIELD-NO_ZERO = 'X'.
    AFIELD-JUST = 'L'.
    APPEND AFIELD TO FIELDCAT.
    AFIELD-COL_POS = 8.
    AFIELD-FIELDNAME = 'BUDAT'.
    AFIELD-SELTEXT_L = 'INPUT RECV DATE'.
    AFIELD-JUST = 'C'.
    APPEND AFIELD TO FIELDCAT.
    AFIELD-COL_POS = 9.
    AFIELD-FIELDNAME = 'EXBAS'.
    AFIELD-SELTEXT_L = 'ASSESSABLE-VALUE'.
    AFIELD-DO_SUM = 'X'.
    AFIELD-JUST = 'R'.
    AFIELD-DECIMALS_OUT = '2'.
    APPEND AFIELD TO FIELDCAT.
    AFIELD-COL_POS = 10.
    AFIELD-FIELDNAME = 'EXBED'.
    AFIELD-SELTEXT_L = 'DET OF CREDIT TAKEN CENVAT'.
    AFIELD-JUST = 'R'.
    APPEND AFIELD TO FIELDCAT.
    AFIELD-COL_POS = 11.
    AFIELD-FIELDNAME = 'ECS'.
    AFIELD-SELTEXT_L = 'DET OF CREDIT TAKEN E-CESS'.
    AFIELD-JUST = 'R'.
    APPEND AFIELD TO FIELDCAT.
    AFIELD-COL_POS = 12.
    AFIELD-FIELDNAME = 'MATNR'.
    AFIELD-SELTEXT_L = 'MATERIAL-CODE'.
    AFIELD-JUST = 'L'.
    APPEND AFIELD TO FIELDCAT.
    AFIELD-COL_POS = 13.
    AFIELD-FIELDNAME = 'MAKTX'.
    AFIELD-SELTEXT_L = 'DESCRIPTION'.
    AFIELD-JUST = 'L'.
    APPEND AFIELD TO FIELDCAT.
    AFIELD-COL_POS = 14.
    AFIELD-FIELDNAME = 'CHAPID'.
    AFIELD-SELTEXT_L = 'TARIFF-ID'.
    AFIELD-JUST = 'L'.
    APPEND AFIELD TO FIELDCAT.
    AFIELD-COL_POS = 15.
    AFIELD-FIELDNAME = 'MENGE'.
    AFIELD-SELTEXT_L = 'QUANTITY'.
    AFIELD-JUST = 'R'.
    AFIELD-DO_SUM = ' '.
    APPEND AFIELD TO FIELDCAT.
    AFIELD-COL_POS = 16.
    AFIELD-FIELDNAME = 'MEINS'.
    AFIELD-SELTEXT_L = 'UOM'.
    AFIELD-JUST = 'C'.
    APPEND AFIELD TO FIELDCAT.
    AFIELD-COL_POS = 17.
    AFIELD-FIELDNAME = 'DEL_IND'.
    AFIELD-SELTEXT_L = 'Deleted'.
    AFIELD-JUST = 'C'.
    APPEND AFIELD TO FIELDCAT.
    * LAYOUT FOR ZEBRA CATLOG
    LAYOUT_IN-COLWIDTH_OPTIMIZE = 'X'.
    LAYOUT_IN-ZEBRA = 'X'.
    LAYOUT_IN-GET_SELINFOS = 'X'.
    LAYOUT_IN-CONFIRMATION_PROMPT = 'X'.
    LAYOUT_IN-DETAIL_POPUP = 'X' .
    SORTCAT-decimals = '0'.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    I_CALLBACK_PROGRAM = G_REPID
    I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
    I_SAVE = G_SAVE
    IS_VARIANT = GS_VARIANT
    IT_FIELDCAT = FIELDCAT
    IT_SORT = SORTCAT
    IS_LAYOUT = LAYOUT_IN
    IT_EVENTS = EVENTCAT
    I_BACKGROUND_ID = g_back_ground
    TABLES
    T_OUTTAB = IT_OUT.
    *& Form TOP_OF_PAGE_LIST_HEADER
    text
    -->LIST_HEADERtext
    FORM TOP_OF_PAGE_LIST_HEADER USING LIST_HEADER TYPE SLIS_T_LISTHEADER.
    DATA : HLINE TYPE SLIS_LISTHEADER,
    TEXT(60) TYPE C.
    CLEAR : HLINE,TEXT.
    HLINE-TYP = 'H'.
    WRITE 'ROOTS INDUSTRIES LTD' TO TEXT.
    HLINE-INFO = TEXT.
    APPEND HLINE TO LIST_HEADER.
    SELECT SINGLE * FROM T001W WHERE WERKS = WERKS.
    CLEAR : HLINE,TEXT.
    HLINE-TYP = 'H'.
    WRITE 'PLANT :' TO TEXT.
    WRITE WERKS TO TEXT+8.
    HLINE-INFO = TEXT.
    APPEND HLINE TO LIST_HEADER.
    CLEAR : HLINE,TEXT.
    HLINE-TYP = 'H'.
    WRITE T001W-NAME1 TO TEXT.
    HLINE-INFO = TEXT.
    APPEND HLINE TO LIST_HEADER.
    CLEAR : HLINE,TEXT.
    HLINE-TYP = 'H'.
    WRITE T001W-STRAS TO TEXT.
    HLINE-INFO = TEXT.
    APPEND HLINE TO LIST_HEADER.
    CLEAR : HLINE,TEXT.
    HLINE-TYP = 'H'.
    WRITE T001W-ORT01 TO TEXT.
    HLINE-INFO = TEXT.
    APPEND HLINE TO LIST_HEADER.
    CLEAR : HLINE,TEXT.
    HLINE-TYP = 'H'.
    WRITE 'DATE :' TO TEXT.
    WRITE BUDAT-LOW TO TEXT+7.
    IF BUDAT-HIGH NE ''.
    WRITE 'TO' TO TEXT+18.
    WRITE BUDAT-HIGH TO TEXT+22.
    ENDIF.
    HLINE-INFO = TEXT.
    APPEND HLINE TO LIST_HEADER.
    ENDFORM. "TOP_OF_PAGE_LIST_HEADER
    *& Form ALV_EVENT_INIT
    text
    FORM ALV_EVENT_INIT .
    CLEAR ALV_EVENT.
    ALV_EVENT-NAME = SLIS_EV_TOP_OF_PAGE.
    ALV_EVENT-FORM = 'ALV_TOP_OF_PAGE'.
    APPEND ALV_EVENT TO EVENTCAT.
    CLEAR ALV_EVENT.
    ALV_EVENT-NAME = SLIS_EV_TOP_OF_LIST.
    ALV_EVENT-FORM = 'ALV_TOP_OF_LIST'.
    APPEND ALV_EVENT TO EVENTCAT.
    CLEAR ALV_EVENT.
    ALV_EVENT-NAME = SLIS_EV_END_OF_LIST.
    ALV_EVENT-FORM = 'ALV_END_OF_LIST'.
    APPEND ALV_EVENT TO GT_EVENTS.
    CLEAR ALV_EVENT.
    ALV_EVENT-NAME = SLIS_EV_END_OF_PAGE.
    ALV_EVENT-FORM = 'ALV_END_OF_PAGE'.
    APPEND ALV_EVENT TO GT_EVENTS.
    ENDFORM. "ALV_EVENT_INIT
    *& Form ALV_TOP_OF_PAGE
    text
    FORM ALV_TOP_OF_PAGE.
    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
    IT_LIST_COMMENTARY = LIST_HEADER
    I_LOGO = 'ENJOYSAP_LOGO'.
    ENDFORM. "ALV_TOP_OF_PAGE
    *& Form BUILD_EVENT
    text
    -->P_GT_EVENTS[] text
    FORM BUILD_EVENT USING P_EVENTS TYPE SLIS_T_EVENT.
    CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
    I_LIST_TYPE = 0
    IMPORTING
    ET_EVENTS = P_EVENTS
    EXCEPTIONS
    LIST_TYPE_WRONG = 1
    OTHERS = 2.
    READ TABLE P_EVENTS WITH KEY NAME = SLIS_EV_USER_COMMAND INTO
    ALV_EVENT.
    IF SY-SUBRC = 0.
    MOVE GC_FORMNAME_USER_COMMAND TO ALV_EVENT-FORM.
    APPEND ALV_EVENT TO P_EVENTS.
    ENDIF.
    READ TABLE P_EVENTS WITH KEY NAME = SLIS_EV_BEFORE_LINE_OUTPUT INTO
    ALV_EVENT.
    IF SY-SUBRC = 0.
    MOVE GC_FORMNAME_BEFORE_OUTPUT TO ALV_EVENT-FORM.
    APPEND ALV_EVENT TO P_EVENTS.
    ENDIF.
    ENDFORM. " BUILD_EVENT
    Reward pts if help.

  • Short dump when trying to download alv into excel

    Hi SAPAll.
    here i have got one alv report ,when executing this alv report it displays in correct way but the only problem is when i click on the icon(local file) which exists at standard tool bar at the top to dowbload into local excel file it is raising the runtime error as
      The current statement requires a character-type data object.
    at happened?
      Error in the ABAP Application Program
      The current ABAP program "SAPLKKBL" had to be terminated because it has
      come across a statement that unfortunately cannot be executed.
    ror analysis
      At the statment
           "STRLEN( obj )..."
      , only character-type data objects are supported at the argument
      position "obj".
      In this particular case, the operand "obj" has the non-charcter-type type
      "P".
    igger Location of Runtime Error
      Program                                 SAPLKKBL
      Include                                 LKKBLF99
      Row                                     3.948
      Module type                             (FORM)
      Module Name                             GEN_FIELD_OUT2
    Line  SourceCde
    3923 * Bei NUMC führende '0' und ' ' nicht berücksichtigen
    3924   elseif gs_fc-tech_form = 6.
    3925     write  to gs_out-hlpchar no-zero left-justified.
    3926     if gs_fc-just = 'R'.
    3927       condense gs_out-hlpchar.
    3928     endif.
    3929     gs_out-hlplen = strlen( gs_out-hlpchar ).
    3930   elseif gs_fc-tech_form = 11.                              "INS TECH11
    3931 *   Min. Ausgabelänge für ein Datum ist immer 8
    3932     if gs_fc-datatype = 'DATS'.                             "INS TECH11
    3933       gs_out-hlplen = 8.                                    "INS TECH11
    3934 *    Min. Ausgabelänge für eine Uhrzeit ist immer 6
    3935     elseif gs_fc-datatype = 'TIMS'.                         "INS TECH11
    3936       gs_out-hlplen = 6.                                    "INS TECH11
    3937     endif.                                                  "INS TECH11
    3938   elseif gs_fc-tech_form = 1 or gs_fc-tech_form = 90.
    3939 *   Überführung int. in ext. Format via Konvertierungsexit
    3940     if not gs_fc-convexit is initial or                     "INS TECH11
    3941        not gs_fc-inttype ca 'CN'.
    3942 *   elseif not gs_fc-convexit is initial.            "DEL TECH11
    will be waiting for quick response please respond at your discretion.
    regards.
    Varma
    Edited by: Thomas Zloch on Mar 11, 2010 11:48 AM

    hi suhas .
    the folliwing below is the code for alv and i had used 2 different structures for populating the data into alv
    FORM fieldcat_init  USING    p_fieldcat TYPE slis_t_fieldcat_alv.
      DATA: ls_fieldcat TYPE slis_fieldcat_alv.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname   = 'ORDER'.
      ls_fieldcat-ref_tabname = 'st_proc_out'.
      ls_fieldcat-key         = 'X'.
      ls_fieldcat-seltext_s   = 'ORDER NUMBER'.
      ls_fieldcat-seltext_m   = 'ORDER NUMBER'.
      ls_fieldcat-seltext_l   = 'ORDER NUMBER'.
      APPEND ls_fieldcat TO p_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname   = 'P_ORDER'.
      ls_fieldcat-ref_tabname = 'st_proc_out'.
      ls_fieldcat-key         = 'X'.
      ls_fieldcat-seltext_s   = 'P.O.NUMBER'.
      ls_fieldcat-seltext_m   = 'P.O.NUMBER'.
      ls_fieldcat-seltext_l   = 'P.O.NUMBER'.
      APPEND ls_fieldcat TO p_fieldcat.
    CLEAR ls_fieldcat.
      ls_fieldcat-fieldname   ='LINE'.
      ls_fieldcat-ref_tabname = 'st_proc_out2'.
      ls_fieldcat-key         = 'X'.
      ls_fieldcat-seltext_s   = 'Line Number'.
      ls_fieldcat-seltext_m   = 'Line Number'.
      ls_fieldcat-seltext_l   = 'Line Number'.
      APPEND ls_fieldcat TO p_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname   ='MATNO'.
      ls_fieldcat-ref_tabname = 'st_proc_out2'.
      ls_fieldcat-key         = 'X'.
      ls_fieldcat-seltext_s   = 'Mat.Number'.
      ls_fieldcat-seltext_m   = 'Mat.Number'.
      ls_fieldcat-seltext_l   = 'Mat.Number'.
      APPEND ls_fieldcat TO p_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname   ='MATERIAL'.
      ls_fieldcat-ref_tabname = 'st_proc_out2'.
      ls_fieldcat-key         = 'X'.
      ls_fieldcat-seltext_s   = 'Mat Descrption'.
      ls_fieldcat-seltext_m   = 'Mat Descrption'.
      ls_fieldcat-seltext_l   = 'Mat Descrption'.
      APPEND ls_fieldcat TO p_fieldcat .
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program = 'YSDRO024C1'
          i_grid_title       = 'EXPORT ORDER REPORT'
          is_layout          = alv_layout
          it_fieldcat        = alv_fieldcat
          i_save             = 'A'
        TABLES
          t_outtab           = i_output
        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.
      PERFORM  proc_print.
    FORM proc_print .
      DATA: ls_fieldcat TYPE slis_fieldcat_alv.
      CLEAR ls_fieldcat.
      ls_fieldcat-col_pos     = '1'.
      ls_fieldcat-fieldname   = 'ORDER'.
      ls_fieldcat-key         = 'X'.
      ls_fieldcat-seltext_m   = 'ORDER NUMBER'.
      ls_fieldcat-ddictxt     = 'M'.
      APPEND ls_fieldcat TO alv_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-col_pos     = '2'.
      ls_fieldcat-fieldname   = 'P_ORDER'.
      ls_fieldcat-key         = 'X'.
      ls_fieldcat-seltext_m   = 'PO NUMBER'.
      ls_fieldcat-ddictxt     = 'M'.
      APPEND ls_fieldcat TO alv_fieldcat.
    regards,
    Varma

  • How to export alv into excel sheet without using toolbar button

    hi,
    i have developed ALV using FM methord on that i have created one button when user will click on that button
    hole ALV should export in to excel as it is and that ALV is Heaving top of page contain also i want that shuld
    also copy please help me for that please send me the sample code for that
    Edited by: ankita khare on Nov 3, 2008 9:42 AM

    Check this:
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
          filename                = 'C:/test.xls'
          filetype                = 'ASC'
          write_field_separator   = 'X'
        TABLES
          data_tab                = t_output
    Regards.

  • Download the ALV Report output into excel sheet or notepad

    Hi,
    how to downlaod the alv report out into excel sheet or notepad in a proper manner. program contain large number records....
    Thanks in advance!!!!
    Regards,
    kranthi.

    Hi
    Download a report to excel with format (border, color cell, etc) 
    Try this program...it may help you to change the font ..etc.
    Code:
    REPORT ZSIRI NO STANDARD PAGE HEADING.
    this report demonstrates how to send some ABAP data to an
    EXCEL sheet using OLE automation.
    INCLUDE OLE2INCL.
    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
    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 UP TO 10 ROWS.
    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 'Flug'(001).
      PERFORM FILL_CELL USING 1 2 0 'Nr'(002).
      PERFORM FILL_CELL USING 1 3 1 'Von'(003).
      PERFORM FILL_CELL USING 1 4 1 'Nach'(004).
      PERFORM FILL_CELL USING 1 5 1 'Zeit'(005).
      LOOP AT IT_SPFLI.
    copy flights to active EXCEL sheet
        H = SY-TABIX + 1.
        PERFORM FILL_CELL USING H 1 0 IT_SPFLI-CARRID.
        PERFORM FILL_CELL USING H 2 0 IT_SPFLI-CONNID.
        PERFORM FILL_CELL USING H 3 0 IT_SPFLI-CITYFROM.
        PERFORM FILL_CELL USING H 4 0 IT_SPFLI-CITYTO.
        PERFORM FILL_CELL USING H 5 0 IT_SPFLI-DEPTIME.
      ENDLOOP.
    changes by Kishore  - start
    CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.
      CALL METHOD OF H_EXCEL 'Worksheets' = H_MAPL." EXPORTING #1 = 2.
      PERFORM ERR_HDL.
    add a new workbook
      CALL METHOD OF H_MAPL 'Add' = H_MAP  EXPORTING #1 = 2.
      PERFORM ERR_HDL.
    tell user what is going on
      SET PROPERTY OF H_MAP 'NAME' = 'COPY'.
      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 'Flug'(001).
      PERFORM FILL_CELL USING 1 2 0 'Nr'(002).
      PERFORM FILL_CELL USING 1 3 1 'Von'(003).
      PERFORM FILL_CELL USING 1 4 1 'Nach'(004).
      PERFORM FILL_CELL USING 1 5 1 'Zeit'(005).
      LOOP AT IT_SPFLI.
    copy flights to active EXCEL sheet
        H = SY-TABIX + 1.
        PERFORM FILL_CELL USING H 1 0 IT_SPFLI-CARRID.
        PERFORM FILL_CELL USING H 2 0 IT_SPFLI-CONNID.
        PERFORM FILL_CELL USING H 3 0 IT_SPFLI-CITYFROM.
        PERFORM FILL_CELL USING H 4 0 IT_SPFLI-CITYTO.
        PERFORM FILL_CELL USING H 5 0 IT_SPFLI-DEPTIME.
      ENDLOOP.
    changes by Kishore  - end
    disconnect from Excel
         CALL METHOD OF H_EXCEL 'FILESAVEAS' EXPORTING  #1 = 'C:\SKV.XLS'.
      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 VAL.
      CALL METHOD OF H_EXCEL 'Cells' = H_ZL EXPORTING #1 = I #2 = J.
      PERFORM ERR_HDL.
      SET PROPERTY OF H_ZL 'Value' = VAL .
      PERFORM ERR_HDL.
      GET PROPERTY OF H_ZL 'Font' = H_F.
      PERFORM ERR_HDL.
      SET PROPERTY OF H_F 'Bold' = BOLD .
      PERFORM ERR_HDL.
    ENDFORM.
    *&      Form  ERR_HDL
          outputs OLE error if any                                       *
    -->  p1        text
    <--  p2        text
    FORM ERR_HDL.
    IF SY-SUBRC <> 0.
      WRITE: / 'Fehler bei OLE-Automation:'(010), SY-SUBRC.
      STOP.
    ENDIF.
    ENDFORM.                    " ERR_HDL
    Please note that this example maybe slow at filling the excel table
    (perhaps four fields per second on a 900 MHz machine - almost 30 seconds
    for a short example).
    To get the data on properties and methods - there is a bit of smoke and mirrors
    going on here; they are EXCEL properties and methods, not sap ones - so you need
    to look at excel help to determine how a particular function is structured. then
    build the block in sap, as shown in the example.
    If you only want to transfer the data to Excel like when you transfer the data from
    ALV to Excel simply use the Function Modules:
    XXL_SIMPLE_API
    If you want more modifications when you transfer it to Excel use:
    XXL_FULL_API

  • Reg: Download alv grid data with top of page into excel sheet

    Hi All,
    I have a selection screen with radio button for download .
    If that radio button was selected then the data will download into excel sheet (like if we execute normal ALV grid display from there we can download top-of-page and body as it is).
    AOO : 2009P               
    Fiscal year : 2009               
    Posting period : 00               
    Local Currency : USD               
    CO Area Currency :               
    Accounting standard:               
    Sector : 23               
    BB code     Period Value LC     Periodic Quantity
    AHDKGKAJ   200                         0

    Did not get your question

  • Download from ALV to excel sheet.

    When i am downloading the Alv to excel sheet. I want to get the field descritption also in the excel sheet.

    Refer:
    https://forums.sdn.sap.com/click.jspa?searchID=14433981&messageID=3603627

  • 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

  • How to  send ALV output data into Excel sheet format via Mail to the user?

    Hi friends,
    I have a doubt ie,
    How to  send ALV output data into Excel sheet format via Mail to the user?
    regards
    Moosa

    Hi,
    Provide the output internal table to the objbin in the below FM
    Send Message
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
           EXPORTING
                document_data              = i_docdata
                put_in_outbox              = c_x
           TABLES
                packing_list               = i_objpack
                object_header              = i_objhead
                contents_bin               = i_objbin
                contents_txt               = i_objtxt
                receivers                  = i_reclist
    and specify the document type
      i_objpack-doc_type   = 'XLS'.
    and try.
    Regards,
    Nandha

  • Download Sales Contract data into Excel sheet

    Hi,
    I need to download the Sales Contract Data into excel sheet is there a Function module that i can use?? Else how do i go about it. Kindly help.
    Thanks,
    Riya.

    use the function module FUNCTION 'GUI_DOWNLOAD'
    CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
    BIN_FILESIZE =
    filename = 'C:\REPORT.XLS'
    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_PR
    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.
    ENDIF.

Maybe you are looking for