1.准备工作
首先SE11自建一个数据库表(数据元素,域信息请提前建好)
2.编写代码
2.1 新建一个子屏幕
子屏幕中需新定义一个文本输入框,命名为:key_word,新建一个表控件,命名为tab,该表控件的字段选取自建表zchenh001上的所有字段。
可以在“元素清单”界面调整字段显示的宽度,这样更美观:
2.2 拷贝状态栏
SE41 -> 状态
从 程序:SAPLKKBL
状态:STANDARD_FULLSCREEN
到 程序:你的程序
状态:你的程序中需要使用的状态及自定义按钮
2.3 子屏幕的逻辑流
1 PROCESS BEFORE OUTPUT. 2 3 MODULE tab_init. 4 MODULE status_0100. 5 LOOP AT g_tab_itab 6 INTO g_tab_wa 7 WITH CONTROL tab 8 CURSOR tab-current_line. 9 MODULE tab_move. 10 ENDLOOP. 11 12 13 14 PROCESS AFTER INPUT. 15 MODULE user_command_0100. 16 LOOP AT g_tab_itab. 17 CHAIN. 18 FIELD zchenh001-znum. 19 FIELD zchenh001-zname. 20 FIELD zchenh001-zsex. 21 FIELD zchenh001-zhigh. 22 ENDCHAIN. 23 ENDLOOP.
View Code
2.4 se38编写代码
1 *&---------------------------------------------------------------------* 2 *& Report ZCHENH039 3 *& 4 *&---------------------------------------------------------------------* 5 *& 6 *& 7 *&---------------------------------------------------------------------* 8 9 REPORT zchenh039. 10 11 TABLES: zchenh001. 12 13 TYPES: BEGIN OF t_tab, 14 znum LIKE zchenh001-znum, 15 zname LIKE zchenh001-zname, 16 zsex LIKE zchenh001-zsex, 17 zhigh LIKE zchenh001-zhigh, 18 END OF t_tab. 19 20 DATA: gt_tab_itab TYPE t_tab OCCURS 0, 21 g_tab_itab TYPE t_tab OCCURS 0 WITH HEADER LINE, 22 g_tab_wa TYPE t_tab. "work area 23 DATA: g_tab_copied. "copy flag 24 DATA: key_word(20). 25 26 CONTROLS: tab TYPE TABLEVIEW USING SCREEN 0100. 27 28 START-OF-SELECTION. 29 CALL SCREEN 100. 30 31 *----------------------------------------------------------------------* 32 * MODULE TAB_INIT OUTPUT 33 *----------------------------------------------------------------------* 34 * 35 *----------------------------------------------------------------------* 36 MODULE tab_init OUTPUT. 37 SELECT * FROM zchenh001 38 INTO CORRESPONDING FIELDS OF TABLE gt_tab_itab. 39 IF g_tab_copied IS INITIAL. 40 PERFORM frm_get_data. 41 g_tab_copied = 'X'. 42 REFRESH CONTROL 'TAB' FROM SCREEN '0100'. 43 ENDIF. 44 45 ENDMODULE. "TAB_INIT OUTPUT 46 47 *----------------------------------------------------------------------* 48 * MODULE TAB_MOVE OUTPUT 49 *----------------------------------------------------------------------* 50 * 51 *----------------------------------------------------------------------* 52 MODULE tab_move OUTPUT. 53 MOVE-CORRESPONDING g_tab_wa TO zchenh001. 54 ENDMODULE. "TAB_MOVE OUTPUT 55 *&---------------------------------------------------------------------* 56 *& Module STATUS_0100 OUTPUT 57 *&---------------------------------------------------------------------* 58 * text 59 *----------------------------------------------------------------------* 60 MODULE status_0100 OUTPUT. 61 SET PF-STATUS 'ZCHENH039'. 62 ENDMODULE. " STATUS_0100 OUTPUT 63 *&---------------------------------------------------------------------* 64 *& Module USER_COMMAND_0100 INPUT 65 *&---------------------------------------------------------------------* 66 * text 67 *----------------------------------------------------------------------* 68 MODULE user_command_0100 INPUT. 69 CASE sy-ucomm. 70 WHEN 'EXIT' OR '&F03' OR '&F15' OR '&F12'. 71 LEAVE PROGRAM. 72 WHEN 'SEARCH'. 73 PERFORM frm_get_data. 74 WHEN OTHERS. 75 ENDCASE. 76 77 ENDMODULE. " USER_COMMAND_0100 INPUT 78 *&---------------------------------------------------------------------* 79 *& Form FRM_GET_DATA 80 *&---------------------------------------------------------------------* 81 * text 82 *----------------------------------------------------------------------* 83 * --> p1 text 84 * <-- p2 text 85 *----------------------------------------------------------------------* 86 FORM frm_get_data . 87 DATA:ls_tab TYPE t_tab, 88 lv_len TYPE string, 89 lv_msg(255). 90 * 从内表中取数,减少重复使用数据库的操作 91 g_tab_itab[] = gt_tab_itab[]. 92 " 此处 模糊查询 LIKE '% ... %' 不适用 93 IF key_word IS NOT INITIAL. 94 LOOP AT g_tab_itab WHERE znum NS key_word 95 AND zname NS key_word 96 AND zsex NS key_word 97 AND zhigh NS key_word. 98 DELETE g_tab_itab. 99 ENDLOOP. 100 ENDIF. 101 DESCRIBE TABLE g_tab_itab LINES lv_len. 102 CONCATENATE '本次供查询到:' lv_len '条数据!' INTO lv_msg. 103 MESSAGE lv_msg TYPE 'S'. 104 105 ENDFORM. " FRM_GET_DATA
View Code
3. 验证效果
默认为空则查询所有
查询所有“男”性
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/18028.html