Advertising:
Switch(ABAP keyword): Difference between revisions
From SAP Knowledge Base
(Created page with "Kategorie:Schlüsselbegriffe Since ABAP 7.40 you can use SWITCH. In terms of syntax, this is like COND with the only difference being that it checks for equality and no condition like COND is possible. === Mit SWITCH === <syntaxhighlight lang="abap" line start="1"> DATA(lang) = SWITCH char02( sy-langu WHEN 'E' THEN 'EN' WHEN 'D' THEN 'DE' ELSE THROW cx_... "optional...") |
|||
Line 14: | Line 14: | ||
<syntaxhighlight lang="abap" line start="1"> | <syntaxhighlight lang="abap" line start="1"> | ||
DATA lang TYPE char02. | DATA lang TYPE char02. | ||
CASE sy-langu. | CASE sy-langu. | ||
WHEN 'E'. | WHEN 'E'. |
Revision as of 16:18, 21 December 2024
Kategorie:Schlüsselbegriffe Since ABAP 7.40 you can use SWITCH. In terms of syntax, this is like COND with the only difference being that it checks for equality and no condition like COND is possible.
Mit SWITCH
DATA(lang) = SWITCH char02( sy-langu WHEN 'E' THEN 'EN'
WHEN 'D' THEN 'DE'
ELSE THROW cx_... "optional
).
Since "lang" is declared inline, the type char02 must be specified.
With CASE
DATA lang TYPE char02.
CASE sy-langu.
WHEN 'E'.
lang = 'EN'.
WHEN 'D'.
lang = 'DE'.
WHEN OTHERS.
RAISE EXCEPTION TYPE cx_... .
ENDCASE.