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: 

Copying data from structure to internal table

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

varma_narayana
Active Contributor
0 Kudos

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>

8 REPLIES 8

Former Member
0 Kudos

Hi,

Structure doensot contain any data.

varma_narayana
Active Contributor
0 Kudos

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>

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

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

dev_parbutteea
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

simply use APPEND <wa> TO <itab>.

Regards

Prax

Former Member
0 Kudos

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