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

If condition failed

Ranjith_D_Reddy
Participant
0 Likes
4,987

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.

31 REPLIES 31
Read only

matt
Active Contributor
0 Likes
4,235

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'

Read only

former_member209120
Active Contributor
0 Likes
4,235

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 .


Read only

0 Likes
4,235

This message was moderated.

Read only

0 Likes
4,235

Acutually we are making use of the decimal number to compare in the IF condition as '5.5'

Read only

0 Likes
4,235

Are you saying that v_rem is defined as a decimal? What is the EXACT data type?

Read only

0 Likes
4,235

Thanks !Matthew's we are using the CHAR value data type to that

Read only

0 Likes
4,235

Remove ' ' in between 5.5 and try

Read only

0 Likes
4,235

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.

Read only

0 Likes
4,235

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.

Read only

former_member188827
Active Contributor
0 Likes
4,235

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

Read only

Former Member
0 Likes
4,235

Hi Ranjith,

Check yr code for if condition  to some part u did not passed in single quote.

Kindly check it.

Thanks.

Pavan.N

Read only

former_member196490
Active Participant
0 Likes
4,235

what is the data type of V_REM. Remove the quotes from '5.5' and try again

Read only

0 Likes
4,235

"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.

Read only

thangam_perumal
Contributor
0 Likes
4,235

Mr Ranjith,

                I think data type only the problem,Please change the Data type as F and Once again do it.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
4,235

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

Read only

0 Likes
4,235

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"

Read only

former_member189845
Active Participant
0 Likes
4,235

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

Read only

UweFetzer_se38
Active Contributor
0 Likes
4,235

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".

Read only

Former Member
0 Likes
4,235

Hi.

try changing 5.5 for 5,5.

Regards

Read only

0 Likes
4,235

Why should this work? Can you explain?

Read only

0 Likes
4,235

it wont work....i just checked...mistake

Read only

VijayaKrishnaG
Active Contributor
0 Likes
4,235

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

Read only

0 Likes
4,235

Why?

Read only

0 Likes
4,235

hi Vijay,

the logic u said didn't wrk

Read only

0 Likes
4,235

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

Read only

0 Likes
4,235

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

Read only

0 Likes
4,235

Hi Ranjith,

Your Problem Solved or Not?

Read only

0 Likes
4,235

ya the prblem is solved

Read only

0 Likes
4,235
Read only

UweFetzer_se38
Active Contributor
0 Likes
4,235

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'

Read only

Former Member
0 Likes
4,235

Hi.

Use this insted of hard code '5.5'.

constants: p_num type p decimals 2 value '5.5'.

it will work

Regards