如何为字段指定具有特定索引的值。 或者如果该字段不是初始值,我想更改此索引的值 示例:
TYPES : BEGIN OF itab,
number1 type n,
endof itab.
lv_tabix = sy-tabix.
itab-number1 index lv-tabix = '1'.
答案 0 :(得分:2)
检查句子MODIFY(itab)的帮助: https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abapmodify_itab_single.htm
DATA: workarea TYPE your_type.
workarea-field = value.
"modifying for an index
MODIFY your_table INDEX your_index FROM workarea TRANSPORTING field.
"modifying for a condition
MODIFY your_table FROM workarea TRANSPORTING field WHERE your_condition.
或者你可以使用FIELD-SYMBOLS,就像Anton在我之前所指出的那样。
答案 1 :(得分:2)
如果您使用的是最近的ABAP版本,请使用table expressions:
TRY.
itab[ lv-tabix ]-number1 = '1'.
CATCH cx_sy_itab_line_not_found INTO DATA(exc).
cl_demo_output=>display( exc->get_text( ) ).
ENDTRY.
答案 2 :(得分:1)
您应该按索引读取表并首先将目标行分配给字段符号:
READ TABLE {your itab} INDEX lv_tabix ASSIGNING FIELD-SYMBOL(<fs>).
<fs>-number1 = '1'.
根据您的服务器版本,可能需要单独的字段符号声明:
FIELD-SYMBOLS <fs> TYPE {your table line type}
检查READ TABLE在线帮助https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abapread_table_outdesc.htm#!ABAP_ALTERNATIVE_2@2@
答案 3 :(得分:0)
此?
TYPES: begin OF ty_itab,
number1 TYPE n,
END OF ty_itab.
DATA: itab TYPE TABLE OF ty_itab,
wa_itab like line of itab,
lv_tabix TYPE sy-tabix.
APPEND wa_itab TO itab.
lv_tabix = sy-tabix.
READ TABLE itab INTO wa_itab INDEX lv_tabix.
wa_itab-number1 = '1'.
MODIFY itab FROM wa_itab INDEX lv_tabix.
BREAK-POINT.