标签:create sgid symbol folder pat download mil win 文件名
查询界面
执行结果
SE11
主
*&---------------------------------------------------------------------*
*& Report ZIT0003
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zit0003.
INCLUDE zit0003_head.
INCLUDE zit0003_screen.
INCLUDE zit0003_forms.
INITIALIZATION.
sscrfields-functxt_01 = ‘下载文档‘.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file2.
* 选择文件搜索帮助
PERFORM frm_set_file_f4 USING p_file2 CHANGING p_file2.
AT SELECTION-SCREEN.
CASE sscrfields-ucomm.
WHEN ‘FC01‘.
PERFORM frm_down_excel.
WHEN OTHERS.
ENDCASE.
START-OF-SELECTION.
IF sy-uname+0(2) NE ‘IT‘.
MESSAGE ‘仅限IT账号使用‘ TYPE ‘S‘ DISPLAY LIKE ‘E‘.
RETURN.
ENDIF.
IF p_name+0(1) NE ‘Z‘.
MESSAGE ‘仅允许更新自建表‘ TYPE ‘S‘ DISPLAY LIKE ‘E‘.
RETURN.
ENDIF.
IF p_file2 IS INITIAL.
MESSAGE ‘请输入文件名‘ TYPE ‘S‘ DISPLAY LIKE ‘E‘.
RETURN.
ENDIF.
PERFORM frm_get_data. "动态创建内表 <dyn_table>
PERFORM frm_file_data2.
* PERFORM frm_get_filed. "本人电脑使用 TEXT_CONVERT_XLS_TO_SAP 有未知错误,弃之
PERFORM frm_save_data.
END-OF-SELECTION.
PERFORM frm_display_data.
包含文件ZIT0003_HEAD
*&---------------------------------------------------------------------*
*& 包含 ZIT0003_HEAD
*&---------------------------------------------------------------------*
TABLES:sscrfields.
DATA: d_ref TYPE REF TO data,
d_ref2 TYPE REF TO data,
lt_alv_cat TYPE TABLE OF lvc_s_fcat,
ls_alv_cat LIKE LINE OF lt_alv_cat.
DATA: lt_table LIKE TABLE OF dntab.
DATA: ls_table TYPE dntab.
DATA: dyn_table TYPE REF TO data.
DATA: dyn_wa TYPE REF TO data.
FIELD-SYMBOLS :<dyn_table> TYPE table,
<dyn_wa> TYPE any,
<dyn_field> TYPE any,
<fs_str> TYPE any.
DATA: dyn_table2 TYPE REF TO data.
DATA: dyn_wa2 TYPE REF TO data.
FIELD-SYMBOLS :<dyn_table2> TYPE table,
<dyn_wa2> TYPE any,
<dyn_field2> TYPE any,
<fs_str2> TYPE any.
DATA: go_excel TYPE ole2_object,
go_workbook TYPE ole2_object,
go_sheet TYPE ole2_object.
包含文件ZIT0003_SCREEN
*&---------------------------------------------------------------------*
*& 包含 ZIT0003_SCREEN
*&---------------------------------------------------------------------*
PARAMETERS: p_name TYPE dd03l-tabname OBLIGATORY.
PARAMETERS: p_file2 TYPE string MODIF ID m2.
SELECTION-SCREEN: FUNCTION KEY 1.
包含文件
*&---------------------------------------------------------------------*
*& 包含 ZIT0003_FORMS
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form FRM_GET_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_get_data .
*取出表结构的字段目录
CALL FUNCTION ‘NAMETAB_GET‘
EXPORTING
langu = sy-langu
tabname = p_name
TABLES
nametab = lt_table
EXCEPTIONS
no_texts_found = 1.
*根据取出的字段目录生成参考字段目录
CLEAR lt_alv_cat.
LOOP AT lt_table INTO ls_table.
ls_alv_cat-fieldname = ls_table-fieldname.
ls_alv_cat-ref_table = p_name.
ls_alv_cat-ref_field = ls_table-fieldname.
APPEND ls_alv_cat TO lt_alv_cat.
CLEAR ls_alv_cat.
ENDLOOP.
*内表创建
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt_alv_cat
IMPORTING
ep_table = d_ref.
*指定生成的内表到字段符号
ASSIGN d_ref->* TO <dyn_table>.
*创建动态工作区结构
CREATE DATA dyn_wa LIKE LINE OF <dyn_table>.
*创建动态工作区
ASSIGN dyn_wa->* TO <dyn_wa>.
**从动态表中取数到动态内表中
* SELECT * INTO CORRESPONDING FIELDS OF TABLE <dyn_table> UP TO 100
* ROWS FROM (p_name).
* BREAK-POINT.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_DOWN_EXCEL
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_down_excel .
DATA: lv_selected_folder TYPE string,
lv_fullpath TYPE rlgrap-filename.
* CALL METHOD cl_gui_frontend_services=>directory_browse
* CHANGING
* selected_folder = lv_selected_folder
* EXCEPTIONS
* cntl_error = 1
* error_no_gui = 2
* not_supported_by_gui = 3
* OTHERS = 4.
* IF sy-subrc <> 0.
* ENDIF.
*
* lv_fullpath = lv_selected_folder && p_name && ‘.xls‘.
SELECT COUNT(*) FROM dd03l WHERE tabname EQ p_name.
IF sy-subrc NE 0.
MESSAGE ‘该表不存在‘ TYPE ‘S‘ DISPLAY LIKE ‘E‘.
RETURN.
ENDIF.
*取出表结构的字段目录
CALL FUNCTION ‘NAMETAB_GET‘
EXPORTING
langu = sy-langu
tabname = p_name
TABLES
nametab = lt_table
EXCEPTIONS
no_texts_found = 1.
*根据取出的字段目录生成参考字段目录
CLEAR lt_alv_cat.
LOOP AT lt_table INTO ls_table.
ls_alv_cat-fieldname = ls_table-fieldname.
ls_alv_cat-ref_table = p_name.
ls_alv_cat-ref_field = ls_table-fieldname.
APPEND ls_alv_cat TO lt_alv_cat.
CLEAR ls_alv_cat.
ENDLOOP.
*内表创建
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt_alv_cat
IMPORTING
ep_table = d_ref2.
* BREAK-POINT.
*指定生成的内表到字段符号
ASSIGN d_ref2->* TO <dyn_table2>.
*创建动态工作区结构
CREATE DATA dyn_wa2 LIKE LINE OF <dyn_table2>.
DATA: lt_zit0001 LIKE TABLE OF zit0001.
*创建动态工作区
ASSIGN dyn_wa2->* TO <dyn_wa2>.
* READ TABLE lt_alv_cat INTO ls_alv_cat INDEX 1.
* IF sy-subrc EQ 0.
* ASSIGN COMPONENT ls_alv_cat-fieldname OF STRUCTURE <dyn_wa2> TO <fs_str2>.
* APPEND <dyn_wa2> TO <dyn_table2>.
* ENDIF.
* BREAK-POINT.
* <fs_str> = ‘9998‘.
DATA: lv_destination TYPE rlgrap-filename.
DATA: ls_key TYPE wwwdatatab.
* SELECT * INTO CORRESPONDING FIELDS OF TABLE <dyn_table> UP TO 1
* ROWS FROM (p_name).
* 首先下载模版
* SELECT SINGLE relid objid FROM wwwdata INTO CORRESPONDING FIELDS OF ls_key WHERE relid = ‘MI‘ AND objid = ‘ZFICO049‘.
* CALL FUNCTION ‘DOWNLOAD_WEB_OBJECT‘
* EXPORTING
* key = ls_key
* destination = lv_destination.
* 打开模版
CREATE OBJECT go_excel ‘EXCEL.APPLICATION‘.
IF sy-subrc NE 0.
ENDIF.
SET PROPERTY OF go_excel ‘DISPLAYALERTS‘ =