on 12-22-2005 3:05 PM
Hi all,
Kindly send me an example related to tablecontrols. Creation , deletion and Modification of rows in the tablecontrols .
Regards,
Surya
Hi sathish,
Thank you, Now the problem is when i delete a single record , it is deleting all the records. your views.
Regards,
Surya
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Here is the sample code.
PROCESS BEFORE OUTPUT.
MODULE set_status.
MODULE get_t_ctrl_lines.
LOOP AT i_makt WITH CONTROL t_ctrl CURSOR t_ctrl-current_line.
Dynamic screen modifications
MODULE set_screen_fields.
ENDLOOP.
*
PROCESS AFTER INPUT.
LOOP AT i_makt.
FIELD i_makt-pick MODULE check.
FIELD i_makt-zmatnr MODULE zmatnr .
ENDLOOP.
MODULE user_command_9000.
In the program, write the following code.
PROGRAM SAPMZTC MESSAGE-ID zz.
***********************************************************************
Tables Declaration
***********************************************************************
TABLES: zzz_makt.
***********************************************************************
Internal table Declaration
***********************************************************************
DATA : i_makt TYPE STANDARD TABLE OF zzz_makt WITH HEADER LINE.
***********************************************************************
Table control Declaration
***********************************************************************
CONTROLS: t_ctrl TYPE TABLEVIEW USING SCREEN '9000'.
***********************************************************************
Variable Declaration
***********************************************************************
DATA : flg, "Flag to set the change mode
ln TYPE i. "No. of records
&----
*& Module get_T_CTRL_lines OUTPUT
&----
Populating data
----
MODULE get_t_ctrl_lines OUTPUT.
SELECT zmatnr zmaktx
INTO CORRESPONDING FIELDS OF TABLE i_makt
FROM zzz_makt.
DESCRIBE TABLE i_makt LINES ln.
To make the vertical scroll bar to come on runtime
t_ctrl-lines = ln + 100.
ENDMODULE. " get_T_CTRL_lines OUTPUT
&----
*& Module USER_COMMAND_9000 INPUT
&----
Triggering event according to the user command
----
MODULE user_command_9000 INPUT.
DATA :lv_fcode LIKE sy-ucomm, "Function Code
lv_answer(1) type c. "Storing the answer
lv_fcode = sy-ucomm.
CASE lv_fcode.
WHEN 'CHANGE'.
Setting the flag to make the table control in editable mode[excluding
primary key].
flg = 'Y'.
WHEN 'DELETE'.
Setting the flag to make the table control in editable mode after
deleting the selected line
flg = 'Y'.
Confirmation of delete
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
TITLEBAR = 'Confirm'
text_question = 'Are you sure to delete from database?'
TEXT_BUTTON_1 = 'Yes'(001)
TEXT_BUTTON_2 = 'No'(002)
IMPORTING
ANSWER = lv_answer.
if lv_answer eq '1'.
Updating the database table from the internal table
UPDATE zzz_makt FROM TABLE i_makt.
Deleting the selected row from the internal table
DELETE i_makt WHERE pick = 'X'.
Deleting the selected row from the database table
DELETE FROM zzz_makt WHERE pick = 'X'.
MESSAGE s005 WITH 'Deleted Successfully'.
ENDIF.
WHEN 'SAVE'.
Inserting new record or updating existing record in database table
from the internal table
MODIFY zzz_makt FROM TABLE i_makt.
MESSAGE s005 WITH 'Saved Successfully'.
WHEN 'BACK'.
SET SCREEN '0'.
WHEN 'EXIT' OR 'CANCEL'.
Leaving the program
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. " USER_COMMAND_9000 INPUT
&----
*& Module set_screen_fields OUTPUT
&----
Setting the screen fields
----
MODULE set_screen_fields OUTPUT.
LOOP AT SCREEN.
IF flg IS INITIAL.
screen-input = 0.
ELSEIF ( flg EQ 'Y' ).
IF ( ( screen-name = 'I_MAKT-ZMAKTX'
OR screen-name = 'I_MAKT-CHECK1' )
AND t_ctrl-current_line LE ln ) .
Making the screen fields as editable
screen-input = 1.
ELSEIF ( ( screen-name = 'I_MAKT-ZMATNR' )
AND t_ctrl-current_line LE ln ).
Making the screen field as uneditable
screen-input = 0.
ENDIF.
ENDIF.
Modifying the screen after making changes
MODIFY SCREEN.
ENDLOOP.
ENDMODULE. " set_screen_fields OUTPUT
&----
*& Module zmatnr INPUT
&----
Appending records to the internal table
----
MODULE zmatnr INPUT.
MODIFY i_makt INDEX t_ctrl-current_line.
IF t_ctrl-current_line GT ln.
READ TABLE i_makt WITH KEY zmatnr = i_makt-zmatnr.
IF sy-subrc NE 0.
Inserting record if it does not exist in database
APPEND i_makt.
ELSE.
MESSAGE i005 WITH 'Material Number' i_makt-zmatnr 'already exists'.
ENDIF.
ENDIF.
ENDMODULE. " zmatnr INPUT
&----
*& Module set_status OUTPUT
&----
Setting the GUI status
----
MODULE set_status OUTPUT.
SET PF-STATUS 'ZSTATUS'.
SET TITLEBAR 'ZTITLE'.
ENDMODULE. " set_status OUTPUT
*&----
*& Module CHECK INPUT
*&----
Modify the internal table using the current line in table control
*----
MODULE check INPUT.
MODIFY i_makt INDEX t_ctrl-current_line.
ENDMODULE. " CHECK INPUT
Hi look at the following code.
program zsatish_mard_transaction message-id zz.
*table control
controls: tc type tableview using screen 100.
internal table declaration
data: begin of it_mard occurs 0,
sel type c,
matnr type mard-matnr, " Material number
werks type mard-werks, " Plant
lgort type mard-lgort, " Storage location
lvorm type mard-lvorm,
" Flag Material for Deletion at Storage Location Level
lfgja type mard-lfgja, " Fiscal year of current period
lfmon type mard-lfmon, " Current period (posting period)
labst type mard-labst, " Valuated stock with unrestricted use
ersda type mard-ersda, " Creation date
end of it_mard.
table control structure
data: it_mard1 like it_mard occurs 0 with header line.
internal table for the status buttons
data: begin of i_status occurs 0,
name(20) type c,
end of i_status.
variable data
data: v_flag type c value '0', " FLAG VARIABLE TO KNOW PBO OR PAI
v_sel, " selection
v_lines type i, " rows of table view
v_answer(1) type c, " user selection from the popup
v_count type i value 0, " count of records marked for deletion
v_msg(100) type c, " message
ok_code(11) type c, " ok code value
ok_code1(11) type c,
v_newrow type c value 'Y'. " new row indicator
START-OF-SELECTION
start-of-selection.
perform read_mard_table.
CALL SCREEN
call screen 100.
&----
*& Module READ_MARD_TABLE OUTPUT
&----
Fetch data from the database tables
----
form read_mard_table.
if v_flag eq '0'.
select matnr
werks
lgort
lvorm
lfgja
lfmon
labst
ersda
up to 36 rows
from mard into corresponding fields of table it_mard.
if not it_mard[] is initial.
loop at it_mard.
it_mard-sel = ' '.
modify it_mard transporting sel.
endloop.
endif.
describe table it_mard lines tc-lines.
v_lines = tc-lines.
endif.
endform. " READ_MARD_TABLE
&----
*& Module set_status OUTPUT
&----
Set the pf status
----
module set_status output.
if v_flag eq '0'.
clear: i_status,
i_status[].
i_status-name = 'DISPLAY'.
append i_status.
i_status-name = 'SELECTALL'.
append i_status.
i_status-name = 'DESELECT'.
append i_status.
i_status-name = 'NEW'.
append i_status.
i_status-name = 'DELETE'.
append i_status.
set pf-status 'ZTSK' excluding i_status.
endif.
endmodule. " set_status OUTPUT
&----
*& Form GENERATE_ICONS
&----
generate the buttons in the toolbar dynamically
----
form generate_icons.
clear: i_status,
i_status[].
i_status-name = 'CHANGE'.
append i_status.
set pf-status 'ZTSK' excluding i_status.
endform. " GENERATE_ICONS
&----
*& Module MAKE_READ_ONLY OUTPUT
&----
Make the fields of the table control read only
----
module make_read_only output.
if v_flag eq '0'.
loop at screen.
screen-input = '0'.
modify screen.
endloop.
endif.
endmodule. " MAKE_READ_ONLY OUTPUT
&----
*& Module MAKE_WRITABLE OUTPUT
&----
Make table control fields write only
----
module make_writable output.
if v_flag eq '1'.
loop at screen.
if screen-name eq 'IT_MARD1-MATNR' or
screen-name eq 'IT_MARD1-WERKS' or
screen-name eq 'IT_MARD1-LGORT'.
screen-input = '0'.
modify screen.
endif.
endloop.
endif.
endmodule. " MAKE_WRITABLE OUTPUT
&----
*& Module SELECT_ALL_ROWS OUTPUT
&----
Select all the rows of the table control
----
form select_all_rows.
loop at it_mard.
it_mard-sel = 'X'.
modify it_mard.
endloop.
endform.
&----
*& Module MOVE_DATA OUTPUT
&----
Move the data from the internal table to the table control
----
module move_data output.
move-corresponding it_mard to it_mard1.
endmodule. " MOVE_DATA OUTPUT
&----
*& Form deselect_all
&----
Deselect all the rows from the table control
----
form deselect_all.
loop at it_mard.
it_mard-sel = ' '.
modify it_mard.
endloop.
endform. " deselect_all
&----
*& Form delete_records
&----
Delete the selected records
----
form delete_records.
v_flag = '1'.
perform confrim_delete.
endform. " delete_records
&----
*& Form append_record
&----
Append a new record
----
form append_record.
clear: it_mard.
loop at it_mard where matnr is initial.
delete it_mard.
endloop.
append initial line to it_mard.
describe table it_mard lines tc-lines.
tc-top_line = v_lines - 4.
endform. " append_record
&----
*& Form display-report
&----
Display the final report
----
form display-report.
display the titles
if not it_mard[] is initial.
format color col_heading.
write:/ 'Material number',
'Plant',
'Storage location',
'Flag',
'Fiscal Year',
'Posting Period',
'Valuated Stock',
'Creation date'.
format color off.
display the data
format color col_normal.
loop at it_mard where lvorm eq 'X'.
write:/ it_mard-matnr,
it_mard-werks,
it_mard-lgort,
it_mard-lvorm,
it_mard-lfgja,
it_mard-lfmon,
it_mard-labst,
it_mard-ersda.
endloop.
format color off.
else.
format color col_negative.
write:/ 'No data to display'.
format color off.
endif.
endform. " display-report
&----
*& Form confrim_delete
&----
Confirmation for delete
----
form confrim_delete.
loop at it_mard where sel eq 'X'.
v_count = v_count + 1.
endloop.
if v_count > 0.
clear v_msg.
v_msg = 'Selected records will be deleted'.
perform check_delete_records using v_msg.
else.
message i999 with 'No records selected for deletion'.
endif.
endform. " confrim_delete
&----
*& Module REPORT_DISPLAY OUTPUT
&----
Call a report to display a day
----
module report_display output.
suppress dialog.
leave to list-processing and return to screen 0.
set pf-status 'ZTSK1'.
set pf-status space.
set titlebar 'ZSATISH_MARD_TRANSACTION'.
perform display-report.
endmodule. " REPORT_DISPLAY OUTPUT
&----
*& Module STATUS_0200 OUTPUT
&----
Set the pf status for the screen 200
----
module status_0200 output.
set pf-status 'ZTSK1'.
set pf-status space.
set titlebar 'ZSATISH_MARD_TRANSACTION'.
endmodule. " STATUS_0200 OUTPUT
&----
*& Module USER_COMMAND_0100 INPUT
&----
User inputs for screen 100
----
module user_command_0100 input.
*--make a copy of ok_code
ok_code1 = ok_code.
clear ok_code.
case ok_code1.
when 'DISPLAY'.
leave to screen 0.
when 'CHANGE'.
v_flag = '1'.
perform generate_icons.
when 'RETURN'.
leave to screen 0.
when 'SELECTALL'.
perform select_all_rows.
when 'DESELECT'.
perform deselect_all.
when 'DELETE'.
v_flag = '7'.
perform delete_records.
when 'NEW'.
v_flag = '2'.
perform append_record.
when 'REPORT'.
call screen 200 starting at 5 5 ending at 110 24.
when 'OTHERS'.
modify it_mard.
endcase.
endmodule. " USER_COMMAND_0100 INPUT
&----
*& Form check_delete_records
&----
To find the records marked for deletion and confirm the delete
----
-->P_V_MSG text
----
form check_delete_records using v_msg.
call function 'POPUP_TO_CONFIRM'
exporting
titlebar = 'Confirm Delete'
DIAGNOSE_OBJECT = ''
text_question = v_msg
TEXT_BUTTON_1 = 'Ja'(001)
ICON_BUTTON_1 = ' '
TEXT_BUTTON_2 = 'Nein'(002)
ICON_BUTTON_2 = ' '
DEFAULT_BUTTON = '1'
DISPLAY_CANCEL_BUTTON = 'X'
USERDEFINED_F1_HELP = ' '
START_COLUMN = 25
START_ROW = 6
POPUP_TYPE =
importing
answer = v_answer
TABLES
PARAMETER =
exceptions
text_not_found = 1
others = 2.
if sy-subrc = 0.
if v_answer = '1'.
loop at it_mard.
delete it_mard where sel = 'X'.
endloop.
LOOP AT SCREEN.
IF SCREEN-NAME EQ 'IT_MARD1-MATNR' OR
SCREEN-NAME EQ 'IT_MARD1-WERKS' OR
SCREEN-NAME EQ 'IT_MARD1-LGORT'.
*
SCREEN-INPUT = 0.
MODIFY SCREEN.
ELSE.
SCREEN-INPUT = 1.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
elseif v_answer eq '2'. " when no is selected
message i999 with 'User Dont want to delete the selected records'.
else. " when cancel is selected
message i999 with 'User cancelled the operation'.
endif.
endif.
endform. " check_delete_records
&----
*& Module move_data INPUT
&----
text
----
module move_data input.
move-corresponding it_mard1 to it_mard.
modify it_mard index tc-current_line.
endmodule. " move_data INPUT
&----
*& Module make_writable_when_append OUTPUT
&----
text
----
module make_writable_when_append output.
if v_flag eq '2'.
loop at screen.
if screen-name eq 'IT_MARD1-MATNR' or
screen-name eq 'IT_MARD1-WERKS' or
screen-name eq 'IT_MARD1-LGORT'.
if not it_mard1-matnr is initial.
screen-input = '0'.
modify screen.
else.
screen-input = '1'.
modify screen.
endif.
endif.
endloop.
endif.
endmodule. " make_writable_when_append OUTPUT
&----
*& Module VALIDATE_MATNR INPUT
&----
text
----
module validate_matnr input.
data: l_matnr type mara-matnr.
select single matnr
from mara into l_matnr
where matnr eq it_mard1-matnr.
if sy-subrc <> 0.
message e999 with 'INVALID MATNR'.
endif.
endmodule. " VALIDATE_MATNR INPUT
&----
*& Module validate_werks INPUT
&----
text
----
module validate_werks input.
data: l_werks type t001w-werks.
select single werks
from t001w into l_werks
where werks eq it_mard1-werks.
if sy-subrc <> 0.
message e999 with 'INVALID WERKS'.
endif.
endmodule. " validate_werks INPUT
&----
*& Module validate_lgort INPUT
&----
text
----
module validate_lgort input.
data: l_lgort type t001l-lgort.
select single lgort
from t001l into l_lgort
where lgort eq it_mard1-lgort.
if sy-subrc <> 0.
message e999 with 'INVALID LGORT'.
endif.
endmodule. " validate_lgort INPUT
&----
*& Module help_matnr INPUT
&----
text
----
module help_matnr input.
data: begin of it_matnr occurs 0,
matnr like mard-matnr,
end of it_matnr.
data: l_choice type i.
select matnr
from mard
into table it_matnr.
call function 'POPUP_WITH_TABLE_DISPLAY'
exporting
endpos_col = 20
endpos_row = 25
startpos_col = 2
startpos_row = 5
titletext = 'F4 values for MATNR'
importing
choise = l_choice
tables
valuetab = it_matnr
exceptions
break_off = 1
others = 2.
if sy-subrc = 0.
if not l_choice is initial.
read table it_matnr index l_choice.
it_mard1-matnr = it_matnr-matnr.
endif.
endif.
endmodule. " help_matnr INPUT
&----
*& Module help_WERKS INPUT
&----
text
----
module help_werks input.
data: begin of it_werks occurs 0,
werks like mard-werks,
end of it_werks.
data: l_choice1 type i.
select werks
from mard
into table it_werks.
call function 'POPUP_WITH_TABLE_DISPLAY'
exporting
endpos_col = 20
endpos_row = 25
startpos_col = 2
startpos_row = 5
titletext = 'F4 values for WERKS'
importing
choise = l_choice1
tables
valuetab = it_werks
exceptions
break_off = 1
others = 2.
if sy-subrc = 0.
if not l_choice1 is initial.
read table it_werks index l_choice1.
it_mard1-werks = it_werks-werks.
endif.
endif.
endmodule. " help_WERKS INPUT
&----
*& Module help_LGORT INPUT
&----
text
----
module help_lgort input.
data: begin of it_lgort occurs 0,
lgort like mard-lgort,
end of it_lgort.
data: l_choice2 type i.
select lgort
from mard
into table it_lgort.
call function 'POPUP_WITH_TABLE_DISPLAY'
exporting
endpos_col = 20
endpos_row = 25
startpos_col = 2
startpos_row = 5
titletext = 'F4 values for LGORT'
importing
choise = l_choice2
tables
valuetab = it_lgort
exceptions
break_off = 1
others = 2.
if sy-subrc = 0.
if not l_choice2 is initial.
read table it_lgort index l_choice2.
it_mard1-lgort = it_lgort-lgort.
endif.
endif.
endmodule. " help_LGORT INPUT
Satish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Bhasker ,
The link was very helpful. But iam unable to solve the problem. The row selected field is not marked and so the corresponding row is not deleted. Can anybody help...
Regards,
Surya
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Surya,
Look at the sample codes in the links below.
1. http://members.aol.com/_ht_a/skarkada/sap/table_control/table_control.htm
2. http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/contro02.htm
3. <a href="http://www.planetsap.com/<b>Tips_and_Tricks</b>.htm#colhide">http://www.planetsap.com/<b>Tips_and_Tricks</b>.htm#colhide</a>
4. http://help.sap.com/saphelp_bw31/helpdata/en/9f/dbac9f35c111d1829f0000e829fbfe/content.htm
5.Updating table control.
hope this helps you.
Kindly reward point if it is useful by clicking the star in the left hand side of the screen.
Regards,
Maheswaran.B
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Check this link.In this link you can find manipulations in database using table control.This will help you.Kindly reward points if it helps.
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/a1-8-4/table control in abap.pdf
Thanks,
Bhaskar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Check demo transactions TZ60, TZ61, TZ70 based on SFLIGHT .
Regards
Kalpana
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have a look at the programs,
DEMO_DYNPRO_TABLE_CONTROL_1
DEMO_DYNPRO_TABLE_CONTROL_2
REgards,
Ravi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.