OData导入SAP ABAP:时间戳转换逻辑不解及目标值实现求助
Converting OData Epoch Timestamps to ABAP Long Format
Let’s break down why your OData timestamp 1449479875000 translates to the ABAP value you see.
That OData number represents the total milliseconds since the Unix epoch (January 1, 1970, 00:00:00 UTC). Here’s how to map it to ABAP’s long timestamp format (YYYYMMDDhhmmss.mmmuuun):
- Convert milliseconds to seconds: Divide by 1000 →
1449479875seconds. - Map to UTC datetime: This equals
2015-12-07 09:17:55.000 UTC. - Format to ABAP’s raw timestamp:
- Date part:
20151207(year 2015, month 12, day 07) - Time part:
091755(hour 09, minute 17, second 55) - Milliseconds:
000(from the OData value’s trailing zeros) - Microseconds:
000000(default if not specified) - Raw ABAP timestamp:
20151207091755.0000000
- Date part:
The displayed value 20.151.207.091.755,0000000 is just your ABAP system’s formatting mask (splitting digits with dots) — the underlying raw timestamp matches the conversion above.
Uploading a Specific ABAP Timestamp via OData
To upload a timestamp like 20.181.207.091.755,0000000, follow these steps:
Step 1: Decode the Displayed Timestamp to Raw Format
First, translate the human-readable display back to ABAP’s raw long timestamp. For your example:
20.181.207.091.755,0000000maps to the raw value20181207091755.7550000(assuming the display uses a mask likeYYYY.MMDD.hhmm.ss,uuuuuu).
Step 2: Convert Raw Timestamp to OData Epoch Milliseconds
Next, convert this raw UTC timestamp to milliseconds since the Unix epoch:
- The raw timestamp
20181207091755.7550000corresponds to2018-12-07 09:17:55.755 UTC. - The epoch milliseconds for this datetime is
1544164675755.
Step 3: Build the OData Payload
Use the /Date(...)/ format in your JSON payload:
{ "Id" : "", "Timestamp" : "/Date(1544164675755)/", "UserName" : "USER", "SourceSystemId" : "ANY" }
Quick Programming Tips
- ABAP to OData: Use the function module
CONVERT_TIMESTAMP_TO_UNIXto get Unix seconds, multiply by 1000, and add the milliseconds component to get the epoch value for OData. - OData to ABAP: ABAP’s OData service should automatically parse the
/Date(...)/format into the long timestamp type if the entity property is correctly defined as a UTC timestamp. - Always stick to UTC timestamps to avoid timezone mismatches between your source system and SAP.
内容的提问来源于stack exchange,提问作者C. Ubkcah

