Ver Mensaje Individual
  #5  
Viejo 05/11/13, 15:59:45
serdiro serdiro is offline
Junior Member
 
Fecha de Ingreso: ene 2009
Mensajes: 1
Yo lo he solucionado construyendo la tabla dinámica de esta forma :

DATA: gs_comp TYPE abap_componentdescr,
gt_comp TYPE abap_component_tab.

"example table
DATA: BEGIN OF it OCCURS 3, "<- your ITAB1
pernr TYPE persno,
kostl TYPE kostl,
endda TYPE endda,
END OF it.

"data references
DATA: r_type_struct TYPE REF TO cl_abap_structdescr,
r_type_table TYPE REF TO cl_abap_tabledescr,
r_data_tab TYPE REF TO data,
r_data_str TYPE REF TO data.

* 1. ------------- filling example table IT -> i.e your ITAB1
it-pernr = '12345678'.
it-kostl = '0112345678'.
it-endda = sy-datum.
APPEND it.

it-pernr = '45678909'.
it-kostl = '3452345678'.
it-endda = sy-datum - 1.
APPEND it.

* 2. ------------ components structure type
gs_comp-name = 'PERNR'.
gs_comp-type ?= cl_abap_elemdescr=>describe_by_name( 'PERSNO' ).
APPEND gs_comp TO gt_comp.

gs_comp-name = 'KOSTL'.
gs_comp-type ?= cl_abap_elemdescr=>describe_by_name( 'KOSTL' ).
APPEND gs_comp TO gt_comp.

gs_comp-name = 'BEGDA'.
gs_comp-type ?= cl_abap_elemdescr=>describe_by_name( 'BEGDA' ).
APPEND gs_comp TO gt_comp.

* 3. ------------- create structure type
TRY.
r_type_struct = cl_abap_structdescr=>create(
p_components = gt_comp ).
CATCH cx_sy_struct_creation .
ENDTRY.

* 4. ------------- create table type
TRY.
r_type_table = cl_abap_tabledescr=>create( r_type_struct ).

CATCH cx_sy_table_creation .
ENDTRY.

" 5. -------------- create table based on RTTS types
CREATE DATA: r_data_tab TYPE HANDLE r_type_table,
r_data_str TYPE HANDLE r_type_struct.

FIELD-SYMBOLS: <fs_table> TYPE INDEX TABLE, "-> here table must by type INDEX TABLE in order to append to it
<fs_wa> TYPE ANY.

ASSIGN: r_data_tab->* TO <fs_table>,
r_data_str->* TO <fs_wa>. "work area for dynamic table (based on your dynamic structure)

" 6. ---------------- move internal table data (IT) to dynamic table
LOOP AT it.
MOVE-CORRESPONDING it TO <fs_wa>.
APPEND <fs_wa> TO <fs_table>.
ENDLOOP.
Responder Con Cita