2007 Jan 30 11:23 AM
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!
2007 Jan 30 11:30 AM
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
2007 Jan 30 11:26 AM
trying using cl_abap_typedescr=>DESCRIBE_BY_OBJECT_REF or DESCRIBE_BY_OBJECT_REF=>DESCRIBE_BY_DATA_REF
2007 Jan 30 11:30 AM
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
2007 Jan 30 11:52 AM
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?
2007 Jan 30 12:04 PM
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
2007 May 24 8:44 AM
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.