Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Assign structure error

Former Member
0 Likes
1,577

hi experts,

Error : ST22
Field "<ZSORD>" was to assigned a new value but this field is at least
  partly
protected against changes.

Explanation :

I am getting a  dynamic table as input at run time for the fm.So I am passing this table in the changing parameter as

ct_package type standard table.

And my requirement is to do some calculations and finally modify/update this table and send it back to the caller.

My code :

DATA:    cr TYPE REF TO data.

Field symbols : <fs1> type any,
                       <fs2> type any.


  CREATE DATA cr LIKE LINE OF ct_package.
  ASSIGN cr->* TO <fs1>.
  ASSIGN cr->* TO <fs2>.

  CREATE DATA cr LIKE HASHED TABLE OF <fs1> WITH UNIQUE DEFAULT KEY.
  ASSIGN cr->* TO <ltab>.


LOOP AT CT_PACKAGE assigning <fs1>.

doing some calculations...

    COLLECT <fs1> INTO <ltab>.

endloop.


Loop at <ltab> assigning <fs1>.

MOVE-CORRESPONDING <fs1> TO <fs2>.

ASSIGN COMPONENT 'ZSALEORD' OF STRUCTURE <fs1> TO <zsord>.
ASSIGN COMPONENT 'ZCURR' OF STRUCTURE <fs2> TO <zCURR>.

* I got the value in <ZSORD> as 73737 but I am trying to change it.Here I am getting dump
<zsord> = '12323'.

* I got the value in <ZCURR> as INR but I am trying to change it.Here I am getting dump
<zcurr> = 'USD'.

APPEND <fs2> TO ct_package.

endloop.


Please help in following.
1) Is the way I am declaring for referring dynamic tables is right or should I use different approach
2) Please tell me why I am not able to pass a value to <zsord> and <ZCURR>, if that is not possible then please advice
how to acheive that and add the records to ct_package.

1 ACCEPTED SOLUTION
Read only

naimesh_patel
Active Contributor
0 Likes
1,159

Since you are creating the HASH table without unique key, it is using all fields as the key fields. It is running into issues, because you are changing the field which is part of the key.

To fix - You need to define the type with specific key fields or create the Standard table instead of the Hashed table.

More on Primary key of the table : http://help.sap.com/abapdocu_702/en/abaptypes_primary_key.htm

More on Collect (see below for Hash table)

http://help.sap.com/abapdocu_702/en/abapcollect.htm

If a standard table is still filled using COLLECT, it should not be edited using any other statement, with the exception of MODIFY. If the latter is used with the addition TRANSPORTING, you must ensure that no primary key fields are changed. This is the only way to ensure that the table entries are always unique and compressed, and that the COLLECT statement runs efficiently. The function module ABL_TABLE_HASH_STATE can be used to check whether a standard table is suitable for editing using COLLECT.

Regards,
Naimesh Patel

1 REPLY 1
Read only

naimesh_patel
Active Contributor
0 Likes
1,160

Since you are creating the HASH table without unique key, it is using all fields as the key fields. It is running into issues, because you are changing the field which is part of the key.

To fix - You need to define the type with specific key fields or create the Standard table instead of the Hashed table.

More on Primary key of the table : http://help.sap.com/abapdocu_702/en/abaptypes_primary_key.htm

More on Collect (see below for Hash table)

http://help.sap.com/abapdocu_702/en/abapcollect.htm

If a standard table is still filled using COLLECT, it should not be edited using any other statement, with the exception of MODIFY. If the latter is used with the addition TRANSPORTING, you must ensure that no primary key fields are changed. This is the only way to ensure that the table entries are always unique and compressed, and that the COLLECT statement runs efficiently. The function module ABL_TABLE_HASH_STATE can be used to check whether a standard table is suitable for editing using COLLECT.

Regards,
Naimesh Patel