—恢复内容开始—
业务背景:
有时候我们可能对自建屏幕上的字段要进行双击操作,要触发自建屏幕的双击需要设置一些东西,本文将介绍一种触发自建屏幕字段双击的例子。
解决步骤
- 新建一个程序,然后再新建一个屏幕,注意勾选回应双击
- 处理屏幕的PBO和PAI,设置STATUS和USER_COMMOND.
-
1 PROCESS BEFORE OUTPUT. 2 *&SPWIZARD: PBO FLOW LOGIC FOR TABLECONTROL 'ZTAB_CTRL' 3 MODULE ZTAB_CTRL_INIT. 4 *&SPWIZARD: MODULE ZTAB_CTRL_CHANGE_TC_ATTR. 5 *&SPWIZARD: MODULE ZTAB_CTRL_CHANGE_COL_ATTR. 6 LOOP AT G_ZTAB_CTRL_ITAB 7 INTO G_ZTAB_CTRL_WA 8 WITH CONTROL ZTAB_CTRL 9 CURSOR ZTAB_CTRL-CURRENT_LINE. 10 *&SPWIZARD: MODULE ZTAB_CTRL_CHANGE_FIELD_ATTR 11 MODULE ZTAB_CTRL_MOVE. 12 MODULE ZTAB_CTRL_GET_LINES. 13 ENDLOOP. 14 15 MODULE STATUS_0100. 16 17 PROCESS AFTER INPUT. 18 *&SPWIZARD: PAI FLOW LOGIC FOR TABLECONTROL 'ZTAB_CTRL' 19 LOOP AT G_ZTAB_CTRL_ITAB. 20 CHAIN. 21 FIELD ZTIF_LOG-ZIFID. 22 FIELD ZTIF_LOG-ZIFNO. 23 FIELD ZTIF_LOG-TYPE. 24 FIELD ZTIF_LOG-CRDAT. 25 FIELD ZTIF_LOG-CRTIM. 26 FIELD ZTIF_LOG-ZBZNO. 27 MODULE ZTAB_CTRL_MODIFY ON CHAIN-REQUEST. 28 ENDCHAIN. 29 ENDLOOP. 30 MODULE ZTAB_CTRL_USER_COMMAND. 31 *&SPWIZARD: MODULE ZTAB_CTRL_CHANGE_TC_ATTR. 32 *&SPWIZARD: MODULE ZTAB_CTRL_CHANGE_COL_ATTR. 33 34 MODULE USER_COMMAND_0100.
其中模块STATUS_0100和USER_COMMAND_0100是需要我们完成的,其他字段皆是TAB_CTRL向导模式生成的。
- 设置STATUS,注意设置F2(鼠标双击,这是一个SAP预设的功能)的功能码(其实我们注意观察的话,可以看到标准的SAP STATUS都是设置了F2的功能码的)
- 编写逻辑代码
1 *&---------------------------------------------------------------------* 2 *& Report ZTEST016 3 *&---------------------------------------------------------------------* 4 *& 5 *&---------------------------------------------------------------------* 6 REPORT ztest016. 7 8 ***&SPWIZARD: DATA DECLARATION FOR TABLECONTROL 'ZTAB_CTRL' 9 *&SPWIZARD: DEFINITION OF DDIC-TABLE 10 TABLES: ztif_log. 11 12 *&SPWIZARD: TYPE FOR THE DATA OF TABLECONTROL 'ZTAB_CTRL' 13 TYPES: BEGIN OF t_ztab_ctrl, 14 zifid LIKE ztif_log-zifid, 15 zifno LIKE ztif_log-zifno, 16 type LIKE ztif_log-type, 17 crdat LIKE ztif_log-crdat, 18 crtim LIKE ztif_log-crtim, 19 zbzno LIKE ztif_log-zbzno, 20 END OF t_ztab_ctrl. 21 22 *&SPWIZARD: INTERNAL TABLE FOR TABLECONTROL 'ZTAB_CTRL' 23 DATA: g_ztab_ctrl_itab TYPE t_ztab_ctrl OCCURS 0, 24 g_ztab_ctrl_wa TYPE t_ztab_ctrl. "work area 25 DATA: g_ztab_ctrl_copied. "copy flag 26 27 *&SPWIZARD: DECLARATION OF TABLECONTROL 'ZTAB_CTRL' ITSELF 28 CONTROLS: ztab_ctrl TYPE TABLEVIEW USING SCREEN 0100. 29 30 *&SPWIZARD: LINES OF TABLECONTROL 'ZTAB_CTRL' 31 DATA: g_ztab_ctrl_lines LIKE sy-loopc. 32 33 DATA: ok_code LIKE sy-ucomm. 34 35 *&---调用屏幕 36 CALL SCREEN 100. 37 *&---------------------------------------------------------------------* 38 *& Module STATUS_0100 OUTPUT 39 *&---------------------------------------------------------------------* 40 *& 41 *&---------------------------------------------------------------------* 42 MODULE status_0100 OUTPUT. 43 SET PF-STATUS 'STATUS'. 44 * SET TITLEBAR 'xxx'. 45 ENDMODULE. 46 47 *&---------------------------------------------------------------------* 48 *& Module USER_COMMAND_0100 INPUT 49 *&---------------------------------------------------------------------* 50 * text 51 *----------------------------------------------------------------------* 52 MODULE user_command_0100 INPUT. 53 DATA: lv_okcode TYPE sy-ucomm, 54 lv_sfield TYPE screen-name, "屏幕字段 55 lv_vfield1 TYPE char30, "值字段 56 lv_vfield2 TYPE char30, 57 lv_line TYPE i, 58 lv_msg TYPE string. 59 60 FIELD-SYMBOLS: <fs> TYPE any. 61 62 lv_okcode = sy-ucomm. 63 64 CASE lv_okcode. 65 WHEN '&IC1'. 66 GET CURSOR FIELD lv_sfield LINE lv_line. 67 SPLIT lv_sfield AT '-' INTO lv_vfield1 lv_vfield2. 68 69 READ TABLE g_ztab_ctrl_itab INTO g_ztab_ctrl_wa INDEX lv_line. 70 IF sy-subrc = 0. 71 ASSIGN COMPONENT lv_vfield2 OF STRUCTURE g_ztab_ctrl_wa TO <fs>. 72 IF <fs> IS ASSIGNED. 73 lv_msg = '我被双击了! Give Me Five!我的值是:' && <fs>. 74 MESSAGE lv_msg TYPE 'I'. 75 ENDIF. 76 ENDIF. 77 WHEN '&F03'. 78 LEAVE TO SCREEN 0. 79 WHEN '&F04' OR '&F05'. 80 LEAVE PROGRAM. 81 WHEN OTHERS. 82 ENDCASE. 83 ENDMODULE. 84 85 *&SPWIZARD: OUTPUT MODULE FOR TC 'ZTAB_CTRL'. DO NOT CHANGE THIS LINE! 86 *&SPWIZARD: COPY DDIC-TABLE TO ITAB 87 MODULE ztab_ctrl_init OUTPUT. 88 IF g_ztab_ctrl_copied IS INITIAL. 89 *&SPWIZARD: COPY DDIC-TABLE 'ZTIF_LOG' 90 *&SPWIZARD: INTO INTERNAL TABLE 'g_ZTAB_CTRL_itab' 91 SELECT * FROM ztif_log 92 INTO CORRESPONDING FIELDS 93 OF TABLE g_ztab_ctrl_itab. 94 g_ztab_ctrl_copied = 'X'. 95 REFRESH CONTROL 'ZTAB_CTRL' FROM SCREEN '0100'. 96 ENDIF. 97 ENDMODULE. 98 99 *&SPWIZARD: OUTPUT MODULE FOR TC 'ZTAB_CTRL'. DO NOT CHANGE THIS LINE! 100 *&SPWIZARD: MOVE ITAB TO DYNPRO 101 MODULE ztab_ctrl_move OUTPUT. 102 MOVE-CORRESPONDING g_ztab_ctrl_wa TO ztif_log. 103 ENDMODULE. 104 105 *&SPWIZARD: OUTPUT MODULE FOR TC 'ZTAB_CTRL'. DO NOT CHANGE THIS LINE! 106 *&SPWIZARD: GET LINES OF TABLECONTROL 107 MODULE ztab_ctrl_get_lines OUTPUT. 108 g_ztab_ctrl_lines = sy-loopc. 109 ENDMODULE. 110 111 *&SPWIZARD: INPUT MODULE FOR TC 'ZTAB_CTRL'. DO NOT CHANGE THIS LINE! 112 *&SPWIZARD: MODIFY TABLE 113 MODULE ztab_ctrl_modify INPUT. 114 MOVE-CORRESPONDING ztif_log TO g_ztab_ctrl_wa. 115 MODIFY g_ztab_ctrl_itab 116 FROM g_ztab_ctrl_wa 117 INDEX ztab_ctrl-current_line. 118 ENDMODULE. 119 120 *&SPWIZARD: INPUT MODULE FOR TC 'ZTAB_CTRL'. DO NOT CHANGE THIS LINE! 121 *&SPWIZARD: PROCESS USER COMMAND 122 MODULE ztab_ctrl_user_command INPUT. 123 ok_code = sy-ucomm. 124 PERFORM user_ok_tc USING 'ZTAB_CTRL' 125 'G_ZTAB_CTRL_ITAB' 126 'FLAG' 127 CHANGING ok_code. 128 sy-ucomm = ok_code. 129 ENDMODULE. 130 131 *----------------------------------------------------------------------* 132 * INCLUDE TABLECONTROL_FORMS * 133 *----------------------------------------------------------------------* 134 135 *&---------------------------------------------------------------------* 136 *& Form USER_OK_TC * 137 *&---------------------------------------------------------------------* 138 FORM user_ok_tc USING p_tc_name TYPE dynfnam 139 p_table_name 140 p_mark_name 141 CHANGING p_ok LIKE sy-ucomm. 142 143 *&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------* 144 DATA: l_ok TYPE sy-ucomm, 145 l_offset TYPE i. 146 *&SPWIZARD: END OF LOCAL DATA------------------------------------------* 147 148 *&SPWIZARD: Table control specific operations * 149 *&SPWIZARD: evaluate TC name and operations * 150 SEARCH p_ok FOR p_tc_name. 151 IF sy-subrc <> 0. 152 EXIT. 153 ENDIF. 154 l_offset = strlen( p_tc_name ) + 1. 155 l_ok = p_ok+l_offset. 156 *&SPWIZARD: execute general and TC specific operations * 157 CASE l_ok. 158 WHEN 'INSR'. "insert row 159 PERFORM fcode_insert_row USING p_tc_name 160 p_table_name. 161 CLEAR p_ok. 162 163 WHEN 'DELE'. "delete row 164 PERFORM fcode_delete_row USING p_tc_name 165 p_table_name 166 p_mark_name. 167 CLEAR p_ok. 168 169 WHEN 'P--' OR "top of list 170 'P-' OR "previous page 171 'P+' OR "next page 172 'P++'. "bottom of list 173 PERFORM compute_scrolling_in_tc USING p_tc_name 174 l_ok. 175 CLEAR p_ok. 176 * WHEN 'L--'. "total left 177 * PERFORM FCODE_TOTAL_LEFT USING P_TC_NAME. 178 * 179 * WHEN 'L-'. "column left 180 * PERFORM FCODE_COLUMN_LEFT USING P_TC_NAME. 181 * 182 * WHEN 'R+'. "column right 183 * PERFORM FCODE_COLUMN_RIGHT USING P_TC_NAME. 184 * 185 * WHEN 'R++'. "total right 186 * PERFORM FCODE_TOTAL_RIGHT USING P_TC_NAME. 187 * 188 WHEN 'MARK'. "mark all filled lines 189 PERFORM fcode_tc_mark_lines USING p_tc_name 190 p_table_name 191 p_mark_name . 192 CLEAR p_ok. 193 194 WHEN 'DMRK'. "demark all filled lines 195 PERFORM fcode_tc_demark_lines USING p_tc_name 196 p_table_name 197 p_mark_name . 198 CLEAR p_ok. 199 200 * WHEN 'SASCEND' OR 201 * 'SDESCEND'. "sort column 202 * PERFORM FCODE_SORT_TC USING P_TC_NAME 203 * l_ok. 204 205 ENDCASE. 206 207 ENDFORM. " USER_OK_TC 208 209 *&---------------------------------------------------------------------* 210 *& Form FCODE_INSERT_ROW * 211 *&---------------------------------------------------------------------* 212 FORM fcode_insert_row 213 USING p_tc_name TYPE dynfnam 214 p_table_name . 215 216 *&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------* 217 DATA l_lines_name LIKE feld-name. 218 DATA l_selline LIKE sy-stepl. 219 DATA l_lastline TYPE i. 220 DATA l_line TYPE i. 221 DATA l_table_name LIKE feld-name. 222 FIELD-SYMBOLS <tc> TYPE cxtab_control. 223 FIELD-SYMBOLS <table> TYPE STANDARD TABLE. 224 FIELD-SYMBOLS <lines> TYPE i. 225 *&SPWIZARD: END OF LOCAL DATA------------------------------------------* 226 227 ASSIGN (p_tc_name) TO <tc>. 228 229 *&SPWIZARD: get the table, which belongs to the tc * 230 CONCATENATE p_table_name '[]' INTO l_table_name. "table body 231 ASSIGN (l_table_name) TO <table>. "not headerline 232 233 *&SPWIZARD: get looplines of TableControl * 234 CONCATENATE 'G_' p_tc_name '_LINES' INTO l_lines_name. 235 ASSIGN (l_lines_name) TO <lines>. 236 237 *&SPWIZARD: get current line * 238 GET CURSOR LINE l_selline. 239 IF sy-subrc <> 0. " append line to table 240 l_selline = <tc>-lines + 1. 241 *&SPWIZARD: set top line * 242 IF l_selline > <lines>. 243 <tc>-top_line = l_selline - <lines> + 1 . 244 ELSE. 245 <tc>-top_line = 1. 246 ENDIF. 247 ELSE. " insert line into table 248 l_selline = <tc>-top_line + l_selline - 1. 249 l_lastline = <tc>-top_line + <lines> - 1. 250 ENDIF. 251 *&SPWIZARD: set new cursor line * 252 l_line = l_selline - <tc>-top_line + 1. 253 254 *&SPWIZARD: insert initial line * 255 INSERT INITIAL LINE INTO <table> INDEX l_selline. 256 <tc>-lines = <tc>-lines + 1. 257 *&SPWIZARD: set cursor * 258 SET CURSOR LINE l_line. 259 260 ENDFORM. " FCODE_INSERT_ROW 261 262 *&---------------------------------------------------------------------* 263 *& Form FCODE_DELETE_ROW * 264 *&---------------------------------------------------------------------* 265 FORM fcode_delete_row 266 USING p_tc_name TYPE dynfnam 267 p_table_name 268 p_mark_name . 269 270 *&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------* 271 DATA l_table_name LIKE feld-name. 272 273 FIELD-SYMBOLS <tc> TYPE cxtab_control. 274 FIELD-SYMBOLS <table> TYPE STANDARD TABLE. 275 FIELD-SYMBOLS <wa>. 276 FIELD-SYMBOLS <mark_field>. 277 *&SPWIZARD: END OF LOCAL DATA------------------------------------------* 278 279 ASSIGN (p_tc_name) TO <tc>. 280 281 *&SPWIZARD: get the table, which belongs to the tc * 282 CONCATENATE p_table_name '[]' INTO l_table_name. "table body 283 ASSIGN (l_table_name) TO <table>. "not headerline 284 285 *&SPWIZARD: delete marked lines * 286 DESCRIBE TABLE <table> LINES <tc>-lines. 287 288 LOOP AT <table> ASSIGNING <wa>. 289 290 *&SPWIZARD: access to the component 'FLAG' of the table header * 291 ASSIGN COMPONENT p_mark_name OF STRUCTURE <wa> TO <mark_field>. 292 293 IF <mark_field> = 'X'. 294 DELETE <table> INDEX syst-tabix. 295 IF sy-subrc = 0. 296 <tc>-lines = <tc>-lines - 1. 297 ENDIF. 298 ENDIF. 299 ENDLOOP. 300 301 ENDFORM. " FCODE_DELETE_ROW 302 303 *&---------------------------------------------------------------------* 304 *& Form COMPUTE_SCROLLING_IN_TC 305 *&---------------------------------------------------------------------* 306 * text 307 *----------------------------------------------------------------------* 308 * -->P_TC_NAME name of tablecontrol 309 * -->P_OK ok code 310 *----------------------------------------------------------------------* 311 FORM compute_scrolling_in_tc USING p_tc_name 312 p_ok. 313 *&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------* 314 DATA l_tc_new_top_line TYPE i. 315 DATA l_tc_name LIKE feld-name. 316 DATA l_tc_lines_name LIKE feld-name. 317 DATA l_tc_field_name LIKE feld-name. 318 319 FIELD-SYMBOLS <tc> TYPE cxtab_control. 320 FIELD-SYMBOLS <lines> TYPE i. 321 *&SPWIZARD: END OF LOCAL DATA------------------------------------------* 322 323 ASSIGN (p_tc_name) TO <tc>. 324 *&SPWIZARD: get looplines of TableControl * 325 CONCATENATE 'G_' p_tc_name '_LINES' INTO l_tc_lines_name. 326 ASSIGN (l_tc_lines_name) TO <lines>. 327 328 329 *&SPWIZARD: is no line filled? * 330 IF <tc>-lines = 0. 331 *&SPWIZARD: yes, ... * 332 l_tc_new_top_line = 1. 333 ELSE. 334 *&SPWIZARD: no, ... * 335 CALL FUNCTION 'SCROLLING_IN_TABLE' 336 EXPORTING 337 entry_act = <tc>-top_line 338 entry_from = 1 339 entry_to = <tc>-lines 340 last_page_full = 'X' 341 loops = <lines> 342 ok_code = p_ok 343 overlapping = 'X' 344 IMPORTING 345 entry_new = l_tc_new_top_line 346 EXCEPTIONS 347 * NO_ENTRY_OR_PAGE_ACT = 01 348 * NO_ENTRY_TO = 02 349 * NO_OK_CODE_OR_PAGE_GO = 03 350 OTHERS = 0. 351 ENDIF. 352 353 *&SPWIZARD: get actual tc and column * 354 GET CURSOR FIELD l_tc_field_name 355 AREA l_tc_name. 356 357 IF syst-subrc = 0. 358 IF l_tc_name = p_tc_name. 359 *&SPWIZARD: et actual column * 360 SET CURSOR FIELD l_tc_field_name LINE 1. 361 ENDIF. 362 ENDIF. 363 364 *&SPWIZARD: set the new top line * 365 <tc>-top_line = l_tc_new_top_line. 366 367 368 ENDFORM. " COMPUTE_SCROLLING_IN_TC 369 370 *&---------------------------------------------------------------------* 371 *& Form FCODE_TC_MARK_LINES 372 *&---------------------------------------------------------------------* 373 * marks all TableControl lines 374 *----------------------------------------------------------------------* 375 * -->P_TC_NAME name of tablecontrol 376 *----------------------------------------------------------------------* 377 FORM fcode_tc_mark_lines USING p_tc_name 378 p_table_name 379 p_mark_name. 380 *&SPWIZARD: EGIN OF LOCAL DATA-----------------------------------------* 381 DATA l_table_name LIKE feld-name. 382 383 FIELD-SYMBOLS <tc> TYPE cxtab_control. 384 FIELD-SYMBOLS <table> TYPE STANDARD TABLE. 385 FIELD-SYMBOLS <wa>. 386 FIELD-SYMBOLS <mark_field>. 387 *&SPWIZARD: END OF LOCAL DATA------------------------------------------* 388 389 ASSIGN (p_tc_name) TO <tc>. 390 391 *&SPWIZARD: get the table, which belongs to the tc * 392 CONCATENATE p_table_name '[]' INTO l_table_name. "table body 393 ASSIGN (l_table_name) TO <table>. "not headerline 394 395 *&SPWIZARD: mark all filled lines * 396 LOOP AT <table> ASSIGNING <wa>. 397 398 *&SPWIZARD: access to the component 'FLAG' of the table header * 399 ASSIGN COMPONENT p_mark_name OF STRUCTURE <wa> TO <mark_field>. 400 401 <mark_field> = 'X'. 402 ENDLOOP. 403 ENDFORM. "fcode_tc_mark_lines 404 405 *&---------------------------------------------------------------------* 406 *& Form FCODE_TC_DEMARK_LINES 407 *&---------------------------------------------------------------------* 408 * demarks all TableControl lines 409 *----------------------------------------------------------------------* 410 * -->P_TC_NAME name of tablecontrol 411 *----------------------------------------------------------------------* 412 FORM fcode_tc_demark_lines USING p_tc_name 413 p_table_name 414 p_mark_name . 415 *&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------* 416 DATA l_table_name LIKE feld-name. 417 418 FIELD-SYMBOLS <tc> TYPE cxtab_control. 419 FIELD-SYMBOLS <table> TYPE STANDARD TABLE. 420 FIELD-SYMBOLS <wa>. 421 FIELD-SYMBOLS <mark_field>. 422 *&SPWIZARD: END OF LOCAL DATA------------------------------------------* 423 424 ASSIGN (p_tc_name) TO <tc>. 425 426 *&SPWIZARD: get the table, which belongs to the tc * 427 CONCATENATE p_table_name '[]' INTO l_table_name. "table body 428 ASSIGN (l_table_name) TO <table>. "not headerline 429 430 *&SPWIZARD: demark all filled lines * 431 LOOP AT <table> ASSIGNING <wa>. 432 433 *&SPWIZARD: access to the component 'FLAG' of the table header * 434 ASSIGN COMPONENT p_mark_name OF STRUCTURE <wa> TO <mark_field>. 435 436 <mark_field> = space. 437 ENDLOOP. 438 ENDFORM. "fcode_tc_mark_lines
- 效果展示
—恢复内容结束—
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/19348.html