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

ABAP - Case Statement

Former Member
0 Likes
27,628

Hi ABAPers,

I have an ABAP code just like the pseudo code below.

 
Case Val.

When 'A'.

<Some Conditional Statements>.

When 'B'.

<Some Statements>.

endcase.

A and B values are depend on 'Val'.

My program executes the above code almost everytime. when the conditional statement of Case (A) is successful, then I dont want my program to execute the case(B).

When the conditional statement of case(A) is unsuccessful, then only i want to execute case (B). Can anyone please tell me how to correct my code to suit the above situation.

Thanks,

Creasy Matt

Edited by: Vijay Babu Dudla on Jan 19, 2009 11:20 PM

23 REPLIES 23
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
3,894

Yea, you are coding it right. What's the problem?

Regards,.

Rich Heilman

Read only

0 Likes
3,894

The problem is most of the time , the value of 'VAL' can be A and B at the same time.

I don't want both the 'WHEN' statements to be executed.

I want to modify the above code in a way that if the 'WHEN' statement 'A' is success, i don't want to execute 'WHEN' statement 'B'.

I hope you got the problem now.

What should i do to correct it?

Read only

0 Likes
3,894

Hi Mathew,

As the Pseudo code written by you

Case Val.

When 'A'.

<Some Conditional Statements>.

When 'B'.

<Some Statements>.

endcase.

---

you won't get such true conditional , both the WHEN executed in a single Check... do you?

Regards,

GP

Read only

0 Likes
3,894

the value of 'VAL' can be A and B at the same time

THat, my friend, is an impossibility. The CASE statement that you have coded is correct. There is really nothing more I can say about it. If the value of VAL = A, then that code under the WHEN 'A' statement will be executed, and then processing will leave the CASE statement, and not do the code under the WHEN 'B' statement. If the value of VAL = B, then it will do the reverse.

Regards,

Rich Heilman

Read only

0 Likes
3,894

There is one case.

Case IDocSegment-QUALF.

When '001'

<Some statements>.

When '002'.

<Some statements>.

endcase. 

An IDoc segment can have two qualifiers in the same IDoc.

E1EDK02-QUALF = '001' = Customer PO

E1EDK02-QUALF = '002' = Sales Order No.

So there is a case. In my case, all the IDocs contain both the qualifiers. It executes both the 'WHEN' statements. I don't want to. I want only one 'WHEN' statment to be executed depending upon the success of the first 'WHEN' statement.

I hope you clearly understand now. Sorry for the confusion.

What can i do in this situation. Please reply.

Thanks ,

Creasy Matt

Edited by: Creasy Matthew on Jan 20, 2009 3:32 AM

Read only

0 Likes
3,894

hi Creasy,

Try using IF.....ElseIf....endif. Hope that should solve your problem.

Regards,

Shano

Read only

0 Likes
3,894

Nope.

If qualf = '001'.

Executes this part.

elseif qualf = '002'.

Always this part will be skipped.

endif.

I dont think it will solve my problem.

Anyway thanks for your advice. Anymore suggestions.

Read only

0 Likes
3,894

Well, then this coding would have to be inside some loop. If idocsegment is an internal table, then you must loop through the records.

Loop at idocsegment. 

Case IDocSegment-QUALF.
 
When '001'
 
<Some statements>.
 
When '002'.
 
<Some statements>.
 
endcase. 

endloop.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
3,894

Hi Mathew,

The Pseudo code written by you is right.

what else you would like to know., in this.. Pls.

Regards,

GP

Read only

Former Member
0 Likes
3,894

Hi Creasy Matt,

Just check how did you declare VAL type it should either C or a STRING, If not this case will allow all time.

Regards,

sg.

Read only

0 Likes
3,894

Guys,

I finally get it.

 Case IDocSegment-QUALF.
 
When '001'
 
<Some statements>.

Exit.
 
When '002'.
 
<Some statements>.
 
endcase. 
 

Thanks for all your time.

Regards,

Creasy Matt

Read only

0 Likes
3,894

So... if the IDoc segment table starts with the value '002' this will fail miserably I think...

Regards,

Bruno

Read only

Former Member
0 Likes
3,894

Why case statement does  not support for small alphabet letters ( a, b, c,..z) ?

here i have attached some code .. this is not working for small letters but works for caps letter.

what is the reason . ?

PARAMETERS: uname(10) TYPE C.
CASE uname.
   WHEN 'karthi'" but work for caps letter . when 'KARTHI'.
     WRITE: ' user name is' ,uname.
   WHEN OTHERS.
     WRITE 'Your name is not karthi'.
ENDCASE.

Thank you friends


Read only

0 Likes
3,894

Hi Karthi,

You should post this question on a new topic.

However, the answer for you is that type C does not differentiate between lower and upper case (it automatically translates to upper case).

Therefore, when you execute the program the variable 'uname' will always be in upper case.

If you want to differentiate between upper and lower case you need to use another data element with the respective check box ticked:

Regards,

Bruno

Read only

0 Likes
3,894

Thank you Bruno Esperanca. How to create new post here? i couldn't find it . that's why i post here. anyway thanks a lot for your information.

Read only

0 Likes
3,894

In selection screen all the character value which we give will convert into uppercase because SAP thinks that we will be using as a key to retrieve data from tables. if you want only lowercase then you can go with bruno suggestion .

Thanks

Saikrishna

Read only

0 Likes
3,894

Hi,

try this

PARAMETERS: uname(10) TYPE c.
TRANSLATE uname TO LOWER CASE.
CASE uname.
   WHEN 'karthi'" but work for caps letter . when 'KARTHI'.
     WRITE: ' user name is' ,uname.
   WHEN OTHERS.
     WRITE 'Your name is not karthi'.
ENDCASE.

Regards

Bharath

Read only

0 Likes
3,894

You're welcome Karthi!

To post a new discussion, scroll all the way up, click on the link "ABAP Development", then on your right in the 'Actions' pane click on "Start a new discussion".

It would be cool as I haven't had a "right answer" yet for my missions badges, but it's ok you don't need to create a new discussion only for this if you don't want to

Regards,

Bruno

Read only

0 Likes
3,894

Hi Bharath,

If he tries it like that it will not work for upper case...

I think what he wants is a case-sensitive input field.

Regards,

Bruno

Read only

0 Likes
3,894

Hi Bruno,

But in single quotes it is case sensitive.

Regards

Bharath

Read only

0 Likes
3,894

Exactly.

So with your code what happens when the user types "KARTHI" in parameter uname?

I'm betting it will go in the 'karthi' case, instead of the 'KARTHI' one, which would be the correct one.

Regards,

Bruno

Read only

0 Likes
3,894

Hi Bharath kumar i tried that code which you sent . but it works for both caps letter and small letter as well. i want to check 'karthi' only. if i enter 'KARTHI' it should print '

Your name is not karthi'.  I think it doesn't differentiate the case sensitive . anyway thanks lot for your help . we will find the correct solution for this problem.

Read only

former_member221372
Participant
0 Likes
3,894

Hi,

Both at a time is not possible,but as you are saying that is possible then use OTHERS.

Case VAL.

when 'A'.

Logic

when 'B'.

Logic

when others.

Logic

endcase.

Regards

Bharath