ABAP顾问
分类:
2007-12-12 22:00:21
REPORT zrs08056 .
TABLES: t001,dd02l.
DATA: zx030l LIKE x030l.
DATA BEGIN OF zdfies OCCURS 0.
INCLUDE STRUCTURE dfies.
DATA END OF zdfies.
DATA: BEGIN OF flditab OCCURS 0,
fldname(11) TYPE c,
END OF flditab.
DATA itabt001 LIKE t001 OCCURS 0 WITH HEADER LINE.
DATA tname LIKE dd02l-tabname.
START-OF-SELECTION.
SELECT * FROM t001 INTO TABLE itabt001.
tname = 'T001'.
PERFORM getfieleds.
PERFORM showdata.
*&---------------------------------------------------------------------*
*& Form GETFIELEDS
*&---------------------------------------------------------------------*
FORM getfieleds.
CALL FUNCTION 'GET_FIELDTAB'
EXPORTING
langu = sy-langu
only = space
tabname = tname
withtext = 'X'
IMPORTING
header = zx030l
TABLES
fieldtab = zdfies
EXCEPTIONS
internal_error = 01
no_texts_found = 02
table_has_no_fields = 03
table_not_activ = 04.
CASE sy-subrc.
WHEN 0.
LOOP AT zdfies.
flditab-fldname = zdfies-fieldname.
APPEND flditab.
ENDLOOP.
WHEN OTHERS.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-subrc.
ENDCASE.
ENDFORM. "GETFIELEDS
*&---------------------------------------------------------------------*
*& Form SHOWdata
*&---------------------------------------------------------------------*
FORM showdata.
CALL FUNCTION 'EXCEL_OLE_STANDARD_DAT'
EXPORTING
file_name = 'C:\T001.XLS'
data_sheet_name = 'USER LIST'
TABLES
data_tab = itabt001
fieldnames = flditab
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.
ENDFORM.