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

update database

Former Member
0 Likes
1,024
 
data: i_aad_tab type standard table zxxv_aad_tab 

IF NOT i_aad_tab[] IS INITIAL .

      UPDATE zxxv_aad_tab FROM TABLE i_aad_tab[].
      IF sy-subrc EQ 0.
*        MESSAGE successful update.
        LEAVE TO SCREEN '1000'.
      ENDIF.

    ENDIF.

please help the update doesn't work . can anyone advise

i_aad_tab contain same structure as the update database table and it contain value selected on the selection screen

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,004

Check primary key of the table..

12 REPLIES 12
Read only

Former Member
0 Likes
1,004

Hi,

Try this

data: i_aad_tab type standard table zxxv_aad_tab

IF NOT i_aad_tab[] IS INITIAL .

MODIFY zxxv_aad_tab FROM TABLE i_aad_tab.

IF sy-subrc EQ 0.

  • MESSAGE successful update.

LEAVE TO SCREEN '1000'.

ENDIF.

ENDIF.

Regards,

Satish

Read only

Former Member
0 Likes
1,005

Check primary key of the table..

Read only

JozsefSzikszai
Active Contributor
0 Likes
1,004

hi newbie82,

change like:

IF sy-subrc EQ 0.

COMMIT WORK.

...

ELSE.

ROLLBACK WORK.

ENDIF.

hope this helps

ec

Read only

0 Likes
1,004

by since my internal table has same types as my database table the primary key is the same

note: the sy-subrc = 4 and i don't know why

Read only

Former Member
0 Likes
1,004

Hi,

Check SY-DBCNT value after UPDATE, it will give the number of records updated

Also check SY-SUBRC

If, in the database, there is no row with the same content of the primary key for a row in the internal table, or if the change would lead to a double entry in a unique secondary key, the respective row is not changed and sy-subrc is set to 4. If the internal table is empty, sy-subrc is set to 0

use MODIFY and checkout if it works

Read only

0 Likes
1,004

thanks for the tips SY-DBCNT it's because i am updating a field which is the primary key

Read only

Former Member
0 Likes
1,004

That means atleast one line of ut internal table entry is not matching database strcture enrty..check it out once

Read only

0 Likes
1,004

i am updating a field which is also a primary key in my database table

. i used modify and it created a new record which i don't want . and with update it won't undate since if i make changes to primary key it doesn't find the record .

not being able to use update and modify . i think the only option is to remove promary key in the field that i am updating . i need your advise?

Read only

0 Likes
1,004

you can select all entries from table zxxv_aad_tab into an internal table and than loop through i_aad_tab and check if the entry you created exists already in the DB (i. e. READ TABLE with key fields), than if sy-subrc is not zero, than you can delete from your internal table.

something like this:

DATA : gt_aad_tab TYPE HASHED TABLE OF zxxv_aad_tab

WITH UNIQUE KEY (list key fields here).

SELECT * FROM zxxv_aad_tab INTO gt_aad_tab.

LOOP AT i_aad_tab.

READ TABLE gt_aad_tab WITH KEY all key field TRANSPORTING NO FIELDS.

IF sy-subrc NE 0.

*delete entry from i_aad_tab

ENDIF.

ENDLOOP.

Read only

0 Likes
1,004

no i can't do that since what ever the record i am selecting i need to change the value of one of the primary key fields

the purpose is to update the database value

Read only

0 Likes
1,004

Hi,

Just to make sure, have you checked if that Z table has the keys defined correctly (SE11), otherwise your abap statements won't work as expected if table definition is not defined as required.

Hope it helps.

Regards,

Gilberto Li

Read only

0 Likes
1,004

my itab has same structure as my database table