Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

case statement

Former Member
0 Likes
3,996

what is case statement

7 REPLIES 7
Read only

former_member69765
Contributor
0 Likes
1,641

I think you must first go and read some documentation on ABAP and other basic things instead of just hosting a Quiz contest over here .

1st go and read ur self.. then If u have doubts come to SDN.

All the questions that you have asked are very basic questions that can be understood just by reading some material.

Read only

Former Member
0 Likes
1,641

a case statement is an abap syntax, which wil help you to brach to one of the multiple paths available based on a value.

eg:

case value.

when 1.

  • do something.

when 2.

  • do something else.

when 3.

  • do something else..

when others.

  • do some other thing.

endcase.

Regards,

Ravi

Read only

Former Member
0 Likes
1,641

Case is an ABAP Syntax which will allow u to execute the part depending on the field value in when condition.

E.g

CASE sy-ucomm.

WHEN 'BACK'.

LEAVE TO SCREEN 100.

WHEN 'CANCEL'.

LEAVE SCREEN.

WHEN 'EXIT'.

LEAVE PROGRAM.

WHEN OTHERS.

MESSAGE '...' TYPE 'E'.

ENDCASE.

Read only

Former Member
0 Likes
1,641

Case statement in ABAP is same as C language for exam:

case value.

when 1.

  • do something.

when 2.

  • do something else.

when 3.

  • do something else..

when others.

  • do some other thing.

endcase.

Its always preferred to use case statement rather than if else ladder. The case statement internaly generates the binary search to satisfy the "Value". If-else ladder is like linear search.

Hope this helps u to understand case statement.

Read only

Former Member
0 Likes
1,641

FYA

I think you must first go and read some documentation on ABAP and other basic things instead of just hosting a Quiz contest over here .

1st go and read ur self.. then If u have doubts come to SDN.

All the questions that you have asked are very basic questions that can be understood just by reading some material.

Read only

Former Member
0 Likes
1,641

Hi Abhay Singh

Syntax

CASE operand.

[WHEN operand1 [OR operand2 [OR operand3] ...].

[statement_block1] ]

...

[WHEN OTHERS.

[statement_blockn] ]

ENDCASE.

Effect

These statements define a control structure that can contain multiple statement blocks statement_block1 ... statement_blockn, of which no more than one is executed depending on the value in the operand operand.

Starting with the first WHEN-statement, the content of the operand operand is compared with the content of the operand operand1 operand2 ... in a descending order. The statement block is executed after the first identical instance is found. If no matches are found, the statement block is executed after the statement WHEN OTHERS.

For operand, operand1, operand2 , ...you can use the data object built-in functions and functional methods. With the latter, you receive the return value as an operand.

If the end of the executed statement block is reached or no statement block is executed, then the processing continues after ENDCASE.

For the comparison of the contents, the following logical expression can be used:

operand = operand1 [OR operand = operand2 [OR operand = operand3] ... ]

For the execution of the comparison with dependency on the data types of the involved operands, the same rules apply as described in the section Relational Operators for all Data Types.

Note

You cannot use a statement between the statement CASE and the first statement WHEN

Example

Linking the program flow according to the function code in the system field sy-ucomm.

CASE sy-ucomm.

WHEN 'BACK'.

LEAVE TO SCREEN 100.

WHEN 'CANCEL'.

LEAVE SCREEN.

WHEN 'EXIT'.

LEAVE PROGRAM.

WHEN OTHERS.

MESSAGE '...' TYPE 'E'.

ENDCASE.