‎2007 Jun 25 7:01 AM
Hi Friends,
I want to update my database table with new record for this I wrote a coding like this, but i am unable to update the database table please find my coding:
LOOP AT lt_invmov INTO lw_invmov WHERE check = 'X'.
SELECT MAX( trans )
INTO zinv_mov-trans FROM zinv_mov.
IF sy-subrc EQ 0.
zinv_mov-trans = zinv_mov-trans + '0000000001'.
ELSE.
MOVE '0000000001' TO zinv_mov-trans.
ENDIF.
itab-lifnr = lw_invmov-lifnr.
itab-xblnr = lw_invmov-xblnr.
itab-bukrs = lw_invmov-bukrs.
itab-usnam = zinv_mov-usnam.
itab-appdate = sy-datum.
MOVE 'V2' TO itab-status.
MOVE 'CL' TO itab-clear.
APPEND itab.
INSERT INTO zinv_mov VALUES itab.
ENDLOOP.
ENDIF.
Regards,
Line
‎2007 Jun 25 8:53 AM
1. refresh your itab just before the select max statement
2. to update the dbtable use modify stt.
modify zinv_mov from table itab .
this way even if a record exists in the dbatable with the same key it will not dump
Raja
‎2007 Jun 25 7:04 AM
Hi Line,
Please write commit-work after insert statement.
Try it.
Reward if useful!
‎2007 Jun 25 7:10 AM
Hi Line ,
Your code seems to be correct , what is the value of sy-subrc you get after the insert command.
I would also suggest you one thing , currently you are inserting the data into internal table itab and the inseerting the table with data in the header , what i would suggest is instead of using the insert command for each record , why dont you insert all the records at one go , after ENDLOOP.
Use the syntax
INSERT dbtab FROM TABLE itab .
Regards
Arun
‎2007 Jun 25 7:32 AM
Yes I am getting sy-subrc = 4 at the insert statement. please suggest me
Regards,
Line
‎2007 Jun 25 7:57 AM
Hi Line ,
So it basically means that record is not getting inserted into the table , please check if there is already a record with the same key feilds in the database.
Generally it is better to use modify command , as it will insert a new record if it is not there or modify the existing record , where as insert will try only to insert a record if a record with the same key already exists then it will give sy-subrc as 4.
Try with modify command and see.
Regards,
Arun
‎2007 Jun 25 7:14 AM
do like this it may help you..
LOOP AT lt_invmov INTO lw_invmov WHERE check = 'X'.
SELECT MAX( trans )
INTO zinv_mov-trans FROM zinv_mov.
IF sy-subrc EQ 0.
zinv_mov-trans = zinv_mov-trans + '0000000001'.
ELSE.
MOVE '0000000001' TO zinv_mov-trans.
ENDIF.
itab-lifnr = lw_invmov-lifnr.
itab-xblnr = lw_invmov-xblnr.
itab-bukrs = lw_invmov-bukrs.
itab-usnam = zinv_mov-usnam.
itab-appdate = sy-datum.
MOVE 'V2' TO itab-status.
MOVE 'CL' TO itab-clear.
APPEND itab.
ENDLOOP.
INSERT INTO zinv_mov from table itab.
ENDIF.
your itab should be like zinv_mov .
regards
shiba dutta
‎2007 Jun 25 7:59 AM
first check whether your itab is like dbtab or not? then confirm that whether key fields of the table are you filling or not ? I think you have to fill the values in key fields also you can not insert initial value in key fields.
regards
shiba dutta
‎2007 Jun 25 8:15 AM
Shiba,
Itab is like dbtab.
All the key fields are filling in the intenal table.
All the records are updated in the internal table but not in the database table.
Regards,
Line
‎2007 Jun 25 8:53 AM
i dont know why it is happening you can try
insert dbtab from table itab accepting duplicate keys.
if you are trying some duplicate keys to enter then it will not insert in the database table. only the previous value will be there for that key... Just check whether you are repeating the keys or not(may be already exist in the dbtab)? and use commit work after insert.
regards
shiba dutta
‎2007 Jun 25 8:53 AM
1. refresh your itab just before the select max statement
2. to update the dbtable use modify stt.
modify zinv_mov from table itab .
this way even if a record exists in the dbatable with the same key it will not dump
Raja