‎2008 May 28 3:55 PM
Hi,
I added a table control to a dynpro using the wizard in the screen painter. Now I have an issue with the inserting line button:
If I add a new line the first time, a new empty line is added to the table control before my last line. So far so good.
If I add now another line, again a new line empty is added before my last line and two lines are added after my last line: one empty line and a line with the same content as my former second last line.
The following should explain it a bit better:
table before inserting new line:
line 1
line 2
line 3
line 4
line 5
after inserting a new line:
line 1
line 2
line 3
line 4
new empty line
line 5
table before inserting the second line:
line 1
line 2
line 3
line 4
line 5
line 6
after inserting the second line:
line 1
line 2
line 3
line 4
line 5
new empty line
line 6
new empty line
line 5
I didn't change the generated coding yet!
Thanks in advance and regards,
Martin
Edited by: fischerman on May 29, 2008 9:08 AM
‎2008 May 29 9:09 AM
Here is the code of the form which is called in PAI if the insert button was pressed:
FORM fcode_insert_row
USING p_tc_name TYPE dynfnam
p_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 body
ASSIGN (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 table
l_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 table
l_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