Use switch statement instead of case statement. (7.4+).

Switch statement.

    

    * From ABAP 7.4 onwards, SAP introduced SWITCH statement.

    * We need to use SWITCH statement instead of CASE statement.

    * In CASE statement, we need to specify the variable which is getting filled in every condition.

    * In SWITCH statement, we need not to mention the variable which is getting filled in every condition. 


CASE (Old).

        REPORT zab_rp_switch.


    PARAMETERSp_day TYPE i.
    DATAlv_output(15TYPE c.

    CASE p_day.
      WHEN 1.
        lv_output TEXT-000.   " SUNDAY.
      WHEN 2.
        lv_output TEXT-001.   " MONDAY.
      WHEN 3.
        lv_output TEXT-002.   " TUESDAY.
      WHEN 4.
        lv_output TEXT-003.    " WEDNESDAY.
      WHEN 5.
        lv_output TEXT-004.    " THURSDAY.
      WHEN 6.
        lv_output = TEXT-005    " FRIDAY.
      WHEN 7.
        lv_output TEXT-006.     " SATURDAY.
      WHEN OTHERS.
        lv_output TEXT-007    " Pls enter correct day number.
    ENDCASE.

Input1

Output1


Input2


Output2



Switch statement
                 Referswitch statement
*****************************Thank You*******************

Comments

Popular posts from this blog

Pf status and user command in factory method - OOPS ALV in ABAP

fetch the data from table and send an email in ABAP

Enhancements in abap