I need to evaluate a dynamic logical expression and I know that in ABAP it is not possible. I found the class cl_java_script and with this class I could achieve my requeriment. I've try something like this:
result = cl_java_script=>create( )->evaluate( `( 1 + 2 + 3 ) == 6 ;` ).
After the method evaluate execution result = true as espected. But my happiness is over when I look into the class documentation that says This class is obsolete.
My question is, there is another way to achieve this?
SAPs BRF is an option, but potentially massive overkill in your scenario.
Here is a blog on calling BRF from abap. And here is how Rules/Expressions can be defined dynamically.
BUT, if you know enough about the source problem to generate 1 + 2 + 3 = 6
Then it is hard to imagine why a simple custom parser cant be used. Just how complex should the expressions be ?
Id probably write my own parser before investing in calling BRF.
Since some/many BSPs use server side JAVAscript and not ABAP as the scripting language, i cant see SAP removing the Kernel routine anytime soon. SYSTEM-CALL JAVA SCRIPT EVALUATE.
SO maybe consider Just calling the cl_java_script anyway until it is an issue. Then worry about a parser if and when it is really no longer a valid call.
But definitely some movement in the obsolete space here. SAP is pushing/forcing you to cloud with the SDK, to execute such things.
https://sap.github.io/cloud-sdk/docs/js/overview-cloud-sdk-for-javascript