05-18-2020 1:18 PM
Hi Experts,
is it possible to improve my logic(7.4 above alternative) so that we have lesser lines yet the same results?
i also consider LOOPING into ITAB and adding counter logic
but i'm thinking if is it possible to have one line logic for counting
eg. describle table itab where key = 'Key1' and flag1 = 'X' lines Key1Flag1count.
describle table itab where key = 'Key1' and flag2 = 'X' lines Key1Flag2count.
result should be:
Key1Flag1count = 2
Key1Flag2count = 0
Key1Flag3count = 2
Key2Flag1count = 0
Key2Flag2count = 2
Key2Flag3count = 0
05-18-2020 3:37 PM
Hi mchua9,
As you said you are working on 7.40 then REDUCE statement can come for rescue.
data(lv_lines) = REDUCE i( init x = 0 for wa in itab where ( key1 = 'Key1' or key2 = 'Key2' ..... ) next x = x + 1 ).
Regards,
Anmol
05-18-2020 1:23 PM
Check FILTER statement
https://blogs.sap.com/2014/10/06/abap-news-for-740-sp08-more-for-internal-tables/
05-18-2020 1:29 PM
Hi mchua9
I would go with a LOOP statement, because you want to have a count of records for different conditions. This way you will only LOOP once through the table and count all necessary records in one go.
Regards,05-18-2020 1:53 PM
05-18-2020 3:37 PM
Hi mchua9,
As you said you are working on 7.40 then REDUCE statement can come for rescue.
data(lv_lines) = REDUCE i( init x = 0 for wa in itab where ( key1 = 'Key1' or key2 = 'Key2' ..... ) next x = x + 1 ).
Regards,
Anmol
05-19-2020 9:35 AM
FILTER statement is also similar with transferring and deleting internal tables, which is great
but REDUCE statement gets the requirement done in just a single line! thank you for this answer!
03-25-2022 1:40 PM
Hi Anmol,
I had a similar requirement where I had to simulate the COUNT feature of SELECT syntax over an INTERNAL Table.
And your response helped me in achieving the same, just attaching the sample code snippet for others with similar requirements.
Thanks,
Sijin