我有一个<lt_something>
指向表格的字段符号。该表有一行作为内容。我如何将表格中的那一行分配给一个新的字段符号,比如说<ls_something>
?
我试过了 :
READ TABLE <lt_something> INDEX 1 REFERENCE INTO <ls_something>.
但是上面的代码转储,这个问题的正确方法是什么?
我有一个<lt_something>
指向表格的字段符号。该表有一行作为内容。我如何将表格中的那一行分配给一个新的字段符号,比如说<ls_something>
?
我试过了 :
READ TABLE <lt_something> INDEX 1 REFERENCE INTO <ls_something>.
但是上面的代码转储,这个问题的正确方法是什么?
您正在混淆字段符号和数据引用。使用任一
DATA lr_foo TYPE REF TO something.
READ TABLE lt_something INDEX 1 REFERENCE INTO lr_foo.
lr_foo->bar = 'baz'.
或者
FIELD-SYMBOLS <ls_foo> TYPE something.
READ TABLE lt_something INDEX 1 ASSIGNING <ls_foo>.
<ls_foo>-bar = 'baz'.
但不要合并这两种方式。
Are you sure that your field symbol table is assigned before you perform your read? The general structure of your read table looks OK, but you should use ASSIGNING in your read statement:
FIELD-SYMBOLS: <lt_something> TYPE ANY TABLE,
<ls_something> TYPE ANY.
" ... blah blah presume you did some work on <lt_something>...
IF <lt_something> IS ASSIGNED.
READ TABLE <lt_something> INDEX 1 ASSIGNING <ls_something>.
" Check sy-subrc or <ls_something> IS ASSIGNED.
" Do work.
ENDIF.
field-symbol 需要是表格的线型,而不是表格本身。
DATA:
i_vbak type standard table of vbak.
FIELD-SYMBOLS:
<i_vbak> type vbak.
READ TABLE i_vbak ASSIGNING <i_vbak>.