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

comparing field data in two itabs

Former Member
0 Likes
1,001

Hi All

Iu2019m calling on FM and it returns tab ITAB1 (with fields user,data, tcode & etc.). I have another structure Itab2 (with fields sing, option, low & high). Now I want to check each row in Itab2 is in the Itab2 range or not. And finally I want to save in another Itab.

Suggest me in ABAP statements,

Regards,

Hi All

Iu2019m calling on FM and it returns tab ITAB1 (with fields user,data, tcode & etc.). I have another structure Itab2 (with fields sing, option, low & high). Now I want to check each row in Itab2 is in the Itab2 range or not. And finally I want to save in another Itab.

Suggest me in ABAP statements,

Regards,

8 REPLIES 8
Read only

Former Member
0 Likes
975

Loop at itab1 .

Read table itab2 with key ( Comparing fields ).

If sy-subrc eq o.

Move what ever your require in the 3rd itab.

Append itab3.

clear itab3.

endif.

endloop.

Read only

Former Member
0 Likes
975

Hi

declare a range r_range and pass the values of itab2 to r_range.

loop at itab1 into wa_itab1.

if wa_itab1-data in r_range .

els.

endif.

endloop.

regards,

Ramya

Read only

0 Likes
975

Hi Ramy,

Can you explain a little bit clearly. I hope this process will solve my problem.

Thkx

Read only

JozsefSzikszai
Active Contributor
0 Likes
975

for example you can use:

LOOP AT ITAB1 INTO ... WHERE field IN itab2.

==> this value of field is in itab2

ENDLOOP.

Read only

Former Member
0 Likes
975

Hi

data: itab3 like table of itab1 with header line.

loop at itab1.

    read table  itab2 with table key  <condition>.
       if sy-subrc = 0.
         move itab1 to itab3.       
       endif .
enloop.

Hope this logic will help ful

Regards

Srinivasu

Edited by: srinivasu bv on Nov 10, 2008 11:06 AM

Read only

0 Likes
975

Hi Srinivas,

Sorry for asking this question.

In ur replay, in Read stat I need to write some contion. But the confustion is Itab1 contains a field Tcode but Itab2 contain fields Low & High (as Tcode fields).

So, How can i write a condition at this case. Plz help me on this.

Thnks.

Read only

0 Likes
975

Hi Sandya

Give the Declerations of itab1 and itab2 internal tabels

then it is easy to understand your requiremnt

Regards

Read only

Former Member
0 Likes
975

REPORT ZSRK_035 .

DATA : BEGIN OF ITAB1 OCCURS 0,

USER LIKE USR01-BNAME,

DATA(30),

TCODE LIKE TSTC-TCODE,

END OF ITAB1.

DATA : BEGIN OF ITAB2 OCCURS 0,

SIGN,

OPTION(2),

LOW LIKE TSTC-TCODE,

HIGH LIKE TSTC-TCODE,

END OF ITAB2.

ITAB2-SIGN = 'I'.

ITAB2-OPTION = 'BT'.

ITAB2-LOW = 'MM01'.

ITAB2-HIGH = 'MM03'.

APPEND ITAB2.

CLEAR ITAB2.

ITAB1-USER = SY-UNAME.

ITAB1-DATA = 'AAAAAAAAAAAA'.

ITAB1-TCODE = 'VA01'.

APPEND ITAB1.

CLEAR ITAB1.

ITAB1-USER = SY-UNAME.

ITAB1-DATA = 'BBBBBBBBBBBB'.

ITAB1-TCODE = 'MM02'.

APPEND ITAB1.

CLEAR ITAB1.

ITAB1-USER = SY-UNAME.

ITAB1-DATA = 'CCCCCCCCCCCCCCC'.

ITAB1-TCODE = 'MM01'.

APPEND ITAB1.

CLEAR ITAB1.

ITAB1-USER = SY-UNAME.

ITAB1-DATA = 'DDDDDDDDDDDDD'.

ITAB1-TCODE = 'VA02'.

APPEND ITAB1.

CLEAR ITAB1.

ITAB1-USER = SY-UNAME.

ITAB1-DATA = 'EEEEEEEEEEEE'.

ITAB1-TCODE = 'MM03'.

APPEND ITAB1.

CLEAR ITAB1.

LOOP AT ITAB1 WHERE TCODE IN ITAB2.

WRITE : / ITAB1-DATA.

ENDLOOP.