‎2007 Dec 13 8:00 PM
Hi Gurus,
Please see the code below . I want avoid the loop at itab1 just for processing a single field.
select * from <dbtable> into corresponding fields of table itab1
where city eq 'value1'
and pstatus eq 1.
<b> loop at itab1.
shift itab1-field1 left deleting leading '0'.
modify itab1 index sy-tabix.
endloop.</b>
loop at itab2.
read table itab2 with key field1 = itab2-field1.
.........
..........
..........
endloop.
Please suggest an optimised code to do the above in a single shot.
Thanks
Dany
‎2007 Dec 13 11:04 PM
Hi Dan,
1. use loop ... assigning <field-symbol>. This is up to 5 times faster
2. define the table as SORTED or better HASHED and read with TABLE KEY.
3. Avoid SELECT *. Select the fields you really need.
4. Don't worry about INTO CORRESPONDING FIELDS of. Although people say so it does not cost time that can be measured.
Regards,
Clemens
‎2007 Dec 13 8:03 PM
Hi Dan
remove into corresponding fields of and specify in the same order...
when u read the table first sort it with the key u read it and say Binary search
with binary search ur code will be twice faster and before...
Award points if usefull
‎2007 Dec 13 8:06 PM
I understand that you need to modify the itab1 because you have to read the table in other loop.
You can do something like this to avoid the loop on ITAB1.
*loop at itab1.
*shift itab1-field1 left deleting leading '0'.
*modify itab1 index sy-tabix.
*endloop.
loop at itab2.
unpack itab2-field1 to l_field1. " << set the L_FIELD1 with ZEROs padded
read table itab1 with key field1 = l_field1.
.........
..........
..........
endloop.Regards,
Naimesh Patel
‎2007 Dec 13 8:13 PM
Hi Naimesh,
i need to use itab2 as it is inevitable.. Any other suggestion.
thanks
‎2007 Dec 13 8:14 PM
Hi Naimesh,
i need toloop at itab2. it is inevitable. it has more entries than itab1
loop at itab2.
read table itab1 with key field1 = itab2-field1.
.........
..........
..........
endloop.
Any other suggestion.
thanks
‎2007 Dec 13 8:47 PM
Hi Dan,
I believe there won't be able to get rid of that first loop because it's a preliminary process that you need so you can match it through the read table in the second loop. You won't be able to modify that single field, unless you got another way(field) to link the itab1 and itab2 that isn't field1.
Hope it helps.
Regards,
Gilberto Li
‎2007 Dec 13 9:00 PM
Maybe something like:
SELECT * FROM <dbtable> INTO CORRESPONDING FIELDS OF TABLE itab1
WHERE city EQ 'value1'
AND pstatus EQ 1.
*loop at itab1.
*shift itab1-field1 left deleting leading '0'.
*modify itab1 index sy-tabix.
*endloop.
LOOP AT itab2.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = itab2-field1
IMPORTING
output = itab2-field1.
READ TABLE itab1 WITH KEY field1 = itab2-field1.
.........
..........
..........
ENDLOOP.Rob
‎2007 Dec 14 1:49 PM
Gentlemen - Thanks to all.
My main requirement is to filter out MISMATCHED records between itab 1 & itab 2. itab2 has MORE records than itab 1..So obviuosly i need to use l:
loop at itab2.
read table itab2 with key field1 = itab2-field1.
.........
..........
..........
endloop.
Any more suggestions?
‎2007 Dec 14 2:41 PM
In your first and last posts you are only looking at itab2.
Rob
‎2007 Dec 14 3:31 PM
Oh! sorry ROB that's a typo error
loop at itab2.
read table itab1 with key field1 = itab2-field1.
endloop.
‎2007 Dec 14 3:41 PM
So itab2 has more records than itab1 and some records in itab2 do not exist in itab1. Is that correct?
Rob
‎2007 Dec 14 3:48 PM
I'm thinking of something like
loop at itab2.
read table itab1 TRANSPORTING NO FIELDS
with key field1 = itab2-field1.
if sy-subrc eq 0.
delete itab2
endif.
endloop.
‎2007 Dec 14 7:17 PM
‎2007 Dec 14 7:23 PM
‎2007 Dec 14 7:58 PM
‎2007 Dec 14 8:03 PM
And you want the records that are in itab1, but not itab2 and the records that are in itab2 but not itab1?
Rob
‎2007 Dec 15 10:51 PM
Hi Rob,
I want all the uncommon entries between both of them.
thanks
‎2007 Dec 15 11:39 PM
Hi Dan,
Do like this
Loop at itab1 into wa1.
Read Table itab2 into wa2 with key <key field> = wa1-key field.
If sy-subrc <> 0.
append wa2 to itab3. " ITAB3 will have uncommon entries.
clear wa2.
endif.
endloop.Regards,
Satish
‎2007 Dec 16 4:01 AM
OK - you can use the parallel cursor technique to go through each table once only and keep only the records you want.
Rob
‎2007 Dec 13 11:04 PM
Hi Dan,
1. use loop ... assigning <field-symbol>. This is up to 5 times faster
2. define the table as SORTED or better HASHED and read with TABLE KEY.
3. Avoid SELECT *. Select the fields you really need.
4. Don't worry about INTO CORRESPONDING FIELDS of. Although people say so it does not cost time that can be measured.
Regards,
Clemens
‎2007 Dec 14 4:33 PM
Hi Dan,
try the other way round and skip the second loop like this:
ranges: rdel1 for itab2-field1.
select * from <dbtable> into corresponding fields of table itab1
where city eq 'value1'
and pstatus eq 1.
rdel1-sign = 'E'. "depends on which entries you want to delete
* 'E' for unmatched - 'I' for matched
rdel1-option = 'EQ'.
loop at itab1.
write itab1-field1 to rdel1-low using edit-mask '__________'.
append rdel1.
endloop.
delete itab2 where field1 in rdel1.Regards
JW