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

Create Dynamic Tables!!!

Former Member
0 Likes
3,459

Hello Experts,

i will create dynamic a table but there is a Problem with the type "ABAP_COMPONENT_TAB", he said that it is not exist.

Can anyone help me??

TYPE-POOLS: abap.

DATA: obj_table1 TYPE REF TO cl_abap_tabledescr,

obj_table2 TYPE REF TO cl_abap_tabledescr.

DATA: obj_struc1 TYPE REF TO cl_abap_structdescr,

obj_struc2 TYPE REF TO cl_abap_structdescr.

DATA: lt_component TYPE abap_component_tab,

wa_component TYPE abap_componentdescr.

DATA: obj_data1 TYPE REF TO data,

obj_data2 TYPE REF TO data.

FIELD-SYMBOLS: <table1> TYPE ANY TABLE,

<table2> TYPE ANY TABLE.

CLEAR wa_component.

wa_component-name = 'STREET'.

wa_component-type ?= cl_abap_typedescr=>describe_by_name( 'STRING' ).

INSERT wa_component INTO TABLE lt_component.

CLEAR wa_component.

wa_component-name = 'POST_CODE'.

wa_component-type ?= cl_abap_typedescr=>describe_by_name( 'STRING' ).

INSERT wa_component INTO TABLE lt_component.

CLEAR wa_component.

wa_component-name = 'CITY1'.

wa_component-type ?= cl_abap_typedescr=>describe_by_name( 'STRING' ).

INSERT wa_component INTO TABLE lt_component.

obj_struc1 = cl_abap_structdescr=>create( lt_component ).

*TRY.

CALL METHOD cl_abap_tabledescr=>create

EXPORTING

p_line_type = obj_struc1

  • p_table_kind = TABLEKIND_STD

  • p_unique = ABAP_FALSE

  • p_key =

  • p_key_kind = KEYDEFKIND_DEFAULT

RECEIVING

p_result = obj_table1.

  • CATCH cx_sy_table_creation .

*ENDTRY.

REFRESH: lt_component.

CREATE DATA obj_data1 TYPE HANDLE obj_table1.

ASSIGN obj_data1->* TO <table1>.

CLEAR wa_component.

wa_component-name = 'PARTNER'.

wa_component-type ?= cl_abap_typedescr=>describe_by_name( 'STRING' ).

INSERT wa_component INTO TABLE lt_component.

CLEAR wa_component.

wa_component-name = 'NAME_ORG1'.

wa_component-type ?= cl_abap_typedescr=>describe_by_name( 'STRING' ).

INSERT wa_component INTO TABLE lt_component.

CLEAR wa_component.

wa_component-name = 'NAME_ORG2'.

wa_component-type ?= cl_abap_typedescr=>describe_by_name( 'STRING' ).

INSERT wa_component INTO TABLE lt_component.

CLEAR wa_component.

wa_component-name = 'ADDR_TABLE'.

wa_component-type ?= cl_abap_typedescr=>describe_by_data( <table1> ).

INSERT wa_component INTO TABLE lt_component.

obj_struc2 = cl_abap_structdescr=>create( lt_component ).

*TRY.

CALL METHOD cl_abap_tabledescr=>create

EXPORTING

p_line_type = obj_struc2

  • p_table_kind = TABLEKIND_STD

  • p_unique = ABAP_FALSE

  • p_key =

  • p_key_kind = KEYDEFKIND_DEFAULT

RECEIVING

p_result = obj_table2.

  • CATCH cx_sy_table_creation .

*ENDTRY.

REFRESH: lt_component.

CREATE DATA obj_data2 TYPE HANDLE obj_table2.

ASSIGN obj_data2->* TO <table2>.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,017

Hi,


i will create dynamic a table but there is a Problem with the type "ABAP_COMPONENT_TAB", he said that it is not exist.

Who said ? If you are getting the syntax then try to see the Types -Pools ABAP where you have table defined there or not with name ABAP_COMPONENT_TAB. If not then declare the component table using the structure "abap_componentdescr".

Let me know if this works for you.

Regards,

SRinivas

11 REPLIES 11
Read only

Former Member
0 Likes
2,017

Hi,

Check if abap_component_tab exists in TYPE-POOLS: abap.

This did not give any errors for me.

Regards,

Srini.

Read only

Former Member
0 Likes
2,018

Hi,


i will create dynamic a table but there is a Problem with the type "ABAP_COMPONENT_TAB", he said that it is not exist.

Who said ? If you are getting the syntax then try to see the Types -Pools ABAP where you have table defined there or not with name ABAP_COMPONENT_TAB. If not then declare the component table using the structure "abap_componentdescr".

Let me know if this works for you.

Regards,

SRinivas

Read only

0 Likes
2,017

Thanks i have checked and have corrected.

But now there is another Error, the Methode Create is not common .

I think the name is maybe different??

CALL METHOD cl_abap_tabledescr=>create

EXPORTING

p_line_type = obj_struc1

  • p_table_kind = TABLEKIND_STD

  • p_unique = ABAP_FALSE

  • p_key =

  • p_key_kind = KEYDEFKIND_DEFAULT

RECEIVING

p_result = obj_table1.

Read only

0 Likes
2,017

Hi,

There are several techniques for creating dynamic tables.

Always you can choose different method ...


CALL METHOD cl_alv_table_create=>create_dynamic_table
     EXPORTING
            it_fieldcatalog           = lt_fieldcat
     IMPORTING
            ep_table                  = lt_dyn_table
     EXCEPTIONS
            generate_subpool_dir_full = 1
            OTHERS                    = 2.

Read only

0 Likes
2,017

Hi,

the Method (CL_ABAP_STRUCTDESCR=>create) is Static and Protected.

With wich Method can I get a structure of my internal Table "database"???

Read only

0 Likes
2,017

... but never use cl_alv_table_create=>create_dynamic_table

because this method will do an unwanted database COMMIT.

like this, roughly:

METHOD create_data.
    DATA:
      lo_structdescr         TYPE REF TO cl_abap_structdescr,
      lo_typedescr           TYPE REF TO cl_abap_typedescr,
      lo_tabledescr          TYPE REF TO cl_abap_tabledescr,
      lt_lvc_scol            TYPE lvc_t_scol,
      lt_lvc_styl            TYPE lvc_t_styl,
      lt_comp_all            TYPE cl_abap_structdescr=>component_table.
    FIELD-SYMBOLS:
      <component>            TYPE LINE OF abap_component_tab.

    APPEND INITIAL LINE TO lt_comp_all ASSIGNING <component>.
    <component>-type ?= cl_abap_datadescr=>describe_by_data( lt_lvc_styl ).
    <component>-name = lc_fieldname_t_styl.

    APPEND INITIAL LINE TO lt_comp_all ASSIGNING <component>.
    <component>-type ?= cl_abap_datadescr=>describe_by_data( lt_lvc_scol ).
    <component>-name = lc_fieldname_t_color.

* create structure description
    lo_structdescr = cl_abap_structdescr=>create( lt_comp_all ).

* create table description for structure
    lo_tabledescr = cl_abap_tabledescr=>create(
                    p_line_type  = lo_structdescr
                    p_table_kind = cl_abap_tabledescr=>tablekind_std
                    p_unique     = abap_false ).

* create data object
    CREATE DATA rr_dispodata TYPE HANDLE lo_tabledescr.

  ENDMETHOD.

Regards,

Clemens

Read only

0 Likes
2,017

Hello Clemens,

thanks for youuuu excellent help and i have understand it, BUT int the table cl_abap_structdescr i cant find the method CREATE.

What is the reason for this Problem??

Read only

0 Likes
2,017

?? What SAP release are you working with? These classes have been enhanced a couple of times.

We have methods

LOAD_CLASS
CLASS_CONSTRUCTOR
GET_COMPONENT_TYPE
GET_DDIC_FIELD_LIST
CREATE
GET_COMPONENTS
GET_INCLUDED_VIEW
GET_SYMBOLS
CREATE_STRUCTDESCR_OBJECT
XTYP_TO_STRUC_DESC
CREATE_XTYP_FROM_STRUC_DESC

in ECC600, ABA_701.

Regards,

Clemens

Read only

0 Likes
2,017

Hi,

many sorry to all helps.

It was my stupid mistake, i work in Release 4.7 and there is missing the Method.

The other alternativ is there to create a structure over ALV.

Many thanks again for your helps.

Read only

0 Likes
2,017

Hi,

what did I do when the new RTTS runtime time type services where not available?

Create and use a dictionary structure with all fields ever used. Then in field catalog, set all unused fields as TECH = 'X'.

Regards,

Clemens

Read only

Former Member
0 Likes
2,017

Hi,

    Can anybody please tell me the purpose of P_KEY_KIND parameter in

     "cl_abap_tabledescr=>create" method.

I found that there is 3 different key kinds are 'KEYDEFKIND_DEFAULT' , 'KEYDEFKIND_USER'  and 'KEYDEFKIND_TABLELINE'. What is the purpose of these key kinds.

Thanks in advance,

Regards,

Venkat