业务背景:
有时候我们可能对自建屏幕上的字段要进行双击操作,要触发自建屏幕的双击需要设置一些东西,本文将介绍一种触发自建屏幕字段双击的例子。
- 解决步骤
- 新建一个程序,然后再新建一个屏幕,注意勾选回应双击
- 处理屏幕的PBO和PAI,设置STATUS和USER_COMMOND。
12345678910111213141516171819202122232425262728293031323334PROCESS BEFORE OUTPUT.*&SPWIZARD: PBO FLOW LOGIC FOR TABLECONTROL 'ZTAB_CTRL'MODULE ZTAB_CTRL_INIT.*&SPWIZARD: MODULE ZTAB_CTRL_CHANGE_TC_ATTR.*&SPWIZARD: MODULE ZTAB_CTRL_CHANGE_COL_ATTR.LOOP AT G_ZTAB_CTRL_ITABINTO G_ZTAB_CTRL_WAWITH CONTROL ZTAB_CTRLCURSOR ZTAB_CTRL-CURRENT_LINE.*&SPWIZARD: MODULE ZTAB_CTRL_CHANGE_FIELD_ATTRMODULE ZTAB_CTRL_MOVE.MODULE ZTAB_CTRL_GET_LINES.ENDLOOP.MODULE STATUS_0100.PROCESS AFTER INPUT.*&SPWIZARD: PAI FLOW LOGIC FOR TABLECONTROL 'ZTAB_CTRL'LOOP AT G_ZTAB_CTRL_ITAB.CHAIN.FIELD ZTIF_LOG-ZIFID.FIELD ZTIF_LOG-ZIFNO.FIELD ZTIF_LOG-TYPE.FIELD ZTIF_LOG-CRDAT.FIELD ZTIF_LOG-CRTIM.FIELD ZTIF_LOG-ZBZNO.MODULE ZTAB_CTRL_MODIFY ON CHAIN-REQUEST.ENDCHAIN.ENDLOOP.MODULE ZTAB_CTRL_USER_COMMAND.*&SPWIZARD: MODULE ZTAB_CTRL_CHANGE_TC_ATTR.*&SPWIZARD: MODULE ZTAB_CTRL_CHANGE_COL_ATTR.MODULE USER_COMMAND_0100.
其中模块STATUS_0100和USER_COMMAND_0100是需要我们完成的,其他字段皆是TAB_CTRL向导模式生成的。 - 设置STATUS,注意设置F2(鼠标双击,这是一个SAP预设的功能)的功能码(其实我们注意观察的话,可以看到标准的SAP STATUS都是设置了F2的功能码的)
- 编写逻辑代码
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438*&---------------------------------------------------------------------**& Report ZTEST016*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT ztest016.***&SPWIZARD: DATA DECLARATION FOR TABLECONTROL 'ZTAB_CTRL'*&SPWIZARD: DEFINITION OF DDIC-TABLETABLES: ztif_log.*&SPWIZARD: TYPE FOR THE DATA OF TABLECONTROL 'ZTAB_CTRL'TYPES: BEGIN OF t_ztab_ctrl,zifid LIKE ztif_log-zifid,zifno LIKE ztif_log-zifno,type LIKE ztif_log-type,crdat LIKE ztif_log-crdat,crtim LIKE ztif_log-crtim,zbzno LIKE ztif_log-zbzno,END OF t_ztab_ctrl.*&SPWIZARD: INTERNAL TABLE FOR TABLECONTROL 'ZTAB_CTRL'DATA: g_ztab_ctrl_itab TYPE t_ztab_ctrl OCCURS 0,g_ztab_ctrl_wa TYPE t_ztab_ctrl. "work areaDATA: g_ztab_ctrl_copied. "copy flag*&SPWIZARD: DECLARATION OF TABLECONTROL 'ZTAB_CTRL' ITSELFCONTROLS: ztab_ctrl TYPE TABLEVIEW USING SCREEN 0100.*&SPWIZARD: LINES OF TABLECONTROL 'ZTAB_CTRL'DATA: g_ztab_ctrl_lines LIKE sy-loopc.DATA: ok_code LIKE sy-ucomm.*&---调用屏幕CALL SCREEN 100.*&---------------------------------------------------------------------**& Module STATUS_0100 OUTPUT*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*MODULE status_0100 OUTPUT.SET PF-STATUS 'STATUS'.* SET TITLEBAR 'xxx'.ENDMODULE.*&---------------------------------------------------------------------**& Module USER_COMMAND_0100 INPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*MODULE user_command_0100 INPUT.DATA: lv_okcode TYPE sy-ucomm,lv_sfield TYPE screen-name, "屏幕字段lv_vfield1 TYPE char30, "值字段lv_vfield2 TYPE char30,lv_line TYPE i,lv_msg TYPE string.FIELD-SYMBOLS: <fs> TYPE any.lv_okcode = sy-ucomm.CASE lv_okcode.WHEN '&IC1'.GET CURSOR FIELD lv_sfield LINE lv_line.SPLIT lv_sfield AT '-' INTO lv_vfield1 lv_vfield2.READ TABLE g_ztab_ctrl_itab INTO g_ztab_ctrl_wa INDEX lv_line.IF sy-subrc = 0.ASSIGN COMPONENT lv_vfield2 OF STRUCTURE g_ztab_ctrl_wa TO <fs>.IF <fs> IS ASSIGNED.lv_msg = '我被双击了! Give Me Five!我的值是:' && <fs>.MESSAGE lv_msg TYPE 'I'.ENDIF.ENDIF.WHEN '&F03'.LEAVE TO SCREEN 0.WHEN '&F04' OR '&F05'.LEAVE PROGRAM.WHEN OTHERS.ENDCASE.ENDMODULE.*&SPWIZARD: OUTPUT MODULE FOR TC 'ZTAB_CTRL'. DO NOT CHANGE THIS LINE!*&SPWIZARD: COPY DDIC-TABLE TO ITABMODULE ztab_ctrl_init OUTPUT.IF g_ztab_ctrl_copied IS INITIAL.*&SPWIZARD: COPY DDIC-TABLE 'ZTIF_LOG'*&SPWIZARD: INTO INTERNAL TABLE 'g_ZTAB_CTRL_itab'SELECT * FROM ztif_logINTO CORRESPONDING FIELDSOF TABLE g_ztab_ctrl_itab.g_ztab_ctrl_copied = 'X'.REFRESH CONTROL 'ZTAB_CTRL' FROM SCREEN '0100'.ENDIF.ENDMODULE.*&SPWIZARD: OUTPUT MODULE FOR TC 'ZTAB_CTRL'. DO NOT CHANGE THIS LINE!*&SPWIZARD: MOVE ITAB TO DYNPROMODULE ztab_ctrl_move OUTPUT.MOVE-CORRESPONDING g_ztab_ctrl_wa TO ztif_log.ENDMODULE.*&SPWIZARD: OUTPUT MODULE FOR TC 'ZTAB_CTRL'. DO NOT CHANGE THIS LINE!*&SPWIZARD: GET LINES OF TABLECONTROLMODULE ztab_ctrl_get_lines OUTPUT.g_ztab_ctrl_lines = sy-loopc.ENDMODULE.*&SPWIZARD: INPUT MODULE FOR TC 'ZTAB_CTRL'. DO NOT CHANGE THIS LINE!*&SPWIZARD: MODIFY TABLEMODULE ztab_ctrl_modify INPUT.MOVE-CORRESPONDING ztif_log TO g_ztab_ctrl_wa.MODIFY g_ztab_ctrl_itabFROM g_ztab_ctrl_waINDEX ztab_ctrl-current_line.ENDMODULE.*&SPWIZARD: INPUT MODULE FOR TC 'ZTAB_CTRL'. DO NOT CHANGE THIS LINE!*&SPWIZARD: PROCESS USER COMMANDMODULE ztab_ctrl_user_command INPUT.ok_code = sy-ucomm.PERFORM user_ok_tc USING 'ZTAB_CTRL''G_ZTAB_CTRL_ITAB''FLAG'CHANGING ok_code.sy-ucomm = ok_code.ENDMODULE.*----------------------------------------------------------------------** INCLUDE TABLECONTROL_FORMS **----------------------------------------------------------------------**&---------------------------------------------------------------------**& Form USER_OK_TC **&---------------------------------------------------------------------*FORM user_ok_tc USING p_tc_name TYPE dynfnamp_table_namep_mark_nameCHANGING p_ok LIKE sy-ucomm.*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*DATA: l_ok TYPE sy-ucomm,l_offset TYPE i.*&SPWIZARD: END OF LOCAL DATA------------------------------------------**&SPWIZARD: Table control specific operations **&SPWIZARD: evaluate TC name and operations *SEARCH p_ok FOR p_tc_name.IF sy-subrc <> 0.EXIT.ENDIF.l_offset = strlen( p_tc_name ) + 1.l_ok = p_ok+l_offset.*&SPWIZARD: execute general and TC specific operations *CASE l_ok.WHEN 'INSR'. "insert rowPERFORM fcode_insert_row USING p_tc_namep_table_name.CLEAR p_ok.WHEN 'DELE'. "delete rowPERFORM fcode_delete_row USING p_tc_namep_table_namep_mark_name.CLEAR p_ok.WHEN 'P--' OR "top of list'P-' OR "previous page'P+' OR "next page'P++'. "bottom of listPERFORM compute_scrolling_in_tc USING p_tc_namel_ok.CLEAR p_ok.* WHEN 'L--'. "total left* PERFORM FCODE_TOTAL_LEFT USING P_TC_NAME.** WHEN 'L-'. "column left* PERFORM FCODE_COLUMN_LEFT USING P_TC_NAME.** WHEN 'R+'. "column right* PERFORM FCODE_COLUMN_RIGHT USING P_TC_NAME.** WHEN 'R++'. "total right* PERFORM FCODE_TOTAL_RIGHT USING P_TC_NAME.*WHEN 'MARK'. "mark all filled linesPERFORM fcode_tc_mark_lines USING p_tc_namep_table_namep_mark_name .CLEAR p_ok.WHEN 'DMRK'. "demark all filled linesPERFORM fcode_tc_demark_lines USING p_tc_namep_table_namep_mark_name .CLEAR p_ok.* WHEN 'SASCEND' OR* 'SDESCEND'. "sort column* PERFORM FCODE_SORT_TC USING P_TC_NAME* l_ok.ENDCASE.ENDFORM. " USER_OK_TC*&---------------------------------------------------------------------**& Form FCODE_INSERT_ROW **&---------------------------------------------------------------------*FORM fcode_insert_rowUSING p_tc_name TYPE dynfnamp_table_name .*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*DATA l_lines_name LIKE feld-name.DATA l_selline LIKE sy-stepl.DATA l_lastline TYPE i.DATA l_line TYPE i.DATA l_table_name LIKE feld-name.FIELD-SYMBOLS <tc> TYPE cxtab_control.FIELD-SYMBOLS <table> TYPE STANDARD TABLE.FIELD-SYMBOLS <lines> TYPE i.*&SPWIZARD: END OF LOCAL DATA------------------------------------------*ASSIGN (p_tc_name) TO <tc>.*&SPWIZARD: get the table, which belongs to the tc *CONCATENATE p_table_name '[]' INTO l_table_name. "table bodyASSIGN (l_table_name) TO <table>. "not headerline*&SPWIZARD: get looplines of TableControl *CONCATENATE 'G_' p_tc_name '_LINES' INTO l_lines_name.ASSIGN (l_lines_name) TO <lines>.*&SPWIZARD: get current line *GET CURSOR LINE l_selline.IF sy-subrc <> 0. " append line to tablel_selline = <tc>-lines + 1.*&SPWIZARD: set top line *IF l_selline > <lines>.<tc>-top_line = l_selline - <lines> + 1 .ELSE.<tc>-top_line = 1.ENDIF.ELSE. " insert line into tablel_selline = <tc>-top_line + l_selline - 1.l_lastline = <tc>-top_line + <lines> - 1.ENDIF.*&SPWIZARD: set new cursor line *l_line = l_selline - <tc>-top_line + 1.*&SPWIZARD: insert initial line *INSERT INITIAL LINE INTO <table> INDEX l_selline.<tc>-lines = <tc>-lines + 1.*&SPWIZARD: set cursor *SET CURSOR LINE l_line.ENDFORM. " FCODE_INSERT_ROW*&---------------------------------------------------------------------**& Form FCODE_DELETE_ROW **&---------------------------------------------------------------------*FORM fcode_delete_rowUSING p_tc_name TYPE dynfnamp_table_namep_mark_name .*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*DATA l_table_name LIKE feld-name.FIELD-SYMBOLS <tc> TYPE cxtab_control.FIELD-SYMBOLS <table> TYPE STANDARD TABLE.FIELD-SYMBOLS <wa>.FIELD-SYMBOLS <mark_field>.*&SPWIZARD: END OF LOCAL DATA------------------------------------------*ASSIGN (p_tc_name) TO <tc>.*&SPWIZARD: get the table, which belongs to the tc *CONCATENATE p_table_name '[]' INTO l_table_name. "table bodyASSIGN (l_table_name) TO <table>. "not headerline*&SPWIZARD: delete marked lines *DESCRIBE TABLE <table> LINES <tc>-lines.LOOP AT <table> ASSIGNING <wa>.*&SPWIZARD: access to the component 'FLAG' of the table header *ASSIGN COMPONENT p_mark_name OF STRUCTURE <wa> TO <mark_field>.IF <mark_field> = 'X'.DELETE <table> INDEX syst-tabix.IF sy-subrc = 0.<tc>-lines = <tc>-lines - 1.ENDIF.ENDIF.ENDLOOP.ENDFORM. " FCODE_DELETE_ROW*&---------------------------------------------------------------------**& Form COMPUTE_SCROLLING_IN_TC*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** -->P_TC_NAME name of tablecontrol* -->P_OK ok code*----------------------------------------------------------------------*FORM compute_scrolling_in_tc USING p_tc_namep_ok.*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*DATA l_tc_new_top_line TYPE i.DATA l_tc_name LIKE feld-name.DATA l_tc_lines_name LIKE feld-name.DATA l_tc_field_name LIKE feld-name.FIELD-SYMBOLS <tc> TYPE cxtab_control.FIELD-SYMBOLS <lines> TYPE i.*&SPWIZARD: END OF LOCAL DATA------------------------------------------*ASSIGN (p_tc_name) TO <tc>.*&SPWIZARD: get looplines of TableControl *CONCATENATE 'G_' p_tc_name '_LINES' INTO l_tc_lines_name.ASSIGN (l_tc_lines_name) TO <lines>.*&SPWIZARD: is no line filled? *IF <tc>-lines = 0.*&SPWIZARD: yes, ... *l_tc_new_top_line = 1.ELSE.*&SPWIZARD: no, ... *CALL FUNCTION 'SCROLLING_IN_TABLE'EXPORTINGentry_act = <tc>-top_lineentry_from = 1entry_to = <tc>-lineslast_page_full = 'X'loops = <lines>ok_code = p_okoverlapping = 'X'IMPORTINGentry_new = l_tc_new_top_lineEXCEPTIONS* NO_ENTRY_OR_PAGE_ACT = 01* NO_ENTRY_TO = 02* NO_OK_CODE_OR_PAGE_GO = 03OTHERS = 0.ENDIF.*&SPWIZARD: get actual tc and column *GET CURSOR FIELD l_tc_field_nameAREA l_tc_name.IF syst-subrc = 0.IF l_tc_name = p_tc_name.*&SPWIZARD: et actual column *SET CURSOR FIELD l_tc_field_name LINE 1.ENDIF.ENDIF.*&SPWIZARD: set the new top line *<tc>-top_line = l_tc_new_top_line.ENDFORM. " COMPUTE_SCROLLING_IN_TC*&---------------------------------------------------------------------**& Form FCODE_TC_MARK_LINES*&---------------------------------------------------------------------** marks all TableControl lines*----------------------------------------------------------------------** -->P_TC_NAME name of tablecontrol*----------------------------------------------------------------------*FORM fcode_tc_mark_lines USING p_tc_namep_table_namep_mark_name.*&SPWIZARD: EGIN OF LOCAL DATA-----------------------------------------*DATA l_table_name LIKE feld-name.FIELD-SYMBOLS <tc> TYPE cxtab_control.FIELD-SYMBOLS <table> TYPE STANDARD TABLE.FIELD-SYMBOLS <wa>.FIELD-SYMBOLS <mark_field>.*&SPWIZARD: END OF LOCAL DATA------------------------------------------*ASSIGN (p_tc_name) TO <tc>.*&SPWIZARD: get the table, which belongs to the tc *CONCATENATE p_table_name '[]' INTO l_table_name. "table bodyASSIGN (l_table_name) TO <table>. "not headerline*&SPWIZARD: mark all filled lines *LOOP AT <table> ASSIGNING <wa>.*&SPWIZARD: access to the component 'FLAG' of the table header *ASSIGN COMPONENT p_mark_name OF STRUCTURE <wa> TO <mark_field>.<mark_field> = 'X'.ENDLOOP.ENDFORM. "fcode_tc_mark_lines*&---------------------------------------------------------------------**& Form FCODE_TC_DEMARK_LINES*&---------------------------------------------------------------------** demarks all TableControl lines*----------------------------------------------------------------------** -->P_TC_NAME name of tablecontrol*----------------------------------------------------------------------*FORM fcode_tc_demark_lines USING p_tc_namep_table_namep_mark_name .*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*DATA l_table_name LIKE feld-name.FIELD-SYMBOLS <tc> TYPE cxtab_control.FIELD-SYMBOLS <table> TYPE STANDARD TABLE.FIELD-SYMBOLS <wa>.FIELD-SYMBOLS <mark_field>.*&SPWIZARD: END OF LOCAL DATA------------------------------------------*ASSIGN (p_tc_name) TO <tc>.*&SPWIZARD: get the table, which belongs to the tc *CONCATENATE p_table_name '[]' INTO l_table_name. "table bodyASSIGN (l_table_name) TO <table>. "not headerline*&SPWIZARD: demark all filled lines *LOOP AT <table> ASSIGNING <wa>.*&SPWIZARD: access to the component 'FLAG' of the table header *ASSIGN COMPONENT p_mark_name OF STRUCTURE <wa> TO <mark_field>.<mark_field> = space.ENDLOOP.ENDFORM. "fcode_tc_mark_lines
5.效果展示
以上。
发表评论