‎2008 Jun 25 1:48 PM
Hello,
Wanted to know if the INSERT statement has a COMMIT within itself or do i need to explicitly use a COMMIT after the INSERT.
Also please let me know the process of ROLLBACK after a INSERT statement
Regards,
Prav
‎2008 Jun 25 1:50 PM
hi praveen,
plz search sdn for such queries..and abide by the rules of engagement..
on the right hand side dere is search provided for such questions...
a lot of stuff is available for dis..
‎2008 Jun 25 1:56 PM
Praveen,
yes Commit is must after insert.
see my sample code:
IF r_update = 'X'.
INSERT zpayroll FROM it_final.
* modify zpayroll FROM it_final.
IF sy-subrc = 0.
COMMIT WORK.
ELSE.
UPDATE zpayroll FROM it_final.
IF sy-subrc = 0.
COMMIT WORK.
ENDIF.Also i woud suggest always prefer SAP help by pressing F1 on that keyword.because somtime we may miss but SAP never.
Amit.
‎2008 Jun 25 1:56 PM
Hi,
Lines specified with the INSERT command are not finally
added to the database table until after a database commit
You can use the following syntax for the same:
ROLLBACK WORK.
Regards,
Himanshu Verma
‎2008 Jun 25 1:58 PM
Hi Praveen,
INSERT/UPDATE/DELETE/MODIFY: none of these has implicit commit.
eg: If u are using it in a program then immediately after insert ur database will not be updated unless u do explicit commit or finish the execution of program(This will do implicit commit).
Coming to rollback, Rollback will work if u havenot used explicit commit. If the changes are commited using COMMIT WORK statement u cant revert the changes by ROLL BACK statement. This is just to stop the updation of the database from application server when u completely execute the program
eg: Line 5 has INSERT statement.
line 20 has some CHECK and later ROLL BACK. If u have not used COMMIT WORK between line 5 to 20 and check satisfies then ur INSERT statement will not have any effect here because ur changes gone till application server and deleted by ROLL back statement.
Hope it is clear.
Thanks,
Vinod.
‎2008 Jun 25 1:59 PM
Hi,
Since, as a rule, an application program is processed by several work processes in succession, and every change of the work process is linked to an implicit database commit, an application program is not automatically linked to a single database LUW.
This applies in particular to dialog-oriented applications, in which one database LUW is assigned to one dialog step.
To ensure the data consistency of application programs that are executed across different work processes, the application statements are not directly executed in an SAP LUW.
Instead, they are first registered and then executed by a single work process, that is, in a single database LUW.
A SAP LUW is controlled via the Open SQL statements
COMMIT WORK
ROLLBACK WORK
SET UPDATE TASK LOCAL.
Explict Commit after the INSERT statement is necessary to effect the changes to the database.
To use RollBack.
INSERT...
Rollback work.
Warm Regards,
R Adarsh
‎2008 Jun 25 2:28 PM
Hello guys,
Thank you all for the answers. it helped to clear my doubts.
‎2008 Jun 25 2:29 PM
Its a basic thing if your doubt is closed than please reward all.
Amit.
‎2008 Jun 25 2:36 PM
Hi Praveen.
Yes, We have to include a 'commit' statement after insert statement,
Because, The database changes that occur within a database LUW are not actually written to the database until after the database commit.
Also, The roll-back process is related to the commit statement.
__Roll-back process:__
A roll-back is a process of reversal of changes made to the database.
This is necessary when we but rarely encounter some errors in the database actions or inconsistent data.
First, you must know LUW- logical unit of work.
It is a sequence of database operations that end with a database commit.
The database LUW is either fully executed by the database system or not at all. Once a database LUW has been successfully executed, the database will be in a consistent state.
If an error occurs within a database LUW, all of the database changes since the beginning of the database LUW are reversed.
This leaves the database in the state it was in before the transaction started.
So, To reverse this undesired state or reverse changes or return to original state we use Roll back as these changes are not written into the database.
This process is called Roll back work process.
Hope this solves your query & in case you are not satisfied,
feel free to discuss again.
And give justice to this answer accordingly.
Take care
Harsh Dave