Search code examples
s4sdk

How to get the text of localized fields in VDM?


I'm trying to get business partner data from our S/4HANA Cloud (Public Cloud) by using VDM.

        final List<BusinessPartner> businessPartners =
                new DefaultBusinessPartnerService()
                        .getAllBusinessPartner()
                        .select(BusinessPartner.BUSINESS_PARTNER,
                                BusinessPartner.BUSINESS_PARTNER_NAME)
                        .filter(BusinessPartner.BUSINESS_PARTNER_CATEGORY.eq("2"))
                        .orderBy(BusinessPartner.BUSINESS_PARTNER, Order.ASC)
                        .execute();

The English business partner name is displayed correctly. But the Japanese business partner name is displayed as ?????.

{"BusinessPartner":"80000001","BusinessPartnerName":"Domestic US Customer 1"},
{"BusinessPartner":"80000002","BusinessPartnerName":"?????????????"},
{"BusinessPartner":"90000001","BusinessPartnerName":"Domestic US Supplier 1"},
{"BusinessPartner":"90000002","BusinessPartnerName":"????????"}

Could you give me advice how to get the text of localized fields?

Thanks.

(Additional notes)

I executed OData manually with Postman. In this case localized fields was displayed in Japanese.

https://myXXXXXX.s4hana.ondemand.com/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner?$select=BusinessPartner,BusinessPartnerName&$orderby=BusinessPartner&$filter=BusinessPartnerCategory%20eq%20'2'&$format=json&saml2=disabled

output

{
    "d": {
        "results": [
            {
                "__metadata": {
                    "id": "https://myXXXXXX.s4hana.ondemand.com:443/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner('80000001')",
                    "uri": "https://myXXXXXX.s4hana.ondemand.com:443/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner('80000001')",
                    "type": "API_BUSINESS_PARTNER.A_BusinessPartnerType"
                },
                "BusinessPartner": "80000001",
                "BusinessPartnerName": "Domestic US Customer 1"
            },
            {
                "__metadata": {
                    "id": "https://myXXXXXX.s4hana.ondemand.com:443/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner('80000002')",
                    "uri": "https://myXXXXXX.s4hana.ondemand.com:443/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner('80000002')",
                    "type": "API_BUSINESS_PARTNER.A_BusinessPartnerType"
                },
                "BusinessPartner": "80000002",
                "BusinessPartnerName": "東京得意先株式会社"
            },
            {
                "__metadata": {
                    "id": "https://myXXXXXX.s4hana.ondemand.com:443/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner('90000001')",
                    "uri": "https://myXXXXXX.s4hana.ondemand.com:443/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner('90000001')",
                    "type": "API_BUSINESS_PARTNER.A_BusinessPartnerType"
                },
                "BusinessPartner": "90000001",
                "BusinessPartnerName": "Domestic US Supplier 1"
            },
            {
                "__metadata": {
                    "id": "https://myXXXXXX.s4hana.ondemand.com:443/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner('90000002')",
                    "uri": "https://myXXXXXX.s4hana.ondemand.com:443/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner('90000002')",
                    "type": "API_BUSINESS_PARTNER.A_BusinessPartnerType"
                },
                "BusinessPartner": "90000002",
                "BusinessPartnerName": "東京仕入先株式会社"
            }
        ]
    }
}

Solution

  • If you're using a HttpServlet, then make sure to set the character encoding of the HttpServletResponse object to UTF-8 and the content type to application/json before writing the response.

    response.setContentType("application/json");
    response.setCharacterEncoding("UTF-8");