Duplicates From Internal Tabl
Hello,
I have an internal table with 6 fields and if the first five fields are same then its called a dublicate and I shud collect these duplicates in an other table moving the original to the other internal table. So from the basic Internal table I need to form 2 tables one with originals and the other with duplicates..How do i do this?
Thanks
Viky
Hi
Say itab is your first table and
itab2 is table of the same type as itab
wa_itab and wa_itab are work areas of the type of your internal table.
Loop at itab into wa_itab.
clear cnt.
Loop at itab into wa_itab1 where field1 = wa_itab-field1
field2 = wa_itab-field2
field3 = wa_itab-field3
field4 = wa_itab-field4
field5 = wa_itab-field5
cnt = cnt + 1.
If cnt gt 1.
append wa_itab1 to itab2.
DELETE itab from wa_itab1.
endif.
Endloop.
Similar Messages
-
How to choose in Delete Duplicates from internal table?
Now I need to delete Duplicates from internal table,
So at first I sort
than I delete duplicate
Sort itab1 BY Company_Code Asset_No Capital_Date.
DELETE ADJACENT DUPLICATES FROM itab1 COMPARING Company_Code Asset_No Capital_Date
Company_Code
Asset_No
Capital_Date
Remark
BC35
1515593
20021225
Helen
BC35
1515593
20021225
Common Asset
BC35
1515594
20030109
Judy
BC35
1515594
20030109
Common Asset
But here comes my problem~If I want to delete the Common Asset in Remark Column,how I let it choose the right one to do it?Hi Jack
Try the below coding..
Report zsamp.
types: begin of t_tab,
comp_code(4) type c,
***_no(7) type n,
cap_date type d,
remark type string,
end of t_tab.
data: i_tab type TABLE OF t_tab,
w_tab type t_tab.
w_tab-comp_code = 'BC35'.
w_tab-***_no = '1515593'.
w_tab-cap_date = '20021225'.
w_tab-remark = 'Helen'.
append w_tab to i_tab.
w_tab-comp_code = 'BC35'.
w_tab-***_no = '1515593'.
w_tab-cap_date = '20021225'.
w_tab-remark = 'Common Asset'.
append w_tab to i_tab.
w_tab-comp_code = 'BC35'.
w_tab-***_no = '1515594'.
w_tab-cap_date = '20030109'.
w_tab-remark = 'Judy'.
append w_tab to i_tab.
w_tab-comp_code = 'BC35'.
w_tab-***_no = '1515594'.
w_tab-cap_date = '20030109'.
w_tab-remark = 'Common Asset'.
append w_tab to i_tab.
sort i_tab by remark.
delete ADJACENT DUPLICATES FROM i_tab COMPARING remark. -
Delete Duplicates from internal table with object references
Hi
How can I delete duplicates from an internal table in ABAP OO based on the value of one of the attributes?
I have created a method, with the following code:
LOOP AT me->business_document_lines INTO l_add_line.
CREATE OBJECT ot_line_owner
EXPORTING
i_user = l_add_line->add_line_data-line_owner
i_busdoc = me->business_document_id.
APPEND ot_line_owner TO e_line_owners.
ENDLOOP.
e_line_owners are defined as a table containing only object references.
One of the attribute of the object in the table is called USER. And I would like to do a "delete ADJACENT DUPLICATES FROM e_line_owners", based on that attribute.
How can do this?
Regards,
Morten NielsenHello Morten
Assuming that the instance attribute is <b>public </b>you could try to use the following coding:
SORT e_line_owners BY table_line->user.
DELETE ADJACENT DUPLICATES FROM e_line_owners
COMPARING table_line->user.
However, I am not really sure (cannot test myself) whether <b>TABLE_LINE</b> can be used together with SORT and DELETE.
Alternative solution:
DATA:
ld_idx TYPE sy-tabix.
LOOP AT e_line_owners INTO ls_line.
ld_idx = syst-tabix + 1.
LOOP AT e_line_owners TRANSPORTING NO FIELDS FROM ld_idx
WHERE ( table_line->user = ls_line->user ).
DELETE e_line_owners INDEX syst-tabix.
ENDLOOP.
ENDLOOP.
Regards
Uwe -
Delete duplicate from internal table
HI Abapers,
I have a query on how to remove the duplicates from an internal table
My internal table data is as follows :
Cno Catg1 Catg2
01 0 1000
01 2000 0
I want to get only one record as
01 2000 1000
How to get the result.
I tried sorted by cno and used delete duplicates but it was not helpful.
Is there any other alternative to get this done
Please help me.
Regards,
Priyacheck it out with delete adjacent duplicate records
Deleting Adjacent Duplicate Entries
To delete adjacent duplicate entries use the following statement:
DELETE ADJACENT DUPLICATE ENTRIES FROM <itab>
[COMPARING <f1> <f 2> ...
|ALL FIELDS].
The system deletes all adjacent duplicate entries from the internal table <itab>. Entries are duplicate if they fulfill one of the following compare criteria:
Without the COMPARING addition, the contents of the key fields of the table must be identical in both lines.
If you use the addition COMPARING <f1> <f 2> ... the contents of the specified fields <f 1 > <f 2 > ... must be identical in both lines. You can also specify a field <f i > dynamically as the contents of a field <n i > in the form (<n i >). If <n i > is empty when the statement is executed, it is ignored. You can restrict the search to partial fields by specifying offset and length.
If you use the addition COMPARING ALL FIELDS the contents of all fields of both lines must be identical.
You can use this statement to delete all duplicate entries from an internal table if the table is sorted by the specified compare criterion.
If at least one line is deleted, the system sets SY-SUBRC to 0, otherwise to 4. -
To delete duplicate records from internal table
hi friends,
i have to delete records from internal table based on following criterion.
total fields are 7.
out of which if 4 fields are same and 5th field is different,then both records must be deleted.
in case all five fields are same,the program should do nothing.
for example.
if there are 3 records as follows
a1 b1 c1 d1 e1 f g
a1 b1 c1 d1 e2 w r
a1 b1 c1 d1 e1 j l
then first two records should be deleted as four fields are same but fifth(e) field differs.
but third record should remain as it is evenif first five fields are same for first and third record.
values of last two fields need not to be consider for deleting the records.LOOP AT ITAB.
V_FILED5 = ITAB-F5. "to compare later
V_TABIX = SY-TABIX. "used to delete if condition not matches
READ TABLE ITAB WITH KEY F1 = ITAB-F1
F2 = ITAB-F2
F3 = ITAB-F3
F4 = ITAB-F4.
IF SY-SUBRC = 0.
IF ITAB-F5 <> V_FIELD5.
*--both the records to be deleted,as Field5 is different.
DELETE ITAB INDEX SY-TABIX. "deletes that record
DELETE ITAB INDEX V_TABIX. "deletes the current record
ENDIF.
ENDIF.
ENDLOOP.
Message was edited by: Srikanth Kidambi
added comments
Message was edited by: Srikanth Kidambi -
Can not insert or update [TABLE] from internal table in method
I've faced a problem with OO abap. I've tried to insert into [ TABLE ] from internal table, but i've got error msg after i compiled.
"An explicit work area is necessary in the OO context. Use "INSERT wa INTO [TABLE] itab""
After i changed to loop in work area and INSERT INTO [TABLE] VALUES gw_data., everything is fine, can compile and run.
This is error code.
METHOD set_data_to_table.
REFRESH gi_data.
CLEAR gi_data.
IF gi_file[] IS NOT INITIAL.
* Set data for modify table
LOOP AT gi_file INTO gw_file.
MOVE-CORRESPONDING gw_file TO gw_data.
me->conversion_input( EXPORTING im_vendor = gw_data-vendor
CHANGING ch_vendor = gw_data-vendor ).
APPEND gw_data TO gi_data.
ENDLOOP.
INSERT [TABLE] FROM TABLE gi_data.
* LOOP AT gi_data INTO gw_data.
* INSERT INTO [TABLE] VALUES gw_data.
* IF sy-subrc = 0.
* COMMIT WORK.
* ELSE.
* ROLLBACK WORK.
* ENDIF.
* ENDLOOP.
ELSE.
MESSAGE 'No data found' TYPE 'I'.
ENDIF.
ENDMETHOD. "set_data_to_tableHi Matthew,
I think there is no difference in database insert between OO and non-OO.
The correct syntax according to ECC600 online documentation is
[Inserting Several Lines|http://help.sap.com/saphelp_erp2005vp/helpdata/en/fc/eb3a6d358411d1829f0000e829fbfe/content.htm]
To insert several lines into a database table, use the following:
INSERT target FROM TABLE itab \[ACCEPTING DUPLICATE KEYS].
This writes all lines of the internal table itabto the database table in one single operation. If one or more lines cannot be inserted because the database already contains a line with the same primary key, a runtime error occurs. You can prevent the runtime error occurring by using the addition ACCEPTING DUPLICATE KEYS.
Whenever you want to insert more than one line into a database table, it is more efficient to work with an internal table than to insert the lines one by one.
I think the syntax
INSERT my_dbtable FROM TABLE gi_data.
should work, your suggestion may lead to syntax error.
Regards,
Clemens -
Deleting entry from internal table
Hi Experts,
i have the following internal table:
data : it_result1 TYPE crmt_object_guid_tab
and work area
data : wa_result1 type crmt_object_guid.
i have to delete a guid from internal table based on some condition.
loop at it_resul1 into wa_result1
if lv_priority eq priority.
delete this entry from internal table.
endif.
endloop..
i tried using delete table it_result with table key CRMT_OBJECT_GUID = wa_result. but this is giving syntax error.
what should be done to delete the entry?
Thanks and regards
ShilpiHi
Check Syntax for DELETE operator on pressing F1
1. DELETE itab.
2. DELETE TABLE itab WITH TABLE KEY k1 = v1 ... kn = vn.
3. DELETE TABLE itab [FROM wa].
4. DELETE itab INDEX idx.
5. DELETE itab FROM idx1 TO idx2.
6. DELETE itab WHERE logexp.
7. DELETE ADJACENT DUPLICATES FROM itab.
delete table it_result with table key CRMT_OBJECT_GUID = wa_result
this is wrong
delete it_result where CRMT_OBJECT_GUID = wa_result
Edited by: Lavanya K on Apr 22, 2009 10:20 AM -
Update databse from internal table statement not using index
Hi Guys,
We are updating a databse table from a file. The file has a couple of fields which have data different from what the database has (non-primary fields :). We upload the file data into an internal table and then update the database table from internal table. At a time, internal table is supposed to have 10,000 records. I did SQL trace and found that the update statement is not making use of the databse index.
Should not the update statement here be using the table index (for primary key)?
Regards,
Munish... as often there are recommendations in this forum which makes me wonder, how people overestimate their knowledge!!!
Updates and Deletes do of course use indexes, as can be seen in the SQL Trace (use explain).
Inserts don't use indexes, because in many databases inserts are just done somewhere, But also with the INSERT, the primary key is the constraint for the uniqueness condition, duplicate keys are not allowed.
Coming to the original question, what is you actually coding for the update?
What is the table, which fields are in the internal table and what are the indexes?
Siegfried -
Fill database table from internal table
I made one table ZDISP_CHDOC_CC and want to fill that table from internal table.and i got runtime error. that duplicate entry
and two entry are like 10 200000 likhp 10
10 200000 likp 10
DESCRIBE TABLE IT_CHDOC .
LOOP AT IT_CHDOC.
INSERT ZDISP_CHDOC_CC FROM IT_CHDOC.
endloop.
IF SY-SUBRC = 0.
COMMIT WORK.
ELSE.
and when i used following then only one entry is insreted.
DESCRIBE TABLE IT_CHDOC .
LOOP AT IT_CHDOC.
INSERT ZDISP_CHDOC_CC FROM IT_CHDOC.
IF SY-SUBRC = 0.
COMMIT WORK.
endloop.
ELSE.Hi,
Replace your current code
DESCRIBE TABLE IT_CHDOC .
LOOP AT IT_CHDOC.
INSERT ZDISP_CHDOC_CC FROM IT_CHDOC.
endloop.
IF SY-SUBRC = 0.
COMMIT WORK.
ELSE.
WITH THE ONE GIVEN BELOW
DESCRIBE TABLE IT_CHDOC .
INSERT ZDISP_CHDOC_CC FROM TABLE IT_CHDOC ACCEPTING DUPLICATE KEYS.
IF SY-SUBRC = 0.
COMMIT WORK.
ELSE.
Regards,
Siddarth -
Hash lookup or Binary search to fetch data from internal table
Hi All,
I want to know Which is faster, Hash lookup or Binary search to fetch data from internal tables?
Thanks,
Mahesh
Moderator Message: Duplicate post
Edited by: kishan P on Oct 14, 2010 4:22 PMtype mod* .the the sign would change to pattern.try and see.i checked.reward if works.
-
Fetch the values from internal table inside an internal table (urgent!!)
data : BEGIN OF PITB2_ZLINFO occurs 0,
BEGDA LIKE SY-DATUM,
ENDDA LIKE SY-DATUM,
PABRJ(4) TYPE N, "Payroll Year
PABRP(2) TYPE N, "Pay. Period
ZL LIKE PC2BF OCCURS 0,
END OF PITB2_ZLINFO.
I have a internal table like this,
How to Fetch the values from internal table inside an internal table.
Kindly Help me on this..
Regards,
Ram.Hi,
Try this....
Loop at PITB2_ZLINF0.
Loop at PITB2_ZLINF0-ZL.
endloop.
Endloop.
Thanks...
Preetham S -
How to send data from internal table to the shared folder in ABAP
Hi experts,
My requirement is to transfer data from a file to shared folder. i just did reading data from a file to a internal table. Now i want to send this internal table data into a shared folder which is "
xxx\y\z....".
I do not have any idea on how to send data from internal table to the shared folder path.
can anybody please help me out how to do this?
Thanks & Regards
Sireesha.Where that folder is located, its on presentation server i.e. desktop or application server.
If its on presentation server, use FM GUI_UPLOAD.
If its on application server, then use DATASET functions. Have a look at below link.
[File Handling in ABAP|http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3ca6358411d1829f0000e829fbfe/frameset.htm]
I hope it helps.
Thanks,
Vibha
Please mark all the useful answers -
Deleting Duplicates from a table
Its a huge table with 52 fields and 30k rows. I need to delete the duplicates based on one of the fields. GROUP BY is taking a lot of time. Is there a quicker way to delete the duplicates using SQL.
Thanks.How many duplicates have you got? Do you have even a vague idea? 1%? 20%? 90%?
One way would be to add a unique constraint on the column in question. This will fail, of course, but you can use the EXCEPTIONS INTO clause to find all the ROWIDs which have duplicate values. You can then choose to delete those rows using a variant on teh query already posted. You may need to run %ORACLE_HOME%\rdbms\admin\utlexcptn.sql to build the EXCEPTIONS table first.
This may seem like some unnecessary work, but the most effective way of deleting duplicates from a table is to have relational integrity constraints in place which prevent you having duplicates in the first place. To paraphrase Tim Gorman, you can't get faster than zero work!
Cheers, APC -
To get recent timestamp records from internal table
hi all,
i have one requirment
i'm storing error messages in one table while creating a sales order basing on timestamp
which is of this format yyyy-mm-dd hh:mm:ss (random Number)
if i want to see the error messages left i'm getting all the error messages displayed
for example i have created a sales order
i got 10 errors displayed
i have rectified 5 errors ... if i again display error messages the 10 errors + the 5 errors is getting displayed
i want to display the 5 error messages only not the previous messages from internal table
basing on timestamp current one has to displayed remaining has to deleted from internal table.I thought we used Sales Order Incompletion process for this.... but, if you're recreating the errors list every time you save with a create or change transaction then, at save, delete all rows in your error table for this document. Then get your errors and update your db table from your current errors table. From this viewpoint, the timestamp is not relevant.
-
Create XML file from internal table and vise a versa
Hi Friends,
I have requirement to create an XML string from internal table data and also read XML string data to internal table.
Can anybody tell are there any Function Modules or methods existing for this?
Thanks.
Krishna Yerram.1. Write XSLT program. T.code XSLT . e.g. XSLT name "ZTRANS".
2. Write ABAP program
Which includes declaration of internal tables
that you need "IT_DATA".
Upload XML data to an internal table "IT_XML "
use below statement to convert XML to internal table.
Call transformation ZTRANS
source XML IT_XML
result IT_DATA.
Maybe you are looking for
-
ITunes (AppleTV) TV Show Episode Sort Order
I have purchased Dr Who Season 6 but it comes in two parts. Part One and Part Two. When these settle into iTunes in the TV series section they combine into one season but the sort (play) order is wrong. When viewing from within iTunes or through Appl
-
Hi, After using sql loader to import informations in the table fa_mass_additions and after the functionnal uses a treatment to imputate this assets, it asks me to do an update on the table fa_additions to change the value of attribute1 but i get an e
-
Chart from CSV datasource not appearing
Hi, I'm using CRXI in VS.NET 2005 on Vista32. I get the feeling that maybe I've misunderstood something fundamental about how Crystal Reports can be used to bind to a report datasource at runtime. I know that I can set the datasource using the OLE Te
-
Need some help with my Air Application
Hello Friends I am developing a desktop application which have few modules from flex and few from HTML-Perl based existing application. I am using <mx:Html> component for showing that HTML-Perl Application. That application is running fine inside <mx
-
Virus/Cleaning/Ver. 4.3.5
Question 1: Is it true that ipad 2s are not subject to virus attacks like PCs are and thus, do not need software like Norton, etc.? If not true, what sofrware is applicable to ensure the ipad 2 remains clean? Question 2: How do you clean an ipad 2