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 data into ztable

Former Member
0 Likes
3,538

i have itab with 1200 lines

and i make

loop at itab.

insert into ztable values itab.

endloop.

and at the end i get 1000 lines, where are the 200 lines and how i can catch them..

1 ACCEPTED SOLUTION
Read only

andrea_galluccio2
Contributor
0 Likes
1,204

Hi,

simply check the sy-subrc value after the insert instruction.

If it's different from 0, the record is not inserted.

Probably the destination table is type standard/sorted table with unique key.

Best Regards

Andrea

7 REPLIES 7
Read only

Former Member
0 Likes
1,204

Probably itab has entries with duplicated key, so that's why you are "losing" those 200 entries.

Read only

andrea_galluccio2
Contributor
0 Likes
1,205

Hi,

simply check the sy-subrc value after the insert instruction.

If it's different from 0, the record is not inserted.

Probably the destination table is type standard/sorted table with unique key.

Best Regards

Andrea

Read only

Former Member
0 Likes
1,204

Hi,

First you have to know the usage of insert:

INSERT INTO <target> <lines>.

It allows you to insert one or more lines into the database table <target>. You can only insert lines into an ABAP Dictionary view if it only contains fields from one table, and its maintenance status is defined as Read and change. You may specify the database table <target> either statically or dynamically

Hence there might be chance that there already exists record with same key and hence the data is not inserted..Instead use MODIFY statement....

To insert lines into a database table regardless of whether there is already a line in the table with the same primary key, use the following:

MODIFY <target> <lines>.

If the database table contains no line with the same primary key as the line to be inserted, MODIFY works like INSERT, that is, the line is added.

If the database already contains a line with the same primary key as the line to be inserted, MODIFY works like UPDATE, that is, the line is changed.

For performance reasons, you should use MODIFY only if you cannot distinguish between these two options in your ABAP program.

You can add or change one or more lines <lines> in a database table <target>. You can only insert or change lines in an ABAP Dictionary view if it only contains fields from one table, and its maintenance status is defined as Read and change. You may specify the database table <target> either statically or dynamically.

Regards

Shiva

Read only

Former Member
0 Likes
1,204

Hi Sikken,

Check sy-subrc value after INSERT statement.You can find the list which does not have 0 as sy-subrc.

Check the definition of database table whether it has primary key(s). If you want to insert any entry with duplicate entries to primary key will not insert the entry to database table.

Otherwise, you the following statement to add records to database table from internal table at one shot

INSERT dbtab FROM TABLE itab

Thanks,

Vinay

Read only

Former Member
0 Likes
1,204

jus check ig ur passing the values to the same set of primary keys.

for example: if u insert data into the table for a set of primary keys and u again insert data for the same set of primary keys, then it will jus over write the existing entry with new entry.

Read only

Former Member
0 Likes
1,204

Hi,

Instead of insert use modify statement....then in case the key is duplicate, your record that you want to add will update the Ztable and when the key wiil not match it will add new rows to the ztable

loop at itab into wa.

modify ztab from wa index sy-tabix.

clear wa.

endloop.

regards,

Prinan

Read only

Former Member
0 Likes
1,204

what are the key fields of the database table...also let me know how u have declared the internal table...

Regards,

SG