ABAP Addition 1 ... LEFT-JUSTIFIED|CENTERED|RIGHT-JUSTIFIED 2 ... EXPONENT exp 3 ... NO-GROUPING 4 ... NO-SIGN 5 ... NO-ZERO 6 ... CURRENCY cur 7 ... DECIMALS dec 8 ... ROUND scale 9 ... UNIT unit 10 ... ENVIRONMENT TIME FORMAT 11 ... TIME ZONE tz 12 ... STYLE stl 13 ... USING { {NO EDIT MASK}|{EDIT MASK mask} } 14 ... DD/MM/YY | MM/DD/YY | DD/MM/YYYY | MM/DD/YYYY | DDMMYY | MMDDYY | YYMMDD
What does it do? These formatting options override thepredefined formats of the statements WRITE ... TO and WRITE . Without these additions, the content of the source field is formatted only according to its data type.
The result of the formatting is adapted to the available length. In the case of WRITE ... TO, this is the length of the target variable; in the case of WRITE, this is the output length. In some cases, the behavior of the additions used in combination with WRITE can differ from the general behavior in the case of WRITE ... TO.
If a conversion routine is executed when formatting, the other formatting options are ignored.
The additions can be used together, with the following restrictions: The additions ENVIRONMENT TIME FORMAT and TIME ZONE are mutually exclusive and cannot be used with the additions CURRENCY , DECIMALS, EXPONENT, NO-GROUPING, NO-SIGN, NO-ZERO, ROUND, STYLE, or UNIT. The addition STYLE cannot be used together with the additions CURRENCY, DD/MM/YY, ... , YYMMDD, ROUND, ENVIRONMENT TIME FORMAT, TIME ZONE, and UNIT. The addition UNIT cannot be used together with the additions DECIMALS, ROUND, STYLE, ENVIRONMENT TIME FORMAT , and TIME ZONE.
Latest notes:The definition of a decimal floating point number in ABAP Dictionary always defines an output style. This means that, when data objects declared with a reference to this type in ABAP Dictionary and are part of the output, then the same exclusions apply as when using the addition STYLE. • LEFT-JUSTIFIED WRITE • CENTERED WRITE • RIGHT-JUSTIFIED WRITE
ABAP Addition
What does it do? This addition determines whether the content of the source field that is formatted according to the other options is adjusted within the available length to the right, the center, or to the left. Trailing blanks are ignored for fields of type c and are treated like all other characters for fields of type string.
The adjustment is done by filling surplus positions in the result either from the right or from the left or alternately from the left and right with blanks. If the available length is too short, source fields of the types c and string are truncated on the left (if right-justified), unlike the usual cutoff behavior.
Example ABAP Coding Left-justified, centered, and right-justified assignment of three text field literals to a text field of 50 characters length. DATA formatted_text TYPE c LENGTH 50.
WRITE 'Left' TO formatted_text LEFT-JUSTIFIED. cl_demo_output=>write( formatted_text ). WRITE 'Center' TO formatted_text CENTERED. cl_demo_output=>write( formatted_text ). WRITE 'Right' TO formatted_text RIGHT-JUSTIFIED. cl_demo_output=>write( formatted_text ).
cl_demo_output=>display( ). • EXPONENT WRITE
ABAP Addition
This addition cannot be used together with additions ENVIRONMENT TIME FORMAT and TIME ZONE.
What does it do? This addition determines the exponent when formattingfloating point numbers. The addition EXPONENT affects source fields of the type f or when the STYLE addition is declared. Otherwise it is ignored.
exp expects a data object of the type i that contains the required exponent. In data type f, the mantissa is adjusted to this exponent by moving the decimal point and padding with zeros. If exp contains 0, no exponent is created. If the value of exp is greater than the exponent of the source field plus 16, only zeros are allocated to the mantissa. If the value of exp is less than the exponent of the source field, and there is not enough space for the places required before the decimal point, the addition is ignored. If the value in exp is positive and has more than three digits, only the first three digits of the exponent are used. The addition STYLE converts source fields of all numeric types (b, s), i, int8, p, f, decfloat16, and decfloat34 before formatting to decfloat34. Only the scientific notation O_SCIENTIFIC can be declared together with EXPONENT after STYLE. The addition EXPONENT defines the exponent here.
Example ABAP Coding The formatted result of the statement WRITE TO is '1,414'. The standard formatting for a length of 6 would be '1E+00'. DATA: float TYPE f, formatted_text TYPE c LENGTH 6.
This addition cannot be used together with additions ENVIRONMENT TIME FORMAT and TIME ZONE.
What does it do? When formatting data objects of the data types (s ), i, int8, p, decfloat16, or decfloat34, this addition suppresses the thousands separators. Otherwise, the addition is ignored. • NO-SIGN WRITE
ABAP Addition
This addition cannot be used together with additions ENVIRONMENT TIME FORMAT and TIME ZONE.
What does it do? When formatting data objects of the data types (s ), i, int8, p, decfloat16, decfloat34, or f, this addition suppresses the sign. Otherwise, the addition is ignored.
Example ABAP Coding Output of numbers with explanatory text instead of with +/-sign. DATA: number TYPE i, formatted_text TYPE c LENGTH 10.
DO 10 TIMES. number = sy-index - 5. IF number >= 0. WRITE number TO formatted_text. cl_demo_output=>write_text( formatted_text <(> <)><(> <)> ` (positive)` ). ELSE. WRITE number TO formatted_text NO-SIGN. cl_demo_output=>write_text( formatted_text <(> <)><(> <)> ` (negative)` ). ENDIF. ENDDO. cl_demo_output=>display( ). • NO-ZERO WRITE
ABAP Addition
This addition cannot be used together with additions ENVIRONMENT TIME FORMAT and TIME ZONE.
What does it do? If the source field has a numeric data type and contains the value 0, the available length is padded with blanks. If the source field has the data type c, n, or string, leading zeros are formatted as blanks. Otherwise, the addition is ignored.
Example ABAP Coding Formatting the content of a numeric text field as '123' instead of '0000000123'. DATA: num TYPE n LENGTH 10 VALUE '123', formatted_text TYPE c LENGTH 10.
WRITE num TO formatted_text. cl_demo_output=>write_text( formatted_text ). WRITE num TO formatted_text NO-ZERO. cl_demo_output=>display_text( formatted_text ). • CURRENCY WRITE
ABAP Addition
This addition cannot be used together with the additions ENVIRONMENT TIME FORMAT and TIME ZONE and not for the numerical data types decfloat16 and decfloat34. This means it also cannot be used together with the addition STYLE.
What does it do? This addition determines the currency-dependentfractional portion when formatting data objects of the numeric data types (b, s), i, int8, p, and f. The numeric data types decfloat16 and decfloat34 produce a syntax error or raise an exception. For all other data types the addition is ignored.
For all permitted numerical data types, cur expects a character-like field containing a currency code from the column WAERS of the database table TCURC in uppercase. Usually two decimal places are used for every value entered in cur, unless the currency code specified is in the column CURRKEY of the database table TCURX. In this case, the number of decimal places is determined using the CURRDEC column of this table.
For the individual numeric data types, the following applies: For data objects of the types (b, s) and i und int8 , a decimal separator is inserted into the result at the position determined by cur and the thousands separators are moved accordingly. For data objects of type p, the decimal places determined by the definition of the data type are ignored completely. Independent of the actual value and without rounding, decimal separators and thousands separators are inserted between the digits at the positions determined by cur. For data objects of type f, addition CURRENCY has the same effect as addition DECIMALS (see below), where the number of decimal places is determined by cur.
Latest notes:The addition CURRENCY is useful with currencies from the database tables TCURC or TCURX for displaying data objects of types (b, s), i , int8 , or p without decimal places, whose contents are currency amounts in the smallest unit of the currency.
Example ABAP Coding The formatted result of '12345678' is '123456,78'. The currency code 'EUR' is contained in the database table TCURC , but not in TCURX. For this reason two decimal places are used by default. DATA: int TYPE i VALUE 12345678, formatted_text TYPE c LENGTH 10.
WRITE int TO formatted_text NO-GROUPING CURRENCY 'EUR'. cl_demo_output=>display_text( formatted_text ). • DECIMALS WRITE
ABAP Addition
This addition cannot be used together with additions ENVIRONMENT TIME FORMAT, TIME ZONE, and UNIT.
What does it do? This addition determines the number ofdecimal places when formatting data objects of the data types (b, s),i, int8, p, decfloat16, decfloat34, or f. Otherwise, the addition is ignored.
dec expects a data object of type i that contains the number of desired decimal places. If the content of dec is less than 0, it is treated like 0. The content of data objects of data types (b, s), i, or p is multiplied by 10 to the power of dec beforehand. For the individual numeric data types, the following applies: For data objects of types (b, s) and i und int8 , a decimal separator and as many zeros as specified in dec are appended. The content of dec must not exceed 14, otherwise an unhandleable exception is raised. If the content of dec is 0, the output remains unaffected. For data objects of type p, independently of the number of decimal places determined in the data type, as many decimal places are used as are specified in dec. The content of dec must not exceed 14, otherwise an unhandleable exception is raised. If the source field has more decimal places, they are rounded to the decimal places in dec. If the source field has fewer decimal places, zeros are appended for the missing number. For data objects of types decfloat16 and decfloat34, the content of dec decides the number of decimal places in mathematical notation and the number of decimal places in the mantissa in scientific notation. For data objects of type f, the content of dec determines the number of decimal places in the scientific notation. If the content of dec is greater than 16, it is handled like 16. If the content of dec is greater than the number of decimal places of the source field, zeros are appended accordingly. If the content of dec is less than the number of decimal places of the source field, they are rounded to the decimal places in dec.
If the addition CURRENCY is also specified, it is first executed for the data types (b, s), i , int8 , and p before the addition DECIMALS is applied. For data type f, the addition CURRENCY is ignored if it is specified together with DECIMALS.
Example ABAP Coding The formatted result of '1234.5678' is '1234,57'. DATA: pack TYPE p LENGTH 8 DECIMALS 4 VALUE '1234.5678', formatted_text TYPE c LENGTH 10.
This addition cannot be used together with additions STYLE,ENVIRONMENT TIME FORMAT, TIME ZONE, and UNIT. Also, ROUND cannot be used for decimal floating point numbers defined in ABAP Dictionary, because these always have an output style assigned to them.
What does it do? For source fields of data type p, this addition multiplies the value of the data object by 10 to the power of -scale before it is formatted. Otherwise, the addition is ignored.
scale expects a data object of type i that contains the value of the desired scaling.
If the value of scale is greater than 0 and the addition DECIMALS is not specified, the intermediate result is rounded to the fractional portion defined in the data type. If the addition DECIMALS is specified, it is rounded to the number of decimal places specified in dec and these places are output.
If the addition CURRENCY is specified, it is applied to the content of the source field before the multiplication is executed. If the addition DECIMALS is not specified, the number of decimal places determined by cur is used for rounding and formatting. If the addition DECIMALS is specified, the value in dec is used.
Example ABAP Coding The formatted result of '12345678' is '123456.7800'. DATA: pack TYPE p LENGTH 8 DECIMALS 0 VALUE '12345678', formatted_text TYPE c LENGTH 12.
WRITE pack TO formatted_text NO-GROUPING ROUND 2 DECIMALS 4. cl_demo_output=>display_text( formatted_text ). • UNIT WRITE
ABAP Addition This addition cannot be used together with additions DECIMALS, ROUND, STYLE, ENVIRONMENT TIME FORMAT, and TIME ZONE. Also, UNIT cannot be used for decimal floating point numbers defined in ABAP Dictionary, because these always have an output style assigned to them.
What does it do? This addition truncates thedecimal places that have a value of 0 and that lie outside of the accuracy of a measurement unit when formatting data objects of data type p. Otherwise the addition is ignored (except for type f).
unit expects a character-like field that contains aunit code from column MSEHI of database table T006 in uppercase letters. The system uses column DECAN of the related row in database table T006 to determine the number of decimal places. If the content of unit is not found in T006, the addition is ignored. If the data type of source field is p and has at least as many decimal places as specified by unit, and if no other places that are not equal to 0 are truncated by this action, the content of the source field is formatted with this number of decimal places. For data objects of type f, the addition UNIT has the same effect as the addition DECIMALS (see above), where the number of decimal places is determined by unit.
If, at the same time, the addition CURRENCY is used, this addition is executed first for data type p, before addition UNIT. In this case the addition is ignored for data type f as well.
Example ABAP Coding The first unit ID of the database table T006 is read for which no decimal places are specified in the column DECAN and this ID is used after the addition UNIT. This formats '1234.0000' as '1234'. DATA: pack TYPE p LENGTH 8 DECIMALS 4 VALUE '1234.0000', formatted_text TYPE c LENGTH 12, unit TYPE t006-msehi.
SELECT SINGLE msehi FROM t006 INTO (unit) WHERE decan = 0.
IF sy-subrc = 0. WRITE pack TO formatted_text NO-GROUPING UNIT unit. cl_demo_output=>display_text( formatted_text ). ENDIF. • ENVIRONMENT TIME FORMAT WRITE
ABAP Addition
This addition cannot be used together with additions CURRENCY,DECIMALS, EXPONENT, NO-GROUPING, NO-SIGN, NO-ZERO,