2010 Jan 21 6:24 AM
Hi,
I have an internal table which has three fields(F1,F2,F3).
Now suppose I have 5 records and I have to compare whether the fields(F1 and F3) of record 1st and 3rd are same or not(F2 is common for both records).Can you suggest any syntax?
2010 Jan 21 6:35 AM
Hi,
Please test the following Sample Code hope will solve out your problem
TYPES: BEGIN OF ty_test,
f1(3),
f2(3),
f3(3),
END OF ty_test.
DATA: it_test TYPE STANDARD TABLE OF ty_test WITH HEADER LINE,
old_f1(3),
old_f3(3).
it_test-f1 = 'AAA'. it_test-f2 = 'AAA'. it_test-f3 = 'DDD'. APPEND it_test.
it_test-f1 = 'BBB'. it_test-f2 = 'AAA'. it_test-f3 = 'CCC'. APPEND it_test.
it_test-f1 = 'AAA'. it_test-f2 = 'AAA'. it_test-f3 = 'AAA'. APPEND it_test.
it_test-f1 = 'BBB'. it_test-f2 = 'AAA'. it_test-f3 = 'CCC'. APPEND it_test.
SORT: it_test by f1 f3.
LOOP AT it_test.
IF old_f1 = it_test-f1 and old_f3 = it_test-f3.
WRITE: 'There is Duplicate Record on Index ', sy-tabix.
ENDIF.
old_f1 = it_test-f1.
old_f3 = it_test-f3.
ENDLOOP.Please Reply if any problem
Best Regards,
Faisal
Hi
sort the inetrnal table
use read stmt
READ TABLE itab INTO wa COMPARING f1 f2 ...
Thanks
SUbha
2010 Jan 21 6:34 AM
Hi
I don't think there is a dirrent command.We may need to put logic around the internal table to compare the records.
Regards
Gaurav Arora
2010 Jan 21 6:35 AM
hi,
You can try this:
1. sort itab by fields F1 and F3.
2. Delete adjacent duplicates comparing F1 and F3.
Regards,
Komal
2010 Jan 21 6:35 AM
Hi,
Please test the following Sample Code hope will solve out your problem
TYPES: BEGIN OF ty_test,
f1(3),
f2(3),
f3(3),
END OF ty_test.
DATA: it_test TYPE STANDARD TABLE OF ty_test WITH HEADER LINE,
old_f1(3),
old_f3(3).
it_test-f1 = 'AAA'. it_test-f2 = 'AAA'. it_test-f3 = 'DDD'. APPEND it_test.
it_test-f1 = 'BBB'. it_test-f2 = 'AAA'. it_test-f3 = 'CCC'. APPEND it_test.
it_test-f1 = 'AAA'. it_test-f2 = 'AAA'. it_test-f3 = 'AAA'. APPEND it_test.
it_test-f1 = 'BBB'. it_test-f2 = 'AAA'. it_test-f3 = 'CCC'. APPEND it_test.
SORT: it_test by f1 f3.
LOOP AT it_test.
IF old_f1 = it_test-f1 and old_f3 = it_test-f3.
WRITE: 'There is Duplicate Record on Index ', sy-tabix.
ENDIF.
old_f1 = it_test-f1.
old_f3 = it_test-f3.
ENDLOOP.Please Reply if any problem
Best Regards,
Faisal
2010 Jan 21 6:40 AM
hi Ginger ..
You need to sort at the internal table and than compare the record and delete if same
sort it_tab by F1 F2.
delete adjacent duplicates from it_tab comparing F1 F2.thanks
2010 Jan 21 6:41 AM
HI,
Exactly, I did not get what you trying to say, but what I have understand is that, in your internal table you have to check if the record 1 , 3, or on any number is same or not , ie. value of F1 & F3 field, is same or not, and value of F2 is common in both the records,
So, you can sort the table on F1, F3 & F2 and if you want to remove the duplicate entries you can use delete adjuscent duplicates,
Or you can populate same data in one internal table say ITAB1 and then , you can loop at ITAB AND READ TABLE iITAB1 WITH KEY F1-ITAB-F1 AND F3-ITAB-F3 AND IF SY-SUBRC EQ 0, YOU CAN FIND THE records where you are getting duplicates, then according to your next program logic you can proceed.
Hope this may helpful to you
Rani
2010 Jan 21 6:42 AM
Hi
sort the inetrnal table
use read stmt
READ TABLE itab INTO wa COMPARING f1 f2 ...
Thanks
SUbha
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |