Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

write statement

Former Member
0 Likes
4,491

explain the different formatting options for write statement

5 REPLIES 5
Read only

prasanth_kasturi
Active Contributor
0 Likes
2,360

hi,

http://venus.imp.mx/hilario/Libros/TeachYrslfAbap4/ch14.htm

Extras:

1. ... LEFT-JUSTIFIED|CENTERED|RIGHT-JUSTIFIED

2. ... NO-GAP

3. ... UNDER other_dobj

4. ... EXPONENT exp

5. ... NO-GROUPING

6. ... NO-SIGN

7. ... NO-ZERO

8. ... CURRENCY cur

9. ... DECIMALS dec

10. ... ROUND scale

11. ... UNIT unit

12. ... TIME ZONE tz

13. ... USING { {NO EDIT MASK}|{EDIT MASK mask} }

14. ... DD/MM/YY | MM/DD/YY

| DD/MM/YYYY | MM/DD/YYYY

| DDMMYY | MMDDYY

| YYMMDD

Effect

These format options override the predefined settings. Without the specification of these additions, the output format depends implicitly on the data type. The result of formatting is adjusted to match the output length. If, during output, a conversion routine is executed, all the formatting options - except for NO-GAP and UNDER - are ignored.

The additions can be used together with the following limitations:

The addition UNIT cannot be used together with the additions DECIMALS and ROUND.

The addition TIME ZONE cannot be used together with the additions CURRENCY, DECIMALS, EXPONENT, NO-GROUPING, NO-SIGN, NO-ZERO, ROUND, or UNIT.

Addition 1

... LEFT-JUSTIFIED|CENTERED|RIGHT-JUSTIFIED

Effect

This addition defines whether the output formatted according to the other options is aligned left-justified, centered, or right-justified outside the current output length in the list buffer. Closing blanks are ignored in the case of fields of the type c and they are treated like the other characters in the case of fields of type string.

The alignment takes place in that the superfluous positions in the list buffer are filled up either right-justified, or left-justified, or alternating right and left. If the output length is not sufficient, the characters are cut off to the right for left-justified and centered, and to the left for right-justified alignment.

If the output length in the list display is not sufficient in Unicode systems, characters are cut off during transfer of data from the list buffer into the list. They are cut off to the right for left-justified, and to the left for right- justified output. In the case of centered output, blanks are removed in alternating fashion on both sides, whereby the cut-off starts on the side with more blanks, and then the other characters on the right side. If, during data transfer from the list buffer into the list, characters are cut off, this is made visible on the left side with the character < and on the right side with the character >.

Example

Output of three literals left, in the middle, and to the right of an output area 60 characters in length.

WRITE: /(60) 'Left' LEFT-JUSTIFIED,

/(60) 'Center' CENTERED,

/(60) 'Right' RIGHT-JUSTIFIED.

Addition 2

... NO-GAP

Effect

The list cursor is positioned directly after the output and not in the position in the list buffer after the next one.

Example

The output for both WRITE statements is " NoGap".

WRITE: 'No' NO-GAP, 'Gap'.

Addition 3

... UNDER other_dobj

Effect

The output takes place in the current line at the position where, in a previous WRITE statement, the data object other_dobj was output. The data object other_dobj must be written in the same way as in the respective WRITE statement - that is, including possible offset/length specifications, and so on. if the data object other_dobj was not specified beforehand, the addition is ignored.

The addition UNDER cannot be used together with a position specification pos after AT.

Vertical positioning must be taken care of. If the list cursor is at the same position as the output of other_dobj, this will be overwritten.

The data object other_dobj should be defined globally in the current program. The use of local data objects in procedures can lead to undesirable results, for example, if components with the same structure are used in different procedures.

Example

Table-type output of flight connections.

DATA: carrid TYPE spfli-carrid,

connid TYPE spfli-connid.

WRITE: 10 'Carrier', 40 'Connection'.

ULINE.

SELECT carrid connid

FROM spfli

INTO (carrid,connid).

WRITE: / carrid UNDER 'Carrier',

connid UNDER 'Connection'.

ENDSELECT.

Addition 4

... EXPONENT exp

This addition cannot be used together with the addition TIME ZONE.

Effect

This addition defines the exponent for output of data objects of the data type f. For all other data types, the addition is ignored. For exp, a data object of the type i is expected that contains the required exponent. The mantissa is adjusted by moving the decimal point and inserting zeroes to the exponent. If exp contains the value 0, no exponent is output. If the value of exp is larger than the exponent in dobj plus 16, only zeroes are displayed in the mantissa. If the value of exp is less than the exponent in dobj and the output length is not sufficient for the required positions bfore the decimal separator, the addition is ignored. If the value in exp is positive and more than three digits, only the first three positions of the exponent are displayed.

Example

The output of the WRITE statement is "1,414". The standard output for an output length of 6 would be "1E+00".

DATA float TYPE f.

float = sqrt( 2 ).

WRITE (6) float EXPONENT 0.

Addition 5

... NO-GROUPING

This addition cannot be used together with the addition TIME ZONE.

Effect

This addition suppresses the thousands separator in the output of data objects of data types i or p. In all other data types, the addition is ignored.

Addition 6

... NO-SIGN

This addition cannot be used together with the addition TIME ZONE.

Effect

This addition suppresses the plus/minus sign in the output of data objects of data types i, p, or f. In all the other data types, the addition is ignored.

If the addition NO-SIGN is used with the length specification * or ** after AT, it is used first and the output length is determined from the result.

Example

Output with red background color instead of with a plus/minus sign.

DATA number TYPE i.

DO 10 TIMES.

number = sy-index - 5.

IF number < 0.

WRITE number NO-SIGN COLOR = 6.

ENDIF.

ENDDO.

Addition 7

... NO-ZERO

This addition cannot be used together with the addition TIME ZONE.

Effect

If dobj has a numeric data type and contains the value 0, blanks are output for the length of the output. If dobj has the data type c, n, or string, leading zeroes are displayed by blanks.

Example

Output of 22 blanks with red background color instead of the standard output "0,0000000000000000E+00".

DATA float TYPE f.

SET BLANK LINES ON.

IF float = 0.

WRITE float NO-ZERO COLOR = 6.

ENDIF.

Addition 8

... CURRENCY cur

This addition cannot be used together with the addition TIME ZONE.

Effect

This addition defines currency-dependent decimal places for the output of data objects of data types i or p. For all other data types, except for f, the addition is ignored. For cur, a three-digit, character-type field is expected that contains a currency key from the column CURRKEY of the database table TCURX in uppercase letters. The system determines the number of decimal places from the column CURRDEC of the respective row in the database table TCURX. If the content of cur is not found in TCURX, two decimal places are used. The following applies for numeric data types:

In the case of data types of type i, a decimal separator is inserted at the position determined by cur and the thousands separators are moved accordingly.

In the case of data objects of type p, the decimal places defined in the definition of the data type are ignored completely. Irrespective of the actual value and without rounding actions, the decimal separators and the thousand separators are inserted at the positions in the numbers determined by cur.

In the case of data objects of type f, the addition CURRENCY has the same effect as the addition DECIMALS (see below). Here, the number of decimal places is determined by cur.

If the addition CURRENCY with length specification * or ** is used after AT, it is used first and the output length is determined from the result.

Note

The addition CURRENCY is appropriate for the display of data objects of type i or p without decimal places, whose contents are currency amounts in the smallest unit of the currency.

Example

The output of the WRITE statement is "123456,78".

DATA int TYPE i VALUE 12345678.

WRITE int NO-GROUPING CURRENCY 'EUR'.

Addition 9

... DECIMALS dec

This addition cannot be used together with the addition TIME ZONE.

Effect

This addition defines the number of displayed decimal places for the output of data objects of data types i, p, or f. For all other data types, the addition is ignored. For dec, a data object of type i is expected that contains the number of required decimal places. If the content of dec is less than 0, it is treated as 0, whereby the content of data objects of data types i or p is previously multiplied by 10 to the power of dec. For the individual numeric data types, the following applies:

In the case of data objects of type i, a decimal separator and as many zeroes as are specified in dec are added on. The content of dec can be maximum 14. Otherwise, an exception that cannot be handled will be triggered. If the content of dec is 0, the output is unchanged.

In the case of data objects of type p, as many decimal places as are specified in dec are displayed - irrespective of the number of decimal places defined in the data type. The content of dec can be maximum 14. Otherwise, an exception that cannot be handled will be triggered. If dobj has more decimal places, it is rounded to the decimal places in dec. If dobj has less decimal places, a corresponding number of zeroes are inserted.

In the case of data objects of type f, the content of dec determines the number of decimal places in scientific notation. If the content of dec is greater than 16, it will be treated like 16. If the content of dec is greater than the number of decimal places in dobj, a corresponding number of zeroes will be inserted. If the content of dec is less than the number of decimal places in dobj, it is rounded to the decimal places defined in dec.

If the addition DECIMALS is used with length specification * or ** after AT, it is used first and then the output length is determined from the result.

If the addition CURRENCY is specified as well, this is executed first in the case of data types i and p, and then the addition DECIMALS is applied. In the case of data type f, the addition CURRENCY is ignored if it is specified together with DECIMALS.

Example

The output for the WRITE statement is "1234,57".

DATA pack TYPE p LENGTH 8 DECIMALS 4 VALUE '1234.5678'.

WRITE pack NO-GROUPING DECIMALS 2.

Addition 10

... ROUND scale

This addition cannot be used together with the addition TIME ZONE.

Effect

If dobj has the data type p, this addition multiplies the value of the data object, before output, by 10 to the power of scale. In all other data types, the addition is ignored. For scale, a data object of type i is expected that contains the value of the required scale.

If the value of scale is greater than 0 and the addition DECIMALS is not specified, the interim result is rounded to the number of decimal places 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 are then output.

If the addition ROUND is used with the length specification * or ** after AT, it is used first and the output length is determined from the result.

If the addition CURRENCY is specified, this is used, before multiplication, for the content of dobj. If the addition DECIMALS is not specified, the number of decimal places specified through cur is used for rounding off and for the output. If the addition DECIMALS is specified, the value in dec is used.

Example

The output of the WRITE statement is "123456,7800".

DATA pack TYPE p VALUE '12345678'.

WRITE pack NO-GROUPING ROUND 2 DECIMALS 4.

Addition 11

... UNIT unit

This addition cannot be used together with the addition TIME ZONE.

Effect

This addition cuts off decimal places that have the value 0 and are outside the exactness of a unit of measure during output of data objects of data type p. For all other data types, except f, this addition is ignored. For unit, a three-digit, character-type field is expected that contains a unit key from the column MSEHI in the database table T006 in uppercase letters. The system determines the number of decimal places from the column DECAN in the corresponding row in the database table T006. If the content of unit is not found in T006, the addition is ignored.

If the data type of dobj is p and has at least as many decimal places as specified by unit, and if no positions are thus cut off that are not equal to 0, then dobj is output with this number of decimal places.

In the case of data objects of type f, the addition UNIT will be treated like the addition DECIMALS (see above). Here, the number of decimal places is determined by unit.

If the addition UNIT is used with the length specification * or ** after AT, it is used first, and the output length is determined from the result.

If the addition CURRENCY is used at the same time, this is used first for data type p and then the addition UNIT is used. In the case of data type f, the addition UNIT is ignored.

Example

If no decimal places are specified for the number "PC" in T006, the output of the WRITE statement is "1234".

DATA pack TYPE p DECIMALS 4 VALUE '1234.0000'.

WRITE pack NO-GROUPING UNIT 'PC'.

Addition 12

... TIME ZONE tz

Effect

This addition edits a time stamp in relation to a time zone. The data object dobj must be of type p of length 0 without decimal places, or of type p of length 11 with seven decimal places. The content of dobj is interpreted in such a way as if it contained the long or the short form of a time stamp in UTC reference time.

For tz, a data object of type TIMEZONE from the ABAP Dictionary must be specified. It must contain a time zone from the column TZONE of the database table TTZZ in uppercase letters. If tz is initial, the UTC reference time is output.

The time stamp in dobj is converted to the time zone given in tz, and edited as follows from the left:

First of all, the date is output. The format depends on the settings in the user master record or on any data mask date_mask specified concurrently. After the date, a blank is output.

Secondly, the time is output in the format predefined for type t. Colons ":" are inserted here as separators between hours, minutes, and seconds.

If the time stamp is in the long form, a comma "," is output directly after the time, and after that the milliseconds.

If the value of tz is not contained in the database table TTZZ or if dobj does not contain any valid time stamp, the content of dobj is output without conversion. Before the date, an asterisk "*" is entered, and the last position of the time is cut off.

The editing takes place in an interim result of length 19 if the time stamp is in its short form or of length 27, or if the time stamp is in the long form. If the output length is shorter than 19 or 27, respectively, first all the separators in date and time are removed in the interim result, then the blanks between date and time, and only then characters are cut off at the right. If, at the same time, a date mask date_mask is specified, the separators in the date are not removed.

Note

The data objects dobj and tz can be declared in relation to data types TIMESTAMP, TIMESTAMPL, and TIMEZONE in the ABAP Dictionary.

Example

Output of a UTC time stamp in Tasmanian time. In daylight-saving time, the output is "28.06.2002 04:00:00".

DATA: time_stamp TYPE timestamp,

tzone TYPE timezone.

time_stamp = 20020627180000.

tzone = 'AUSTAS'.

WRITE / time_stamp TIME ZONE tzone.

Addition 13

... USING { {NO EDIT MASK}|{EDIT MASK mask} }

Effect

This addition overrides a conversion routine defined through reference to the ABAP Dictionary. The addition NO EDIT MASK only switches off the execution of an assigned conversion routine. The addition EDIT MASK calls either another conversion routine or defines an edit mask. For mask, a data object of the same name is expected.

In order to call an arbitrary conversion routine CONV, mask must contain two equals signs, followed directly by the name of the conversion routine: "==CONV". During output, the content of dobj is passed to the function module CONVERSION_EXIT_CONV_OUTPUT, converted there, and then the result is displayed. If the function module is not found, an exception that can be handled is triggered (as of Release 6.10). The statement DESCRIBE FIELD contains an addition in order to fill mask accordingly.

If the output length is specified explicitly with len, the conversion routine is executed for the specified length; otherwise for the implicit output length. If * or ** is specified for the output length, the appropriate rules are used for the converted result.

If the first two characters in mask are not equals signs, the content is interpreted as an edit mask in which some characters have a particular meaning. The WRITE statement does not then output the content of dobj directly, but the character string in mask as follows:

If the first two characters in mask are "LL" or "RR ", these are not output, They control whether the edit mask is left-justified or right-justified. If the first two characters are other characters, the edit mask is left-justified.

All "_" characters are replaced from the left (in the case of "LL") or from the right (in the case of "RR") with characters for character-type types or numbers for the types p or i from dobj. In the case of fields of type c, closing blanks are ignored. Data objects of type f or x are converted into type c before editing. Superfluous characters "_" in mask are replaced by blanks. Characters from dobj for which there are no characters "_" in mask are not displayed.

If dobj is of type i or p, the first character from the left "V" in mask is replaced with "-" in the case of a negative number and by blank in the case of a positive number.

All the other characters of the edit mask are displayed unchanged.

If no output length is specified, the implicit output length of dobj is used. If len is specified for the output length, the value of len is used. If * is specified for the output length, exactly that length that is required for the list display is set. If, in Unicode systems, characters of the edit mask are replaced by characters that take up more than one column on the list, the output length is increased accordingly and the output is filled with blanks in the list buffer. If ** is specified for the output length, double the length of the edit mask mask is used.

If other formatting options are specified concurrently for an edit mask, these are used first and then the special characters in the edit mask are replaced by the interim result. The date masks date_mask are an exception to this. If these are specified, the edit mask is ignored.

Notes

In Unicode systems, you must remember that a character "_"in the edit mask does not necessarily correspond to a column in the list display since the space required in the display depends on the character to be replaced.

The minus sign for a negative number is not displayed if no edit character "V" is specified. The decimal separator of a packed number with decimal places must be specified at the required position in the edit mask.

Example

Edited output of time duration. In the first output, the function module CONVERSION_EXIT_DURA_OUTPUT is executed. This converts the duration specified in seconds into minutes. In the second output, the edit mask is output according to the above rules. However, the underscore characters "_" are replaced by the characters from time.

DATA: dura TYPE i,

time TYPE t VALUE '080000'.

dura = sy-uzeit - time.

time = dura.

WRITE /(30) dura USING EDIT MASK '==SDURA'.

WRITE /(30) time USING EDIT MASK

'RRThe duration is __:__:__'.

Addition 14

... DD/MM/YY | MM/DD/YY

| DD/MM/YYYY | MM/DD/YYYY

| DDMMYY | MMDDYY

| YYMMDD

Effect: These additions influence the output of data objects of the data type d. In all other data types, the addition is ignored.

The content of a data object of type d is interpreted as a valid date in the format YYYYMMDD and is output as follows for the individual additions:

DD/MM/YY and MM/DD/YY:

Both additions have the same effect. The date output has a two-digit year value and a separator. The separator and the order are taken from the definition for date output in the user master record.

DD/MM/YYYY und MM/DD/YYYY:

Both additions have the same effect. The date output has a four-digit year value and separator. The separator and the order are taken from the definition for date output in the user master record.

DDMMYY und MMDDYY:

Both additions have the same effect. The date output has a two-digit year value and no separator. The order is taken from the definition for date output in the user master record.

YYMMDD:

This addition provides a date output with a two-digit year value without a separator in the format YYMMDD.

If the output length is defined implicitly or specified using len, this is used. If it is too short, the edited output is cut off to the right. If the output length is specified using * or **, it is set to the length of the specified edit mask (6, 8, or 10).

Note

The behavior for abbreviation differs from the output of a data in accordance with the user master record, where the separator is removed first and then cut off.

Example

The output of the WRITE statement is, for example, "230402".

WRITE sy-datum YYMMDD.

reward if helpful

prasanth

Read only

GauthamV
Active Contributor
0 Likes
2,360

hi,

WRITE - Output to a list

Basic form

WRITE f.

Extras:

1. ... [AT] [/][pos][(len||*) (position and length specification)

2. ... option (formatting option)

3. ... fmt (field-by-field display format)

4. ... AS CHECKBOX (output as a checkbox)

5. ... AS SYMBOL (output as a symbol)

6. ... AS ICON (output as an icon)

7. ... AS LINE (output as a line)

8. ... QUICKINFO g (output as a tool tip)

Effect

Outputs an elementary field f in the correct format for its type in the current list.

Examples

DATA SPFLI_WA TYPE SPFLI.

DATA N TYPE I VALUE 123.

...

WRITE N.

WRITE SPFLI_WA-FLTIME.

FIELD-SYMBOLS <CF> TYPE ANY.

ASSIGN 'NEW YORK' TO <CF>.

WRITE <CF>.

WRITE: '---->', SPFLI_WA-DISTANCE.

WRITE: TEXT-001, SPFLI_WA-ARRTIME.

or

WRITE: 'Time:'(001), SPFLI_WA-ARRTIME.

As in all ABAP statements, text symbols can be addressed in two different ways (TEXT-001 or 'Time:'(001)).

Notes

If no explicit position is specified for a field on a new line, it is output on the left (in column 1). Otherwise, output is one column removed from the previously output field. If a field does not fit on one line, a new line is started.

You can perform explicit positioning with a position and length specification (see addition 1) or with ABAP/4 statements (e.g. POSITION). In this case, the field is always output at the defined position, even if the line is not quite long enough for it to fit completely.

If a field is too long to fit completely on the line, the excess characters are truncated.

When you explicitly position fields on a list, you should almost always use the ... LINE-SIZE (for the corresponding REPORT- or NEW-PAGE NEW-PAGE- statement); otherwise, the width of the list will depend on the current width of the display window, the font used, and other such factors that can lead to the list display being truncated.

Predefined Output Formats

System fields that are useful when generating lists are documented in System Fields for Lists.

Please consult Data Area and Modularization Unit Organization documentation as well.

Addition 1

... [AT] [/][pos][(len||*) (position and length specification before the field)

The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas.See Incorrect Dynamic Position Specifications.

Effect

After AT, you can specify the output position and output length of the current WRITE statement. Any output that already exists at the output position is overwritten in the list buffer in the output length of the new output. After overwriting an existing output, the system sets the list cursor to the next position and not the one after.

The elements of the position and length specification /, pos and len or * or ** must be listed in the specified order and without spaces. If no named data objects are specified in the position and length specification, the AT addition can be omitted.

Using / results in the output in the next line after the current line. If no position pos is specified, the system writes from the first column. Specifying / directly after positioning the list cursor in a list row that is not preceded by an output statement has no effect. This is the case when first writing to a page of a list and after explicit positioning using the statements SKIP, NEW-LINE, NEW-PAGE, and BACK.

Specifying pos defines the output position. pos should be a data object of the type i that contains a value within the current list width. If the value in pos is less than 1 or greater than the current list width, no output takes place. The defined output position specifies the postion in the list buffer.

Specifying len, *, or ** in parentheses defines the output length. You can specify an absolute value with len. len should be a data object of the type i that contains a value within the current list width. If the value of len is less than or equal to 0, no output takes place. When specifying len in Unicode systems, the number of characters displayed on the list can differ from the number of characters stored in the list buffer. When specifying * or **, the output length depends on the data type of the data object dobj, as described in the following table:

Data Type * **

c Number of columns required to display the entire contents in the list; closing blanks are ignored. In Unicode systems, this length can be greater than the implicit length. Double the length of the data object

string implicit length Double the number of contained characters

n, x, xtring implicit length implicit length

d 10 10

t 8 8

i, f, p Length required to display the current value including thousand separators; the system uses the value that exists after the use of any of the additions CURRENCY, DECIMALS, NO-SIGN, ROUND, or UNIT. Length required to display the maximum possible values of these types including prefixes and thousand separators; the system uses the value that exists after the use of any of the additions CURRENCY, DECIMALS, NO-SIGN, ROUND, or UNIT.

If a conversion routine is executed with reference to a data type in the ABAP Dictionary, the routine is executed either for the length defined forlen or for the output length defined in the ABAP Dictionary for* or **, depending on which is specified. If you specify * or **, the output length is determined from the result of the conversion routine according the rules above.

Notes

It is always better to specify the output length len after AT than to use a length specification for the data object dobj (accesing part of a field). Unlike the latter option, specifying the output length is not only possible for byte-type and character-type data objects. Furthermore, when accessing part of a field, the assignment of the list output to the data object is lost and it can no longer be addressed in the list.

Specifying * or ** for the output length ensures that it is sufficient - regardless of the data type - to also display all characters of dobj in Unicode systems, even if more columns are required in the list than spaces in the list buffer. For * the system uses the smallest necessary length and for ** the largest possible length.

When specifying an output position within an existing output, you must ensure that the position always refers to the characters stored in the list buffer. If, in a Unicode system, characters are displayed that require more than one column in the list, the displayed output position can differ from the specified output position and the displayed content of a partially overwritten output may be moved, depending on the characters used to overwrite.

Examples

DATA: WORD(16), VALUE '0123456789ABCDEF',

COL TYPE I VALUE 5,

LEN TYPE I VALUE 10.

WRITE AT / WORD. "new line

WRITE AT 5 WORD. "column 5

WRITE AT (10) WORD. "output length 10

WRITE AT /5(10) WORD. "new line, column 5, length 10

WRITE AT COL WORD. "column = contents of COL

WRITE AT (LEN) WORD. "output length = contents of LEN

WRITE AT /COL(LEN) WORD. "new line, column = contents of COL

"output length = contents of LEN

Notes

The position and length specification must appear before the field.

If the position and length specification contains only constants, you the introductory AT is unnecessary. (In the first four of the above examples, you can therefore omit AT.)

Always write the position and length specification without gaps and in the specified order.

Leave at least one space between the position and length specification and the field name.

For dynamic positioning, see also POSITION.

No output results from positioning to the right of the far right edge of the page.

With explicit column specifications, the field is output from this column, even if it no longer completely fits on the line or overwrites another field.

If the output length is too short, numeric fields (types P, I and F are prefixed with an asterisk ('*'), while all other types are truncated on the right.

If you want the abbreviated output of a variable, you should always use WRITE (10) T100-TEXT rather than WRITE T100-TEXT(10) (sub-field access).

On the one hand, the first form is always allowed and the second form can be forbidden for certain data types (e.g. TYPE P). On the other hand, only the first form guarantees the identity of the variables for GET CURSOR ... FIELD and F1 help.

Addition 2

... option (formatting option)

Effect

You can modify the output of the field f by using one of the special formatting options.

Addition 3

... fmt (output format by field)

Effect

Outputs the field with the specified output formats (color, intensity, ready for input, ...).

You can use the same output options as for FORMAT. If no specifications are made, the field is output with the standard formats or with the format set by a preceding FORMAT statement.

Example

DATA F.

FORMAT INTENSIFIED OFF INPUT.

WRITE F INPUT OFF INVERSE COLOR 3.

Note

The format specifications with WRITE apply only for output of the field f. They modify the currently valid format for this field. This means that, in the above example, the non-highlighted output remains for the field F. When f has been output, the system reverts to the old format.

Addition 4

... AS CHECKBOX (output as checkbox)

WRITE - Output as checkbox

Effect

Outputs the field f as a checkbox. The contents of the first character of f is interpreted as the "status":

' ' = not selected

'X' = selected

The user can change this as required.

Note

To prevent the user changing the contents of the checkbox, you can use the addition ... INPUT OFF. The checkbox is then nothing more than a status display and can only be changed by programming.

In technical terms, a checkbox behaves exactly like an input field with a length of 1 (FORMAT INPUT).

Examples

DATA: MARKFIELD(1) TYPE C VALUE 'X'.

...

WRITE MARKFIELD AS CHECKBOX. "checkbox selected

MARKFIELD = SPACE.

WRITE MARKFIELD AS CHECKBOX. "deselected

WRITE MARKFIELD AS CHECKBOX INPUT OFF. "deselected, protected

Additional help

List Creation

Addition 5

... AS SYMBOL (output as symbol)

WRITE - Output as symbol

Effect

You can output certain characters as symbols using the addition ... AS SYMBOL. You should only address these characters with their system-defined names. The include <SYMBOL> (or the more comprehensive include <LIST>) contains the relevant identifiers as constants, e.g. SYM_PHONE, SYM_CIRCLE. (List of symbols, Proposals for use).

Example

INCLUDE .

WRITE: / SYM_RIGHT_HAND AS SYMBOL, " output as symbol

'Tip, Note',

SYM_LEFT_HAND AS SYMBOL. " output as symbol

Note

An output length of one character is enough for most symbols, but some (e.g. SYM_FAX) are twice as long.

You can determine the length of a symbol with DESCRIBE FIELD SYM_... OUTPUT-LENGTH ...

Additional help

List Creation

Addition 6

... AS ICON (output as icon)

WRITE - Output as icon

Effect

You can output certain characters as icons using the addition ...AS ICON. You should only address these characters with their system-defined names. The include <ICON> (or the more comprehensive include <LIST>) contains the relevant identifiers as constants, e.g. ICON_OKAY (see List of icons).

Example

INCLUDE .

WRITE: / ICON_OKAY AS ICON, "output as icon

'Text line'.

Note

Although an output length of 2 characters is enough for most icons, some (e.g. the traffic light icons ICON_RED_LIGHT, ...) have a greater output length.

You can determine the length of an icon with DESCRIBE FIELD ICON_... output length ....

You cannot print out all list icons. The printable icons are flagged as such in the 'list of icons' mentioned above.

Additional help

List Creation

Addition 7

... AS LINE (output as line)

WRITE - Output as line

Effect

On list output, automatically links certain characters together to form continuous lines or boxes, if there is no space between them:

vertical lines, output with the system field SY-VLINE or using a field with the contents "|" (vertical line)

horizontal lines, output with the system field SY-ULINE or using a field with at least 2 consecutive minus signs "--".

Exactly how each line segment is output (e.g. whether as straight line, corner, T-piece or cross) depends on the adjoining characters.

A good rule of thumb sipulates that if the cell adjacent to a line character also contains a line character, the missing piece required to form a connection is added. If an adjacent cell does not also contain a line character, the line character is truncated on that side. Line characters standing on their own remain unchanged.

This technique is sufficient to cope with most cases (e.g. tables, boxes, simple hierarchies). However, no matter how carefully you use some empty characters and lines, it is not possible to stop adjacent line characters being joined in an inappropriate way (e.g. very compact hierarchy diagrams, or densely boxes). The solution here is to output the required line segment explicitly using the addition ... AS LINE.

The include <LINE> (or the more comprehensive include <LIST>) contains the relevant identifiers for lines as constants, e.g. LINE_TOP_LEFT_CORNER, LINE_BOTTOM_MIDDLE_CORNER.

Note

Lines cannot have any other display attributes. If attributes such as color ( COLOR), reverse video (INVERSE) or intensified (INTENSIFIED) are set, these are ignored on output. If the ready for input attribute (INPUT) is set, the actual characters (minus sign, vertical line) are displayed.

Example

Output two nested corner segments:

INCLUDE .

ULINE /1(50).

WRITE: / SY-VLINE NO-GAP, LINE_TOP_LEFT_CORNER AS LINE.

ULINE 3(48).

WRITE: / SY-VLINE NO-GAP, SY-VLINE NO-GAP.

Additional help

List Creation

Note

General notes on outputting boxes to lists

When you output a list, this is sometimes combined with vertical and horizontal lines to form closed boxes:

Vertical lines are output by the system field SY-VLINE or by a field containing "|" (vertical bar),

Horizontal lines are output by the system field SY-ULINE or by a field containing only "-" (minus sign),

Vertical and horizontal lines converge (without gaps).

Addition 8

... QUICKINFO g

Effect

The field f is displayed with the tool tip g: Whenever the mouse pointer is positioned on the display area of f, the contents of g are displayed as an explanatory text on the list (in a small, differently-colored box).

Notes

The tool tip can be up to 40 characters long.

g must be a non-numeric field (data type C, N, D, or T).

Tool tips are unsuitable for lines, input fields, or checkboxes. Their suitability is also limited for icons that are normally displayed in longer fields (the icon assignment may be inexact).

If two output fields overlap (for example, when one field is placed over another with the POSITION ... statement, the 'bottom' field may not have a tool tip.

The output length of f must be greater than zero (f must actually be placed on the list) if you want to use the ... QUICKINFO addition.

Example

INCLUDE .

DATA: INFO(20) VALUE 'Information'.

WRITE: / SY-UNAME QUICKINFO 'User name'.

WRITE: / ICON_INFORMATION AS ICON QUICKINFO info

HOTSPOT COLOR COL_POSITIVE.

Additional help

Creating Lists

Read only

Former Member
0 Likes
2,360

Read the examples

Example

Output of three literals left, in the middle, and to the right of an output area 60 characters in length.

WRITE: /(60) 'Left' LEFT-JUSTIFIED,

/(60) 'Center' CENTERED,

/(60) 'Right' RIGHT-JUSTIFIED.

Example

The output for both WRITE statements is " NoGap".

WRITE: 'No' NO-GAP, 'Gap'.

Example

Table-type output of flight connections.

DATA: carrid TYPE spfli-carrid,

connid TYPE spfli-connid.

WRITE: 10 'Carrier', 40 'Connection'.

ULINE.

SELECT carrid connid

FROM spfli

INTO (carrid,connid).

WRITE: / carrid UNDER 'Carrier',

connid UNDER 'Connection'.

ENDSELECT.

Example

The output of the WRITE statement is "1,414". The standard output for an output length of 6 would be "1E+00".

DATA float TYPE f.

float = sqrt( 2 ).

WRITE (6) float EXPONENT 0.

Example

Output with red background color instead of with a plus/minus sign.

DATA number TYPE i.

DO 10 TIMES.

number = sy-index - 5.

IF number < 0.

WRITE number NO-SIGN COLOR = 6.

ENDIF.

ENDDO.

Example

Output of 22 blanks with red background color instead of the standard output "0,0000000000000000E+00".

DATA float TYPE f.

SET BLANK LINES ON.

IF float = 0.

WRITE float NO-ZERO COLOR = 6.

ENDIF.

Example

The output of the WRITE statement is "123456,78".

DATA int TYPE i VALUE 12345678.

WRITE int NO-GROUPING CURRENCY 'EUR'.

Example

The output for the WRITE statement is "1234,57".

DATA pack TYPE p LENGTH 8 DECIMALS 4 VALUE '1234.5678'.

WRITE pack NO-GROUPING DECIMALS 2.

Example

The output of the WRITE statement is "123456,7800".

DATA pack TYPE p VALUE '12345678'.

WRITE pack NO-GROUPING ROUND 2 DECIMALS 4.

Example

If no decimal places are specified for the number "PC" in T006, the output of the WRITE statement is "1234".

DATA pack TYPE p DECIMALS 4 VALUE '1234.0000'.

WRITE pack NO-GROUPING UNIT 'PC'.

Example

Output of a UTC time stamp in Tasmanian time. In daylight-saving time, the output is "28.06.2002 04:00:00".

DATA: time_stamp TYPE timestamp,

tzone TYPE timezone.

time_stamp = 20020627180000.

tzone = 'AUSTAS'.

WRITE / time_stamp TIME ZONE tzone.

Example

Edited output of time duration. In the first output, the function module CONVERSION_EXIT_DURA_OUTPUT is executed. This converts the duration specified in seconds into minutes. In the second output, the edit mask is output according to the above rules. However, the underscore characters "_" are replaced by the characters from time.

DATA: dura TYPE i,

time TYPE t VALUE '080000'.

dura = sy-uzeit - time.

time = dura.

WRITE /(30) dura USING EDIT MASK '==SDURA'.

WRITE /(30) time USING EDIT MASK

'RRThe duration is __:__:__'.

Example

The output of the WRITE statement is, for example, "230402".

WRITE sy-datum YYMMDD.

Read only

Former Member
Read only

Former Member
0 Likes
2,360

Hi,

Below is the formatting options for write statement :

You can use various formatting options with the WRITE statement.

Syntax

WRITE .... <f> <option>.

Formatting options for all data types

Option

Function

LEFT-JUSTIFIED

Output is left-justified.

CENTERED

Output is centered.

RIGHT-JUSTIFIED

Output is right-justified.

UNDER <g>

Output starts directly under field <g>.

NO-GAP

The blank after field <f> is omitted.

USING EDIT MASK <m>

Specifies format template <m>.

USING NO EDIT MASK

Deactivates a format template specified in the ABAP Dictionary.

NO-ZERO

If a field contains only zeros, these are replaced by blanks. For type C and N fields, leading zeros are replaced automatically.

Formatting options for numeric fields

Option

Function

NO-SIGN

The leading sign is not displayed on the screen.

DECIMALS <d>

<d> defines the number of digits after the decimal point.

EXPONENT <e>

In type F fields, the exponent is defined in <e>.

ROUND <r>

Type P fields are multiplied by 10**(-r) and then rounded.

CURRENCY <c>

Format according to currency <c> in table TCURX.

UNIT <u>

The number of decimal places is fixed according to unit <u> specified in table T006 for type P fields.

Formatting options for date fields

Option

Function

DD/MM/YY

Separators as defined in useru2019s master record.

MM/DD/YY

Separators as defined in useru2019s master record.

DD/MM/YYYY

Separators as defined in useru2019s master record.

MM/DD/YYYY

Separators as defined in useru2019s master record.

DDMMYY

No separators.

MMDDYY

No separators.

YYMMDD

No separators.

Below are some examples of formatting options. For more examples, see Creating Complex Lists. The decimal character and thousands separators (period or comma) of numeric fields are defined in the useru2019s master record

ABAP Code

Screen output

DATA: g(5) TYPE c VALUE 'Hello',

f(5) TYPE c VALUE 'Dolly'.

WRITE: g, f.

WRITE: /10 g,

/ f UNDER g.

WRITE: / g NO-GAP, f.

Hello Dolly

Hello

Dolly

HelloDolly

DATA time TYPE t VALUE '154633'.

WRITE: time,

/(8) time USING EDIT MASK '__:__:__'.

154633

15:46:33

WRITE: '000123',

/ '000123' NO-ZERO.

000123

123

DATA float TYPE f VALUE '123456789.0'.

WRITE float EXPONENT 3.

123456,789E+03

DATA pack TYPE p VALUE '123.456'

DECIMALS 3.

WRITE pack DECIMALS 2.

WRITE: / pack ROUND -2,

/ pack ROUND -1,

/ pack ROUND 1,

/ pack ROUND 2.

123,46

12.345,600

1.234,560

12,346

1,235

WRITE: sy-datum,

/ sy-datum yymmdd.

27.06.1995

950627

Apart from the formatting options shown in the above tables, you can also use the formatting options of the FORMAT statement. These options allow you to specify the intensity and color of your output. For more information, see The FORMAT Statement.