Application Development 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: 

Internal Table

Former Member
0 Kudos

Hi friends,

I have an Internal table I_tab and j_tab with matnr as a field,

for each entry in I_tab, I need to check j_tab ,is there is repeating matnr in j_tab.

10 REPLIES 10

Former Member
0 Kudos

hi Karhik,

Use <b>for all corresponding fields of j_tab</b> statement in the select statement

or

sort: l_tab , j_tab.

loop at l_tab.

<b>read table j_tab with key matnr = l_tab-matnr</b>

endloop.

Regards,

Santosh

suresh_datti
Active Contributor
0 Kudos

try this..


sort: l_tab,j_tab.
loop at l_tab.
read table j_tab with key matnr = l_tab-matnr
binary search.
if sy-sub rc eq 0.
* entry exists in j_tab.
endif.
endloop.

Regards,

Suresh Datti

Former Member
0 Kudos

Hi,

Loop at I_tab.

read table J_tab with key matnr = i_tab-matnr.

if sy-subrc = 0

Success

endif.

endloop.

If you are looking for more than one entry in J_tab ...

Loop at I_tab.

loop at J_tab where matnr = i_tab-matnr.

if sy-tabix = 2

Success

endif.

endloop.

endloop.

Regards,

Ravi

Note : Please close the thread of the issue is resolved.

0 Kudos

Hi Ravi

You can't check SY-TABIX, because it indicates the number of the record you're elaborating and not how many records (with a certain value) are in the table.

max

former_member927251
Active Contributor
0 Kudos

Hi,

Use the following code.

Loop at I_tab into wa_tab1.

Read table j_tab into wa_tab2

with key matnr = wa_itab1-matnr.

if sy-subrc eq 0.

  • There is an entry for matnr in both the tables

  • Do your processing

endif.

endloop.

Hope this helps.

Please reward some points if it helps.

Regards,

Amit Mishra

Message was edited by: Amit Mishra

Former Member
0 Kudos

Hi

You need to read j_tab with field MATNR

DATA: COUNT TYPE I.

LOOP AT I_TAB.

COUNT = 0.

LOOP AT J_TAB WHERE MATNR = ITAB-MATNR.

COUNT = COUNT + 1.

IF COUNT > 2. EXIT. ENDIF.

ENDLOOP.

ENDLOOP.

max

ferry_lianto
Active Contributor
0 Kudos

Hi Kalimuthu,

You can use ABAP command <b>SEARCH itab</b>.


SEARCH itab FOR pattern [IN {BYTE|CHARACTER} MODE] 
       [STARTING AT idx1] [ENDING AT idx2] 
       [ABBREVIATED] 
       [AND MARK].

and check the return value

SY-SUBRC Relevance

0 Pattern found in itab.

4 Pattern not found in itab.

Hope this will help.

Regards,

Ferry Lianto

Former Member
0 Kudos

Just to be different...


data: j_tab_temp LIKE j_tab OCCURS 0,
      count      TYPE i.

LOOP AT i_tab.
  j_tab_temp[] = j_tab[].
  DELETE j_tab_temp WHERE matnr <> i_tab-matnr.
  DESCRIBE TABLE j_tab_temp LINES count.
  IF count > 1.
*-- more than one entry exists in j_tab for this MATNR
  ENDIF.
  CLEAR j_tab_temp[].
ENDLOOP.

Former Member
0 Kudos

Have a look at <a href="/people/rob.burbank/blog/2006/02/07/performance-of-nested-loops">this.</a>

Rob

Former Member
0 Kudos

Hi Kalimuthu,

You can use the following Logic. I have given the sample code.


DATA : count TYPE i.

SORT i_tab BY matnr.
SORT j_tab BY matnr.

CLEAR count.
LOOP AT i_tab.
  LOOP AT j_tab WHERE matnr = i_tab-matnr.
    count = count + 1.
    IF count GT 1.

      "Repeating matnr do your processing here

      EXIT.
    ENDIF.

  ENDLOOP.
  CLEAR count.  "Clear the count for next matnr in i_tab
ENDLOOP.

Regards,

Arun S.