‎2008 Nov 02 1:43 PM
Hi gurus!
I want to refer on a strucutre, whose components' definitions are available only during runtime.
Example:
The type which i want to refer on should be a structure with one component, which is a CHAR with variable length. (i.e. the VALUE of the component's parameter LENGTH is evaluated during runtime).
Any hints are welcome.
With best regards Jonas
‎2008 Nov 02 3:34 PM
use cl_abap_elemdescr=>get_c( length )
DATA: r_stru TYPE REF TO cl_abap_structdescr,
it_comp TYPE cl_abap_structdescr=>component_table,
r_comp TYPE abap_componentdescr,
r_elem TYPE REF TO cl_abap_elemdescr,
r_data TYPE REF TO data.
DATA: length_of_field TYPE i VALUE 10.
FIELD-SYMBOLS: <fs> TYPE ANY.
START-OF-SELECTION.
r_elem = cl_abap_elemdescr=>get_c( length_of_field ).
r_comp-name = 'FIELD1'.
r_comp-type = r_elem.
append r_comp to it_comp.
r_stru = cl_abap_structdescr=>create( it_comp ).
CREATE DATA r_data TYPE HANDLE r_stru.
ASSIGN r_data->('FIELD1') TO <fs>.
<fs> = 'ABC'.
WRITE: / <fs>.
‎2008 Nov 02 1:55 PM
hi, Jonas Soiné,
i think that following code will help you.
____________________________________
TYPES : BEGIN OF my_type,
char(10) TYPE c,
END OF my_type.
DATA my_type_variable TYPE my_type.
my_type_variable-char = 'asdfas'.
WRITE: my_type_variable-char.
____________________________________
Kind Regards,
Faisal
‎2008 Nov 02 3:23 PM
Hi Jones,
For your requirement you nedd to play with the Field Symbols.
By Field Symbosl you can assign it to strucuture during runtime.
Please see the link below.
http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/field_sy.htm
Thanks,
Chidanand
‎2008 Nov 02 3:34 PM
use cl_abap_elemdescr=>get_c( length )
DATA: r_stru TYPE REF TO cl_abap_structdescr,
it_comp TYPE cl_abap_structdescr=>component_table,
r_comp TYPE abap_componentdescr,
r_elem TYPE REF TO cl_abap_elemdescr,
r_data TYPE REF TO data.
DATA: length_of_field TYPE i VALUE 10.
FIELD-SYMBOLS: <fs> TYPE ANY.
START-OF-SELECTION.
r_elem = cl_abap_elemdescr=>get_c( length_of_field ).
r_comp-name = 'FIELD1'.
r_comp-type = r_elem.
append r_comp to it_comp.
r_stru = cl_abap_structdescr=>create( it_comp ).
CREATE DATA r_data TYPE HANDLE r_stru.
ASSIGN r_data->('FIELD1') TO <fs>.
<fs> = 'ABC'.
WRITE: / <fs>.
‎2008 Nov 09 10:28 AM
Cheers friends!
Somehow the last answer was the closest to solve the problem.
But finally i descided not to use dynamical types due to the fact that i would have had to change the whole programm logic without even knowing wether i would recieve better performance.
Anyway thanks J.Soiné