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 into dbtab from itab

Former Member
0 Likes
4,205

Hi friends,

I have a strange problem. The INSERT statement to insert mass records into a z table from an internal table results in a short dump even if the table does not contain any records and the internal table entries are unique. If we use ACCEPTING DUPLICATE ENTRIES nothing is updated. The internal table structure is the same as the database table.What could be wrong?

Prompt replies would be rewarded.

Thanks in advance.

Tamilarasan.

8 REPLIES 8
Read only

former_member221770
Contributor
0 Likes
2,685

Hi Tamilarasan,

When using the INSERT dbtab FROM TABLE itab command, you must make sure that the itab is defined EXACTLY the same as the dbtab (including MANDT).

eg:


data: tbl_ztab type table of ztable with header line.

insert ztable from table tbl_ztab accepting duplicate keys.

Otherwise you can try the MODIFY command.

Hope this helps.

Cheers,

Pat.

Read only

Former Member
0 Likes
2,685

What is the error message? Is your Z table empty before you run the program oe they are deleted within the program and reinserted? If they are deleted and reinserted in the same program run, then your problem most probably is due to buffering. Do a commit and wait after your delete statment and do your INSERT with the option BYPASSING BUFFER.

Read only

0 Likes
2,685

Hi Srinivas,

The error message says something like 'an attempt is made to insert duplicate entries'.The z table entries are not deleted in the program. I am just trying to insert records from an internal table into the database table.

By the way do we have BYPASSING BUFFER option in INSERT?

Thanks

Tamilarasan.

Message was edited by: Tamilarasan Lakshmanan

Read only

0 Likes
2,685

Hi,

Just check the already existing records in your z table.If the records having space as value for primary key and if you are trying to insert the blank record(may be without knowingly),there is possiblity of dump.Because I faced the same problem recently.

You can do one thing.

You can find out which record is actually duplicated by the following code.

loop at itab into wa.

insert ztable from wa.

if sy-subrc ne 0.

message i000 with 'Record is not inserted.Check for work area record whether it is in database table'.

endif.

endloop.

Definetely this won't show dump.

After you identified that duplicated record,you can remove the message statement.

Or you can also use Modify.

This will take care of inserting[if no such record already] or updating[if such record already exists].

Kindly reward points if it is helpful.

Read only

0 Likes
2,685

it will help if you can post your code here...and if possible internal table structure and contents...

rgds,

PJ

Read only

0 Likes
2,685

Hi,

If u dont want to have duplicae entries before inserting just

DELETE ADJACENT DUPLICATES FROM internal table

.

Then do an

INSERT

.

Read only

0 Likes
2,685

>> By the way do we have BYPASSING BUFFER option in INSERT?

No, that was a mistake I did. It is available with SELECT. I thought you are doing a SELECT of all or some Z table records into an internal table that you will use later to delete the records. So instead of mentioning the option for SELECT, I incorrectly said INSERT. Sorry about that.

Now coming to the issue, even if you are using the option "ACCEPTING DUPLICATE KEYS", it will not insert the duplicate record. What it does is to avoid runtime error. See the documentation here.

"<i>If the system cannot insert a line, the program does not terminate with a runtime error. Instead, SY-SUBRC is set to 4. All lines of the internal table after the one that could not be inserted are still inserted into the database table.</i>"

So, using this option, you should still be able to insert the records, but for the duplicate record.

Srinivas

Read only

0 Likes
2,685

the best option would be to use

modify <dbtab> from table <itab>.

Regards

Raja