Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

insert record into table

Former Member
0 Likes
2,283

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

1 ACCEPTED SOLUTION
Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
998

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

8 REPLIES 8
Read only

Former Member
0 Likes
998

after ur loop use update keyword like this:

UPDATE ztable FROM TABLE itab.

Read only

Former Member
0 Likes
998
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.
Read only

Former Member
0 Likes
998

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

Read only

Former Member
0 Likes
998

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

Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
999

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

Read only

Former Member
0 Likes
998

TARUN you have explained clearly thank you and also to all

Read only

Former Member
0 Likes
998

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

Read only

Former Member
0 Likes
998

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