REPORT z_scm_vendor_min_amount .
TYPE-POOLS: rsds,slis.
TABLES: zscm_vendor_min.
TYPES: BEGIN OF ty_itab.
INCLUDE STRUCTURE zscm_vendor_min.
TYPES: END OF ty_itab.
*DATA: BEGIN OF messtab OCCURS 0.
* INCLUDE STRUCTURE bdcmsgcoll.
*DATA: END OF messtab.
DATA: BEGIN OF itab_log OCCURS 0,
message(132) TYPE c,
END OF itab_log.
DATA: BEGIN OF itab_t1 OCCURS 0,
TEST1 TYPE LIFNR,
END OF itab_t1.
DATA: BEGIN OF itab_t2 OCCURS 0,
test2(10) TYPE c,
END OF itab_t2.
DATA: itab TYPE STANDARD TABLE OF ty_itab WITH HEADER LINE ,
old_tab TYPE STANDARD TABLE OF ty_itab ,
new_tab TYPE STANDARD TABLE OF ty_itab ,
add_tab TYPE STANDARD TABLE OF ty_itab ,
del_tab TYPE STANDARD TABLE OF ty_itab ,
mod_tab TYPE STANDARD TABLE OF ty_itab .
DATA: n_add(3) TYPE c ,
n_del(3) TYPE c ,
n_mod(3) TYPE c .
DATA mes_text(60) TYPE c .
DATA: BEGIN OF itab_key OCCURS 0 ,
mandt LIKE zscm_vendor_min-mandt ,
lifnr LIKE zscm_vendor_min-lifnr ,
city1 LIKE zscm_vendor_min-city1 ,
END OF itab_key .
DATA rt_extab TYPE slis_t_extab.
SELECT-OPTIONS : s_lifnr FOR itab-lifnr ,
s_city1 FOR itab-city1 .
SELECTION-SCREEN SKIP .
PARAMETERS: p_view AS CHECKBOX DEFAULT 'X'.
DATA: ok_code LIKE sy-ucomm.
DATA: l_valid(1) TYPE c .
DATA: go_grid TYPE REF TO cl_gui_alv_grid,
go_custom_container TYPE REF TO cl_gui_custom_container.
DATA: gt_fieldcat TYPE lvc_t_fcat,
gs_fieldcat TYPE lvc_s_fcat,
gs_variant TYPE disvariant,
gt_sort TYPE lvc_t_sort,
gs_sort TYPE lvc_s_sort,
gt_filt TYPE lvc_t_filt,
gs_filt TYPE lvc_s_filt,
ls_cell TYPE lvc_s_styl,
sla TYPE lvc_s_layo,
gt_f4 TYPE lvc_t_f4,
gs_f4 TYPE lvc_s_f4.
DATA: t_index_rows TYPE lvc_t_row,
wa_index_rows TYPE lvc_s_row.
DATA: w_lines TYPE i,
w_error TYPE i.
DATA: subrc LIKE sy-subrc ,
subrc2 LIKE sy-subrc .
*---------------------------------------------------------------------*
* CLASS lcl_event_receiver DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS handle_f4
FOR EVENT onf4 OF cl_gui_alv_grid
IMPORTING e_fieldname
es_row_no
er_event_data
et_bad_cells.
METHODS catch_doubleclick
FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING e_row
e_column
es_row_no .
ENDCLASS. "lcl_event_receiver DEFINITION
*---------------------------------------------------------------------*
* CLASS lcl_event_receiver IMPLEMENTATION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_f4.
PERFORM f4 USING e_fieldname
es_row_no
er_event_data
et_bad_cells.
ENDMETHOD. "handle_f4
METHOD catch_doubleclick.
PERFORM atdoubleclick USING e_row
e_column
es_row_no.
ENDMETHOD.
ENDCLASS. "lcl_event_receiver IMPLEMENTATION
DATA: event_receiver TYPE REF TO lcl_event_receiver.
INITIALIZATION.
itab_t1-test1 = 'JASONTEST'.
APPEND itab_t1.
itab_t1-test1 = 'TESTJASON'.
APPEND itab_t1.
* gd_repid = sy-repid.
PERFORM fieldcat_init USING gt_fieldcat[].
START-OF-SELECTION.
CALL SCREEN '100'.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'BACK'.
SET SCREEN 0 .
WHEN 'SAVE'.
PERFORM run_save.
ENDCASE.
CLEAR ok_code .
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
TYPES: BEGIN OF sta_tab_type,
fcode LIKE rsmpe-func,
END OF sta_tab_type.
DATA: tab TYPE STANDARD TABLE OF sta_tab_type WITH
NON-UNIQUE DEFAULT KEY INITIAL SIZE 10,
wa_sta_tab TYPE sta_tab_type.
IF p_view = 'X'.
CLEAR rt_extab.
REFRESH rt_extab.
APPEND 'SAVE' TO rt_extab .
SET PF-STATUS 'MAIN200' EXCLUDING rt_extab .
ELSE.
SET PF-STATUS 'MAIN200'.
ENDIF.
gs_variant-report = sy-repid.
IF go_grid IS INITIAL.
CREATE OBJECT go_grid
EXPORTING
i_parent = cl_gui_container=>screen0.
CREATE OBJECT event_receiver.
SET HANDLER event_receiver->handle_f4 FOR go_grid.
CALL METHOD go_grid->register_f4_for_fields
EXPORTING
it_f4 = gt_f4.
SET HANDLER event_receiver->catch_doubleclick FOR go_grid.
IF sy-batch IS INITIAL.
CALL METHOD go_grid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter.
ENDIF.
PERFORM load_data_into_grid.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Form load_data_into_grid
*&---------------------------------------------------------------------*
FORM load_data_into_grid.
SELECT * FROM zscm_vendor_min INTO CORRESPONDING FIELDS OF TABLE itab
WHERE lifnr IN s_lifnr
AND city1 IN s_city1.
old_tab[] = itab[].
* sla-cwidth_opt = 'X'.
sla-zebra = 'X'.
CALL METHOD go_grid->set_table_for_first_display
EXPORTING
is_variant = gs_variant
i_save = 'A'
is_layout = sla
CHANGING
it_outtab = itab[]
it_fieldcatalog = gt_fieldcat[]
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
IF p_view = 'X'.
CALL METHOD go_grid->set_ready_for_input
EXPORTING
i_ready_for_input = 0.
ELSE.
CALL METHOD go_grid->set_ready_for_input
EXPORTING
i_ready_for_input = 1.
ENDIF.
ENDFORM. " load_data_into_grid
*&--------------------------------------------------------------------*
*& Form fieldcat_init
*&--------------------------------------------------------------------*
FORM fieldcat_init USING rt_fieldcat TYPE lvc_t_fcat.
DATA: ls_fieldcat TYPE lvc_s_fcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'MANDT'.
ls_fieldcat-scrtext_l = 'MANDT'.
ls_fieldcat-no_out = 'X'.
APPEND ls_fieldcat TO rt_fieldcat .
PERFORM frm_catlg_set USING:
'LIFNR' '' '供应商' 'X' 'LIFNR' 'LIFNR' 'ZSCM_VENDOR_MIN' rt_fieldcat,
'CITY1' '' '城市' 'X' '' 'CITY1' 'ZSCM_VENDOR_MIN' rt_fieldcat,
'PMONY' '' '最小金额' 'X' 'KBLBTR' 'PMONY'
'ZSCM_VENDOR_MIN' rt_fieldcat,
'PDAYS' '' '送货天数' 'X' '' ''
'' rt_fieldcat.
gs_f4-fieldname = 'LIFNR'.
gs_f4-register = 'X'.
gs_f4-getbefore = 'X'.
gs_f4-chngeafter = 'X'.
INSERT gs_f4 INTO TABLE gt_f4.
ENDFORM. "fieldcat_init
*---------------------------------------------------------------------*
* FORM frm_catlg_set *
*---------------------------------------------------------------------*
FORM frm_catlg_set USING p_field p_key p_text p_edit p_decimals
ref_f ref_t rt_fieldcat TYPE lvc_t_fcat .
DATA: tmp_fieldcat TYPE lvc_s_fcat.
tmp_fieldcat-fieldname = p_field.
tmp_fieldcat-key = p_key .
* tmp_fieldcat-scrtext_m = p_text.
tmp_fieldcat-coltext = p_text.
tmp_fieldcat-edit = p_edit.
tmp_fieldcat-decimals = p_decimals .
tmp_fieldcat-f4availabl = 'X'.
tmp_fieldcat-ref_field = ref_f.
tmp_fieldcat-ref_table = ref_t.
APPEND tmp_fieldcat TO rt_fieldcat .
CLEAR tmp_fieldcat .
ENDFORM. " FRM_CATLG_SET
*&--------------------------------------------------------------------*
*& Form run_save
*&--------------------------------------------------------------------*
FORM run_save .
DATA: out(128) TYPE c .
CALL METHOD go_grid->check_changed_data "把修改的内容更改到内表里
IMPORTING
e_valid = l_valid.
IF l_valid = 'X'.
new_tab[] = itab[].
PERFORM get_multi_tab.
PERFORM checkdata .
IF w_error = 1 .
EXIT .
ENDIF.
ENDIF.
IF n_del = 0 AND n_add = 0 AND n_mod = 0 .
MESSAGE i000(oo) WITH '没有变化需要更新'.
EXIT.
ENDIF.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
titlebar = '确认'
text_question = mes_text
icon_button_1 = 'ICON_ADDRESS' "按钮ICON,
IMPORTING
answer = out. "1、 2、 A
IF out = '1' .
DELETE zscm_vendor_min FROM TABLE del_tab.
IF sy-subrc <> 0 .
ROLLBACK WORK.
MESSAGE i000(oo) WITH '更新数据库错误'.
EXIT.
ENDIF.
INSERT zscm_vendor_min FROM TABLE add_tab.
IF sy-subrc <> 0 .
ROLLBACK WORK.
MESSAGE i000(oo) WITH '更新数据库错误'.
EXIT.
ENDIF.
MODIFY zscm_vendor_min FROM TABLE mod_tab .
IF sy-subrc <> 0 .
ROLLBACK WORK.
MESSAGE i000(oo) WITH '更新数据库错误'.
EXIT.
ENDIF.
COMMIT WORK.
REFRESH: del_tab,
add_tab,
mod_tab.
CLEAR: n_del ,n_add ,n_mod.
MESSAGE s000(oo) WITH '更新成功'.
old_tab[] = itab[].
ENDIF.
CALL METHOD go_grid->refresh_table_display.
ENDFORM. "run_save
*&---------------------------------------------------------------------*
*& Form checkdata
*&---------------------------------------------------------------------*
FORM checkdata .
DATA wa_add LIKE LINE OF add_tab.
CLEAR subrc .
REFRESH t_index_rows .
CLEAR t_index_rows .
CLEAR w_error .
LOOP AT add_tab INTO wa_add.
SELECT SINGLE * FROM zscm_vendor_min
WHERE lifnr = wa_add-lifnr
AND city1 = wa_add-city1.
IF sy-subrc = 0.
READ TABLE itab WITH KEY lifnr = wa_add-lifnr
city1 = wa_add-city1.
IF sy-subrc = 0.
wa_index_rows-index = sy-tabix.
APPEND wa_index_rows TO t_index_rows.
ENDIF.
CLEAR wa_index_rows.
ENDIF.
ENDLOOP.
DESCRIBE TABLE t_index_rows LINES w_lines.
IF w_lines GT 0.
CALL METHOD go_grid->set_selected_rows
EXPORTING
it_index_rows = t_index_rows.
w_error = 1 .
MESSAGE s000(oo) WITH '高亮的行记录已经存在!'.
EXIT.
ENDIF .
REFRESH t_index_rows .
CLEAR t_index_rows .
LOOP AT itab.
IF itab-lifnr = '' OR itab-city1 = ''.
wa_index_rows-index = sy-tabix.
APPEND wa_index_rows TO t_index_rows.
CLEAR wa_index_rows.
ENDIF.
ENDLOOP.
DESCRIBE TABLE t_index_rows LINES w_lines.
IF w_lines GT 0.
CALL METHOD go_grid->set_selected_rows
EXPORTING
it_index_rows = t_index_rows.
w_error = 1 .
MESSAGE s000(oo) WITH '关键字段必填!'.
EXIT.
ENDIF .
subrc = 1 .
itab_key[] = itab[].
ENDFORM. " checkdata
*&--------------------------------------------------------------------*
*& Form f4
*&--------------------------------------------------------------------*
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
rt_bad_cells TYPE lvc_t_modi.
FIELD-SYMBOLS: TYPE lvc_t_modi.
DATA: ls_f4 TYPE lvc_s_modi ,
t_index LIKE sy-tabix .
DATA: BEGIN OF return_tab OCCURS 0 .
INCLUDE STRUCTURE ddshretval .
DATA: END OF return_tab .
IF go_grid->is_ready_for_input( ) = 0 .
rr_event_data->m_event_handled = 'X'.
EXIT.
ENDIF .
READ TABLE itab INDEX rs_row_no-row_id .
IF r_fieldname = 'LIFNR'.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'TEST1' "起作用的字段
value_org = 'S'
TABLES
value_tab = itab_t1[]
return_tab = return_tab
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
ASSIGN rr_event_data->m_data->* TO .
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 .
ENDIF .
* ELSEIF r_fieldname = 'ZZPOSTATUS'.
* CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
* EXPORTING
* retfield = 'TEST2' "起作用的字段
* value_org = 'S'
* TABLES
* value_tab = itab_t1[]
* return_tab = return_tab
* EXCEPTIONS
* parameter_error = 1
* no_values_found = 2
* OTHERS = 3.
* ASSIGN rr_event_data->m_data->* TO .
* 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 .
* ENDIF .
ENDIF.
rr_event_data->m_event_handled = 'X'.
ENDFORM. " F4
*---------------------------------------------------------------------*
* FORM get_multi_tab *
*---------------------------------------------------------------------*
FORM get_multi_tab.
REFRESH: del_tab,
add_tab,
mod_tab.
CALL FUNCTION 'CTVB_COMPARE_TABLES'
EXPORTING
table_old = old_tab[]
table_new = new_tab[]
key_length = 53
IMPORTING
table_del = del_tab[]
table_add = add_tab[]
table_mod = mod_tab[].
DESCRIBE TABLE del_tab LINES n_del.
DESCRIBE TABLE add_tab LINES n_add.
DESCRIBE TABLE mod_tab LINES n_mod.
CONCATENATE '删除' n_del '条' ','
'添加' n_add '条' ','
'更改' n_mod '条' ','
INTO mes_text .
ENDFORM. "get_multi_tab
*&---------------------------------------------------------------------*
*& Form atdoubleclick
*&---------------------------------------------------------------------*
FORM atdoubleclick USING p_e_row
p_e_column
p_es_row_no.
READ TABLE itab INDEX p_e_row.
IF p_e_column = 'LIFNR'.
CALL FUNCTION 'MMPUR_VENDOR_DISPLAY'
EXPORTING
im_lifnr = itab-lifnr
im_ekorg = 'B000'.
ENDIF.
ENDFORM. " atdoubleclick