Search code examples
s4sdk

Does S/4HANA Cloud SDK support obtaining metadata instead of the actual entities for OData?


I am trying to obtain the metadata to an OData service endpoint. I am not interested in the entities themselves, but the metadata tethering to this particular entity.

I saw there is a useMetadata(Boolean boolean) method, but it is set to true by default and it doesn't seem to do anything.

Does the cloud connectivity sdk support this feature?

The library I am currently using is com.sap.cloud.sdk.odatav2.connectivity.ODataQueryBuilder.

EDIT:
The use case is that my team is currently developing an app to examine and automate the data migration process from a provider to S/4HANA. The app will prompt the user to make remedying fixes if the configuration it obtains from the metadata shows discrepancies from our best practice and in turn, will probably cause trouble in the data replication process. This said configuration is exposed through metadata instead of the entities from the OData API.

For instance: If a customer would like to migrate the FOCustomer records to S/4HANA, he or she may want to set the MaxLength of the FormalName property to 12, or the data integrity might be compromised in the destination system. We are not interested in the customer entries, or what is actually in FormalName, but the configuration the customer set in the source system, which is exposed in the OData API as a metadata document entry like:

<Property Name="name_defaultValue" Type="Edm.String" Nullable="true" sap:required="false" sap:creatable="true" sap:updatable="true" sap:upsertable="true" sap:visible="true" sap:sortable="true" sap:filterable="true" MaxLength="32" sap:label="Name"></Property>

In this case, MaxLength is set as 32 instead of 12 which would be logged and referred to the customer for further action.

We used Olingo for this purpose before. Now we are evaluating S/4SDK since it seemingly provides a more streamlined solution.


Solution

  • the ODataQueryBuilder itself does not support standalone metadata retrieval. The metadata is only used under the hood, therefore useMetadata() does not help you for your use case.

    However, given that you have setup the destination from which you want to retrieve the metadata, you could do the following (my destination is named ErpQueryEndpoint in this example):

    final String destinationUriString = DestinationAccessor.getDestination("ErpQueryEndpoint").getUri().toString();
    final HttpClient httpClient = HttpClientAccessor.getHttpClient("ErpQueryEndpoint");
    final URI uri = new URI(destinationUriString + "/sap/opu/odata/sap/NAME_OF_THE_API/$metadata");
    final HttpResponse httpResponse = httpClient.execute(new HttpGet(uri));
    

    This should allow you to retrieve the metadata in XML format. You'd still need to parse it using Olingo, though.

    Currently we do not plan to support standalone metadata retrieval. However, if you want, you can open an issue on our public GitHub page so we may consider this in the future.

    Let me know if this answers your questions or if you have further questions!