REPORT zsdrp160.
TYPE-POOLS : truxs.
TABLES sscrfields.
DATA:BEGIN OF gs_itab,
kunnr TYPE ztsd_fktj-kunnr, "客户编号
vkbur TYPE ztsd_fktj-vkbur, "销售部门
zterm TYPE ztsd_fktj-zterm, "付款条件代码
name1 TYPE kna1-name1, "客户名称
bezei TYPE tvkbt-bezei, "销售部门描述
text1 TYPE t052u-text1, "付款条件描述
icon TYPE char4, "消息类型
msg TYPE bapi_msg, "消息
END OF gs_itab,
gt_itab LIKE TABLE OF gs_itab.
DATA:BEGIN OF gs_kna1,
kunnr TYPE kna1-kunnr,
name1 TYPE kna1-name1,
END OF gs_kna1,
gt_kna1 LIKE TABLE OF gs_kna1.
DATA:gs_tvkbt TYPE tvkbt,
gt_tvkbt TYPE TABLE OF tvkbt,
gs_t052u TYPE t052u,
gt_t052u TYPE TABLE OF t052u.
SELECTION-SCREEN: FUNCTION KEY 1. "下载模板
SELECTION-SCREEN: FUNCTION KEY 2. "维护数据
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS p_path TYPE rlgrap-filename.
SELECTION-SCREEN END OF BLOCK b1.
INITIALIZATION.
sscrfields-functxt_01 = '下载模板'. "定义按钮文本
sscrfields-functxt_02 = '维护数据'. "定义按钮文本
*- Event
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
PERFORM get_filename USING p_path.
AT SELECTION-SCREEN.
CASE sscrfields-ucomm. "处理按钮命令
WHEN 'FC01'.
PERFORM frm_download_template.
WHEN 'FC02'.
PERFORM frm_wh_data. "SM30维护数据
ENDCASE.
*- Event
START-OF-SELECTION.
"从Excel文件里导入数据
PERFORM data_upload.
PERFORM process_data.
PERFORM get_des_check USING ''.
END-OF-SELECTION.
PERFORM alv_out.
*&---------------------------------------------------------------------*
*& Form get_filename
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PV_PATH text
*----------------------------------------------------------------------*
FORM get_filename USING pv_path TYPE rlgrap-filename..
DATA : lv_file_filter TYPE string.
DATA : ls_filetable TYPE file_table,
lt_filetable TYPE filetable.
DATA : lv_rc TYPE i.
DATA : lv_user_action TYPE i.
lv_file_filter = '(*.xlsx;*.xls)|*.xlsx;*.xls|'.
cl_gui_frontend_services=>file_open_dialog(
EXPORTING window_title = 'Select file'
file_filter = lv_file_filter
CHANGING file_table = lt_filetable
rc = lv_rc
user_action = lv_user_action ).
CHECK lv_user_action EQ 0.
CHECK lt_filetable[] IS NOT INITIAL.
READ TABLE lt_filetable INTO ls_filetable INDEX 1.
pv_path = ls_filetable-filename.
ENDFORM. " GET_FILENAME
*&---------------------------------------------------------------------*
*& Form frm_download_template
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM frm_download_template .
DATA:
lv_destination TYPE rlgrap-filename,
ls_key TYPE wwwdatatab.
DATA: lv_filename TYPE string VALUE'客户付款条款维护导入模板' ,
lv_path TYPE string VALUE'' ,
lv_fullpath TYPE string VALUE'' .
CALL METHOD cl_gui_frontend_services=>file_save_dialog "调用保存对话框
EXPORTING
default_extension = 'XLS'
default_file_name = lv_filename
CHANGING
filename = lv_filename
path = lv_path
fullpath = lv_fullpath
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.
IF sy-subrc EQ 0.
ELSE.
ENDIF.
IF lv_fullpath = ''.
MESSAGE '下载模板失败' TYPE 'E'.
ENDIF.
lv_destination = lv_fullpath.
ls_key-relid = 'MI'.
ls_key-objid = 'ZSDRP160'.
CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
EXPORTING
key = ls_key
destination = lv_destination.
ENDFORM. "frm_download_template
*&---------------------------------------------------------------------*
*& Form frm_wh_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM frm_wh_data.
DATA lv_view_name TYPE dd02v-tabname.
lv_view_name = 'ZTSD_FKTJ_V'.
CALL FUNCTION 'VIEW_MAINTENANCE_CALL'
EXPORTING
action = 'U'
view_name = lv_view_name
EXCEPTIONS
client_reference = 1
foreign_lock = 2
invalid_action = 3
no_clientindependent_auth = 4
no_database_function = 5
no_editor_function = 6
no_show_auth = 7
no_tvdir_entry = 8
no_upd_auth = 9
only_show_allowed = 10
system_failure = 11
unknown_field_in_dba_sellist = 12
view_not_found = 13
maintenance_prohibited = 14
OTHERS = 15.
IF sy-subrc EQ 0.
ELSE.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. "frm_wh_data
*&---------------------------------------------------------------------*
*& Form data_upload
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM data_upload.
DATA: ls_excel TYPE zalsmex_tabline,
lt_excel TYPE TABLE OF zalsmex_tabline.
DATA: lv_idx LIKE sy-tabix.
FIELD-SYMBOLS: TYPE any.
IF p_path IS INITIAL.
MESSAGE s000(z1) WITH '请输入上传文件名!' DISPLAY LIKE 'E'.
LEAVE LIST-PROCESSING.
ENDIF.
CALL FUNCTION 'ZALSM_EXCEL_TO_INTERNAL_TABLE2'
EXPORTING
filename = p_path
i_begin_col = 1
i_begin_row = 2
i_end_col = 3
i_end_row = 65536
TABLES
intern = lt_excel
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 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.
SORT lt_excel BY row col.
LOOP AT lt_excel INTO ls_excel.
lv_idx = ls_excel-col.
ASSIGN COMPONENT lv_idx OF STRUCTURE gs_itab TO .
= ls_excel-value.
AT END OF row.
APPEND gs_itab TO gt_itab.
CLEAR gs_itab.
ENDAT.
ENDLOOP.
ENDFORM. "data_upload
*&---------------------------------------------------------------------*
*& Form process_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM process_data.
CHECK gt_itab IS NOT INITIAL.
*客户编码补0
LOOP AT gt_itab INTO gs_itab.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = gs_itab-kunnr
IMPORTING
output = gs_itab-kunnr.
MODIFY gt_itab FROM gs_itab.
ENDLOOP.
*客户名称
SELECT kunnr name1 INTO TABLE gt_kna1
FROM kna1
FOR ALL ENTRIES IN gt_itab
WHERE kunnr EQ gt_itab-kunnr.
IF sy-subrc EQ 0.
SORT gt_kna1 BY kunnr.
ENDIF.
*销售部门描述
SELECT vkbur bezei INTO CORRESPONDING FIELDS OF TABLE gt_tvkbt
FROM tvkbt
WHERE spras EQ sy-langu.
IF sy-subrc EQ 0.
SORT gt_tvkbt BY vkbur.
ENDIF.
*付款条件描述
SELECT zterm ztagg text1 INTO CORRESPONDING FIELDS OF TABLE gt_t052u
FROM t052u
WHERE spras EQ sy-langu.
IF sy-subrc EQ 0.
SORT gt_t052u BY zterm ztagg.
ENDIF.
ENDFORM. "process_data
*&---------------------------------------------------------------------*
*& Form get_des
*&---------------------------------------------------------------------*
* text pv_check 是否检查数据
*----------------------------------------------------------------------*
FORM get_des_check USING pv_check TYPE char1.
DEFINE m_msg.
gs_itab-icon = '@0A@'."红灯
if gs_itab-msg is initial.
gs_itab-msg = &1.
else.
gs_itab-msg = gs_itab-msg && '/' && &1.
endif.
END-OF-DEFINITION.
LOOP AT gt_itab INTO gs_itab.
CLEAR:gs_itab-icon,gs_itab-msg.
READ TABLE gt_kna1 INTO gs_kna1
WITH KEY kunnr = gs_itab-kunnr BINARY SEARCH.
IF sy-subrc EQ 0.
gs_itab-name1 = gs_kna1-name1.
ELSE.
IF pv_check EQ 'X'.
m_msg '客户编码不存在'.
ENDIF.
ENDIF.
READ TABLE gt_tvkbt INTO gs_tvkbt
WITH KEY vkbur = gs_itab-vkbur BINARY SEARCH.
IF sy-subrc EQ 0.
gs_itab-bezei = gs_tvkbt-bezei.
ELSE.
IF pv_check EQ 'X'.
m_msg '销售部门不存在'.
ENDIF.
ENDIF.
READ TABLE gt_t052u INTO gs_t052u
WITH KEY zterm = gs_itab-zterm BINARY SEARCH.
IF sy-subrc EQ 0.
gs_itab-text1 = gs_t052u-text1.
ELSE.
IF pv_check EQ 'X'.
m_msg '付款条件不存在'.
ENDIF.
ENDIF.
MODIFY gt_itab FROM gs_itab.
ENDLOOP.
ENDFORM. "get_des
*&---------------------------------------------------------------------*
*& Form alv_out
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM alv_out.
"使用alv网格显示
DATA: lt_fieldcat TYPE slis_t_fieldcat_alv,
ls_layout TYPE slis_layout_alv, "ALV的格式
lv_callback_program TYPE sy-repid,
lv_user_command TYPE slis_formname VALUE 'USER_COMMAND'. "双击事件
PERFORM fieldcat_init USING lt_fieldcat."输出列表控件表头
PERFORM layout_init USING ls_layout.
lv_callback_program = sy-repid."当前主程序
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = lv_callback_program
i_callback_user_command = lv_user_command
i_callback_pf_status_set = 'PF_STATUS_SET'
is_layout = ls_layout
it_fieldcat = lt_fieldcat
i_save = 'A' "保存
TABLES
t_outtab = gt_itab
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc NE 0.
MESSAGE 'ALV输出报错' TYPE 'E'.
ENDIF.
ENDFORM. " ALV_OUT.
*&---------------------------------------------------------------------*
*& Form fieldcat_init
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PT_FIELDCAT text
*----------------------------------------------------------------------*
FORM fieldcat_init USING pt_fieldcat TYPE slis_t_fieldcat_alv.
DATA: ls_fieldcat TYPE slis_fieldcat_alv.
DEFINE addfield.
ls_fieldcat-fieldname = &1.
ls_fieldcat-seltext_l = &2.
ls_fieldcat-seltext_m = &2.
ls_fieldcat-seltext_s = &2.
ls_fieldcat-reptext_ddic = &2.
ls_fieldcat-key = &3.
if &1 = 'ICON'.
ls_fieldcat-icon = 'X'.
endif.
append ls_fieldcat to pt_fieldcat.
clear ls_fieldcat.
END-OF-DEFINITION.
addfield 'KUNNR' '客户编号' ''.
addfield 'NAME1' '客户名称' ''.
addfield 'VKBUR' '销售部门' ''.
addfield 'BEZEI' '销售部门描述' ''.
addfield 'ZTERM' '付款条件代码' ''.
addfield 'TEXT1' '付款条件描述' ''.
addfield 'ICON' '消息类型' ''.
addfield 'MSG' '消息' ''.
LOOP AT pt_fieldcat INTO ls_fieldcat.
CASE ls_fieldcat-fieldname.
WHEN 'KUNNR'.
ls_fieldcat-ref_fieldname = 'KUNNR'.
ls_fieldcat-ref_tabname = 'KNA1'.
ENDCASE.
MODIFY pt_fieldcat FROM ls_fieldcat.
ENDLOOP.
ENDFORM. "FIELDCAT_INIT
*&---------------------------------------------------------------------*
*& Form layout_init
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PS_LAYOUT text
*----------------------------------------------------------------------*
FORM layout_init USING ps_layout TYPE slis_layout_alv.
ps_layout-colwidth_optimize = 'X'.
ps_layout-detail_popup = ''.
ps_layout-def_status = ''.
ENDFORM. "LAYOUT_INIT
*&---------------------------------------------------------------------*
*& Form user_command
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PV_UCOMM text
* -->##CALLED text
* -->PS_SELFIELD text
* -->##NEEDED text
*----------------------------------------------------------------------*
FORM user_command USING pv_ucomm LIKE sy-ucomm ##called
ps_selfield TYPE slis_selfield ##needed .
CASE pv_ucomm.
WHEN 'IA05'.
PERFORM import_data.
"刷新数据
ps_selfield-refresh = 'X'.
ps_selfield-col_stable = 'X'.
ps_selfield-row_stable = 'X'.
WHEN OTHERS.
ENDCASE.
ENDFORM. "USER_COMMAND
*&---------------------------------------------------------------------*
*& Form pf_status_set
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PT_EXTAB text
*----------------------------------------------------------------------*
FORM pf_status_set ##called
USING pt_extab TYPE slis_t_extab.
DATA: ls_extab TYPE slis_extab.
ls_extab-fcode = '&CRB'.
APPEND ls_extab TO pt_extab.
ls_extab-fcode = '&CRL'.
APPEND ls_extab TO pt_extab.
ls_extab-fcode = '&CRR'.
APPEND ls_extab TO pt_extab.
ls_extab-fcode = '&CRE'.
APPEND ls_extab TO pt_extab.
SET PF-STATUS 'PF100' EXCLUDING pt_extab.
ENDFORM. "PF_STATUS_SET
*&---------------------------------------------------------------------*
*& Form import_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM import_data.
DATA:ls_ztsd_fktj TYPE ztsd_fktj,
lt_ztsd_fktj TYPE TABLE OF ztsd_fktj.
PERFORM get_des_check USING 'X'.
LOOP AT gt_itab INTO gs_itab
WHERE icon NE '@0A@'.
gs_itab-icon = '@08@'.
gs_itab-msg = '导入成功'.
MODIFY gt_itab FROM gs_itab.
CLEAR ls_ztsd_fktj.
ls_ztsd_fktj-kunnr = gs_itab-kunnr."客户编号
ls_ztsd_fktj-vkbur = gs_itab-vkbur."销售部门
ls_ztsd_fktj-zterm = gs_itab-zterm."付款条件代码
ls_ztsd_fktj-aedat = sy-datum."更改日期
ls_ztsd_fktj-cputm = sy-uzeit."输入时间
ls_ztsd_fktj-usnam = sy-uname."用户名
APPEND ls_ztsd_fktj TO lt_ztsd_fktj.
ENDLOOP.
IF lt_ztsd_fktj[] IS NOT INITIAL.
MODIFY ztsd_fktj FROM TABLE lt_ztsd_fktj.
COMMIT WORK AND WAIT.
ENDIF.
ENDFORM. "import_data
阅读(1208) | 评论(0) | 转发(0) |