Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Date and Time Processing →  Time Stamps →  Time Stamp Field with Time Stamp Type →  System Class for Time Stamp Fields 

Read Time Stamp from String

This example demonstrates the method READ of the system class CL_ABAP_UTCLONG.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA(utc) = utclong_current( ).

    DO.
      p_utc  = |{ utc  TIMESTAMP = ENVIRONMENT TIMEZONE = sy-zonlo }|.
      CALL SELECTION-SCREEN 100 STARTING AT 10 10.
      IF sy-subrc <> 0.
        EXIT.
      ENDIF.
      setup( ).
      TRY.
          DATA(utc_save) = utc.
          cl_abap_utclong=>read( EXPORTING string   = p_utc
                                          timezone = sy-zonlo
                                IMPORTING value    = utc ).
        CATCH cx_abap_utclong_invalid INTO DATA(exc).
          MESSAGE exc->get_text( ) TYPE 'I' DISPLAY LIKE 'E'.
          utc = utc_save.
      ENDTRY.
    ENDDO.

    teardown( ).

Description

A selection screen displays a time stamp in a string whose content can be modified in any way. Both a date format and a time format can be selected.

When Execute is chosen, the method READ of the system class CL_ABAP_UTCLONG is used to read the string as a time stamp. If the read action raises an exception, this is displayed in a message.