‎2006 Jan 17 8:23 PM
Hi, experts!
My program need to print the data when the account
number, company_code and profit_center are equals between two tables <b>(T_ITAB1, T_ITAB2)</b>.
I have two loops like this:
LOOP AT t_itab1 INTO WA_ITAB.
LOOP at T_ITAB2 WHERE account = wa_itab-RACCT AND
PROFIT_CENTER = wa_itab-prctr and company_code =
wa_itab-rbukrs.
The T_ITAB2 have data that is key. No have repeatedly data and the relationship is one to one. But when I execute the program the information of the internal table T_ITAB2 is repeatedly many times.
How can I resolve this problem.
Thanks for the help!!
‎2006 Jan 17 8:28 PM
Instead of looping around itab2, read it.
like this
LOOP AT t_itab1 INTO WA_ITAB.
read table T_ITAB2 into wa_itab2 with key account = wa_itab-RACCT AND PROFIT_CENTER = wa_itab-prctr and company_code = wa_itab-rbukrs.
if sy-subrc = 0.
*Do something
endif.
endloop.
REgards,
Ravi
‎2006 Jan 17 8:28 PM
Hi Carlos,
You can do a read statement on T_ITAB2 to get single value & use
IF SY-SUBRC = 0.
ENDIF.
Can you tell me whether the where condition fields are the key fields.
‎2006 Jan 17 8:28 PM
Instead of looping around itab2, read it.
like this
LOOP AT t_itab1 INTO WA_ITAB.
read table T_ITAB2 into wa_itab2 with key account = wa_itab-RACCT AND PROFIT_CENTER = wa_itab-prctr and company_code = wa_itab-rbukrs.
if sy-subrc = 0.
*Do something
endif.
endloop.
REgards,
Ravi
‎2006 Jan 17 8:30 PM
Try the following:
SORT T_ITAB2 by account PROFIT_CENTER company_code.
LOOP AT t_itab1 INTO WA_ITAB.
read table T_ITAB2 with key
account = wa_itab-RACCT
PROFIT_CENTER = wa_itab-prctr
company_code = wa_itab-rbukrs
binary search.
ENDLOOP.
Rob
‎2006 Jan 17 8:32 PM
Do it the other way around..
Loop at Itab2.
read table itab1 comparing keys from itab2.
if sy-subrc eq 0.
write : Itab2 field values...
endif.
EndLoop.
‎2006 Jan 17 8:33 PM
Hi carlos,
Sort both the internal tables on key fields(same in both tables)
Now ,
<b>Loop on itab1.
clear itab2.
read table itab2 with key1 = itab1-key1....
if sy-subrc = 0.
<process>
endif.
Endloop.</b>
Regards,
Raj
‎2006 Jan 17 8:34 PM
Hi,
it seems as if you had duplicate entries in your internal tables.
Have a look at abap sentence:
<b>DELETE ADJACENT DUPLICATE ENTRIES FROM <itab>
[COMPARING <f1> <f 2> ...
|ALL FIELDS].</b>
... before processing both loops.
Best regards.
‎2006 Jan 17 8:35 PM
Phani Kiran Nudurupati, Yes, the where condition are the key fields.
‎2006 Jan 17 8:43 PM
Carlos,are these the Key fields for the first table also T_ITAB1.
If yes then you can go with the read statement on the T_ITAB2 with the same where condition.
‎2006 Jan 18 5:04 AM
Even though you have unique records in T_ITAB2 for the combination of account number, company code, and profit center, the outer loop of T_ITAB1 may be having duplicate records for this combination. It is like looping at items table and within that looking at the header table with the key. Even though there is only one header record for each key, there may be several items for that header table, so obviously you will see repetetion.
May be you need to reverse the order of the loops.
Srinivas