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

ASSIGN COMPONENT from a table to a dynamic table

Former Member
0 Likes
2,353

every body,

     there is a very interesting thing,i didn't use before.

     in a programe,i want to transfer data from a internal table to a dynamic table,and the table tb_data may be diffrent every time,so i coded follow:


CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
     EXPORTING
       IT_FIELDCATALOG = IT_FLDCAT
     IMPORTING
       EP_TABLE        = DREF.

   ASSIGN DREF->* TO <GT_DYN_TABLE>.

   ASSIGN COMPONENT 0 OF STRUCTURE TB_DATA[] TO <GT_DYN_TABLE>.

not used work area and assign filed one by one,the <GT_DYN_TABLE> get structure and has all data from TB_DATA.but the <GT_DYN_TABLE> is diffrent with DREF now.


ps,i don't want the table <GT_DYN_TABLE>  has the same fileds with tb_data,maybe one field more,is there any solution?

1 ACCEPTED SOLUTION
Read only

jrg_wulf
Active Contributor
1,303

Hi,

first of all, the answer is yes.

Now for your code-sample. Upto ASSIGN DREF->* TO <GT_DYN_TABLE> everything is fine.

With the next Statement however, you messed it up..

Provided you are on NW 7.4 or later, you could just use

MOVE_CORRESPONDING TB_DATA[] TO <GT_DYN_TABLE>.

BTW. does your TB_DATA really have a headerline? And if so, to what purpose?

Otherwise the brackets [] aren't necessary.

On lower Releases, you'll need at least another set of field-symbols, one for each table.

Then, you can just

LOOP A TB_DATA ASSIGNING <FS1>.

APPEND INITIAL LINE TO <GT_DYN_TABLE> ASSIGNING <FS2>.

MOVE-CORRESPONDING <FS1> TO <FS2>.

ENDLOOP.

Or, in case you really have a Header line use:

LOOP AT TB_DATA INTO TB_DATA.

APPEND INITIAL LINE TO <GT_DYN_TABLE> ASSIGNING <FS2>.

MOVE-CORRESPONDING TB_DATA TO <GT_DYN_TABLE>.

ENDLOOP.

That should do the trick.

Best regards - Jörg

every body,

     there is a very interesting thing,i didn't use before.

     in a programe,i want to transfer data from a internal table to a dynamic table,and the table tb_data may be diffrent every time,so i coded follow:


CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
     EXPORTING
       IT_FIELDCATALOG = IT_FLDCAT
     IMPORTING
       EP_TABLE        = DREF.

   ASSIGN DREF->* TO <GT_DYN_TABLE>.

   ASSIGN COMPONENT 0 OF STRUCTURE TB_DATA[] TO <GT_DYN_TABLE>.

not used work area and assign filed one by one,the <GT_DYN_TABLE> get structure and has all data from TB_DATA.but the <GT_DYN_TABLE> is diffrent with DREF now.


ps,i don't want the table <GT_DYN_TABLE>  has the same fileds with tb_data,maybe one field more,is there any solution?

2 REPLIES 2
Read only

jrg_wulf
Active Contributor
1,304

Hi,

first of all, the answer is yes.

Now for your code-sample. Upto ASSIGN DREF->* TO <GT_DYN_TABLE> everything is fine.

With the next Statement however, you messed it up..

Provided you are on NW 7.4 or later, you could just use

MOVE_CORRESPONDING TB_DATA[] TO <GT_DYN_TABLE>.

BTW. does your TB_DATA really have a headerline? And if so, to what purpose?

Otherwise the brackets [] aren't necessary.

On lower Releases, you'll need at least another set of field-symbols, one for each table.

Then, you can just

LOOP A TB_DATA ASSIGNING <FS1>.

APPEND INITIAL LINE TO <GT_DYN_TABLE> ASSIGNING <FS2>.

MOVE-CORRESPONDING <FS1> TO <FS2>.

ENDLOOP.

Or, in case you really have a Header line use:

LOOP AT TB_DATA INTO TB_DATA.

APPEND INITIAL LINE TO <GT_DYN_TABLE> ASSIGNING <FS2>.

MOVE-CORRESPONDING TB_DATA TO <GT_DYN_TABLE>.

ENDLOOP.

That should do the trick.

Best regards - Jörg

Read only

Former Member
0 Likes
1,303

hi,Jörg

thank you for your response and i will try your suggest later

and the code is a part of a form,because of the tb_data is not static, so i didn't declare the type,  like this


FORM ASSIGNDATATODYNTABLE TABLES TB_DATA.

before the form,there is no header line.