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

Copying data from structure to internal table

Former Member
0 Likes
3,505

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
Read only

varma_narayana
Active Contributor
0 Likes
1,919

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>

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

8 REPLIES 8
Read only

Former Member
0 Likes
1,919

Hi,

Structure doensot contain any data.

Read only

varma_narayana
Active Contributor
0 Likes
1,920

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>

Read only

Former Member
0 Likes
1,919

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.

Read only

Former Member
0 Likes
1,919

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

Read only

Former Member
0 Likes
1,919

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

Read only

dev_parbutteea
Active Contributor
0 Likes
1,919

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.

Read only

Former Member
0 Likes
1,919

simply use APPEND <wa> TO <itab>.

Regards

Prax

Read only

Former Member
0 Likes
1,919

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