在SAP ABAP中创建具有动态变量类型的变量
您可以使用与RTTS相关的API来创建一个标准表(例如RANGE),该表具有类似“ LOW”,“ HIGH”,“ EQ”和“ OPTION”的组件
data:rr_data type ref to data,
rt_range_string type range of string,
rs_range_string like line of rt_range_string,
rt_component type abap_component_tab,
rs_component type line of abap_component_tab,
rt_range_components type abap_component_tab,
ro_struc_descr type ref to cl_abap_structdescr,
ro_table_descr type ref to cl_abap_tabledescr,
ro_data_descr type ref to cl_abap_datadescr.
场符号
<var_value> type any,<rt_range_type> type standard table, //<rt_range_type> is your range table
<rs_range_type> type any.
data(var_type) = 'BU_PARTNER'.
create data rr_data type (var_type).
ro_struc_descr ?= cl_abap_structdescr=>describe_by_data( p_data = rs_range_string ).
rt_component = ro_struc_descr->get_components( ).
ro_data_descr ?= cl_abap_elemdescr=>describe_by_name( var_type ).
rt_range_components = value #( for comp in rt_component (
name = comp-name
type = cond #(
when comp-name eq 'SIGN'
or comp-name eq 'OPTION'
then comp-type
else ro_data_descr )
) ).
ro_struc_descr ?= cl_abap_structdescr=>create( rt_range_components ).
ro_table_descr ?= cl_abap_tabledescr=>create( ro_struc_descr ).
create data rr_data type handle ro_table_descr.
assign rr_data->* to <rt_range_type>.
create data rr_data like line of <rt_range_type>.
assign rr_data->* to <rs_range_type>.
assign component 'SIGN' of structure <rs_range_type> to <var_value>.
<var_value> = 'I'.
assign component 'OPTION' of structure <rs_range_type> to <var_value>.
<var_value> = 'EQ'.
assign component 'LOW' of structure <rs_range_type> to <var_value>.
<var_value> = 'X1'.
assign component 'HIGH' of structure <rs_range_type> to <var_value>.
<var_value> = 'X2'.
以上是 在SAP ABAP中创建具有动态变量类型的变量 的全部内容, 来源链接: utcz.com/z/358239.html