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

internal table validation

killspree07
Newcomer
0 Likes
1,514

I have an internal table with some data lets say emp no, emp salary,emp dob,etc. I have a database table with the same entries .I need to copy the internal table in the DB table while no duplicate entries should be populated. How to do this validation part? Please help.

1 ACCEPTED SOLUTION
Read only

ClausB
Active Participant
1,429

This statement could help you.

Hint: If possible never write directly to SAP tables

MODIFY <your_db_table> FROM TABLE <your_itab>.
5 REPLIES 5
Read only

lenastodal
Product and Topic Expert
Product and Topic Expert
0 Likes
1,429

Hi Rahul,
Warm welcome and thank you for visiting SAP Community to get answers to your questions. Since you're asking a question here for the first time, I recommend that you familiarize yourself with https://community.sap.com/resources/questions-and-answers (if you haven't already), as it provides tips for preparing questions that draw responses from our members. For example, you can outline what steps you took to find answers (and why they weren't helpful), share screenshots of what you've seen/done, make sure you've applied the appropriate tags, and use a more descriptive subject line. The more details you provide, the more likely it is that members will be able to assist you.
Should you wish, you can revise your question by selecting Actions, then Edit (although once someone answers your question, you'll lose the ability to edit the question -- but if that happens, you can leave more details in a comment).
Finally, if you're hoping to connect with readers, please consider adding a picture to your profile. Here's how you do it: https://www.youtube.com/watch?v=F5JdUbyjfMA&list=PLpQebylHrdh5s3gwy-h6RtymfDpoz3vDS. By personalizing your profile with a photo of you, you encourage readers to respond.

Best regards,
Lena (SAP Community Global Moderator)


Join or subscribe to SAP Community Groups to stay up-to-date, including SAP TechEd Group.
Read only

FredericGirod
Active Contributor
1,429

This is not a place where people will do your job, it is a place for technical HELP.

So, please, give us the problem you have, describe what you have already done

Read only

ClausB
Active Participant
1,430

This statement could help you.

Hint: If possible never write directly to SAP tables

MODIFY <your_db_table> FROM TABLE <your_itab>.
Read only

michael_piesche
Active Contributor
0 Likes
1,429

Where do you have duplicate entries? In your internal table or between internal and database table?

1) Duplicate entries in internal table

In order to make sure that you dont have duplicate entries in your internal table, use the following coding to eliminate duplicates. The table need to be sortable, e.g. a standard table would do.

SORT itab BY key1 key2 key3.
DELETE ADJACENT DUPLICATES FROM itab COMPARING key1 key2 key3.

2) Duplicate entries between internal and database table

If you have duplicate entries between internal and database table, you have two options: a) Only insert new records, disregard existing records, or b) insert new records and update existing records.

2a) Insert new records only, disregard existing records

If the addition ACCEPTING DUPLICATE KEYS is specified, all rows are inserted for which this is possible. The remaining rows are discarded and sy-subrc is set to 4. The system field sy-dbcnt is set to the number of rows that are inserted. (I normally would not recommend using this addition, as it clearly shows, that you are not 100% in control of what is in and what goes in that table.)

INSERT dbtable FROM TABLE itab ACCEPTING DUPLICATE KEYS. 

2b) Insert new records and update existing records

If you want to insert new records and update existing records, use modify instead of insert.

MODIFY dbtable FROM TABLE itab.
Read only

michael_piesche
Active Contributor
0 Likes
1,429

killspree07, do you continue to have issues with your coding or were you able to solve your problem?

Please add comments to your question that further describe your problem or add an answer that describes how you solved your problem.
If your problem is solved, accept an answer if it helped you and please close the question.