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

Updating the Database Table

Former Member
0 Likes
482

Hi Experts,

I have the requirements where i need to update the Database table for only two fields, But the Update should happen for every 1000 records for all the records. If one record has error none of the records should get updated in the database table.

Appreciate if you have a quick response.

Regards,

Shankar

3 REPLIES 3
Read only

andreas_mann3
Active Contributor
0 Likes
460

1) use a counter in you loop.

2) use command rollback work (look F1)

A.

Read only

Former Member
0 Likes
460

Hi,

Copy the DB table into an internal table.

Loop at Internal table.

if sy-tabix is a multiple of '1000' update the db table.

endloop.

Reawrd if helpfull.

Regards Madhu.

Read only

Former Member
0 Likes
460

You should have your 1000 records in an internal table with the same structure as the database table.

Then you use:

UPDATE dbtab FROM TABLE itab.

then you check for SY-SUBRC. If it equals 0 it means that all entries were updated. In the other hand, if it's 4 then at least one row could not be updated. The code should be:

IF SY-SUBRC EQ 0.
COMMIT WORK.
ELSE.
ROLLBACK WORK.
MESSAGE eXXX.
ENDIF.

In the message you can specify the number of rows that contains error, because in SY-DBCNT the number of updated rows are stored. Then if you know you have 1000 lines in the internal table you can do:

error = 1000 - SY-DBCNT.

MESSAGE e000 WITH 'There where ' error ' lines with errors'.

I hope it helps, reward points please.