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

Modify Table

Former Member
0 Likes
767

Hello,

I have to save 4 records in a table. When I use the command MODIFY FROM TABLE is only saving 2 records. What is the problem that may be occurring?

Thank“

6 REPLIES 6
Read only

Former Member
0 Likes
741

Maybe the other two are already existing in the table with the same keyfield values.

Regards

Read only

Former Member
0 Likes
741

Hi

Check the key combination of the records, if the key combination is different then only it inserts else modifies the records

Regards

Shiva

Read only

MarcinPciak
Active Contributor
0 Likes
741

Try this:


data: inserted type i,
        modified type i.

loop at itab.
   insert itab into table itab.
   if sy-subrc = 0 .
     add 1 to inserted
  else.
    modify table from itab.
    if sy-subrc = 0.
      add 1 to modified.
    endif.
   endif.
endloop.

write: 'Inserted', inserted,
       / 'Modified', modified.

Regards

Marcin

Read only

Former Member
0 Likes
741

Thanks for the help of everyone, could solve the problem

Thank“

Read only

Former Member
0 Likes
741

hi,

this is due to double entry of data based on key combination

MODIFY

a line is searched for in the database table that has the same content in the primary key as the corresponding beginning part of the work area.

If such a line is not found, a new line is inserted according to the same rules as for the INSERT statement.

If such a line is found, this line is overwritten according to the same rules as for the UPDATE statement.

If the change would lead to a double entry in a unique secondary index, then it is not executed

hope it helps you.

thanks

Sachin

Read only

Former Member
0 Likes
741

Hi Friend,

The Modify statement checks the key fields first, if the key fields are same them it will modify the same record without inserting the new record. Therefore check with the key fields and see that it already exist, If this is the case then it will not insert the new record instead modify the same record as well.

If the key fields have some different values then it will append the new record in the internal table.

Hope the answer of your question.

Regards,

Md Ziauddin.