Special Output Formats

For a summary of all formatting options of the WRITE statement, see Formatting Options. The current topic describes some special formatting options. These options format output according to certain entries that have to be made in special database tables. Usually, the customer maintains these tables when customizing the application (for information on Customizing, refer to the documentation .

Country-specific and User-specific Output Formats

The output formats of number and date fields are defined in the user master record of the individual program user. You can change these settings from within your program, using this statement:

Syntax

SET COUNTRY c.

For c, set either a country key defined in table T005X or space.

If c is not space, the system deactivates the settings from the user master record and searches table T005X for the country key. If the key exists, the system sets sy-subrc to 0 and formats the output of all subsequent WRITE statements according to the settings defined in T005X. If the country key you specified does not exist, the system sets sy-subrc to 4 and formats for all subsequent WRITE statements the decimal characters as period '.' and date specifications as MM/DD/YY.

If c is space, the system uses the settings in the user master record instead of reading table T005X. In this case, sy-subrc is always zero.

Maintaining table T005X is part of Customizing. However, you can use Start of the navigation pathSystem Next navigation step Services  Next navigation step Table MaintenanceEnd of the navigation path to display or change entries.

Currency-Specific Output Formats

To format the output of a number field according to a specific currency, use the CURRENCY option of the WRITE statement:

Syntax

WRITE f CURRENCY c.

This statement determines the number of decimal places in the output according to the currency c. If the contents of c exist in table TCURX as currency key CURRKEY, the system sets the number of decimal places according to the entry CURRDEC in TCURX. Otherwise, it uses the default setting of two decimal places. That means that TCURX only has to list the exceptions with a number of decimal places other than 2.

The output format for currencies does not depend on the decimal places of a number that may exist in the program. The system uses only the sequence of digits. This sequence of digits thus represents an amount specified in the smallest unit of the currency in use, for example Cents for US Dollar (USD) or Francs for Belgian Francs (BEF). For processing currency amounts in ABAP programs, SAP therefore recommends that you use data type p without decimal places.

Unit-specific Output Formats

You can format fields of type p according to certain units. For example, quantities should not have decimal places, weights should have three decimals, and so on. To do this, you can use the UNIT option in the WRITE statement as follows:

Syntax

WRITE f UNIT u.

This statement sets the number of decimal places according to the unit u. The contents of u must be an entry in database table T006 in column MSEHI. The entry in column DECAN then determines the number of decimal places of the field f to be displayed. If the system does not find the entry u in table T006, it ignores the option.

For more information, refer to the keyword documentation.