Skip to Content
Author's profile photo Jakob Marius Kjær

Handling date and time in POST requests in Odata

Hi all,

Just thought I would share my recent thoughts and findings on a well debated area of Odata Development in ABAP.

There are numerous blogs about the edm.dateTime object, but not really many solutions on how to ACTUALLY handle it. So I thought I would share my easy way with you all.

First rule of odata dateTime club, do NOT just use string for convenience. I know it can be a pain, but it leads to bad design. Secondly don’t just use a date AND a time property, you can actually quite easily handle this properly.

Instead assign your edm.dateTime or edm.dateTimeOffset to your property. If you haven’t assigned a structure to your entity, the gateway builder will automatically propose the timestamp type.

I’ve had so much trouble with this and can’t really get it through all the automatic mapping in the gateway.

However if you change your type to timestampl like below.


This will allow your odata calls to pass through all the automatic mapping without worry.

Now in your update, create etc method you can get the values you need from this with a simple code:

  data: lv_local_date type sy-datum,
        lv_local_time type sy-uzeit.

CONVERT TIME STAMP <property-with-timestampl> TIME ZONE sy-zonlo
          INTO DATE lv_local_date TIME lv_local_time.

With the above you will get the date and time in the servers timezone, since a odata call is always transferred to UTC.

Thats pretty much it. Easy peasy.



Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Kjetil Kilhavn
      Kjetil Kilhavn

      Easy peasy, but not correct...
      The system variable SY-ZONLO is the user's time zone, so this will give an incorrect value if the user master data has been changed to specify a different time zone.

      The SYST structure does not contain the system time zone, but you can use function module GET_SYSTEM_TIMEZONE to get it.