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: 

Insert statement and commit work

Former Member
0 Kudos

Hello Everyone,

Got doubt about the insert statement.

I have my custom table and using insert statement to insert the records in my custom table.

Sometimes, records get inserted in custom table sometimes not.

If i use commit work statement after insert statement,everytime records get inserted in my custom table.

Why insert statement without commit work does not work properly in my case.

I am using SAP ver 4.7C

Any pointers on this.

Regards,Tarun

5 REPLIES 5

suresh_datti
Active Contributor
0 Kudos

Hi Tarun,

An explicit COMMIT WORK after your INSERT statement commits the changes to the database immediately. Without the COMMIT WORK, the database is updated only after completion of the Program. It is possible that there might be a Program failure,in cases where the database didn't get updated without the COMMIT WORK.

Regards,

Suresh Datti

former_member184569
Active Contributor
0 Kudos

Hello Tarun,

When you use the INSERT statement, the data is not written firmly to the database until a database commit occurs . Before this, you can use a database rollback to undo any changes.

The Open SQL statements INSERT, UPDATE, MODIFY, and DELETE allow you to program database changes that extend over several dialog steps. Even if you have not explicitly programmed a database commit, the implicit database commit that occurs after a screen has been processed concludes the database LUW.

A logical unit consisting of dialog steps, whose changes are written to the database in a single database LUW is called an SAP LUW. Unlike a database LUW, an SAP LUW can span several dialog steps, and be executed using a series of different work processes. If an SAP LUW contains database changes, you should either write all of them or none at all to the database. To ensure that this happens, you must include a database commit when your transaction has ended successfully, and a database rollback in case the program detects an error.

Hope that cleared your doubt.

Thanks,

Susmitha

Former Member
0 Kudos

Hey Tarun,

The Commit Work executes a database commit and thus closes a Logical Unit of Work ( LUW).

The updates and insert in a DB are rolled back in case the program abruptly terminates.

In case of successful completion, the Commit work is called.

When u explicitly mention Commit, Commit work is called then n then n u see the entry in the DB.

The reason u dont see entry in the DB sometimes is probably due to abrupt end of program as a result of which the transactions are rolled back.

Regards,

Tanveer.

<b>Please mark helpful answers</b>

Former Member
0 Kudos

Hi !

The insert only "writes" the data to the database if any COMMIT WORK follows that statement.

Any... that means even an "implicid" COMMIT would be enough.

In that cases your insert worked without an explicid COMMIT you may have a MESSAGE follwing or a new screen or anything that does implicid COMMITs.

You should allways "close" an database-transaction with a COMMIT (or a ROLLBACK of course).

Regards

Rainer

Some points would be nice if that helped a bit.

Former Member
0 Kudos

Hi tarun,

1. Why insert statement without commit work does not work properly in my case

Ideally it should not happen.

The reason is :

2. Whenever we fire a INSERT statement,

COMMIT is necessary so that database changes are done.

3. Now this COMMIT can happen in two ways :

a) either thru the abap code COMMIT WORK

b) or automatically thru SCREEN CHANGE

(ie. - it is called implicit commit,

- whenever the screen changes,

commit work is automatically done by r/3.

4. In your case,

when u notice that database changes have not occured,

u must have seen it, (in another session window)

while u must be ON THE SAME SCREEN of your program.

5. Try to Change your screen,

and then see.

(it will work even without commit work statement)

6. But ideally, in all such cases,

its better to use COMMIT work.

regards,

amit m.