03-08-2007 5:23 PM
Hallo friends,
Can someone please take a look at my code and help me.
What I want to achieve:
I have im my screen a table control TC_100. User should input data in TC_100. These (the inputed datas would later be saved in internal table).
Problem:
I want user to be able to insert / delete more rows if neccessary.
I have created two buttons (insert / delete). When user presses the buttons, rows are inserted or deleted at the first action. If user tries to insert / delete row second time or more. All data should still show in TC_100 untill user finishes all inputs.
Problem:
New rows are inserted but the inputed datas are repeating cumulatively. I hope i am making sense.
Example of what I want to achieve is like in smartform, when new rows are inserted / deleted at CONDITIONS. The new row is inserted and the datas remain.
<b>Please see my code / Logic flow and help me !!</b>
*Start PBO----
PROCESS BEFORE OUTPUT.
MODULE status_100_pbo. "Screen Status/Titel
LOOP WITH CONTROL tc_100.
CHAIN.
FIELD: nr
,demo_conn-carrid
,demo_conn-connid
,demo_conn-fldate
.
MODULE fill_tc_100. "initializ tc_100 before input
ENDCHAIN.
ENDLOOP.
MODULE refresh_it_demo.
*ENDE PBO----
*Start PAI----
PROCESS AFTER INPUT.
MODULE leave_prog_pai AT EXIT-COMMAND. "Leave Prog.
LOOP WITH CONTROL tc_100.
CHAIN.
FIELD: nr
,demo_conn-carrid
,demo_conn-connid
,demo_conn-fldate
.
MODULE fill_itab_demo.
ENDCHAIN.
ENDLOOP.
MODULE fcode.
*ENDE PAI----
ABAP CODE
PBO:
&----
*
*& Module status_100_pbo OUTPUT
&----
text
----
MODULE status_100_pbo OUTPUT.
CASE sy-dynnr.
WHEN 100.
SET PF-STATUS 'SCREEN_100_STATUS'.
SET TITLEBAR 'SCREEN_100'.
ENDCASE.
ENDMODULE. " status_100_pbo OUTPUT
----
MODULE fill_tc_100 OUTPUT *
----
........ *
----
MODULE fill_tc_100 OUTPUT.
IF NOT it_demo IS INITIAL.
*filling tc_100
READ TABLE it_demo INDEX tc_100-current_line INTO wa_demo.
IF sy-subrc = 0.
*Fill current lines of tc_100
SET CURSOR FIELD 'NR' LINE tc_100-current_line.
MOVE wa_demo-nr TO nr.
SET CURSOR FIELD 'DEMO_CONN-CARRID' LINE tc_100-current_line.
MOVE wa_demo-carrid TO demo_conn-carrid.
SET CURSOR FIELD 'DEMO_CONN-CONNID' LINE tc_100-current_line.
MOVE wa_demo-connid TO demo_conn-connid.
SET CURSOR FIELD 'DEMO_CONN-FLDATE' LINE tc_100-current_line.
MOVE wa_demo-fldate TO demo_conn-fldate.
*Cursor to the first field
IF nr CP '00' AND sy-subrc = 0.
SET CURSOR FIELD 'NR' LINE tc_100-top_line.
ELSE.
SET CURSOR FIELD 'NR' LINE tc_100-current_line.
ENDIF.
ENDIF.
ENDIF.
ENDMODULE. " fill_tc_100 OUTPUT
PAI:
&----
*& Module leave_prog_pai INPUT
&----
text
----
MODULE leave_prog_pai INPUT.
DATA confirmation TYPE string.
save_code = ok_code.
CLEAR ok_code.
IF save_code = 'BACK' OR
save_code = 'EXIT' OR
save_code = 'CANCEL'.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
titlebar = 'Confirm '
text_question = 'Are you sure?'
text_button_1 = 'Ja'(001)
text_button_2 = 'Nein'(002)
IMPORTING
answer = confirmation.
IF confirmation = '1'.
SET SCREEN 0.
LEAVE PROGRAM.
ELSEIF confirmation = '2' OR
confirmation = 'A'.
LEAVE TO SCREEN 100.
ENDIF.
ENDIF.
ENDMODULE. " leave_prog_pai INPUT
&----
*& Module fill_table_pai INPUT
&----
text
----
MODULE fill_itab_demo INPUT.
MOVE:
nr TO wa_demo-nr
,demo_conn-carrid TO wa_demo-carrid
,demo_conn-connid TO wa_demo-connid
,demo_conn-fldate TO wa_demo-fldate
.
APPEND wa_demo TO it_demo.
ENDMODULE. " fill_itab_demo INPUT
&----
*& Module fcode INPUT
&----
text
----
MODULE fcode INPUT.
save_code = ok_code.
CLEAR ok_code.
CASE save_code.
WHEN space.
LEAVE TO SCREEN 100.
WHEN 'INS_ROW'.
insert line above cursor position
GET CURSOR FIELD fld LINE linno OFFSET off.
IF sy-subrc = 0.
SET CURSOR FIELD fld LINE linno OFFSET off.
IF linno >= 1.
linno = linno + tc_100-top_line - 1.
INSERT it_demo INDEX linno.
tc_100-lines = tc_100-lines + 1.
ELSE.
tc_100-lines = tc_100-lines + 1.
ENDIF.
ENDIF.
WHEN 'DEL_ROW'.
remove marked lines
LOOP AT it_demo INTO wa_demo WHERE marked = 'X'.
DELETE it_demo.
ENDLOOP.
IF sy-subrc <> 0.
GET CURSOR FIELD fld LINE linno OFFSET off.
SET CURSOR FIELD fld LINE linno OFFSET off.
linno = linno + tc_100-top_line - 1.
DELETE it_demo INDEX linno.
tc_100-lines = tc_100-lines - 1.
ENDIF.
ENDCASE.
ENDMODULE. " fcode INPUT
03-09-2007 9:47 AM
Check these demo programs
RSDEMO_TABLE_CONTROL
DEMO_DYNPRO_TABLE_CONTROL_1
DEMO_DYNPRO_TABLE_CONTROL_2
RSDEMO_TABLE_CONTROL
RSDEMO02
Regards,
Santosh
03-09-2007 9:41 AM
Hi,
Please send me a sample code to copy a row of table control and to paste it in the row selected.
This is very urgent
03-09-2007 9:47 AM
Check these demo programs
RSDEMO_TABLE_CONTROL
DEMO_DYNPRO_TABLE_CONTROL_1
DEMO_DYNPRO_TABLE_CONTROL_2
RSDEMO_TABLE_CONTROL
RSDEMO02
Regards,
Santosh
03-09-2007 1:11 PM
Hallo Santosh,
Thanks for the tip. I will look into the demo prog. and see what I can make out of them.
However, I have been able to improve on my code- It it still not as perfect as O want, burt a lot better.
Black.