*=====================================================================
*& Report ZPM_RP_01_TB
*=====================================================================
REPORT zpm_rp_01_tb.
======================================================================
* Tables
======================================================================
TABLES:zpm003.
======================================================================
* Constants
======================================================================
======================================================================
* Types
======================================================================
TYPE-POOLS : abap,slis,icon.
======================================================================
* Internal Tables/work areas
======================================================================
DATA:BEGIN OF gt_out OCCURS 0,
swerk LIKE zpm003-swerk, “工厂
name1 LIKE zpm003-name1, “工厂名称
zzfgs LIKE zpm003-zzfgs, “分公司
butxt LIKE zpm003-butxt, “分公司名称
bukrs LIKE zpm003-bukrs, “公司代码
butxt_d LIKE zpm003-butxt_d, “公司代码名称
sel(1) TYPE c,
END OF gt_out.
DATA: fieldcat TYPE lvc_t_fcat WITH HEADER LINE.
DATA:gt_excel LIKE TABLE OF alsmex_tabline,
gw_excel LIKE alsmex_tabline.
DATA:BEGIN OF gt_upload OCCURS 0,
swerk LIKE zpm003-swerk, “工厂
name1 LIKE zpm003-name1, “工厂名称
zzfgs LIKE zpm003-zzfgs, “分公司
butxt LIKE zpm003-butxt, “分公司名称
bukrs LIKE zpm003-bukrs, “公司代码
butxt_d LIKE zpm003-butxt_d, “公司代码名称
END OF gt_upload.
======================================================================
* Data declarations
======================================================================
DATA: wa_layout TYPE lvc_s_layo,
gt_events TYPE slis_t_event WITH HEADER LINE,
gs_event LIKE LINE OF gt_events.
DATA: g_grid TYPE REF TO cl_gui_alv_grid.
DATA:gv_file TYPE rlgrap-filename.
DATA: ref_grid TYPE REF TO cl_gui_alv_grid.
———————————————————————-
* CLASS lcl_event_receiver DEFINITION
———————————————————————-
*
———————————————————————-
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS handle_modify
FOR EVENT data_changed_finished OF cl_gui_alv_grid
IMPORTING e_modified et_good_cells.
METHODS:
handle_f4
FOR EVENT onf4 OF cl_gui_alv_grid
IMPORTING e_fieldname
es_row_no
er_event_data
et_bad_cells.
ENDCLASS. “LCL_EVENT_RECEIVER DEFINITION
———————————————————————-
* CLASS LCL_EVENT_RECEIVER IMPLEMENTATION
———————————————————————-
*
———————————————————————-
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_modify.
DATA stbl TYPE lvc_s_stbl.
DATA:WA_OUT LIKE gt_out.
LOOP AT gt_out INTO WA_OUT.
SELECT SINGLE NAME1
INTO wa_out-NAME1
FROM T001W
WHERE WERKS = WA_out-SWERK.
MODIFY gt_out FROM WA_OUT.
ENDLOOP.
* 稳定刷新
stbl-row = ‘X’.” 基于行的稳定刷新
stbl-col = ‘X’.” 基于列稳定刷新
CALL METHOD ref_grid->refresh_table_display
EXPORTING
is_stable = stbl.
ENDMETHOD. “HANDLE_MODIFY
———————————————————————————————
METHOD handle_f4.
* 窗口时间参数的自定义f4检索帮助
PERFORM f4_help_zsjcs USING e_fieldname
es_row_no.
* 设置后,alv稳定刷新
PERFORM refresh_table_alv.
ENDMETHOD. “HANDLE_F4
ENDCLASS. “LCL_EVENT_RECEIVER IMPLEMENTATION
DATA gt_event_receiver TYPE REF TO lcl_event_receiver .
—————————————————————
*DEFINATION
—————————————————————
DEFINE fill_field.
CLEAR FIELDCAT.
FIELDCAT-FIELDNAME = &1.
FIELDCAT-SCRTEXT_L = &2.
FIELDCAT-CFIELDNAME = &3.
FIELDCAT-OUTPUTLEN = &4.
FIELDCAT-EDIT = &5.
APPEND FIELDCAT.
END-OF-DEFINITION.
======================================================================
* Range declarations
======================================================================
======================================================================
* Input Selection Screen
======================================================================
SELECTION-SCREEN BEGIN OF SCREEN 9000 TITLE text-001 AS WINDOW.
PARAMETERS: p_swerk LIKE zpm003-swerk, “工厂
p_name1 LIKE zpm003-name1, “工厂名称
p_zzfgs LIKE zpm003-zzfgs, “分公司
p_butxt LIKE zpm003-butxt. “分公司名称
SELECTION-SCREEN END OF SCREEN 9000.
======================================================================
* Initialization
======================================================================
INITIALIZATION.
======================================================================
* At Selection Screen
======================================================================
AT SELECTION-SCREEN.
======================================================================
* At Selection Screen Output
======================================================================
AT SELECTION-SCREEN OUTPUT .
======================================================================
* AT SELECTION-SCREEN ON VALUE-REQUEST
======================================================================
*at selection-screen on value-request for p_ksgru.
======================================================================
* Start of Selection
======================================================================
START-OF-SELECTION.
PERFORM frm_get_data.
======================================================================
* End of Selection
======================================================================
END-OF-SELECTION.
PERFORM frm_display_data.
&———————————————————————
*& Form FRM_GET_DATA
&———————————————————————
* text
———————————————————————-
* –> p1 text
* <– p2 text
———————————————————————-
FORM frm_get_data .
SELECT swerk name1 zzfgs butxt bukrs butxt_d
INTO CORRESPONDING FIELDS OF TABLE gt_out
FROM zpm003.
ENDFORM.
&———————————————————————
*& Form FRM_DISPLAY_DATA
&———————————————————————
* text
———————————————————————-
* –> p1 text
* <– p2 text
———————————————————————-
FORM frm_display_data .
PERFORM frm_layout.
PERFORM frm_fill_field.
PERFORM frm_alv_display.
ENDFORM.
&———————————————————————
*& Form FRM_LAYOUT
&———————————————————————
* text
———————————————————————-
* –> p1 text
* <– p2 text
———————————————————————-
FORM frm_layout .
CLEAR: wa_layout.”它用来定义ALV报表的整体属性
wa_layout-cwidth_opt = ‘X’.”优化列宽选项是否设置
wa_layout-box_fname = ‘SEL’.
ENDFORM.
&———————————————————————
*& Form FRM_FILL_FIELD
&———————————————————————
* text
———————————————————————-
* –> p1 text
* <– p2 text
———————————————————————-
FORM frm_fill_field .
fieldcat-fieldname = ‘SWERK’.
fieldcat-scrtext_l = ‘工厂’.
fieldcat-cfieldname = ”.
fieldcat-outputlen = ‘20’.
fieldcat-edit = ”.
fieldcat-F4AVAILABL = ‘X’.
APPEND fieldcat.
CLEAR fieldcat.
fill_field ‘NAME1’ ‘工厂名称’ ” ‘20’ ”.
fill_field ‘ZZFGS’ ‘分公司’ ” ‘20’ ”.
fill_field ‘BUTXT’ ‘分公司名称’ ” ‘20’ ”.
fill_field ‘BUKRS’ ‘公司代码’ ” ‘20’ ”.
fill_field ‘BUTXT_D’ ‘公司代码名称’ ” ‘20’ ”.
ENDFORM.
&———————————————————————
*& Form FRM_ALV_DISPLAY
&———————————————————————
* text
———————————————————————-
* –> p1 text
* <– p2 text
———————————————————————-
FORM frm_alv_display .
gt_eventS-name = ‘CALLER_EXIT’. “slis_ev_caller_exit_at_start事件
gt_eventS-FORM = ‘FM_BUTTON’.
APPEND gt_eventS.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY_LVC’
EXPORTING
i_callback_program = sy-repid
i_callback_user_command = ‘USER_COMMAND’
i_callback_pf_status_set = ‘PF_STATUS’
is_layout_lvc = wa_layout
it_fieldcat_lvc = fieldcat[]
i_default = ‘X’
i_save = ‘A’
it_events = gt_events[]
TABLES
t_outtab = gt_out[]
EXCEPTIONS
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
ENDFORM. ” FRM_ALV_DISPLAY
FORM pf_status USING lt_extab.
SET PF-STATUS ‘MENU’.
ENDFORM.
&———————————————————————
*& Form user_command
&———————————————————————
* text
———————————————————————-
* –>UCOMM text
* –>RS_SELFIELD text
———————————————————————-
FORM user_command USING ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield. “#EC CALLED
CASE ucomm.
WHEN ‘CHANGE’.
PERFORM frm_change_function.
WHEN ‘DELETE’.
PERFORM frm_delete_function.
WHEN ‘CREATE’.
PERFORM frm_create_function.
WHEN ‘SAVE’.
PERFORM frm_save_function.
WHEN ‘IMPORT’.
PERFORM frm_import_function.
ENDCASE.
rs_selfield-refresh = ‘X’.
rs_selfield-col_stable = ‘X’.
rs_selfield-row_stable = ‘X’.
ENDFORM. “user_command
&———————————————————————
*& Form fm_button
&———————————————————————
* text
———————————————————————-
* –>E_GRID text
———————————————————————-
FORM fm_button USING e_grid TYPE slis_data_caller_exit.
CALL FUNCTION ‘GET_GLOBALS_FROM_SLVC_FULLSCR’
IMPORTING
e_grid = ref_grid.
* 设置enter事件
CALL METHOD ref_grid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter
EXCEPTIONS
error = 1
OTHERS = 2.
CREATE OBJECT gt_event_receiver.
SET HANDLER gt_event_receiver->handle_modify FOR ref_grid.
DATA: lv_event_receiver TYPE REF TO lcl_event_receiver,
lt_f4 TYPE lvc_t_f4,
ls_f4 TYPE lvc_s_f4.
ls_f4-fieldname = ‘SWERK’. “窗口时间参数(需要定义F4帮助按钮的字段)
ls_f4-register = ‘X’.
ls_f4-getbefore = ‘X’.
ls_f4-chngeafter = ‘X’.
INSERT ls_f4 INTO TABLE lt_f4.
CREATE OBJECT lv_event_receiver.
SET HANDLER lv_event_receiver->handle_f4 FOR ReF_grid.
CALL METHOD ReF_grid->register_f4_for_fields
EXPORTING
it_f4 = lt_f4[].
ENDFORM. “FM_BUTTON
&———————————————————————
*& Form REFRESH_TABLE_ALV
&———————————————————————
* 设置后,alv稳定刷新
———————————————————————-
FORM refresh_table_alv .
DATA: stbl TYPE lvc_s_stbl.
*
stbl-row = ‘X’.” 基于行的稳定刷新
stbl-col = ‘X’.” 基于列稳定刷新
CALL METHOD REF_grid->refresh_table_display
EXPORTING
is_stable = stbl.
ENDFORM. ” REFRESH_TABLE_ALV
&———————————————————————
*& Form F4_HELP_ZSJCS
&———————————————————————
* 窗口时间参数的自定义f4检索帮助
———————————————————————-
FORM f4_help_zsjcs USING p_fieldname TYPE lvc_fname
p_row_no TYPE lvc_s_roid.
DATA: lt_return TYPE STANDARD TABLE OF ddshretval,
ls_return TYPE ddshretval.
DATA:BEGIN OF LT_T001W OCCURS 0,
WERKS LIKE T001W-WERKS,
NAME1 LIKE T001W-name1,
END OF LT_T001W.
IF p_fieldname = ‘SWERK’.
SELECT name1 WERKS
INTO CORRESPONDING FIELDS OF TABLE LT_T001W
FROM T001W.
SORT LT_T001W BY werks.
DELETE ADJACENT DUPLICATES FROM LT_T001W
COMPARING werks.
ENDIF.
CALL FUNCTION ‘F4IF_INT_TABLE_VALUE_REQUEST’
EXPORTING
retfield = ‘WERKS’ “lt内表里面的字段
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = ‘SWERK’ “画面上绑定字段
value_org = ‘S’
callback_program = sy-repid
TABLES
value_tab = LT_T001W “需要显示帮助的值内表
return_tab = lt_return “返回值
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
IF sy-subrc = 0.
READ TABLE gt_out INDEX p_row_no-row_id.
IF gt_out-swerk IS INITIAL.
READ TABLE lt_return INTO ls_return INDEX 1.
gt_out-swerk = ls_return-fieldval.
MODIFY gt_out INDEX p_row_no-row_id
TRANSPORTING swerk.
ENDIF.
ENDIF.
ENDFORM. ” F4_HELP_