Sunday, 13 April 2025

Using COND as a Replacement for IF/ELSE:

         The COND expression is a more concise and modern way to express conditional logic, replacing traditional IF/ELSE statements. It provides a more functional programming-style approach to handling conditions:-

Before

DATA: lv_text(30).

IF lv_vehicle = '01' AND lv_type = 'C'.

    lv_text = 'Toyota'.

ELSE.

Endif.

IF lv_vehicle ='02' AND lv_type = 'C'.

    lv_text = 'Chevy'

ELSE.

Endif

IF lv_vehicle ='03' AND lv_type = 'C'.

    lv_text = 'Range Rover'.

ENDIF.


After

DATA(lv_text) = COND text30(

WHEN lv_vehicle ='01' AND lv_type = 'C' THEN 'Toyota'

WHEN lv_vehicle ='02' AND lv_type = 'C' THEN 'Chevy'

WHEN lv_vehicle ='03' AND lv_type = 'C' THEN 'Range Rover').

No comments:

Post a Comment