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

Is it necessary to commit after insert statement ?

former_member220286
Participant
0 Likes
6,938

Hi Gurus ,

Hi I have a requirement that I need to update by ztable with insert statement in an fm .I just want to know that is it necessary that after insert we need to write the commit statement .Please suggest .

DATA(lv_length) = strlen( lv_sernr ).
IF lv_length > 10 .
wa_meterno-meter_no = lv_sernr.
SELECT SINGLE meter_no FROM zmeter_no INTO @lv_meter_no WHERE meter_no = @wa_meterno-meter_no.
IF sy-subrc <> 0 .
INSERT zmeter_no FROM wa_meterno.
CLEAR wa_meterno.
ENDIF.

Regards

Deep

9 REPLIES 9
Read only

FredericGirod
Active Contributor
5,853

If you do a commit, you will saved all the database modification done in your program. (so maybe other done before)

If you do nothing, depending of the type of FM, the commit will be implicite.

That means, you commit only if you really need to have the data stored in the database, because you will use it just after this INSERT statement.

Read only

joltdx
Active Contributor
5,853

Hey, frdric.girod, make that an answer instead of a comment, so I can upvote it... 🙂

Read only

Sandra_Rossi
Active Contributor
5,853

After a database update, as per database principle, you must COMMIT or ROLLBACK. Doing nothing is non-sense, or it means that you know you are part of a whole process which ends with a COMMIT or ROLLBACK. Search the Web for more information (ACID for instance, atomicity, consistency, isolation, durability)

Read only

joltdx
Active Contributor
0 Likes
5,853

sandra.rossi Yes, I think you and I agree here. In this case i think the question is about a function module (if that is what "insert statement in an fm" is), and then it should most likely be a "part of a whole process". I prefer FM's, and methods, to not COMMIT everything they do. It should be done but in a controlled manner, which also would give the possibility of a ROLLBACK if needed.

Or did I misunderstand you?

Read only

Sandra_Rossi
Active Contributor
5,853

Jörgen Lindqvist Well I don't understand what you mean. I don't want to talk about FMs and methods, because I don't know the context of the OP question (I let you the responsibility of "most likely"). The only thing I can say is that there must be a COMMIT and a ROLLBACK somewhere. Maybe that answers the question, maybe not, I don't know.

Read only

joltdx
Active Contributor
5,853

Yes, sandra.rossi, I see, and we agree. 🙂

These questions are not always clear to understand, but OP says "update by ztable with insert statement in an fm". In my interpretation it's a question about a function module, that's why I was asking... But you never know... 🙂

Read only

Abinathsiva
Active Contributor
0 Likes
5,853

Hi,

usually for inserting data to ztable - Insert statement is sufficient. modify also can be used, commit is not required.

Read only

Sijin_Chandran
Active Contributor
5,853

Hi,

Must say the information you have mentioned here is not sufficient for this, but let me try answering this by trying to cover all the aspects.

You have just mentioned INSERT in an FM, now here are the points :

1. If the FM is a SMOD EXIT FM you don't need any COMMIT, because Standard Transactions COMMIT will take care of everything.

2. You should never use COMMIT inside an EXIT/BADI/Enhancements etc because it will affect the Data consistency. In case you need to update DATA in a Custom Table , create a FM with UPDATE Task and put the INSERT statement inside that FM and call this FM in the Enhancement. This is similar to the Point 1 only.

3. Apart from this if you are doing an INSERT statement in a Custom Program then you can call COMMIT after INSERT.

Hope this answers.

Thanks,

Sijin

Read only

0 Likes
5,853
2. You should never user COMMIT inside an EXIT/BADI/Enhancements etc because it will affect the Data consistency. 

I feel like I should explain this as well. So here we go.

Suppose in an EXIT for PO you have wrote a code for updating a ZTABLE with respect to a PO. Then that Table should be updated only if we are sure that PO itself gets updated to DB successfully.

This can be made sure or taken care by updating the ZTABLE in the Update Task FM. On the contrary if you use COMMIT inside EXIT for Table INSERT, it will independently update that ZTABLE without waiting for the PO to COMMIT to DB. Resulting to an inconsistent Data.

Hope I was able to make you understand.