09-24-2008 8:20 AM
Hi friends
iam using the below code and can any one tell me why even after assigning the value in the case statement it coming out of it.
code
data :
p1(1) type n.
case p1.
when '0'.
write 'sunday'.
p1 = 1.
when '1'.
write 'monday'.
p1 = 2.
when others.
write 'invalid day'.
endcase.
output.
sunday
can any one tell me why it is coming out of the case statement even iam assigning p1 = 1
09-24-2008 9:19 AM
hi,
once one WHEN condition was found true, it will jump to ENDCASE, no other conditions will be checked.
you can do something like this:
WHILE condition.
CASE ... => your code from above
...
ENDCASE.
ENDWHILE.
hope this helps
ec
09-24-2008 8:23 AM
Hi,
It is working as it should.
each of the when block acts exactly similar to if....elseif....else...endif. block.
when one of the block is satisfies by your value , the cursor will jump to the ENDCASE statement only.
So even you update the value of p1, it will not go to the next when block.
There is no room for break or similar statement in ABAP as we used in C for case.
Regards,
Anirban
09-24-2008 8:24 AM
Hi,
Try like this:
parameters: p1(1) type n.
case p1.
when '0'.
write 'sunday'.
when '1'.
write 'monday'.
when others.
write 'invalid day'.
endcase.
Regards,
Bhaskar
09-24-2008 8:24 AM
This is happening b'cause u have already in the when clause where u r setting the value of the variable that is controlling ur case..endcase statement.To meet ur requirement u need to trigger the case..endcase statement again as shown below:
data :
p1(1) type n.
do 3 times.
case p1.
when '0'.
write 'sunday'.
p1 = 1.
when '1'.
write 'monday'.
p1 = 2.
when others.
write 'invalid day'.
endcase.
enddo.
09-24-2008 8:34 AM
after executing the first case, it comes out of the case and does not check other cases.
09-24-2008 8:41 AM
ya its coming out of the case statement after displaying sunday.
is do n times
enddo
is the only solution to print all the when conditions are do we have any other alternative for that.
Regards
PRIYANKA.
09-24-2008 8:46 AM
09-24-2008 8:49 AM
even for if endif also iam facing the same problem.
Regards
priyanka
09-24-2008 9:15 AM
Hi priyanka,
that's what I would like you to say in my previous post above.
Both IF....ENDIF.
and CASE....ENDCASE will behabe same way.
and if you use do....enddo. to get all the cases executed, what is the requirment of case...endcase.
you can get them directly.
Isn't it?
Regards,
Anirban
09-24-2008 9:08 AM
hi,
do like this
parameters: p1(1) type n.
do n times.
case p1.
when '0'.
write 'sunday'.
when '1'.
write 'monday'.
when others.
write 'invalid day'.
endcase.
p1 = p1 + 1.
enddo.
09-24-2008 9:19 AM
hi,
once one WHEN condition was found true, it will jump to ENDCASE, no other conditions will be checked.
you can do something like this:
WHILE condition.
CASE ... => your code from above
...
ENDCASE.
ENDWHILE.
hope this helps
ec