cancel
Showing results for 
Search instead for 
Did you mean: 

RAP OData v4 Web-API metadata set nullable option

jrtr
Explorer
0 Kudos
314

I implemented an OData v4 Web-API and realized that the metadata document contains nullable="false" for almost every property (all but Edm.Date typed properties) of my entities. As far as I recall the metadata document of the RAP implementation (UI service) of the S4D437 course didn't contain that much nullables. I searched for an answer and found Andre Fischers post in this thread that says that you can't set it directly but influence it by the implementation.

Sadly there is nothing mentioned "how" you influence it. What do I have to do to make properties nullable?

View Entire Topic
TuncayKaraca
Active Contributor

Hi @jrtr,

It seems @Semantics.nullValueIndicatorFor can be used. Check out similar question Set Nullable Property on SAP RAP based OData V4 and @tudor_teoteoi's response. 

@Semantics.nullValueIndicatorFor: "OriginalField"
cast ('X' as boole_d) as NullValIndicator

Thought it must be applicable only in "Only available with the latest SAP BTP or SAP S/4HANA Cloud, public edition release and for SAP S/4HANA, on-premise edition or SAP S/4HANA Cloud, private edition, from release 2023 onwards." Check out here.

Thanks,
Tuncay

jrtr
Explorer
Thank you TuncayKaraca, I knew it works in cloud environment, should have tested in our on-premise system...
TuncayKaraca
Active Contributor
0 Kudos
You are welcome, @jrtr It's good to see all good!
jrtr
Explorer
0 Kudos
@TuncayKaraca This works for standard CDS entities. Regarding custom CDS entities I figured out that the annotation and the definition of a NullValueIndicator field of type boole_d is sufficient to remove nullable="false" there. For abstract entities this does not seem to hold true, do you know how i can suppress nullable="false" there?
jrtr
Explorer
0 Kudos
I stumbled across the problem, that the metadata document is correct, but casting X (true) to the NullValueIndicator infuences the response as the property is set to null. Casting a blank (false) yields the correct entry in the metadata document (nullable="false" is gone) and the correct value for the property.