MichaelB.
7/23/2018 - 8:29 PM

Use quantity and currency fields

These fields are treated like packed number fields, so you need to declare currency field as packed number (also note how many decimals you want). Decimals affect calculations. Better to associate field with pre-existing ABAP fields, they already have right length and decimal places for individual fields. ABAP fields that you want to reference can change, so always use LIKE statement to reference currency fields. This keeps the fields in sync, including decimal places # and associated currency / quant keys.

*****************************
* CURRENCY & QUANTITY FIELDS
* Field for Currency Calculations
DATA my_salary  LIKE zemployees2-salary.
DATA my_tax_amt LIKE zemployees2-salary.
DATA my_net_pay LIKE zemployees2-salary.
DATA tax_perc   TYPE p DECIMALS 2.

*****************************
* CURRENCY CALCULATIONS
tax_perc = '0.20'.
SELECT * FROM zemployees2.
  WRITE: / zemployees2-surname, zemployees2-salary, zemployees2-ecurrency.
  my_tax_amt = tax_perc * zemployees2-salary.
  my_net_pay = zemployees2-salary - my_tax_amt.
  WRITE: / 'tax amount: ', my_tax_amt, zemployees2-ecurrency,
           'net amount: ', my_net_pay, zemployees2-ecurrency.
  SKIP.
ENDSELECT.