03-03-2008 9:57 AM
Hello Everyone,
i have 2 screens .. screen 1 -- company code.
plant, year, posting period.
screen 2 -- contains a table control
with fields invoice number,
cheque no., check date ,
amount.
I have to update all these values into a ztable . and also
modify , delete and retrieve the data from ztable.
please send me the complete coding,,
its very urgent,,,
will be rewarded,,,,,,,,
03-03-2008 10:26 AM
hi,
This uploads table control with the data.u have to write this in pbo.
select * from zcust_master2 into table wi_cust1. "This uploads the table control with data from customer master
tb-lines = sy-dbcnt.
To save, create a module in PAI and write the following code.
ex:
case sy-ucomm.
when 'SAVE'.
modify wi_cust1 index tb-current_line.
if sy-subrc = 0.
modify zcust_master2 from table wi_cust1.
message s005(zmsgbanks1).
else.
message e006(zmsgbanks1).
endif.
To delete,
Case sy-ucomm.
when 'DELETE'.
Write the code as per ur requirement.
SAMPLE CODE:
In the flow logic of the screen 9000, write the following 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 Successfull
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
chk this link too, i got the above sample code from this link..
Regards,
Arunsri
03-03-2008 10:31 AM
> Hello Everyone,
>
> i have 2 screens .. screen 1 -- company code.
> plant, year, posting period.
>
> screen 2 -- contains a table control
> with fields invoice number,
> cheque no., check date ,
> amount.
> I have to update all these values into a ztable . and also
> modify , delete and retrieve the data from ztable.
>
> please send me the complete coding,,
> its very urgent,,,
>
> will be rewarded,,,,,,,,
Table Control
© 2005 SAP AG 1
Applies To:
Usage of Table Control in ABAP
Summary
Normally we use wizard if we are working with table control. This document helps us how to create a table
control without using a wizard and how to manipulate the database based on the records in the table control.
All the fields in the screen should be disabled .After clicking that Change button, we should be able to insert
new records and update existing records . Save in the standard toolbar will be used to
save the changes made. Delete button should be used to delete the rows selected from the database.
A custom table zzz_makt with the following fields is used in this program.
Fields FieldType
ZMANDT MANDT
ZMATNR MATNR(Key field)
ZMAKTX MAKTX
PICK CHAR1
Company and Title: Project Engineer in Wipro Technologies
Date: 08 March 2005
Table of Contents
Applies To:.......................................................................................................................................1
Summary .........................................................................................................................................1
Table of Contents .............................................................................................................................1
Procedure ..2
Code....................................................................................... Error! Bookmark not defined.0
Output Screens ...................................................................... Error! Bookmark not defined.7
Disclaimer & Liability Notice.........................................................................................................201
Author Bio....................................................................................................................................212
Table Control
© 2005 SAP AG 2
Procedure
Go to SE38 -> Create a program with executable type as Module Pool.
Table Control
© 2005 SAP AG 3
After saving this, click display object list.
Table Control
© 2005 SAP AG 4
Right click the program name on the left side. Click Create-> Screen. Then give screen no. .
Then fill the attributes of the screen as follows.
Table Control
© 2005 SAP AG 5
Click the layout button. Drag the table control from the controls and place it on screen.
Set the properties of table control as follows.
In the properties,
(1) The separators checkboxes need to be checked.
(2) The W/Selcolumn should be given a name which is having char1 in the database table so that the
selection column is visible in the table control.
(3) In order to view the horizontal scrollbar at runtime, choose the option none in Column sel.
Table Control
© 2005 SAP AG 6
Table Control
© 2005 SAP AG 7
Table Control
© 2005 SAP AG 8
Create the status by right clicking create ->GUI Status in the object display.
Similarly create title.
Set the SAVE , BACK, EXIT, CANCEL in standard toolbar and activate it.
Table Control
© 2005 SAP AG 9
Create a transaction by right clicking create ->Transaction in the object display. Enter required fields.
Table Control
© 2005 SAP AG 10
Code
In the flow logic of the screen 9000, write the following 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.
Table Control
© 2005 SAP AG 11
***********************************************************************
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
Table Control
© 2005 SAP AG 12
*&----
*
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'.
Table Control
© 2005 SAP AG 13
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.
Table Control
© 2005 SAP AG 14
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'.
Table Control
© 2005 SAP AG 15
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
Table Control
© 2005 SAP AG 16
Output Screens
Enter the transaction code ZTC.
Table Control
Reward point if usefull