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 statement question.

Former Member
0 Likes
761

Hi people,

If I put a UPDATE statement in a code I need obligatory to put 'COMMIT WORK' after that to make true it or not necesary?

UPDATE zavg_bal_table FROM wa_zavg.

COMMIT WORK

Thanks for the help!

1 ACCEPTED SOLUTION
Read only

former_member156446
Active Contributor
0 Likes
737
UPDATE zavg_bal_table FROM wa_zavg.
if sy-subrc = 0.
COMMIT WORK.
endif.
8 REPLIES 8
Read only

former_member156446
Active Contributor
0 Likes
738
UPDATE zavg_bal_table FROM wa_zavg.
if sy-subrc = 0.
COMMIT WORK.
endif.
Read only

Former Member
0 Likes
737

No its not compulsary to put the commit work statement. But if you dont put that it may take some time depending upon where have you used this code (LUW concept)

and its better to use lock objects before updating the database to avoind any conflict,which might occur if some another person is also trying to update the same kind of data

Read only

Former Member
0 Likes
737

Hello Carlos

If you commit the operation just after the update, if there is an error you wont be able to rollback the operation, so have to be aware of it.

The commit will be automaticaly done after program´s execution.

It depends on what you need...

Bye

Gabriel

Read only

Former Member
0 Likes
737

Thanks to everyone!

But... In the code I check that is I don't put the commit work the update statement not work. If I don't put that, in the table I can't see the records updated...

I have the update statement into a loop... but I don't know why is not working without the commit.

Read only

0 Likes
737

There are some places that SAP will issue its own commit work and I've certainly encountered some report programs, for example, that have relied on this "feature" for them to work... However it is best practice to issue the commit work explicitly - there are some features of SAP that will not work unless you do e.g. a workflow trigger, email send, XI proxy send etc.

Jonathan

Read only

0 Likes
737

Hello Carlos

You wont see the updated records until the program ends...if still not seeing anything check tables keys...your may be repeating data so will not update any records.

Bye

dont forget to reward

Gabriel P-

Read only

Former Member
0 Likes
737

Hi,

It is not compulsory to write Commit statement.

If you commit the operation after the update, if there is an error you wont be able to rollback the operation.

Regards,

Kinjal

Read only

Former Member
0 Likes
737

Thanks all for the responses. Today I will try to wait the finish of the program to see if without the commit statement the update works... because yesterday I tested without waiting the ending execution of the program.

I let you know the results.

Thanks again!