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

Dynamic Internal Table

Former Member
0 Likes
585

Hello all,

I have the below requirement.

Based on certain conditions i am building a dynamic fieldcatalog.The number of columns for the Fieldcatalog are determined.

Ex : Number of columns can be 21 or 39 or 51.

Now my requirement is that i need to fill in these fieldcatalog with the data from my internal table.

How do i create an Internal table having the exact number of columns.I have to use the RTTS classes like

CL_ABAP_TYPEDESCR

CL_ABAP_STRUCTDESCR

I cant use CL_ALV_TABLE_CREATE as it gives a Dump after certain instances.So it doesnt meet my logic.

Kindly suggest.

Regards,

Arun

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
539

Hopefully you are using a newer release of NetWeaver. If so, you can do something like this.

TYPE-POOLS: abap.

DATA:
  lr_structdescr    TYPE REF TO cl_abap_structdescr,
  lr_tabledescr     TYPE REF TO cl_abap_tabledescr,
  lr_datadescr      TYPE REF TO cl_abap_datadescr,
  lt_components     TYPE abap_component_tab,
  ls_component      TYPE LINE OF abap_component_tab,
  lr_wa             TYPE REF TO data,
  lr_tab            TYPE REF TO data.

DATA: lv_index_num(3) TYPE n.
DATA: lv_index_char(3) TYPE c.

FIELD-SYMBOLS: <fs_wa> TYPE ANY.
FIELD-SYMBOLS: <fs_tab> TYPE table.

START-OF-SELECTION.

  DO 20 TIMES.
    lv_index_num = sy-index.
    lv_index_char = lv_index_num.
    CONCATENATE 'value' lv_index_char INTO ls_component-name.
    ls_component-type ?= cl_abap_elemdescr=>get_c( p_length = 10 ).
    INSERT ls_component INTO TABLE lt_components.
  ENDDO.

* get structure descriptor -> lr_STRUCTDESCR
  lr_structdescr ?= cl_abap_structdescr=>create( lt_components ).

* create work area of structure lr_STRUCTDESCR -> lr_WA
  CREATE DATA lr_wa TYPE HANDLE lr_structdescr.
  ASSIGN lr_wa->* TO <fs_wa>.

  lr_datadescr ?= lr_structdescr.
  lr_tabledescr ?= cl_abap_tabledescr=>create( lr_datadescr ).

* Create dynmaic internal table, <FS_TAB> will be your dynamic internal table
  CREATE DATA lr_tab TYPE HANDLE lr_tabledescr.
  ASSIGN lr_tab->* TO <fs_tab>.

2 REPLIES 2
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
540

Hopefully you are using a newer release of NetWeaver. If so, you can do something like this.

TYPE-POOLS: abap.

DATA:
  lr_structdescr    TYPE REF TO cl_abap_structdescr,
  lr_tabledescr     TYPE REF TO cl_abap_tabledescr,
  lr_datadescr      TYPE REF TO cl_abap_datadescr,
  lt_components     TYPE abap_component_tab,
  ls_component      TYPE LINE OF abap_component_tab,
  lr_wa             TYPE REF TO data,
  lr_tab            TYPE REF TO data.

DATA: lv_index_num(3) TYPE n.
DATA: lv_index_char(3) TYPE c.

FIELD-SYMBOLS: <fs_wa> TYPE ANY.
FIELD-SYMBOLS: <fs_tab> TYPE table.

START-OF-SELECTION.

  DO 20 TIMES.
    lv_index_num = sy-index.
    lv_index_char = lv_index_num.
    CONCATENATE 'value' lv_index_char INTO ls_component-name.
    ls_component-type ?= cl_abap_elemdescr=>get_c( p_length = 10 ).
    INSERT ls_component INTO TABLE lt_components.
  ENDDO.

* get structure descriptor -> lr_STRUCTDESCR
  lr_structdescr ?= cl_abap_structdescr=>create( lt_components ).

* create work area of structure lr_STRUCTDESCR -> lr_WA
  CREATE DATA lr_wa TYPE HANDLE lr_structdescr.
  ASSIGN lr_wa->* TO <fs_wa>.

  lr_datadescr ?= lr_structdescr.
  lr_tabledescr ?= cl_abap_tabledescr=>create( lr_datadescr ).

* Create dynmaic internal table, <FS_TAB> will be your dynamic internal table
  CREATE DATA lr_tab TYPE HANDLE lr_tabledescr.
  ASSIGN lr_tab->* TO <fs_tab>.

Read only

0 Likes
539

Hello,

Can you help me with the below issue.I referred ur suggestion for building the Dynamic Internal table.

Issue is :

I have created a Dynamic ALV using RTTS classes like cl_abap_structdescr,cl_abap_tabledescr and cl_abap_datadescr.

The number of columns to be displayed is dynamic and i am able to display the same.

Now i need to perform SUBTOTAL on few of the columns.

In dynamic table how do i assign those columns as Type 'I' so that i can perform DO_SUM.

I used the method GET_I of class cl_abap_elemdescr but unable to achive the same.

Kindly suggest.

Regards,

Arun