‎2009 Feb 26 4:02 AM
I want to create one internal table to extract data of multiple structures.
E.g. I have two structures :
Types:
Begin of g_struct1,
column1 type c ,
column2 type c ,
Begin of g_struct1,
Begin of g_struct2,
column3 type c ,
column4 type c ,
column5 type c ,
Begin of g_struct2,
data: w_struct1 type g_struct1,
w_struct2 type g_struct3,
w_struct1-column1 = 'A'.
w_struct1-column2 = 'B'.
w_struct2-column3 = 'C'.
w_struct2-column4 = 'D'.
w_struct2-column5 = 'E'.
For the above two structures i want to build internal table and create a common key.
Expected Data in Internal Table
1AB
1CDE
Appreciate help.
‎2009 Feb 26 4:05 AM
Hi Rao,
Can you elabrate your requirement .so that it is more convenient get a solution for your question.
‎2009 Feb 26 4:15 AM
‎2009 Feb 26 4:17 AM
i did not understood ur queryy properly, but, do u mean like below,(with assumption that, each itab1 and itab2 does contans same # of recs)
data ind type i.
consolidated_itab is ur result itab.
describe table itab1 lines sy-tfill.
do sy-tfill times.
add 1 to idx.
read itab1 index idx
consolidated_itab-key = idx.
consolidated_itab-field1 = itab1-field1.
append consolidated_itab
clear consolidated_itab
read itab2 index idx
consolidated_itab-key = idx.
consolidated_itab-field1 = itab2-field1.
append consolidated_itab
clear consolidated_itab
enddo.
there r syntax errors, pls. check.
thanq
‎2009 Feb 26 4:19 AM
Dear,
do like this,
data: begin of t_itab occurs 0,
include structure t_struct1.
include structure t_struct2.
data: end of t_itab.
regards
vijay
‎2009 Feb 26 4:35 AM
Hi,
try this.
Create one more field which would be common for both structures.
Types:
Begin of g_struct1,
comm type i,
column1 type c ,
column2 type c ,
Begin of g_struct1,
Begin of g_struct2,
comm type i,
column3 type c ,
column4 type c ,
column5 type c ,
Begin of g_struct2,
data: w_struct1 type g_struct1,
w_struct2 type g_struct3.
data: itab1 like standard table of w_struct1,
itab2 like standard table of w_struct2.
w_struct1-comm = 1.
w_struct1-column1 = 'A'.
w_struct1-column2 = 'B'.
append w_struct1 to itab1.
clear w_struct1.
w_struct2-comm = 1.
w_struct2-column3 = 'C'.
w_struct2-column4 = 'D'.
w_struct2-column5 = 'E'.
append w_struct2 to itab2.
clear w_struct2.
‎2009 Feb 26 5:02 AM
Hi Rao,
One small suggession. Check whether this is useful in your case.
Instead of having two different internal tables with a common key, you can create one internal table with all the fields available in it.
Please see the code below.
Types:
Begin of g_struct3,
column1 type c ,
column2 type c ,
column3 type c ,
column4 type c ,
column5 type c ,
End of g_struct3.
data: it_struct3 type standard table of g_struct3.
data: w_struct3 type g_struct3.
w_struct3-column1 = 'A'.
w_struct3-column2 = 'B'.
w_struct3-column3 = 'C'.
w_struct3-column4 = 'D'.
w_struct3-column5 = 'E'.
append w_struct3 to it_struct3.
Your internal table will have the data like shown below.
A B C D E
What ever manipulations you want to make with two internal tables (having a common key), you can do those manipulations with one internal table (having all those fields available) also.
‎2009 Feb 28 11:10 PM
Hi,
To have multiply structures in one table and later be able to address them within one table row, do the following:
"first structure
types: begin of g_struct1,
column1 type c ,
column2 type c ,
end of g_struct1.
"second one
types: begin of g_struct2,
column3 type c ,
column4 type c ,
column5 type c ,
end of g_struct2.
"compound type of these two structures
types: begin of g_struct.
include type g_struct1 as first_struct.
include type g_struct2 as sec_struct.
types: end of g_struct.
"table type of compound structures type
types: g_tab type table of g_struct with key ..... "list your key fields here (will become common key)
"declare your table
data: gt_tab type g_tab with header line.
"now you address table components (all 5 columns) normally i.e.
gt_tab-column1 = ...
gt_tab-column2 = ...
...
gt_tab-column5 = ...
"but you can also address entire structures within the table (not only its components) i.e. when passing to
"subroutine
perform my_sub using gt_tab-first_struct1 "pass all components of first structure (2 first columns)
gt_tab-sec_struct2. "pass all components of sec one (3 last columns)
form my_sub using f_struct1 type g_struct1
f_struct2 type g_struct2.
"here you still can adress the componetns separately like
f_strcut1-column1 = ...
...
f_strcut2-column4 =...
"but also address them like
move-corresponding f_struct1 to .... "move all components at once
endform.
This way you can achieve structures' multiplicity in one table using desired fields as key fields (which will be a common key to those two structures)
Regards
Marcin