1.准备工作
首先SE11自建一个数据库表(数据元素,域信息请提前建好)
2.编写代码
2.1 新建一个子屏幕
子屏幕中需新定义一个文本输入框,命名为:key_word,新建一个表控件,命名为tab,该表控件的字段选取自建表zchenh001上的所有字段。
可以在“元素清单”界面调整字段显示的宽度,这样更美观:
2.2 拷贝状态栏
SE41 -> 状态
从 程序:SAPLKKBL
状态:STANDARD_FULLSCREEN
到 程序:你的程序
状态:你的程序中需要使用的状态及自定义按钮
2.3 子屏幕的逻辑流
PROCESS BEFORE OUTPUT. MODULE tab_init.
MODULE status_0100.
LOOP AT g_tab_itab
INTO g_tab_wa
WITH CONTROL tab
CURSOR tab-current_line.
MODULE tab_move.
ENDLOOP. PROCESS AFTER INPUT.
MODULE user_command_0100.
LOOP AT g_tab_itab.
CHAIN.
FIELD zchenh001-znum.
FIELD zchenh001-zname.
FIELD zchenh001-zsex.
FIELD zchenh001-zhigh.
ENDCHAIN.
ENDLOOP.
2.4 se38编写代码
*&---------------------------------------------------------------------*
*& Report ZCHENH039
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------* REPORT zchenh039. TABLES: zchenh001. TYPES: BEGIN OF t_tab,
znum LIKE zchenh001-znum,
zname LIKE zchenh001-zname,
zsex LIKE zchenh001-zsex,
zhigh LIKE zchenh001-zhigh,
END OF t_tab. DATA: gt_tab_itab TYPE t_tab OCCURS ,
g_tab_itab TYPE t_tab OCCURS WITH HEADER LINE,
g_tab_wa TYPE t_tab. "work area
DATA: g_tab_copied. "copy flag
DATA: key_word(). CONTROLS: tab TYPE TABLEVIEW USING SCREEN . START-OF-SELECTION.
CALL SCREEN . *----------------------------------------------------------------------*
* MODULE TAB_INIT OUTPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE tab_init OUTPUT.
SELECT * FROM zchenh001
INTO CORRESPONDING FIELDS OF TABLE gt_tab_itab.
IF g_tab_copied IS INITIAL.
PERFORM frm_get_data.
g_tab_copied = 'X'.
REFRESH CONTROL 'TAB' FROM SCREEN ''.
ENDIF. ENDMODULE. "TAB_INIT OUTPUT *----------------------------------------------------------------------*
* MODULE TAB_MOVE OUTPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE tab_move OUTPUT.
MOVE-CORRESPONDING g_tab_wa TO zchenh001.
ENDMODULE. "TAB_MOVE OUTPUT
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'ZCHENH039'.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
WHEN 'EXIT' OR '&F03' OR '&F15' OR '&F12'.
LEAVE PROGRAM.
WHEN 'SEARCH'.
PERFORM frm_get_data.
WHEN OTHERS.
ENDCASE. ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form FRM_GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_get_data .
DATA:ls_tab TYPE t_tab,
lv_len TYPE string,
lv_msg().
* 从内表中取数,减少重复使用数据库的操作
g_tab_itab[] = gt_tab_itab[].
" 此处 模糊查询 LIKE '% ... %' 不适用
IF key_word IS NOT INITIAL.
LOOP AT g_tab_itab WHERE znum NS key_word
AND zname NS key_word
AND zsex NS key_word
AND zhigh NS key_word.
DELETE g_tab_itab.
ENDLOOP.
ENDIF.
DESCRIBE TABLE g_tab_itab LINES lv_len.
CONCATENATE '本次供查询到:' lv_len '条数据!' INTO lv_msg.
MESSAGE lv_msg TYPE 'S'. ENDFORM. " FRM_GET_DATA
3. 验证效果
默认为空则查询所有
查询所有“男”性