问题描述
任务是使用动态 name 创建变量.不是打字,而是名字!
向我提出的所有方法(例如通过cl_abap_typedescr
和cl_abap_elemdescr
类)都是无用的.我想在语义上实现类似这样的东西,但是这种语法是不正确的:
The task is to create variable with dynamic name. Not type, but name!
All the ways proposed to me (e.g. via cl_abap_typedescr
and cl_abap_elemdescr
classes) were useless.
I want to implement semantically something like this, but this syntax is incorrect:
CREATE DATA (name) TYPE var_type.
有什么解决办法吗?
推荐答案
我认为,如果将'name'声明为字段符号,它将起作用.
I think if 'name' was declared as a field-symbol it would work.
效果该语句声明了一个名为的符号字段.在运行时,您可以使用ASSIGN将具体字段分配给字段符号.然后,使用字段符号执行的所有操作都会直接影响为其分配的字段.
EffectThis statement declares a symbolic field called . At runtime, you can assign a concrete field to the field symbol using ASSIGN. All operations performed with the field symbol then directly affect the field assigned to it.
尝试一下:
data:
b_1 type i,
b_2 type i,
b_3 type i,
b_4 type i,
num1(1) type n,
fldname type fieldname.
FIELD-SYMBOLS:
<fld> type i.
do 4 times.
num1 = sy-index.
CONCATENATE 'B_' num1 into fldname.
ASSIGN (fldname) to <fld>.
<fld> = sy-index.
enddo.
write: b_1, b_2, b_3, b_4.
这篇关于动态声明变量名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!