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

Expand internal table at runtime

Former Member
0 Likes
1,802

Hello guys,

i have a problem with my internal table.

i create a dynamical internal table with:

CREATE DATA lt_object1 TYPE STANDARD TABLE OF ('VBAK').
   ASSIGN lt_object1->* TO <gt_object>.


This works fine. but after this statement i have a fixed structure of the table VBAK. i have to add an another column to my internal table, because i need the field input_style TYPE lvc_t_styl, for my ALV-GRID.


I tried also to create the dynamical table with the CALL METHOD cl_alv_table_create=>create_dynamic_table, but then i get a issue with the widht of my internal table, compared to the real table.


does anyone have a solution for this?


best regards

Hello guys,

i have a problem with my internal table.

i create a dynamical internal table with:

CREATE DATA lt_object1 TYPE STANDARD TABLE OF ('VBAK').
   ASSIGN lt_object1->* TO <gt_object>.


This works fine. but after this statement i have a fixed structure of the table VBAK. i have to add an another column to my internal table, because i need the field input_style TYPE lvc_t_styl, for my ALV-GRID.


I tried also to create the dynamical table with the CALL METHOD cl_alv_table_create=>create_dynamic_table, but then i get a issue with the widht of my internal table, compared to the real table.


does anyone have a solution for this?


best regards

6 REPLIES 6
Read only

Former Member
0 Likes
1,635

Hi,

for LVC_T_STYL is a table type and not a simple column I don't know, if this is possible for a dynamic internal table. Maybe this is not supported.

Regards,

Klaus

Read only

0 Likes
1,635

hi,

thanks i used LVC_T_STYL in a another programm. but there i had to handle this only for one fixed table not for more tables.

so i dont know how to expand my internal table.

Read only

0 Likes
1,635

Hi,

maybe class CL_ABAP_TABLEDESCR may solve your issue, but I have no experience with it.

Regards,

Klaus

Read only

former_member192842
Participant
0 Likes
1,635
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
1,635

Hello,

First-of-all a very unique name

Anyway the RTTS classes are very intuitive and you can think of creating the components of a runtime structure similar to creating a static structure.

The algorithm is as follows -

  1. Get the components(read: fields) from the data reference you have created earlier.
  2. Add the component, type LVC_T_STYL, to the table from (1).
  3. Get the RTTC instance of the table using the component table from (2).
  4. Create the data reference using the RTTC handle from (3).

So you can try this code snippet

  1. DATA dref_tab TYPE REF TO data.
  2. CREATE DATA dref_tab TYPE STANDARD TABLE OF ('SFLIGHT').
  3. ASSIGN dref_tab->* TO FIELD-SYMBOL(<tab>).
  4. * Get the fields from the data reference
  5. DATA(comp_tab) =
  6. CAST cl_abap_structdescr(
  7.      CAST cl_abap_tabledescr(
  8.           cl_abap_typedescr=>describe_by_data_ref( dref_tab )
  9.           )->get_table_line_type( )
  10.      )->get_components( ).
  11. * Add the field for the "Style" element
  12. DATA component TYPE abap_componentdescr.
  13. component-name = `STYLE`.
  14. component-type
  15. = CAST cl_abap_tabledescr(
  16.        cl_abap_typedescr=>describe_by_name( 'LVC_T_STYL' )
  17.        ).
  18. APPEND component TO comp_tab.
  19. TRY .
  20.     DATA(oref_rttc_tab) =
  21.     cl_abap_tabledescr=>get( cl_abap_structdescr=>get( comp_tab ) ).
  22.   CATCH ##no_handler
  23.         cx_sy_struct_creation
  24.         cx_sy_table_creation.
  25. ENDTRY.
  26. DATA dref_tab_alv TYPE REF TO data.
  27. CREATE DATA dref_tab_alv TYPE HANDLE oref_rttc_tab.
  28. UNASSIGN <tab>.
  29. ASSIGN dref_tab_alv->* TO <tab>.

BR,

Suhas

PS - Please excuse me i can't stop loving ABAP 740

Read only

0 Likes
1,635

We have to have a small discussion about intuitive, but.... For me it worked out perfectly