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 collect similar record from the internal table

Former Member
0 Kudos

I need to collect exact matched records from 1 internal table to another internal table by searching 5 fields. I need to have records which are exactly matched for 5 fields. i have written a code wich is mention below it gave me only similar records but not 100% matched record.. would you like to help me. any correction, suggetion,. Will be great help to me.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

To get exact match of 5 records, do as follows.

Check whether internal table gives only one record or not after READ statement.If internal table gives more than one entry for READ then the results will be improper.

I think there is no need of READ statement on same internal table within LOOP. I commented the same in code.

sort i_bp_p by title initials name_last idnumber idtype f50code rbcode. "acc_num.

loop at i_bp_p into wa_i_bp_p.

*lv_tabix = sy-tabix.

*read table i_bp_p index lv_tabix into wa_i_bp_p.read table i_but0id into wa_but0id with key idnumber = wa_i_bp_p-idnumber

idtype = wa_i_bp_p-idtype binary search.

if sy-subrc = 0.

read table i_but000 into wa_but000 with key title = wa_i_bp_p-title

initials = wa_i_bp_p-initials

name_last = wa_i_bp_p-name_last binary search.

if sy-subrc = 0.

read table i_but0is into wa_but0is with key f50code = wa_i_bp_p-f50code

rbcode = wa_i_bp_p-rbcode binary search.

if sy-subrc = 0.

move-corresponding wa_i_bp_p to i_bp_p100.

append i_bp_p100.

endif.

endif.

endif.

endloop.

sort i_bp_p100 by partner.

loop at i_bp_p100.

write : /10 i_bp_p100-partner,

20 i_bp_p100-title,

30 i_bp_p100-initials,

40 i_bp_p100-name_last,

53 i_bp_p100-idnumber,

70 i_bp_p100-idtype,

85 i_bp_p100-rbcode,

95 i_bp_p100-f50code.

endloop.

************************************************

sort i_bp_p by title initials name_last idnumber idtype f50code rbcode. "acc_num.

loop at i_bp_p into wa_i_bp_p.

lv_tabix = sy-tabix.

read table i_bp_p index lv_tabix into wa_i_bp_p.

if sy-subrc = 0.

read table i_but0id into wa_but0id with key idnumber = wa_i_bp_p-idnumber

idtype = wa_i_bp_p-idtype binary search.

if sy-subrc = 0.

read table i_but000 into wa_but000 with key title = wa_i_bp_p-title

initials = wa_i_bp_p-initials

name_last = wa_i_bp_p-name_last binary search.

if sy-subrc = 0.

read table i_but0is into wa_but0is with key f50code = wa_i_bp_p-f50code

rbcode = wa_i_bp_p-rbcode binary search.

if sy-subrc = 0.

move-corresponding wa_i_bp_p to i_bp_p100.

append i_bp_p100.

endif.

endif.

endif.

endif.

endloop.

4 REPLIES 4

Former Member
0 Kudos

sort i_bp_p by title initials name_last idnumber idtype f50code rbcode. "acc_num.

loop at i_bp_p into wa_i_bp_p.

lv_tabix = sy-tabix.

read table i_bp_p index lv_tabix into wa_i_bp_p.

read table i_but0id into wa_but0id with key idnumber = wa_i_bp_p-idnumber

idtype = wa_i_bp_p-idtype binary search.

read table i_but000 into wa_but000 with key title = wa_i_bp_p-title

initials = wa_i_bp_p-initials

name_last = wa_i_bp_p-name_last binary search.

read table i_but0is into wa_but0is with key f50code = wa_i_bp_p-f50code

rbcode = wa_i_bp_p-rbcode binary search.

if sy-subrc = 0.

move-corresponding wa_i_bp_p to i_bp_p100.

append i_bp_p100.

endif.

endloop.

sort i_bp_p100 by partner.

loop at i_bp_p100.

write : /10 i_bp_p100-partner,

20 i_bp_p100-title,

30 i_bp_p100-initials,

40 i_bp_p100-name_last,

53 i_bp_p100-idnumber,

70 i_bp_p100-idtype,

85 i_bp_p100-rbcode,

95 i_bp_p100-f50code.

endloop.

Former Member
0 Kudos

by default internal table taking some key fields taht are of type C,N,D,T or X.

so when this data types fields are matching collect will add the integer or packed or quantity field i.e. numeric type fields.

try to define key fields to your numeric type fields also if you want to treat that as a key field.

regards

shiba dutta

anversha_s
Active Contributor
0 Kudos

hi,

chk this.

data : begin of itab1 occurs 0. "itab with work area.
field1 like ztable1-field1,
field2 like ztable1-field2,
field3 like ztable1-field3,
field4 like ztable1-field4,
field5 like ztable1-field5,
field6 like ztable1-field6,
field7 like ztable1-field7,
endof itab1. 


LOOP AT ITAB1 where FILED1 = FIELD1_val FILED2 = FIELD2_val  FILED3 = FIELD3_val  FILED4 = FIELD4_val FILED5 = FIELD5_val.

MOVE-CORRESPONDING TO ITAB1 to ITAB_FINAL.
append itab_final.
clear itab_final.
endloop

rgds

Anver

Former Member
0 Kudos

To get exact match of 5 records, do as follows.

Check whether internal table gives only one record or not after READ statement.If internal table gives more than one entry for READ then the results will be improper.

I think there is no need of READ statement on same internal table within LOOP. I commented the same in code.

sort i_bp_p by title initials name_last idnumber idtype f50code rbcode. "acc_num.

loop at i_bp_p into wa_i_bp_p.

*lv_tabix = sy-tabix.

*read table i_bp_p index lv_tabix into wa_i_bp_p.read table i_but0id into wa_but0id with key idnumber = wa_i_bp_p-idnumber

idtype = wa_i_bp_p-idtype binary search.

if sy-subrc = 0.

read table i_but000 into wa_but000 with key title = wa_i_bp_p-title

initials = wa_i_bp_p-initials

name_last = wa_i_bp_p-name_last binary search.

if sy-subrc = 0.

read table i_but0is into wa_but0is with key f50code = wa_i_bp_p-f50code

rbcode = wa_i_bp_p-rbcode binary search.

if sy-subrc = 0.

move-corresponding wa_i_bp_p to i_bp_p100.

append i_bp_p100.

endif.

endif.

endif.

endloop.

sort i_bp_p100 by partner.

loop at i_bp_p100.

write : /10 i_bp_p100-partner,

20 i_bp_p100-title,

30 i_bp_p100-initials,

40 i_bp_p100-name_last,

53 i_bp_p100-idnumber,

70 i_bp_p100-idtype,

85 i_bp_p100-rbcode,

95 i_bp_p100-f50code.

endloop.

************************************************

sort i_bp_p by title initials name_last idnumber idtype f50code rbcode. "acc_num.

loop at i_bp_p into wa_i_bp_p.

lv_tabix = sy-tabix.

read table i_bp_p index lv_tabix into wa_i_bp_p.

if sy-subrc = 0.

read table i_but0id into wa_but0id with key idnumber = wa_i_bp_p-idnumber

idtype = wa_i_bp_p-idtype binary search.

if sy-subrc = 0.

read table i_but000 into wa_but000 with key title = wa_i_bp_p-title

initials = wa_i_bp_p-initials

name_last = wa_i_bp_p-name_last binary search.

if sy-subrc = 0.

read table i_but0is into wa_but0is with key f50code = wa_i_bp_p-f50code

rbcode = wa_i_bp_p-rbcode binary search.

if sy-subrc = 0.

move-corresponding wa_i_bp_p to i_bp_p100.

append i_bp_p100.

endif.

endif.

endif.

endif.

endloop.