After creating an oData service (with trx SEGW) for notifications my collegae (functional consultant) asked me if the time could also be filled in the output of the service. The service already showed the date and time but the time was always shown as 00:00:00, i thought that this would not be that hard….
After searching the net and trying several possible solutions for a day i got it to work. Because i could’nt find it all in one place i will make an effort to bring this together (also being my first blog).
How did i create my initial oData service?
At first i created a view that i imported as a structure in SEGW. Very soon i discoverd that this is not the way to go because now the oData service is very tight coupled to the fields of the database view. So i created a structure with the desired fields, containing some date fields (type dats).
After generating the runtime objects and implementing the …_get_entityset method of the Data Provider Secondary Class the oData service worked fine, except for the fact that the time fields were always shown as 00:00:00 in the oData service (for the obvious reason that the dats fields were mapped to these ….datum fields).
Result at this time was:
Definition in SEGW at this time was:
Abap type editor for field Storingsdatum:
How did i change my oData service?
After some searching i discoverd that i should change the data type in the abap type editor but this was not possible, reason for this was the fact that i imported the fields from an abap structure. After removing the abap structure type name (zspm_wpb_meldingen) in the entity type i was possible to get the abap type editor in change mode.
Now change the mode to ‘Explicit Assignment’, the category to ‘D Data element’ and the associated type to Timestamp. To get it to work i also changed the Edm core type to Edm.DateTimeOffset (the Edm.DateTime just wouldn’t work).
After this the code in the method …get_entityset must be changed beacuse the field Storingsdatumtijd is now of type timestamp. In the abap code the timestamp must be filled with the date and time (i’m using the fm ‘ABI_TIMESTAMP_CONVERT_INTO’ for this ).
After these changes (and clearing buffers and/or (de)activating service) i got the time in the storingsdatum field:
… after writing this blog i’m wondering if it all would have worked from the start if i had added the timestamp field in the structure that i imported … to be continued.