Datumsberechnung (ABAP)

Aus MattWiki

Rechnen mit Datumswerten

  "convert current system time to utc --> rspclogchain date and time is utc
  CALL METHOD cl_abap_tstmp=>systemtstmp_syst2utc
    EXPORTING
      syst_date = sy-datum
          "syst_time = sy-uzeit
      syst_time = '000000'
    IMPORTING
      utc_tstmp = l_timestamp_current.
      
      

  "subtract timestamps
  CALL FUNCTION 'RSSM_SUBSTRACT_TIMESTAMPS'
    EXPORTING
      timestamp1 = l_timestamp_current
      timestamp2 = l_timestamp_subtract
    IMPORTING
*     TIME       =
*     SECS       =
*     DAYS       =
*     MILISECS   =
*     DIFF       =
      timestamp  = l_timestamp.

Zeitzonen konvertieren

* Convert timestamp into date and time for look up in table
lv_timezone = 'UTC'.
CONVERT TIME STAMP l_timestamp
  TIME ZONE lv_timezone
  INTO DATE l_sydatum TIME l_syuzeit.

Umrechnung Datum / Zeit UTC in lokale Zeitzone und wieder zurück (Funktionert für Datums- und Zeitfelder sowie für Timestamps):

Funktionsgruppe RS_GENERAL Allgemeine Hilfsfunktionen

Funktion: RSSM_GET_TIME Zeit holen

CALL FUNCTION 'RSSM_GET_TIME'
* EXPORTING
*   I_TIMESTAMPL           =
*   I_TIMESTAMPS           =
*   I_DATUM_UTC            =
*   I_UZEIT_UTC            =
*   I_DATUM_LOC            =
*   I_UZEIT_LOC            =
*   I_DATUM_SYS            =
*   I_UZEIT_SYS            =
*   I_USE_ENQ_SERVER       = ' '
* IMPORTING
*   E_DATUM_LOC            =
*   E_UZEIT_LOC            =
*   E_TIMESTAMPS           =
*   E_TIMESTAMPL           =
*   E_DATUM_UTC            =
*   E_UZEIT_UTC            =
*   E_DATUM_SYS            =
*   E_UZEIT_SYS            =
* EXCEPTIONS
*   FAILED                 = 1
*   OTHERS                 = 2
          .

Beispielprogramm

/***/*BW_PKHW_LOAD_CHAIN_STAT