Advertising:

Cond(ABAP keyword)

From SAP Knowledge Base

COND can be used since ABAP 7.40. This is an alternative to IF, especially because the code is much shorter, but also sometimes more confusing.
The advantage is to set a condition directly when assigning a value to a variable or to parameters in methods.

With COND

Here the COND is used in a method call to pass a parameter like a subobject for the application log:

bal = cf_reca_message_list=>create( EXPORTING id_object = 'YOBJECT'
                                              id_subobject = COND balsubobj( WHEN mode = 'a' THEN 'YOBJECTSUBA'
                                                                             WHEN mode = 'b' THEN 'YOBJECTSUBB'
                                                                             WHEN mode = 'c' THEN 'YOBJECTSUBC'
                                           ELSE THROW cx_root "ELSE is optional
                                           )
                                  ).

After COND, the data type can be seen. Here you could also have worked with #, since the type is already known to id_suboject. If you were to make an inline declaration where the type is not known at all, you would have to specify it after COND.

With IFs

Without COND, you would have to use IFs to query which mode is currently active in order to assign the correct sub-object:

 DATA: subobject TYPE balsubobj. 
 
 IF mode = 'a'.
  subobject = 'YOBJECTSUBA'
 ELSEIFmode = 'b'.
  subobject = 'YOBJECTSUBB'
 ELSEIF mode = 'c'.
  subobject = 'YOBJECTSUBC'
 ELSE
  RAISE EXCEPTION TYPE cx_root.
  "other error handling...
 ENDIF.
 
 bal = cf_reca_message_list=>create(  EXPORTING id_object = 'YOBJECT'
                                                d_subobject = subobject ).

This is a wiki created in the spare time of a private person working in the SAP ERP area. The aim is to collect knowledge for the own use. The wiki is maintained to the best of knowledge and belief.
All products shown, including in form of screenshots, belong to SAP SE. Their trademarks are, among others: SAP®,ABAP®,SAP Fiori®,SAP HANA®,SAP NetWeaver®,SAP® R/3®,SAP S/4HANA®,SAP S/4HANA® Cloud