cancel
Showing results for 
Search instead for 
Did you mean: 

BRFplus: Sum Amount in Table

jongilman
Explorer
0 Kudos
492

Experts,

We are having trouble summing amount columns of tables in BRFplus.  We have tried 2 different ideas and each has a different error:

  1. Table Operation - sum the column containing the amount.  This returns a currency error.  It is not possible to pass a currency at runtime because it does not exist in the table structure.
  2. TABLE_SUM_AMOUNT - create a formula and use this function to calculate the amount.  This always returns the error "Column 0050569BA4BE1EE487810606D083E1 does not exist in table Table Type."  Regardless of the column or the table type, this same error appears for all TABLE_SUM* functions.

Any ideas?  Your help would be greatly appreciated.

Accepted Solutions (0)

Answers (3)

Answers (3)

jongilman
Explorer
0 Kudos

We have opened OSS Note 887267/2014 for this issue.  The error in the formula function can be worked around by switching to expert mode and changing the column name to the field in single quotes (although SAP should still fix this issue - workarounds are not acceptable):

     TABLE_SUM_AMOUNT ( 0050569BA4BE1EE486990918279CB05B , 'BETRW' )

However, once this is fixed, the Formula Function now has the same currency problem as the Table Operation in #1 of my original post.  Considering BRFplus is used by a large number of SAP customers, I find it hard to believe that this issue has not been encountered before.

ttrapp
Active Contributor
0 Kudos

Thanks for this Information - it would be good to hear when SAP solved this issue since I'd like to install this note, too.

carsten_ziegler
Active Contributor
0 Kudos

Can you post some screenshots? How does the structure of the table look like? What is the exact error message? Do you have currency conversion customizing set up?

In fast the usage of the column name is not a workaround but the formula function was build like this from the beginning. You do not have to enter the expert mode. You can stay in the standard mode and use the buttons below the formula pane to insert a text for the column name.

jongilman
Explorer
0 Kudos

Carsten,

To make things move a little faster, can you post an example of summing an amount column from any table structure in the SAP system?  I don't care which table, I just need to see a functional example.  I don't think this functionality works and would like to be proven wrong.

Jon

carsten_ziegler
Active Contributor
0 Kudos

Please see the following screenshots

Function with Table

Ruleset with two expressions, formula and table operation

Details of the formula

Details of the table operatoin

Simulation input

Simulation result

Former Member
0 Kudos

I just wonder:

Why is there difference on decimal precision level in the two expressions?

carsten_ziegler
Active Contributor
0 Kudos

The formula always rounds the result to the decimals defined for the object.

Other expressions do not round. You can use a formula to round explicitly in a rule.

Former Member
0 Kudos

Well, it might make semse, but I'm not sure I've understood how it explains these examples.

Which decimals definition is used in this case? Data object Amount or Amount1?

jongilman
Explorer
0 Kudos

Carsten,

From ABAP, you can only pass an amount to BRFplus.  For example, 10 instead of 10 USD.  In your example, you are specifying the currency.  The purpose of my post is that none of the summing functionality works without currency specified, and I cannot find a way to pass the currency to BRFplus from ABAP.

Jon

carsten_ziegler
Active Contributor
0 Kudos

Jon,

You have to pass an amount consisting of a number and a currency. Without the currency the conversion cannot be performed. An amount is not an amount without a currency.

You may use the BRFplus standard types (IF_FDT_TYPES and the DDIC data elements used there) or you can use your own type. Make sure you have a number value and a currency in your structure and have one point to the other (CURR + CUKY). Then you can pass this to BRFplus and work with it.

Regards,

Carsten

carsten_ziegler
Active Contributor
0 Kudos

In case of amounts the decimals are defined by the currency. EUR has 2 decimal places, YEN has none. Currencies can be defined with more decimal places, too. Such as US3 for USD with 3 decimal places.


jongilman
Explorer
0 Kudos

My specific requirement is to sum the BETRW amount field on an internal table of structure DFKKOP.  In ABAP, the structure contains a currency field called WAERS.  If you attempt to create a table Data Object in BRFplus based on the DFKKOP structure, for some reason the WAERS field disappears:

This is really a very simple and common use case.  My function module that calls BRFplus is posted below.  What I need to know from the experts is:

****HOW DO I SUM THE FIELD BETRW IN TABLE DFKKOP?****

The examples posted so far are not helping at all.

FUNCTION ZFICA_BRFPLUS_SUM_TEST.

*"----------------------------------------------------------------------

*"*"Local Interface:

*"  EXPORTING

*"     VALUE(EV_AMOUNT) TYPE  BETRW_KK

*"  TABLES

*"      IT_DFKKOP STRUCTURE  DFKKOP

*"  EXCEPTIONS

*"      NO_INKGP_FOUND

*"----------------------------------------------------------------------

   CONSTANTSlv_function_id TYPE if_fdt_types=>id VALUE '0050569BA4BE1EE48FE94B283920E9F1'. "THE BRFPLUS FUNCTION

   DATA: lt_name_value  TYPE           abap_parmbind_tab,

         ls_name_value  TYPE           abap_parmbind,

         lv_timestamp   TYPE           timestamp,

         exc            TYPE REF TO    cx_fdt,

         lr_data        TYPE REF TO    data.

   FIELD-SYMBOLS: <logmsg> TYPE if_fdt_actn_message_log=>s_log_msg,

                  <wa>     TYPE any.

   GET TIME STAMP FIELD lv_timestamp.

   "SEND THE OPEN ITEMS TO BRFPLUS

   CLEAR ls_name_value.

   MOVE: 'IT_DFKKOP' TO ls_name_value-name.

   GET REFERENCE OF IT_DFKKOP INTO lr_data.

   TRY.

       CALL METHOD cl_fdt_function_process=>move_data_to_data_object

         EXPORTING

           ir_data        = lr_data

           iv_function_id = lv_function_id

           iv_data_object = 'IT_DFKKOP'

           iv_timestamp   = lv_timestamp

         IMPORTING

           er_data        = ls_name_value-value.

     CATCH cx_fdt_input.

   ENDTRY.

   INSERT ls_name_value INTO TABLE lt_name_value.

   "THEN CALL THE BRFPLUS FUNCTION

   TRY.

       CALL METHOD cl_fdt_function_process=>process

         EXPORTING

           iv_function_id = lv_function_id

           iv_timestamp   = lv_timestamp

         CHANGING

           ct_name_value  = lt_name_value.

     CATCH cx_fdt_input cx_fdt INTO exc.

       MESSAGE exc TYPE 'E'.

   ENDTRY.

   "NOW GET THE RESULT FROM THE CALL TO THE BRFPLUS FUNCTION

   cl_fdt_function_process=>get_context_value( EXPORTING iv_function_id      = lv_function_id

                                                         iv_data_object      = 'EV_AMOUNT'

                                                         iv_timestamp        = lv_timestamp

                                               IMPORTING ev_data             = EV_AMOUNT ).

ENDFUNCTION.

carsten_ziegler
Active Contributor
0 Kudos

Field WAERS is a currency key. Therefore, it is not taken over into the structure in BRFplus.

Fields BETR* (e.g. BETRH) are taken over as amounts. In the DDIC they are defined with a pointer to WAERS.

The data types in BRFplus differ from ABAP. In BRFplus there are amounts that consist of number and currency. In case we can find this relationship in DDIC we use it. Some fields however are just ignored like types xstring.

jongilman
Explorer
0 Kudos

Carsten,

Getting back to the original question - how can I sum the BETRW field from DFKKOP in BRFplus?  If I can't pass an internal table of type DFKKOP to BRFplus, what do I need to do?

Jon

carsten_ziegler
Active Contributor
0 Kudos

Jon

The question is not how to sum a column in BRFplus. It is more about how to pass the data into BRFplus. In case you have more complex variables you should use method CL_FDT_FUNCTION_PROCESS=>MOVE_DATA_TO_DATA_OBJECT for this purpose. The code template generator can output some code for you. In release >=731 you can find it in the menu on the function UI. In earlier releases use report FDT_TEMPLATE_FUNCTION_PROCESS.

Carsten

Jocelyn_Dart
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Jon,

Also if you are always or mostly summing to one main currency you might want to put a default currency in your Rules Applications settings.. at least that helps sort out the default treatment of decimal places.


Also Amounts in BRFplus have both a value and a currency part.  You need to move both into and out of your BRFplus amount.  If you move your BETRW and WAERS to a value of data type IF_FDT_TYPES=>ELEMENT_AMOUNT then you can easily map it to your BRFplus amount, and pass it to BRFplus as fully formulated amount with currency.  Put the BETRW in the NUMBER part, and WAERS in the CURRENCY part.


I'd also warn you that the standard conversion formula function CONVERT_AMOUNT only converts at the default exchange rate on the current date.  However it's really surprisingly easy to create  a custom formula function that extends that.  (One blog I'm still trying to find time to write). Took me about an hour to create the custom formula function... seriously!  The code's more than half written for you already in CL_FDT_FORMULA_FUNCTIONAL->CONVERT_AMOUNT.   Let me know if that's critical to what you are doing and I'll try and move up my blogging timeframe.


Rgds,

Jocelyn

Former Member
0 Kudos

Can you elaborate more about 1.

'Total' Table operation & result filed is amount field.

Input table:

1) 10, blank currency

2) 10, blank currency

Output element:

30, blank currency

on NW731.11

jongilman
Explorer
0 Kudos

Rahul,

We do not get that result.  Below are some screenshots.  Here we input two $10 items without currency specified:

The result is $0:

However, if we input the currency:

Then we get the correct result:

Is there a trick to specify currency at runtime?

Former Member
0 Kudos

You are right. It doesn't work in simulation mode.

I created a z brf+ integration program to test this rule without currency code & it works. No trick!

jongilman
Explorer
0 Kudos

I actually did the same thing, but still no success.  Below is a function module I created to call the BRFplus table operation, but still the same result:

Can you share a screenshot of your table operation?  Thanks.

Former Member
0 Kudos

You always have chance to create your own custom formula / procedure call & report this bug to SAP.

Former Member
0 Kudos
jongilman
Explorer
0 Kudos

Thanks Rahul, we have already opened an OSS note and are waiting to hear back.

christianlechne
Active Contributor
0 Kudos

Hi Jon,

from my point of view the second option is the one that should definitly work, However I tested it on our system and it does not. I get the same error as you.

When debugging the issue one will see that the problem is located in the class CL_FDT_FORMULA_PARSER method _CHECK_TABLE_FUNCTIONAL. Here the program tries to compare the column name that is entered in the formula expression vs. the available column names determined via the structure of the table:


IF lv_name EQ lv_colname.

    lv_found = abap_true.

    EXIT. ">>>>>>>>>>

ENDIF.

The problem is that the parameter lv_name contains the technical name of the column (e. g. AMOUNT) and the while the parameter lv_colname contains the GUID of the column (that is also the reson for the cryptical error message). As this check is done for all these functions, it is consistent that the error is raised as you describe it.

I did not find any note that solves that issue, so I would recommend that you open an OSS.

Best regards

Christian

P.S. I am on a NW740 with SP06