Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Calculations with Currency fields

vimalv
Active Participant
0 Kudos

Hi Experts,

Could you kindly throw some light on how Currency fields are processed in the Dictionary? How does the system calculate the local currency?

For example, let us consider table BSAK, I see the fields WAERS(Curr key), DMBRT (Amount in local currency) and WRBTR (Amount in document currency).

How do I calculate the total Amount for a given values of

LIFNR, BUKRS,GJAHR, MONAT and SHKZG = 'S' ?

Do I just add all the DMBTR values?

What would be the local currency be?

Kindly advice.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Vimal,

The fields DMBRT and WRBTR hold the amount whereas the field WAERS specifies the currency key of these fields . That is whether they are in Indian Currency ( IND ) or is it US Dollars ( USD ) etc... The Table to hold the currency keys is TCURC. You can find this table as a value table in the domain of the field WAERS.

So if you have to calculate the currencies you have to check with their currency keys if the currency key is same then you Add the prices.

Try to write this code in ABAP Editor :

*"Table Declarations...................................................
TABLES :
  sflight.                             " Flight


*"Select Screen Elements...............................................
SELECT-OPTIONS :
  s_carrid FOR sflight-carrid.         " Carrier ID


*"Data Declarations....................................................
*"--------------------------------------------------------------------*
* Work Variables                                                      *
*"--------------------------------------------------------------------*
DATA :
  w_gross    TYPE p DECIMALS 2,        " Holds Gross Value
  w_net      TYPE p DECIMALS 2,        " Holds Net Value
  w_curr     LIKE sflight-currency.    " Holds Currency


*"--------------------------------------------------------------------*
* Internal table to hold Flight data                                  *
*"--------------------------------------------------------------------*
DATA :
  t_sflight LIKE
   STANDARD TABLE
         OF sflight.


*"--------------------------------------------------------------------*
*                       TOP-OF-PAGE EVENT                             *
*"--------------------------------------------------------------------*
TOP-OF-PAGE.

  PERFORM top_of_page.


*"--------------------------------------------------------------------*
*                    AT SELECTION-SCREEN EVENT                        *
*"--------------------------------------------------------------------*
AT SELECTION-SCREEN.

  PERFORM at_selection_screen.


*"--------------------------------------------------------------------*
*                    START-OF-SELECTION EVENT                         *
*"--------------------------------------------------------------------*
START-OF-SELECTION.

  PERFORM fetch_sflight_data.

  PERFORM display_sflight_data.



*&---------------------------------------------------------------------*
*&      Form  top_of_page
*&---------------------------------------------------------------------*
* This Subroutine Performs the Event Top-Of-Page
*----------------------------------------------------------------------*
*  There are no interface parameters to be passed to this subroutine.  *
*----------------------------------------------------------------------*
FORM top_of_page .

  WRITE :/45 text-001.
  ULINE.

ENDFORM.                               " FORM TOP_OF_PAGE


*&---------------------------------------------------------------------*
*&      Form  AT_SELECTION_SCREEN                                      *
*&---------------------------------------------------------------------*
* This Subroutine Performs the Required Input Validations              *
*----------------------------------------------------------------------*
*  There are no interface parameters to be passed to this subroutine.  *
*----------------------------------------------------------------------*
FORM at_selection_screen .

  SELECT carrid                        " Carrier ID
    FROM sflight
    INTO TABLE t_sflight
   WHERE carrid = s_carrid-low.

  IF sy-subrc NE 0
  AND s_carrid-low NE space.

    MESSAGE e184(bc_global) WITH text-007.

  ENDIF.                               " IF SY-SUBRC NE 0

  SELECT carrid                        " Carrier ID
    FROM sflight
    INTO TABLE t_sflight
   WHERE carrid = s_carrid-high.

  IF sy-subrc NE 0
  AND s_carrid-high NE space.

    MESSAGE e184(bc_global) WITH text-008.

  ENDIF.                               " IF SY-SUBRC NE 0

ENDFORM.                               " AT_SELECTION_SCREEN


*&---------------------------------------------------------------------*
*&      Form  FETCH_SFLIGHT_DATA                                       *
*&---------------------------------------------------------------------*
* This Subroutine Fetches Data from the Database table Sflight         *
*----------------------------------------------------------------------*
*  There are no interface parameters to be passed to this subroutine.  *
*----------------------------------------------------------------------*
FORM fetch_sflight_data .

  SELECT carrid                        " Carrier ID
         connid                        " Connection ID
         fldate                        " Flight Date
         price                         " Price
         currency                      " Currency
         seatsmax                      " Seats Maximum
         seatsocc                      " Seats Occupied
    FROM sflight
    INTO CORRESPONDING FIELDS OF
   TABLE t_sflight
   WHERE carrid IN s_carrid.

ENDFORM.                               " FORM FETCH_SFLIGHT_DATA


*&---------------------------------------------------------------------*
*&      Form  display_sflight_data
*&---------------------------------------------------------------------*
* This Subroutine Displays Data from the Database table Sflight        *
*----------------------------------------------------------------------*
*  There are no interface parameters to be passed to this subroutine.  *
*----------------------------------------------------------------------*
FORM display_sflight_data .

  LOOP AT t_sflight INTO sflight.

    AT FIRST.
      FORMAT COLOR 1.
      WRITE :  /5  'Carrier ID'(002),
              140  space,
              /25  'Flight Date'(003),
              140  space,
              /44  'Seats'(004),
               65  'Seats'(004),
              140  space,
              /44 '(Maximum)'(005),
               65 '(Occupied)'(006),
              140   space.
      ULINE.
    ENDAT.


*" AT NEW CONNID

    AT NEW connid.
      FORMAT COLOR 6 INTENSIFIED OFF.
      WRITE 😕  sflight-carrid   UNDER text-002,
             10   sflight-connid.
    ENDAT.                             " AT NEW CONNID

    FORMAT COLOR 5 INTENSIFIED OFF.
    WRITE 😕  sflight-fldate   UNDER text-003,
              sflight-seatsmax UNDER text-005,
              sflight-seatsocc UNDER text-006,
           90 sflight-currency,
          110 space.

    w_gross = w_gross + sflight-price * sflight-seatsocc.
    w_curr = sflight-currency.



*" AT END OF CONNID

    AT END OF connid.
      FORMAT COLOR 3 INTENSIFIED OFF.
      WRITE 😕 'Total Bookings so far '(009),
             40 w_gross,
             60 w_curr.
      w_net = w_net + w_gross.
    ENDAT.                             " AT END OF CONNID

*" AT END OF CARRID

    AT END OF carrid.
      SKIP 2.
      FORMAT COLOR 3 INTENSIFIED ON.
      WRITE 😕 'Total Bookings so far for '(013),
               sflight-carrid,
               w_net,
               w_curr.
      ULINE.
      CLEAR w_gross.
      CLEAR w_net.
    ENDAT.                             " AT END OF CARRID

  ENDLOOP.                             " LOOP AT T_SFLIGHT...


ENDFORM.                               " FORM DISPLAY_SFLIGHT_DATA

This is to sum the prices of a flight according to currency key

Regards,

Swapna.

5 REPLIES 5

Former Member
0 Kudos

Hi,

The amounts are DMBTR and WRBTR unless specified say tax etc (MWSTS,SKFBT)..You can take DMBTR/WRBTR unless specified .Some times ,both are asked by the FO.

Shkzg gives the debit credit indicator..using which u need to add or subtract the amount.

WAERS does not help you in calculations but should be used for display purpose.Based on the currency key,The alignment is automatically done while display.

Ex :


if wa-shkzg = c_s.
wa-wrbtr = wa-wrbtr * -1 .
endif.

write : wa-wrbtr currency wa-waers .

Thank you..

Former Member
0 Kudos

Hello,

Amount in Document currency - This is the currency in which the document was created. For e.g. if the document was created in Germany , the document currency would be Euros. If the company is headquartered in USA, then the local currency would be USD.

The company should know how much profit is made in local currency because all the reports and analytics are run from USA. Hence local currency and amount in local currency is important.

Usually all reports will lay stress on teh amounts in local currency.

As explained earlier, the debit / credit indicator will determine whether its a postive or negative entry.

Hope this helps.

cheers,

Sushil Joshi

Former Member
0 Kudos

Hi,

You need to do the calculations in a loop. Suppose you want to get sum for a a Vendor for a particular company in the example given by you, in that case you need to use the On Change of statement in your loop and then sum the amount.

Also while summing up make sure to put a check for Debit/Credit Indicator.

IF itab-shkzg EQ 'H'.

itab-wrbtr = itab-wrbtr * -1.

ENDIF.

Hope this would answer your question.

Regards,

Lalit

Former Member
0 Kudos

Hi Vimal,

The fields DMBRT and WRBTR hold the amount whereas the field WAERS specifies the currency key of these fields . That is whether they are in Indian Currency ( IND ) or is it US Dollars ( USD ) etc... The Table to hold the currency keys is TCURC. You can find this table as a value table in the domain of the field WAERS.

So if you have to calculate the currencies you have to check with their currency keys if the currency key is same then you Add the prices.

Try to write this code in ABAP Editor :

*"Table Declarations...................................................
TABLES :
  sflight.                             " Flight


*"Select Screen Elements...............................................
SELECT-OPTIONS :
  s_carrid FOR sflight-carrid.         " Carrier ID


*"Data Declarations....................................................
*"--------------------------------------------------------------------*
* Work Variables                                                      *
*"--------------------------------------------------------------------*
DATA :
  w_gross    TYPE p DECIMALS 2,        " Holds Gross Value
  w_net      TYPE p DECIMALS 2,        " Holds Net Value
  w_curr     LIKE sflight-currency.    " Holds Currency


*"--------------------------------------------------------------------*
* Internal table to hold Flight data                                  *
*"--------------------------------------------------------------------*
DATA :
  t_sflight LIKE
   STANDARD TABLE
         OF sflight.


*"--------------------------------------------------------------------*
*                       TOP-OF-PAGE EVENT                             *
*"--------------------------------------------------------------------*
TOP-OF-PAGE.

  PERFORM top_of_page.


*"--------------------------------------------------------------------*
*                    AT SELECTION-SCREEN EVENT                        *
*"--------------------------------------------------------------------*
AT SELECTION-SCREEN.

  PERFORM at_selection_screen.


*"--------------------------------------------------------------------*
*                    START-OF-SELECTION EVENT                         *
*"--------------------------------------------------------------------*
START-OF-SELECTION.

  PERFORM fetch_sflight_data.

  PERFORM display_sflight_data.



*&---------------------------------------------------------------------*
*&      Form  top_of_page
*&---------------------------------------------------------------------*
* This Subroutine Performs the Event Top-Of-Page
*----------------------------------------------------------------------*
*  There are no interface parameters to be passed to this subroutine.  *
*----------------------------------------------------------------------*
FORM top_of_page .

  WRITE :/45 text-001.
  ULINE.

ENDFORM.                               " FORM TOP_OF_PAGE


*&---------------------------------------------------------------------*
*&      Form  AT_SELECTION_SCREEN                                      *
*&---------------------------------------------------------------------*
* This Subroutine Performs the Required Input Validations              *
*----------------------------------------------------------------------*
*  There are no interface parameters to be passed to this subroutine.  *
*----------------------------------------------------------------------*
FORM at_selection_screen .

  SELECT carrid                        " Carrier ID
    FROM sflight
    INTO TABLE t_sflight
   WHERE carrid = s_carrid-low.

  IF sy-subrc NE 0
  AND s_carrid-low NE space.

    MESSAGE e184(bc_global) WITH text-007.

  ENDIF.                               " IF SY-SUBRC NE 0

  SELECT carrid                        " Carrier ID
    FROM sflight
    INTO TABLE t_sflight
   WHERE carrid = s_carrid-high.

  IF sy-subrc NE 0
  AND s_carrid-high NE space.

    MESSAGE e184(bc_global) WITH text-008.

  ENDIF.                               " IF SY-SUBRC NE 0

ENDFORM.                               " AT_SELECTION_SCREEN


*&---------------------------------------------------------------------*
*&      Form  FETCH_SFLIGHT_DATA                                       *
*&---------------------------------------------------------------------*
* This Subroutine Fetches Data from the Database table Sflight         *
*----------------------------------------------------------------------*
*  There are no interface parameters to be passed to this subroutine.  *
*----------------------------------------------------------------------*
FORM fetch_sflight_data .

  SELECT carrid                        " Carrier ID
         connid                        " Connection ID
         fldate                        " Flight Date
         price                         " Price
         currency                      " Currency
         seatsmax                      " Seats Maximum
         seatsocc                      " Seats Occupied
    FROM sflight
    INTO CORRESPONDING FIELDS OF
   TABLE t_sflight
   WHERE carrid IN s_carrid.

ENDFORM.                               " FORM FETCH_SFLIGHT_DATA


*&---------------------------------------------------------------------*
*&      Form  display_sflight_data
*&---------------------------------------------------------------------*
* This Subroutine Displays Data from the Database table Sflight        *
*----------------------------------------------------------------------*
*  There are no interface parameters to be passed to this subroutine.  *
*----------------------------------------------------------------------*
FORM display_sflight_data .

  LOOP AT t_sflight INTO sflight.

    AT FIRST.
      FORMAT COLOR 1.
      WRITE :  /5  'Carrier ID'(002),
              140  space,
              /25  'Flight Date'(003),
              140  space,
              /44  'Seats'(004),
               65  'Seats'(004),
              140  space,
              /44 '(Maximum)'(005),
               65 '(Occupied)'(006),
              140   space.
      ULINE.
    ENDAT.


*" AT NEW CONNID

    AT NEW connid.
      FORMAT COLOR 6 INTENSIFIED OFF.
      WRITE 😕  sflight-carrid   UNDER text-002,
             10   sflight-connid.
    ENDAT.                             " AT NEW CONNID

    FORMAT COLOR 5 INTENSIFIED OFF.
    WRITE 😕  sflight-fldate   UNDER text-003,
              sflight-seatsmax UNDER text-005,
              sflight-seatsocc UNDER text-006,
           90 sflight-currency,
          110 space.

    w_gross = w_gross + sflight-price * sflight-seatsocc.
    w_curr = sflight-currency.



*" AT END OF CONNID

    AT END OF connid.
      FORMAT COLOR 3 INTENSIFIED OFF.
      WRITE 😕 'Total Bookings so far '(009),
             40 w_gross,
             60 w_curr.
      w_net = w_net + w_gross.
    ENDAT.                             " AT END OF CONNID

*" AT END OF CARRID

    AT END OF carrid.
      SKIP 2.
      FORMAT COLOR 3 INTENSIFIED ON.
      WRITE 😕 'Total Bookings so far for '(013),
               sflight-carrid,
               w_net,
               w_curr.
      ULINE.
      CLEAR w_gross.
      CLEAR w_net.
    ENDAT.                             " AT END OF CARRID

  ENDLOOP.                             " LOOP AT T_SFLIGHT...


ENDFORM.                               " FORM DISPLAY_SFLIGHT_DATA

This is to sum the prices of a flight according to currency key

Regards,

Swapna.

vimalv
Active Participant
0 Kudos

Experts, this was my conclusion :

Each company's(BUKRS) local currency will be given by the curr key WAERS, and DMBTR is value in that currency. So i should only be adding DMBTR per company.

In case I want the total amount per vendor, WRBTR, which is amount in document currency.

Hope this was not incorrect.