Hi,
Check :
CALL FUNCTION 'EVAL_FORMULA'
Regards.
Some code:
REPORT y_r_eitan_test_51_13.
START-OF-SELECTION .
PERFORM at_start_of_selection .
*----------------------------------------------------------------------*
FORM at_start_of_selection .
PERFORM do_eval_formula .
ENDFORM . "at_selection_screen_input
*----------------------------------------------------------------------*
FORM do_eval_formula .
CONSTANTS: c_formula TYPE char50 VALUE '(A+B)/C' .
WRITE: / c_formula .
DATA: program TYPE syrepid.
DATA: value TYPE f .
DATA: result TYPE p DECIMALS 4 .
program = sy-repid.
DATA: my_sy_subrc TYPE sysubrc .
IF 1 EQ 2 .
* For reference only the actual usage is done in function 'eval_formula'
PERFORM assign_value
USING
'A'
CHANGING
value
my_sy_subrc.
ENDIF .
CALL FUNCTION 'EVAL_FORMULA'
EXPORTING
* DEGREES = ' '
formula = c_formula
program = program
routine = 'ASSIGN_VALUE'
IMPORTING
value = value
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.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
result = value .
WRITE: / result .
ENDFORM . "do_EVAL_FORMULA
*----------------------------------------------------------------------*
FORM assign_value
USING
var_name
CHANGING
var_value
my_sy_subrc .
CASE var_name .
WHEN 'A' . var_value = '10.0' .
WHEN 'B' . var_value = '20.0' .
WHEN 'C' . var_value = '2.0' .
ENDCASE .
DATA: number TYPE p DECIMALS 2 .
number = var_value .
WRITE: / var_name , '=' , number .
my_sy_subrc = 0 .
ENDFORM . "assign_value
*----------------------------------------------------------------------*
Dear Suganth,
Even we are getting the value during runtime also, we can fill the internal table values for the column(D & E) at the time when the values are passed to the columns(A & B & C).
In some case, if required after the internal filled also, using field symbol, we can fill the values to the column (D & E) as shown below.
Code:
Field-symbols: <fs_final> type ty_final.
loop at it_final assigning <fs_final>.
<fs_final>-d = (<fs_final>-a /0.5) + <fs_final>-b
<fs_final>-e = <fs_final>-b * <fs_final>-c.
endloop.
Regards
Rajkumar Narasimman
Add a comment