A currency field is a component of a structure, database table, or view defined in ABAP Dictionary of type CURR and used to record an amount in a specific currency. The amount is specified as a whole number in the smallest unit of the currency. A currency field must be associated with a currency key of a structure, database table, or view that specifies the currency and the number of decimal places. A currency key is a component of a structure, database table, or view defined in ABAP Dictionary, has the type CUKY, and can contain a currency ID from the database table TCURC.
By default, the number of decimal places for a currency is always two. Currencies with a different number of decimal places must also be entered in the table TCURX, where the number of decimal places can be defined explicitly.
7.31 | 7.40 | 7.54
- Currencies are handled as specified by the data saved in the database tables TCUR... of the package SFIB. The exchange rates and other settings can be edited in transaction OB08.
Handling in ABAP Dictionary
A data element of data type CURR is handled as a field of data type DEC and is stored in database tables in the BCD format. When creating a data element or a structure component of the data type CURR in an ABAP Dictionary tool, a number of decimal places other than zero must be defined. The standard value is two fractional digits.
For every structure component of data type CURR, a component of the same structure or of a different structure, database table, or view must be specified when editing the individual component as a reference field with the data type CUKY. This field is the currency key that defines the actual currency. From a technical perspective, the data type CUKY is handled like a type CHAR with length 5.
- The number of decimal places for the currency defined by the currency key of type CUKY only determines the formatting and checking of a currency field on a dynpro. In principal, it is independent of the number given for the currency field of type CURR. The default value of two decimal places for currency fields in ABAP Dictionary is chosen because most of the currencies in the database table TCURC have two decimal places and are not entered in the database table TCURX. It is not advisable to use any other value, since in this case any unforeseen operations with currency keys in ABAP programs are largely ignored.
- The conversion function CURRENCY_CONVERSION in ABAP CDS also assumes two decimal places for currency fields. If the function for currency fields is used with other amounts of decimal places, unexpected behaviour may arise.
- As in general packed numbers, the number of places in type CURR should be odd.
Handling in Dynpros
For the display of an input/output field of type CURR on a dynpro, the content is displayed as character-like content and in accordance with a type-dependent mask, as for all dynpro fields. Here, the positioning of the decimal point for a currency field of type CURR on a dynpro is completely independent of the number of decimal places specified by the data element in ABAP Dictionary (greater than or equal to one, the default value is two). The number of decimal places on a dynpro is defined as follows:
- When displaying a dynpro field of type CURR, the reference field for the currency key is searched for in the global data of the current ABAP program. The content of this field must be a valid
currency ID from the database
table TCURC. If the reference field is not found or there is no entry in the database table TCURX with
the content of the field, the currency field is displayed with two fractional digits by default.
The reference field is either defined in the relevant structure in ABAP Dictionary or was defined using Screen Painter for the attributes of the dynpro field. It does not have to be present on the dynpro itself.
- If the currency ID for the reference field is found in the database table TCURX, the currency field is displayed with the decimal places specified there. This also applies to initial reference fields.
A dynpro therefore only uses the string of digits of a currency field from the ABAP program (or a
in between) or just sends this string. Any information about currency keys and decimal places is not
passed automatically. It must be ensured that the reference field for PBO is filled with the appropriate
value. For PAI, the correct currency key plays a part in the automatic format check. Especially on dynpros
in which currency fields are displayed in differing currencies, it must be ensured that the reference
field is transported before the currency by using the statements
Handling in ABAP Programs
The ABAP type that corresponds to the CURR data type is
p. An ABAP data object
declared with reference to a dictionary type of type CURR has the number of decimal places defined there
(greater than or equal to one and the default is two). These decimal places are respected for all operations
and calculations, as for all packed numbers. The only exceptions are the programs for which the program
property fixed point arithmetic was not set.
To work correctly with a currency field, all digits in the number must be recorded as currency amounts
in the smallest possible currency units, regardless of the number of decimal places. This occurs automatically
sometimes, for example, if
is used after
WRITE [TO] or the formatting option
CURRENCY in an
embedded expression of a
character string template. For other operations, the following restrictions apply:
- Comparison, addition, subtraction, and division of two currency fields with the same number of fractional digits are not critical.
- Multiplication with and division by a non-currency-dependent number is not critical.
- All other operations are critical, for example:
- Multiplication of two currency fields.
- Operations between two fields with different currencies that include assignments.
- Assignments of non-currency-dependent numbers to currency fields.
Accurate results should not be expected when performing critical operations if the number of decimal places in the program does not match the number in the currency.
- For currencies, one of the data types for decimal floating point numbers is recommended rather than the data type CURR. The currency-compliant formatting is supported on dynpros by output styles and by style-compatible formatting in ABAP programs. See the executable example.
- The methods CONVERT_CURR_TO_DECFLOAT and CONVERT_DECFLOAT_TO_CURR of the system class CL_ABAP_DECFLOAT convert currency amounts to decimal floating point numbers (and back) as specified by a currency key.