类型为ANY的字段符号中的类型为ANY TABLE的MODIFY TABLE

时间:2018-12-13 07:55:01

标签: sap abap

我有一个类型为“ any table”的通用表,并且我试图通过这种方式在其中修改一些条目:

  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
  
  
  <div class="container-fluid">
  <div class="row">
    <div class="col-sm" style="background-color:lavender;">.col-sm-4</div>
    <div class="col-sm" style="background-color:lavenderblush;">.col-sm-4</div>
    <div class="col-sm" style="background-color:lavender;">.col-sm-4</div>
  </div>
</div>

Field-Symbols的类型均为“ any”。

这段代码中的所有内容都可以正常运行,但是在此行之后:

  LOOP AT ct_data INTO <fs_data>.
    ASSIGN COMPONENT 'KEY' OF STRUCTURE <fs_data> TO <fs_feld_fu_key>.
    IF <fs_feld_fu_key> IS ASSIGNED.
      IF <fs_feld_fu_key> = <fs_mci_items>-parent_key.
        ASSIGN COMPONENT 'ZZ_CHANGED_FIELD' OF STRUCTURE <fs_data>  TO <fs_feld_walzzyk>.
        IF <fs_feld_walzzyk> IS ASSIGNED.
          <fs_feld_walzzyk> = <fs_mci_items>-zz_changed_field.
          MODIFY TABLE ct_data FROM <fs_data>.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDLOOP.

我得到SY_SUBRC = 4,该表将不会被修改。有人有什么想法或提示吗?在这种情况下我怎么了?

完整代码:

MODIFY TABLE ct_data FROM <fs_data>.

2 个答案:

答案 0 :(得分:3)

<fs_data>不指向ct_data。它指向您在开始时创建的新存储区。删除它并声明内联字段符号以获取指向实际输出的指针:

DATA: rt_data TYPE REF TO data,
      ls_key  TYPE /bobf/s_frw_key,
      lt_key  TYPE /bobf/t_frw_key.
FIELD-SYMBOLS: <fs_feld_fu_key>  TYPE any,
               <fs_feld_walzzyk> TYPE any.


IF <fs_data> IS ASSIGNED.
  LOOP AT ct_data ASSIGNING FIELD-SYMBOL(<fs_data>).
    ASSIGN COMPONENT 'fu_key' OF STRUCTURE <fs_data> TO <fs_feld_fu_key>.
    IF <fs_feld_fu_key> IS ASSIGNED.
      ls_key-key = <fs_feld_fu_key>.
      APPEND ls_key TO lt_key.
    ENDIF.
  ENDLOOP.
ENDIF.


/scmtms/cl_tor_helper_read=>get_tor_data(
  EXPORTING
    it_root_key          = lt_key
  IMPORTING
    et_mci_items         = DATA(lt_mci_items)
).


LOOP AT lt_mci_items ASSIGNING FIELD-SYMBOL(<fs_mci_items>).
  LOOP AT ct_data ASSIGNING <fs_data>.
    ASSIGN COMPONENT 'FU_KEY' OF STRUCTURE <fs_data> TO <fs_feld_fu_key>.
    IF <fs_feld_fu_key> IS ASSIGNED.
      IF <fs_feld_fu_key> = <fs_mci_items>-parent_key.
        ASSIGN COMPONENT 'ZZ_CHANGED_FIELD' OF STRUCTURE <fs_data>  TO <fs_feld_walzzyk>.
        IF <fs_feld_walzzyk> IS ASSIGNED.
          <fs_feld_walzzyk> = <fs_mci_items>-zz_walzzyklus.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDLOOP.
ENDLOOP.

答案 1 :(得分:0)

<fs_data>是指向ct_data中一行的指针。您正在尝试从自身修改表。 sy-subrc = 4只是声明没有任何更改。

正如JozsefSzikszai在其评论中指出的那样,您根本不需要MODIFY TABLE。只需直接更改<fs_data>中的值即可。