Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Please help me to modify the code here !!!!

Former Member
0 Likes
1,104

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 !!!

11 REPLIES 11
Read only

Former Member
0 Likes
1,085

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.

Read only

0 Likes
1,085

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

Read only

Former Member
0 Likes
1,085

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

Read only

Former Member
0 Likes
1,085

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.

Read only

0 Likes
1,085

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.

Read only

Former Member
0 Likes
1,085

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

Read only

0 Likes
1,085

WHAT IS VN_TABIX ?

Read only

0 Likes
1,085

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

Read only

Former Member
0 Likes
1,085

after looping over itab2, you can write:

DELETE ADJACENT DUPLICATES FROM itab2

COMPARING vtext.

Read only

Former Member
0 Likes
1,085

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.

Read only

Former Member
0 Likes
1,085

plz proceed with sriram ponna's code, that is better in the performance view

Regards,

Sre