08-24-2009 8:14 AM
Hi Experts,
Please advice me, as multiple records are not getting updated in table .
select single * from mseg where ............
case sy-tabix.
when 1.
zabc-matnr = matnr1.
zabc-menge = menge1.
zabc-budat = budat.
when 2.
zabc-matnr = matnr2.
zabc-menge = menge2.
zabc-budat = budat.
when 3.
zabc-matnr = matnr3.
zabc-menge = menge3.
zabc-budat = budat.
endcase
INSERT zabc.
Please advice as only the first line is getting updated in zabc table.
08-24-2009 11:02 AM
Why selecting all the data and then write them back? Use Update statement instead.
update mseg
set field1= field1 + 1
where key = 'xyz'.
Thats it. And guess what? Its really performant und saves ressources.
08-24-2009 8:16 AM
08-24-2009 8:19 AM
Hi ,
Why you wrote SY-tabix in case ?
If you are trying to add duplicate recors to the table it will give sy-subrc value non-zero and would not insert any line.
So you can use the MODIFY ztab FROM ztab . Instead INSERT.
Regards
Pinaki
08-24-2009 8:21 AM
HI,
Are you inserting into DataBase table or Internal table
For Database tables
Insert dbtab from table interanal_tab
Please take F1 help for further info
For internal Tables
loop at itab
itab-f1 = x
itab-f2 = y etc
Modify itab index sy-tabix.
endloop.
Cheers
Ramc
Edited by: Ramchander Krishnamraju on Aug 24, 2009 9:23 AM
08-24-2009 9:30 AM
Hi Ram,
Thanx,
I am inserting to database table...
In my senario, where the user enters matnr the corresponding raw materials will display in
seperate seletion-screen.
*note- for each matnr there can be upto 3 raw materials.*
I have used loop at screen and modifid for this, and there are seperate fields where user enters the input
manually and when he executes , the data entered should save in dbtab.
eg-
selection-screen : begin of block b1 with frame.
parameters: s_matnr like mara-matnr,
parameters: s_maktx like makt-maktx modifid th1,
parameters: s_werks like mseg-werks,
parameters: s_budat like mkpf-budat,
selection-screen : end of block b1 with frame.
selection-screen : begin of block b2 with frame.
parameters: s_idnrk1 like resb-idnrk modifid th2,
parameters: s_menge1 like resb-menge modifid th2,
parameters: s_manual1 like zxyz-manual modifid th3,
selection-screen : end of block b2 with frame.
selection-screen : begin of block b3 with frame.
parameters: s_idnrk2 like resb-idnrk modifid th2,
parameters: s_menge2 like resb-menge modifid th2,
parameters: s_manual2 like zxyz-manual modifid th3,
selection-screen : end of block b2 with frame.
selection-screen : begin of block b4 with frame.
parameters: s_idnrk3 like resb-idnrk modifid th2,
parameters: s_menge3 like resb-menge modifid th2,
parameters: s_manual3 like zxyz-manual modifid th3,
selection-screen : end of block b2 with frame.
I have tried all the above said but its not working.
Please advice
Karthik
Edited by: Karthik R on Aug 24, 2009 2:01 PM
08-24-2009 8:25 AM
Hi,
You cannot insert a line if a line with the same primary key
already exists or if a UNIQUE index already has a line with
identical key field values.
Check the table if it already has a value with the same key if thats the case you should use modify.
Regards,
Himanshu
08-24-2009 8:33 AM
Hi,
Select Single * will pickup only one matching record from the database into the buffer, and returns the same to the internal table..
so try with Select *.
Regards,
Sudha S.
08-24-2009 8:40 AM
Hi Kartik,
Check your Z table's primary key. Use MODIFY instead of INSERT.
Regards,
Rajitha.
08-24-2009 9:36 AM
You can fetch multiple records and updte these records into ztable all at a time so there is no need to to use case statement.
Example
Select * from mseg into table itab where......
modify ztab from table itab.
Modify statement performs the combined operation of insert and update. It means if record doesnt exixt in table then it will insert the new recod else it will update the existing record.
Hope this will help you.
08-24-2009 11:02 AM
Why selecting all the data and then write them back? Use Update statement instead.
update mseg
set field1= field1 + 1
where key = 'xyz'.
Thats it. And guess what? Its really performant und saves ressources.