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

need data form three different itabs

Former Member
0 Likes
619

Dear All!

There are three various internal tables

lets say itab1,itab2,itab3 which are containing data.

Only these information where the user

selects through select-options fields are relevant for the

report which have to be created.

My Problem is now. How can I obtain these affected

information simultionously from three different itabs and also

considering the restrictions in respect of users entered values

via select-options fileds. Do u have an idea how to solve

such a complex situation.

Thanks is advance.

Regards

Erdem Sas

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
602

Hi,

Check the below code.

tables p0001.

select-options: s_pernr for p0001-pernr.

data: begin of itab1 occurs 0,

pernr like p0001-pernr,

end of itab1.

data: begin of itab2 occurs 0,

pernr like p0001-pernr,

ename like p0001-ename,

end of itab2.

data: begin of itab3 occurs 0,

pernr like p0001-pernr,

gbdat like p0002-gbdat,

end of itab3.

data: begin of it_final occurs 0,

pernr like p0001-pernr,

ename like p0001-ename,

gbdat like p0002-gbdat,

end of it_final.

select distinct pernr

from pa0000 up to 5 rows

into table itab1 where stat2 ='3' .

if sy-subrc = 0.

sort itab1 by pernr.

select distinct pernr ename from pa0001 into table itab2

for all entries in itab1 where pernr = itab1-pernr.

if sy-subrc = 0.

sort itab2 by pernr.

endif.

select distinct pernr gbdat from pa0002 into table itab3

for all entries in itab1 where pernr = itab1-pernr.

if sy-subrc = 0.

sort itab3 by pernr.

endif.

endif.

loop at itab1 where pernr in s_pernr.

it_final-pernr = itab1-pernr.

read table itab2 with key pernr = itab1-pernr.

if sy-subrc = 0.

it_final-ename = itab2-ename.

endif.

read table itab3 with key pernr = itab1-pernr.

if sy-subrc = 0.

it_final-gbdat = itab3-gbdat.

endif.

append it_final.

clear it_final.

endloop.

loop at it_final.

write:/5 it_final-pernr,

15 it_final-ename,

55 it_final-gbdat.

endloop.

Edited by: Velangini Showry Maria Kumar Bandanadham on Apr 24, 2008 2:59 PM

5 REPLIES 5
Read only

Sm1tje
Active Contributor
0 Likes
602

well I hope that the data in your three internal tables already have the selection screen data taken into account before filling them. So the selections on selection screen should be used during selection of the data. So this problem should really not be an issue here.

Now take ONE internal table as your starting point and loop over it. Next read (READ or LOOP depends on the relation between the internal tables) the other two tables with the keys fields from the first internal table into a workarea.

At last move all the data to a new internal table which will be your output. For this, define a fourth internal table with the structure of your output. Also create a workarea for this internal table and you are almost there.

Read only

Former Member
0 Likes
602

Hi,

he selection screen data has benn taken into account.

Do you have an code example for me ?

Regards

sas

Read only

0 Likes
602

loop at itab1 into wa1.

read itab2 into wa2 with key fieldx = wa1-fieldx

fieldy = wa1-fieldy.

  • OR IF SECOND TABLE CAN HAVE MORE THAN ONE ENTRY FOR EVERY RECORD IN itab1.

loop at itab2 into wa2 where fieldx = wa1-fieldx and fieldy = wa1-fieldy.

endloop.

  • FOR THIRD INTERNAL TABLE DO THE SAME.

  • AT THE END MOVE DATA TO NEW WORKAREA AND APPEND TO FOURTH INTERNAL TABLE.

wa4-fieldx = wa1-fieldx

wa4-fieldy = wa1-fieldy

wa4-fielda = wa2-fielda

wa4-fieldb = wa3-fieldb.

append wa4 to itab2.

clear wa1, wa2, wa3, wa4.

endloop.

This is just an example, you will have to determine what the best is in your particular case. Like should we do an append in there a NO entries in itab2 when reading / looping??

There has to be a relationship between the three internal tables and this relationship is in this case fieldx and fieldy. You jhave to determine for yourself which fields are relevant.

Read only

Former Member
0 Likes
603

Hi,

Check the below code.

tables p0001.

select-options: s_pernr for p0001-pernr.

data: begin of itab1 occurs 0,

pernr like p0001-pernr,

end of itab1.

data: begin of itab2 occurs 0,

pernr like p0001-pernr,

ename like p0001-ename,

end of itab2.

data: begin of itab3 occurs 0,

pernr like p0001-pernr,

gbdat like p0002-gbdat,

end of itab3.

data: begin of it_final occurs 0,

pernr like p0001-pernr,

ename like p0001-ename,

gbdat like p0002-gbdat,

end of it_final.

select distinct pernr

from pa0000 up to 5 rows

into table itab1 where stat2 ='3' .

if sy-subrc = 0.

sort itab1 by pernr.

select distinct pernr ename from pa0001 into table itab2

for all entries in itab1 where pernr = itab1-pernr.

if sy-subrc = 0.

sort itab2 by pernr.

endif.

select distinct pernr gbdat from pa0002 into table itab3

for all entries in itab1 where pernr = itab1-pernr.

if sy-subrc = 0.

sort itab3 by pernr.

endif.

endif.

loop at itab1 where pernr in s_pernr.

it_final-pernr = itab1-pernr.

read table itab2 with key pernr = itab1-pernr.

if sy-subrc = 0.

it_final-ename = itab2-ename.

endif.

read table itab3 with key pernr = itab1-pernr.

if sy-subrc = 0.

it_final-gbdat = itab3-gbdat.

endif.

append it_final.

clear it_final.

endloop.

loop at it_final.

write:/5 it_final-pernr,

15 it_final-ename,

55 it_final-gbdat.

endloop.

Edited by: Velangini Showry Maria Kumar Bandanadham on Apr 24, 2008 2:59 PM

Read only

S0025444845
Active Participant
0 Likes
602

Hi,

declare one more internal table it_final. with all the fields u want in output.

now ,

loop at itab1 into wa_itab1.

move fields of wa_itab1 to wa_final.

read table itab2 into wa_itab2 with key < use the fields which are common in itab1 and itab2>.

if sy-subrc is initail.

move fields of wa_itab2 to wa_final.

endif.

read table itab3 into wa_itab3 with key < use the fields which are common in itab1 and itab3>.

if sy-subrc is initail.

move fields of wa_itab3 to wa_final.

endif.

append wa_final to it_final.

clear: wa_final,wa_itab1,wa_itab2,wa_itab3.

endloop.

regards,

sudha