Skip to Content
author's profile photo Former Member
Former Member

How to add a header line to excel sheet?

Hi Guru's

I have download the scheduling agreement report in a excel sheet, I want to know how to add the header line to that excel sheet.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

6 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Mar 12, 2009 at 06:16 AM

    hi,

    please refer this link

    TYPES: BEGIN OF ty_head,

    h(10) TYPE c,

    END OF ty_head.

    DATA: it_head TYPE TABLE OF ty_head WITH HEADER LINE.

    it_head-h = 'Field1'.

    APPEND it_head.

    it_head-h = 'Field2'.

    APPEND it_head.

    it_head-h = 'Field3'.

    APPEND it_head.

    it_head-h = 'Field4'.

    APPEND it_head.

    CALL FUNCTION 'GUI_DOWNLOAD'

    EXPORTING

    filename = p_file

    filetype = 'ASC'

    write_field_separator = 'X'

    header = '00'

    TABLES

    data_tab = it_tab

    fieldnames = it_head[]

    EXCEPTIONS

    OTHERS = 1.

    https://www.sdn.sap.com/irj/scn/wiki?path=/display/snippets/download%252bdata%252binto%252bexcel%252bwith%252bheader

    thanks

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 12, 2009 at 06:16 AM
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 12, 2009 at 06:24 AM

    Hi

    See this sample code:

    Tables : zacg_cca,zacg_exsh.

    data: P_file like RLGRAP-FILENAME.

    Data: Begin of it_header occurs 0,

    Header(15) ,

    end of it_header.

    Data : begin of it_final occurs 0,

    ccode type zacg_cca-ccode,

    mat_cd type zacg_cca-mat_cd,

    ingr_desc type zacg_cca-ingr_desc,

    conc type zacg_cca-conc,

    quantity type zacg_cca-quantity,

    percqty type zacg_cca-percqty,

    flag ,

    APP_DATE type zacg_cca-app_date,

    rsamnos type zacg_cca-rsamnos,

    end of it_final.

    SELECTION-SCREEN : BEGIN OF BLOCK blk WITH FRAME TITLE text-000.

    select-options : s_Date for zacg_cca-app_date.

    SELECTION-SCREEN : END OF BLOCK blk.

    it_header-Header = 'Samp_code'.

    Append it_header.

    it_header-Header = 'Mat_code'.

    Append it_header.

    it_header-Header = 'Ingr_Desc'.

    Append it_header.

    it_header-Header = 'Conc'.

    Append it_header.

    it_header-Header = 'Quan'.

    Append it_header.

    it_header-Header = 'Perc'.

    Append it_header.

    it_header-Header = 'Flag'.

    Append it_header.

    it_header-Header = 'Date'.

    Append it_header.

    it_header-Header = 'Rsamnos'.

    Append it_header.

    it_header-Header = 'Mat_code'.

    Append it_header.

    select ccode

    mat_cd

    ingr_desc

    conc

    quantity

    percqty

    app_date

    rsamnos

    from zacg_cca into corresponding

    fields of table

    it_final where zacg_cca~app_date in s_date.

    loop at it_final.

    it_final-flag = 'T'.

    modify it_final.

    it_final-quantity = it_final-quantity * 2 .

    Modify it_final.

    endloop.

    CALL FUNCTION 'MS_EXCEL_OLE_STANDARD_DAT'

    EXPORTING

    FILE_NAME = 'E:\IT\P_FILE'

    CREATE_PIVOT = 0

    DATA_SHEET_NAME = ' '

    PIVOT_SHEET_NAME = ' '

    PASSWORD = ' '

    PASSWORD_OPTION = 0

    TABLES

    PIVOT_FIELD_TAB =

    DATA_TAB = it_final[]

    FIELDNAMES = it_header[]

    EXCEPTIONS

    FILE_NOT_EXIST = 1

    FILENAME_EXPECTED = 2

    COMMUNICATION_ERROR = 3

    OLE_OBJECT_METHOD_ERROR = 4

    OLE_OBJECT_PROPERTY_ERROR = 5

    INVALID_PIVOT_FIELDS = 6

    DOWNLOAD_PROBLEM = 7

    OTHERS = 8

    .

    IF SY-SUBRC 0.

    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    regards

    Satish

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 12, 2009 at 06:36 AM

    Hi,

    you can use FM GUI_DOWNLOAD to down load excel file.

    1. create a internal table with 1 record containing all the headers only.

    2. call GUI_DOWNLOAD and down load the file with headers only.

    3. create internal table with subsequent data records with same column sequence as above internal table.

    4.call GUI_DOWNLAOD with same file name as of above and this time set exporting PARAMETER 'APPEND' of GUI_DOWNLOAD with 'X'.

    5.this will appand the second output to the same excel file downlaoded before.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 12, 2009 at 06:16 AM

    Hi,

    I had a similar requirement but wat I did was i inserted a row in the Internal Table (obviously the first row with index 1) with all the header contents. And after that I appended the desired data to the Internal Table.

    Regards,

    Sakkthiss.R

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 12, 2009 at 06:17 AM

    hi,

    Use GUI_DOWNLOAD and the tables parameter

    FIELDNAMES is used to get the header in the file.

    Give the file extension as "xls" and field separator 'X' for proper download of your data

    Thanks

    Sharath

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.