‎2008 Dec 16 4:00 AM
hello gurus
i have a ztable with fields client ,sales organisation,material ,material descriptaion.
so if i want to update one record into ztable do i need to give the client also ie update client also ?
i have written the program to update and it is not working please correct me.
REPORT updatetable .
DATA : BEGIN OF itab OCCURS 0,
mandt TYPE ztable-mandt,
vkorg TYPE ztable-vkorg,
matkl TYPE ztable-matnr,
mtbez TYPE ztable-matkx,
END OF itab.
LOOP AT itab.
itab-mandt = 020. " is nessarcy to populate client also?
itab-vkorg = 'M012'.
itab-matnr = '1230762345'.
itab-matkx = 'RAW MATERIAL'.
APPEND itab.
ENDLOOP.
INSERT INTO ztable VALUES itab.
please correct me where i wrong
‎2008 Dec 16 4:12 AM
Hi Madan,
No it not neccessary to take mandt field like this for inserting a record into database table.
Use it this way, its working.
Internal table declaration
data : begin of itab occurs 0 with header line.
include structure ztable. "include the structure same as database table
data : end of itab.
Or use
data : itab type standard table of ztable initial size 10 with header line.
Now say you have following fileds in your databse table:-
vkorg, matkl, and mtbez.
itab-vkorg = 'M012'.
itab-matnr = '1230762345'.
itab-matkx = 'RAW MATERIAL'.
APPEND itab. "append records into internal table
Similarly you can take more entries into the internal table.
And the insert into database table using this internal table.
insert ztable from table itab. "this will insert records from itab to ztable
Hope this solves your problem.
Thanks & Regards
Tarun Gambhir
‎2008 Dec 16 4:05 AM
after ur loop use update keyword like this:
UPDATE ztable FROM TABLE itab.
‎2008 Dec 16 4:06 AM
REPORT updatetable .
DATA : BEGIN OF itab OCCURS 0,
vkorg TYPE ztable-vkorg,
matkl TYPE ztable-matnr,
mtbez TYPE ztable-matkx,
END OF itab.
LOOP AT itab.
itab-vkorg = 'M012'.
itab-matnr = '1230762345'.
itab-matkx = 'RAW MATERIAL'.
APPEND itab.
ENDLOOP.
MODIFY ZTABLE from itab.
commit work.
‎2008 Dec 16 4:07 AM
hi madan,
initially, you have to declare same ztable structure for internal table , then append value to internal table .
finally you can update value from internal table to ztable.
example : insert into ztable value <internaltable>.
regards,
velmurugan.s
‎2008 Dec 16 4:09 AM
Hi, you have done a big mistake....
DATA : BEGIN OF itab OCCURS 0,
mandt TYPE ztable-mandt,
vkorg TYPE ztable-vkorg,
matkl TYPE ztable-matnr,
mtbez TYPE ztable-matkx,
END OF itab.
why MATKL & MTBEZ here???
At the time of filling the internal table...you have used MATNR & MAKTX......
Correct that error....
Arunima
‎2008 Dec 16 4:12 AM
Hi Madan,
No it not neccessary to take mandt field like this for inserting a record into database table.
Use it this way, its working.
Internal table declaration
data : begin of itab occurs 0 with header line.
include structure ztable. "include the structure same as database table
data : end of itab.
Or use
data : itab type standard table of ztable initial size 10 with header line.
Now say you have following fileds in your databse table:-
vkorg, matkl, and mtbez.
itab-vkorg = 'M012'.
itab-matnr = '1230762345'.
itab-matkx = 'RAW MATERIAL'.
APPEND itab. "append records into internal table
Similarly you can take more entries into the internal table.
And the insert into database table using this internal table.
insert ztable from table itab. "this will insert records from itab to ztable
Hope this solves your problem.
Thanks & Regards
Tarun Gambhir
‎2008 Dec 16 5:51 PM
‎2008 Dec 16 4:16 AM
hi,
.
no not nesessary to give client ,you should check primary key on the z table
you should not use loop and endloop,
give a message ' Record successfully updated' type 'S' . after insert statement
‎2008 Dec 16 4:20 AM
its working try this.
*
"here we declaring inernal table type of standard table
"if we do this than mandt field also come into the structure.
data: itab type standard table of ztable initial size 10 with hedaer line.
" passing value in internal table
itab-vkorg = 'M012'.
itab-matnr = '1230762345'.
itab-matkx = 'RAW MATERIAL'.
APPEND itab.
"inserting value from internal table to data base table.
"this statemant will insert the record into the data base table.
insert ztable from table itab.
Thanks
Arun Kayal.
Edited by: Arun Kayal on Dec 16, 2008 5:21 AM