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

Populating Dynamic Internal Table ?

Former Member
0 Likes
2,368

Hello All,

I have the fieldcatalog and from this I have creted a dynamic internal table like this :


* Create Dynamic Table
  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = lt_fcat[]
    IMPORTING
      ep_table        = dy_table.
  ASSIGN dy_table->* TO <dyn_table>.

* Create Dynamic Work Area and Assign to FS
  CREATE DATA dy_line LIKE LINE OF <dyn_table>.
  ASSIGN dy_line->* TO <dyn_wa>.

I have my data in one of the internal table (ITAB).

Now I want to populate the dynamic internal table <fs_tab> with that data in the other internal table (itab) .

For this I guess I need to use ASSIGN COMPONENT Statement.

But I'm not able to decide upon how to do that.

For eg. :-

1. Say my internal table (ITAB) has 5 fields f1,f2,f3,f4,f5.

2. My Dynamic INternal table <fs_tab> has 3 fields f1,f3,f5 (from the above code).

3. Now I want to populate this dynamic table with the data from the Internal table ITAB for those particular 3 fields (f1,f3,f5).

How to pass the data to the dyntab ?

Request you all to clarify.

PS: PLease don't send me any links as I already read them but cudn't get thru it!

Regards,

Deepu.K

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,141

Hi

* Create Dynamic Table
  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = lt_fcat[]
    IMPORTING
      ep_table        = dy_table.
  ASSIGN dy_table->* TO <dyn_table>.
 
* Create Dynamic Work Area and Assign to FS
  CREATE DATA dy_line LIKE LINE OF <dyn_table>.
  ASSIGN dy_line->* TO <dyn_wa>.

DATA: FIELDNAME(3) TYPE C.

FIELD-SYMBOLS: <FS_FIELD_FROM>, 
                            <FS_FIELD_TO>.

LOOP AT ITAB.
    
   DO 3 TIMES.
     WHEN 1. FIELDNAME = 'F1'.
     WHEN 2. FIELDNAME = 'F3'.
     WHEN 3. FIELDNAME = 'F5'.
    ASSINGN COMPONENT FIELDNAME OF STRUCTURE ITAB TO <FS_FIELD_FROM>.
    ASSINGN COMPONENT FIELDNAME OF STRUCTURE <DYN_WA> TO <FS_FIELD_TO>.
    <FS_FIELD_TO> = <FS_FIELD_FROM>.
   ENDDO.
   APPEND  <DYN_WA> TO <dyn_table>.
ENDLOOP.

Max

4 REPLIES 4
Read only

Former Member
0 Likes
1,141

Simple way is to create a work area for the dynamic table and populate the work area using move-corresponding and append the dynamic internal table.

as shown below:


  data: l_wa_ref type ref to data.
  field-symbols:
  <l_wa_f_data> type any.

  create data l_wa_ref like line of <f_data>.
*Assign the work area
  assign l_wa_ref->* to <l_wa_f_data>.
  check sy-subrc = 0.

  loop at i_final2 into wa_final2.

    move-corresponding wa_final2 to <l_wa_f_data>.
* etc etc

  endloop.
 

Read only

0 Likes
1,141

Hello Sourav,

I did the same but it's going for a dump saying :

" Incorrect type of operand with the MOVE-CORRESPONDING statement."

Any other clues ?

Regards,

Deepu.K

Read only

Former Member
0 Likes
1,142

Hi

* Create Dynamic Table
  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = lt_fcat[]
    IMPORTING
      ep_table        = dy_table.
  ASSIGN dy_table->* TO <dyn_table>.
 
* Create Dynamic Work Area and Assign to FS
  CREATE DATA dy_line LIKE LINE OF <dyn_table>.
  ASSIGN dy_line->* TO <dyn_wa>.

DATA: FIELDNAME(3) TYPE C.

FIELD-SYMBOLS: <FS_FIELD_FROM>, 
                            <FS_FIELD_TO>.

LOOP AT ITAB.
    
   DO 3 TIMES.
     WHEN 1. FIELDNAME = 'F1'.
     WHEN 2. FIELDNAME = 'F3'.
     WHEN 3. FIELDNAME = 'F5'.
    ASSINGN COMPONENT FIELDNAME OF STRUCTURE ITAB TO <FS_FIELD_FROM>.
    ASSINGN COMPONENT FIELDNAME OF STRUCTURE <DYN_WA> TO <FS_FIELD_TO>.
    <FS_FIELD_TO> = <FS_FIELD_FROM>.
   ENDDO.
   APPEND  <DYN_WA> TO <dyn_table>.
ENDLOOP.

Max

Read only

0 Likes
1,141

Hello Max,

Many Thanks for your Wonderful Reply !!!

I got it done now.

But I've one more Problem.

I'll post it in another thread.

Hope u'll come to rescue !

Regards,

Deepu.K