On one of my more recent projects I went through a code review and afterwards my team lead pulled me aside and asked me to explain something. As it turns out he was referring to my use of the REDUCE operator in one the class methods. Much to my surprise this particular operator is not as widely used as I thought and the reason doesn’t seem to be that it’s actually hard to use but rather it just “looks” difficult to begin with.
It’s a great way to quickly and efficiently sum up or collect strings in a way that lets you summarize large tables of information. It’s also, in my humble opinion, a very clean and tidy way to collect summarised data making the logic easy to read for other developers.
So in this article I really want to encourage you, if you aren’t already doing so, to give the REDUCE operator a try 🙂
The SAP documentation on this particular operator is really well written and so I made a short video simply following 3 examples directly from the online documentation.
These are the three examples I run through:
REDUCE – Reduction Operator – https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-us/abenconstructor_expression_reduce.htm
Creating Values with FOR and REDUCE – https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-us/abencond_iteration_reduce_abexa.htm
Table Reductions, Summation of an Array – https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-us/abenreduce_simple_abexa.htm
There’s also a great blog post by Horst Keller on the subject – https://blogs.sap.com/2016/08/25/i-dont-like-reduce-i-love-it/
The example can be found in this GitHub Repo – https://github.com/brandoncaulfield/youtube-abap/blob/master/z_reduce_example.abap
If you have any questions or anything you’d like to add, please let me know in a comment and I’ll help where I can.
Thanks for reading!