本文主要是介绍标准的ALV模式中的表维护程序,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
有时候新建一张表,需要通过ALV模式进行,增、删、改、减的标准动作。
提供一个标准的程序如下:基本上只要修改定义就可以使用(标红部分需要自定义)
ZBWSDT005_PG
"ALV 事件定义,如F4、输入检查等
INCLUDE zbwt005_pg_class.
"数据定义
INCLUDE zbwt005_pg_top.
INCLUDE zbwt005_pg_f01.
INCLUDE zbwt005_pg_mo1.
INITIALIZATION."获得要维护表的表名,存入g_tabname中
descr_ref ?= cl_abap_typedescr=>describe_by_data( gs_db ).
db_tab = descr_ref->get_ddic_header( ).
g_tabname = db_tab-tabname.
PERFORM get_chan.
PERFORM get_sales.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_chan.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'ZWWCHAN_KH'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'P_CHAN'
value_org = 'S'
TABLES
value_tab = gt_chan_kh.
* PERFORM get_chan_.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_compy.
PERFORM get_compy_f4.
* PERFORM get_zdpco1 USING 'S_ZDPC01-HIGH'.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_sales.
PERFORM get_sales_f4.
AT SELECTION-SCREEN OUTPUT.
* 设置选择画面输出格式
PERFORM frm_modify_screen.
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.
*----------------------------------------------------------------------*
* START-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.
* PERFORM get_zwwchan_kh.
PERFORM get_compy.
PERFORM get_other_data.
PERFORM prepare_layout CHANGING gs_layout ."设置layout
REFRESH gt_fieldcat.
PERFORM prepare_field_catalog CHANGING gt_fieldcat ."设置Field Catalog
PERFORM fieldcat_init USING gt_fieldcat[].
* 设置F4帮助
PERFORM set_f4.
CALL SCREEN '100'.
INCLUDE zbwt005_pg_top.
*&---------------------------------------------------------------------*
*& 包含 ZBWT006_PG_TOP
*&---------------------------------------------------------------------*
* 全局常量定义
*----------------------------------------------------------------------*
CONSTANTS:
c_flg_on TYPE c VALUE 'X'.
*----------------------------------------------------------------------*
* 表申明
*----------------------------------------------------------------------*
TABLES:
/bic/tzww_compy,
zbw_sdt010,
zbw_sdt005.
*----------------------------------------------------------------------*
* 全局类型定义
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
* 定义
*----------------------------------------------------------------------*
FIELD-SYMBOLS:
<f_excel> TYPE any,
<lt_f4> TYPE lvc_t_modi.
*----------------------------------------------------------------------*
* 全局变量/工作区定义
*----------------------------------------------------------------------*
DATA:
gs_db TYPE zbw_sdt005,
g_tabname(30) TYPE c. "存放维护表的表名
DATA: db_tab LIKE x030l, "存放变量的数据字典头信息
descr_ref TYPE REF TO cl_abap_typedescr. "分析ABAP类型描述的对象
TYPES: t_db LIKE gs_db.
DATA: BEGIN OF return_tab OCCURS 0 .
INCLUDE STRUCTURE ddshretval .
DATA: END OF return_tab .
*ALV显示内表结构
DATA: BEGIN OF gs_data_wa.
INCLUDE TYPE t_db.
DATA: txtsh TYPE /bic/tzww_compy-txtsh,
txtsh_kh TYPE zbw_sdt010-txtsh_kh,
txtsh_sa TYPE /bi0/tsales_off-txtsh,
txtmd TYPE /bi0/tcustomer-txtmd,
flag(1),
rowmsg(80),
END OF gs_data_wa.
DATA: BEGIN OF gs_chan_kh,
zwwchan_kh TYPE zbw_sdt010-zwwchan_kh,
txtsh_kh TYPE zbw_sdt010-txtsh_kh,
END OF gs_chan_kh.
DATA gt_chan_kh LIKE STANDARD TABLE OF gs_chan_kh.
DATA: gt_compy TYPE STANDARD TABLE OF /bic/tzww_compy,
gs_compy TYPE /bic/tzww_compy.
DATA: gt_sales TYPE STANDARD TABLE OF /bi0/tsales_off,
gs_sales TYPE /bi0/tsales_off.
DATA: gt_sales_dec TYPE STANDARD TABLE OF /bi0/tsales_off,
gs_sales_dec TYPE /bi0/tsales_off.
DATA: gt_customer TYPE STANDARD TABLE OF /bi0/tcustomer,
gs_customer TYPE /bi0/tcustomer.
DATA: i_dom_apstt TYPE STANDARD TABLE OF dd07v,
lv_wa_domtab TYPE dd07v.
data: BEGIN OF gs_ZPRODH1_f4."事业部搜帮助索
data:PROD_HIER like /BI0/TPROD_HIER-PROD_HIER,
TXTLG like /BI0/TPROD_HIER-TXTLG,
end of gs_ZPRODH1_f4.
data: gt_ZPRODH1_f4 LIKE TABLE OF gs_ZPRODH1_f4 WITH HEADER LINE.
data: BEGIN OF gs_ZPRODH3_f4."产品线搜帮助索
data:PROD_HIER like /BI0/TPROD_HIER-PROD_HIER,
TXTLG like /BI0/TPROD_HIER-TXTLG,
end of gs_ZPRODH3_f4.
data: gt_ZPRODH3_f4 LIKE TABLE OF gs_ZPRODH3_f4 WITH HEADER LINE.
DATA:BEGIN OF ps_data_wa.
INCLUDE TYPE t_db.
DATA: txtsh_kh TYPE zbw_sdt010-txtsh_kh,
flag(1),
rowmsg(80),
END OF ps_data_wa.
DATA: BEGIN OF gs_excel.
INCLUDE TYPE t_db.
DATA: flag(1),
rowmsg(80),
END OF gs_excel.
DATA:BEGIN OF gt_xlstmp OCCURS 0,
row TYPE zalsmex_tabline-row,
col TYPE zalsmex_tabline-row,
value TYPE zalsmex_tabline-value,
END OF gt_xlstmp.
DATA:gt_excel LIKE STANDARD TABLE OF gs_excel.
DATA: gt_data LIKE STANDARD TABLE OF gs_data_wa, "ALV数据内表
gt_data_old LIKE STANDARD TABLE OF gs_data_wa.
DATA: ok_code TYPE sy-ucomm,
save_ok TYPE sy-ucomm.
DATA: gt_fcode LIKE sy-ucomm OCCURS 0 WITH HEADER LINE.
*---------------------------------------------------------------------*
* ALV DATA DECLARATION
*---------------------------------------------------------------------*
DATA: gr_alvgrid TYPE REF TO cl_gui_alv_grid , "ALV对象
gt_fieldcat TYPE lvc_t_fcat,
gs_layout TYPE lvc_s_layo,
gs_variant TYPE disvariant,
alv_container TYPE scrfname VALUE 'T_COL', "ALV展示数据存放在此容器中
alv_custom_container TYPE REF TO cl_gui_custom_container,
gt_exclude TYPE ui_functions, "存放排除按钮的内表
gt_index_rows TYPE lvc_t_row, "用以存放要选择行的内表
gs_index_rows TYPE lvc_s_row. "用以存放要选择行的工作区
DATA: gf_valid(1) TYPE c,
gf_error(1) TYPE c.
***带出描述
DATA: g_event_receiver TYPE REF TO lcl_event_receiver,
* F4帮助用内表
gt_f4 TYPE lvc_t_f4,
gs_f4 TYPE lvc_s_f4. "F4帮助用工作区
DATA: g_reffield TYPE lvc_fname.
*----------------------------------------------------------------------*
* SELECTION-SCREEN
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
PARAMETERS:
p_insert RADIOBUTTON GROUP z USER-COMMAND f DEFAULT 'X',
p_modify RADIOBUTTON GROUP z,
p_delete RADIOBUTTON GROUP z,
p_disp RADIOBUTTON GROUP z.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF BLOCK blk2 WITH FRAME TITLE text-002.
*SELECT-OPTIONS:
* S_CHAN FOR ZBW_SDT010-ZWWCHAN MODIF ID Z01 OBLIGATORY.
PARAMETERS:
p_compy TYPE char4, "分公司
p_chan TYPE zbw_sdt010-zwwchan_kh MODIF ID z01, "考核旺旺渠道
p_sales TYPE zbw_sdt005-sales_off MODIF ID z01. "营业所
SELECT-OPTIONS
s_custom FOR zbw_sdt005-customer MODIF ID z01. "负责客户
SELECTION-SCREEN END OF BLOCK blk2.
SELECTION-SCREEN END OF BLOCK blk1.
”存放range 类型数据
DATA s_chan TYPE RANGE OF zbw_sdt010-zwwchan_kh.
DATA: s_chan_st LIKE LINE OF s_chan.
DATA s_sales TYPE RANGE OF zbw_sdt005-sales_off.
DATA: s_sales_st LIKE LINE OF s_sales.
INCLUDE zbwt005_pg_class.
* 定义临时类名称
CLASS lcl_event_receiver DEFINITION DEFERRED.
DATA:
gr_event TYPE REF TO lcl_event_receiver. "接受事件的对象
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS:
* 处理用户的F4帮助
handle_f4 FOR EVENT onf4 OF cl_gui_alv_grid
IMPORTING e_fieldname
es_row_no
er_event_data,
handle_data_changed
FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed.
ENDCLASS. "LCL_EVENT_RECEIVER DEFINITION
*&---------------------------------------------------------------------*
*& CLASS (IMPLEMENTATION) LCL_EVENT_RECEIVER
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.
* 处理用户的F4帮助
METHOD handle_f4.
PERFORM f4 USING e_fieldname
es_row_no
er_event_data.
ENDMETHOD.
*--DATA_CHANGED
METHOD handle_data_changed.
PERFORM handle_data_changed CHANGING er_data_changed.
ENDMETHOD. "HANDLE_CHANGED_DATA
ENDCLASS. "LCL_EVENT_RECEIVER
ZBWT005_PG_MO1
SET PF-STATUS 'MAIN100'.
IF p_modify = 'X' OR p_delete = 'X'.
CLEAR gt_fcode.
* APPEND 'EXCEL' TO gt_fcode.
SET PF-STATUS 'MAIN100' EXCLUDING gt_fcode.
ENDIF.
IF p_disp = 'X'.
CLEAR gt_fcode.
* APPEND 'EXCEL' TO gt_fcode.
APPEND 'SAVE' TO gt_fcode.
SET PF-STATUS 'MAIN100' EXCLUDING gt_fcode.
ENDIF.
gs_variant-report = sy-repid.
IF gr_alvgrid IS INITIAL .
CREATE OBJECT gr_alvgrid "第一次载入,建立对象
EXPORTING
i_parent = cl_gui_container=>screen0.
***建立对象 带出描述
CREATE OBJECT alv_custom_container
EXPORTING
container_name = alv_container.
*** 设置ALV的抬头标题
PERFORM load_data_into_grid.
PERFORM display_alv .
CALL METHOD gr_alvgrid->refresh_table_display.
CALL METHOD gr_alvgrid->set_ready_for_input
EXPORTING
i_ready_for_input = 1.
***带出描述
CREATE OBJECT g_event_receiver.
SET HANDLER g_event_receiver->handle_data_changed FOR gr_alvgrid.
***带出描述
CALL METHOD gr_alvgrid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_modified.
* 事件处理
CREATE OBJECT gr_event.
SET HANDLER gr_event->handle_f4 FOR gr_alvgrid.
SET HANDLER gr_event->handle_data_changed FOR gr_alvgrid.
CALL METHOD gr_alvgrid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_modified.
CALL METHOD gr_alvgrid->register_f4_for_fields
EXPORTING
it_f4 = gt_f4.
ELSE.
CALL METHOD gr_alvgrid->refresh_table_display.
IF gf_error IS NOT INITIAL. "判断修改后是否有不合法数据,有则选中错误行
CALL METHOD gr_alvgrid->set_selected_rows
EXPORTING
it_index_rows = gt_index_rows.
CLEAR gf_error.
REFRESH gt_index_rows.
ENDIF.
ENDIF.
ZBWT005_PG_F01
*&---------------------------------------------------------------------*
*& 包含 ZBWT006_PG_F01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form FRM_MODIFY_SCREEN
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_modify_screen .
LOOP AT SCREEN.
IF p_insert EQ c_flg_on .
IF screen-group1 = 'Z01'.
screen-active = 0.
ENDIF.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
ENDFORM. " FRM_MODIFY_SCREEN
*&---------------------------------------------------------------------*
*& Form F4
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_E_FIELDNAME text
* -->P_ES_ROW_NO text
* -->P_ER_EVENT_DATA text
*----------------------------------------------------------------------*
FORM f4 USING r_fieldname TYPE lvc_fname
rs_row_no TYPE lvc_s_roid
rr_event_data TYPE REF TO cl_alv_event_data.
FIELD-SYMBOLS: <lt_f4> TYPE lvc_t_modi.
DATA: BEGIN OF lt_t001 OCCURS 0 ,
zdp_c001 TYPE zbwt001-zdp_c001, "指标类别代码
zdp_n001 TYPE zbwt001-zdp_n001, "指标类别描述
END OF lt_t001.
DATA: ls_f4 TYPE lvc_s_modi,
ls_t001 LIKE LINE OF lt_t001,
l_fieldname TYPE dfies-fieldname.
DATA:lt_t002 TYPE TABLE OF zbwt002 WITH HEADER LINE.
DATA ls_zprodh1_f4 LIKE LINE OF gt_zprodh1_f4.
DATA ls_zprodh3_f4 LIKE LINE OF gt_zprodh3_f4.
* 当部门使用F4帮助的时候
IF r_fieldname = 'ZWWCHAN_KH'.
g_reffield = r_fieldname.
CLEAR gt_chan_kh.
SELECT zwwchan_kh txtsh_kh
INTO TABLE gt_chan_kh
FROM zbw_sdt010.
* IF sy-subrc NE 0 .
SELECT /bic/zwwchan AS zwwchan_kh
txtsh AS txtsh_kh
APPENDING TABLE gt_chan_kh
FROM /bic/tzwwchan.
* IF sy-subrc NE 0.
** MESSAGE '考核旺旺渠道不正确!' TYPE 'S' DISPLAY LIKE 'E'.
* EXIT.
* ENDIF.
* ENDIF.
SORT gt_chan_kh BY zwwchan_kh.
DELETE ADJACENT DUPLICATES FROM gt_chan_kh.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'ZWWCHAN_KH'
dynpprog = sy-repid
dynpnr = sy-dynnr
* dynprofield = 'P_COMPY'
value_org = 'S'
TABLES
value_tab = gt_chan_kh[]
return_tab = return_tab. "选中的内容
ASSIGN rr_event_data->m_data->* TO <lt_f4>.
ls_f4-fieldname = r_fieldname.
ls_f4-row_id = rs_row_no-row_id.
IF NOT return_tab IS INITIAL .
ls_f4-value = return_tab-fieldval .
APPEND ls_f4 TO <lt_f4>.
ENDIF .
ENDIF.
IF r_fieldname = 'SALES_OFF'.
g_reffield = r_fieldname.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'SALES_OFF'
dynpprog = sy-repid
dynpnr = sy-dynnr
* dynprofield = 'P_COMPY'
value_org = 'S'
TABLES
value_tab = gt_sales_dec[]
return_tab = return_tab. "选中的内容
ASSIGN rr_event_data->m_data->* TO <lt_f4>.
ls_f4-fieldname = r_fieldname.
ls_f4-row_id = rs_row_no-row_id.
IF NOT return_tab IS INITIAL .
ls_f4-value = return_tab-fieldval .
APPEND ls_f4 TO <lt_f4>.
ENDIF .
ENDIF.
IF r_fieldname = 'PRODH1'.
g_reffield = r_fieldname.
IF gt_zprodh1_f4 IS INITIAL."如果搜索帮助表为空,才从数据库读取数据,以节省资源
SELECT prod_hier txtlg FROM /bi0/tprod_hier
INTO CORRESPONDING FIELDS OF TABLE gt_zprodh1_f4
WHERE prod_hier LIKE 'D%' .
ENDIF.
LOOP AT gt_zprodh1_f4 INTO ls_zprodh1_f4 ."只保留三位
IF strlen( ls_zprodh1_f4-prod_hier ) NE 3.
DELETE gt_zprodh1_f4 INDEX sy-tabix.
ENDIF.
ENDLOOP.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'PROD_HIER'
dynpprog = sy-repid
dynpnr = sy-dynnr
* dynprofield = 'P_COMPY'
value_org = 'S'
TABLES
value_tab = gt_zprodh1_f4[]
return_tab = return_tab. "选中的内容
ASSIGN rr_event_data->m_data->* TO <lt_f4>.
ls_f4-fieldname = r_fieldname.
ls_f4-row_id = rs_row_no-row_id.
IF NOT return_tab IS INITIAL .
ls_f4-value = return_tab-fieldval .
APPEND ls_f4 TO <lt_f4>.
ENDIF .
ENDIF.
IF r_fieldname = 'PRODH3'.
g_reffield = r_fieldname.
IF gt_zprodh3_f4 IS INITIAL."如果搜索帮助表为空,才从数据库读取数据,以节省资源
SELECT prod_hier txtlg FROM /bi0/tprod_hier
INTO CORRESPONDING FIELDS OF TABLE gt_zprodh3_f4
WHERE prod_hier LIKE 'D%' .
ENDIF.
LOOP AT gt_zprodh3_f4 INTO ls_zprodh3_f4 ."只保留九位
IF strlen( ls_zprodh3_f4-prod_hier ) NE 9.
DELETE gt_zprodh3_f4 INDEX sy-tabix.
ENDIF.
ENDLOOP.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'PROD_HIER'
dynpprog = sy-repid
dynpnr = sy-dynnr
* dynprofield = 'P_COMPY'
value_org = 'S'
TABLES
value_tab = gt_zprodh3_f4[]
return_tab = return_tab. "选中的内容
ASSIGN rr_event_data->m_data->* TO <lt_f4>.
ls_f4-fieldname = r_fieldname.
ls_f4-row_id = rs_row_no-row_id.
IF NOT return_tab IS INITIAL .
ls_f4-value = return_tab-fieldval .
APPEND ls_f4 TO <lt_f4>.
ENDIF .
ENDIF.
* 抑制标准的Search Help
rr_event_data->m_event_handled = 'X'.
ENDFORM. " F4
*&---------------------------------------------------------------------*
*& Form HANDLE_DATA_CHANGED
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_ER_DATA_CHANGED text
*----------------------------------------------------------------------*
FORM handle_data_changed USING ir_data_changed
TYPE REF TO cl_alv_changed_data_protocol.
DATA: ls_mod_cell TYPE lvc_s_modi,
lv_value TYPE lvc_value.
LOOP AT ir_data_changed->mt_mod_cells
INTO ls_mod_cell.
IF ls_mod_cell-fieldname = 'ZWWCHAN_KH'.
CALL METHOD ir_data_changed->get_cell_value
EXPORTING
i_row_id = ls_mod_cell-row_id
i_fieldname = 'ZWWCHAN_KH'
IMPORTING
e_value = lv_value.
IF lv_value IS NOT INITIAL.
CLEAR gs_chan_kh.
READ TABLE gt_chan_kh INTO gs_chan_kh WITH KEY zwwchan_kh = lv_value.
IF sy-subrc EQ 0.
CALL METHOD ir_data_changed->modify_cell "修改单元格的值的方法
EXPORTING
i_row_id = ls_mod_cell-row_id "单元格的id
i_fieldname = 'TXTSH_KH' "单元格的字段
i_value = gs_chan_kh-txtsh_kh.
ELSE.
CALL METHOD ir_data_changed->modify_cell "修改单元格的值的方法
EXPORTING
i_row_id = ls_mod_cell-row_id "单元格的id
i_fieldname = 'TXTSH_KH' "单元格的字段
i_value = ''.
MESSAGE '考核旺旺渠道不存在' TYPE 'S' DISPLAY LIKE 'E'.
EXIT.
ENDIF.
ELSE.
CALL METHOD ir_data_changed->modify_cell "修改单元格的值的方法
EXPORTING
i_row_id = ls_mod_cell-row_id "单元格的id
i_fieldname = 'TXTSH_KH' "单元格的字段
i_value = ''.
ENDIF.
ENDIF.
IF ls_mod_cell-fieldname = 'ZWW_COMPY'.
CALL METHOD ir_data_changed->get_cell_value
EXPORTING
i_row_id = ls_mod_cell-row_id
i_fieldname = 'ZWW_COMPY'
IMPORTING
e_value = lv_value.
IF lv_value IS INITIAL.
CALL METHOD ir_data_changed->modify_cell "修改单元格的值的方法
EXPORTING
i_row_id = ls_mod_cell-row_id "单元格的id
i_fieldname = 'ZWW_COMPY' "单元格的字段
i_value = p_compy.
CLEAR gs_compy.
READ TABLE gt_compy INTO gs_compy WITH KEY /bic/zww_compy = p_compy.
CALL METHOD ir_data_changed->modify_cell "修改单元格的值的方法
EXPORTING
i_row_id = ls_mod_cell-row_id "单元格的id
i_fieldname = 'TXTSH' "单元格的字段
i_value = gs_compy-txtsh.
ENDIF.
ENDIF.
IF ls_mod_cell-fieldname = 'SALES_OFF'.
CALL METHOD ir_data_changed->get_cell_value
EXPORTING
i_row_id = ls_mod_cell-row_id
i_fieldname = 'SALES_OFF'
IMPORTING
e_value = lv_value.
IF lv_value IS NOT INITIAL.
CLEAR gs_chan_kh.
* READ TABLE gt_chan_kh INTO gs_chan_kh WITH KEY zwwchan_kh = lv_value.
DATA: l_text TYPE char20 .
SELECT SINGLE txtsh
FROM /bi0/tsales_off
INTO l_text
WHERE sales_off = lv_value.
IF sy-subrc EQ 0.
CALL METHOD ir_data_changed->modify_cell "修改单元格的值的方法
EXPORTING
i_row_id = ls_mod_cell-row_id "单元格的id
i_fieldname = 'TXTSH_SA' "单元格的字段
i_value = l_text.
ELSE.
CALL METHOD ir_data_changed->modify_cell "修改单元格的值的方法
EXPORTING
i_row_id = ls_mod_cell-row_id "单元格的id
i_fieldname = 'TXTSH_SA' "单元格的字段
i_value = ''.
MESSAGE '营业所不存在' TYPE 'S' DISPLAY LIKE 'E'.
EXIT.
ENDIF.
ELSE.
CALL METHOD ir_data_changed->modify_cell "修改单元格的值的方法
EXPORTING
i_row_id = ls_mod_cell-row_id "单元格的id
i_fieldname = 'TXTSH_SA' "单元格的字段
i_value = ''.
ENDIF.
ENDIF.
IF ls_mod_cell-fieldname = 'CUSTOMER'.
CALL METHOD ir_data_changed->get_cell_value
EXPORTING
i_row_id = ls_mod_cell-row_id
i_fieldname = 'CUSTOMER'
IMPORTING
e_value = lv_value.
IF lv_value IS NOT INITIAL.
CLEAR gs_chan_kh.
* READ TABLE gt_chan_kh INTO gs_chan_kh WITH KEY zwwchan_kh = lv_value.
* DATA: l_text TYPE char20 .
SELECT SINGLE txtmd
FROM /bi0/tcustomer
INTO l_text
WHERE customer = lv_value.
IF sy-subrc EQ 0.
CALL METHOD ir_data_changed->modify_cell "修改单元格的值的方法
EXPORTING
i_row_id = ls_mod_cell-row_id "单元格的id
i_fieldname = 'TXTMD' "单元格的字段
i_value = l_text.
ELSE.
CALL METHOD ir_data_changed->modify_cell "修改单元格的值的方法
EXPORTING
i_row_id = ls_mod_cell-row_id "单元格的id
i_fieldname = 'TXTMD' "单元格的字段
i_value = ''.
MESSAGE '客户不存在' TYPE 'S' DISPLAY LIKE 'E'.
EXIT.
ENDIF.
ELSE.
CALL METHOD ir_data_changed->modify_cell "修改单元格的值的方法
EXPORTING
i_row_id = ls_mod_cell-row_id "单元格的id
i_fieldname = 'TXTMD' "单元格的字段
i_value = ''.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM. " HANDLE_DATA_CHANGED
*&---------------------------------------------------------------------*
*& Form PREPARE_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GS_LAYOUT text
*----------------------------------------------------------------------*
FORM prepare_layout CHANGING ps_layout TYPE lvc_s_layo.
ps_layout-zebra = 'X' .
ps_layout-smalltitle = 'X' .
* ps_layout-cwidth_opt = 'X'.
ps_layout-no_toolbar = ' '.
IF p_disp = 'X' OR p_modify = 'X'.
ps_layout-no_rowmark = 'X'.
ENDIF.
ENDFORM. " PREPARE_LAYOUT
*&---------------------------------------------------------------------*
*& Form PREPARE_FIELD_CATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GT_FIELDCAT text
*----------------------------------------------------------------------*
FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat .
DATA: ls_fieldcat TYPE lvc_s_fcat,
l_rows TYPE i.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = g_tabname "表结构
i_client_never_display = 'X'
CHANGING
ct_fieldcat = pt_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_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.
*UserExit,用于自定义Field Catalog
PERFORM userexit_fieldcat CHANGING pt_fieldcat.
IF p_disp <> 'X'. "除了显示模式,其他模式都显示选择列和操作结果列
CLEAR ls_fieldcat .
ls_fieldcat-fieldname = 'FLAG' .
ls_fieldcat-coltext = '选择' .
ls_fieldcat-edit = 'X'.
ls_fieldcat-checkbox = 'X'.
ls_fieldcat-key = 'X'.
ls_fieldcat-outputlen = '6'.
ls_fieldcat-col_pos = 0.
APPEND ls_fieldcat TO pt_fieldcat .
CLEAR l_rows.
DESCRIBE TABLE pt_fieldcat LINES l_rows.
CLEAR ls_fieldcat .
ls_fieldcat-fieldname = 'ROWMSG' .
ls_fieldcat-coltext = '操作结果' .
ls_fieldcat-col_pos = l_rows.
ls_fieldcat-outputlen = '30'.
APPEND ls_fieldcat TO pt_fieldcat .
ENDIF.
ENDFORM. " PREPARE_FIELD_CATALOG
*&---------------------------------------------------------------------*
*& Form USEREXIT_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_PT_FIELDCAT text
*----------------------------------------------------------------------*
FORM userexit_fieldcat CHANGING pt_fieldcat TYPE lvc_t_fcat.
DATA: ls_fieldcat TYPE lvc_s_fcat.
DELETE pt_fieldcat WHERE fieldname = 'MANDT'.
LOOP AT pt_fieldcat INTO ls_fieldcat.
CASE ls_fieldcat-fieldname.
WHEN 'ZWW_COMPY'.
ls_fieldcat-coltext = '旺旺销售公司' .
ls_fieldcat-col_pos = 1.
ls_fieldcat-outputlen = 8.
ls_fieldcat-key = ''.
ls_fieldcat-ref_table = ''.
* ls_fieldcat-f4availabl = 'X'.
WHEN 'ZWWCHAN_KH'.
ls_fieldcat-coltext = '考核旺旺渠道' .
ls_fieldcat-col_pos = 3.
ls_fieldcat-outputlen = 12.
ls_fieldcat-f4availabl = 'X'.
ls_fieldcat-col_opt = 'X'.
WHEN 'PRODH1'.
ls_fieldcat-coltext = '事业部' .
ls_fieldcat-col_pos = 5.
ls_fieldcat-outputlen = 18.
ls_fieldcat-ref_table =' '. "F4帮助表设置
ls_fieldcat-ref_field =' '. "F4帮助字段设置
ls_fieldcat-f4availabl = 'X'.
WHEN 'PRODH3'.
ls_fieldcat-coltext = '产品线' .
ls_fieldcat-col_pos = 6.
ls_fieldcat-outputlen = 18.
ls_fieldcat-ref_table =' '. "F4帮助表设置
ls_fieldcat-ref_field =' '. "F4帮助字段设置
ls_fieldcat-f4availabl = 'X'.
WHEN 'SALES_OFF'.
ls_fieldcat-coltext = '营业所' .
ls_fieldcat-outputlen = 14.
ls_fieldcat-col_pos = 7.
ls_fieldcat-f4availabl = 'X'.
WHEN 'CUSTOMER'.
ls_fieldcat-coltext = '负责客户' .
ls_fieldcat-outputlen = 8.
ls_fieldcat-col_pos = 9.
WHEN 'ZYDBZS'.
ls_fieldcat-coltext = '业代编制数' .
ls_fieldcat-outputlen = 8.
ls_fieldcat-col_pos = 11.
* ls_fieldcat-f4availabl = 'X'.
ENDCASE.
IF p_insert = 'X' OR p_modify = 'X'.
IF ls_fieldcat-fieldname = 'ZWWCHAN_KH' OR
ls_fieldcat-fieldname = 'PRODH1' OR
ls_fieldcat-fieldname = 'PRODH3' OR
ls_fieldcat-fieldname = 'SALES_OFF' OR
ls_fieldcat-fieldname = 'CUSTOMER' OR
ls_fieldcat-fieldname = 'ZYDBZS'.
ls_fieldcat-edit = 'X'.
ENDIF.
* IF ls_fieldcat-fieldname = 'ZDP_C007'.
* ls_fieldcat-no_out = c_flg_on.
* ENDIF.
ENDIF.
MODIFY pt_fieldcat FROM ls_fieldcat.
CLEAR ls_fieldcat.
ENDLOOP.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'TXTSH'.
ls_fieldcat-coltext = '分公司名称' .
ls_fieldcat-outputlen = 12.
ls_fieldcat-col_pos = 2.
APPEND ls_fieldcat TO pt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'TXTSH_KH'.
ls_fieldcat-coltext = '考核旺旺渠道文本' .
ls_fieldcat-outputlen = 16.
ls_fieldcat-col_pos = 4.
ls_fieldcat-col_opt = 'X'.
APPEND ls_fieldcat TO pt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'TXTSH_SA'.
ls_fieldcat-coltext = '营业所描述' .
ls_fieldcat-outputlen = 16.
ls_fieldcat-col_pos = 8.
APPEND ls_fieldcat TO pt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'TXTMD'.
ls_fieldcat-coltext = '客户名称' .
ls_fieldcat-outputlen = 18.
ls_fieldcat-col_pos = 10.
APPEND ls_fieldcat TO pt_fieldcat.
SORT pt_fieldcat BY col_pos.
ENDFORM. " USEREXIT_FIELDCAT
*&---------------------------------------------------------------------*
*& Form FIELDCAT_INIT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GT_FIELDCAT[] text
*----------------------------------------------------------------------*
FORM fieldcat_init USING rt_fieldcat TYPE lvc_t_fcat.
ENDFORM. " FIELDCAT_INIT
*&---------------------------------------------------------------------*
*& Form SET_F4
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM set_f4 .
CLEAR gt_f4.
gs_f4-fieldname = 'PRODH1'.
gs_f4-register = 'X'.
gs_f4-getbefore = 'X'.
gs_f4-chngeafter = 'X'.
APPEND gs_f4 TO gt_f4.
CLEAR gs_f4.
gs_f4-fieldname = 'PRODH3'.
gs_f4-register = 'X'.
gs_f4-getbefore = 'X'.
gs_f4-chngeafter = 'X'.
APPEND gs_f4 TO gt_f4.
CLEAR gs_f4.
gs_f4-fieldname = 'SALES_OFF'.
gs_f4-register = 'X'.
gs_f4-getbefore = 'X'.
gs_f4-chngeafter = 'X'.
APPEND gs_f4 TO gt_f4.
CLEAR gs_f4.
gs_f4-fieldname = 'ZWWCHAN_KH'.
gs_f4-register = 'X'.
gs_f4-getbefore = 'X'.
gs_f4-chngeafter = 'X'.
APPEND gs_f4 TO gt_f4.
ENDFORM. " SET_F4
*&---------------------------------------------------------------------*
*& Form LOAD_DATA_INTO_GRID
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM load_data_into_grid .
CLEAR gt_data.
IF p_insert = 'X'.
SET TITLEBAR '100'.
PERFORM userexit_select_data_insert CHANGING gt_data.
ENDIF.
IF p_modify = 'X'.
SET TITLEBAR '101'.
PERFORM userexit_select_data_modify CHANGING gt_data.
ENDIF.
IF p_delete = 'X'.
SET TITLEBAR '102'.
* PERFORM userexit_select_data_delete CHANGING gt_data.
PERFORM userexit_select_data_display CHANGING gt_data.
ENDIF.
IF p_disp = 'X'.
SET TITLEBAR '103'.
PERFORM userexit_select_data_display CHANGING gt_data.
ENDIF.
ENDFORM. " LOAD_DATA_INTO_GRID
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM display_alv .
***排除不要的按钮
PERFORM exclude_tb_functions USING gt_exclude.
***展示数据
CALL METHOD gr_alvgrid->set_table_for_first_display
EXPORTING
is_variant = gs_variant
i_save = 'A'
is_layout = gs_layout
it_toolbar_excluding = gt_exclude
CHANGING
it_outtab = gt_data
it_fieldcatalog = gt_fieldcat
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
ENDFORM. " DISPLAY_ALV
*&---------------------------------------------------------------------*
*& Form USEREXIT_SELECT_DATA_INSERT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GT_DATA text
*----------------------------------------------------------------------*
FORM userexit_select_data_insert CHANGING pt_data LIKE gt_data.
CLEAR gs_data_wa.
* READ TABLE gt_chan_kh INTO gs_chan_kh WITH KEY zwwchan_kh = p_compy.
** READ TABLE i_dom_apstt INTO lv_wa_domtab WITH KEY domvalue_l = p_COMPY.
* IF sy-subrc = 0.
** gs_data_wa-txtsh_kh = lv_wa_domtab-ddtext.
* gs_data_wa-txtsh_kh = gs_chan_kh-txtsh_kh.
* ENDIF.
gs_data_wa-zww_compy = p_compy.
READ TABLE gt_compy INTO gs_compy WITH KEY /bic/zww_compy = gs_data_wa-zww_compy.
IF sy-subrc EQ 0.
gs_data_wa-txtsh = gs_compy-txtsh.
ENDIF.
* gs_data_wa-txtsh_kh = gs_chan_kh-txtsh_kh.
APPEND gs_data_wa TO gt_data.
CLEAR gs_data_wa.
ENDFORM. " USEREXIT_SELECT_DATA_INSERT
*&---------------------------------------------------------------------*
*& Form USEREXIT_SELECT_DATA_MODIFY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GT_DATA text
*----------------------------------------------------------------------*
FORM userexit_select_data_modify CHANGING pt_data LIKE gt_data.
DATA ls_data LIKE gs_data_wa.
SELECT * INTO CORRESPONDING FIELDS OF TABLE pt_data
FROM zbw_sdt005
WHERE zww_compy = p_compy
AND zwwchan_kh IN s_chan
AND sales_off IN s_sales
AND customer IN s_custom.
"获取分公司名称
SORT pt_data BY zww_compy.
SELECT /bic/zww_compy txtsh
FROM /bic/tzww_compy
INTO TABLE gt_compy
FOR ALL ENTRIES IN pt_data
WHERE /bic/zww_compy = pt_data-zww_compy.
"获取营业所描述
SORT pt_data BY sales_off.
SELECT sales_off
txtsh
FROM /bi0/tsales_off
INTO CORRESPONDING FIELDS OF TABLE gt_sales
FOR ALL ENTRIES IN pt_data
WHERE sales_off = pt_data-sales_off.
"获取客户名称
SORT pt_data BY customer.
SELECT customer
txtmd
FROM /bi0/tcustomer
INTO CORRESPONDING FIELDS OF TABLE gt_customer
FOR ALL ENTRIES IN pt_data
WHERE customer = pt_data-customer.
LOOP AT pt_data INTO ls_data.
"获取分公司名称
CLEAR gs_compy.
READ TABLE gt_compy INTO gs_compy WITH KEY /bic/zww_compy = ls_data-zww_compy.
IF sy-subrc EQ 0.
ls_data-txtsh = gs_compy-txtsh.
ENDIF.
"考核旺旺渠道名称
CLEAR gs_chan_kh.
READ TABLE gt_chan_kh INTO gs_chan_kh WITH KEY zwwchan_kh = ls_data-zwwchan_kh.
IF sy-subrc = 0.
ls_data-txtsh_kh = gs_chan_kh-txtsh_kh.
ENDIF.
"获取营业所描述
CLEAR gs_sales.
READ TABLE gt_sales INTO gs_sales WITH KEY sales_off = ls_data-sales_off.
IF sy-subrc = 0.
ls_data-txtsh_sa = gs_sales-txtsh.
ENDIF.
""获取客户名称
CLEAR gs_customer.
READ TABLE gt_customer INTO gs_customer WITH KEY customer = ls_data-customer.
IF sy-subrc EQ 0.
ls_data-txtmd = gs_customer-txtmd.
ENDIF.
MODIFY pt_data FROM ls_data.
ENDLOOP.
* DELETE ADJACENT DUPLICATES FROM pt_data COMPARING ALL FIELDS.
gt_data_old = gt_data.
ENDFORM. " USEREXIT_SELECT_DATA_MODIFY
*&---------------------------------------------------------------------*
*& Form USEREXIT_SELECT_DATA_DELETE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GT_DATA text
*----------------------------------------------------------------------*
FORM userexit_select_data_delete CHANGING pt_data LIKE gt_data.
DATA ls_data LIKE gs_data_wa.
SELECT * INTO CORRESPONDING FIELDS OF TABLE pt_data
FROM zbw_sdt005
WHERE zwwchan_kh EQ p_compy.
SORT pt_data.
LOOP AT pt_data INTO ls_data.
CLEAR gs_chan_kh.
READ TABLE gt_chan_kh INTO gs_chan_kh WITH KEY zwwchan_kh = ls_data-zwwchan_kh.
* READ TABLE i_dom_apstt INTO lv_wa_domtab WITH KEY domvalue_l = ls_data-zwwchan_kh.
IF sy-subrc = 0.
ls_data-txtsh_kh = gs_chan_kh-txtsh_kh.
* ls_data-txtsh_kh = lv_wa_domtab-ddtext.
ENDIF.
MODIFY pt_data FROM ls_data TRANSPORTING txtsh_kh.
ENDLOOP.
ENDFORM. " USEREXIT_SELECT_DATA_DELETE
*&---------------------------------------------------------------------*
*& Form USEREXIT_SELECT_DATA_DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GT_DATA text
*----------------------------------------------------------------------*
FORM userexit_select_data_display CHANGING pt_data LIKE gt_data.
DATA ls_data LIKE gs_data_wa.
SELECT * INTO CORRESPONDING FIELDS OF TABLE pt_data
FROM zbw_sdt005
WHERE zww_compy = p_compy
AND zwwchan_kh IN s_chan
AND sales_off IN s_sales
AND customer IN s_custom.
"获取分公司名称
SORT pt_data BY zww_compy.
SELECT /bic/zww_compy txtsh
FROM /bic/tzww_compy
INTO TABLE gt_compy
FOR ALL ENTRIES IN pt_data
WHERE /bic/zww_compy = pt_data-zww_compy.
"获取营业所描述
SORT pt_data BY sales_off.
SELECT sales_off
txtsh
FROM /bi0/tsales_off
INTO CORRESPONDING FIELDS OF TABLE gt_sales
FOR ALL ENTRIES IN pt_data
WHERE sales_off = pt_data-sales_off
AND langu = '1'.
"获取客户名称
SORT pt_data BY customer.
SELECT customer
txtmd
FROM /bi0/tcustomer
INTO CORRESPONDING FIELDS OF TABLE gt_customer
FOR ALL ENTRIES IN pt_data
WHERE customer = pt_data-customer.
LOOP AT pt_data INTO ls_data.
"获取分公司名称
CLEAR gs_compy.
READ TABLE gt_compy INTO gs_compy WITH KEY /bic/zww_compy = ls_data-zww_compy.
IF sy-subrc EQ 0.
ls_data-txtsh = gs_compy-txtsh.
ENDIF.
"考核旺旺渠道名称
CLEAR gs_chan_kh.
READ TABLE gt_chan_kh INTO gs_chan_kh WITH KEY zwwchan_kh = ls_data-zwwchan_kh.
IF sy-subrc = 0.
ls_data-txtsh_kh = gs_chan_kh-txtsh_kh.
ENDIF.
"获取营业所描述
CLEAR gs_sales.
READ TABLE gt_sales INTO gs_sales WITH KEY sales_off = ls_data-sales_off.
IF sy-subrc = 0.
ls_data-txtsh_sa = gs_sales-txtsh.
ENDIF.
""获取客户名称
CLEAR gs_customer.
READ TABLE gt_customer INTO gs_customer WITH KEY customer = ls_data-customer.
IF sy-subrc EQ 0.
ls_data-txtmd = gs_customer-txtmd.
ENDIF.
MODIFY pt_data FROM ls_data.
ENDLOOP.
ENDFORM. " USEREXIT_SELECT_DATA_DISPLAY
*&---------------------------------------------------------------------*
*& Form GET_ZWWCHAN_KH
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_zwwchan_kh .
SELECT zwwchan_kh txtsh_kh
INTO TABLE gt_chan_kh
FROM zbw_sdt010
WHERE zwwchan_kh = p_compy.
IF sy-subrc NE 0 .
SELECT /bic/zwwchan AS zwwchan_kh
txtsh AS txtsh_kh
INTO TABLE gt_chan_kh
FROM /bic/tzwwchan
WHERE /bic/zwwchan = p_compy.
IF sy-subrc NE 0.
MESSAGE '考核旺旺渠道不存在' TYPE 'S' DISPLAY LIKE 'E'.
STOP.
ENDIF.
ENDIF.
*
* DATA:
* lv_return TYPE sy-subrc.
*
* IF i_dom_apstt IS INITIAL .
*
* CALL FUNCTION 'DD_DOMVALUES_GET'
* EXPORTING
* domname = 'ZWWCHAN_KH' "域名
* text = 'X'
* langu = sy-langu
* IMPORTING
* rc = lv_return
* TABLES
* dd07v_tab = i_dom_apstt
* EXCEPTIONS
* wrong_textflag = 1
* OTHERS = 2.
*
** LOOP at I_DOM_APSTT INTO
*
* ENDIF.
*
* READ TABLE i_dom_apstt INTO lv_wa_domtab WITH KEY domvalue_l = p_COMPY.
* IF sy-subrc NE 0.
* MESSAGE '考核旺旺渠道不存在' TYPE 'S' DISPLAY LIKE 'E'.
* STOP.
* ENDIF.
ENDFORM. " GET_ZWWCHAN_KH
*&---------------------------------------------------------------------*
*& Form EXCLUDE_TB_FUNCTIONS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GT_EXCLUDE text
*----------------------------------------------------------------------*
FORM exclude_tb_functions USING pt_exclude TYPE ui_functions.
DATA ls_exclude TYPE ui_func.
ls_exclude = cl_gui_alv_grid=>mc_fc_current_variant.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_save_variant.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_average.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_load_variant.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_minimum.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_maximum.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_maintain_variant.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_views.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_graph.
APPEND ls_exclude TO pt_exclude.
* ls_exclude = cl_gui_alv_grid=>mc_fc_sum.
* APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_subtot.
APPEND ls_exclude TO pt_exclude.
* ls_exclude = cl_gui_alv_grid=>mc_fc_filter.
* APPEND ls_exclude TO pt_exclude.
* ls_exclude = cl_gui_alv_grid=>mc_fc_sort_dsc.
* APPEND ls_exclude TO pt_exclude.
* ls_exclude = cl_gui_alv_grid=>mc_fc_sort_asc.
* APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_check.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_detail.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_refresh.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_move_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_cut.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_undo.
APPEND ls_exclude TO pt_exclude.
IF p_insert <> 'X' .
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
APPEND ls_exclude TO pt_exclude.
ELSE.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.
APPEND ls_exclude TO pt_exclude.
* ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy.
* APPEND ls_exclude TO pt_exclude.
* ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.
* APPEND ls_exclude TO pt_exclude.
* ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.
* APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
APPEND ls_exclude TO pt_exclude.
ENDIF.
ENDFORM. " EXCLUDE_TB_FUNCTIONS
*&---------------------------------------------------------------------*
*& Form INSERT_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM insert_data .
DATA: l_isucc TYPE i VALUE 0, "成功操作的记录
l_iserror TYPE c, "行信息错误指示
l_tabix LIKE sy-tabix, "行号
ls_data_wa LIKE gs_data_wa,
lt_data_old LIKE TABLE OF gs_data_wa.
REFRESH gt_index_rows. " 用以存放要选择行的内表
LOOP AT gt_data INTO gs_data_wa WHERE flag = 'X'.
l_tabix = sy-tabix.
* 验证行数据正确性、手工添加部分信息
PERFORM userexit_check_row_data CHANGING gs_data_wa
l_tabix l_iserror gs_data_wa-rowmsg.
IF l_iserror = 'X'."判断行信息是否有错误
CLEAR gs_index_rows.
gs_index_rows-index = l_tabix.
APPEND gs_index_rows TO gt_index_rows. "有错误则把当前行号存入GT_index_Rows,用来选择错误行
ELSE.
*验证行数据在数据库中是否存在
PERFORM userexit_check_data_row_exist USING gs_data_wa
CHANGING l_iserror gs_data_wa-rowmsg.
IF l_iserror = 'X'."存在则把当前行号存入GT_index_Rows,用来选择错误行
CLEAR gs_index_rows.
gs_index_rows-index = l_tabix.
APPEND gs_index_rows TO gt_index_rows.
ELSE."插入数据
CLEAR gs_db.
* gs_data_wa-zdp_c006 = sy-uname. "创建者
* gs_data_wa-zdate = sy-datum. "创建日期
MOVE-CORRESPONDING gs_data_wa TO gs_db.
MODIFY (g_tabname) FROM gs_db.
COMMIT WORK AND WAIT.
gs_data_wa-rowmsg = text-005. "插入成功
l_isucc = l_isucc + 1.
ENDIF.
ENDIF.
MODIFY gt_data FROM gs_data_wa."更新操作结果信息
ENDLOOP.
PERFORM display_message USING l_isucc gt_index_rows '添加'."显示操作成功信息,并判断是否有非法数据
ENDFORM. " INSERT_DATA
*&---------------------------------------------------------------------*
*& Form DELETE_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM delete_data .
DATA: l_isucc TYPE i VALUE 0, "成功操作的条数
l_iserror TYPE c, "行信息错误指示
l_tabix LIKE sy-tabix, "行号
ls_data_old LIKE gs_data_wa, "原数据表工作区
ls_sdt006 TYPE zbw_sdt005,
l_isequal TYPE c. "原行与新行主键相同指示
LOOP AT gt_data INTO gs_data_wa WHERE flag = 'X'.
CLEAR gs_db.
l_tabix = sy-tabix.
SELECT SINGLE *
FROM zbw_sdt005
INTO gs_db
WHERE zww_compy = gs_data_wa-zww_compy
AND zwwchan_kh = gs_data_wa-zwwchan_kh
AND prodh1 = gs_data_wa-prodh1
AND prodh3 = gs_data_wa-prodh3
AND sales_off = gs_data_wa-sales_off
AND customer = gs_data_wa-customer.
* SELECT zwwchan_kh
* FROM ZBW_SDT005
* INTO l_zdp_c003
* WHERE zdp_c003 = gs_data_wa-zdp_c003
* AND zdp_c004 = gs_data_wa-zdp_c004
* AND zdp_c005 = gs_data_wa-zdp_c005.
* EXIT.
* ENDSELECT.
IF sy-subrc = 0.
DELETE (g_tabname) FROM gs_db.
COMMIT WORK AND WAIT.
gs_data_wa-rowmsg = text-003. "删除成功
CLEAR gs_index_rows.
gs_index_rows-index = l_tabix.
APPEND gs_index_rows TO gt_index_rows."有错误则把当前行号存入GT_index_Rows,用来选择错误行
ELSE.
* MOVE-CORRESPONDING gs_data_wa TO gs_db.
* MODIFY (g_tabname) FROM gs_db.
* COMMIT WORK AND WAIT.
gs_data_wa-rowmsg = text-004. "删除成功
l_isucc = l_isucc + 1.
ENDIF.
MODIFY gt_data FROM gs_data_wa.
ENDLOOP.
gt_data_old = gt_data."把新表数据放入gt_data_old中
*显示操作成功信息,并判断是否有非法数据
PERFORM display_message USING l_isucc gt_index_rows '删除'.
ENDFORM. " DELETE_DATA
*&---------------------------------------------------------------------*
*& Form MODIFY_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM modify_data .
DATA: l_isucc TYPE i VALUE 0, "成功操作的条数
l_iserror TYPE c, "行信息错误指示
l_tabix LIKE sy-tabix, "行号
ls_data_old LIKE gs_data_wa, "原数据表工作取
l_isequal TYPE c. "原行与新行主键相同指示
LOOP AT gt_data INTO gs_data_wa WHERE flag = 'X'.
CLEAR gs_db.
l_tabix = sy-tabix.
*验证行数据正确性、手工添加部分信息
PERFORM userexit_check_row_data CHANGING gs_data_wa
l_tabix l_iserror gs_data_wa-rowmsg.
IF l_iserror = 'X'."判断行信息是否有错误
CLEAR gs_index_rows.
gs_index_rows-index = l_tabix.
APPEND gs_index_rows TO gt_index_rows."有错误则把当前行号存入GT_index_Rows,用来选择错误行
ELSE.
*验证当前行与原行数据主键是否相同
READ TABLE gt_data_old INDEX l_tabix INTO ls_data_old.
PERFORM userexit_compare_key_equal USING gs_data_wa ls_data_old CHANGING l_isequal.
IF l_isequal = 'X'."主键相同则直接更新
* gs_data_wa-zdp_c006 = sy-uname.
* gs_data_wa-zdate = sy-datum.
MOVE-CORRESPONDING gs_data_wa TO gs_db.
MODIFY (g_tabname) FROM gs_db.
l_isucc = l_isucc + 1.
gs_data_wa-rowmsg = text-006.
COMMIT WORK AND WAIT."提交数据库操作
ELSE."主键不相同,则判断新行数据主键在数据库中是否存在
MOVE-CORRESPONDING gs_data_wa TO gs_db.
PERFORM userexit_check_data_row_exist USING gs_data_wa
CHANGING l_iserror ls_data_old-rowmsg. "不需要返回错误信息,故放入ls_data_old中
IF l_iserror = 'X'."存在,则修改数据
* gs_data_wa-zdp_c006 = sy-uname.
* gs_data_wa-zdate = sy-datum.
MODIFY (g_tabname) FROM gs_db.
l_isucc = l_isucc + 1.
gs_data_wa-rowmsg = text-006.
ELSE."不存在,则新建数据
* gs_data_wa-zdp_c006 = sy-uname.
* gs_data_wa-zdate = sy-datum.
INSERT (g_tabname) FROM gs_db.
l_isucc = l_isucc + 1.
gs_data_wa-rowmsg = text-005.
ENDIF.
CLEAR gs_db.
MOVE-CORRESPONDING ls_data_old TO gs_db.
DELETE (g_tabname) FROM gs_db."删除原行数据
COMMIT WORK AND WAIT."提交数据库操作
ENDIF.
ENDIF.
MODIFY gt_data FROM gs_data_wa.
ENDLOOP.
gt_data_old = gt_data."把新表数据放入gt_data_old中
*显示操作成功信息,并判断是否有非法数据
PERFORM display_message USING l_isucc gt_index_rows '修改'.
ENDFORM. " MODIFY_DATA
*&---------------------------------------------------------------------*
*& Form USEREXIT_CHECK_ROW_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GS_DATA_WA text
* <--P_L_TABIX text
* <--P_L_ISERROR text
* <--P_GS_DATA_WA_ROWMSG text
*----------------------------------------------------------------------*
FORM userexit_check_row_data CHANGING p_datarow LIKE gs_data_wa
p_index TYPE i
pf_error TYPE c
p_errmsg TYPE c.
CLEAR: pf_error, p_errmsg.
DATA: l_db_wa TYPE t_db,
l_msg(50) TYPE c,
l_row(10) TYPE c,
lt_doname TYPE TABLE OF dd07v,
lt_old_data LIKE TABLE OF gs_data_wa.
data: l_prodh1 type char20,
l_prodh3 type char20.
l_row = p_index.
MOVE-CORRESPONDING p_datarow TO l_db_wa.
CLEAR lt_old_data.
"检查必输字段是否已输
IF l_db_wa-zww_compy IS INITIAL.
p_errmsg = '旺旺销售公司不能为空'.
pf_error = 'X'.
RETURN.
ENDIF.
IF l_db_wa-zwwchan_kh IS INITIAL.
p_errmsg = '考核旺旺渠道不能为空'.
pf_error = 'X'.
RETURN.
ENDIF.
* IF l_db_wa-prodh1 IS INITIAL.
* p_errmsg = '事业部不能为空'.
* pf_error = 'X'.
* RETURN.
* ENDIF.
* IF l_db_wa-prodh3 IS INITIAL.
* p_errmsg = '产品线不能为空'.
* pf_error = 'X'.
* RETURN.
* ENDIF.
IF l_db_wa-sales_off IS INITIAL.
p_errmsg = '营业所不能为空'.
pf_error = 'X'.
RETURN.
ENDIF.
IF l_db_wa-customer IS INITIAL.
p_errmsg = '负责客户不能为空'.
pf_error = 'X'.
RETURN.
ENDIF.
IF l_db_wa-zydbzs IS INITIAL.
p_errmsg = ' 业代编制数不能为空'.
pf_error = 'X'.
RETURN.
ENDIF.
IF p_datarow-txtsh_kh CS '县城'.
IF p_datarow-prodh1 EQ space.
p_errmsg = '当旺旺渠道为县城时,字段“事业部”为必输'.
pf_error = 'X'.
RETURN.
ENDIF.
IF p_datarow-prodh3 NE space.
p_errmsg = '当旺旺渠道为县城时,字段“产品线”必须为空'.
pf_error = 'X'.
RETURN.
ENDIF.
ENDIF.
IF p_datarow-txtsh_kh CS '乳品'.
IF p_datarow-prodh3 EQ space.
p_errmsg = '当旺旺渠道为乳品时,字段“产品线”为必输'.
pf_error = 'X'.
RETURN.
ENDIF.
IF p_datarow-prodh1 NE space.
p_errmsg = '当旺旺渠道为乳品时,字段“事业部”必须为空'.
pf_error = 'X'.
RETURN.
ENDIF.
ENDIF.
DATA: ls_tzwwchan TYPE /bic/tzwwchan,
ls_tprod_hier TYPE /bi0/tprod_hier.
READ TABLE gt_chan_kh TRANSPORTING NO FIELDS WITH KEY zwwchan_kh = p_datarow-zwwchan_kh.
IF sy-subrc NE 0.
pf_error = 'X'.
p_errmsg = '考核旺旺渠道不存在,请检查数据!' .
RETURN.
ENDIF.
IF p_datarow-prodh1 IS NOT INITIAL.
IF strlen( p_datarow-prodh1 ) NE 3.
pf_error = 'X'.
p_errmsg = '事业部有误,请检查数据!' .
RETURN.
ELSE.
* CONCATENATE p_datarow-prodh1 '%' INTO l_prodh1.
* TRANSFER p_datarow-prodh1 TO UPPER CASE
SELECT SINGLE *
INTO ls_tprod_hier
FROM /bi0/tprod_hier
WHERE prod_hier = p_datarow-prodh1.
IF sy-subrc NE 0.
pf_error = 'X'.
p_errmsg = '事业部不存在,请检查数据!' .
RETURN.
ENDIF.
ENDIF.
ENDIF.
IF p_datarow-prodh3 IS NOT INITIAL.
IF strlen( p_datarow-prodh3 ) NE 9.
pf_error = 'X'.
p_errmsg = '产品线有误,请检查数据!' .
RETURN.
ELSE.
* CONCATENATE p_datarow-prodh3 '%' INTO l_prodh3.
SELECT SINGLE *
INTO ls_tprod_hier
FROM /bi0/tprod_hier
WHERE prod_hier = p_datarow-prodh3 .
IF sy-subrc NE 0.
pf_error = 'X'.
p_errmsg = '产品线不存在,请检查数据!' .
RETURN.
ENDIF.
ENDIF.
ENDIF.
ENDFORM. " USEREXIT_CHECK_ROW_DATA
*&---------------------------------------------------------------------*
*& Form USEREXIT_CHECK_DATA_ROW_EXIST
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GS_DATA_WA text
* <--P_L_ISERROR text
* <--P_GS_DATA_WA_ROWMSG text
*----------------------------------------------------------------------*
FORM userexit_check_data_row_exist USING p_datarow LIKE gs_data_wa
CHANGING pf_error TYPE c
p_errmsg TYPE c.
CLEAR: pf_error, p_errmsg.
DATA l_db_wa TYPE t_db.
SELECT SINGLE * FROM (g_tabname) INTO l_db_wa
WHERE zww_compy = p_datarow-zww_compy
AND zwwchan_kh = p_datarow-zwwchan_kh
AND prodh1 = p_datarow-prodh1
AND prodh3 = p_datarow-prodh3
AND sales_off = p_datarow-sales_off
AND customer = p_datarow-customer.
IF sy-subrc = 0.
pf_error = 'X'.
p_errmsg = '数据已经存在'.
ENDIF.
ENDFORM. " USEREXIT_CHECK_DATA_ROW_EXIST
*&---------------------------------------------------------------------*
*& Form DISPLAY_MESSAGE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_L_ISUCC text
* -->P_GT_INDEX_ROWS text
* -->P_0953 text
*----------------------------------------------------------------------*
FORM display_message USING p_succ TYPE i
pt_index_rows TYPE lvc_t_row
p_type TYPE c.
DATA: l_succ TYPE string,
l_rows_i TYPE i,
l_rows(10) TYPE c,
l_msg(70) TYPE c.
* CALL METHOD gr_alvgrid->refresh_table_display.
l_succ = p_succ.
DESCRIBE TABLE pt_index_rows LINES l_rows_i."统计错误行数
IF l_rows_i IS INITIAL.
CONCATENATE '成功' p_type '了' l_succ '条记录' INTO l_msg.
ELSE.
l_rows = l_rows_i.
CONCATENATE '成功' p_type '了' l_succ '条记录,高亮行数据不正确' INTO l_msg.
gf_error = 'X'."设置信息表示有错误行
ENDIF.
MESSAGE l_msg TYPE 'S'.
ENDFORM. " DISPLAY_MESSAGE
*&---------------------------------------------------------------------*
*& Form USEREXIT_COMPARE_KEY_EQUAL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GS_DATA_WA text
* -->P_LS_DATA_OLD text
* <--P_L_ISEQUAL text
*----------------------------------------------------------------------*
FORM userexit_compare_key_equal USING ps_datarow1 LIKE gs_data_wa
ps_datarow2 LIKE gs_data_wa
CHANGING isequal TYPE c.
IF ps_datarow1-zww_compy = ps_datarow2-zww_compy
AND ps_datarow1-zwwchan_kh = ps_datarow2-zwwchan_kh
AND ps_datarow1-prodh1 = ps_datarow2-prodh1
AND ps_datarow1-prodh3 = ps_datarow2-prodh3
AND ps_datarow1-sales_off = ps_datarow2-sales_off
AND ps_datarow1-customer = ps_datarow2-customer.
isequal = 'X'.
ENDIF.
ENDFORM. " USEREXIT_COMPARE_KEY_EQUAL
*&---------------------------------------------------------------------*
*& Form GET_CHAN
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_chan .
CLEAR gt_chan_kh.
SELECT zwwchan_kh txtsh_kh
INTO TABLE gt_chan_kh
FROM zbw_sdt010.
IF sy-subrc NE 0 .
ENDIF.
SELECT /bic/zwwchan AS zwwchan_kh
txtsh AS txtsh_kh
APPENDING TABLE gt_chan_kh
FROM /bic/tzwwchan.
SORT gt_chan_kh BY zwwchan_kh.
DELETE ADJACENT DUPLICATES FROM gt_chan_kh.
* CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
* EXPORTING
* retfield = 'ZWWCHAN_KH'
* dynpprog = sy-repid
* dynpnr = sy-dynnr
* dynprofield = 'p_COMPY'
* value_org = 'S'
* TABLES
* value_tab = gt_chan_kh.
ENDFORM. " GET_CHAN
*&---------------------------------------------------------------------*
*& Form GET_COMPY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_compy .
IF p_compy IS INITIAL .
MESSAGE '分公司必输' TYPE 'S' DISPLAY LIKE 'E'.
STOP.
ENDIF.
SELECT /bic/zww_compy txtsh
FROM /bic/tzww_compy
INTO TABLE gt_compy
WHERE /bic/zww_compy = p_compy.
IF sy-subrc NE 0.
MESSAGE '分公司不存在' TYPE 'S' DISPLAY LIKE 'E'.
STOP.
ENDIF.
ENDFORM. " GET_COMPY
*&---------------------------------------------------------------------*
*& Form GET_OTHER_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_other_data .
IF p_chan IS NOT INITIAL .
s_chan_st-sign = 'I'.
s_chan_st-option = 'BT'.
s_chan_st-low = p_chan.
APPEND s_chan_st TO s_chan.
ENDIF.
IF p_sales IS NOT INITIAL .
s_sales_st-sign = 'I'.
s_sales_st-option = 'BT'.
s_sales_st-low = p_sales.
APPEND s_sales_st TO s_sales.
ENDIF.
ENDFORM. " GET_OTHER_DATA
*&---------------------------------------------------------------------*
*& Form GET_COMPY_F4
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_compy_f4 .
DATA: lt_compy TYPE STANDARD TABLE OF /bic/tzww_compy,
ls_compy TYPE /bic/tzww_compy.
SELECT /bic/zww_compy txtsh
FROM /bic/tzww_compy
INTO TABLE lt_compy.
DELETE ADJACENT DUPLICATES FROM lt_compy.
SORT lt_compy BY /bic/zww_compy.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = '/BIC/ZWW_COMPY'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'P_COMPY'
value_org = 'S'
TABLES
value_tab = lt_compy.
ENDFORM. " GET_COMPY_F4
*&---------------------------------------------------------------------*
*& Form GET_SALES_F4
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_sales_f4 .
DATA: lt_sales TYPE STANDARD TABLE OF /bi0/tsales_off,
ls_sales TYPE /bi0/tsales_off.
* "获取营业所描述
* SELECT sales_off
* txtsh
* FROM /bi0/tsales_off
* INTO CORRESPONDING FIELDS OF TABLE lt_sales
* WHERE LANGU = '1'.
**&---------------------------------------------------------------------*
*& 包含 ZBWT006_PG_F01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form FRM_MODIFY_SCREEN
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_modify_screen .
LOOP AT SCREEN.
IF p_insert EQ c_flg_on .
IF screen-group1 = 'Z01'.
screen-active = 0.
ENDIF.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
ENDFORM. " FRM_MODIFY_SCREEN
*&---------------------------------------------------------------------*
*& Form F4
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_E_FIELDNAME text
* -->P_ES_ROW_NO text
* -->P_ER_EVENT_DATA text
*----------------------------------------------------------------------*
FORM f4 USING r_fieldname TYPE lvc_fname
rs_row_no TYPE lvc_s_roid
rr_event_data TYPE REF TO cl_alv_event_data.
FIELD-SYMBOLS: <lt_f4> TYPE lvc_t_modi.
DATA: BEGIN OF lt_t001 OCCURS 0 ,
zdp_c001 TYPE zbwt001-zdp_c001, "指标类别代码
zdp_n001 TYPE zbwt001-zdp_n001, "指标类别描述
END OF lt_t001.
DATA: ls_f4 TYPE lvc_s_modi,
ls_t001 LIKE LINE OF lt_t001,
l_fieldname TYPE dfies-fieldname.
DATA:lt_t002 TYPE TABLE OF zbwt002 WITH HEADER LINE.
DATA ls_zprodh1_f4 LIKE LINE OF gt_zprodh1_f4.
DATA ls_zprodh3_f4 LIKE LINE OF gt_zprodh3_f4.
* 当部门使用F4帮助的时候
IF r_fieldname = 'ZWWCHAN_KH'.
g_reffield = r_fieldname.
CLEAR gt_chan_kh.
SELECT zwwchan_kh txtsh_kh
INTO TABLE gt_chan_kh
FROM zbw_sdt010.
* IF sy-subrc NE 0 .
SELECT /bic/zwwchan AS zwwchan_kh
txtsh AS txtsh_kh
APPENDING TABLE gt_chan_kh
FROM /bic/tzwwchan.
* IF sy-subrc NE 0.
** MESSAGE '考核旺旺渠道不正确!' TYPE 'S' DISPLAY LIKE 'E'.
* EXIT.
* ENDIF.
* ENDIF.
SORT gt_chan_kh BY zwwchan_kh.
DELETE ADJACENT DUPLICATES FROM gt_chan_kh.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'ZWWCHAN_KH'
dynpprog = sy-repid
dynpnr = sy-dynnr
* dynprofield = 'P_COMPY'
value_org = 'S'
TABLES
value_tab = gt_chan_kh[]
return_tab = return_tab. "选中的内容
ASSIGN rr_event_data->m_data->* TO <lt_f4>.
ls_f4-fieldname = r_fieldname.
ls_f4-row_id = rs_row_no-row_id.
IF NOT return_tab IS INITIAL .
ls_f4-value = return_tab-fieldval .
APPEND ls_f4 TO <lt_f4>.
ENDIF .
ENDIF.
IF r_fieldname = 'SALES_OFF'.
g_reffield = r_fieldname.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'SALES_OFF'
dynpprog = sy-repid
dynpnr = sy-dynnr
* dynprofield = 'P_COMPY'
value_org = 'S'
TABLES
value_tab = gt_sales_dec[]
return_tab = return_tab. "选中的内容
ASSIGN rr_event_data->m_data->* TO <lt_f4>.
ls_f4-fieldname = r_fieldname.
ls_f4-row_id = rs_row_no-row_id.
IF NOT return_tab IS INITIAL .
ls_f4-value = return_tab-fieldval .
APPEND ls_f4 TO <lt_f4>.
ENDIF .
ENDIF.
IF r_fieldname = 'PRODH1'.
g_reffield = r_fieldname.
IF gt_zprodh1_f4 IS INITIAL."如果搜索帮助表为空,才从数据库读取数据,以节省资源
SELECT prod_hier txtlg FROM /bi0/tprod_hier
INTO CORRESPONDING FIELDS OF TABLE gt_zprodh1_f4
WHERE prod_hier LIKE 'D%' .
ENDIF.
LOOP AT gt_zprodh1_f4 INTO ls_zprodh1_f4 ."只保留三位
IF strlen( ls_zprodh1_f4-prod_hier ) NE 3.
DELETE gt_zprodh1_f4 INDEX sy-tabix.
ENDIF.
ENDLOOP.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'PROD_HIER'
dynpprog = sy-repid
dynpnr = sy-dynnr
* dynprofield = 'P_COMPY'
value_org = 'S'
TABLES
value_tab = gt_zprodh1_f4[]
return_tab = return_tab. "选中的内容
ASSIGN rr_event_data->m_data->* TO <lt_f4>.
ls_f4-fieldname = r_fieldname.
ls_f4-row_id = rs_row_no-row_id.
IF NOT return_tab IS INITIAL .
ls_f4-value = return_tab-fieldval .
APPEND ls_f4 TO <lt_f4>.
ENDIF .
ENDIF.
IF r_fieldname = 'PRODH3'.
g_reffield = r_fieldname.
IF gt_zprodh3_f4 IS INITIAL."如果搜索帮助表为空,才从数据库读取数据,以节省资源
SELECT prod_hier txtlg FROM /bi0/tprod_hier
INTO CORRESPONDING FIELDS OF TABLE gt_zprodh3_f4
WHERE prod_hier LIKE 'D%' .
ENDIF.
LOOP AT gt_zprodh3_f4 INTO ls_zprodh3_f4 ."只保留九位
IF strlen( ls_zprodh3_f4-prod_hier ) NE 9.
DELETE gt_zprodh3_f4 INDEX sy-tabix.
ENDIF.
ENDLOOP.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'PROD_HIER'
dynpprog = sy-repid
dynpnr = sy-dynnr
* dynprofield = 'P_COMPY'
value_org = 'S'
TABLES
value_tab = gt_zprodh3_f4[]
return_tab = return_tab. "选中的内容
ASSIGN rr_event_data->m_data->* TO <lt_f4>.
ls_f4-fieldname = r_fieldname.
ls_f4-row_id = rs_row_no-row_id.
IF NOT return_tab IS INITIAL .
ls_f4-value = return_tab-fieldval .
APPEND ls_f4 TO <lt_f4>.
ENDIF .
ENDIF.
* 抑制标准的Search Help
rr_event_data->m_event_handled = 'X'.
ENDFORM. " F4
*&---------------------------------------------------------------------*
*& Form HANDLE_DATA_CHANGED
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_ER_DATA_CHANGED text
*----------------------------------------------------------------------*
FORM handle_data_changed USING ir_data_changed
TYPE REF TO cl_alv_changed_data_protocol.
DATA: ls_mod_cell TYPE lvc_s_modi,
lv_value TYPE lvc_value.
LOOP AT ir_data_changed->mt_mod_cells
INTO ls_mod_cell.
IF ls_mod_cell-fieldname = 'ZWWCHAN_KH'.
CALL METHOD ir_data_changed->get_cell_value
EXPORTING
i_row_id = ls_mod_cell-row_id
i_fieldname = 'ZWWCHAN_KH'
IMPORTING
e_value = lv_value.
IF lv_value IS NOT INITIAL.
CLEAR gs_chan_kh.
READ TABLE gt_chan_kh INTO gs_chan_kh WITH KEY zwwchan_kh = lv_value.
IF sy-subrc EQ 0.
CALL METHOD ir_data_changed->modify_cell "修改单元格的值的方法
EXPORTING
i_row_id = ls_mod_cell-row_id "单元格的id
i_fieldname = 'TXTSH_KH' "单元格的字段
i_value = gs_chan_kh-txtsh_kh.
ELSE.
CALL METHOD ir_data_changed->modify_cell "修改单元格的值的方法
EXPORTING
i_row_id = ls_mod_cell-row_id "单元格的id
i_fieldname = 'TXTSH_KH' "单元格的字段
i_value = ''.
MESSAGE '考核旺旺渠道不存在' TYPE 'S' DISPLAY LIKE 'E'.
EXIT.
ENDIF.
ELSE.
CALL METHOD ir_data_changed->modify_cell "修改单元格的值的方法
EXPORTING
i_row_id = ls_mod_cell-row_id "单元格的id
i_fieldname = 'TXTSH_KH' "单元格的字段
i_value = ''.
ENDIF.
ENDIF.
IF ls_mod_cell-fieldname = 'ZWW_COMPY'.
CALL METHOD ir_data_changed->get_cell_value
EXPORTING
i_row_id = ls_mod_cell-row_id
i_fieldname = 'ZWW_COMPY'
IMPORTING
e_value = lv_value.
IF lv_value IS INITIAL.
CALL METHOD ir_data_changed->modify_cell "修改单元格的值的方法
EXPORTING
i_row_id = ls_mod_cell-row_id "单元格的id
i_fieldname = 'ZWW_COMPY' "单元格的字段
i_value = p_compy.
CLEAR gs_compy.
READ TABLE gt_compy INTO gs_compy WITH KEY /bic/zww_compy = p_compy.
CALL METHOD ir_data_changed->modify_cell "修改单元格的值的方法
EXPORTING
i_row_id = ls_mod_cell-row_id "单元格的id
i_fieldname = 'TXTSH' "单元格的字段
i_value = gs_compy-txtsh.
ENDIF.
ENDIF.
IF ls_mod_cell-fieldname = 'SALES_OFF'.
CALL METHOD ir_data_changed->get_cell_value
EXPORTING
i_row_id = ls_mod_cell-row_id
i_fieldname = 'SALES_OFF'
IMPORTING
e_value = lv_value.
IF lv_value IS NOT INITIAL.
CLEAR gs_chan_kh.
* READ TABLE gt_chan_kh INTO gs_chan_kh WITH KEY zwwchan_kh = lv_value.
DATA: l_text TYPE char20 .
SELECT SINGLE txtsh
FROM /bi0/tsales_off
INTO l_text
WHERE sales_off = lv_value.
IF sy-subrc EQ 0.
CALL METHOD ir_data_changed->modify_cell "修改单元格的值的方法
EXPORTING
i_row_id = ls_mod_cell-row_id "单元格的id
i_fieldname = 'TXTSH_SA' "单元格的字段
i_value = l_text.
ELSE.
CALL METHOD ir_data_changed->modify_cell "修改单元格的值的方法
EXPORTING
i_row_id = ls_mod_cell-row_id "单元格的id
i_fieldname = 'TXTSH_SA' "单元格的字段
i_value = ''.
MESSAGE '营业所不存在' TYPE 'S' DISPLAY LIKE 'E'.
EXIT.
ENDIF.
ELSE.
CALL METHOD ir_data_changed->modify_cell "修改单元格的值的方法
EXPORTING
i_row_id = ls_mod_cell-row_id "单元格的id
i_fieldname = 'TXTSH_SA' "单元格的字段
i_value = ''.
ENDIF.
ENDIF.
IF ls_mod_cell-fieldname = 'CUSTOMER'.
CALL METHOD ir_data_changed->get_cell_value
EXPORTING
i_row_id = ls_mod_cell-row_id
i_fieldname = 'CUSTOMER'
IMPORTING
e_value = lv_value.
IF lv_value IS NOT INITIAL.
CLEAR gs_chan_kh.
* READ TABLE gt_chan_kh INTO gs_chan_kh WITH KEY zwwchan_kh = lv_value.
* DATA: l_text TYPE char20 .
SELECT SINGLE txtmd
FROM /bi0/tcustomer
INTO l_text
WHERE customer = lv_value.
IF sy-subrc EQ 0.
CALL METHOD ir_data_changed->modify_cell "修改单元格的值的方法
EXPORTING
i_row_id = ls_mod_cell-row_id "单元格的id
i_fieldname = 'TXTMD' "单元格的字段
i_value = l_text.
ELSE.
CALL METHOD ir_data_changed->modify_cell "修改单元格的值的方法
EXPORTING
i_row_id = ls_mod_cell-row_id "单元格的id
i_fieldname = 'TXTMD' "单元格的字段
i_value = ''.
MESSAGE '客户不存在' TYPE 'S' DISPLAY LIKE 'E'.
EXIT.
ENDIF.
ELSE.
CALL METHOD ir_data_changed->modify_cell "修改单元格的值的方法
EXPORTING
i_row_id = ls_mod_cell-row_id "单元格的id
i_fieldname = 'TXTMD' "单元格的字段
i_value = ''.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM. " HANDLE_DATA_CHANGED
*&---------------------------------------------------------------------*
*& Form PREPARE_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GS_LAYOUT text
*----------------------------------------------------------------------*
FORM prepare_layout CHANGING ps_layout TYPE lvc_s_layo.
ps_layout-zebra = 'X' .
ps_layout-smalltitle = 'X' .
* ps_layout-cwidth_opt = 'X'.
ps_layout-no_toolbar = ' '.
IF p_disp = 'X' OR p_modify = 'X'.
ps_layout-no_rowmark = 'X'.
ENDIF.
ENDFORM. " PREPARE_LAYOUT
*&---------------------------------------------------------------------*
*& Form PREPARE_FIELD_CATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GT_FIELDCAT text
*----------------------------------------------------------------------*
FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat .
DATA: ls_fieldcat TYPE lvc_s_fcat,
l_rows TYPE i.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = g_tabname "表结构
i_client_never_display = 'X'
CHANGING
ct_fieldcat = pt_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_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.
*UserExit,用于自定义Field Catalog
PERFORM userexit_fieldcat CHANGING pt_fieldcat.
IF p_disp <> 'X'. "除了显示模式,其他模式都显示选择列和操作结果列
CLEAR ls_fieldcat .
ls_fieldcat-fieldname = 'FLAG' .
ls_fieldcat-coltext = '选择' .
ls_fieldcat-edit = 'X'.
ls_fieldcat-checkbox = 'X'.
ls_fieldcat-key = 'X'.
ls_fieldcat-outputlen = '6'.
ls_fieldcat-col_pos = 0.
APPEND ls_fieldcat TO pt_fieldcat .
CLEAR l_rows.
DESCRIBE TABLE pt_fieldcat LINES l_rows.
CLEAR ls_fieldcat .
ls_fieldcat-fieldname = 'ROWMSG' .
ls_fieldcat-coltext = '操作结果' .
ls_fieldcat-col_pos = l_rows.
ls_fieldcat-outputlen = '30'.
APPEND ls_fieldcat TO pt_fieldcat .
ENDIF.
ENDFORM. " PREPARE_FIELD_CATALOG
*&---------------------------------------------------------------------*
*& Form USEREXIT_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_PT_FIELDCAT text
*----------------------------------------------------------------------*
FORM userexit_fieldcat CHANGING pt_fieldcat TYPE lvc_t_fcat.
DATA: ls_fieldcat TYPE lvc_s_fcat.
DELETE pt_fieldcat WHERE fieldname = 'MANDT'.
LOOP AT pt_fieldcat INTO ls_fieldcat.
CASE ls_fieldcat-fieldname.
WHEN 'ZWW_COMPY'.
ls_fieldcat-coltext = '旺旺销售公司' .
ls_fieldcat-col_pos = 1.
ls_fieldcat-outputlen = 8.
ls_fieldcat-key = ''.
ls_fieldcat-ref_table = ''.
* ls_fieldcat-f4availabl = 'X'.
WHEN 'ZWWCHAN_KH'.
ls_fieldcat-coltext = '考核旺旺渠道' .
ls_fieldcat-col_pos = 3.
ls_fieldcat-outputlen = 12.
ls_fieldcat-f4availabl = 'X'.
ls_fieldcat-col_opt = 'X'.
WHEN 'PRODH1'.
ls_fieldcat-coltext = '事业部' .
ls_fieldcat-col_pos = 5.
ls_fieldcat-outputlen = 18.
ls_fieldcat-ref_table =' '. "F4帮助表设置
ls_fieldcat-ref_field =' '. "F4帮助字段设置
ls_fieldcat-f4availabl = 'X'.
WHEN 'PRODH3'.
ls_fieldcat-coltext = '产品线' .
ls_fieldcat-col_pos = 6.
ls_fieldcat-outputlen = 18.
ls_fieldcat-ref_table =' '. "F4帮助表设置
ls_fieldcat-ref_field =' '. "F4帮助字段设置
ls_fieldcat-f4availabl = 'X'.
WHEN 'SALES_OFF'.
ls_fieldcat-coltext = '营业所' .
ls_fieldcat-outputlen = 14.
ls_fieldcat-col_pos = 7.
ls_fieldcat-f4availabl = 'X'.
WHEN 'CUSTOMER'.
ls_fieldcat-coltext = '负责客户' .
ls_fieldcat-outputlen = 8.
ls_fieldcat-col_pos = 9.
WHEN 'ZYDBZS'.
ls_fieldcat-coltext = '业代编制数' .
ls_fieldcat-outputlen = 8.
ls_fieldcat-col_pos = 11.
* ls_fieldcat-f4availabl = 'X'.
ENDCASE.
IF p_insert = 'X' OR p_modify = 'X'.
IF ls_fieldcat-fieldname = 'ZWWCHAN_KH' OR
ls_fieldcat-fieldname = 'PRODH1' OR
ls_fieldcat-fieldname = 'PRODH3' OR
ls_fieldcat-fieldname = 'SALES_OFF' OR
ls_fieldcat-fieldname = 'CUSTOMER' OR
ls_fieldcat-fieldname = 'ZYDBZS'.
ls_fieldcat-edit = 'X'.
ENDIF.
* IF ls_fieldcat-fieldname = 'ZDP_C007'.
* ls_fieldcat-no_out = c_flg_on.
* ENDIF.
ENDIF.
MODIFY pt_fieldcat FROM ls_fieldcat.
CLEAR ls_fieldcat.
ENDLOOP.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'TXTSH'.
ls_fieldcat-coltext = '分公司名称' .
ls_fieldcat-outputlen = 12.
ls_fieldcat-col_pos = 2.
APPEND ls_fieldcat TO pt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'TXTSH_KH'.
ls_fieldcat-coltext = '考核旺旺渠道文本' .
ls_fieldcat-outputlen = 16.
ls_fieldcat-col_pos = 4.
ls_fieldcat-col_opt = 'X'.
APPEND ls_fieldcat TO pt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'TXTSH_SA'.
ls_fieldcat-coltext = '营业所描述' .
ls_fieldcat-outputlen = 16.
ls_fieldcat-col_pos = 8.
APPEND ls_fieldcat TO pt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'TXTMD'.
ls_fieldcat-coltext = '客户名称' .
ls_fieldcat-outputlen = 18.
ls_fieldcat-col_pos = 10.
APPEND ls_fieldcat TO pt_fieldcat.
SORT pt_fieldcat BY col_pos.
ENDFORM. " USEREXIT_FIELDCAT
*&---------------------------------------------------------------------*
*& Form FIELDCAT_INIT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GT_FIELDCAT[] text
*----------------------------------------------------------------------*
FORM fieldcat_init USING rt_fieldcat TYPE lvc_t_fcat.
ENDFORM. " FIELDCAT_INIT
*&---------------------------------------------------------------------*
*& Form SET_F4
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM set_f4 .
CLEAR gt_f4.
gs_f4-fieldname = 'PRODH1'.
gs_f4-register = 'X'.
gs_f4-getbefore = 'X'.
gs_f4-chngeafter = 'X'.
APPEND gs_f4 TO gt_f4.
CLEAR gs_f4.
gs_f4-fieldname = 'PRODH3'.
gs_f4-register = 'X'.
gs_f4-getbefore = 'X'.
gs_f4-chngeafter = 'X'.
APPEND gs_f4 TO gt_f4.
CLEAR gs_f4.
gs_f4-fieldname = 'SALES_OFF'.
gs_f4-register = 'X'.
gs_f4-getbefore = 'X'.
gs_f4-chngeafter = 'X'.
APPEND gs_f4 TO gt_f4.
CLEAR gs_f4.
gs_f4-fieldname = 'ZWWCHAN_KH'.
gs_f4-register = 'X'.
gs_f4-getbefore = 'X'.
gs_f4-chngeafter = 'X'.
APPEND gs_f4 TO gt_f4.
ENDFORM. " SET_F4
*&---------------------------------------------------------------------*
*& Form LOAD_DATA_INTO_GRID
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM load_data_into_grid .
CLEAR gt_data.
IF p_insert = 'X'.
SET TITLEBAR '100'.
PERFORM userexit_select_data_insert CHANGING gt_data.
ENDIF.
IF p_modify = 'X'.
SET TITLEBAR '101'.
PERFORM userexit_select_data_modify CHANGING gt_data.
ENDIF.
IF p_delete = 'X'.
SET TITLEBAR '102'.
* PERFORM userexit_select_data_delete CHANGING gt_data.
PERFORM userexit_select_data_display CHANGING gt_data.
ENDIF.
IF p_disp = 'X'.
SET TITLEBAR '103'.
PERFORM userexit_select_data_display CHANGING gt_data.
ENDIF.
ENDFORM. " LOAD_DATA_INTO_GRID
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM display_alv .
***排除不要的按钮
PERFORM exclude_tb_functions USING gt_exclude.
***展示数据
CALL METHOD gr_alvgrid->set_table_for_first_display
EXPORTING
is_variant = gs_variant
i_save = 'A'
is_layout = gs_layout
it_toolbar_excluding = gt_exclude
CHANGING
it_outtab = gt_data
it_fieldcatalog = gt_fieldcat
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
ENDFORM. " DISPLAY_ALV
*&---------------------------------------------------------------------*
*& Form USEREXIT_SELECT_DATA_INSERT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GT_DATA text
*----------------------------------------------------------------------*
FORM userexit_select_data_insert CHANGING pt_data LIKE gt_data.
CLEAR gs_data_wa.
* READ TABLE gt_chan_kh INTO gs_chan_kh WITH KEY zwwchan_kh = p_compy.
** READ TABLE i_dom_apstt INTO lv_wa_domtab WITH KEY domvalue_l = p_COMPY.
* IF sy-subrc = 0.
** gs_data_wa-txtsh_kh = lv_wa_domtab-ddtext.
* gs_data_wa-txtsh_kh = gs_chan_kh-txtsh_kh.
* ENDIF.
gs_data_wa-zww_compy = p_compy.
READ TABLE gt_compy INTO gs_compy WITH KEY /bic/zww_compy = gs_data_wa-zww_compy.
IF sy-subrc EQ 0.
gs_data_wa-txtsh = gs_compy-txtsh.
ENDIF.
* gs_data_wa-txtsh_kh = gs_chan_kh-txtsh_kh.
APPEND gs_data_wa TO gt_data.
CLEAR gs_data_wa.
ENDFORM. " USEREXIT_SELECT_DATA_INSERT
*&---------------------------------------------------------------------*
*& Form USEREXIT_SELECT_DATA_MODIFY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GT_DATA text
*----------------------------------------------------------------------*
FORM userexit_select_data_modify CHANGING pt_data LIKE gt_data.
DATA ls_data LIKE gs_data_wa.
SELECT * INTO CORRESPONDING FIELDS OF TABLE pt_data
FROM zbw_sdt005
WHERE zww_compy = p_compy
AND zwwchan_kh IN s_chan
AND sales_off IN s_sales
AND customer IN s_custom.
"获取分公司名称
SORT pt_data BY zww_compy.
SELECT /bic/zww_compy txtsh
FROM /bic/tzww_compy
INTO TABLE gt_compy
FOR ALL ENTRIES IN pt_data
WHERE /bic/zww_compy = pt_data-zww_compy.
"获取营业所描述
SORT pt_data BY sales_off.
SELECT sales_off
txtsh
FROM /bi0/tsales_off
INTO CORRESPONDING FIELDS OF TABLE gt_sales
FOR ALL ENTRIES IN pt_data
WHERE sales_off = pt_data-sales_off.
"获取客户名称
SORT pt_data BY customer.
SELECT customer
txtmd
FROM /bi0/tcustomer
INTO CORRESPONDING FIELDS OF TABLE gt_customer
FOR ALL ENTRIES IN pt_data
WHERE customer = pt_data-customer.
LOOP AT pt_data INTO ls_data.
"获取分公司名称
CLEAR gs_compy.
READ TABLE gt_compy INTO gs_compy WITH KEY /bic/zww_compy = ls_data-zww_compy.
IF sy-subrc EQ 0.
ls_data-txtsh = gs_compy-txtsh.
ENDIF.
"考核旺旺渠道名称
CLEAR gs_chan_kh.
READ TABLE gt_chan_kh INTO gs_chan_kh WITH KEY zwwchan_kh = ls_data-zwwchan_kh.
IF sy-subrc = 0.
ls_data-txtsh_kh = gs_chan_kh-txtsh_kh.
ENDIF.
"获取营业所描述
CLEAR gs_sales.
READ TABLE gt_sales INTO gs_sales WITH KEY sales_off = ls_data-sales_off.
IF sy-subrc = 0.
ls_data-txtsh_sa = gs_sales-txtsh.
ENDIF.
""获取客户名称
CLEAR gs_customer.
READ TABLE gt_customer INTO gs_customer WITH KEY customer = ls_data-customer.
IF sy-subrc EQ 0.
ls_data-txtmd = gs_customer-txtmd.
ENDIF.
MODIFY pt_data FROM ls_data.
ENDLOOP.
* DELETE ADJACENT DUPLICATES FROM pt_data COMPARING ALL FIELDS.
gt_data_old = gt_data.
ENDFORM. " USEREXIT_SELECT_DATA_MODIFY
*&---------------------------------------------------------------------*
*& Form USEREXIT_SELECT_DATA_DELETE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GT_DATA text
*----------------------------------------------------------------------*
FORM userexit_select_data_delete CHANGING pt_data LIKE gt_data.
DATA ls_data LIKE gs_data_wa.
SELECT * INTO CORRESPONDING FIELDS OF TABLE pt_data
FROM zbw_sdt005
WHERE zwwchan_kh EQ p_compy.
SORT pt_data.
LOOP AT pt_data INTO ls_data.
CLEAR gs_chan_kh.
READ TABLE gt_chan_kh INTO gs_chan_kh WITH KEY zwwchan_kh = ls_data-zwwchan_kh.
* READ TABLE i_dom_apstt INTO lv_wa_domtab WITH KEY domvalue_l = ls_data-zwwchan_kh.
IF sy-subrc = 0.
ls_data-txtsh_kh = gs_chan_kh-txtsh_kh.
* ls_data-txtsh_kh = lv_wa_domtab-ddtext.
ENDIF.
MODIFY pt_data FROM ls_data TRANSPORTING txtsh_kh.
ENDLOOP.
ENDFORM. " USEREXIT_SELECT_DATA_DELETE
*&---------------------------------------------------------------------*
*& Form USEREXIT_SELECT_DATA_DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GT_DATA text
*----------------------------------------------------------------------*
FORM userexit_select_data_display CHANGING pt_data LIKE gt_data.
DATA ls_data LIKE gs_data_wa.
SELECT * INTO CORRESPONDING FIELDS OF TABLE pt_data
FROM zbw_sdt005
WHERE zww_compy = p_compy
AND zwwchan_kh IN s_chan
AND sales_off IN s_sales
AND customer IN s_custom.
"获取分公司名称
SORT pt_data BY zww_compy.
SELECT /bic/zww_compy txtsh
FROM /bic/tzww_compy
INTO TABLE gt_compy
FOR ALL ENTRIES IN pt_data
WHERE /bic/zww_compy = pt_data-zww_compy.
"获取营业所描述
SORT pt_data BY sales_off.
SELECT sales_off
txtsh
FROM /bi0/tsales_off
INTO CORRESPONDING FIELDS OF TABLE gt_sales
FOR ALL ENTRIES IN pt_data
WHERE sales_off = pt_data-sales_off
AND langu = '1'.
"获取客户名称
SORT pt_data BY customer.
SELECT customer
txtmd
FROM /bi0/tcustomer
INTO CORRESPONDING FIELDS OF TABLE gt_customer
FOR ALL ENTRIES IN pt_data
WHERE customer = pt_data-customer.
LOOP AT pt_data INTO ls_data.
"获取分公司名称
CLEAR gs_compy.
READ TABLE gt_compy INTO gs_compy WITH KEY /bic/zww_compy = ls_data-zww_compy.
IF sy-subrc EQ 0.
ls_data-txtsh = gs_compy-txtsh.
ENDIF.
"考核旺旺渠道名称
CLEAR gs_chan_kh.
READ TABLE gt_chan_kh INTO gs_chan_kh WITH KEY zwwchan_kh = ls_data-zwwchan_kh.
IF sy-subrc = 0.
ls_data-txtsh_kh = gs_chan_kh-txtsh_kh.
ENDIF.
"获取营业所描述
CLEAR gs_sales.
READ TABLE gt_sales INTO gs_sales WITH KEY sales_off = ls_data-sales_off.
IF sy-subrc = 0.
ls_data-txtsh_sa = gs_sales-txtsh.
ENDIF.
""获取客户名称
CLEAR gs_customer.
READ TABLE gt_customer INTO gs_customer WITH KEY customer = ls_data-customer.
IF sy-subrc EQ 0.
ls_data-txtmd = gs_customer-txtmd.
ENDIF.
MODIFY pt_data FROM ls_data.
ENDLOOP.
ENDFORM. " USEREXIT_SELECT_DATA_DISPLAY
*&---------------------------------------------------------------------*
*& Form GET_ZWWCHAN_KH
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_zwwchan_kh .
SELECT zwwchan_kh txtsh_kh
INTO TABLE gt_chan_kh
FROM zbw_sdt010
WHERE zwwchan_kh = p_compy.
IF sy-subrc NE 0 .
SELECT /bic/zwwchan AS zwwchan_kh
txtsh AS txtsh_kh
INTO TABLE gt_chan_kh
FROM /bic/tzwwchan
WHERE /bic/zwwchan = p_compy.
IF sy-subrc NE 0.
MESSAGE '考核旺旺渠道不存在' TYPE 'S' DISPLAY LIKE 'E'.
STOP.
ENDIF.
ENDIF.
*
* DATA:
* lv_return TYPE sy-subrc.
*
* IF i_dom_apstt IS INITIAL .
*
* CALL FUNCTION 'DD_DOMVALUES_GET'
* EXPORTING
* domname = 'ZWWCHAN_KH' "域名
* text = 'X'
* langu = sy-langu
* IMPORTING
* rc = lv_return
* TABLES
* dd07v_tab = i_dom_apstt
* EXCEPTIONS
* wrong_textflag = 1
* OTHERS = 2.
*
** LOOP at I_DOM_APSTT INTO
*
* ENDIF.
*
* READ TABLE i_dom_apstt INTO lv_wa_domtab WITH KEY domvalue_l = p_COMPY.
* IF sy-subrc NE 0.
* MESSAGE '考核旺旺渠道不存在' TYPE 'S' DISPLAY LIKE 'E'.
* STOP.
* ENDIF.
ENDFORM. " GET_ZWWCHAN_KH
*&---------------------------------------------------------------------*
*& Form EXCLUDE_TB_FUNCTIONS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GT_EXCLUDE text
*----------------------------------------------------------------------*
FORM exclude_tb_functions USING pt_exclude TYPE ui_functions.
DATA ls_exclude TYPE ui_func.
ls_exclude = cl_gui_alv_grid=>mc_fc_current_variant.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_save_variant.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_average.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_load_variant.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_minimum.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_maximum.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_maintain_variant.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_views.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_graph.
APPEND ls_exclude TO pt_exclude.
* ls_exclude = cl_gui_alv_grid=>mc_fc_sum.
* APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_subtot.
APPEND ls_exclude TO pt_exclude.
* ls_exclude = cl_gui_alv_grid=>mc_fc_filter.
* APPEND ls_exclude TO pt_exclude.
* ls_exclude = cl_gui_alv_grid=>mc_fc_sort_dsc.
* APPEND ls_exclude TO pt_exclude.
* ls_exclude = cl_gui_alv_grid=>mc_fc_sort_asc.
* APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_check.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_detail.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_refresh.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_move_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_cut.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_undo.
APPEND ls_exclude TO pt_exclude.
IF p_insert <> 'X' .
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
APPEND ls_exclude TO pt_exclude.
ELSE.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.
APPEND ls_exclude TO pt_exclude.
* ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy.
* APPEND ls_exclude TO pt_exclude.
* ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.
* APPEND ls_exclude TO pt_exclude.
* ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.
* APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
APPEND ls_exclude TO pt_exclude.
ENDIF.
ENDFORM. " EXCLUDE_TB_FUNCTIONS
*&---------------------------------------------------------------------*
*& Form INSERT_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM insert_data .
DATA: l_isucc TYPE i VALUE 0, "成功操作的记录
l_iserror TYPE c, "行信息错误指示
l_tabix LIKE sy-tabix, "行号
ls_data_wa LIKE gs_data_wa,
lt_data_old LIKE TABLE OF gs_data_wa.
REFRESH gt_index_rows. " 用以存放要选择行的内表
LOOP AT gt_data INTO gs_data_wa WHERE flag = 'X'.
l_tabix = sy-tabix.
* 验证行数据正确性、手工添加部分信息
PERFORM userexit_check_row_data CHANGING gs_data_wa
l_tabix l_iserror gs_data_wa-rowmsg.
IF l_iserror = 'X'."判断行信息是否有错误
CLEAR gs_index_rows.
gs_index_rows-index = l_tabix.
APPEND gs_index_rows TO gt_index_rows. "有错误则把当前行号存入GT_index_Rows,用来选择错误行
ELSE.
*验证行数据在数据库中是否存在
PERFORM userexit_check_data_row_exist USING gs_data_wa
CHANGING l_iserror gs_data_wa-rowmsg.
IF l_iserror = 'X'."存在则把当前行号存入GT_index_Rows,用来选择错误行
CLEAR gs_index_rows.
gs_index_rows-index = l_tabix.
APPEND gs_index_rows TO gt_index_rows.
ELSE."插入数据
CLEAR gs_db.
* gs_data_wa-zdp_c006 = sy-uname. "创建者
* gs_data_wa-zdate = sy-datum. "创建日期
MOVE-CORRESPONDING gs_data_wa TO gs_db.
MODIFY (g_tabname) FROM gs_db.
COMMIT WORK AND WAIT.
gs_data_wa-rowmsg = text-005. "插入成功
l_isucc = l_isucc + 1.
ENDIF.
ENDIF.
MODIFY gt_data FROM gs_data_wa."更新操作结果信息
ENDLOOP.
PERFORM display_message USING l_isucc gt_index_rows '添加'."显示操作成功信息,并判断是否有非法数据
ENDFORM. " INSERT_DATA
*&---------------------------------------------------------------------*
*& Form DELETE_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM delete_data .
DATA: l_isucc TYPE i VALUE 0, "成功操作的条数
l_iserror TYPE c, "行信息错误指示
l_tabix LIKE sy-tabix, "行号
ls_data_old LIKE gs_data_wa, "原数据表工作区
ls_sdt006 TYPE zbw_sdt005,
l_isequal TYPE c. "原行与新行主键相同指示
LOOP AT gt_data INTO gs_data_wa WHERE flag = 'X'.
CLEAR gs_db.
l_tabix = sy-tabix.
SELECT SINGLE *
FROM zbw_sdt005
INTO gs_db
WHERE zww_compy = gs_data_wa-zww_compy
AND zwwchan_kh = gs_data_wa-zwwchan_kh
AND prodh1 = gs_data_wa-prodh1
AND prodh3 = gs_data_wa-prodh3
AND sales_off = gs_data_wa-sales_off
AND customer = gs_data_wa-customer.
* SELECT zwwchan_kh
* FROM ZBW_SDT005
* INTO l_zdp_c003
* WHERE zdp_c003 = gs_data_wa-zdp_c003
* AND zdp_c004 = gs_data_wa-zdp_c004
* AND zdp_c005 = gs_data_wa-zdp_c005.
* EXIT.
* ENDSELECT.
IF sy-subrc = 0.
DELETE (g_tabname) FROM gs_db.
COMMIT WORK AND WAIT.
gs_data_wa-rowmsg = text-003. "删除成功
CLEAR gs_index_rows.
gs_index_rows-index = l_tabix.
APPEND gs_index_rows TO gt_index_rows."有错误则把当前行号存入GT_index_Rows,用来选择错误行
ELSE.
* MOVE-CORRESPONDING gs_data_wa TO gs_db.
* MODIFY (g_tabname) FROM gs_db.
* COMMIT WORK AND WAIT.
gs_data_wa-rowmsg = text-004. "删除成功
l_isucc = l_isucc + 1.
ENDIF.
MODIFY gt_data FROM gs_data_wa.
ENDLOOP.
gt_data_old = gt_data."把新表数据放入gt_data_old中
*显示操作成功信息,并判断是否有非法数据
PERFORM display_message USING l_isucc gt_index_rows '删除'.
ENDFORM. " DELETE_DATA
*&---------------------------------------------------------------------*
*& Form MODIFY_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM modify_data .
DATA: l_isucc TYPE i VALUE 0, "成功操作的条数
l_iserror TYPE c, "行信息错误指示
l_tabix LIKE sy-tabix, "行号
ls_data_old LIKE gs_data_wa, "原数据表工作取
l_isequal TYPE c. "原行与新行主键相同指示
LOOP AT gt_data INTO gs_data_wa WHERE flag = 'X'.
CLEAR gs_db.
l_tabix = sy-tabix.
*验证行数据正确性、手工添加部分信息
PERFORM userexit_check_row_data CHANGING gs_data_wa
l_tabix l_iserror gs_data_wa-rowmsg.
IF l_iserror = 'X'."判断行信息是否有错误
CLEAR gs_index_rows.
gs_index_rows-index = l_tabix.
APPEND gs_index_rows TO gt_index_rows."有错误则把当前行号存入GT_index_Rows,用来选择错误行
ELSE.
*验证当前行与原行数据主键是否相同
READ TABLE gt_data_old INDEX l_tabix INTO ls_data_old.
PERFORM userexit_compare_key_equal USING gs_data_wa ls_data_old CHANGING l_isequal.
IF l_isequal = 'X'."主键相同则直接更新
* gs_data_wa-zdp_c006 = sy-uname.
* gs_data_wa-zdate = sy-datum.
MOVE-CORRESPONDING gs_data_wa TO gs_db.
MODIFY (g_tabname) FROM gs_db.
l_isucc = l_isucc + 1.
gs_data_wa-rowmsg = text-006.
COMMIT WORK AND WAIT."提交数据库操作
ELSE."主键不相同,则判断新行数据主键在数据库中是否存在
MOVE-CORRESPONDING gs_data_wa TO gs_db.
PERFORM userexit_check_data_row_exist USING gs_data_wa
CHANGING l_iserror ls_data_old-rowmsg. "不需要返回错误信息,故放入ls_data_old中
IF l_iserror = 'X'."存在,则修改数据
* gs_data_wa-zdp_c006 = sy-uname.
* gs_data_wa-zdate = sy-datum.
MODIFY (g_tabname) FROM gs_db.
l_isucc = l_isucc + 1.
gs_data_wa-rowmsg = text-006.
ELSE."不存在,则新建数据
* gs_data_wa-zdp_c006 = sy-uname.
* gs_data_wa-zdate = sy-datum.
INSERT (g_tabname) FROM gs_db.
l_isucc = l_isucc + 1.
gs_data_wa-rowmsg = text-005.
ENDIF.
CLEAR gs_db.
MOVE-CORRESPONDING ls_data_old TO gs_db.
DELETE (g_tabname) FROM gs_db."删除原行数据
COMMIT WORK AND WAIT."提交数据库操作
ENDIF.
ENDIF.
MODIFY gt_data FROM gs_data_wa.
ENDLOOP.
gt_data_old = gt_data."把新表数据放入gt_data_old中
*显示操作成功信息,并判断是否有非法数据
PERFORM display_message USING l_isucc gt_index_rows '修改'.
ENDFORM. " MODIFY_DATA
*&---------------------------------------------------------------------*
*& Form USEREXIT_CHECK_ROW_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GS_DATA_WA text
* <--P_L_TABIX text
* <--P_L_ISERROR text
* <--P_GS_DATA_WA_ROWMSG text
*----------------------------------------------------------------------*
FORM userexit_check_row_data CHANGING p_datarow LIKE gs_data_wa
p_index TYPE i
pf_error TYPE c
p_errmsg TYPE c.
CLEAR: pf_error, p_errmsg.
DATA: l_db_wa TYPE t_db,
l_msg(50) TYPE c,
l_row(10) TYPE c,
lt_doname TYPE TABLE OF dd07v,
lt_old_data LIKE TABLE OF gs_data_wa.
data: l_prodh1 type char20,
l_prodh3 type char20.
l_row = p_index.
MOVE-CORRESPONDING p_datarow TO l_db_wa.
CLEAR lt_old_data.
"检查必输字段是否已输
IF l_db_wa-zww_compy IS INITIAL.
p_errmsg = '旺旺销售公司不能为空'.
pf_error = 'X'.
RETURN.
ENDIF.
IF l_db_wa-zwwchan_kh IS INITIAL.
p_errmsg = '考核旺旺渠道不能为空'.
pf_error = 'X'.
RETURN.
ENDIF.
* IF l_db_wa-prodh1 IS INITIAL.
* p_errmsg = '事业部不能为空'.
* pf_error = 'X'.
* RETURN.
* ENDIF.
* IF l_db_wa-prodh3 IS INITIAL.
* p_errmsg = '产品线不能为空'.
* pf_error = 'X'.
* RETURN.
* ENDIF.
IF l_db_wa-sales_off IS INITIAL.
p_errmsg = '营业所不能为空'.
pf_error = 'X'.
RETURN.
ENDIF.
IF l_db_wa-customer IS INITIAL.
p_errmsg = '负责客户不能为空'.
pf_error = 'X'.
RETURN.
ENDIF.
IF l_db_wa-zydbzs IS INITIAL.
p_errmsg = ' 业代编制数不能为空'.
pf_error = 'X'.
RETURN.
ENDIF.
IF p_datarow-txtsh_kh CS '县城'.
IF p_datarow-prodh1 EQ space.
p_errmsg = '当旺旺渠道为县城时,字段“事业部”为必输'.
pf_error = 'X'.
RETURN.
ENDIF.
IF p_datarow-prodh3 NE space.
p_errmsg = '当旺旺渠道为县城时,字段“产品线”必须为空'.
pf_error = 'X'.
RETURN.
ENDIF.
ENDIF.
IF p_datarow-txtsh_kh CS '乳品'.
IF p_datarow-prodh3 EQ space.
p_errmsg = '当旺旺渠道为乳品时,字段“产品线”为必输'.
pf_error = 'X'.
RETURN.
ENDIF.
IF p_datarow-prodh1 NE space.
p_errmsg = '当旺旺渠道为乳品时,字段“事业部”必须为空'.
pf_error = 'X'.
RETURN.
ENDIF.
ENDIF.
DATA: ls_tzwwchan TYPE /bic/tzwwchan,
ls_tprod_hier TYPE /bi0/tprod_hier.
READ TABLE gt_chan_kh TRANSPORTING NO FIELDS WITH KEY zwwchan_kh = p_datarow-zwwchan_kh.
IF sy-subrc NE 0.
pf_error = 'X'.
p_errmsg = '考核旺旺渠道不存在,请检查数据!' .
RETURN.
ENDIF.
IF p_datarow-prodh1 IS NOT INITIAL.
IF strlen( p_datarow-prodh1 ) NE 3.
pf_error = 'X'.
p_errmsg = '事业部有误,请检查数据!' .
RETURN.
ELSE.
* CONCATENATE p_datarow-prodh1 '%' INTO l_prodh1.
* TRANSFER p_datarow-prodh1 TO UPPER CASE
SELECT SINGLE *
INTO ls_tprod_hier
FROM /bi0/tprod_hier
WHERE prod_hier = p_datarow-prodh1.
IF sy-subrc NE 0.
pf_error = 'X'.
p_errmsg = '事业部不存在,请检查数据!' .
RETURN.
ENDIF.
ENDIF.
ENDIF.
IF p_datarow-prodh3 IS NOT INITIAL.
IF strlen( p_datarow-prodh3 ) NE 9.
pf_error = 'X'.
p_errmsg = '产品线有误,请检查数据!' .
RETURN.
ELSE.
* CONCATENATE p_datarow-prodh3 '%' INTO l_prodh3.
SELECT SINGLE *
INTO ls_tprod_hier
FROM /bi0/tprod_hier
WHERE prod_hier = p_datarow-prodh3 .
IF sy-subrc NE 0.
pf_error = 'X'.
p_errmsg = '产品线不存在,请检查数据!' .
RETURN.
ENDIF.
ENDIF.
ENDIF.
ENDFORM. " USEREXIT_CHECK_ROW_DATA
*&---------------------------------------------------------------------*
*& Form USEREXIT_CHECK_DATA_ROW_EXIST
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GS_DATA_WA text
* <--P_L_ISERROR text
* <--P_GS_DATA_WA_ROWMSG text
*----------------------------------------------------------------------*
FORM userexit_check_data_row_exist USING p_datarow LIKE gs_data_wa
CHANGING pf_error TYPE c
p_errmsg TYPE c.
CLEAR: pf_error, p_errmsg.
DATA l_db_wa TYPE t_db.
SELECT SINGLE * FROM (g_tabname) INTO l_db_wa
WHERE zww_compy = p_datarow-zww_compy
AND zwwchan_kh = p_datarow-zwwchan_kh
AND prodh1 = p_datarow-prodh1
AND prodh3 = p_datarow-prodh3
AND sales_off = p_datarow-sales_off
AND customer = p_datarow-customer.
IF sy-subrc = 0.
pf_error = 'X'.
p_errmsg = '数据已经存在'.
ENDIF.
ENDFORM. " USEREXIT_CHECK_DATA_ROW_EXIST
*&---------------------------------------------------------------------*
*& Form DISPLAY_MESSAGE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_L_ISUCC text
* -->P_GT_INDEX_ROWS text
* -->P_0953 text
*----------------------------------------------------------------------*
FORM display_message USING p_succ TYPE i
pt_index_rows TYPE lvc_t_row
p_type TYPE c.
DATA: l_succ TYPE string,
l_rows_i TYPE i,
l_rows(10) TYPE c,
l_msg(70) TYPE c.
* CALL METHOD gr_alvgrid->refresh_table_display.
l_succ = p_succ.
DESCRIBE TABLE pt_index_rows LINES l_rows_i."统计错误行数
IF l_rows_i IS INITIAL.
CONCATENATE '成功' p_type '了' l_succ '条记录' INTO l_msg.
ELSE.
l_rows = l_rows_i.
CONCATENATE '成功' p_type '了' l_succ '条记录,高亮行数据不正确' INTO l_msg.
gf_error = 'X'."设置信息表示有错误行
ENDIF.
MESSAGE l_msg TYPE 'S'.
ENDFORM. " DISPLAY_MESSAGE
*&---------------------------------------------------------------------*
*& Form USEREXIT_COMPARE_KEY_EQUAL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GS_DATA_WA text
* -->P_LS_DATA_OLD text
* <--P_L_ISEQUAL text
*----------------------------------------------------------------------*
FORM userexit_compare_key_equal USING ps_datarow1 LIKE gs_data_wa
ps_datarow2 LIKE gs_data_wa
CHANGING isequal TYPE c.
IF ps_datarow1-zww_compy = ps_datarow2-zww_compy
AND ps_datarow1-zwwchan_kh = ps_datarow2-zwwchan_kh
AND ps_datarow1-prodh1 = ps_datarow2-prodh1
AND ps_datarow1-prodh3 = ps_datarow2-prodh3
AND ps_datarow1-sales_off = ps_datarow2-sales_off
AND ps_datarow1-customer = ps_datarow2-customer.
isequal = 'X'.
ENDIF.
ENDFORM. " USEREXIT_COMPARE_KEY_EQUAL
*&---------------------------------------------------------------------*
*& Form GET_CHAN
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_chan .
CLEAR gt_chan_kh.
SELECT zwwchan_kh txtsh_kh
INTO TABLE gt_chan_kh
FROM zbw_sdt010.
IF sy-subrc NE 0 .
ENDIF.
SELECT /bic/zwwchan AS zwwchan_kh
txtsh AS txtsh_kh
APPENDING TABLE gt_chan_kh
FROM /bic/tzwwchan.
SORT gt_chan_kh BY zwwchan_kh.
DELETE ADJACENT DUPLICATES FROM gt_chan_kh.
* CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
* EXPORTING
* retfield = 'ZWWCHAN_KH'
* dynpprog = sy-repid
* dynpnr = sy-dynnr
* dynprofield = 'p_COMPY'
* value_org = 'S'
* TABLES
* value_tab = gt_chan_kh.
ENDFORM. " GET_CHAN
*&---------------------------------------------------------------------*
*& Form GET_COMPY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_compy .
IF p_compy IS INITIAL .
MESSAGE '分公司必输' TYPE 'S' DISPLAY LIKE 'E'.
STOP.
ENDIF.
SELECT /bic/zww_compy txtsh
FROM /bic/tzww_compy
INTO TABLE gt_compy
WHERE /bic/zww_compy = p_compy.
IF sy-subrc NE 0.
MESSAGE '分公司不存在' TYPE 'S' DISPLAY LIKE 'E'.
STOP.
ENDIF.
ENDFORM. " GET_COMPY
*&---------------------------------------------------------------------*
*& Form GET_OTHER_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_other_data .
IF p_chan IS NOT INITIAL .
s_chan_st-sign = 'I'.
s_chan_st-option = 'BT'.
s_chan_st-low = p_chan.
APPEND s_chan_st TO s_chan.
ENDIF.
IF p_sales IS NOT INITIAL .
s_sales_st-sign = 'I'.
s_sales_st-option = 'BT'.
s_sales_st-low = p_sales.
APPEND s_sales_st TO s_sales.
ENDIF.
ENDFORM. " GET_OTHER_DATA
*&---------------------------------------------------------------------*
*& Form GET_COMPY_F4
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_compy_f4 .
DATA: lt_compy TYPE STANDARD TABLE OF /bic/tzww_compy,
ls_compy TYPE /bic/tzww_compy.
SELECT /bic/zww_compy txtsh
FROM /bic/tzww_compy
INTO TABLE lt_compy.
DELETE ADJACENT DUPLICATES FROM lt_compy.
SORT lt_compy BY /bic/zww_compy.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = '/BIC/ZWW_COMPY'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'P_COMPY'
value_org = 'S'
TABLES
value_tab = lt_compy.
ENDFORM. " GET_COMPY_F4
*&---------------------------------------------------------------------*
*& Form GET_SALES_F4
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_sales_f4 .
DATA: lt_sales TYPE STANDARD TABLE OF /bi0/tsales_off,
ls_sales TYPE /bi0/tsales_off.
* "获取营业所描述
* SELECT sales_off
* txtsh
* FROM /bi0/tsales_off
* INTO CORRESPONDING FIELDS OF TABLE lt_sales
* WHERE LANGU = '1'.
*
* DELETE ADJACENT DUPLICATES FROM lt_sales.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'SALES_OFF'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'P_SALES'
value_org = 'S'
TABLES
value_tab = gt_sales_dec.
ENDFORM. " GET_SALES_F4\
*&---------------------------------------------------------------------*
*& Form GET_SALES
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_sales .
"获取营业所描述
SELECT sales_off
txtsh
FROM /bi0/tsales_off
INTO CORRESPONDING FIELDS OF TABLE gt_sales_dec
WHERE langu = '1'.
DELETE ADJACENT DUPLICATES FROM gt_sales_dec.
SORT gt_sales_dec BY sales_off.
ENDFORM. " GET_SALES
* DELETE ADJACENT DUPLICATES FROM lt_sales.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'SALES_OFF'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'P_SALES'
value_org = 'S'
TABLES
value_tab = gt_sales_dec.
ENDFORM. " GET_SALES_F4\
*&---------------------------------------------------------------------*
*& Form GET_SALES
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_sales .
"获取营业所描述
SELECT sales_off
txtsh
FROM /bi0/tsales_off
INTO CORRESPONDING FIELDS OF TABLE gt_sales_dec
WHERE langu = '1'.
DELETE ADJACENT DUPLICATES FROM gt_sales_dec.
SORT gt_sales_dec BY sales_off.
ENDFORM. " GET_SALES
这篇关于标准的ALV模式中的表维护程序的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!