为什么SAP会在以下情况下尝试变得更聪明并产生短暂转储?
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( ).
方法change
中没有任何变化,但在短暂转储的描述中我看到了
要为字段
<FS_MY_TYPE>-HIERLEVEL
分配一个新值,但此字段至少部分受到保护以防止更改。
看起来SAP试图变得比应有的更聪明。如果我真的试图改变其中一个关键字段,我会理解是否产生了短转储。为什么这样设计?
答案 0 :(得分:0)
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.
答案 1 :(得分:0)
When using INSERT...ASSIGNING <fs_row>
syntax you should always be aware of restrictions that apply to the corresponding field symbol. According to SAP, the same restrictions that exist in READ TABLE ...ASSIGNING <fs_row>
are applied to INSERT
construction as well. In particular, they are:
As long as the field symbol points to the row, assignments to the field symbol modify the row in the internal table. The following limitations apply to modifying key fields of the primary and secondary table key:
- The key fields of the primary table key of sorted tables and hashed tables are read-only and must not be modified. This would invalidate internal table administration. Attempts to do this generally raise an unhandleable exception.
...
The same restrictions are applied for inline declarations as well.
As we see in your code, you use implicit pass by reference declaration for parameters of your method. But pass by reference don't create any local data objects for parameters and works with the actual parameters instead, which requires them to be writable. This is the key to your question.