Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  Character String and Byte String Processing →  Statements for Character String and Byte String Processing →  WRITE - TO →  WRITE - Cutoff Behavior 

WRITE, Cutoff Behavior

This example demonstrates the cutoff behavior of the statement WRITE for all elementary data types.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA: dref TYPE REF TO data,
          len TYPE i,
          name TYPE string.

    FIELD-SYMBOLS <output> TYPE data.

    len = length.
    IF len < 1 OR len > 40.
      WRITE 'Length must be between 1 and 40!' COLOR COL_TOTAL.

    setup( ).
    create_data( ).

    ASSIGN dref->* TO <output>.
    LOOP AT names INTO name.
          CASE name.
            WHEN 't'.
              WRITE t TO <output> ENVIRONMENT TIME FORMAT.
            WHEN 'TIMESTAMP'.
              WRITE timestamp TO <output> TIME ZONE sy-zonlo.
            WHEN 'TIMESTAMPL'.
              WRITE timestampl TO <output> TIME ZONE sy-zonlo.
            WHEN OTHERS.
              WRITE (name) TO <output>.
          display( name   = name len = len
                   output = <output> ).
        CATCH cx_root.
          display( name = name
                   len  = len output = '!' ).

    teardown( ).


The class demo contains an attribute for every predefined ABAP type and for time stamps. These attributes are filled with example values and assigned to a data object by WRITE TO. The length of this data object can be chosen on the selection screen.

The country-specific formats for numbers, dates, and times set by SET COUNTRY can also be specified on the selection screen. This example demonstrates these formats as well.

The output list shows the result of the formatting for each data type. If an exception is raised, the character "!" is highlighted in a different color.