SAP-archive / cloud-s4-sdk-examples

Runnable example applications that showcase the usage of the SAP Cloud SDK.
Apache License 2.0
66 stars 35 forks source link

Cast error on Change Master #69

Closed tiagoquaini closed 5 years ago

tiagoquaini commented 5 years ago

Hello colleagues,

I am working with the Change Master API and we are having some issues regarding class cast exceptions. The exception stack trace is below:

java.lang.ClassCastException: java.util.GregorianCalendar cannot be cast to java.lang.Double at com.sap.cloud.sdk.s4hana.datamodel.odata.namespaces.changemaster.ChangeMaster.fromMap(ChangeMaster.java:1073) at com.sap.cloud.sdk.s4hana.datamodel.odata.helper.FluentHelperCreate.buildEntityFromODataResult(FluentHelperCreate.java:177) at com.sap.cloud.sdk.s4hana.datamodel.odata.helper.FluentHelperCreate.execute(FluentHelperCreate.java:165) at com.sap.cloudscame.bmsmoc.s4.command.CreateChangeMasterV2Command.run(CreateChangeMasterV2Command.java:35)

This happens whenever a GET is executing and all properties of the change master are selected. Also, when we create a new change master, the same error occurs.

We are using scp-neo SDK in version 2.14.0.

Could you please assist us on this issue?

Thanks, Tiago

sawoz commented 5 years ago

Hi, can you share the metadata xml file? Thanks!

tiagoquaini commented 5 years ago

Hi,

We are using the default change master service. I believe the metadata is the same as the one available on the API Business Hub: https://api.sap.com/api/API_CHANGEMASTER/overview

Thanks, Tiago

cschubertcs commented 5 years ago

Can you provide us the response from your system for the following request (of course with any sensitive data removed!):

<host>/sap/opu/odata/sap/API_CHANGEMASTER;v=0002/A_ChangeMaster$top=1.

Especially relevant would be the format of the content of the ChangeNumberLastChgdDateTime field, as it seems that your system returns a Calendar while our VDM expects a Double value.

tiagoquaini commented 5 years ago

Please see below the response from the request. Indeed the ChangeNumberLastChgdDateTime is comming up as a date time rather than a double.

Is there any action or workaround that our team can use to overcome this?

Thanks!

{
    "__metadata": {
        "id": "<host>/sap/opu/odata/sap/API_CHANGEMASTER;v=0002/A_ChangeMaster('555555')",
        "uri": "<host>/sap/opu/odata/sap/API_CHANGEMASTER;v=0002/A_ChangeMaster('555555')",
        "type": "API_CHANGEMASTER.A_ChangeMasterType",
        "etag": "W/\"datetimeoffset'1972-04-01T00%3A00%3A00.0000000Z'\""
    },
    "ChangeNumber": "555555",
    "ChangeNumberStatus": "1",
    "AuthorizationGroup": "",
    "ChangeNumberFunction": "",
    "IsTechnicallyReleased": "",
    "ChangeNumberReleaseKey": "0",
    "ReasonForChangeText": "",
    "ChangeNumberDescription": "MOC APPLICATION TEST",
    "ChangeNumberValidFromDate": "\/Date(1555977600000)\/",
    "ChangeNumberCreationDate": "\/Date(1555977600000)\/",
    "ChangeNumberCreatedByUser": "SCP_RFC",
    "ChangeNumberLastChangedDate": null,
    "ChangeNumberLastChangedByUser": "",
    "IsUsedForDataDefinition": false,
    "ChangeNumberIsMrkdForDeletion": false,
    "ChangeNumberLastChgdDateTime": "\/Date(70934400000+0000)\/",
    "to_AlternativeDate": {
        "__deferred": {
            "uri": "<host>/sap/opu/odata/sap/API_CHANGEMASTER;v=0002/A_ChangeMaster('555555')/to_AlternativeDate"
        }
    },
    "to_ChangeMstrObjectMgmtRecord": {
        "__deferred": {
            "uri": "<host>/sap/opu/odata/sap/API_CHANGEMASTER;v=0002/A_ChangeMaster('555555')/to_ChangeMstrObjectMgmtRecord"
        }
    },
    "to_ChangeMstrObMgReDocInfoRecd": {
        "__deferred": {
            "uri": "<host>/sap/opu/odata/sap/API_CHANGEMASTER;v=0002/A_ChangeMaster('555555')/to_ChangeMstrObMgReDocInfoRecd"
        }
    },
    "to_ChangeMstrObMgReMaterial": {
        "__deferred": {
            "uri": "<host>/sap/opu/odata/sap/API_CHANGEMASTER;v=0002/A_ChangeMaster('555555')/to_ChangeMstrObMgReMaterial"
        }
    },
    "to_ChangeMstrObMgReMatlBOM": {
        "__deferred": {
            "uri": "<host>/sap/opu/odata/sap/API_CHANGEMASTER;v=0002/A_ChangeMaster('555555')/to_ChangeMstrObMgReMatlBOM"
        }
    },
    "to_Characteristics": {
        "__deferred": {
            "uri": "<host>/sap/opu/odata/sap/API_CHANGEMASTER;v=0002/A_ChangeMaster('555555')/to_Characteristics"
        }
    },
    "to_Classification": {
        "__deferred": {
            "uri": "<host>/sap/opu/odata/sap/API_CHANGEMASTER;v=0002/A_ChangeMaster('555555')/to_Classification"
        }
    },
    "to_ObjTypeAssignment": {
        "__deferred": {
            "uri": "<host>/sap/opu/odata/sap/API_CHANGEMASTER;v=0002/A_ChangeMaster('555555')/to_ObjTypeAssignment"
        }
    }
}
cschubertcs commented 5 years ago

Okay, just to verify where this behavior comes from: Can you tell me what the Type property in the ChangeNumberLastChgdDateTime field of the metadata of your specific system file specifies? You can get this via

<host>/sap/opu/odata/sap/API_CHANGEMASTER;v=0002/$metadata
tiagoquaini commented 5 years ago

The type is Edm.DateTimeOffset:

<Property sap:label="Time Stamp" Name="ChangeNumberLastChgdDateTime" Type="Edm.DateTimeOffset" sap:quickinfo="UTC Time Stamp in Long Form (YYYYMMDDhhmmssmmmuuun)" Precision="7" ConcurrencyMode="Fixed" />

cschubertcs commented 5 years ago

Okay, as a workaround this blog post will help you generate your own VDM based on the $metadata you retrieved from your system (which apparently is not the same as published on the API Business Hub).

To understand the actual problem a bit further: What kind if System do you call? Cloud or On-Premise? And which version?

tiagoquaini commented 5 years ago

Thanks Christoph! Our S4 is On-Premise and is on 1809 FPS1 version.

cschubertcs commented 5 years ago

Okay, I will try to dig deeper into this issue and will come back to you once I have more information.

In the meantime I hope you can continue working with the workaround mentioned above!

tiagoquaini commented 5 years ago

Yes, the workaround enabled us to continue our development. Thanks!

sacnl commented 5 years ago

This has been fixed with the latest release of S/4HANA Cloud