‎2014 May 26 6:02 AM
‎2015 Jul 25 2:11 PM
Hi,
ABAP does NOT support true functional programming (FP). Functions are not first class citizens in ABAP. As a side note, ABAP is also not a pure object oriented language as well. Those two facts together defeat possibility to use many many handy FP constructs at the moment. Maybe in future relases it will come, who knows. But at the moment, you can not pass code bits as a parameters to functions if that's what you were asking about.
For those who are not properly educated on what FP really is: FP is not defined by the ability to use functions and funcional expresions in this manner:
DATA(segment) = document->create_simple_element_ns(
name = |{ replace( val = <edidd>-segnam regex = |^Z1IDE_(.*)_D14B$| with = |$1| ) }|
parent = map[ segnum = <edidd>-psgnum ]-element
).
FP is defined as ability to store functions and code bits in variables like any other type of data (in the end, code is also a bit of data - code compiled into instructions for example, or a pointer to a place with the compiled code, both with metadata about parameters, return values and thrown exceptions...). If ABAP supported true FP, I could something like this (my ABAP pseudocode used here):
TYPES t_func TYPE FUNCTION IMPORTING segnam TYPE string RETURNING value(name) TYPE string.
DATA(strip) = VALUE t_func(
" ABAP code here
name = replace( val = segnam regex = |^Z1IDE_(.*)_D14B$| with = |$1| ) }|
).
And then in every place I want to strip the IDoc segment name, I would do this (note how strip variable would now be used just like a built in function):
DATA(segment) = document->create_simple_element_ns(
name = strip( <edidd>-segnam )
parent = map[ segnum = <edidd>-psgnum ]-element
).
With this concept, one can define generic algorithms and then just plug in simple code bit as a parameter that defines what the whole generic construct does then. For example this FP concept almost entirely defeats purpose of loops and need to use variables.
If you check newest ABAP additions, you can find that SAP added 2 functional concepts into ABAP lately:
1) table comprehensions - like map functions in FP
2) table reductions - like fold functions in FP
Generally, the new additions into ABAP in version 7.40 are amazing from my point of view. The code verbosity is now extremely in some places and quite neat constructs can now be created that allow to do the same amount of work in maybe 1/3 of code than before.
David
‎2014 May 26 6:12 AM
Hi,
If you refer to somthing like the new Lambda expressions in java 8 .
Did not see any thing like it since 2006 (When I was introduced to ABAP).
Regards.
‎2014 May 26 6:20 AM
‎2014 May 26 6:14 AM
‎2014 May 26 6:18 AM
‎2014 May 26 6:22 AM
yeah? How?
Any document?
function in ABAP is not first-class citizen if I understand correctly.
‎2014 May 26 6:42 AM
Hi Eitan,
My response is based on this blog post: http://blog.acorel.nl/2013/12/how-abap-moves-towards-functional.html
Now, I'm no expert in functional programming, only know the basics. But if Aaron's questions is as clear as he claims and he knows ABAP function modules are not first-class citzens (they really aren't), so this is just a rhetoric question.
I probably should not have answered "yes", it's more like "kind of does", or "it's getting there", as it provides some of functional programming features, but not all.
Cheers,
Custodio
PS: another blog post to consider is this: The Essence of Functional Programming and ABAP. | &#169; Passionate about SAP - A Blog
‎2014 May 26 7:29 AM
Hi,
From a response for the post you menion:
http://blog.acorel.nl/2013/12/how-abap-moves-towards-functional.html?showComment=1386928417961#c6402...
"I cannot really claim to understand ABAP but I think I have a good enough grasp of FP - that said I cannot find any main ideas from FP in your examples"
If you know Java you can look at:
http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html
More general info:
http://en.wikipedia.org/wiki/Functional_programming
Small java sample:
private class MyWorker implements Runnable {
@Override
public void run() {
// Do some work in different thread
}
}
public void test_1() {
{
// Using Runnable in traditional way
new Thread(new MyWorker()).start();
}
{
// Using lambda
new Thread(() -> {
// Do some work in different thread
});
}
}
Regards.
‎2014 May 26 8:09 AM
Thanks Eitan,
I haven't read the comments earlier. It seems I should have.
Cheers,
Custodio
‎2014 May 26 8:23 AM
‎2014 May 26 6:17 AM
Hi Aaron,
your question is not clear.
Can you explain briefly..
Regards,
Krishna
‎2014 May 26 6:23 AM
I think it's pretty clear, maybe you don't know the concept of functional programming. just google it.
‎2014 May 26 7:15 AM
Hi,
Let me try. Correct me if i am wrong, I think it supports functional programming.
Here is an example i tried.
Suppose u got an internal table(itab) with 10 records.
If lines ( itab ) GE 1.
write : 'Hello'.
Endif.
Regards.
‎2015 Jul 25 2:11 PM
Hi,
ABAP does NOT support true functional programming (FP). Functions are not first class citizens in ABAP. As a side note, ABAP is also not a pure object oriented language as well. Those two facts together defeat possibility to use many many handy FP constructs at the moment. Maybe in future relases it will come, who knows. But at the moment, you can not pass code bits as a parameters to functions if that's what you were asking about.
For those who are not properly educated on what FP really is: FP is not defined by the ability to use functions and funcional expresions in this manner:
DATA(segment) = document->create_simple_element_ns(
name = |{ replace( val = <edidd>-segnam regex = |^Z1IDE_(.*)_D14B$| with = |$1| ) }|
parent = map[ segnum = <edidd>-psgnum ]-element
).
FP is defined as ability to store functions and code bits in variables like any other type of data (in the end, code is also a bit of data - code compiled into instructions for example, or a pointer to a place with the compiled code, both with metadata about parameters, return values and thrown exceptions...). If ABAP supported true FP, I could something like this (my ABAP pseudocode used here):
TYPES t_func TYPE FUNCTION IMPORTING segnam TYPE string RETURNING value(name) TYPE string.
DATA(strip) = VALUE t_func(
" ABAP code here
name = replace( val = segnam regex = |^Z1IDE_(.*)_D14B$| with = |$1| ) }|
).
And then in every place I want to strip the IDoc segment name, I would do this (note how strip variable would now be used just like a built in function):
DATA(segment) = document->create_simple_element_ns(
name = strip( <edidd>-segnam )
parent = map[ segnum = <edidd>-psgnum ]-element
).
With this concept, one can define generic algorithms and then just plug in simple code bit as a parameter that defines what the whole generic construct does then. For example this FP concept almost entirely defeats purpose of loops and need to use variables.
If you check newest ABAP additions, you can find that SAP added 2 functional concepts into ABAP lately:
1) table comprehensions - like map functions in FP
2) table reductions - like fold functions in FP
Generally, the new additions into ABAP in version 7.40 are amazing from my point of view. The code verbosity is now extremely in some places and quite neat constructs can now be created that allow to do the same amount of work in maybe 1/3 of code than before.
David