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: 

Interal table structure in runtime

Former Member
0 Kudos

Hello experts,

How can i copy the structure of an internal table to another internal table?. Im trying to do this:

data: p_table_out type table.

types: begin of ty_generic,

matnr type matnr,

fkimg type fkimg,

meins type meins,

end of ty_generic.

data: it_generic type table of ty_generic.

p_table_out = it_generic. "At this point p_table_out should be exactly like it_generic, but it's not working

" this way =(

Hope you help me with this.

Thanks.

Edited by: marco hernandez on Sep 17, 2008 5:00 PM

5 REPLIES 5

Former Member
0 Kudos

something like this.


data: l_ref type ref to data.
field-symbols <fs> type table.

create data l_ref like it_generic.
assign l_ref->* to <fs>.

0 Kudos

>

> something like this.

>

>


> data: l_ref type ref to data.
> field-symbols <fs> type table.
> 
> create data l_ref like it_generic.
> assign l_ref->* to <fs>.
> 

>

> something like this.

>

>


> data: l_ref type ref to data.
> field-symbols <fs> type table.
> 
> create data l_ref like it_generic.
> assign l_ref->* to <fs>.
> 

Ok now i have another problem.

p_table_out is a CHANGING parameter in a Method. task is a public attribute in the class. This is the code:

Private Section.

methods assign_structure
    changing
      p_table_out type table .


Method assign_structure.
 Case me->task.

   when '01'.
     types: begin of ty_generic,
                  matnr type matnr,
                  fkimg type fkimg,
                  meins type meins,
                end of ty_generic.

    data: it_generic type table of ty_generic.

    p_table_out = it_generic
 endcase.

Endmethod.

As you can see, if a have another value in the case statement, the parameter should have a different structure. I don't know if i can declare field-symbols as parameters in a method =S

Former Member
0 Kudos

Ignore...my reply

JozsefSzikszai
Active Contributor
0 Kudos

hi,

you have to define the second internal table, like the first one:

types: begin of ty_generic,
matnr type matnr,
fkimg type fkimg,
meins type meins,
end of ty_generic.

data: it_generic type table of ty_generic.

data: p_table_out table of ty_generic.
OR
data: p_table_out LIKE it_generic.

hope this helps

ec

former_member1033672
Participant
0 Kudos

Do it this way

* CREATE STRUCTURE
FIELD-SYMBOLS: <fs_details> TYPE abap_compdescr.

  DATA : gt_details TYPE abap_compdescr_tab.

  DATA : ref_table_des TYPE REF TO cl_abap_structdescr.


* get structure
  ref_table_des ?= cl_abap_typedescr=>describe_by_name( 'Z_STRUCTURE' ).

  gt_details[] = ref_table_des->components[].

  LOOP AT gt_details ASSIGNING <fs_details>.
    CLEAR wa_fieldcat.
    wa_fieldcat-fieldname = <fs_details>-name .
    wa_fieldcat-datatype = <fs_details>-type_kind.
    wa_fieldcat-inttype = <fs_details>-type_kind.
    wa_fieldcat-intlen = <fs_details>-length.
    wa_fieldcat-decimals = <fs_details>-decimals.
    APPEND wa_fieldcat TO gt_fieldcat.
  ENDLOOP.
  UNASSIGN <fs_details>.


* create dynamic internal table and assign to fs
  CALL METHOD cl_alv_table_create=>create_dynamic_table
               EXPORTING
                  it_fieldcatalog = gt_fieldcat[]
               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>.

Edited by: Filip Kouba on Sep 17, 2008 5:10 PM