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

header data of excel file

hi,

how can we get header data to excel header when retieving internal table data to an excel file, according to my requirement ,i want to get data into excel file along with its header ,is there any function module available please answer me

thank you

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Nov 22, 2007 at 09:02 AM

    Hi,

    Check this sample code...

    REPORT Z_DOWNLOAD_HEADER.

    DATA : itab LIKE TABLE OF t001 WITH HEADER LINE.

    *----


    SELECT * FROM t001 INTO TABLE itab.

    PERFORM mydownload TABLES itab USING 'Z:\t001.txt'.

    &----


    *& Form mydownload

    &----


    • text

    ----


    • -->PTAB text

    • -->FILENAME text

    ----


    FORM mydownload TABLES ptab USING filename.

    *----


    DAta

    *DATA : components LIKE rstrucinfo OCCURS 0 WITH HEADER LINE.

    DATA: dfies_tab LIKE dfies OCCURS 0 WITH HEADER LINE.

    DATA : allfields(300) TYPE c.

    DATA : fld(100) TYPE c.

    DATA : BEGIN OF htab OCCURS 0,

    allfields(300) TYPE c,

    END OF htab.

    CALL FUNCTION 'DDIF_FIELDINFO_GET'

    EXPORTING

    tabname = 'T001'

    • FIELDNAME = ' '

    • LANGU = SY-LANGU

    • LFIELDNAME = ' '

    • ALL_TYPES = ' '

    • GROUP_NAMES = ' '

    • UCLEN = UCLEN

    • IMPORTING

    • X030L_WA = X030L_WA

    • DDOBJTYPE = DDOBJTYPE

    • DFIES_WA = DFIES_WA

    • LINES_DESCR = LINES_DESCR

    TABLES

    dfies_tab = dfies_tab

    • FIXED_VALUES = FIXED_VALUES

    • EXCEPTIONS

    • NOT_FOUND = 1

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

    LOOP AT dfies_tab.

    CONCATENATE dfies_tab-fieldtext

    cl_abap_char_utilities=>horizontal_tab INTO fld.

    CONCATENATE allfields fld INTO allfields .

    ENDLOOP.

    htab-allfields = allfields.

    APPEND htab.

    *----


    download first field list

    CALL FUNCTION 'GUI_DOWNLOAD'

    EXPORTING

    • BIN_FILESIZE =

    filename = 'Z:\t001.xls'

    filetype = 'DAT'

    write_field_separator = 'X'

    TABLES

    data_tab = htab.

    *----


    then download file data

    CALL FUNCTION 'GUI_DOWNLOAD'

    EXPORTING

    • BIN_FILESIZE =

    filename = 'z:\t001.xls'

    filetype = 'DAT'

    append = 'X'

    write_field_separator = 'X'

    TABLES

    data_tab = ptab.

    ENDFORM. "mydownload

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 22, 2007 at 09:02 AM

    refre below code:

    t_xls TYPE STANDARD TABLE OF tp_xls WITH HEADER LINE,

    t_objhead TYPE STANDARD TABLE OF solisti1 WITH HEADER LINE,

    t_objbin TYPE STANDARD TABLE OF solisti1 WITH HEADER LINE,

    t_objpack TYPE STANDARD TABLE OF sopcklsti1 WITH HEADER LINE,

    t_objtxt TYPE STANDARD TABLE OF solisti1 WITH HEADER LINE,

    t_reclist TYPE STANDARD TABLE OF somlreci1 WITH HEADER LINE.

    *& Form excelrep_criticaljobs

    &----


    • Description : To send the critical Autosys job status via Excel

    • Report

    ----


    • Parameters : None.

    ----


    FORM excelrep_criticaljobs .

    DATA :l_syuzeit TYPE sy-uzeit,

    l_time(5) TYPE c,

    l_ampm(2) TYPE c,

    l_subject(255) TYPE c.

    CLEAR t_xls.

    REFRESH t_xls.

    l_syuzeit = sy-uzeit.

    IF t_final_data1[] IS NOT INITIAL.

    PERFORM fill_header.

    LOOP AT t_final_data1 WHERE status NE space.

    t_xls-jobname = t_final_data1-jobname.

    WRITE t_final_data1-act_start_date TO t_xls-act_start_date.

    WRITE t_final_data1-est_start_time TO t_xls-est_start_time.

    WRITE t_final_data1-act_start_time TO t_xls-act_start_time.

    WRITE t_final_data1-est_end_time TO t_xls-est_end_time.

    WRITE t_final_data1-act_end_time TO t_xls-act_end_time.

    t_xls-est_duration = t_final_data1-est_duration.

    t_xls-act_duration = t_final_data1-duration.

    t_xls-status = t_final_data1-comment.

    t_xls-process = t_final_data1-desc.

    t_xls-fill10 = c_0d.

    t_xls-fill1 = c_09.

    t_xls-fill2 = c_09.

    t_xls-fill3 = c_09.

    t_xls-fill4 = c_09.

    t_xls-fill5 = c_09.

    t_xls-fill6 = c_09.

    t_xls-fill7 = c_09.

    t_xls-fill8 = c_09.

    t_xls-fill9 = c_09.

    APPEND t_xls.

    CLEAR t_xls.

    ENDLOOP.

    l_ampm = c_am.

    IF l_syuzeit GT c_125959.

    l_syuzeit = l_syuzeit - c_120000.

    l_ampm = c_pm.

    ELSEIF l_syuzeit GT c_120000.

    l_ampm = c_pm.

    ELSEIF l_syuzeit LT c_010000.

    l_syuzeit = l_syuzeit + c_120000.

    l_ampm = c_am.

    ENDIF.

    WRITE l_syuzeit TO l_time USING EDIT MASK c_edmask.

    CONCATENATE text-070 l_time l_ampm INTO l_subject

    SEPARATED BY space.

    CLEAR w_doc_chng.

    w_doc_chng-obj_name = l_subject.

    w_doc_chng-obj_descr = l_subject.

    CLEAR t_objtxt.

    REFRESH t_objtxt.

    t_objtxt = text-068.

    APPEND t_objtxt.

    CLEAR t_objtxt.

    t_objtxt = space.

    APPEND t_objtxt.

    CLEAR t_objtxt.

    t_objtxt = text-069.

    APPEND t_objtxt.

    CLEAR t_objtxt.

    t_objtxt = space.

    APPEND t_objtxt.

    CLEAR t_objtxt.

    MOVE w_sysinfo TO t_objtxt.

    APPEND t_objtxt.

    CLEAR t_objtxt.

    t_objtxt = space.

    APPEND t_objtxt.

    CLEAR t_objtxt.

    CLEAR w_tab_lines.

    DESCRIBE TABLE t_objtxt LINES w_tab_lines.

    w_doc_chng-doc_size = w_tab_lines * c_255.

    CLEAR t_objpack.

    REFRESH t_objpack.

    t_objpack-body_start = c_1.

    t_objpack-body_num = w_tab_lines * c_255.

    t_objpack-doc_type = c_txt.

    APPEND t_objpack.

    CLEAR t_objpack.

    CLEAR t_objbin.

    REFRESH t_objbin.

    LOOP AT t_xls.

    t_objbin = t_xls.

    APPEND t_objbin.

    CLEAR t_objbin.

    ENDLOOP.

    CLEAR w_tab_lines.

    DESCRIBE TABLE t_objbin LINES w_tab_lines.

    CLEAR l_subject.

    CONCATENATE text-083 sy-datum l_time l_ampm INTO l_subject

    SEPARATED BY c_uscore.

    CLEAR t_objhead.

    REFRESH t_objhead.

    t_objhead = l_subject.

    APPEND t_objhead.

    CLEAR t_objhead.

    t_objpack-transf_bin = c_x.

    t_objpack-head_start = c_1.

    t_objpack-head_num = c_1.

    t_objpack-body_start = c_1.

    t_objpack-body_num = w_tab_lines.

    t_objpack-doc_type = c_xls.

    t_objpack-obj_name = text-070.

    t_objpack-obj_descr = text-070.

    t_objpack-doc_size = w_tab_lines * c_255.

    t_objpack-mess_type = space.

    APPEND t_objpack.

    CLEAR t_objpack.

    CLEAR t_reclist.

    REFRESH t_reclist.

    IF s_email[] IS NOT INITIAL.

    LOOP AT s_email.

    t_reclist-receiver = s_email-low.

    t_reclist-rec_type = c_u.

    APPEND t_reclist.

    CLEAR t_reclist.

    ENDLOOP.

    ENDIF.

    PERFORM mail_report.

    ELSE.

    MESSAGE e015 WITH text-072.

    ENDIF.

    CLEAR : w_doc_chng,

    t_objpack,

    t_objhead,

    t_objbin,

    t_objtxt.

    REFRESH : t_objpack,

    t_objhead,

    t_objbin,

    t_objtxt,

    t_reclist.

    ENDFORM. " excelrep_criticaljobs

    FORM fill_header .

    MOVE w_sysinfo TO t_xls-jobname.

    t_xls-fill10 = c_0d.

    t_xls-fill1 = c_09.

    t_xls-fill2 = c_09.

    t_xls-fill3 = c_09.

    t_xls-fill4 = c_09.

    t_xls-fill5 = c_09.

    t_xls-fill6 = c_09.

    t_xls-fill7 = c_09.

    t_xls-fill8 = c_09.

    t_xls-fill9 = c_09.

    APPEND t_xls.

    CLEAR t_xls.

    MOVE text-012 TO t_xls-jobname.

    MOVE text-020 TO t_xls-act_start_date.

    MOVE text-058 TO t_xls-est_start_time.

    MOVE text-059 TO t_xls-act_start_time.

    MOVE text-060 TO t_xls-est_end_time.

    MOVE text-061 TO t_xls-act_end_time.

    MOVE text-062 TO t_xls-est_duration.

    MOVE text-063 TO t_xls-act_duration.

    MOVE text-064 TO t_xls-status.

    MOVE text-065 TO t_xls-process.

    t_xls-fill10 = c_0d.

    t_xls-fill1 = c_09.

    t_xls-fill2 = c_09.

    t_xls-fill3 = c_09.

    t_xls-fill4 = c_09.

    t_xls-fill5 = c_09.

    t_xls-fill6 = c_09.

    t_xls-fill7 = c_09.

    t_xls-fill8 = c_09.

    t_xls-fill9 = c_09.

    APPEND t_xls.

    CLEAR t_xls.

    ENDFORM. " fill_header

    FORM mail_report .

    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    EXPORTING

    document_data = w_doc_chng

    commit_work = c_x

    TABLES

    packing_list = t_objpack

    object_header = t_objhead

    contents_bin = t_objbin

    contents_txt = t_objtxt

    receivers = t_reclist

    EXCEPTIONS

    too_many_receivers = 1

    document_not_sent = 2

    document_type_not_exist = 3

    operation_no_authorization = 4

    parameter_error = 5

    x_error = 6

    enqueue_error = 7

    OTHERS = 8.

    IF sy-subrc NE 0.

    CASE sy-subrc.

    WHEN 1.

    MESSAGE i015 WITH text-071.

    WHEN 2.

    MESSAGE i015 WITH text-072.

    WHEN 4.

    MESSAGE i015 WITH text-073.

    WHEN OTHERS.

    MESSAGE i015 WITH text-074.

    ENDCASE.

    ELSE.

    MESSAGE s015 WITH text-081.

    ENDIF.

    ENDFORM. " mail_report

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 22, 2007 at 09:03 AM

    u can write the code for that like below.

    utab-ebeln = 'Pur. no.'.

    utab-ekorg = 'Org'.

    utab-aedat = 'Created'.

    utab-fakt = 'F'.

    utab-gods = 'G'.

    INSERT utab INDEX 1.

    regards,'

    pavan.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 22, 2007 at 09:46 AM

    Hi,

    I am sending this program for getting the header info along with data into the excel file.

    TABLES: T001.

    data: it_t001 type t001 occurs 0,

    it_fields type dfies occurs 0 with header line,

    *DFIES

    *DD Interface: Table Fields for DDIF_FIELDINFO_GET

    begin of it_fnames occurs 0,

    reptext like dfies-reptext,

    end of it_fnames.

    select * from t001 into table it_t001.

    CALL FUNCTION 'GET_FIELDTAB'

    EXPORTING

    • LANGU = SY-LANGU

    • ONLY = ' '

    TABNAME = 'T001'

    • WITHTEXT = 'X'

    • IMPORTING

    • HEADER =

    • RC =

    TABLES

    FIELDTAB = it_fields

    EXCEPTIONS

    INTERNAL_ERROR = 1

    NO_TEXTS_FOUND = 2

    TABLE_HAS_NO_FIELDS = 3

    TABLE_NOT_ACTIV = 4

    OTHERS = 5

    .

    IF SY-SUBRC <> 0.

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

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

    ENDIF.

    loop at it_fields.

    it_fnames-reptext = it_fields-reptext.

    append it_fnames.

    endloop.

    *CALL FUNCTION 'EXCEL_OLE_STANDARD_DAT'

    • EXPORTING

    • FILE_NAME = 'C:\Documents and Settings\pakumar\Desktop\T001'

    • CREATE_PIVOT = 0

  • DATA_SHEET_NAME = 'Companies'

    • PIVOT_SHEET_NAME = ' '

    • PASSWORD = ' '

    • PASSWORD_OPTION = 0

  • TABLES

    • PIVOT_FIELD_TAB =

  • DATA_TAB = it_t001

  • FIELDNAMES = it_fnames

  • EXCEPTIONS

  • FILE_NOT_EXIST = 1

  • FILENAME_EXPECTED = 2

  • COMMUNICATION_ERROR = 3

  • OLE_OBJECT_METHOD_ERROR = 4

  • OLE_OBJECT_PROPERTY_ERROR = 5

  • INVALID_FILENAME = 6

  • INVALID_PIVOT_FIELDS = 7

  • DOWNLOAD_PROBLEM = 8

  • OTHERS = 9

  • .

  • *IF SY-SUBRC <> 0.

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

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

    *ENDIF.

    CALL FUNCTION 'MS_EXCEL_OLE_STANDARD_DAT'

    EXPORTING

    FILE_NAME = 'C:\Documents and Settings\pakumar\Desktop\T001_2'

    • CREATE_PIVOT = 0

    DATA_SHEET_NAME = 'Companies 2'

    • PIVOT_SHEET_NAME = ' '

    • PASSWORD = ' '

    • PASSWORD_OPTION = 0

    TABLES

    • PIVOT_FIELD_TAB =

    DATA_TAB = it_t001

    FIELDNAMES = it_fnames

    EXCEPTIONS

    FILE_NOT_EXIST = 1

    FILENAME_EXPECTED = 2

    COMMUNICATION_ERROR = 3

    OLE_OBJECT_METHOD_ERROR = 4

    OLE_OBJECT_PROPERTY_ERROR = 5

    INVALID_FILENAME = 6

    INVALID_PIVOT_FIELDS = 7

    DOWNLOAD_PROBLEM = 8

    OTHERS = 9

    .

    IF SY-SUBRC <> 0.

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

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

    ENDIF.

    Reward points if useful

    Manoj

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.