‎2007 Aug 13 6:15 AM
hi,
i have one internal table in that 4 records.
f1 f2 f3 f4
1 20 25 35
2 49 25 45
3 50 35 50
4 69 35 70
in this f3 values r repeating
i want only one record means i want oout put like
1 20 25 35
3 50 35 50
pls send me code
‎2007 Aug 13 6:25 AM
Hi,
Check this code.
PARAMETERS p_carrid TYPE scarr-carrid.
DATA scarr_tab TYPE SORTED TABLE OF scarr
WITH UNIQUE KEY carrid.
SELECT *
FROM scarr
INTO TABLE scarr_tab.
READ TABLE scarr_tab WITH TABLE KEY carrid = p_carrid
TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
DELETE scarr_tab INDEX sy-tabix.
ENDIF.
‎2007 Aug 13 6:21 AM
HI,
use this statement
<b>DELETE ADJACENT DUPLICATES FROM itab COMPARING f3.</b>
rgds,
bharat.
‎2007 Aug 13 6:22 AM
sort itab by f3.
delete adjacent duplicates from itab comparing f3.
‎2007 Aug 13 6:23 AM
hi
U can use DELETE statement for deleting the repetitive records
DELETE ADJACENT DUPLUCATES FROM ITAB COMPARING < ALL FILEDS >
here in place of ALL FIELDS u can give ur fields for comparing and deleting .
If it helps dont forget REWARD
rgds
harris
‎2007 Aug 13 6:24 AM
Hi
sort the Internal table based on F3
and delete adjacent duplicates from internal table comparing f3
then it will delete all the reapting f3 values
reward if usefull
‎2007 Aug 13 6:25 AM
Hi,
Check this code.
PARAMETERS p_carrid TYPE scarr-carrid.
DATA scarr_tab TYPE SORTED TABLE OF scarr
WITH UNIQUE KEY carrid.
SELECT *
FROM scarr
INTO TABLE scarr_tab.
READ TABLE scarr_tab WITH TABLE KEY carrid = p_carrid
TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
DELETE scarr_tab INDEX sy-tabix.
ENDIF.
‎2007 Aug 13 6:33 AM
Hi,
To avoid duplicate records you can use the statement
DELETE ADJACENT DUPLICATES FROM itab.
Additions:
1. ... COMPARING fieldname1 fieldname2 .......
2. ... COMPARING ALL FIELDS.
Here in your querry you have to delete accoeding to f3 filed. So te following code will help your problem
DELETE ADJACENT DUPLICATES FROM itab COMPARING f3.
Before this statement try to sort the internal table using f3 field.
Regards,
LIJO JOHN
‎2007 Aug 13 6:45 AM
Hi,
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.
as per your requirement, while deleting duplicate records based on thrid field.
DELETE ADJACENT DUPLICATES FROM ITAB COMPARING COL3.in the above statement ITAB( internal table) and COL3( third field).
for more information follow this link with sample code.
http://help.sap.com/saphelp_nw04/helpdata/en/06/aafd54fc4011d195280000e8353423/content.htm
regards,
Ashok Reddy
‎2007 Aug 13 7:06 AM
hi, try this code;
TYPES : BEGIN OF ITAB,
f1 type i,
f2 type i,
f3 type i,
END OF ITAB.
DATA : ITAB1 type standard TABLE OF ITAB WITH HEADER LINE .
ITab1-f1 = 20.
itab1-f2 = 25.
itab1-f3 = 35.
append itab1.
ITab1-f1 = 49.
itab1-f2 = 25.
itab1-f3 = 45.
append itab1.
ITab1-f1 = 50.
itab1-f2 = 35.
itab1-f3 = 50.
append itab1.
ITab1-f1 = 69.
itab1-f2 = 35.
itab1-f3 = 70.
append itab1.
delete adjacent duplicates from itab1 comparing f2.
loop at itab1 .
write:/ itab1-f1, itab1-f2,itab1-f3.
endloop.
REWARD POINTS IF IT HELPS .
RGDS.