Entering content frame

Special Output Formats Locate the document in its SAP Library structure

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 Structure linkCustomizing, 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 turns off 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 does not read table T005X but uses the settings in the user master record. In this case, sy-subrc is always zero.

Maintaining table T005X is part of Customizing. However, you can use System Services Table maintenanceto display or change entries.

Example

REPORT demo_list_set_country LINE-SIZE 40.

DATA: num TYPE p DECIMALS 3 VALUE '123456.789'.

ULINE.
WRITE: / 'INITIAL:'.
WRITE: / num, sy-datum.
ULINE.

SET COUNTRY 'US'.
WRITE: / 'US,      sy-subrc:', sy-subrc.
WRITE: / num, sy-datum.
ULINE.

SET COUNTRY 'GB'.
WRITE: / 'GB,      sy-subrc:', sy-subrc.
WRITE: / num, sy-datum.
ULINE.

SET COUNTRY 'DE'.
WRITE: / 'DE,      sy-subrc:', sy-subrc.
WRITE: / num, sy-datum.
ULINE.

SET COUNTRY 'XYZ'.
WRITE: / 'XYZ,     sy-subrc:', sy-subrc.
WRITE: / num, sy-datum.
ULINE.

SET COUNTRY space.
WRITE: / 'space,   sy-subrc:', sy-subrc.
WRITE: / num, sy-datum.
ULINE.

This program outputs the packed number numand the system field num using different formatting options.

This graphic is explained in the accompanying text

The first and the last output are user-specific. For all other output, the system reads table T005X. It does not find the entry 'XYZ' and sets the output format itself. The entries in T005X are customer-specific.

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.

Example

REPORT demo_list_write_currency LINE-SIZE 40.

DATA: num1 TYPE p  DECIMALS 4 VALUE '12.3456',
      num2 TYPE p  DECIMALS 0 VALUE '123456'.

SET COUNTRY 'US'.

WRITE: 'USD', num1 CURRENCY 'USD', num2 CURRENCY 'USD',
     / 'BEF', num1 CURRENCY 'BEF', num2 CURRENCY 'BEF',
     / 'KUD', num1 CURRENCY 'KUD', num2 CURRENCY 'KUD'.

This program defines two packed numbers num1und num2, containing the same sequence of digits, but different numbers of decimal places. These numbers appear in the output in several currencies:

This graphic is explained in the accompanying text

For each currency, the output formats of num1 und num2 are the same, since they refer to the sequence of digits only. The currency US Dollar (USD) appears in the default setting of two decimal places, since the smallest unit is one Cent and a hundredth of a Dollar. For Belgian Francs (BEF), CURRDEC in TCURX is set to 0, since the Belgian Franc has no smaller units. Dinars from Kuweit (KUD) have units of a thousandth and therefore three decimal places (CURRDEC is 3).

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 WRITEstatement 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.

Example

REPORT demo_list_write_unit LINE-SIZE 40.

DATA: num1 TYPE p DECIMALS 1 VALUE 1,
      num2 TYPE p DECIMALS 4 VALUE '2.5'.

SET COUNTRY 'US'.

WRITE: 'KG', num1 UNIT 'KG', num2 UNIT 'KG',
     / 'PC', num1 UNIT 'PC', num2 UNIT 'PC'.

This program defines two packed numbers, num1 with one decimal place and num2with four decimal places. If the unit 'KG' (kilograms) has three decimal places in table T006 and 'PC' (pieces) has zero decimal places in T006, the output appears as follows:

This graphic is explained in the accompanying text

The system ignores the option UNIT 'KG' for num1, since num1 has less than three decimal places. The UNIT 'KG' option shortens the output of num2to three decimal places. The UNIT 'PC' option shortens the output of num1to zero decimal places. For num2, the system ignores the option UNIT 'PC', since otherwise a decimal place unequal to zero would have been truncated.

 

 

Leaving content frame