
- SAP ABAP - Home
- SAP ABAP - Overview
- SAP ABAP - Environment
- SAP ABAP - Screen Navigation
- SAP ABAP - Basic Syntax
- SAP ABAP - Data Types
- SAP ABAP - Variables
- SAP ABAP - Constants & Literals
- SAP ABAP - Operators
- SAP ABAP - Loop Control
- SAP ABAP - Decisions
- SAP ABAP - Strings
- SAP ABAP - Date & Time
- SAP ABAP - Formatting Data
- SAP ABAP - Exception Handling
- SAP ABAP - Dictionary
- SAP ABAP - Domains
- SAP ABAP - Data Elements
- SAP ABAP - Tables
- SAP ABAP - Structures
- SAP ABAP - Views
- SAP ABAP - Search Help
- SAP ABAP - Lock Objects
- SAP ABAP - Modularization
- SAP ABAP - Subroutines
- SAP ABAP - Macros
- SAP ABAP - Function Modules
- SAP ABAP - Include Programs
- SAP ABAP - Open SQL Overview
- SAP ABAP - Native SQL Overview
- SAP ABAP - Internal Tables
- SAP ABAP - Creating Internal Tables
- ABAP - Populating Internal Tables
- SAP ABAP - Copying Internal Tables
- SAP ABAP - Reading Internal Tables
- SAP ABAP - Deleting Internal Tables
- SAP ABAP - Object Orientation
- SAP ABAP - Objects
- SAP ABAP - Classes
- SAP ABAP - Inheritance
- SAP ABAP - Polymorphism
- SAP ABAP - Encapsulation
- SAP ABAP - Interfaces
- SAP ABAP - Object Events
- SAP ABAP - Report Programming
- SAP ABAP - Dialog Programming
- SAP ABAP - Smart Forms
- SAP ABAP - SAPscripts
- SAP ABAP - Customer Exits
- SAP ABAP - User Exits
- SAP ABAP - Business Add-Ins
- SAP ABAP - Web Dynpro
SAP ABAP - Case Control Statement
The CASE control statement is used when you need to compare two or more fields.
The syntax for CASE control statement is as follows −
CASE <field>. WHEN <abc>. <statement block>. WHEN <def>. <tatement block>. WHEN <pqr>. <statement block>. ...... ...... ...... WHEN <xyz>. <statement block>. WHEN OTHERS. <statement block>. ENDCASE.
The following rules apply to a CASE statement −
No logical expressions can be used for the <field> field.
The field strings used in the CASE statement are treated as type C variables.
The statement block following a WHEN clause is executed if the content of the fields shown in the <field> is similar to one of the fields <abc>, <def>, <ghi> up to <xyz>.
After executing all the conditions specified in the WHEN statement, the program continues to process the remaining statements after the ENDCASE statement.
The WHEN OTHERS clause is executed in a program when the value of the <field> does not match with any value specified in the <abc> up to <xyz> fields of the WHEN clause.
If the WHEN OTHERS clause is omitted and the value of the <field> does not match with any value specified in the <abc> up to <xyz> fields of the WHEN clause, the program continues to process the remaining statements after the ENDCASE statement.
Flow Diagram

Example
Report YH_SEP_15. Data: Title_1(10) TYPE C, Title_2(15) TYPE C. Title_1 = 'ABAP'. Title_2 = 'Programming'. CASE Title_2. WHEN 'ABAP'. Write 'This is not the title'. WHEN 'Tutorials'. Write 'This is not the title'. WHEN 'Limited'. Write 'This is not the title'. WHEN 'Programming'. Write 'Yes, this is the title'. WHEN OTHERS. Write 'Sorry, Mismatch'. ENDCASE.
The above code produces the following output −
Yes, this is the title.