
With Release 7.40 ABAP supports so called constructor operators. Constructor operators are used in constructor expressions to create a result that can be used at operand positions. The syntax for constructor expressions is
... operator type( ... ) ...
operator is a constructor operator. type is either the explicit name of a data type or the character #. With # the data type can be dreived from the operand position if the operand type is statically known. Inside the parentheses specific parameters can be specified.
Last but not least, two nice ones, the conditionals COND and SWITCH.
constructs a result of the specified type that depends on logical expressions.
constructs a result of the specified type that depends on a case differentiation.
With other words: IF and CASE as expressions in operand positions!
DATA(time) =
COND string(
WHEN sy-timlo < '120000' THEN
|{ sy-timlo TIME = ISO } AM|
WHEN sy-timlo > '120000' THEN
|{ CONV t( sy-timlo - 12 * 3600 )
TIME = ISO } PM|
WHEN sy-timlo = '120000' THEN
|High Noon|
ELSE
THROW cx_cant_be( ) ).
Note the THROW. Now you can raise and throw exceptions ...
CLASS cx_langu_not_supported DEFINITION INHERITING FROM cx_static_check.
ENDCLASS.
CLASS class DEFINITION.
PUBLIC SECTION.
METHODS meth IMPORTING iso_langu TYPE string
RETURNING VALUE(text) TYPE string.
ENDCLASS.
CLASS class IMPLEMENTATION.
METHOD meth.
...
ENDMETHOD.
ENDCLASS.
...
DATA(text) =
NEW class(
)->meth(
SWITCH #( sy-langu
WHEN 'D' THEN `DE`
WHEN 'E' THEN `EN`
ELSE THROW cx_langu_not_supported( ) ) ).
Amazing, n'est-ce pas?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
7 | |
4 | |
2 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 |