Skip to Content
author's profile photo Former Member
Former Member

Dynamic Pool Subroutine.

I have requirement where the value will have to be calculated by evaluating the formula rule. This calculation has to be done while processing the internal table. The amount values in other field will be available during the program runtime only. FIELD AMOUNT FORMULA A 30 B 10 C 20 D (A/0.5)+B E B*C F 90
Need ideas/related code for implementing the above requirement. I read some suggestions to use Dynamic Subroutine Pool but didnt find any sample code..
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Jun 12, 2014 at 10:40 AM

    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

    *----------------------------------------------------------------------*


    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 12, 2014 at 10:25 AM

    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
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.