ABAP顾问
分类:
2008-02-22 11:29:28
alicice 发表时间:2008-02-22 09:00:54 | ||
老白,请问如何在屏幕中的tablecontrl 中实现按回车自动光标跳到下一行,麻烦给个例子!
|
REPORT zdemo_dynpro_tabcont_loop.
TYPE-POOLS vrm.
CONTROLS flights TYPE TABLEVIEW USING SCREEN 100.
DATA: ok_code TYPE sy-ucomm,
save_ok TYPE sy-ucomm.
DATA: c_docking TYPE REF TO cl_gui_docking_container ,
c_spliter TYPE REF TO cl_gui_splitter_container ,
c_grid1 TYPE REF TO cl_gui_alv_grid,
c_editor TYPE REF TO cl_gui_textedit.
DATA: v_repid TYPE syrepid.
DATA: g_container1 TYPE REF TO cl_gui_container,
g_container2 TYPE REF TO cl_gui_container.
DATA: itab TYPE TABLE OF demo_conn,
fill TYPE i.
TABLES demo_conn.
DATA: lines TYPE i,
limit TYPE i.
DATA: l_field(20) ,
l_linno TYPE i.
DATA: vid TYPE vrm_id,
vlist TYPE vrm_values,
value LIKE LINE OF vlist.
SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE itab.
CALL SCREEN 100.
*----------------------------------------------------------------------*
* MODULE status_0100 OUTPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'SCREEN_100'.
DESCRIBE TABLE itab LINES fill.
flights-lines = fill.
IF l_field = 'DEMO_CONN-CITYFROM'.
SET CURSOR FIELD 'DEMO_CONN-CITYFROM' LINE l_linno .
ELSE.
SET CURSOR FIELD 'DEMO_CONN-CITYTO' LINE l_linno .
ENDIF.
IF c_docking IS INITIAL .
CREATE OBJECT c_docking
EXPORTING
repid = v_repid
dynnr = sy-dynnr
side = cl_gui_docking_container=>dock_at_left
extension = '235'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
CREATE OBJECT c_spliter
EXPORTING
parent = c_docking
rows = 2
columns = 1.
CALL METHOD c_spliter->get_container
EXPORTING
row = 1
column = 1
RECEIVING
container = g_container1.
CALL METHOD c_spliter->get_container
EXPORTING
row = 2
column = 1
RECEIVING
container = g_container2.
CALL METHOD c_spliter->set_visible
EXPORTING
visible = 'X'.
ENDIF .
IF c_editor IS INITIAL.
CREATE OBJECT c_editor
EXPORTING
parent = g_container2
wordwrap_mode = cl_gui_textedit=>wordwrap_at_fixed_position
wordwrap_position = 72
max_number_chars = 100000.
ENDIF .
IF c_grid1 IS INITIAL.
CREATE OBJECT c_grid1
EXPORTING i_parent = g_container1.
CALL METHOD c_grid1->set_visible
EXPORTING
visible = 'X'.
ENDIF.
CALL METHOD c_grid1->set_table_for_first_display
EXPORTING
i_structure_name = 'DEMO_CONN'
CHANGING
it_outtab = itab[]
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
ENDMODULE. "status_0100 OUTPUT
*----------------------------------------------------------------------*
* MODULE fill_table_control OUTPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE fill_table_control OUTPUT.
READ TABLE itab INTO demo_conn INDEX flights-current_line.
ENDMODULE. "fill_table_control OUTPUT
*----------------------------------------------------------------------*
* MODULE cancel INPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE cancel INPUT.
LEAVE PROGRAM.
ENDMODULE. "cancel INPUT
*----------------------------------------------------------------------*
* MODULE read_table_control INPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE read_table_control INPUT.
lines = sy-loopc.
MODIFY itab FROM demo_conn INDEX flights-current_line.
ENDMODULE. "read_table_control INPUT
*----------------------------------------------------------------------*
* MODULE user_command_0100 INPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'NEXT_LINE'.
flights-top_line = flights-top_line + 1.
limit = fill - lines + 1.
IF flights-top_line > limit.
flights-top_line = limit.
ENDIF.
WHEN 'PREV_LINE'.
flights-top_line = flights-top_line - 1.
IF flights-top_line < 0.
flights-top_line = 0.
ENDIF.
WHEN 'NEXT_PAGE'.
flights-top_line = flights-top_line + lines.
limit = fill - lines + 1.
IF flights-top_line > limit.
flights-top_line = limit.
ENDIF.
WHEN 'PREV_PAGE'.
flights-top_line = flights-top_line - lines.
IF flights-top_line < 0.
flights-top_line = 0.
ENDIF.
WHEN 'LAST_PAGE'.
flights-top_line = fill - lines + 1.
WHEN 'FIRST_PAGE'.
flights-top_line = 0.
WHEN ''.
GET CURSOR FIELD l_field LINE l_linno .
IF l_field = 'DEMO_CONN-CITYFROM'.
l_linno = l_linno + 1.
ELSE.
ENDIF.
ENDCASE.
ENDMODULE. "user_command_0100 INPUT
*&---------------------------------------------------------------------*
*& Module INIT_LISTBOX OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE init_listbox OUTPUT.
CLEAR vid.
CLEAR value.
CLEAR vlist.
vid = 'DEMO_CONN-CITYTO'.
value-key = 'Key1'.
value-text = 'Text1'.
APPEND value TO vlist.
value-key = 'Key2'.
value-text = 'Text2'.
APPEND value TO vlist.
CLEAR value.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = vid
values = vlist.
ENDMODULE. " INIT_LISTBOX OUTPUT
alicice2008-02-27 08:58:48
非常感谢老白 !!! 光标定位我基本都没问题了 但回车事件还不怎么明白 在那段程序里你是把回车事件当成Ok_CODE = ''了, 但有个问题就是 当我按了下一页 或别的按钮后 ok_code = 'NEXT_LINE' 再敲回车就没反应了 , 跟踪 显示 敲回车后OK_CODE 还是为 'NEXT_LINE',不会再变成 '' 了 即使我在 每个 WHEN后面都加了 clear ok_code.clear save_ok. 如下: MODULE user_command_0100 INPUT. save_ok = ok_code. CLEAR ok_code. CASE save_ok. WHEN 'NEXT_LINE'. flights-top_line = flights-top_line + 1. limit = fill - lines + 1. IF flights-top_line > limit. flights-top_line = limit. E