Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
shilpabasavaraj
Participant
Introduction:

Normally when there is a field (for e.g. DateChanged) of type DateTime in the OData entity, we might face few issue in the front-end

  1. if this field has a null value entry, at this point of time the frontend UI application will throw a run-time error. Here in this blog post we are going to see how to handle this issue of DateTime field in the back-end, so that we don’t face any issue while loading the UI application.

  2. Also there there might be a situation when we tend to show only the Date value in the UI for a field removing the Time from it.


 

  • Steps to take care when the DateTime field value can be null/empty


Step 1: If the properties of an entity in the OData is editable, then make sure to check the checkbox for the option “Nullable”



Step 2:  If the properties of an entity are non-editable, for e.g., when the OData is created through the CDS view). Here the property can be handled by redefining the DEFINE method of MPC_EXT  class of the OData



 

  • How to display a DateTime field in Date format in the UI application.


Simple step here is to redefine the DEFINE method of MPC_EXT class of the OData and add the below code, so that the display format in the UI is ‘Date’



 

Conclusion:

Now you will be able to display the date field of an entity in OData in Date format instead of DateTime format in the UI. And also you will be able to overcome the run-time error which was caused because of DateTime field
4 Comments