2013 Aug 19 5:37 AM
Hi Experts,
I have requirement to update z-table from an internal table.But,If some entries from the internal table exist in z-table then those entries should not get inserted/modified/updated.
I found one solution but it creates performance issue(i think).....
Solution i found::-
Take all records from z-table.
Delete records from internal table which matches above fetched records.
Now,insert remaining records into z-table.
Taking all records from z-table may take huge time.....
What is another feasible solution????
Thanks & Regards,
Abdul
2013 Aug 19 11:24 AM
S/m Abdul,
The approach you are following is absolutely correct but one change.
for all the records you have to insert in table it_insert.
Put a select on Z table with a for all entries in it_insert.
Now loop on the table after select and delete these entries from it_insert.
This way you can also list the records which were duplicate and ignored.
Cheers.
S/m Abdul,
The approach you are following is absolutely correct but one change.
for all the records you have to insert in table it_insert.
Put a select on Z table with a for all entries in it_insert.
Now loop on the table after select and delete these entries from it_insert.
This way you can also list the records which were duplicate and ignored.
Cheers.
2013 Aug 19 5:42 AM
Hi Abdul Rahiman Nadaf,
Just use insert......
Like this
INSERT YVTABLE FROM TABLE IT_YVTABLE ACCEPTING DUPLICATE KEYS.
for example see this
DATA : WA_YVTABLE TYPE YVTABLE1,
IT_YVTABLE TYPE TABLE OF YVTABLE1.
WA_YVTABLE-CARRID = 'TR'.
WA_YVTABLE-CONNID = '456'.
WA_YVTABLE-PRICE = '2000'.
APPEND WA_YVTABLE TO IT_YVTABLE.
CLEAR WA_YVTABLE.
WA_YVTABLE-CARRID = 'RT'.
WA_YVTABLE-CONNID = '456'.
WA_YVTABLE-PRICE = '2000'.
APPEND WA_YVTABLE TO IT_YVTABLE.
CLEAR WA_YVTABLE.
WA_YVTABLE-CARRID = 'RT'.
WA_YVTABLE-CONNID = '457'.
WA_YVTABLE-PRICE = '2000'.
APPEND WA_YVTABLE TO IT_YVTABLE.
CLEAR WA_YVTABLE.
WA_YVTABLE-CARRID = 'TS'.
WA_YVTABLE-CONNID = '459'.
WA_YVTABLE-PRICE = '2000'.
APPEND WA_YVTABLE TO IT_YVTABLE.
CLEAR WA_YVTABLE.
INSERT YVTABLE1 FROM TABLE IT_YVTABLE ACCEPTING DUPLICATE KEYS.
WRITE :/ 'NO OF RECORDS INSERTED SUCCESSFULLY', SY-DBCNT COLOR 2.
YVTABLE1
2013 Aug 19 5:50 AM
Hello Ramesh,
Thanks for your reply but i dont want duplicate entries.I just want to ignore entries which are previously present in z-table....
Regards,
Abdul
2013 Aug 19 5:56 AM
Hi Abdul,
See above above code it will never allows duplicate entries to modify, it will ignores duplicate entries.
once again please see above code..
I am passing like this
WA_YVTABLE-CARRID = 'RT'.
WA_YVTABLE-CONNID = '456'.
WA_YVTABLE-PRICE = '2000'.
APPEND WA_YVTABLE TO IT_YVTABLE.
CLEAR WA_YVTABLE.
WA_YVTABLE-CARRID = 'RT'.
WA_YVTABLE-CONNID = '457'.
WA_YVTABLE-PRICE = '2000'.
APPEND WA_YVTABLE TO IT_YVTABLE.
CLEAR WA_YVTABLE.
RT is keyfiled in ytable.
so it is taken this
WA_YVTABLE-CARRID = 'RT'.
WA_YVTABLE-CONNID = '456'.
WA_YVTABLE-PRICE = '2000'.
APPEND WA_YVTABLE TO IT_YVTABLE.
CLEAR WA_YVTABLE.
ignoring this, because it is duplicate
WA_YVTABLE-CARRID = 'RT'.
WA_YVTABLE-CONNID = '457'.
WA_YVTABLE-PRICE = '2000'.
APPEND WA_YVTABLE TO IT_YVTABLE.
CLEAR WA_YVTABLE.
2013 Aug 19 5:46 AM
Hi Abdul,
Use MODIFY statement. It will do the needful.
Check this link:
http://help.sap.com/saphelp_45b/helpdata/en/34/8e73d66df74873e10000009b38f9b8/content.htm
Also check for INSERT:
http://help.sap.com/saphelp_470/helpdata/en/fc/eb3a6d358411d1829f0000e829fbfe/content.htm
It will be helpful
Regards,
Shahir Mirza
2013 Aug 19 5:52 AM
Hi Shahir,
Thanks for your reply but i dont want duplicate entries.I just want to ignore entries which are previously present in z-table....And in MODIFY statement the records get updated if they have same key fields.
Regards,
Abdul
2013 Aug 19 5:56 AM
2013 Aug 19 5:57 AM
Hi Abdul,
The solution you find out for your problem is tedious one. definitely your z-table have primary key(may be single field or addition of more than one field ) by using PK each record are uniquely identified ,updated, deleted and more.. if you thing you don't maintain PK do please maintain so that database inconsistency and redundancy should be avoided .
1) i think first maintain pk if not
2)do changes in Z-table
3)insert record to z table from internal table using where condition .
if any issues fill free to ask.....
With Hope This will help you.
Thanks And Regards
Swadhin.
Moderator message: Please use proper english ( not PK for primary key ). Thanks for posting
Message was edited by: Kesavadas Thekkillath
2013 Aug 19 7:08 AM
Hi,
It seems to me that there is misinterpretation of the addition of
"ACCEPTING DUPLICATE KEYS":
From SAP help:
So I believe that duplicate records will not be inserted to the table. (Same primary or UNIQUE secondary index)
Regards.
2013 Aug 19 11:18 AM
Hi Abdul,
You can use MODIFY statement instead of INSERT.
syntax : MODIFY dbtab FROM TABLE itab.
This statement will insert those line in internal table into the database table which are not present in the database table and will modify those lines in the database table which are present in the internal table.
You can refer the link for reference:
http://help.sap.com/saphelp_45b/helpdata/en/34/8e73d66df74873e10000009b38f9b8/content.htm
Regards.
2013 Aug 19 11:24 AM
S/m Abdul,
The approach you are following is absolutely correct but one change.
for all the records you have to insert in table it_insert.
Put a select on Z table with a for all entries in it_insert.
Now loop on the table after select and delete these entries from it_insert.
This way you can also list the records which were duplicate and ignored.
Cheers.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |