Application Development 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: 

How to Create Composite Functions related to Functional Programming in ABAP?

fweil
Explorer

Hello SAP Devs,

Lately, I had serveral use cases, where I had to compose the same functions/methods in different order. In Functional Programming this kind of programming use case is solved with a higher order compose function (sometimes also called pipe or flow).

The JavaScript ecosystems has the lodash library and its functional programming package. See an example

https://hackernoon.com/function-composition-with-lodash-d30eb50153d1

Does within the ABAP ecosystem exist a functional programming library like lodash?

Thank you very much in advance, all the best

Florian

P.S. Method Chaining could be an approach to improve the API ergonomics, but that is not exactly I am looking for

4 REPLIES 4

FredericGirod
Active Contributor

I think you cannot find this kind of "tool" in ABAP, the hard part is :

const formatData = fp.compose(
fp.map(formatPhone),
fp.uniqBy('phone'),
fp.filter('phone'),
fp.sortBy('firstName'),
);

a constant containing a list of class/method ... never seen

but, you have something looks like that with Design Pattern: Chain of Responsibility :

https://blogs.sap.com/2020/02/26/abap-with-coffee-and-chain-of-responsibilitycor-oo-pattern/

fweil
Explorer

Hi Frederic,

thank you very much for your reply. Your are right, your advice of the Chain of Responsibility Pattern looks very interesting! That might work if my functions have very similar import und export arguments. Does this pattern works with different parameter, too? In ABAP parameter overloading ist not possible as far as I know... But maybe working with the type any might solve this problem...

I just learnt a little about Functional Programming from my (math loving) coworker and I have found some articles about Functional Programming here about ABAP

https://blogs.sap.com/2015/04/09/funtional-programming-in-abap/

https://blogs.sap.com/2017/02/26/functional-programming-simulate-curry-in-abap/

https://blogs.sap.com/2017/02/27/functional-programming-try-reduce-in-javascript-and-in-abap/

I thought after reading those blog posts, i had the hope that maybe some developer has already created a functional utility package... but maybe it is more nerdy topic than a pragmatic way of daily coding

All the best from Germany,

Florian

FredericGirod
Active Contributor

naimesh.patel made very nice blogs about design pattern :

http://zevolving.com/category/abapobjects/oo-design-patterns/

For the parameters, you have the Design Pattern Adapter (but the code will be very complex), or you could set some parameters optional. It depends a lot of your requierment.

The main problem here is, to make a code someone else could read & understand.

Hi Frederic,

thank you very much for the great link! Now I have a perfect reading list for a good morning coffee routine.

You are definitely right. Code readablity is one of the most important points, while writing code. Functional Programming claims to produce readable code due a declarative code style. I have problems to understand more complex Functional Programming. Another coworker made a nice metapher... Use Functional Programming style like you use spice in cooking... Too much destroys the taste of the meal, but without spice the meal has no real taste... I assume the higher order functions map, reduce, filter, compose, pipe could be a nice flavor to the ABAP Language... But it seems with the standard coding tools it might be impossible to express it in an readable manner...

Thanks again for your links and replies. It helped a lot to think about this topic more deeply.