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 Update query

Former Member
0 Likes
514

Hello Friends,

I have one internal table Loop like......

Loop at Itab.

Write : / itab-matnr,itab-maktx.

Endloop.

Now i want to insert This Matnr and Maktx in to one Ztable. and later i want to Update it fro internal table loop.

SO can any one help me that how to use insert n update data in to Ztable from Internal table loop.

Give me an example of code.

Thanks in advance.

Points awarded soon.

-nmz

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
490

Hi Nimesh,

Below code will insert as well as update your database table <b>ZTABLE</b> with respect to data present in internal table <b>itab.</b>

Loop at Itab.

Write : / itab-matnr,itab-maktx.

Endloop.

Modify ztable from table itab.

Note:- If the internal table itab is empty, SY-SUBRC and SY-DBCNT are set to 0.

<b>Reward with points if it helps.</b>

Thanks and regards,

Amit

3 REPLIES 3
Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
490

Hi,

If you want to INSERT if the data is not there and UPDATE if the data is already there in Ztable then use MODIFY instead.

Populate your data into internal table and use like this.


MODIFY ztable FROM table itab. " The data in itab will be inserted/updated into ztable.

Regards,

Sesh

Read only

Former Member
0 Likes
490

Hello,

We have 3 basic operations for your scenario

1) insert....

can be used to insert a new record with a new key to a table

if the insert fails...sy-subrc not equal to zero

2)Update

can be used to update an existing record with the same key

if update fails again sy-subrc will be non-zero

3)Modify

if a record already exists with the same key.-->the record updates the non-key fields of the table

if a record with the same key does not exists -->new record is inserted

if fails nonzero is returned to sy-subrc

you can choose based on your requirement....

for syntax,use SAP information key

Hope it proved useful....

Reward all helpful answers

Regards

Byju

Read only

Former Member
0 Likes
491

Hi Nimesh,

Below code will insert as well as update your database table <b>ZTABLE</b> with respect to data present in internal table <b>itab.</b>

Loop at Itab.

Write : / itab-matnr,itab-maktx.

Endloop.

Modify ztable from table itab.

Note:- If the internal table itab is empty, SY-SUBRC and SY-DBCNT are set to 0.

<b>Reward with points if it helps.</b>

Thanks and regards,

Amit