2005 Aug 01 8:11 AM
Hi All,
I have 2 queries regarding table control.
<b>1.</b> Is it possible to access the table control changed text from screen? How?
Here I have to display the data in table control & when user selects change the changed text is to be saved in data base table when user selects save after making the changes.
<b>2.</b>How to enable only one selected row for updation.
Here if I say change all the rows are enabled for change mode.
Thanks & Regards,
Dilip
2005 Aug 01 9:20 AM
Hi,
To make selected rows for editable mode,
MODULE set_screen_fields OUTPUT.
LOOP AT SCREEN.
IF ( ( screen-name = 'I_MAKT-ZMAKTX'
OR screen-name = 'I_MAKT-CHECK1' )
AND <b>t_ctrl-current_line</b> 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.
MODIFY SCREEN.
ENDLOOP.
ENDMODULE. " set_screen_fields OUTPUT
Here is the sample code for table control.
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.
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.
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.
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.
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.
SET PF-STATUS 'ZSTATUS'.
SET TITLEBAR 'ZTITLE'.
ENDMODULE. " set_status OUTPUT
MODULE check INPUT.
MODIFY i_makt INDEX t_ctrl-current_line.
ENDMODULE. " CHECK INPUT
Hope it helps.If so,kindly reward points.Otherwise get back.
2005 Aug 01 8:48 AM
Hi,
1, To access the changed fields in the table control, declare an internal table with the same name as table control and the fields (inside the internal table) same as the table control fields(probably, u could have used such an internal table for poping up the data to the table control).
Now, Use the Loop at <internal table> statement in the PAI, which gets the data from the table control row by row and places in the header of the internal table. Then use the modify statement to update the internal table.
2, Check the SCREEN structure for the particular columnname and make the INPUT field as 1 for enabling updation.
2005 Aug 01 9:20 AM
Hi,
To make selected rows for editable mode,
MODULE set_screen_fields OUTPUT.
LOOP AT SCREEN.
IF ( ( screen-name = 'I_MAKT-ZMAKTX'
OR screen-name = 'I_MAKT-CHECK1' )
AND <b>t_ctrl-current_line</b> 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.
MODIFY SCREEN.
ENDLOOP.
ENDMODULE. " set_screen_fields OUTPUT
Here is the sample code for table control.
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.
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.
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.
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.
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.
SET PF-STATUS 'ZSTATUS'.
SET TITLEBAR 'ZTITLE'.
ENDMODULE. " set_status OUTPUT
MODULE check INPUT.
MODIFY i_makt INDEX t_ctrl-current_line.
ENDMODULE. " CHECK INPUT
Hope it helps.If so,kindly reward points.Otherwise get back.
2005 Aug 01 12:00 PM
Hi Jayanti,
When I click on modify button it enables the columnn editable instead of making editable for the particular row editable.
Regards,
Dilip
2005 Aug 01 12:03 PM
Hi Diliip,
AS I already mentioned in my reply,t_ctrl-current_line is compared to check the rows and screen-name is compared to check columns in that rows.
IF ( ( screen-name = 'I_MAKT-ZMAKTX'
OR screen-name = 'I_MAKT-CHECK1' )
AND t_ctrl-current_line EQ 1) .
The above code refers to First row and 2 columns mentioned by screen-name.
2005 Aug 02 6:36 AM
Hi Jayanthi,
Still I am not able to get the changed values on screen by the user. How to access the table control changed values?
Regards,
Dilip
2005 Aug 02 7:16 AM
Hi,
PROCESS AFTER INPUT.
LOOP AT i_makt.
This will take care of updating the internal table
FIELD i_makt-pick MODULE check.
FIELD i_makt-zmatnr MODULE zmatnr .
ENDLOOP.
MODULE check INPUT.
MODIFY i_makt INDEX t_ctrl-current_line.
ENDMODULE. " CHECK INPUT
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.
Then in PAI,
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'.
....
Hope it helps.
2005 Aug 02 8:04 AM
Hi Jayanthi,
My problem is solved ! Thanks for your help.
Regards,
Dilip
2005 Aug 01 10:10 AM
Hi,
1. It is possible to access the data from the table
control.
Declare a same internal table like Table control, so that data will be automatically available in that.
2. In order to make the field editable,
Loop at screen.
Check for the table control field with field name and make it editable using "Screen_input = 1".
endloop.
Cheers,
Venkat