Search code examples
abap

Passing a field symbol as changing parameter cause short dump. Why?


Why does SAP try to be smarter than it has to be and produce short dump in the following case?

REPORT zzy.

CLASS lcl_main DEFINITION FINAL CREATE PRIVATE.
  PUBLIC SECTION.
    CLASS-METHODS:
      main.
  PRIVATE SECTION.
    TYPES:
      BEGIN OF t_my_type,
        hierlevel TYPE i,
        groupname TYPE ktext,
        result    TYPE p LENGTH 9 DECIMALS 2,
      END OF t_my_type,
      tt_my_type TYPE HASHED TABLE OF t_my_type WITH UNIQUE KEY hierlevel groupname.
    CLASS-METHODS:
      change
        CHANGING
          cs_my_type TYPE t_my_type.
ENDCLASS.

CLASS lcl_main IMPLEMENTATION.
  METHOD main.
    DATA:
      lt_my_table TYPE tt_my_type.

    INSERT VALUE #( hierlevel = 0 groupname = 'MY_GROUP' result = '0.0' ) INTO TABLE lt_my_table
      ASSIGNING FIELD-SYMBOL(<fs_my_type>).

    change(
      CHANGING
        cs_my_type = <fs_my_type>
    ).
  ENDMETHOD.

  METHOD change.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  lcl_main=>main( ).

There is nothing changed in the method change and yet in the description of the short dump I see

Field <FS_MY_TYPE>-HIERLEVEL was to assigned a new value but this field is at least partly protected against changes.

It looks that SAP tries to be smarter than it should be. I would understand if the short dump was produced if I actually tried to change one of the key fields. Why is this designed that way?


Solution

  • I have just spotted that further description in the short dump has that

    The following are protected against changes:
    - Access using field symbols if the field assigned using ASSIGN is partly or completely protected (for example key components of internal table of the type SORTED or HASHED TABLE).

    A bit strange for me but looks like a design decision. Maybe it was technically hard to check only for the fields that are actually protected.