07-26-2007 10:36 AM
Hi Everybody,
I have a structure stab_sunit and an internal table itab_sunit.The structure has multiple records. Is there a way to copy the structure contents to the internal table?
Following is the code :
data : begin of stab_sunit occurs 0,
salenit type zrit_salesunit-zsunit,
prodh type zrit_salesunit-zprodh.
data : end of stab_sunit.
types : begin of t_tab_sunit,
salesunit type zrit_salesunit-zsunit,
hierarchy type zrit_salesunit-zprodh,
data : end of t_tab_sunit.
data : itab_sunit type table of t_tab_sunit.
Regards,
Varadharajan.S
07-26-2007 10:39 AM
Hi..
What do you mean by STRUCTURE here ... is it WORKAREA ?
You can APPEND a work area to internal table
APPEND <WA> TO <ITAB>.
or You can also COPY one Itab to another ITab.
itab1[] = itab2[].
<b>Reward if Helpful..</b>
07-26-2007 10:37 AM
07-26-2007 10:39 AM
Hi..
What do you mean by STRUCTURE here ... is it WORKAREA ?
You can APPEND a work area to internal table
APPEND <WA> TO <ITAB>.
or You can also COPY one Itab to another ITab.
itab1[] = itab2[].
<b>Reward if Helpful..</b>
07-26-2007 10:39 AM
Hi Varadharajan,
When you mention a STRUCTURE, by default it will have only one line. By definition STAB_SUNIT is not a structure, but it an internal table with header line.
So you can in turn use STAB_SUNIT itself as your internal table.
If you want to move the data to another internal table, then you can declare a Structure of type STAB_SUNIT and loop into STAB_SUNIT and move the records one by one.
Kindly let me know if that is what you are looking for.
<b>Reward points for informatory answers.</b>
Best Regards,
Ram.
07-26-2007 10:41 AM
Hi Varadharajan,
Strucute will only contain data at run time only.
Moving the structure content into internal table as
<b>MOVE-CORRESPONDING t_tab_sunit TO stab_sunit.
APPEND stab_sunit.</b>
But your syntaxes show t_tab_sunit as internal table and
stab_sunit as structure.
Thanks,
Vinay
07-26-2007 10:42 AM
Hi
Here the structure stab_sunit is not a structure it is an internal table only since you wrote OCCURS 0. and a structure will not have multiple records, it will have only one record
So stab_sunit is an internal table and write this line as
data : itab_sunit type table of t_tab_sunit with header line.
use
LOOP at stab_sunit .
itab_sunit-salesunit = stab_sunit-salenit.
itab_sunit-hierarchy = stab_sunit-prodh.
append itab_sunit.
clear itab_sunit.
endloop.
<b>Reward points for useful Answers</b>
Regards
Anji
07-26-2007 10:51 AM
Hi,
data : begin of stab_sunit occurs 0,
salenit type zrit_salesunit-zsunit,
prodh type zrit_salesunit-zprodh.
data : end of stab_sunit.
types : begin of t_tab_sunit,
salesunit type zrit_salesunit-zsunit,
hierarchy type zrit_salesunit-zprodh,
data : end of t_tab_sunit.
data : itab_sunit type table of t_tab_sunit.
loop at stab_sunit.
move stab_sunit-salenit to itab_sunit-salesunit.
move stab_sunit-prodh to itab_sunit-hierarchy.
append itab_sunit.
endloop.
07-26-2007 11:23 AM
08-01-2007 9:00 AM
Hi Varadharajan,
Append the datas from structure and tables is same. only diff is structure contains one data but tables contains more than one data.But same procudure only used to copy data to internal table .
with Regards,
Neptune.M