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: 

ABAP Descriptor Classes for Dynamic Local Declarations

Former Member
0 Kudos

Hi Friednds,

I need to create Local Internal table in my program. I had initially used cl_alv_table_create=>create_dynamic_table for my table creation. But due to a limitation I canot use this.

Someone told me I can use Descriptor Classes for this.

But I dont know how to use it to create the local table..

I am having all the fieldnames and their Types at present in my program. How do I call these classes to crete my Local Tables and Structures.

Regards,

Arunava

9 REPLIES 9

Former Member
0 Kudos

Hi Arunava,

You can use the class CL_ABAP_TABLEDESCR to do this:

1. If you need don't have the row type available first create the row type by filling a table of components (type comp_tab) and create the type using class CL_ABAP_STRUCTDESCR.

2. Then create the table like:

zz_tabletype = cl_abap_tabledescr=>create(

p_line_type = <type of the row>

p_table_kind = (e.g. cl_abap_tablesdescr=>tablekind_sorted)

p_key = <key>)

3. Then CREATE DATA dref TYPE HANdle zz_tabletype.

4. And finally assign a the created table to a field symbol for further processing: ASSIGN dref->* to <table>.

Regards,

John.

0 Kudos

Hi John

May the requirement be fulfilled just using generic data decleration, i.e. <i>xxx TYPE REF TO DATA .</i> and casting i.e. <i>CREATE DATA xxx CASTING LIKE yyy .</i>?

*--Serdar

0 Kudos

Hi John,

Thanks for your help...but I am not able to create the row type by filling each compoent...

Can you please help with regards to the data element type for filling the row type of the table.

I cant find the type (comp_tab) that you have mentioned.This element is in which class.

Thanks and Regards,

Arunava

0 Kudos

Hi Arunava,

Check class CL_ABAP_STRUCTDESCR, you will find type COMPONENT_TABLE there.

So you can defines this table in your program like:

DATA:

COMP_TAB type CL_ABAP_STRUCTDESCR=>component_table.

To fill the component table you can use the following example (adding component of table VBAK):

DATA:

comp_tab TYPE cl_abap_structdescr=>component_table

comp_line LIKE LINE OF comp_tab,

new_linetype TYPE REF TO cl_abap_structdescr,

tab_key TYPE abap_keydescr_tab,

vbak_type TYPE REF TO cl_abap_structdescr.

vbak_type ?= cl_abap_typedescr=>describe_by_name('VBAK')

comp_tab = vbak_type->get_Components( ).

read table comp_tab

with key name = 'VBELN'

into comp_line.

append comp_line to comp_tab.

.

. (for each component you need)

.

.

new_linetype = cl_abap_structdescr=>create( comp_tab ).

zz_tabletype = cl_abap_tabledescr=>create(

p_line_type = new_linetype.

p_table_kind = cl_abap_tablesdescr=>tablekind_sorted

p_key = tab_key)

Hope this helps?

John.

0 Kudos

Hi Serdar,

I don't know the addition CASTING LIKE, but that could do the job. However I'm currently with a customer on a prehistorical SAP release (4.6C....), so I can't test this at the moment.

Regards,

John.

Former Member
0 Kudos

Hi John,

Thanks for your input...At present I am in WAS 6.2 ..and dont find the creet and other methods you have mentioned...I think they all exist for WAS 6.4.

Pls correct if I am wrong..

Arunava

0 Kudos

Hi Arunava,

I'm sorry, the functionality is available as of 6.4.

Regards,

John.

0 Kudos

For 620 type creation is only possible by creating a subroutine-pool/program with the intended type. The number of subroutine-pool is limited ( 7 ? ).

Since the Cl_Alv_Table_Create Class is based on the technique I assume this is the limitation you mention in your first post.

This limitation applies to the internal mode. Maybe you can use a submit or RFC call to act on this types. This would soften up this limitation to one execution of your logic.

If you need more types within one execution doing the subroutine-generation manually with several types might help.

Kind Regards

Klaus

0 Kudos

Hi Arunava

I am not sure that I have exactly understand your requirement but will this information help? I guess it will be OK in case you have definite structure name in the ABAP dictionary or in the program. Otherwise, if you are talking about creating a table type where you never guess before runtime I think previos post will be closer to you solution.


*-- Generic variable
DATA gr_xxx TYPE REF TO DATA .
*-- Variable to hold name of the structure for casting
DATA gv_str_name(30) TYPE c .
*-- Variable to hold each component name of the structure
DATA gv_comp_name(30) TYPE c .
*-- Field symbol to get reference of the structure
FIELD-SYMBOLS: <fs> TYPE ANY .
*-- Field symbol to get reference of the component
FIELD-SYMBOLS: <comp> TYPE ANY .

*--Creating variable
CREATE DATA gr_xxx LIKE (gv_str_name) .
*--or CREATE DATA gr_xxx TYPE (gv_str_name) .

ASSIGN gr_xxx->* TO <fs> CASTING LIKE (gv_str_name) .
*--or ASSIGN gr_xxx->* TO <fs> CASTING LIKE (gv_str_name) .

.. ..

*--To reach each component
ASSIGN COMPONENT (gv_compname) OF STRUCTURE <fs> TO <comp> .
.. ..

*--Serdar