2009 Jan 20 1:49 AM
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
2009 Jan 20 1:50 AM
2009 Jan 20 1:56 AM
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?
2009 Jan 20 2:02 AM
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
2009 Jan 20 2:07 AM
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
2009 Jan 20 2:32 AM
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
2009 Jan 20 2:39 AM
hi Creasy,
Try using IF.....ElseIf....endif. Hope that should solve your problem.
Regards,
Shano
2009 Jan 20 2:47 AM
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.
2009 Jan 20 3:03 AM
2009 Jan 20 1:58 AM
Hi Mathew,
The Pseudo code written by you is right.
what else you would like to know., in this.. Pls.
Regards,
GP
2009 Jan 20 3:39 AM
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.
2009 Jan 20 3:59 AM
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
2013 Nov 26 3:41 PM
So... if the IDoc segment table starts with the value '002' this will fail miserably I think...
Regards,
Bruno
2013 Nov 26 3:36 PM
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
2013 Nov 26 3:47 PM
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
2013 Nov 26 5:01 PM
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.
2013 Nov 26 5:51 PM
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
2013 Nov 27 6:30 AM
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
2013 Nov 27 7:54 AM
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
2013 Nov 27 7:56 AM
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
2013 Nov 27 8:32 AM
Hi Bruno,
But in single quotes it is case sensitive.
Regards
Bharath
2013 Nov 27 8:39 AM
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
2013 Nov 27 5:24 PM
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.
2013 Nov 27 6:22 AM
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