12-18-2006 12:17 AM
hi! i am tryin to update ztable from an internal table(8 records). but i see that only one record gets updated in ztable. i used the followin code
loop at itab into wa.
modify z3pus from wa.
commit work.
if sy-subrc <>0.
write: / 'fail'.
else.
write: / 'success'.
endif.
endloop.
(used insert and update also not much luck.....)
i got output 'success' 8 times..........but i see only one record in ztable. what could possibly go wrong???????????????
12-18-2006 12:53 AM
Hi Dilip,
when u write in the way u wrote it makes a performance issue as u r trying to update the database table in the loop. so each time it triggers the database and is not suggested.
instead u can update the database Z table just like this.
modify Z3PUS from table itab.
if sy-subrc = 0.
write : / 'Success'.
else.
write : / 'Fail.
endif.
Regards
- Gopi
12-18-2006 2:26 AM
You're checking sy-subrc after your COMMIT WORK statement, not the MODIFY statement.
COMMIT WORK always sets sy-subrc to 0, even if MODIFY set a different sy-subrc earlier on.
Hope that helped.
12-18-2006 4:31 PM
hey gopi i tried what u said. i got output as success but still i see only one record.
12-20-2006 6:36 AM
You can try this .
loop at itab.
Ztab-field1 = itab-field1.
ztab-field2 = itab-field2.
modify ztab.
commit work.
endloop.
Rewards interms of points expected.
Message was edited by:
Manu Kapur
12-18-2006 4:39 AM
Hi Dilip ,
Did you check if the database table already contains the records havving the primary key same as that of your internal table.
Regards
Arun
12-18-2006 4:43 AM
hi,
before that :- modify statemnt will modify a record if there is record having the same key like that of record in work area.
if there is no record in itab with key of work area record, it will insert a new record in itab.
Rgds
Anver
12-18-2006 6:46 AM
12-18-2006 6:56 AM
Do not direcly modify from work are.
Atfirst select, if record presents then update.
*select record with
loop at ITAb.
select single * from ztable into wa
where a = ITAB-a and
b = ITAb-b.
*if there is, mark
if sy-dbcnt eq 1.
modify ztable from wa.
commit work.
endif. " modify the record
endloop.
12-18-2006 9:16 AM
Hi Dilip,
I can see problem due to Primary Key or Index of <b>z3pus</b> table. Please check <b>z3pus</b> table whether you have defined the Primary Key or Index. Write COMMIT WORK after your END...LOOP.
Regards,
Ramki.
12-18-2006 4:00 PM
Two things
You are getting sy-subrc eq zero because the commit work will set sy-subrc zero.
The problem you are facing related to updation is because either you are trying to insert the same data again and again which violates primary key/unique key.
Try with the statement
insert z3pus from wa.