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

Former Member
0 Likes
808

Hi,

I have a requirement where in i have to check for amount field should be between -1 and 1.

I have kept the condition as amount_field LE 1 and amount_field GT -1. But the problem is it is passing any thing less between -1.5 to 1.5. Pls let me know how to put this condition so it will take between -1 and 1.

Thanks,

Raju

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
780

TYPES : BEGIN Of TP_VAL1,

val1 TYPE p DECIMALS 2,

end of tp_val1.

DATA: wl_val1 type tp_val1,

t_val1 TYPE STANDARD TABLE OF tp_val1,

w_custom TYPE int2.

l_val1-val1 = '1.2'. APPEND wl_val1 to t_val1.

wl_val1-val1 = '0.9'. APPEND wl_val1 to t_val1.

wl_val1-val1 = '-0.6'. APPEND wl_val1 to t_val1.

wl_val1-val1 = '1.9'. APPEND wl_val1 to t_val1.

wl_val1-val1 = '-1.6'. APPEND wl_val1 to t_val1.

wl_val1-val1 = '1.49'. APPEND wl_val1 to t_val1.

wl_val1-val1 = '-1.46'. APPEND wl_val1 to t_val1.

clear w_custom.

LOOP AT t_val1 INTO wl_val1.

IF wl_val1-val1 LE '1' AND wl_val1-val1 GT '1'. "Same as what you have given

ADD 1 TO w_custom.

ENDIF.

ENDLOOP.

The output i'm getting is 2 ( which is correct )

Can you check again? I don't believe there is a problem in the IF statement. Problem could be in the data type of amount_field.

Thanks

Sujay

6 REPLIES 6
Read only

Former Member
0 Likes
780

Hi,

Try this,

If amount_field gt '-1' and amount_field lt '1'.

Thanks,

Venkat

Edited by: venkatramana k on Aug 19, 2010 7:05 PM

Read only

Former Member
0 Likes
780

you have decimals in the field? You're being affected by the rounding for that data type? Try something like:

data: lv_low(5) type p decimals 1 value '-1.0',  "or same type as your data.
        lv_high(5) type p decimals 1 value '1.0'.

If <field> gt lv_low and <field> lt lv_high.

Read only

Former Member
0 Likes
781

TYPES : BEGIN Of TP_VAL1,

val1 TYPE p DECIMALS 2,

end of tp_val1.

DATA: wl_val1 type tp_val1,

t_val1 TYPE STANDARD TABLE OF tp_val1,

w_custom TYPE int2.

l_val1-val1 = '1.2'. APPEND wl_val1 to t_val1.

wl_val1-val1 = '0.9'. APPEND wl_val1 to t_val1.

wl_val1-val1 = '-0.6'. APPEND wl_val1 to t_val1.

wl_val1-val1 = '1.9'. APPEND wl_val1 to t_val1.

wl_val1-val1 = '-1.6'. APPEND wl_val1 to t_val1.

wl_val1-val1 = '1.49'. APPEND wl_val1 to t_val1.

wl_val1-val1 = '-1.46'. APPEND wl_val1 to t_val1.

clear w_custom.

LOOP AT t_val1 INTO wl_val1.

IF wl_val1-val1 LE '1' AND wl_val1-val1 GT '1'. "Same as what you have given

ADD 1 TO w_custom.

ENDIF.

ENDLOOP.

The output i'm getting is 2 ( which is correct )

Can you check again? I don't believe there is a problem in the IF statement. Problem could be in the data type of amount_field.

Thanks

Sujay

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
780

I dont think you need a lt and gt

if lv_val between '-1' and '1'.

endif.

Also check the decimals places, type i will just convert the decimal value to its nearest integer.

Read only

0 Likes
780

Nothing wrong with the IF condition.

Amount type declaration is converting the amount to the nearest integer that is one. In debugging you will see the value and understand why the IF condition is failing

Read only

Former Member
0 Likes
780

nothing wrong with the if the problem can be the rounding try using 1 decimal or use


DATA: ZM_PRUEBA(3) TYPE P DECIMALS 2 VALUE '1.2'.

IF ZM_PRUEBA BETWEEN 1 and -1.
 WRITE: 'fail'.
ELSE.
 WRITE: 'done'.
ENDIF.