‎2013 Jun 24 8:51 AM
We are facing one issue in the below mentioned code
As per debugging the value we are passing in V_REM =13
But the control is executing the code in line Num:1327 .Actually the condition should fail as per the value passed ,but in this case it is not happening.
regards,
ranjith.
‎2013 Jun 24 9:12 AM
What is the type of v_rem? And I assume you mean line 1328 is being executed?
Note: 4 without quotes is not the same as '4'
‎2013 Jun 24 9:24 AM
Hi Ranjith,
Use if condition like this, it should be clear to analyze.
data : a(4) type C,
b(4) type C,
c(4) type C.
a = 10.
b = 11.
c = 12.
if a gt 4 and a le 10.
Write : 'Hi 4'.
elseif a gt 11 and a le 20.
Write : 'Hi 9'.
endif.
What every you used if condition totally confusing, please make if condition like above and try, you will get answer .
‎2013 Jun 24 9:58 AM
‎2013 Jun 24 9:58 AM
Acutually we are making use of the decimal number to compare in the IF condition as '5.5'
‎2013 Jun 24 10:02 AM
Are you saying that v_rem is defined as a decimal? What is the EXACT data type?
‎2013 Jun 24 10:07 AM
Thanks !Matthew's we are using the CHAR value data type to that
‎2013 Jun 24 10:18 AM
‎2013 Jun 24 10:42 AM
Here's some sample code. Type it into the abap editor, then do a syntax check.
DATA: v_rep type c length 80.
IF v_rep GT 4 and LT 5.5
ENDIF.
Please think before posting.
‎2013 Jun 24 10:44 AM
Define v_rem_f as type f. Then do v_rem_f = v_rem. Use v_rem_f for your comparison and enclose all numbers that you are comparing with in quotes.
If your data is defined as character, the system will do a character comparison - not a numeric comparison.
‎2013 Jun 24 9:30 AM
what is the value in "EX_MVGR3"? Line no 1327 will be processed as system would check the "if" condition but control should not go to 1328 in your case.
Regards
‎2013 Jun 24 9:40 AM
Hi Ranjith,
Check yr code for if condition to some part u did not passed in single quote.
Kindly check it.
Thanks.
Pavan.N
‎2013 Jun 24 9:47 AM
what is the data type of V_REM. Remove the quotes from '5.5' and try again
‎2013 Jun 24 1:17 PM
"Remove the quotes from '5.5'? Why don't you actually try that and see what happens. Here's some sample code. Type it into the abap editor, then do a syntax check.
DATA: v_rep type c length 80.
IF v_rep GT 4 and LT 5.5
ENDIF.
Please think before posting.
‎2013 Jun 24 11:25 AM
Mr Ranjith,
I think data type only the problem,Please change the Data type as F and Once again do it.
‎2013 Jun 24 12:23 PM
Better define such constants as CONSTANTS in your program, define those with same definition as the variable you compare with, so no implicit conversion would be involved during comparison.
Regards,
Raymond
‎2013 Jun 25 5:23 AM
This is very good advice. Read this link about good programming practice and "magic numbers". Use arbitrary numbers directly in your program code is "...breaking one of the oldest rules of programming"
‎2013 Jun 24 12:33 PM
Hi Ranjith,
Plz check the below code,,
data: v_rem type c length 2 value 13.
if v_rem gt '4' and v_rem le '5.5'.
v_rem = 432.
else.
IF v_rem gt 15 and v_rem le 22.
v_rem = 111.
ENDIF.
endif.
write: v_rem.
if u use '4' like that den the if condition will fail. is this satisfy ur thing ?
Thx,
Siva
‎2013 Jun 24 2:29 PM
SAP is working correctly (if V_REM is really a CHAR):
"13" IS lower "4" and lower "5.5" because it starts with a "1".
Sorry, have to correct me:
"13" IS greater 4 (number conversion) but lower "5.5" because it starts with a "1".
‎2013 Jun 24 3:05 PM
‎2013 Jun 24 3:22 PM
‎2013 Jun 24 3:47 PM
‎2013 Jun 24 3:26 PM
Hi Ranjith,
As you declared the variable V_REM as CHAR, you have to maintain the ' ' (quotes) for both the values in the IF Condition.
Example:
IF V_REM LT '4' AND V_REM GT '5.5'.
*code
ELSE.
*code
ENDIF.
Thanks & Regards,
- Vijay
‎2013 Jun 24 7:06 PM
‎2013 Jun 25 1:11 PM
‎2013 Jun 25 3:22 PM
Hi Ranjith,
Yeah, that may not be worked out. I have tried only with the values you mentioned. But after reply from Former Member I checked with other values too, then it is not working. Once go through his reply, he explained well.
Sorry.
Thanks & Regards,
Vijay
‎2013 Jun 26 4:48 AM
Hi Ranjith,
Please try like this
TYPES : BEGIN OF ty_final,
a(10) TYPE C,
b(10) TYPE c,
c(10) TYPE c,
END OF ty_final.
DATA : it_final TYPE TABLE OF ty_final,
wa_final TYPE ty_final.
wa_final-a = '4'.
wa_final-b = '4.5'.
wa_final-c = '12'.
APPEND wa_final TO it_final.
CLEAR wa_final.
wa_final-a = '9.5'.
wa_final-b = '14.5'.
wa_final-c = '12.2'.
APPEND wa_final TO it_final.
CLEAR wa_final.
wa_final-a = '8.4'.
wa_final-b = '4.5'.
wa_final-c = '12'.
APPEND wa_final TO it_final.
CLEAR wa_final.
wa_final-a = '11.5'.
wa_final-b = '8.50'.
wa_final-c = '0.20'.
APPEND wa_final TO it_final.
CLEAR wa_final.
LOOP AT it_final INTO wa_final.
IF wa_final-a GE 4 AND wa_final-a LE '5.5'.
WRITE 😕 '1', wa_final-a. " 11.5 getting from here
ELSEIF wa_final-a GT '5.5' AND wa_final-a LE 11.
WRITE 😕 '2', wa_final-a.
ELSEIF wa_final-a GT 11 AND wa_final-a LE 20.
WRITE 😕 '3', wa_final-a.
ENDIF.
CLEAR wa_final.
ENDLOOP.
Output:
TYPES : BEGINOF ty_final,
a(10) TYPE p DECIMALS 2,
b(10) TYPEc,
c(10) TYPEc,
ENDOF ty_final.
DATA : it_final TYPETABLEOF ty_final,
wa_final TYPE ty_final.
wa_final-a = '4'.
wa_final-b = '4.5'.
wa_final-c = '12'.
APPEND wa_final TO it_final.
CLEAR wa_final.
wa_final-a = '9.5'.
wa_final-b = '14.5'.
wa_final-c = '12.2'.
APPEND wa_final TO it_final.
CLEAR wa_final.
wa_final-a = '8.4'.
wa_final-b = '4.5'.
wa_final-c = '12'.
APPEND wa_final TO it_final.
CLEAR wa_final.
wa_final-a = '11.5'.
wa_final-b = '8.50'.
wa_final-c = '0.20'.
APPEND wa_final TO it_final.
CLEAR wa_final.
LOOPAT it_final INTO wa_final.
IF wa_final-a GE4AND wa_final-a LE'5.5'.
WRITE 😕 '1', wa_final-a.
ELSEIF wa_final-a GT'5.5'AND wa_final-a LE11.
WRITE 😕 '2', wa_final-a.
ELSEIF wa_final-a GT11AND wa_final-a LE20.
WRITE 😕 '3', wa_final-a. " 11.5 getting from here
ENDIF.
CLEAR wa_final.
ENDLOOP.
Output
See the difference in if condition above two programs
Change C type as P with decimals your problem will be solved....
Regards,
Ramesh.T
‎2013 Jun 26 7:32 AM
‎2013 Jul 02 10:40 AM
‎2013 Jul 03 1:00 PM
Read How to close a discussion and why (if I understood Ramesh T)
‎2013 Jun 24 7:16 PM
Please guys, don't just guess but think (or try it at least on your system).
If Ranjith is really not able to change the data type of V_REM (CHAR), the condition must also be a CHAR but with the same decimal places in front of the decimal point. The condition will be checked character wise from left to right.
alternative 1.) IF v_rem > '04' and v_rem <= '05.5'.....
alternative 2.) IF v_rem > 4 and v_rem <= '05.5' ...
'5.5' > '13' because '5' > '1'
'05.5' < '13' because '0' < '1'
‎2013 Jun 24 8:58 PM
Hi.
Use this insted of hard code '5.5'.
constants: p_num type p decimals 2 value '5.5'.
it will work
Regards