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: 

Need Dynamic declaration of a Structure in TYPES

Former Member
0 Kudos

Hi Guys,

I have a selection screen with input as TABLE.


TYPES: BEGIN OF ty_dyn.
        INCLUDE STRUCTURE (Selection-Screen Table).
TYPES: END OF ty_dyn.

My requirement is if I enter the Table name as KNA1 in Selection Screen,My Include structure should be KNA1.

What should I do?

Thanks,

Prasad.

1 ACCEPTED SOLUTION

naimesh_patel
Active Contributor
0 Kudos

You need to use the RTTS - Run Time Type Services to get your type created at runtime.

Check this: http://help-abap.blogspot.com/2008/09/dynamic-internal-table-creation.htm

Regards,

Naimesh Patel

8 REPLIES 8

naimesh_patel
Active Contributor
0 Kudos

You need to use the RTTS - Run Time Type Services to get your type created at runtime.

Check this: http://help-abap.blogspot.com/2008/09/dynamic-internal-table-creation.htm

Regards,

Naimesh Patel

0 Kudos

Hi Patel,

This is about creation of Dynamic ITAB.

I want Dynamic Structure.

Thanks,

prasad.

Edited by: Dheeru Prasad on Jun 17, 2009 10:52 PM

0 Kudos

If you are on a newer release, you can use the RTTS to create an internal table and work area dynamically. You should not try to be create dynamic TYPE statements.

data: lo_dataref type ref to data.

PARAMETERS: p_table type char20.

FIELD-SYMBOLS: <lt_tab> type table.
FIELD-SYMBOLS: <ls_tab> type any.

*Create an internal table
create data lo_dataref type table of (p_table).
ASSIGN lo_dataref->* to <lt_tab>.

*create a work area
create data lo_dataref like line of <lt_tab>.
ASSIGN lo_dataref->* to <ls_tab>.

Regards,

Rich Heilman

0 Kudos

So if you just want a structure(or work area) then you can do this. <LS_TAB> would be your dynamic structure

data: lo_dataref type ref to data.

PARAMETERS: p_table type char20.

FIELD-SYMBOLS: <ls_tab> type any.


*create a work area
create data lo_dataref type (p_table).
ASSIGN lo_dataref->* to <ls_tab>.

Regards

Rich Heilman

0 Kudos

Hi Rich,

Thanks for your help.

How can I assign another table field values to this work area.

I mean

<ls_tab>-kunnr = kna1-kunnr.

When I am declaring this I am getting error like


The data object <ls_tab> has no structure and there fore
has no component called kunnr

Can you explain it.

Thanks,

Prasad.

0 Kudos

So since we are creating the work area at runtime, it does not know what KUNNR is, so you must assign at runtime like this.

field-symbols: <lv_field> type any.


assign component 'KUNNR' of structure <ls_tab> to <lv_field>.
if sy-subrc = 0.
<lv_field>. = kna1-kunnr.
endif.

Regards,

Rich Heilman

0 Kudos

Hi Rich,

Actually it will not be kunnr.

It will be fields of any table which is coming from selection field.

so how to map all the fields of that Dynamic table to our created dynamic <ls_tab>.

Thanks,

Prasad.

0 Kudos

Rich,

Thanks a lot.

I got that resolved.

I need a small advise from you.

Where to get a good documentation of this classes & objects how to declare objects like itabs and workarea some thing like this stuff.

Thanks,

Prasad.