New syntax for ABAP 740:
Code is equivalent to:
DATA: ls_data LIKE LINE OF it_data.READ TABLE it_data INTO ls_data WITH KEY object_ext = cl_crm_prodil_bo_names=>gc_prod_root.CALL METHOD add_data EXPORTING ir_child_object = ir_root_object is_data = ls_data.
This shows that the new syntax is relatively concise, can write less than 3 lines of code. However, there is a flaw in the new syntax, if the Object_ext value of cl_crm_prodil_bo_names=>gc_prod_root is not present in the It_data table, the program execution is aborted and an exception is thrown cx_sy_itab_ Line_not_found.
In this case, ABAP also has a corresponding solution.
The 17th line throws an exception, and 19 rows are not, semantically easy to understand: If a record of name Spring2 does not exist in the inner table Lt_data, then the developer uses the default keyword to specify a struct as the defaults.
There are similar mechanisms in Java 8. To avoid the infamous Nullpointerexception,java developer, before using an instance method of an object, you need to check that the object instance is not NULL:
ifnull ){ xx.doSomething();}
In Java 8, a new tool class optional is provided in the package java.util to see its usage.
The 11th row of the filter method should semantically return a null because the length of the string constant that I initialized on line 10th is obviously greater than 6. But the object that invokes the filter method is a optional object, so the final filter method eventually returns a optional object that wraps a null. As shown in the debugger:
The result of the execution of line 14th prints out the value specified in OrElse, where OrElse's ideas are consistent with the default keywords in the ABAP described above.
The implementation of this optional tool class is also simple, and OrElse is just a ternary expression.
To see more language feature comparisons between ABAP and Java,javascript, please follow Jerry's public number: Wang Zixi.
Some language features in ABAP and Java about the default mechanism