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
1,552

Is it necessary that a case statement should always be followed by a when statement?? i mean will i get any error if i dont do the same?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,365

Hi Sneha..

U can use Case statement like this ....this is the example case statement formate....

CASE .

WHEN .

WHEN .

WHEN OTHERS.

ENDCASE.

Reward me points ..

By

Pari

11 REPLIES 11
Read only

Former Member
0 Likes
1,365

without when what is the use of case

Read only

Former Member
0 Likes
1,365

when is mandatory

for what do you need this info ?

regards

Read only

0 Likes
1,365

i mean i know when is mandatory... what i wanted to know is wht if my stucture is sumthing like this ......

case abc.

sum lines of code here.................

when '1'.

...............

Read only

0 Likes
1,365

Hi,

You should have at least one when.

with is case...endcase the first statement should be the WHEN.

if u want to write some condition statements(i.e,irrespective of whens)

write them before the case...endcase.

rgds,

bharat.

Read only

0 Likes
1,365

Hi sneha

might be u have not used endcase.

try this it will work

case sy-ucomm.

when '1'.

-


-


endcase.

Read only

0 Likes
1,365

hi,

wht error u r getting ..

Read only

Former Member
0 Likes
1,366

Hi Sneha..

U can use Case statement like this ....this is the example case statement formate....

CASE .

WHEN .

WHEN .

WHEN OTHERS.

ENDCASE.

Reward me points ..

By

Pari

Read only

Former Member
0 Likes
1,365

U will not get any error .

But there is no use of such a statement.

case v_check.

endcase.

Read only

prasanth_kasturi
Active Contributor
0 Likes
1,365

hi,

there is no point of using a case statement without when.

if you dont use u will get a warning saying case must be folloed by when.

reward if helpful

prasanth

Read only

Former Member
0 Likes
1,365

Hi,

I dont think it is can ever be a requirement for discussion

However, in short, there are specific requirements and mandatory rules/ syntax in every language, and is same in ABAP as well.

Pts to remember in Case-Endcase:

Pt1) A Case-EndCase should have atleast one When statement.

Pt2) You cannot write any statement between Case and the first When statement.

In otherwords, When must be the first statement after a Case statement.

Hope it answers you query

Regards, Tapas

Read only

Former Member
0 Likes
1,365

Hi Sneha,

You wont be getting any error without using WHEN with CASE, but it wont give u any fruitful results, as it will come out of processing without any condition.

Instead of this, try IF....ENDIF.

--

Prateek.