- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Suppressing duplicate entries in classical and ALV report in SAP ABAP
To delete adjacent duplicate entries in an internal table, you can use the below command −
DELETE ADJACENT DUPLICATE ENTRIES FROM <itab> [COMPARING <f1> <f 2> ... |ALL FIELDS].
Also, consider the below points −
- 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.
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.
The output is −
2 4 4 16
The program fills a hashed table with a list of square numbers. The DELETE statement deletes the lines from the table where the key field COL1 has the contents 1 or 3.
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. DELETE ITAB WHERE ( COL2 > 1 ) AND ( COL1 < 4 ). LOOP AT ITAB INTO LINE. WRITE: / LINE-COL1, LINE-COL2. ENDLOOP.
The output is −
1 1 4 16
The program fills a hashed table with a list of square numbers. The DELETE statement deletes the lines of the table where the content of field COL2 is greater than 1 and the content of field COL1 is less than 4.
- Difference between class alv and function alv in SAP ABAP?
- Multiple ALV grids on a single screen in SAP ABAP
- How to switch between different views in ALV Grid in SAP ABAP?
- Displaying T-code description and T-code field in Output ALV of report SM20 in SAP system
- Avoid duplicate entries in MongoDB?
- Writing at the end of report without clearing current screen in SAP ABAP
- How to create an ALV in docking container in SAP?
- Count distinct entries in SAP BusinessObjects
- Delete duplicate alphanumeric entries from column data in SQL
- Program to remove duplicate entries in a list in Python
- Getting a carriage return of report field in SAP Crystal Report
- Double click on ALV Grid to call Transaction and pass information in SAP
- Program to remove duplicate entries in a linked list in Python
- How to remove duplicate entries by two keys in MongoDB?
- Show creator name in SAP WEBI report