2005 Jul 25 7:01 AM
Hi,
I want to compare two value like this.
data: opera(2) type c.
data: value1(15) type c.
data: value2(15) type c.
if value1 opera value2.
true.
else.
false.
endif.
i have try the marco statment. but it does not support realtional operator. Any idea ?
Thanks
Wilson
Hi, Wilson
using GENERATE SUBROUTINE POOL might meet your requirement.
But are you sure you really need to import it into your code?
It shouldn't do good at performance.
Just do a case-when logic filter, don't make the code too complex. It's my suggestion.
2005 Jul 25 7:07 AM
Hi,
You can use wildcard.
DATA: f1(5) TYPE c VALUE <f1>,
f2(5) TYPE c VALUE <f2>.
IF f1 <operator> f2.
WRITE: / 'Vergleich wahr, SY-FDPOS=', sy-fdpos.
ELSE.
WRITE: / 'Vergleich falsch, SY-FDPOS=', sy-fdpos.
ENDIF.
The following table shows the results of executing this program, depending on which operators and values of F1 and F2.
<f1> <operator> <f2> Result SY-FDPOS
'BD ' CO 'ABCD ' true 5
'BD ' CO 'ABCDE' false 2
'ABC12' CN 'ABCD ' true 3
'ABABC' CN 'ABCD ' false 5
'ABcde' CA 'Bd ' true 1
'ABcde' CA 'bD ' false 5
'ABAB ' NA 'AB ' false 0
'ababa' NA 'AB ' true 5
'ABcde' CS 'bC ' true 1
'ABcde' CS 'ce ' false 5
'ABcde' NS 'bC ' false 1
'ABcde' NS 'ce ' true 5
'ABcde' CP 'b' true 1
'ABcde' CP '#b' false 5
'ABcde' NP 'b' false 1
'ABcde' NP '#b' true 5
Hope this helps.If so,kindly reward points and close the thread.
2005 Jul 25 7:26 AM
Sorry, I want to compare two values.
data: opera(2) type c.
data: value1 type I.
data: value2 type I.
value1 = 16.
value2 = 18.
opera = '>='.
if value1 opera value2.
true.
else.
false.
endif.
Thanks
Wilson
2005 Jul 25 7:26 AM
Hi, try to use GENERATE SUBROUTINE POOL:
...
APPEND 'report z1.' TO progtab.
APPEND 'form upro using result.' TO progtab.
CONCATENATE 'if' value1 opera value2 '.' INTO progtab
SEPARATED BY space.
APPEND progtab.
APPEND 'result = 1.' TO progtab.
APPEND 'endif.' TO progtab.
APPEND 'endform.' TO progtab.
*
GENERATE SUBROUTINE POOL progtab NAME genprog MESSAGE message
LINE line WORD word.
IF sy-subrc <> 0.
message e001(00) with message line word.
ENDIF.
*
PERFORM upro IN PROGRAM (genprog) USING result.Andreas
2005 Jul 25 7:39 AM
Hi, Wilson
using GENERATE SUBROUTINE POOL might meet your requirement.
But are you sure you really need to import it into your code?
It shouldn't do good at performance.
Just do a case-when logic filter, don't make the code too complex. It's my suggestion.
2005 Jul 25 9:00 AM
Hi Wilson,
I have never come across a requirement like this. I hope it is just a matter of academic interest for you. In case you're trying to use this in a program for your customer, then I must warn you that trying to determine the operator at run time will make debugging and error-detection very difficult. Also, I don't think it is a nice way of programming your logic.
Now, here's what I think you can do -
define evaluate_condition.
case &2.
when 1.
if &1 EQ &3.
" do something.
endif.
when 2.
if &1 NE &3.
" do something.
endif.
when 3.
if &1 GT &3.
" do something.
endif.
when 4.
if &1 GE &3.
" do something.
endif.
when 5.
if &1 LT &3.
" do something.
endif.
when 6.
if &1 LE &3.
" do something.
endif.
endcase.
end-of-definition.
constants: eq type n value '1',
ne type n value '2',
gt type n value '3',
ge type n value '4',
lt type n value '5',
le type n value '6'.
data: operand1 type i,
operator type n,
operand2 type i.
operand1 = 16.
operand2 = 18.
operator = ge.
evaluate_condition operand1 operator operand2.
operand1 = 10.
operand2 = 10.
evaluate_condition operand1 eq operand2.You might get the feeling that this code is not really dynamic. I agree. But I think it is readable and will make life easier for anybody else who reads / reviews your program :-).
Let me know what you think. And reward the points by clicking the stars if any of the answers have helped you.
Regards,
Anand Mandalika.
2005 Jul 25 10:49 AM
Thanks all !!
I will use this method.
data: it_temp like range of bsid-wrbtr with header line.
it_temp-low = value2.
it_temp-sign = 'I'.
it_temp-option = opera.
loop at wa_temp
where value1 in it_temp.
true.
endloop.
Any comments ?
Thanks
Wilson
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |