08-22-2022 1:05 PM
Hi All,
Suppose, I want to use collect statement for matnr values and according to that I want sum of quantity field. but I get an error that we can use collect command if all non unique key fields are numeric. How to write the code for that Please anyone guide me.
Thank you in advance.
08-22-2022 2:33 PM
Did you use ‘with EMPTY KEY’ ?
If yes then you have to replace it – “WITH KEY <name of the non numeric field>”
For example replace line 18 with line 19:
TYPES:08-22-2022 1:07 PM
Please share your internal table on which you set a loop - to collect the sum of quantities.
Also share the piece of code on whihc you do collect.
08-22-2022 1:24 PM
Key should be unique to perform the collect statement. You can use loops on your internal table, and write the logic for addition or use SUM.
08-22-2022 1:28 PM
Please indicate the EXACT error message.
About using COLLECT, the documentation says: "All components that are not part of the primary table key must have a numeric data type."
How did you define your internal table, what is the primary table key, especially what components are NOT part of the primary table key?
08-22-2022 2:33 PM
Did you use ‘with EMPTY KEY’ ?
If yes then you have to replace it – “WITH KEY <name of the non numeric field>”
For example replace line 18 with line 19:
TYPES:08-23-2022 10:34 AM
Ahana,
Please share the structure of your internal table and more details(screen capture etc.) on the error. You might also take help from this answer - https://answers.sap.com/questions/2880928/use-of-collect-statement.html