09-17-2008 12:34 AM
Hi,
I'm new to ABAP, please help me with the below code. When i check the code i get the message "E:Incorrect logical expression: Comparison / SELECT-OPTION can only be followed by "AND", "OR" or ")".
data: pphd(7) type p decimals 2,
ppha(7) type p decimals 2,
abs_pphd(7) type p decimals 2.
if pphd >= 0.
if pphd < 1.
ppha = 0.
elseif 1 <= pphd <= 4.
ppha = '0.16'.
elseif 4.01 <= pphd <= 8.
ppha = '0.32'.
elseif 8.01 <= pphd <= 12.
ppha = '0.50'.
elseif 12.01 <= pphd <= 16.
ppha = '0.66'.
elseif 16.01 <= pphd <= 20.
ppha = '0.83'.
elseif 20.01 <= pphd <= 24.
ppha = '1.00'.
elseif 24.01 <= pphd <= 28.
ppha = '1.16'.
elseif 28.01 <= pphd <= 32.
ppha = '1.32'.
elseif pphd >= 32.
ppha = '1.50'.
endif.
else.
abs_pphd = abs( pphd ).
if abs_pphd < 1.
abs_ppha = 0.
elseif 1 <= abs_pphd <= 4.
ppha = '-0.16'.
elseif 4.01 <= abs_pphd <= 8.
ppha = '-0.32'.
elseif 8.01 <= abs_pphd <= 12.
ppha = '-0.50'.
elseif 12.01 <= abs_pphd <= 16.
ppha = '-0.66'.
elseif 16.01 <= abs_pphd <= 20.
ppha = '-0.83'.
elseif 20.01 <= abs_pphd <= 24.
ppha = '-1.00'.
elseif 24.01 <= abs_pphd <= 28.
ppha = '-1.16'.
elseif 28.01 <= abs_pphd <= 32.
ppha = '-1.32'.
elseif abs_pphd >= 32.
ppha = '-1.50'.
endif.
endif.
Thanks,
AM
09-17-2008 1:02 AM
Change all your 'IF' conditions to use BETWEEN instead.
eg: Use elseif pphd between 1 and 4.
instead of elseif 1 <= pphd <= 4.
Award points, if it helps.
Edited by: Raj Julakanti on Sep 17, 2008 2:03 AM
09-17-2008 1:02 AM
Change all your 'IF' conditions to use BETWEEN instead.
eg: Use elseif pphd between 1 and 4.
instead of elseif 1 <= pphd <= 4.
Award points, if it helps.
Edited by: Raj Julakanti on Sep 17, 2008 2:03 AM
09-17-2008 1:26 AM
Hi Raj,
Thanks a lot for the reply. i modified the code as you suggested but i get the error "E:Incorrect logical expression: Only "... BETWEEN AND ..." is expected." Below is the modified code.
data: pphd(7) type p decimals 2,
ppha(7) type p decimals 2,
abs_pphd(7) type p decimals 2.
if pphd >= 0.
if pphd < 1.
ppha = 0.
elseif pphd between 1 and 4.
ppha = '0.16'.
elseif pphd between 4.01 and 8.
ppha = '0.32'.
elseif pphd between 8.01 and 12.
ppha = '0.50'.
elseif pphd between 12.01 and 16.
ppha = '0.66'.
elseif pphd between 16.01 and 20.
ppha = '0.83'.
elseif pphd between 20.01 and 24.
ppha = '1.00'.
elseif pphd between 24.01 and 28.
ppha = '1.16'.
elseif pphd between 28.01 and 32.
ppha = '1.32'.
elseif pphd >= 32.
ppha = '1.50'.
endif.
else.
abs_pphd = abs( pphd ).
if abs_pphd < 1.
ppha = 0.
elseif abs_pphd between 1 and 4.
ppha = '-0.16'.
elseif abs_pphd between 4.01 and 8.
ppha = '-0.32'.
elseif abs_pphd between 8.01 and 12.
ppha = '-0.50'.
elseif abs_pphd between 12.01 and 16.
ppha = '-0.66'.
elseif abs_pphd between 16.01 and 20.
ppha = '-0.83'.
elseif abs_pphd between 20.01 and 24.
ppha = '-1.00'.
elseif abs_pphd between 24.01 and 28.
ppha = '-1.16'.
elseif abs_pphd between 28.01 and 32.
ppha = '-1.32'.
elseif abs_pphd >= 32.
ppha = '-1.50'.
endif.
endif.
09-17-2008 1:38 AM
1, 4, 4.01 should be inside quotes:
elseif pphd between '1.00' and '4.00'.
Also be careful when comparing characters and decimals. Characters are compared left to right.
Better use:
CONSTANTS: c_1 type p decimals 2 value '1.00',
c_4 type p decimals 2 value '4.00'.
.....
elseif pphd between c_1 and c_4.
and similiar.