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: 

how to fetch similar record from the internal table,

naimkhans_babi
Active Participant
0 Kudos

dear firends,

would you like to give me some idea, about how to fetch, similar record from one internal table to another internal table...any code, suggestion, article will be greate help of mine,,

thankign you..

regards,

Naim

1 ACCEPTED SOLUTION

rahulkavuri
Active Contributor
0 Kudos

do u mean to get similar records from 2 internal tables then u need to use the read statement and get the records into another internal table of similar structure

LOOP AT ITAB1.

READ TABLE ITAB2 WITH KEY VBELN = ITAB1-VBELN.

IF SY-SUBRC = 0.

ITAB3 = ITAB1.// this get the header line into itab

APPEND ITAB3.

ENDIF.

ENDLOOP.

otherwise if u mean to say similar records from one internal table then u need to

SORT ITAB BY VBELN POSNR.
  LOOP AT ITAB.

    AT NEW VBELN.

MOVE ITAB TO ITAB2.

    ENDAT.

  ENDLOOP.

This will get all the distinct records into ITAB2

6 REPLIES 6

Former Member
0 Kudos

Hello Naim,

Could you provide an example of 2 internal tables with their content, to clarify your problem?

Regards,

John.

former_member181962
Active Contributor
0 Kudos

loop at itab where field1 = 'test'.

move-coresponding itab to itab_new.

append itab_new.

clear itab_new.

endloop.

For demo programs on internal tables, look at the program:

DEMO_INTERNAL_TABLE

and for more:

go to se38 and type

demointtable* and press f4 to get a big list of programs.

Regards,

Ravi

rahulkavuri
Active Contributor
0 Kudos

do u mean to get similar records from 2 internal tables then u need to use the read statement and get the records into another internal table of similar structure

LOOP AT ITAB1.

READ TABLE ITAB2 WITH KEY VBELN = ITAB1-VBELN.

IF SY-SUBRC = 0.

ITAB3 = ITAB1.// this get the header line into itab

APPEND ITAB3.

ENDIF.

ENDLOOP.

otherwise if u mean to say similar records from one internal table then u need to

SORT ITAB BY VBELN POSNR.
  LOOP AT ITAB.

    AT NEW VBELN.

MOVE ITAB TO ITAB2.

    ENDAT.

  ENDLOOP.

This will get all the distinct records into ITAB2

Former Member
0 Kudos

hi naim,

loop at itab where field1 = 'aaa'.

itab1[] = itab[].

append itab1.

clear itab1.

endloop.

Former Member
0 Kudos

Hi Naim,

loop at itab1.

read table itab2 where fld1 = itab1-dat1.

if sy-subrc=0.

append itab2 to itab3.

endif.

endloop.

award if it helps.

regards,

keerthi.

Former Member
0 Kudos

Hi Naim,

Do this way.

Sort internal table first and then check for similar records and transfer those records.

Sort itab.

Loop at itab.

if itab_previous = itab.

move itab to itab1.

append itab1.

endif.

itab_previous = itab.

clear itab.

endloop.

loop at itab1.

write:/ itab1.

endloop.

declare itab and itab1 as similar internal tables and itab_previous is the work area of itab.

Finally, itab1 contains the similar records present in itab.

Hope this helps.

Regards,

Vicky

PS: Award points if helpful