‎2008 Feb 04 11:20 AM
i am trying to fetch data from itab2
with in another itab1 using loop at
but i am getting same value for vtext.....
How will i get other values of vtext ...
i dont want repeation of values of vtext....in every line of itab1 values......
plz give me the solutions
is there any system variable which can increment the value of
itab2-vtext before every exit....?
loop at itab1
loop at itab2
write : / itab2-vtext.
exit.
endlloop.
endloop.
plz help...its urgent !!!
‎2008 Feb 04 11:24 AM
Hi,
You can do as below :
loop at itab1.
read table itab2 with key field1 = itab1-field1. "Here field1 of itab1 and itab2 should be equal
if sy-subrc eq 0.
write : itab2-vtext.
endif.
endloop.
‎2008 Feb 04 11:27 AM
try this friend
loop at itab1.
read table itab2 with key field1 = itab1-field1. "checking equality"
if sy-subrc = 0.
write : itab2-vtext.
else.
message e001.
endif.
endloop.
plz reward if helpful
vivek
‎2008 Feb 04 11:25 AM
Hello,
If you have any common fields in Itab1 and Itab2 you can make it.
loop at itab1.
loop at itab2 where field1 eq Itab1-field1. " Check here
write : / itab2-vtext.
exit.
endloop.
endloop.
Cheers,
Vasanth
‎2008 Feb 04 11:25 AM
try this,
loop at itab1
loop at itab2
if itab2-vtext ne itab1-vtext.
write : / itab2-vtext.
exit.
endif.
endlloop.
endloop.
or
loop at itab1
loop at itab2 where itab2-vtext ne itab1-vtext.
write : / itab2-vtext.
exit.
endif.
endlloop.
endloop.
‎2008 Feb 04 11:33 AM
please there is no common field between itab 1 and itab 2
they are completely different.
the code i have written something like that....Is there can be done between 'exit' and write : / itab2-vtext
so that i could get differeent values of vtext along with fieldx , fieldy....need help thnks
loop at itab1
write : / itab1-fieldx,
itab1-fieldy.
loop at itab2
write : / itab2-vtext.
exit.
endlloop.
endloop.
‎2008 Feb 04 11:27 AM
Hi
U should use some conditions to read the table ITAB2, or if there are no conditions, u can check the index:
loop at itab1.
loop at itab2 where .......
write : / itab2-vtext.
exit.
endlloop.
endloop.or
loop at itab1.
VN_TABIX = VN_TABIX + 1.
READ TABLE ITAB2 INDEX VN_TABIX.
IF SY-SUBRC = 0.
write : / itab2-vtext.
ENDIF.
endloop.So you shoul give us the link beetween the ITAB1 and ITAB2
Max
‎2008 Feb 04 11:42 AM
‎2008 Feb 04 11:50 AM
Hi
In the code you've pasted, it seems there's no link beetween the two internal table, so u can use an index (a counter) to be sure to print a record of ITAB2 only once:
DATA: VN_TABIX TYPE SY-TABIX.
LOOP AT ITAB1.
* Calculate the index
VN_TABIX = VN_TABIX + 1.
READ TABLE ITAB2 INDEX VN_TABIX.
IF SY-SUBRC = 0.
WRITE: ......
ENDIF.
ENDLOOP.U can use the system variable SY-TABIX instead of the variable VN_TABIX:
LOOP AT ITAB1.
* SY-TABIX has the number of the current record of ITAB1:
READ TABLE ITAB2 INDEX SY-TABIX.
IF SY-SUBRC = 0.
WRITE: ......
ENDIF.
ENDLOOP.In thi way you're sure of writing a record of ITAB2 once,but I don't know if the right solution for you, because I can't understand the link beetween ITAB1 and ITAB2.
Max
‎2008 Feb 04 11:31 AM
after looping over itab2, you can write:
DELETE ADJACENT DUPLICATES FROM itab2
COMPARING vtext.
‎2008 Feb 04 11:34 AM
sort itab2 by field1.
loop at itab1 into wa1.
clear wa2.
read table itab2 into wa2 with key field1 = wa1-field1 binary search.
if sy-subrc = 0.
write:/ wa2-field1.
endif.
endloop.
‎2008 Feb 04 11:58 AM
plz proceed with sriram ponna's code, that is better in the performance view
Regards,
Sre