Application Development 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: 

How to modify changes of table control data in PAI

amber_garg
Active Participant
0 Kudos

I have a table control where the columns are brought by dict fields.I am able to bring data into table control through an itab.

Now what i want is whenever user edits data in table control and clicks on save button the corresponding changes should be made in database.

For this according to my understanding we need to (in PAI) modify the changes in itab from the table control and then in SY-UCOMM of SAVE button we need to update in database table using itab.

For this , I am not able to write code for modifying the changes in itab from table control. Here is my code below.Please tell me how to do this.

PROCESS BEFORE OUTPUT.
 MODULE FILL_DATA.
 LOOP AT ITAB INTO ZEMPLOYEE_MASTER WITH CONTROL EMPTABLE CURSOR
EMPTABLE-CURRENT_LINE.
 ENDLOOP.
 MODULE STATUS_0001.
*
PROCESS AFTER INPUT.
 LOOP AT ITAB.
   MODULE MODIFY_ITAB.
 ENDLOOP.
 MODULE USER_COMMAND_0001.

REPORT  ZDATA_FORM1.

TABLES: ZEMPLOYEE_MASTER.

CONTROLS EMPTABLE TYPE TABLEVIEW USING SCREEN 0001.

data: begin of itab occurs 0,
       emp_no like zemployee_master-emp_no,
       name like zemployee_master-name,
       city like zemployee_master-city,
      end of itab,
      rowno TYPE I VALUE 1.


*&---------------------------------------------------------------------*
*&      Module  STATUS_0001  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_0001 OUTPUT.
*  SET PF-STATUS 'xxxxxxxx'.
*  SET TITLEBAR 'xxx'.

ENDMODULE.                 " STATUS_0001  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0001  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0001 INPUT.
  MESSAGE 'Inside INPUT' TYPE 'I'.
 CASE SY-UCOMM.
   WHEN 'SAVE'.
     UPDATE zemployee_master.
   WHEN 'EXIT'.
     LEAVE PROGRAM.
 ENDCASE.
ENDMODULE.                 " USER_COMMAND_0001  INPUT
*&---------------------------------------------------------------------*
*&      Module  fill_data  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE fill_data OUTPUT.
  select emp_no name city from zemployee_master into TABLE itab ORDER BY emp_no.
  Describe table itab lines EMPTABLE-LINES.
ENDMODULE.                 " fill_data  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  modify_itab  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE modify_itab INPUT.
* MODIFY itab from zemployee_master index
* MESSAGE 'Inside modify_itab' TYPE 'I'.
ENDMODULE.                 " modify_itab  INPUT

1 ACCEPTED SOLUTION

former_member1245113
Active Contributor
0 Kudos

Hi

In the following module of your code

MODULE modify_itab INPUT.
 MODIFY itab from zemployee_master index tc-current_line " Where TC is the name of the Table control on the Screen
ENDMODULE.

http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/2165e990-0201-0010-5cbb-b5c2ad436140

Cheerz

Ramchander Rao.K

6 REPLIES 6

former_member1245113
Active Contributor
0 Kudos

Hi

In the following module of your code

MODULE modify_itab INPUT.
 MODIFY itab from zemployee_master index tc-current_line " Where TC is the name of the Table control on the Screen
ENDMODULE.

http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/2165e990-0201-0010-5cbb-b5c2ad436140

Cheerz

Ramchander Rao.K

0 Kudos

I added the index tc-current_line thing (tc = table control name) but still no change.

What i need to do in order to make the changes from ITAB to database in SY-uCOMM for save.

Secondly as u told to add tc-current_line , since in that particular loop i am not using WITH TC , then how the value of current_line is going to be changed on each iteration.Would'nt it keep on pointing to the last assigned value.

THANKS

0 Kudos

I checked in debugging mode that the itab is getting modified correctly. So now the cause of concern is the update statement.

I have written like this in SY-UCOMM for SAVE .

UPDATE zemployee_master from table itab.

I get an error saying ITAB is not long enough which is true because in the database one extra field is there called dept_no which i have not included in itab because i dont want to display it in table control.So is there any other way to transport the table ITAB to structure zemployee_master in update??

0 Kudos

I know this problem can be solved by creating itab with the same structure as database table.But what i want is that if my database table has 100 columns but i am using only 5 columns in my module pool then I should declare my itab for those 5 cols only in order to be efficient.

Please tell if its possible .

THANKS

0 Kudos

Hi


simply declare another Internal table of type dictionary table then

loop at itab into wa.
move-corresponding wa to jtab " JTAB is of type dictionary
append jtab 
endloop.
now use 

MODIFY DBTAB FROM TABLE JTAB " Check the syntax

Take care of the consistency of the data in database as you are updating only 5 fields of the database table 
use all primary key fields in the update statements else you end up in inconsistent data

Cheerz

Ram

0 Kudos

Thanks for your reply. So I think its not possible to do this using only 1 internal table itab i guess. Getting a bit clarity now on this.THank you very much