示例展示:
屏幕依据输入的物料编码或下拉框物料编码拍回车自动带出物料描述:
点击弹出框,输入物料编码拍回车带出物料描述,点击确认,更新ALV:
1.创建屏幕9000,用于处理ALV弹出框:
2.针对屏幕9000画屏幕如下:
3.屏幕属性如下:
4.为屏幕9000设置OK_CODE接收屏幕回传值:
5.为屏幕9000设置状态栏,下拉框列表,命令执行:
6.为屏幕1000设置AG1状态栏
7.为屏幕9000设置AG2状态栏(ENTER用于接收弹出框回车事件):
8.全部代码如下:
*&---------------------------------------------------------------------*
*& Report ZTEST2
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZTEST2.
TABLES: vbak,vbap.
TYPE-POOLS: slis.
DATA:t_fieldcat TYPE lvc_t_fcat,
w_fieldcat TYPE lvc_s_fcat,
t_layout TYPE lvc_s_layo.
DATA: gt_event TYPE slis_t_event,
gs_event LIKE LINE OF gt_event.
DATA: ref_grid TYPE REF TO cl_gui_alv_grid.
DATA: stbl TYPE lvc_s_stbl.
DATA: le_row TYPE i,
le_value TYPE c,
le_col TYPE i,
les_row_id TYPE lvc_s_row,
les_col_id TYPE lvc_s_col,
les_row_no TYPE lvc_s_roid.
DATA gv_smart TYPE rs38l_fnam.
DATA: ok_code(3).
TYPES:BEGIN OF ty_result,
vbeln TYPE vbak-vbeln, "so
posnr TYPE vbap-posnr, "项目
ckbox TYPE char1,
matnr TYPE makt-matnr,
dlmatnr TYPE makt-matnr,
maktx TYPE makt-maktx,
dd_handle TYPE int4,
END OF ty_result.
DATA: gt_ddval TYPE lvc_t_drop,
gw_ddval TYPE lvc_s_drop.
DATA:t_result TYPE TABLE OF ty_result.
DATA:w_result TYPE ty_result.
DATA:parvw TYPE C LENGTH 2.
TYPES:BEGIN OF ty_vbakp,
vbeln TYPE vbak-vbeln, "so
posnr TYPE vbap-posnr, "项目
END OF ty_vbakp.
DATA:t_vbakp TYPE TABLE OF ty_vbakp,
w_vbakp TYPE ty_vbakp.
DATA:t_vbpa TYPE STANDARD TABLE OF vbpa,
w_vbpa TYPE vbpa.
DATA:rt_extab TYPE slis_t_extab.
SELECTION-SCREEN:BEGIN OF BLOCK a1 WITH FRAME TITLE text-001.
SELECT-OPTIONS:s_vbeln FOR vbak-vbeln.
SELECTION-SCREEN:END OF BLOCK a1.
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.
ENDCLASS. "LCL_EVENT_RECEIVER DEFINITION
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_modify.
* PERFORM refresh.
* Get the Current Cell
CALL METHOD ref_grid->get_current_cell
IMPORTING
E_ROW = le_row
E_VALUE = le_value
E_COL = le_col
ES_ROW_ID = les_row_id
ES_COL_ID = les_col_id
ES_ROW_NO = les_row_no.
READ TABLE t_result INTO w_result INDEX les_row_id-index.
IF sy-subrc = 0.
SELECT SINGLE maktx INTO w_result-maktx FROM makt WHERE matnr = w_result-matnr OR matnr = w_result-dlmatnr.
MODIFY t_result FROM w_result INDEX les_row_id-index.
stbl-row = 'X'." 基于行的稳定刷新
stbl-col = 'X'." 基于列稳定刷新
CALL METHOD ref_grid->refresh_table_display
EXPORTING
is_stable = stbl.
ENDIF.
ENDMETHOD. "HANDLE_MODIFY
ENDCLASS.
START-OF-SELECTION.
*-----------------------获取数据
PERFORM frm_get_data.
*-------------------------处理数据
PERFORM frm_handle_data.
IF t_result IS NOT INITIAL.
PERFORM frm_alv_show.
ELSE.
MESSAGE '没有符合的数据,请重新查询' TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
END-OF-SELECTION.
FORM frm_get_data .
SELECT * INTO CORRESPONDING FIELDS OF TABLE t_vbakp UP TO 5 ROWS
FROM vbak
JOIN vbap ON vbak~vbeln = vbap~vbeln
WHERE vbak~vbeln IN s_vbeln.
ENDFORM.
FORM frm_handle_data .
CLEAR w_vbakp.
LOOP AT t_vbakp INTO w_vbakp.
w_result-vbeln = w_vbakp-vbeln.
w_result-posnr = w_vbakp-posnr.
APPEND w_result TO t_result.
CLEAR w_result.
ENDLOOP.
ENDFORM. " FRM_HANDLE_DATA
*------展示ALV
FORM frm_alv_show.
PERFORM frm_init_layout.
PERFORM frm_set_fieldset.
PERFORM create_dropdown_values.
PERFORM frm_set_event.
PERFORM frm_output_alv.
PERFORM f_status USING rt_extab.
ENDFORM.
*------初始化ALV布局,可以自动根据数据长度调整列宽
FORM frm_init_layout.
t_layout-zebra = 'X'.
t_layout-box_fname = 'ckbox'.
ENDFORM.
*------该子程序主要用于设置ALV字段
FORM frm_set_fieldset.
PERFORM frm_init_fieldcat USING 'VBELN' '销售凭证' 'X' '' 10 ''.
PERFORM frm_init_fieldcat USING 'POSNR' '项目' 'X' '' 4 ''.
PERFORM frm_init_fieldcat USING 'MATNR' '物料编码' space 'X' 20 ''.
PERFORM frm_init_fieldcat USING 'DLMATNR' '物料编码' space 'X' 20 'DD_HANDLE'.
PERFORM frm_init_fieldcat USING 'MAKTX' '物料描述' space '' 40 ''.
ENDFORM.
FORM frm_init_fieldcat USING fieldcatname LIKE w_fieldcat-fieldname
seltext LIKE w_fieldcat-scrtext_l
selkey LIKE w_fieldcat-key
edit LIKE w_fieldcat-edit
len LIKE w_fieldcat-outputlen
drdn_field LIKE w_fieldcat-drdn_field.
.
CLEAR w_fieldcat.
w_fieldcat-fieldname = fieldcatname .
w_fieldcat-scrtext_l = seltext.
w_fieldcat-key = selkey.
w_fieldcat-edit = edit.
w_fieldcat-outputlen = len.
w_fieldcat-drdn_field = drdn_field.
APPEND w_fieldcat TO t_fieldcat.
ENDFORM.
FORM frm_output_alv .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
i_callback_pf_status_set = 'F_STATUS '
i_callback_user_command = 'ALV_USER_COMMAND'
is_layout_lvc = t_layout
it_fieldcat_lvc = t_fieldcat
i_default = 'X'
i_save = 'A'
IT_EVENTS = gt_event
TABLES
t_outtab = t_result
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM.
FORM f_status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'AG1' EXCLUDING rt_extab.
"frm_platform_o
ENDFORM.
FORM alv_user_command USING r_ucomm LIKE sy-ucomm
rs_selfield
TYPE slis_selfield.
CASE r_ucomm.
WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
LEAVE TO SCREEN 0.
WHEN '&IC1'."双击
IF rs_selfield-fieldname = 'VBELN'.
READ TABLE t_result INTO w_result INDEX rs_selfield-tabindex.
SET PARAMETER ID 'AUN' FIELD rs_selfield-value.
CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
CLEAR w_result.
ENDIF.
WHEN 'DIALOG'.
CALL SCREEN 9000 STARTING AT 20 10 ENDING AT 108 20 .
CHECK ok_code EQ 'YES'.
CLEAR ok_code.
PERFORM save_matnr.
ENDCASE.
ENDFORM.
FORM frm_set_event.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE
= 0
IMPORTING
ET_EVENTS
= gt_event
EXCEPTIONS
LIST_TYPE_WRONG
= 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID
TYPE SY-MSGTY
NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
gs_event
-name = 'CALLER_EXIT'. "slis_ev_caller_exit_at_start事件
gs_event
-FORM = 'FM_BUTTON'.
APPEND gs_event TO gt_event .
ENDFORM.
FORM fm_button USING e_grid TYPE slis_data_caller_exit.
DATA gt_event_receiver TYPE REF TO lcl_event_receiver .
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid
= ref_grid.
*设置Dropdown List事件
CALL METHOD ref_grid->set_drop_down_table
EXPORTING
it_drop_down
= gt_ddval.
* 设置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.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form BRING_MAKTX
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
DATA: p-maktx TYPE makt-maktx,
p
-matnr TYPE makt-matnr.
FORM BRING_MAKTX .
SELECT SINGLE maktx INTO p-maktx From makt WHERE matnr = p-matnr.
ENDFORM.
*&---------------------------------------------------------------------*
*& Module LISTBOX_MATNR OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE LISTBOX_MATNR OUTPUT.
TYPE-POOLS vrm.
DATA: vid TYPE vrm_id VALUE 'P-MATNR',
vlist
TYPE vrm_values,
l_matnr
TYPE mara-matnr,
values
LIKE LINE OF vlist.
CLEAR vlist.
CLEAR values.
SELECT DISTINCT matnr INTO l_matnr FROM mara UP TO 10 ROWS WHERE matnr LIKE 'AA%'.
values
-key = l_matnr.
APPEND values TO vlist.
CLEAR values.
ENDSELECT.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = vid
values
= vlist
EXCEPTIONS
id_illegal_name
= 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE '下拉框出错,请联系管理员!' TYPE 'I' DISPLAY LIKE 'S'.
ENDIF.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_9000 OUTPUT.
SET PF-STATUS 'AG2'.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9000 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_9000 INPUT.
DATA lv_ok(3).
lv_ok
= ok_code.
CASE lv_ok.
WHEN 'YES' OR '&F1' OR 'CAN'.
LEAVE TO SCREEN 0.
WHEN 'ENT'.
PERFORM bring_maktx.
WHEN OTHERS.
ENDCASE.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Form SAVE_MATNR
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM SAVE_MATNR .
LOOP AT t_result INTO w_result WHERE ckbox = 'X'.
w_result
-matnr = p-matnr.
w_result
-dlmatnr = p-matnr.
w_result
-maktx = p-maktx.
MODIFY t_result FROM w_result.
CLEAR w_result.
ENDLOOP.
CLEAR ref_grid.
CLEAR stbl.
stbl
-col = 'X'.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid
= ref_grid.
CALL METHOD ref_grid->check_changed_data.
CALL METHOD ref_grid->refresh_table_display
EXPORTING
is_stable
= stbl
i_soft_refresh
= 'X'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form CREATE_DROPDOWN_VALUES
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CREATE_DROPDOWN_VALUES .
CLEAR w_result.
DATA: l_line TYPE i VALUE 0,
l_matnr
TYPE makt-matnr.
LOOP AT t_result INTO w_result.
ADD 1 TO l_line.
SELECT DISTINCT matnr INTO l_matnr UP TO 10 ROWS FROM makt WHERE matnr LIKE 'AA%'.
gw_ddval
-handle = l_line.
gw_ddval
-value = l_matnr.
APPEND gw_ddval TO gt_ddval.
ENDSELECT.
CLEAR gw_ddval.
w_result
-dd_handle = l_line.
MODIFY t_result FROM w_result.
CLEAR w_result.
ENDLOOP.
ENDFORM.
9.设置屏幕显示字段名称: