2015 May 11 3:42 PM
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.
2015 May 11 6:08 PM
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
2015 May 11 6:08 PM
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