ABAP Delete duplicate Usage Guide

Source: Internet
Author: User

Reference from http://hi.baidu.com/wangyantsing/blog/item/19b2a8189fbc1b0134fa4157.html

 

Delete table <itab> from <wa>.
Or
Delete table <itab> with table key <K1 >=< F 1>... <k N >=< F n>.
Delete a row of data in the internal table according to the condition.

Delete <itab> where <cond>.
Delete multiple rows of data in the internal table based on conditions

Delete adjacent duplicate entries from <itab>
[Comparing <F1> <F 2>...
| All fields].
Delete duplicate entries of adjacent rows and keep the first record
1. If the non-nuique key is not defined and no conditions are specified during deletion, all fields are compared.
Delete adjacent duplicates from itab comparing all fields
The non-unique field is defined as follows:
Data itab like standard table of Line
With NON-UNIQUE key col2.
2. If a non-unique key exists, the key is compared if no comparison condition is deleted, and adjacent duplicate items are deleted.
3. You can use the specified conditions to compare and process comparing <F1> <F 2>... at this time, all the specified fields must be the same as the adjacent fields, otherwise they will not be deleted.
Of course, you can also use dynamic methods to specify the content for comparison. The following example 2 is a simple test for your reference only.

Other supplementary instructions:
If the fields to be compared are sorted in advance, you can delete all rows with repeated fields.
If at least one item is successfully deleted, Sy-subrc returns 0; otherwise, 4.

The following are two examples:
Example 1:
Data: Begin of line,
Col1 type I,
Col2 type I,
End of line.

Data itab like hashed table of line with unique key col1.

Do 4 times.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
Insert line into Table itab.
Enddo.

LINE-COL1 = 1.

Delete table itab: from line,
With table key col1 = 3.

Loop at itab into line.
Write:/LINE-COL1, LINE-COL2.
Endloop.

Example 2:
Data off type I.

Data: Begin of line,
Col1 type I,
Col2 type C,
Col3 type C,
End of line.

Data itab like standard table of Line
With NON-UNIQUE key col2.
LINE-COL1 = 1. LINE-COL2 = 'A'. line-col3 = '9'. append line to itab.
LINE-COL1 = 1. LINE-COL2 = 'A'. line-col3 = '9'. append line to itab.
LINE-COL1 = 1. LINE-COL2 = 'B'. line-col3 = '9'. append line to itab.
LINE-COL1 = 2. LINE-COL2 = 'B'. line-col3 = '9'. append line to itab.
LINE-COL1 = 3. LINE-COL2 = 'B'. line-col3 = '8'. append line to itab.
LINE-COL1 = 4. LINE-COL2 = 'B'. line-col3 = '9'. append line to itab.
LINE-COL1 = 5. LINE-COL2 = 'A'. line-col3 = '9'. append line to itab.

Off = 0.
Perform list.

Delete adjacent duplicates from itab comparing all fields.
Off = 30.
Perform list.

Delete adjacent duplicates from itab comparing col1 col3.
Off = 60.
Perform list.
Delete adjacent duplicates from itab.

* Data: COL (4) type C.
* Field-Symbols: <FS-lydn> type any.
* Col = 'col1 '.
* Assign Col to <FS-lydn>.
* Delete adjacent duplicates from itab comparing (<FS-lydn>) col3.
* Off = 60.
* Perform list.
* Delete adjacent duplicates from itab.

Off = 90.
Perform list.
Form list.
Skip to line 3.
Loop at itab into line.
Write: AT/off LINE-COL1, LINE-COL2, line-col3.
Endloop.
Endform.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.