Hi All,
I'm trying to create a data with a type setted dynamically.
I have 2 parameters : an internal table (p_reference) and the name (colonne, as a string) of one of its columns.
My code doesnt work because the instruction : "create data: ty_type type (desired_type)"
wont accept these desired_type :
- P(8) DECIMALS 3
- P8
It can only accept 'P'
Can I set the length and the decimals later Or should I change something else to make this code work ?
Thanks a lot,
Jessie
FIELD-SYMBOLS <table_reference> TYPE STANDARD TABLE.
ASSIGN p_reference TO <table_reference>.
FIELD-SYMBOLS <table_reference_fields> TYPE ANY.
DATA gs_fldname TYPE REF TO data.
CREATE DATA gs_fldname LIKE LINE OF <table_reference>.
ASSIGN gs_fldname->* TO <table_reference_fields>.
FIELD-SYMBOLS <lfs_comp_wa> TYPE abap_compdescr.
l_descr_ref ?= cl_abap_typedescr=>describe_by_data( <table_reference_fields> ).
LOOP AT l_descr_ref->components[] ASSIGNING <lfs_comp_wa>.
IF <lfs_comp_wa>-name = colonne.
exit.
endif.
endloop.
data desired_type type string.
" This CONCATENATE dont work but this is just an example
concatenate <lfs_comp_wa>-type_kind
<lfs_comp_wa>-length
' DECIMALS '
<lfs_comp_wa>-decimals
into desired_type.
data: ty_type type ref to data .
field-SYMBOLS <fs_data> type any .
create data: ty_type type (desired_type) . " crash :(
ASSIGN: ty_type->* TO <fs_data> .