Wednesday 27 September 2017

ABAP: CASE-ENDCASE statement

CASE-ENDCASE statement is used to check multiple conditions.

Syntax
CASE variable.
         WHEN val1.
                 * Execute statments if variable is equal to val1
         WHEN val2.
                 * Execute statements if variable is equal to val2
         WHEN OTHERS.
                 * Execute this block, if variable is not match to any of the values above.
ENDCASE.

Z_HELLO_WORLD
*&---------------------------------------------------------------------*
*& Report Z_HELLO_WORLD
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT Z_HELLO_WORLD.
DATA day_of_the_week TYPE I VALUE 3.

CASE day_of_the_week.
  WHEN 1.
    Write 'Monday'.
  WHEN 2.
    Write 'Tuesday'.
  WHEN 3.
    Write 'Wednesday'.
  WHEN 4.
    Write 'Thrusday'.
  WHEN 5.
    Write 'Friday'.
  WHEN 6.
    Write 'Saturday'.
  WHEN 7.
    Write 'Sunday'.
  WHEN OTHERS.
    Write 'Invalid Day'.
ENDCASE.



Previous                                                 Next                                                 Home

No comments:

Post a Comment