‎2007 Jul 20 2:33 PM
Hi,
I have the following requirement.
I have an internal table IT_TEST1 which has values
Column1
A
B
C
D
..
consider a second internal table IT_TEST2. It'll have values like as follows:..I need to know which are the entries in column1 that have more than one entry in column 2 without looping through this internal table..Kindly suggest..
Column1 column2
A VAL1
B VAL1
B VAL2
C VAL1
C VAL2
D VAL1
D VAL2
D VAL3
This has caused very big performance issue for it is
‎2007 Jul 20 2:37 PM
Hi,
I would suggest do the read with binary serach over second table and then in addition check if thenext entry has the same key.
e.g.
READ ITAB2 WITH KEY k = A BINARY SEARCH
lv _idx = sy-tabix + 1.
READ ITAB2 INDEX lv _idx.
...check if the second record has the same key -- if so you have at least duplicates
BR, Artem
remember points
‎2007 Jul 20 6:32 PM
Hi!
You can try this.
1. Make a temporary internal table and copy IT_TEST2 into this IT_TEMP.
2. Now LOOP AT IT_TEST1
3. READ TABLE IT_TEMP WITH KEY Column1 = IT_TEST1-column1 binary search.
4. DELETE IT_TEMP. This will delete the current entry from IT_TEMP
5. Now again read IT_TEMP. READ TABLE IT_TEMP WITH KEY Column1 = IT_TEST1-column1 binary search.
6. If SY-SUBRC = 0 then you have more than one entry in IT_TEST2.
7. ENDLOOP.
Reward points if useful.
‎2007 Jul 20 6:36 PM
I would suggest ..
First sort the table by column1... so all records are in sorted form..
sort ITAB by column1..
read table ITAB with key column1 = 'A'.
l_index = sy-tabix + 1.
read table ITAB index l_index.
if sy-subrc eq 0.
write:/ 'More than 1 record'.
else.
write:/ 'Single record only'.
endif.Reward if useful
Regards
Prax
‎2007 Jul 21 10:47 AM
Hi,
I have faced a similar problem and the following strategy has saved a lot of processing time
the following code may serve your pupose
if you are using IT_TEST2 for further processing please use IT_TEST3
otherwise use IT_TEST2 instead of IT_TEST3 in the code below......'
*************************CODE SAMPLE************************************
data : IT_TEST3 like IT_TEST2. "declare internal table same as IT_TEST2
IT_TEST3[] = IT_TEST2[].
"Pass contents if IT_TEST2 is used for further processing
Sort IT_TEST1 by column1 . "Sort
Sort IT_TEST3 by column1 . "Sort
loop at IT_TEST1.
read table IT_TEST3
with key column1 = IT_TEST1-column1.
if sy-subrc = 0.
describle table IT_TEST3 lines n.
if lines > 1.
"Multiple entries
else.
"Single entry
endif.
endif.
"Perform all operations on IT_TEST3
DELETE IT_TEST3 WHERE column1 = IT_TEST1-column1.
"Delete the entry in IT_TEST3 already processed with the key of IT_TEST1
"Next time you do the read entries for the previous and all predecessor loops
will not be there'
"As you go down the loop performance increases
endloop.
Regards
Byju
‎2007 Jul 26 7:12 AM
I think there is not one decent solution to your problem as all use nested loop which will kill your performance.
And I am not sure whether I really understand your problem. To count the number of entries make it necessary to loop over the whole table, therefore you must
loop of table2. But you should not loop inside another loop on table1.
I propose precprocessing:
define a hashed table itab3 with key column2 and count
loop at itab2 into wa2.
read itab3 with table key column2 = wa2-column2.
if ( sysubrc eq 0 )
wa3-count = wa3-count + 1.
modify itab3
else.
insert itab3
endif.
endloop.
=> itab3 will tell you how often the values in itab2 appear. It need only one loop.
Then it is very simple to solve your problem
loop itab1..
read itab3
if ( count > 1 ).
endif.
endloop
Coding is not exactly correct. Please correct, if I did not understand your problem.
Siegfried
Message was edited by:
Siegfried Boes
‎2007 Jul 27 10:15 AM
Use the parallel cursor method of looping through the two tables: Read <a href="/people/rob.burbank/blog/2006/02/07/performance-of-nested-loops of Nested Loops</a>.
MattG.