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: 

append new field after call cl_abap_typedescr=>describe_by_name( tabname )

Former Member
0 Kudos
570

Dears :

i use cl_abap_typedescr=>describe_by_name( tabname ) to create a new structure type. The parameter tabname could be 'MARA' .

and now i want to append a new field such as 'ZTEST' to this structure, is this possible ?

ths in advance!

1 ACCEPTED SOLUTION

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Kudos
254

Hi,

This is possible, Use get_components method to get the list of components

Then once yout get this list add one more component to this list.

Then use this list to create your strucutre using the method create.

See the below code.

DATA: lr_rtti_struc TYPE REF TO cl_abap_structdescr.

DATA: lt_comp TYPE cl_abap_structdescr=>component_table.

DATA: ls_comp LIKE LINE OF lt_comp.

lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( wa_data ).

lt_comp = lr_rtti_struc->get_components( ).

LOOP AT it_elements INTO wa_element.

ls_comp-name = wa_element.

ls_comp-type = cl_abap_elemdescr=>get_string( ).

APPEND ls_comp TO lt_comp.

ENDLOOP.

CALL METHOD cl_abap_structdescr=>create

EXPORTING

p_components = lt_comp

p_strict = abap_false

RECEIVING

p_result = lr_rtti_struc.

Regards,

Sesh

Message was edited by:

Seshatalpasai Madala

5 REPLIES 5

Former Member
0 Kudos
254

trying using cl_abap_typedescr=>DESCRIBE_BY_OBJECT_REF or DESCRIBE_BY_OBJECT_REF=>DESCRIBE_BY_DATA_REF

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Kudos
255

Hi,

This is possible, Use get_components method to get the list of components

Then once yout get this list add one more component to this list.

Then use this list to create your strucutre using the method create.

See the below code.

DATA: lr_rtti_struc TYPE REF TO cl_abap_structdescr.

DATA: lt_comp TYPE cl_abap_structdescr=>component_table.

DATA: ls_comp LIKE LINE OF lt_comp.

lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( wa_data ).

lt_comp = lr_rtti_struc->get_components( ).

LOOP AT it_elements INTO wa_element.

ls_comp-name = wa_element.

ls_comp-type = cl_abap_elemdescr=>get_string( ).

APPEND ls_comp TO lt_comp.

ENDLOOP.

CALL METHOD cl_abap_structdescr=>create

EXPORTING

p_components = lt_comp

p_strict = abap_false

RECEIVING

p_result = lr_rtti_struc.

Regards,

Sesh

Message was edited by:

Seshatalpasai Madala

0 Kudos
254

Dear Seshatalpasai :

I have tried your way and that is ok.

And another thinking, could i insert this new field as the first field or other order ?

It seems system will gernerate the element in order after call method get_components( ).

Any advice?

0 Kudos
254

HI,

Its based on your requirement. If you need this field as the first field try using INSERT AT INDEX 1. APPEND any way puts it at the end if you are perticular at some other index then use INSERT AT INDEX n. Once you got the list of components what you have is an internal table of elements. I think you should be able to play with this internal table and insert your new field at any position since this internal table is of type STANDARD table.

Regards,

Sesh

0 Kudos
254

Hi

I have a similar requirement. Along with creating an extra field i also would like to copy the data that was available in one of the coulmn to this newly created column.

Upto creating a column is fine. How would I read the data from any other column and put it in this column.

Pls Suggest.

Thank You,

Suresh.