on 10-04-2005 10:26 AM
Hi
I am nwe to ABAP. I have a few doubts on table COntrol.I am in search of the Best Practises to be followed.
1) Should we always map the Table control to a Structure or an Internal table.
2) Whenever i key in Data for a line in Table control and hit enter key, the contents vanish.
Can anyone send me a Template of the source code of how it needs to be handled.
I don't think it matters whether you use an internal table or structure. But it is easy to use the internal table since you don't have to explicitly move the data to the structure. Your internal table will hold all the data selected from the database and will automatically moved with the following PBO code :
LOOP AT G_DELIVERY_ITAB
WITH CONTROL DELIVERY_TC
CURSOR DELIVERY_TC-CURRENT_LINE.
ENDLOOP.
Attached is a sample program. Hope this helps.
SCREEN 100
-
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
LOOP WITH CONTROL TCTRL_USERDATA.
MODULE DISPLAY_USERDATA.
ENDLOOP.
DATA: BEGIN OF RECORD,
NAME(30),
PHONE(20),
EMAIL(50),
END OF RECORD.
DATA: ITAB_PHONELIST LIKE RECORD OCCURS 0 WITH HEADER LINE.
CONTROLS: TCTRL_PHONELIST TYPE TABLEVIEW USING SCREEN 100.
DATA: SAVE_CODE(4),
OK_CODE(4),
FILENAME LIKE RLGRAP-FILENAME,
CONFIRMATION,
SELECTION.
*&----
*& Module STATUS_0100 OUTPUT
*&----
text
*----
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'FOR100'.
SET TITLEBAR '100'.
ENDMODULE. " STATUS_0100 OUTPUT
*&----
*& Module DISPLAY_USERDATA OUTPUT
*&----
text
*----
MODULE DISPLAY_USERDATA OUTPUT.
READ TABLE ITAB_PHONELIST INDEX TCTRL_PHONELIST-CURRENT_LINE.
IF SY-SUBRC EQ 0.
RECORD-NAME = ITAB_PHONELIST-NAME.
RECORD-PHONE = ITAB_PHONELIST-PHONE.
RECORD-EMAIL = ITAB_PHONELIST-EMAIL.
ELSE.
EXIT FROM STEP-LOOP.
ENDIF.
ENDMODULE. " DISPLAY_USERDATA OUTPUT
Kindly reward points by clicking the star on the left of reply,if it helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Create a module pool program and add this code:
PROGRAM Z_SAMPLE_TABLE_CONTROL_PROGRAM message-id zz.
include z_Sample_Top.
include z_Sample_Pbo100.
include z_Sample_Pai100.
include z_Sample_Forms.
include z_Sample_Top below
CONTROLS TableControl1 TYPE TABLEVIEW USING SCREEN 100.
tables: vbrk.
types: begin of t_Tc1,
chosen(1),
kunag like vbrk-kunag, "Sold To Customer
vbeln like vbrk-vbeln, "Billing Doc
fkart like vbrk-fkart, "Billing Doc Type
zterm like vbrk-zterm, "Payment Terms
valdt like vbrk-valdt, "Fixed Value Date
fkdat like vbrk-fkdat, "Billing Date
waerk like vbrk-waerk, "Currency
netwr like vbrk-netwr, "Net Value
duedt like vbrk-valdt, "Invoice Due Date
end of t_Tc1.
data: Tc1 type t_Tc1 occurs 0 with header line.
include z_Sample_Pbo100 below
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'E100'.
SET TITLEBAR '100'.
if Tc1[] is initial.
Perform Fill_Tc1.
endif.
describe table Tc1 lines TableControl1-lines.
ENDMODULE. " STATUS_0100 OUTPUT
include z_Sample_Pai100 below
MODULE USER_COMMAND_0100 INPUT.
case sy-ucomm.
when 'CANCEL' or 'EXIT' or 'BACK'. " Exit program
clear sy-ucomm.
leave program.
when 'BUTTON'.
clear sy-ucomm.
Perform Count_Selected.
when 'SALL'.
clear sy-ucomm.
Perform Select_All.
when 'DALL'.
clear sy-ucomm.
Perform DeSelect_All.
endcase.
ENDMODULE. " USER_COMMAND_0100 INPUT
&----
&----
*----
MODULE MoveChosen INPUT.
if Tc1-chosen = 'X'.
Tc1-chosen = 'X'.
else.
clear Tc1-chosen.
endif.
modify Tc1 index tablecontrol1-current_line.
ENDMODULE. " MoveChosen INPUT
include z_Sample_Forms below
&----
*----
FORM Fill_Tc1 .
select * from vbrk into corresponding fields of table Tc1
where fkdat between '20040701' and '20040811'.
ENDFORM. " Fill_Tc1
&----
*&----
FORM Count_Selected .
data: yy(8) type n.
loop at Tc1 where chosen = 'X'.
yy = yy + 1.
endloop.
message i000 with 'You have selected: ' yy ' records.'.
ENDFORM. " Count_Selected
&----
FORM Select_All .
loop at Tc1.
Tc1-chosen = 'X'.
modify Tc1.
endloop.
ENDFORM. " Select_All
&----
&----
----
<-- p2 text
*----
FORM DeSelect_All .
loop at Tc1.
Tc1-chosen = ' '.
modify Tc1.
endloop.
ENDFORM. " DeSelect_All
*And create a screen '0100' with flow logic like this:
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
loop at Tc1 with control TableControl1 cursor
TableControl1-top_line.
endloop.
*
PROCESS AFTER INPUT.
loop at Tc1.
module MoveChosen.
endloop.
MODULE USER_COMMAND_0100.
On screen 100, add a table control and attach it to internal table Tc1 (from the Top include).
Create a GUI status as well with the items cited in the PAI mdoule.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
99 | |
11 | |
11 | |
6 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.