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

looping internal tables

Former Member
0 Likes
1,052

Hi all,

I have an internal table filled with data. I need to take up a single record at a time and compare with all the other records of the internal table. This I need to do for all the records of the internal table.

Please tell me the best way of doing this.

Thx..

Paul

12 REPLIES 12
Read only

Former Member
0 Likes
982

Use READ statement..

-Mohan.

Read only

Former Member
0 Likes
982

use

FOR All entries in ITAB1 into ITAB2.

Do not put a select query in a loop.

Read only

dani_mn
Active Contributor
0 Likes
982

HI,

use

LOOP AT itab1.

 READ table itab2 with key field1 = itab1-field1 
                           field2 = itab1-field2.
                         

ENDLOOP.

<b>OR</b>

LOOP AT itab1.

 LOOP AT itab2.
     if itab1-field1 = itab2-field1 AND 
        itab1-field2 = itab2-field2.

     endif.
 ENDLOOP.

ENDLOOP.

Regards,

HRA

Read only

Former Member
0 Likes
982

Hi

i will give some sample code.

Loop at abc.

read table xys key xys-fieldname = abc-firlsname.

if sy-sybrc = 0.

do the comparision or any opration as requried.

endif.

read table lmn key lmn-fieldname = abc-firlsname.

if sy-sybrc = 0.

do the comparision or any opration as requried.

endif.

endloop

This will help

If it help you please don't forget to give ratting

with regards

Dhananjay

Read only

Former Member
0 Likes
982

hi pradipta..

u can use READ statement.

Read table itab with key <>.

it will bring the record one by one to the work area.

Then u can process the record in this work area.

Naveen

Read only

Former Member
0 Likes
982

Eg:

SELECT * FROM ebkn

INTO TABLE ITAB2

FOR ALL ENTRIES IN

ITAB2

WHERE (your condition).

Please reward if useful.

cheers,

Read only

0 Likes
982

Apologies!!

I misinterprited the question..

Read only

Former Member
0 Likes
982

Hi,

LOOP AT ITAB.

LOOP AT ITAB.

Do the comparison...

ENDLOOP.

ENDLOOP.

Read only

Former Member
0 Likes
982

Hello,

You can either loop on internal table and do comparision. To simplify the code you can create a copy of your internal table

ITAB_COPY[] = ITAB_ORIGINAL[].

LOOP AT ITAB_ORIGINAL.

LOOP AT ITAB_COPY.

  • If you want to compare the whole row(all columns)

IF ITAB_COPY = ITAB_ORIGINAL.

  • Do what you want

ENDIF.

ENDLOOP.

ENDLOOP.

If required you can use the

READ TABLE ITAB_ORIGINAL INDIX SY-TABIX.

TO remove duplicate rows:

SORT ITAB_ORIGIBAL.

Use...DELETE ADJACENT DUPLICATE ..COMPARING <FIELDS><fields>.

Hope it helps !!

Regards,

Vishal

Rewardif helpful

Read only

Former Member
0 Likes
982

hi,

try doing this...

sort itab1.

loop at itab2.

read table itab1 with key field1 = itab2-field1 binary search.

itab2-fld1 = itab1-fdl1.

...

...

append itab2.

endloop.

Read only

Former Member
0 Likes
982
LOOP AT ITAB1.
v_tabix = sy-tabix.
LOOP AT ITAB1.
 *--For each ITAB1 record you will be looping with all other records.
  if sy-tabix = v_tabix.
    continue.
*--this is the same record.no need to check this.
   endif.
write your code to compare & place to any other itab
ENDLOOP.
ENDLOOP.
Read only

Former Member
0 Likes
982

Hello

The best possible soln would depend on your detail requirement but as per the given details below can be one of the solutions.

--itab and itab1 have the same structure.

--your data is in itab.

itab1[] = itab[].

loop at itab.

clear itab1.

loop at itab1. {where condition}

--comparing the fields of itab with itab1.

endloop.

endloop.

regards

Anurag