COND ABAP in SAP – new ABAP syntax construction. COND very useful for using in ABAP program for getting value with conditions. In old syntax you can use CASE or IF and ELSE, for example, but it will be with addition variable and ABAP code will be longer.
COND in ABAP examples SAP
I create a lot of examples using COND and I will show you step by step from the easiest to the most difficult with new ABAP syntax in SAP program.

Simple example COND in SAP
For example, we want to check price, and if price not correct to change to 0. It old ABAP it will be:
1 2 3 4 5 |
DATA: lv_price TYPE p. lv_price = -35. IF lv_price < 0. lv_price = 0. ENDIF. |
Not so long, but it the easiest example. In new syntax ABAP:
1 2 |
DATA(lv_price) = -35. DATA(lv_sum) = COND netwr( WHEN lv_price > 0 THEN lv_price ELSE 0 ). |
We not only check conditions for price, but also convert type to NETWR. You also can convert types in ABAP with construction CONV ABAP.
Example COND SAP with 2 conditions
We can also use COND ABAP with more difficult conditions. For example, I need to choose order number with some conditions.
1 2 3 4 5 6 7 8 9 10 |
DATA: lv_vbeln_old TYPE vbeln, lv_vbeln_old TYPE vbeln VALUE '2', lv_vbeln_cur TYPE vbeln. IF lv_vbeln_new IS NOT INITIAL. lv_vbeln_cur = lv_vbeln_new. ELSEIF lv_vbeln_old IS NOT INITIAL. lv_vbeln_cur = lv_vbeln_old. ENDIF. |
Also not so big. But for example if you want to send this variable to method it will be easier with new syntax:
1 2 3 4 5 6 7 |
DATA(lv_vbeln_old) = CONV vbeln( '' ). DATA(lv_vbeln_new) = CONV vbeln( '2' ). DATA(lv_vbeln_cur) = COND #( WHEN lv_vbeln_new IS NOT INITIAL THEN lv_vbeln_new WHEN lv_vbeln_old IS NOT INITIAL THEN lv_vbeln_old ). BREAK-POINT. |
Because in this case you can use all construction COND #( … ) in parameter for methods. You also can use COND # without type if program can understand type.
Example COND with WHEN and ELSE.
COND SAP in this case in old syntax will be IF, ELSEIF and ELSE. But in new ABAP:
1 2 3 4 5 6 |
DATA(lv_vbeln_o) = CONV vbeln( '1' ). DATA(lv_vbeln_n) = CONV vbeln( '2' ). DATA(lv_vbeln_curr) = COND #( WHEN lv_vbeln_n IS NOT INITIAL THEN | { lv_vbeln_n ALPHA = IN }| WHEN lv_vbeln_o IS NOT INITIAL THEN | { lv_vbeln_o ALPHA = IN }| ELSE '0000000000' ). |
In this example I also to add using new ABAP construction Concatenate ABAP for adding lidding zeros with other ways.
Example COND with dates
One more example using this construction with date
1 2 3 4 5 6 7 8 |
DATA(lv_date_o) = CONV datum( '20241021' ). DATA(lv_date_n) = CONV datum( '20241022' ). DATA(lv_date_cur) = COND #( WHEN lv_date_n IS NOT INITIAL AND lv_date_n > lv_date_o THEN lv_date_n WHEN lv_date_o IS NOT INITIAL THEN lv_date_o ELSE sy-datum ). BREAK-POINT. |
I will add more examples in future. Because with COND we also can use LET for creating new local variable for using inside.