程序:ZSDR0005
*&---------------------------------------------------------------------*
*& Report ZSDR0005
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZSDR0005.
INCLUDE ZSDR0005_TOP.
INCLUDE ZSDR0005_SCR.
INCLUDE ZSDR0005_FRM.
*---------------------------------------------------------------------*
* INITIALIZATION *
* *
*---------------------------------------------------------------------*
INITIALIZATION.
PERFORM frm_screen_initial.
*---------------------------------------------------------------------*
* AT SELECTION-SCREEN ON VALUE-REQUEST *
* *
*---------------------------------------------------------------------*
AT SELECTION-SCREEN.
CASE sy-ucomm.
WHEN 'ONLI'.
WHEN OTHERS.
CASE sscrfields-ucomm.
WHEN 'FC01'.
PERFORM frm_download_module.
ENDCASE.
ENDCASE.
*---------------------------------------------------------------------*
* AT SELECTION-SCREEN OUTPUT *
* *
*---------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR pa_path.
"获取文件地址搜索帮助
PERFORM frm_get_fielpath.
*---------------------------------------------------------------------*
* START-OF-SELECTION
*---------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM frm_upload_data. "加载外部数据
PERFORM frm_deal_data. "处理数据
PERFORM frm_alv_layout_build. "设置ALV整体布局
PERFORM frm_alv_set_columns. "设置ALV各个列的格式
PERFORM frm_alv_display_data. "调用ALV输出函数输出数据
INCLUDE:ZSDR0005_TOP
*&---------------------------------------------------------------------*
*& Include ZSDR0001_TOP
*&---------------------------------------------------------------------*
TYPE-POOLS:slis.
TYPE-POOLS: abap.
TABLES sscrfields.
*EXCEL 上传模板
TYPES:
BEGIN OF ty_data.
INCLUDE STRUCTURE zcustomer.
TYPES:
icon TYPE char10, "指示灯
message TYPE string, "返回消息
styletab TYPE lvc_t_styl,
sel TYPE c,
END OF ty_data.
DATA:gt_data TYPE TABLE OF ty_data WITH HEADER LINE,
wa_data TYPE ty_data.
*&---Alv变量定义
DATA:gs_layout TYPE lvc_s_layo.
DATA:gt_fieldcat TYPE lvc_t_fcat.
DATA:gs_fieldcat TYPE lvc_s_fcat.
DATA:gt_events TYPE slis_t_event. " 事件存储内表
DATA:wa_events TYPE slis_alv_event.
DATA:g_grid TYPE REF TO cl_gui_alv_grid.
DATA:where_clause TYPE string VALUE 'SEL = ABAP_TRUE'.
DATA functxt TYPE smp_dyntxt. "下载模板按钮需要用到的变量
DATA:gv_tabix TYPE i.
DATA: ls_stylerow TYPE lvc_s_styl,
lt_styletab TYPE lvc_t_styl.
INCLUDE:ZSDR0005_SCR
*&---------------------------------------------------------------------*
*& Include ZSDR0001_SCR
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK bk01 WITH FRAME TITLE TEXT-001.
PARAMETERS: pa_path TYPE rlgrap-filename MODIF ID a.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN END OF BLOCK bk01.
SELECTION-SCREEN: FUNCTION KEY 1."下载模板按钮
INCLUDE:ZSDR0005_FRM
*&---------------------------------------------------------------------*
*& Include ZSDR0001_FRM
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form frm_screen_initial
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_screen_initial .
functxt-icon_id = icon_xls.
functxt-quickinfo = '下载模板'.
functxt-icon_text = '下载模板'.
functxt-quickinfo = '下载模板'.
functxt-text = '下载模板'.
sscrfields-functxt_01 = functxt.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_download_module
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_download_module .
DATA:l_folder TYPE string.
DATA:l_dest LIKE rlgrap-filename.
DATA:l_rc LIKE sy-subrc.
DATA:lo_objdata LIKE wwwdatatab.
CALL METHOD cl_gui_frontend_services=>directory_browse( CHANGING selected_folder = l_folder ).
IF l_folder IS NOT INITIAL.
l_dest = l_folder && '\客户主数据银行批导模板.XLSX'.
SELECT SINGLE relid objid FROM wwwdata
INTO CORRESPONDING FIELDS OF lo_objdata
WHERE srtf2 = 0
AND relid = 'MI'
AND objid = 'ZSDR0005'.
IF sy-subrc NE 0 OR lo_objdata-objid EQ space.
MESSAGE '模板文件:物料主数据收集模板不存在,请用TCODE:SMW0进行加载' TYPE 'E'.
ELSE.
CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
EXPORTING
key = lo_objdata
destination = l_dest
IMPORTING
rc = l_rc.
IF l_rc NE 0.
MESSAGE '模板文件下载失败!' TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
ENDIF.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_get_fielpath
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_get_fielpath .
DATA:
lv_subrc TYPE i,
ls_filename TYPE file_table,
lt_filetables TYPE filetable. "路径列表
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
* WINDOW_TITLE =
* DEFAULT_EXTENSION =
* DEFAULT_FILENAME =
* FILE_FILTER =
initial_directory = 'C:\'
* multiselection = ''
CHANGING
file_table = lt_filetables[]
rc = lv_subrc
* USER_ACTION =
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
LOOP AT lt_filetables INTO ls_filename.
pa_path = ls_filename-filename.
ENDLOOP.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_upload_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_upload_data .
DATA: lt_excel TYPE STANDARD TABLE OF alsmex_tabline,
ls_data TYPE ty_data,
lv_column TYPE i.
FIELD-SYMBOLS:
<fs_field> TYPE any,
<fs_excel> TYPE alsmex_tabline.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = pa_path
i_begin_col = 4
i_begin_row = 12
i_end_col = 12
i_end_row = 10000
TABLES
intern = lt_excel
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
* 导入失败
IF sy-subrc <> 0.
MESSAGE 'EXCEL文件上传失败' TYPE 'E'.
LEAVE LIST-PROCESSING.
ENDIF.
IF lt_excel IS INITIAL.
MESSAGE '导入数据为空,请检查您的数据' TYPE 'E'.
LEAVE LIST-PROCESSING.
ENDIF.
SORT lt_excel BY row ASCENDING col ASCENDING.
PERFORM frm_set_l_fieldcat USING 'SSID' 'X' '序号'.
PERFORM frm_set_l_fieldcat USING 'ICON' 'X' '指示灯'. "
PERFORM frm_set_l_fieldcat USING 'PARTNER' 'X' '客户编号'.
PERFORM frm_set_l_fieldcat USING 'BKVID' '' '银行明细标识'.
PERFORM frm_set_l_fieldcat USING 'BANKS' '' '银行国家/地区'.
PERFORM frm_set_l_fieldcat USING 'ACCNAME' '' '账户名称'.
PERFORM frm_set_l_fieldcat USING 'BANKL' '' '银行代码'.
PERFORM frm_set_l_fieldcat USING 'BANKN' '' '银行帐户'.
PERFORM frm_set_l_fieldcat USING 'KOINH' '' '账户持有人'.
PERFORM frm_set_l_fieldcat USING 'BKREF' '' '状态'.
PERFORM frm_set_l_fieldcat USING 'MESSAGE' '' '返回消息'.
CLEAR:wa_data,gt_data[],lv_column.
LOOP AT lt_excel INTO DATA(ls_line).
CASE ls_line-col.
WHEN 1. gt_data-partner = ls_line-value."客户编号
WHEN 2. gt_data-bkvid = ls_line-value."银行明细标识
WHEN 3. gt_data-banks = ls_line-value."银行国家/地区
WHEN 4. gt_data-accname = ls_line-value."账户名称
WHEN 5. gt_data-bankl = ls_line-value."银行代码
WHEN 6. gt_data-bankn = ls_line-value."银行帐户
WHEN 7. gt_data-koinh = ls_line-value."账户持有人
WHEN 8. gt_data-bkref = ls_line-value."状态
ENDCASE.
AT END OF row.
lv_column = lv_column + 1.
gt_data-ssid = lv_column."序号
APPEND gt_data.
CLEAR gt_data.
ENDAT.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_deal_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_deal_data .
* LOOP AT gt_data INTO wa_data.
* MODIFY gt_data FROM wa_data.
* CLEAR wa_data.
* ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_alv_layout_build
*&---------------------------------------------------------------------*
*& text`
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_alv_layout_build .
CLEAR: gs_layout.
gs_layout-zebra = 'X'. "带条纹模式,隔行换色 "
gs_layout-cwidth_opt = 'X'. "优化列宽
gs_layout-detailinit = 'X'. "是否出现细节屏幕
* gs_layout-box_fname = 'SEL'.
gs_layout-stylefname ='STYLETAB'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_alv_set_columns
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_alv_set_columns .
REFRESH gt_fieldcat.
PERFORM frm_set_l_fieldcat USING 'SSID' 'X' '序号'.
PERFORM frm_set_l_fieldcat USING 'ICON' 'X' '指示灯'. "
PERFORM frm_set_l_fieldcat USING 'PARTNER' 'X' '客户编号'.
PERFORM frm_set_l_fieldcat USING 'BKVID' '' '银行明细标识'.
PERFORM frm_set_l_fieldcat USING 'BANKS' '' '银行国家/地区'.
PERFORM frm_set_l_fieldcat USING 'ACCNAME' '' '账户名称'.
PERFORM frm_set_l_fieldcat USING 'BANKL' '' '银行代码'.
PERFORM frm_set_l_fieldcat USING 'BANKN' '' '银行帐户'.
PERFORM frm_set_l_fieldcat USING 'KOINH' '' '账户持有人'.
PERFORM frm_set_l_fieldcat USING 'BKREF' '' '状态'.
PERFORM frm_set_l_fieldcat USING 'MESSAGE' '' '返回消息'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_SET_L_FIELDCAT
*&---------------------------------------------------------------------*
* 将值赋给每一个列
*----------------------------------------------------------------------*
* -->L_POS 列数
* -->NAME 列的名称也就是对应的内表的名称
* -->TEXTL 列的抬头文本
*----------------------------------------------------------------------*
FORM frm_set_l_fieldcat USING name fix_col textl.
gs_fieldcat-fieldname = name.
gs_fieldcat-coltext = textl.
gs_fieldcat-fix_column = fix_col.
IF name = 'ICON'.
gs_fieldcat-icon = 'X'.
ENDIF.
* IF name = 'ZLGPBE_1' OR name = 'ZLGPBE_2' OR name = 'ZLGPBE_3' OR
* name = 'ZLGPBE_4' OR name = 'ZLGPBE_5' OR name = 'ZLGPBE_6' OR
* name = 'MATNR' OR name = 'WERKS' OR name = 'LGORT' OR name = 'SOBKZ'.
* gs_fieldcat-edit = 'X'.
* ENDIF.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
ENDFORM. " FRM_SET_L_FIELDCAT
*&---------------------------------------------------------------------*
*& Form frm_alv_display_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_alv_display_data .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
i_callback_pf_status_set = 'FRM_PF_STATUS_SET'
i_callback_user_command = 'FRM_USER_COMMAND'
is_layout_lvc = gs_layout
it_fieldcat_lvc = gt_fieldcat[]
TABLES
t_outtab = gt_data
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_PF_STATUS_SET
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
FORM frm_pf_status_set USING lt_extab TYPE slis_t_extab.
DATA:rs_extab TYPE slis_extab.
"设置GUI状态栏
DATA:lv_text TYPE cua_tit_tx.
DATA l_num TYPE i.
DATA l_num1 TYPE char10.
CLEAR:l_num1,l_num,lv_text.
lv_text = '目录录入'.
SET PF-STATUS 'PF_STATUS' EXCLUDING lt_extab.
SET TITLEBAR 'PF_TITLE' WITH lv_text.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_USER_COMMAND
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
FORM frm_user_command USING ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
DATA: lt_rows TYPE lvc_t_row,
ls_row TYPE lvc_s_row.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = g_grid.
CALL METHOD g_grid->check_changed_data.
rs_selfield-refresh = 'X'.
rs_selfield-row_stable = 'X'.
rs_selfield-col_stable = 'X'.
CALL METHOD g_grid->get_frontend_layout
IMPORTING
es_layout = gs_layout.
gs_layout-cwidth_opt = 'X'.
CALL METHOD g_grid->set_frontend_layout
EXPORTING
is_layout = gs_layout.
CASE ucomm.
WHEN '&F12' OR '&F15' OR '&F03'.
LEAVE TO SCREEN 0.
WHEN 'SAVE'.
PERFORM frm_save USING ''.
* WHEN 'CHECK'.
* PERFORM frm_save USING 'X'.
WHEN OTHERS.
ENDCASE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_save
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_save USING test TYPE char1.
DATA:lt_zcustomer LIKE TABLE OF zcustomer.
DATA:lt_return LIKE TABLE OF zcustomer_return WITH HEADER LINE.
DATA:ls_input TYPE zssd_customeri.
DATA:ls_output TYPE zssd_customero.
LOOP AT gt_data ASSIGNING FIELD-SYMBOL(<fs>).
CLEAR: ls_input,ls_output.
ls_input = VALUE #( partner = <fs>-partner
bank = VALUE #( ( bkvid = <fs>-bkvid
banks = <fs>-banks"银行国家/地区
accname = <fs>-accname"账户名称
bankl = <fs>-bankl"银行代码
bankn = <fs>-bankn"银行帐户
koinh = <fs>-koinh
bkref = <fs>-bkref
) )"账户持有人
fields = VALUE #( ( 'NOFIELDS' ) ) ).
CALL FUNCTION 'ZSD_RF_CUSTOMER02'
EXPORTING
input = ls_input
IMPORTING
output = ls_output.
IF ls_output-status = 'S'.
<fs>-icon = icon_green_light.
<fs>-partner = ls_output-partner.
<fs>-message = ls_output-message.
ELSE.
<fs>-icon = icon_red_light.
<fs>-message = ls_output-message.
ENDIF.
ENDLOOP.
ENDFORM.