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

Database Commit

Former Member
0 Likes
1,026

Hi All,

i need to insert a line item in my ztable.

for some reason, sometimes it works, sometimes it doesn't.

i already added the commit work, still, same thing happens.

when i run it through debug mode, the database gets updated successfully.

but when i run the program i made, it does not update.

if sy-subrc eq 0.

insert into ztab_equip values wa_ztab.

commit work.

else.

delete from ztab_equip

where begda eq is_header_dialog-gstrs and

aufnr eq is_header_dialog-aufnr and

equnr eq ly_equnr.

commit work.

endif.

is there anything else that i need to add? or do i need to use commit work and wait.

thanks!

-jo

1 ACCEPTED SOLUTION
Read only

JackGraus
Active Contributor
0 Likes
979

Your database table is only updated when SY-SUBRC eq 0. So your database table might not be updated because the statement(s) before this code fragment is(are) not executed succesfuly giving SY-SUBRC ne 0.

Regards Jack

9 REPLIES 9
Read only

Former Member
0 Likes
979

Hi,

Add a Wait statement before the Commit work

Wait 2 seconds.

Commit work.

Hope this should work fine.

Thanks

Guru

Read only

RaymondGiuseppi
Active Contributor
0 Likes
979

Try to call the FM DB_COMMIT. ([Database Commit |http://help.sap.com/abapdocu_70/en/ABENDB_COMMIT.htm])

Regards,

Raymond

Read only

Former Member
0 Likes
979

Hi Geniusrain,

Why dont you try MODIFY & then do database commit with wait.

IF sy-subrc EQ 0.
  MODIFY ztab_equip FROM wa_ztab.
  COMMIT WORK.
ELSE.
  DELETE FROM ztab_equip
  WHERE begda EQ is_header_dialog-gstrs AND
  aufnr EQ is_header_dialog-aufnr AND
  equnr EQ ly_equnr.
  COMMIT WORK.
ENDIF.

Kindly set to resolved if it helps you.

Regards

Abhii...

Edited by: Abhii on Nov 19, 2009 9:12 AM

Read only

Former Member
0 Likes
979

Hi All,

Thank you for your inputs.

But unfortunately, i still get the same result.

Sometimes it updates, sometimes not.

Any other ideas?

Read only

JackGraus
Active Contributor
0 Likes
980

Your database table is only updated when SY-SUBRC eq 0. So your database table might not be updated because the statement(s) before this code fragment is(are) not executed succesfuly giving SY-SUBRC ne 0.

Regards Jack

Read only

Former Member
0 Likes
979

Hi Jack,

I tried putting that statement already.

insert into ztab values of wa_tab.

if sy-subrc ne 0.

commit work and wait.

enif.

so that if the insert command didnt work and returned a subrc ne 0, i can do commit and maybe it will write.

what bugs me is that when i pass the codes on debug mode, it works perfectly.

but when i just execute it. it does not perform as i expected/coded it to be.

Read only

0 Likes
979

Hi,

You should keep commit for success of insert.


insert into ztab values of wa_tab.

if sy-subrc eq 0. " it should be eq
commit work and wait.
wait upto 2 sec.
endif.

Regards,

Swarna Munukoti

Read only

Former Member
0 Likes
979

Hi Swarna.

I think your proposed solution solved it.

But i will still test it further in QAS.

Thank you!

Regards,

Joan

Read only

RaymondGiuseppi
Active Contributor
0 Likes
979

Did you actually check the record did not exist before inserting in database. If INSERT returns a sy-subrc = 4, then there is already a record with the same primary key. Also there may be garbage in the work area that is rejected by the SQL system (check via SM21)

If you have a duplicate key or invalid data (for database) no commit will correct it for you.

Regards,

Raymond