1
votes

I have a generic table of type "any table" and I'm trying to modify some entries in there, in this way:

  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.

Field-Symbols are all having the type "any".

Everything in this code woks just fine, BUT after this line:

MODIFY TABLE ct_data FROM <fs_data>.

I get SY_SUBRC = 4 and the table will not be modified. Does anybody have some ideas or tips? What am I doing wrong in this case?

Full code:

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


CREATE DATA rt_data LIKE LINE OF ct_data.
ASSIGN rt_data->* TO <fs_data>.

IF <fs_data> IS ASSIGNED.
  LOOP AT ct_data INTO <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 INTO <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.
          MODIFY TABLE ct_data FROM <fs_data>.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDLOOP.
ENDLOOP.
2
I might overlook something, but I don't get why do you need the MODIFY TABLE ... line at all. You use field symbols, which means the 'ZZ_CHANGE_FIELD' field of internal table CT_DATA will be changed directly through the field symbol assignments. Can you just remove the MODIFY TABLE line and see in debugging what happens?József Szikszai
That's exactly what I have done first. I also was sure, that I don't need MODIFY TABLE in this case, but even <fs_data> get updated with the right data. The ct_data does not get updated. That's why I've tried MODIFY TABLE.dyz
@dyz if you remove the line "MODIFY TABLE", your code looks correct. Just be careful with one thing: after ASSIGN ... TO <fs>, testing IF <fs> IS ASSIGNED may be an error if at the same time the assignment was erroneous AND <fs> was previously assigned. Just check your full code (maybe you have more lines?). If that's the case, then replace the IF <fs> IS ASSIGNED with IF sy-subrc = 0.Sandra Rossi
@SandraRossi I just adjusted my code in the way you wrote and also have deleted MODIFY TABLE. There is no error at all and the field in the <fs_data> will be updated properly. But still no changes in CT_DATA. I really don't understand why...dyz
I forgot to say that it "may be an error" because in case ASSIGN fails, the field symbol remains unchanged (so it remains assigned if it was previously assigned).Sandra Rossi

2 Answers

3
votes

<fs_data> doesn't point to ct_data. It points to a new memory area that you create in the very beginning. Remove this and declare the field symbol inline to get a pointer to the actual output:

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.
0
votes

<fs_data> is a pointer to a row in ct_data. You are trying to modify the table from itself. The sy-subrc = 4 simply states that there is nothing to change.

As JozsefSzikszai points out in his comment, you don't need the MODIFY TABLE at all. Simply change the values in <fs_data> directly.