2005 Nov 07 6:23 AM
DATA ii TYPE i.
IF ( ii + 1 ) > 2.
WRITE: / 'more than 2'.
ENDIF.putting forward this error:
relational operator "+" is not supportedIs there any workaround or I have only left with inline functions and define macros.
DATA ii TYPE i.
IF ( ii + 1 ) > 2.
WRITE: / 'more than 2'.
ENDIF.putting forward this error:
relational operator "+" is not supportedIs there any workaround or I have only left with inline functions and define macros.
2005 Nov 07 6:31 AM
Hi,
try:
DATA ii TYPE i.
add 1 to ii.
IF ( ii ) > 2.
WRITE: / 'more than 2'.
ENDIF.
Andreas
2005 Nov 07 6:32 AM
HI Flora,
In abap you can't arithmatic ops in IF statement.
rather you do the ops and store the result in a variable, and use it in IF statement.
data sum type i.
......
......
sum = ii + 1.
if sum > 2
...
endif.
plz reward points if it helps you
2005 Nov 07 6:32 AM
Hi,
In IF u can use only Logical Expressions.
Do a F1 and check for the synax.
IF logexp.
Used for case distinction.
Depending on whether the logical expression logexp is true or not, this statement triggers the execution of various sections of code enclosed by IF and ENDIF.
There are three different types:
IF logexp.
processing1
ENDIF.
If the logical expression is true, processing1 is executed. Otherwise, the program resumes immediately after ENDIF.
IF logexp.
processing1
ELSE.
processing2
ENDIF.
If the logical expression is true, processing1 is executed. Otherwise, processing2 is executed (see ELSE).
IF logexp1.
processing1
ELSEIF logexp2.
processing2
ELSEIF ...
...
ELSE.
processingN
ENDIF.
If the logexp1 is false, logexp2 is evaluated and so on. You can use any number of ELSEIF statements. If an ELSE statement exists, it always appears after all the ELSEIF statements.
Reward points if this helps.
2005 Nov 07 6:33 AM
Hi,
The problem is because you used + in if st.
Try it in following way.
if i1 > 1.
write : / 'more than 2'.
endif.
Both are same logic.
Kindly reward points by clicking the star on the left of reply,if it helps.
2005 Nov 07 6:37 AM
Hi,
You can not use any arithmatic operators in a logical expression. If at it is required..a separate temporary variable should be assigned the value of arithmatic operation and then the temporary variable should be used in logical expression. Eg.
DATA ii TYPE i.
DATA var1 TYPE I.
var1 = ii + 1.
IF var1 > 2.
WRITE: / 'more than 2'.
ENDIF.
Also note that it is not recomended to use Macro's.
Cheers,
Gajendra Bhatt
2005 Nov 07 6:46 AM
Hi Andreas Mann / Jayanthi Jayaraman : sorry, but that is not what i m looking for. the simple example was just to emphasise that i want to do arthmatic operation in IF statement.
2005 Nov 07 6:48 AM
Re-sending...
HI Flora,
In abap you can't do arithmatic ops in IF statement.
rather you do the ops and store the result in a variable, and use it in IF statement.
data sum type i.
......
......
sum = ii + 1.
if sum > 2
...
endif.
plz reward points if it helps you
2005 Nov 07 6:52 AM
Hi,
It is not possible to use arithmetic operation in if statement in ABAP as we do the same in other programming languages.
Even the following is not allowed.
if ( 1 + 1 ) ge 2.
write 'dsfd'.
endif.
So kindly reward points by clicking the star on the left of reply,if it helps.Kindly close the thread if your question is answered.
2005 Nov 07 8:10 AM
As you read it is not allowed to have aritmetic expressions in an IF statement, but perhaps it is helpful that you can compare returning parameters from methods in an IF statement like this:
data: xyz type ref to z_own_class.
create object xyz.
IF xyz->method(parameters) = 5.
write:/ 'DO something'.
endif.
Message was edited by: Rainer Hübenthal
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |