‎2009 Nov 19 7:48 AM
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
‎2009 Nov 19 8:53 AM
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
‎2009 Nov 19 7:57 AM
Hi,
Add a Wait statement before the Commit work
Wait 2 seconds.
Commit work.
Hope this should work fine.
Thanks
Guru
‎2009 Nov 19 8:08 AM
‎2009 Nov 19 8:11 AM
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
‎2009 Nov 19 8:23 AM
Hi All,
Thank you for your inputs.
But unfortunately, i still get the same result.
Sometimes it updates, sometimes not.
Any other ideas?
‎2009 Nov 19 8:53 AM
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
‎2009 Nov 19 8:56 AM
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.
‎2009 Nov 19 9:01 AM
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
‎2009 Nov 19 9:26 AM
Hi Swarna.
I think your proposed solution solved it.
But i will still test it further in QAS.
Thank you!
Regards,
Joan
‎2009 Nov 19 9:08 AM
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