Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Program Flow Logic →  Conditional Expressions 

COND, SWITCH - result

Other versions: 7.31 | 7.40 | 7.54


...   operand 
  | { THROW [RESUMABLE|SHORTDUMP] cx_class( [ message]
                                            [p1 = a1 p2 = a2 ...] ) } ...


1. ... operand

2. ... THROW [RESUMABLE|SHORTDUMP] cx_class( [message] [p1 = a1 p2 = a2 ...] )


When specified after THEN and ELSE in the conditional expressions COND and SWITCH, these strings determine the result of the expression if the appropriate branch is selected.

Alternative 1

... operand


If an operand operand is specified, its value is converted to the data type type if necessary and returned as the result of the conditional expression. operand is a general expression position with the following restrictions:

  • If operand is specified as a bit expression, type must be byte-like.


When an operand is specified, the condition operators COND and SWITCH create a temporary data object whose data type is determined by the specified type and whose content is determined by the selected operand. This data object is used as the operand of a statement and then deleted. It is deleted either when the current statement is closed or when a relational expression is evaluated after the truth value is determined.


Specifies the operands sum and sum + 1. The number of times a random number is less than half of its maximum value is counted.

DATA(rnd) = cl_abap_random_int=>create( 
  seed = CONV i( sy-uzeit ) min = 1 max = 101 ). 

DATA(sum) = 0. 
DO 100 TIMES. 
  sum = COND i( WHEN rnd->get_next( ) <= 50 THEN sum + 1 
                                           ELSE sum ). 
cl_demo_output=>display( sum ). 

Alternative 2

... THROW [RESUMABLE|SHORTDUMP] cx_class( [message] [p1 = a1 p2 = a2 ...] )


If specified, THROW raises either an exception or a runtime error.

  • If the addition SHORTDUMP is not specified, THROW functions like the statement RAISE EXCEPTION TYPE and raises an exception of the exception class cx_class. The following applies here:
  • The addition RESUMABLE can be used to make the exception resumable.
  • A message can be passed to the exception object using the addition message.
  • The input parameters p1, p2, ... of the instance constructor can be filled with actual parameters a1, a2.
  • If the addition SHORTDUMP is specified, THROW functions like the statement RAISE SHORTDUMP TYPE and raises a runtime error with the exception class cx_class. In both cases, a message can be passed and the input parameters can be filled.


  • If the exception class is specified after THROW, the parentheses must always be specified, even if no messages or actual parameters are passed. EXPORTING cannot be specified, nor does it need to be.


Raises an exception of the class CX_DEMO_DYN_T100 that includes the interface IF_T100_DYN_MSG.

DATA cflag TYPE abap_bool. 


DATA(iflag) = COND i( WHEN cflag = abap_true  THEN 1 
                      WHEN cflag = abap_false THEN 0 
                      ELSE THROW cx_demo_dyn_t100( 
                             MESSAGE e888(sabapdemos) 
                                    WITH 'Illegal value!' '' '' '' ) ).


Raises a runtime error with an exception object of the class CX_DEMO_DYN_T100, which includes the interface IF_T100_DYN_MSG.

DATA(time) = COND t( WHEN sy-timlo BETWEEN '090000' AND '170000' 
                      THEN sy-timlo 
                       THROW SHORTDUMP cx_demo_dyn_t100( 
                          MESSAGE e888(sabapdemos) 
                                 WITH `I` `don't` `work` `now!` ) ).