How to use the case Statement in SAP

The case statement performs a series of comparisons. Syntax for the case Statement

The following is the syntax for the case statement.

case v1.
when v2 [ or vn ... ].

when v3 [ or vn ... ].

[ when others.
--- ]
endcase.

where:
* v1 or v2 can be a variable, literal, constant, or field string.
* — represents any number of lines of code. Even zero lines are allowed.

The following points apply:
* Only statements following the first matching when are executed.
* when others matches if none of the preceding whens match.
* If when others is not coded and none of the whens match, processing continues with the first statement following endcase.
* Expressions are not allowed.
* Field strings are treated as type c variables.

Case is very similar to if/elseif. The only difference is that on each if/elseif, you can specify a complex expression. With case, you can specify only a single value to be compared, and values are always compared for equality.

Popularity: 5% [?]

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • Slashdot
  • StumbleUpon
  • Reddit

Leave a Reply

You must be logged in to post a comment.