‎2009 Nov 04 9:12 AM
Hi Experts,
I have a requirement where in I need to pass Arithmetic Expressions (+,-,/) as constants to a subroutine.For ex:
constants:c_p type char1 value '+',
c_m type char1 value '-',
data:v_a type char1 value '2',
v_b type char1 value '6',
v_r type string.
v_r = v_ a + v_b.
In the above instead of + I want use c_p.Please help me out is there any other way in defining Arithmetic expresiions where I could use constants or variables instead of directly using these expressions(+,-).Thanks in advance.
With Regards,
Srini..
‎2009 Nov 04 9:16 AM
Hello Srini,
I think you must have a look at the FMs belonging to FuGr. CALC.
For e.g., EVAL_FORMULA which evaluates Literal or Variable formulas
CONSTANTS:
C_P TYPE CHAR1 VALUE '+',
C_M TYPE CHAR1 VALUE '-'.
DATA:
V_A TYPE CHAR1 VALUE '2',
V_B TYPE CHAR1 VALUE '6',
V_FORMULA TYPE STRING,
V_RES_F TYPE F,
V_RES_P TYPE P.
CONCATENATE V_A C_P V_B INTO V_FORMULA SEPARATED BY SPACE.
CALL FUNCTION 'EVAL_FORMULA'
EXPORTING
FORMULA = V_FORMULA
IMPORTING
VALUE = V_RES_F
EXCEPTIONS
DIVISION_BY_ZERO = 1
EXP_ERROR = 2
FORMULA_TABLE_NOT_VALID = 3
INVALID_EXPRESSION = 4
INVALID_VALUE = 5
LOG_ERROR = 6
PARAMETER_ERROR = 7
SQRT_ERROR = 8
UNITS_NOT_VALID = 9
MISSING_PARAMETER = 10
OTHERS = 11.
IF SY-SUBRC = 0.
MOVE V_RES_F TO V_RES_P.
WRITE: V_RES_P .
ENDIF.BR,
Suhas
‎2009 Nov 04 10:33 AM
Hey Suhas,
The FM u said will work fine but I am thinking for a solution where we can pass keywords or arthematic expressions dynamically.Anyways thanks a lot for your help you all deserve good score.I will update you all if I find any kind of solution.
Note:No macros.
Thanks and Regards,
Srini..
‎2009 Nov 04 9:19 AM
‎2009 Nov 04 9:39 AM
>
> > ADD v_a v_b TO v_r.
I can not use this Statement in SAP. Are you using any RFC which incorporates C language syntax with ABAP?
Cheers
‎2009 Nov 04 9:52 AM
HI Pushparaj,
ADD v_a v_b TO v_r is showing an error.Any other ways can I achieve this???
Thankis and Regards,
Srini...
‎2009 Nov 04 10:01 AM
Hi
You could do
CLEAR v_r.
ADD v_a TO v_r.
ADD v_b TO v_r.
Pushpraj
‎2009 Nov 04 10:04 AM
I can not use this Statement in SAP. Are you using any RFC which incorporates C language syntax with ABAP?
Ya my bad!
‎2009 Nov 04 10:12 AM
How about this?
data: num1 type i,
num2 type i,
num3 type i.
num1 = '7'.
num2 = '8'.
add num1 then num2 until num3 giving num3.
write: num3.
Vikranth
‎2009 Nov 04 10:19 AM
Hello ,
I think you can check the FM: EVAL_FORMULA?
What's the problem using that FM?
Suhas
‎2009 Nov 04 9:20 AM