Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

problem in table control

Former Member
0 Likes
917

HI,

I have created a table control. I am passing values to the table control selecting from database table through internal table.

I have a button on the same screen. If i change a value in the table control and click the button the database table should be updated with the new values. And i should get the new values on the table control.

I am not able to do this. I am getting the same values on table control and the data base table is not getting updated.

Kindly any one help me.

thanks,

Kumar

12 REPLIES 12
Read only

Former Member
0 Likes
880

Hi,

In the PAI do the following..

PROCESS AFTER INPUT.

LOOP AT T_DATA.

MODULE UPDATE_DATA.

ENDLOOP.

MODULE UPDATE_DATA.

  • S_DATA WILL BE YOUR SCREEN STRUCTURE.

  • TABLE_CONTROL WILL BE YOUR TABLE CONTROL NAME.

MODIFY T_DATA FROM S_DATA INDEX TABLE_CONTROL-CURRENT_LINE.

ENDMODULE.

Thanks,

Naren

Read only

0 Likes
880

Sorry,

still i m not able to get your code.

can you plz give me the complete code for this example. what should be the table control name.

plz.

kumar

Read only

0 Likes
880

Hi

Table control name should be the one which you have defined. can you paste your code so that i can tell you where to implement this code.

Regards

Navneet

Read only

0 Likes
880

see,

my table control name is tc. and all the field names are from a database table.

i am not able to get the new field values from table control to itab. so that i can modify database table from internal table.

kumar

Read only

0 Likes
880

I hope it can help you:

CONTROLS T_CTRL TYPE TABLEVIEW USING SCREEN 100.

DATA: BEGIN OF ITAB OCCURS 0.

INCLUDE STRUCTURE ZITAB.

DATA: MARK,

END OF ITAB.

PROCESS BEFORE OUTPUT.

LOOP WITH CONTROL T_CTRL.

MODULE DISPLAY_DATA.

ENDLOOP.

*

PROCESS AFTER INPUT.

LOOP WITH CONTROL T_CTRL.

CHAIN.

FIELD: MARK,

ZITAB-FIELD1,

...........

ZITAB-FIELDN.

MODULE UPDATE_DATA.

ENDCHAIN.

ENDLOOP.

MODULE USER_COMMAND.

MODULE DISPLAY_DATA OUTPUT.

READ TABLE ITAB INDEX T_CTRL-CURRENT_LINE.

IF SY-SUBRC <> 0.

CLEAR: MARK, ZITAB.

LOOP AT SCREEN.

IF SCREEN-NAME = 'ITAB-MARK'.

SCREEN-INPUT = 0.

MODIFY SCREEN.

ENDIF.

ENDLOOP.

ELSE.

MOVE-CORRESPONDING ITAB TO ZITAB.

MARK = ITAB-MARK.

ENDIF.

ENDMODULE. " DISPLAY_DATA OUTPUT

MODULE UPDATE_DATA INPUT.

MOVE-CORRESPONDING ZITAB TO ITAB.

ITAB-MARK = MARK.

MODIFY ITAB INDEX T_CTRL-CURRENT_LINE.

IF SY-SUBRC <> 0. APPEND ITAB. ENDIF.

ENDMODULE. " UPDATE_DATA INPUT

MODULE USER_COMMAND.

SAVE_OK_CODE = OK_CODE.

CLEAR OK_CODE.

CASE SAVE_OK_CODE.

WHEN 'SAVE'. MODIFY ZITAB FROM TABLE ITAB.

ENDCASE.

ENDMODULE.

Max

Read only

0 Likes
880

Hi

Use code similar to below.

PROCESS BEFORE OUTPUT.

LOOP AT ITAB WITH CONTROL TC.

SELECT * FROM ZTABLE

WHERE ...

ENDLOOP.

PROCESS AFTER INPUT.

MODULE EXIT_COMMAND AT EXIT-COMMAND.

LOOP AT ITAB.

MODULE UPDATE_ZTABLE.

ENDLOOP.

Thanks,

Ramakrishna

Read only

0 Likes
880

My code is as follows..

module user_command_0500 input.

case sy-ucomm.

when 'SAVE_CHANGES'.

itab2-item_cat = z_test-item_cat.

itab2-plant = z_test-plant.

itab2-email = z_test-email.

itab2-on_line = z_test-on_line.

itab2-isa = z_test-isa.

update z_test from z_test.

endcase.

if sy-subrc = 0.

message i000(zabd) with 'RECORD MODIFIED'.

else.

message i000(zabd) with ' ERROR OCCURED '.

endif.

endmodule. "user_command_0500 INPUT

"user_command_0500

*

&----


*& Module modify_itab2 INPUT

&----


  • text

----


module modify_itab2 input.

modify itab2 index tc-current_line.

endmodule. " modify_itab2 INPUT

&----


*& Module DISPLAY_DATA OUTPUT

&----


  • text

----


module display_data output.

select * from z_test into table itab2.

endmodule. " DISPLAY_DATA OUTPUT

z_test is my database table, itab2 is internaltable.tc is my table control. still im not able to do this.

kinldy give me a complete code.

i m new to the table controls..

kumar

Read only

Former Member
0 Likes
880

Hi

Your flow screen should be like this:

PROCESS PBO.

LOOP AT ITAB WITH CONTROL ....

ENDLOOP.

PROCESS PAI.

LOOP AT ITAB.

MODULE MODIFY_ITAB.

ENDLOOP.

MODULE USER_COMMAND.

MODULE MODIFY_ITAB.

  • Here you have to transfer the data from table control * to internal table:

ITAB-FIELD1 = ......

MODIFY ITAB INDEX <TABLE CONTROL>-CURRENT_LINE.

ENDMODULE.

MODULE USER_COMMAND.

CASE OK_CODE.

WHEN 'SAVE'.

UPDATE ZTABLE FROM ITAB.

......

ENDCASE.

CLEAR OK_CODE.

ENDMODULE.

Max

Read only

Former Member
0 Likes
880

Hi

In the PAI event, when you loop at the internal table to be displayed in the table control, write a module in the loop to modify the internal table at index

tc-current_line, where tc is the name of the table control.

With this, the internal table will be modified.

Now when you click on some button to update the record in the database, move the data from the internal table to work area of that database table type and fill the mandt as sy-mandt.

give MODIFY dbtable from wa.

Sample code

PROCESS PAI.

Loop at i_tab.

MODULE modify_itab.

endloop.

Module modify_itab.

modify i_tab index tc-current_line. "tc is control table

endmodule.

Module user_command.

Case sy-ucomm.

when 'SAVE'.

wa-mandt = sy-mandt.

move-corresponding fields of i_tab into wa.

update table form wa.

endcase.

endmodule.

Regards,

Navneet

Message was edited by: Navneet Saraogi

Read only

Former Member
0 Likes
880

Hi,

The table control name is the one that you used to create the table control in the layout..Also you would have declared the same in the top include..

EXAMPLE.

controls: tc0 type tableview using screen 2002.

Thanks,

Naren

Read only

Former Member
0 Likes
880

Hi,

PROCESS AFTER INPUT.

LOOP AT T_DATA.

MODULE UPDATE_DATA.

ENDLOOP.

MODULE UPDATE_DATA.

DATA: S_DATA LIKE T_DATA.

  • ZTABLE_NAME will be your Z TABLE that you created.

  • T_DATA will be your internal table name.

  • You would have used ZTABLE_NAME for defining the screens.

MOVE-CORRESPONDING ZTABLE_NAME TO S_DATA.

MODIFY T_DATA FROM S_DATA INDEX TC-CURRENT_LINE.

  • The above modify will modify your internal table with

  • the values from the screen.

ENDMODULE.

Hope this helps..

Thanks,

Naren

Read only

Former Member
0 Likes
880

Hi,

Check the changes..Changes are marked in bold..Also you have to have the module modify_itab2 between LOOP and ENDLOOP in PAI...

module user_command_0500 input.

case sy-ucomm.

when 'SAVE_CHANGES'.

<b>*itab2-item_cat = z_test-item_cat.

*itab2-plant = z_test-plant.

*itab2-email = z_test-email.

*itab2-on_line = z_test-on_line.

*itab2-isa = z_test-isa.</b>

update z_test from table itab2.

endcase.

if sy-subrc = 0.

message i000(zabd) with 'RECORD MODIFIED'.

else.

message i000(zabd) with ' ERROR OCCURED '.

endif.

endmodule. "user_command_0500 INPUT

"user_command_0500

*

&----


*& Module modify_itab2 INPUT

&----


  • text

----


module modify_itab2 input.

<b>itab2-item_cat = z_test-item_cat.

itab2-plant = z_test-plant.

itab2-email = z_test-email.

itab2-on_line = z_test-on_line.

itab2-isa = z_test-isa.</b>

modify itab2 index tc-current_line.

endmodule. " modify_itab2 INPUT

&----


*& Module DISPLAY_DATA OUTPUT

&----


  • text

----


module display_data output.

select * from z_test into table itab2.

endmodule. " DISPLAY_DATA OUTPUT

Thanks,

Naren