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

join between itab and ztable

Former Member
0 Likes
1,700

i have a scenario,

where i have a itab inprofpost which has

besides other fields kostl aufnr lstar as key fields,

now for each entry in inprofpost

i have to pick up all the entries from bseg which match

kostl aufnr lstar

into another itab final_tab along with inprofpost entries.

am i clear, the final_tab must have entries

which are join of this itab and also bseg. ie. it should have

a total of ( # of itab * # of bseg ) entries.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,672

thank you all of you.

we can use select inside loop with condition, thats ok,

but wat about the other fields in itab1 which have to be copied into final_itab.

like i said itab1 has 5 fields and ztable has 5 fields.

the final_itab should have all the 10 entries including 3 common fields.

i have a scenario,

where i have a itab inprofpost which has

besides other fields kostl aufnr lstar as key fields,

now for each entry in inprofpost

i have to pick up all the entries from bseg which match

kostl aufnr lstar

into another itab final_tab along with inprofpost entries.

am i clear, the final_tab must have entries

which are join of this itab and also bseg. ie. it should have

a total of ( # of itab * # of bseg ) entries.

12 REPLIES 12
Read only

Former Member
0 Likes
1,672

Hi Saritha,

Can you please be more specific. I am not clear as what exactly you want :(.

Regards,

Atish

Read only

Former Member
0 Likes
1,672

data is there in itab1 and ztable.

now final_itab is empty.

for every entry in itab1, all the entries in ztable should be copied to final_itab along with itab1 values.

if for entry in itab1 there are 5 entries in ztable, and if itab1 has 2 entries.

then final_itab should have a total of 10 entries.

am i clear, if not i will try to be more clear.

thankyou for the response.

Read only

Former Member
0 Likes
1,672

then use forall entries command instead of join ...

Read only

0 Likes
1,672

Or just use loop , like

loop at itab.

select ... from bseg into itab2 where ... = itab-col

endloop.

Then you'll have itab2 as result you wanted .

Read only

Former Member
0 Likes
1,672

there are 3 fields common in between itab1 and ztable, which should match before picking.

Read only

0 Likes
1,672

Hi Saritha,

try something like this,

select field1 field 2... from ztable into final_itab for all entries in itab

where ....(three common field condition)

Revert back if further query.

Regards,

Atish

Read only

0 Likes
1,672

Hi,

Use the three common fields in condition for select statement.

Read only

Former Member
0 Likes
1,672

use this select query

if inprofpost[] is not intial.

select * from bseg

into table final_tab

for all entiries in inprofpost

where lstar = inprofpost-lstar

and aufnr = inprofpost-aufnr

and kostl = inprofpost-kostl.

endif.

Please reward ponts if helpful

Read only

Former Member
0 Likes
1,673

thank you all of you.

we can use select inside loop with condition, thats ok,

but wat about the other fields in itab1 which have to be copied into final_itab.

like i said itab1 has 5 fields and ztable has 5 fields.

the final_itab should have all the 10 entries including 3 common fields.

Read only

0 Likes
1,672

Hi Saritha,

First select 5 fields in final_itab as mentioned above.

now use below code.

LOOP AT final_itab.

Read table itab1 with key ...(use common fields as key between itab and final_itab)

final_itab-field6 = itab-field1.

..like this move all fields.

Modify final_itab.

ENDLOOP.

Hope it is clear.

Regards,

Atish

Read only

0 Likes
1,672

Hi,

If you decided to use select inside loop, then your logic should be,

loop at itab1 into wa1.

select f1 f2 f3 f4 f5 into corresponding fields of wa_ztable

where f1 = wa1-f1 and f2 = wa1-f2 and f3 = wa1-f3.

move-corresponding wa_ztable to wa_final.

move-corresponding wa1 to wa_final.

append wa_final to itab_final.

endselect.

endloop.

Otherwise, you can use for all entries.

if not itab[] is initial.

select f1 f2 f3 f4 f5 from bseg into table itab_ztable for all entries in itab

where f1 = itab-f1 and f2 = itab-f2 and f3 = itab-f3.

endif.

loop at itab into wa.

read table itab_ztable into wa_ztable with key f1 = wa-f1

f2 = wa-f2 f3 = wa-f3.

if sy-subrc eq 0.

move-corresponding wa_ztable to wa_final.

move-corresponding wa1 to wa_final.

append wa_final to itab_final.

endif.

endloop.

Kindly reward points by clicking the star on the left of reply,if it helps.

Read only

Former Member
0 Likes
1,672

thanks jayanthi,

thank you very much.

i couldnot assign more points because i already gave those to thers.

i appreciate your help.