cloud-sdk-java icon indicating copy to clipboard operation
cloud-sdk-java copied to clipboard

Unable to reproduce API call from SDK documentation

Open StefanieSchulk opened this issue 8 months ago • 3 comments

Describe the Bug

For the API Trial Balance - Read (OData V2) for S/4Hana Public Cloud, I am unable to reproduce the call[ https://myXXXXXX-api.s4hana.cloud.sap/sap/opu/odata/sap/C_TRIALBALANCE_CDS/C_TRIALBALANCE(P_FromPostingDate=datetime'2025-01-01T00:00:00',P_ToPostingDate=datetime'2025-01-31T23:59:59')/Results from the SDK documentation. In the SDK documentation there is no documentation on how to set C_TrialBalanceParameters, which are necessary to make the call work and get the results.

We can create classes based on the XML, and we are using:

com.sap.cloud.sdk.datamodel odata-core

We are getting: @Nonnull TrialBalanceFluentHelper getAllTrialBalance();

What we expected: @Nonnull TrialBalanceByKeyFluentHelper getTrialBalanceByKey(final LocalDateTime postingDateFrom, final LocalDateTime postingDateTo);

Without the parameters, the API call will not work so to have them included in the sdk datamodel is necessary. Do you perhaps have any JAVA or KOTLIN example with this call using the key properties and the navigation target?

Steps to Reproduce

  1. Try to set up and connect to the API Trial Balance - Read (OData V2) from S/4Hana Cloud
  2. The API is in need of parameters in the call because otherwise the API response is not returned / does not contain the right data.
  3. We create classes based on the XML
  4. We are getting: @Nonnull TrialBalanceFluentHelper getAllTrialBalance();

Full technical description can be found in the attached word

Trial Balance.docx

Expected Behavior

We would expect to have something similar to this:

@Nonnull TrialBalanceByKeyFluentHelper getTrialBalanceByKey(final LocalDateTime postingDateFrom, final LocalDateTime postingDateTo);

Screenshots

No response

Used Versions

  • Java and Maven version via `mvn archetype:generate "-DarchetypeGroupId=com.sap.cloud.sdk.archetypes" "-DarchetypeArtifactId=scp-cf-spring" "-DarchetypeVersion=RELEASE"
  • SAP Cloud SDK version: 5.6.0
  • Spring Boot or CAP version: ...
  • com.sap.cloud.sdk.datamodel odata-core

Code Examples

// Your code here

Stack Trace

No response

Log File

Log file ...

Affected Development Phase

Production

Impact

Blocked

Timeline

No response

StefanieSchulk avatar May 16 '25 05:05 StefanieSchulk

Assuming this is the OData service, you communicating with, I think that'll work for you:

@Nonnull
TRIALBALANCEParametersByKeyFluentHelper
  getTRIALBALANCEParametersByKey( final LocalDateTime p_FromPostingDate, final LocalDateTime p_ToPostingDate );

If you have questions regarding OData API usage, please find our documentation first: https://sap.github.io/cloud-sdk/docs/java/features/odata/v2-vdm-client#select

If the generated code or the available API does not offer correct feature scope for you, please also see the "Generic OData Client" - it allows for almost full customization of your request: https://sap.github.io/cloud-sdk/docs/java/features/odata/generic-untyped-odata-client

newtork avatar May 16 '25 07:05 newtork

We tried that endpoint already using the following code balanceClient.getTRIALBALANCEParametersByKey(LocalDate.of(2025, 1, 1).atStartOfDay(), LocalDate.of(2025, 12, 31).atStartOfDay()) .select(TRIALBALANCEParameters.TO_RESULTS) .execute() But SAP is returning Entity set C_TRIALBALANCEParameters is not supported...

.toRequest() shows these information (see attachment)

Image

StefanieSchulk avatar May 16 '25 09:05 StefanieSchulk

.select(TRIALBALANCEParameters.TO_RESULTS)

... does not mean /Results is appended to request URL, but ?$select=Results/*&$expand=Results is added as query parameter.

While the OData service may not support the Entity lookup "C_TRIALBALANCEParameters" of endpoint /C_TRIALBALANCE - for whatever questionable reason; according to spec it does support the direct Entity field lookup for /Results. The API necessary for that request is not supported directly on this convenience layer of Cloud SDK.

You can however use the Generic OData client: https://sap.github.io/cloud-sdk/docs/java/features/odata/generic-untyped-odata-client

ODataResourcePath resource = ODataResourcePath
  .of("C_TRIALBALANCE", new ODataEntityKey(ODataProtocol.V2)
    .addKeyProperty("P_FromPostingDate", LocalDate.of(2025, 1, 1).atStartOfDay()))
    .addKeyProperty("P_ToPostingDate", LocalDate.of(2025, 12, 31).atStartOfDay()))
    .addSegment("Results");

Destination destination;
HttpClient httpClient = HttpClientAccessor.getHttpClient(destination);

String serviceUrl = CTRIALBALANCECDSService.DEFAULT_SERVICE_PATH;
String encodedQuery = "";

ODataRequestRead request = new ODataRequestRead(serviceUrl, resource, encodedQuery, ODataProtocol.V2);
ODataRequestResultGeneric response = request.execute(httpClient);
List<TRIALBALANCEResult> results = response.asList(TRIALBALANCEResult.class);

This should result in your expected request to

/sap/opu/odata/sap/C_TRIALBALANCE_CDS/C_TRIALBALANCE(P_FromPostingDate=datetime'2025-01-01T00:00:00',P_ToPostingDate=datetime'2025-01-31T23:59:59')/Results

newtork avatar May 16 '25 12:05 newtork

Closed due to inactivity.

newtork avatar Jun 04 '25 13:06 newtork