cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to perform CRUD operation on onpremise using S/4 Hana Cloud SDK

meenakshi_a_n_
Explorer
0 Kudos

Hi everyone,

Currently we are working on CRUD operation on onpremise by using white listed API(API_PRODUCT_SRV).

  • We were successfully able to do read operation. But while doing update operation service.updateProduct(toUpdate).execute() method is returning null object.
  • In toupdate we are able to fetch the updated data.And while executing it in the postman we are getting 204 status with no content.
  • We also tried both in neo and cloud foundary environment.We were not able to perform update. Any suggestions/blogs/information are much appreciated.
  • Below is the sample code for update operation using cloud sdk classes and methods.

@Override protected Integer run() throws Exception

{

final ODataUpdateResult oDataUpdateResult=service.updateProduct(toUpdate).execute();

return oDataUpdateResult.getHttpStatusCode());

}

Thanks and Regards,

Meenakshi A N

Accepted Solutions (0)

Answers (7)

Answers (7)

former_member186608
Active Participant
0 Kudos

Are you sure that you searched in the whole project and not only in one of the POM files?

Apart from that, kindly increase the version of this dependency to the latest one:

<parent>  
<groupId>com.sap.cloud.servicesdk.prov</groupId>
<artifactId>projects-parent-odatav2</artifactId>
<version>1.17.1</version>
</parent>

Check it out on Maven Central:

https://mvnrepository.com/artifact/com.sap.cloud.servicesdk.prov/projects-parent-odatav2

former_member186608
Active Participant
0 Kudos

Referring to your statement that you do not have the S/4HANA Cloud SDK dependency in your project:

Kindly search for the string

<groupId>com.sap.cloud.s4hana</groupId>

in your source code. Can you find it?

meenakshi_a_n_
Explorer
0 Kudos
  • No I cannot find this line.I haven't used this dependency.But I am able to use com.sap.cloud.sdk.s4hana.datamodel.odata.namespaces.productmaster.* in java code without any errors.
package my.company;
import com.sap.cloud.sdk.s4hana.datamodel.odata.namespaces.productmaster.*;
import com.sap.cloud.sdk.s4hana.datamodel.odata.services.DefaultProductMasterService;
import com.sap.cloud.sdk.service.prov.api.operations.Read;
import com.sap.cloud.sdk.service.prov.api.operations.Create;
//import com.sap.cloud.sdk.service.prov.api.operations.Delete;
import com.sap.cloud.sdk.service.prov.api.operations.Query;
import com.sap.cloud.sdk.service.prov.api.operations.Update;
import com.sap.cloud.sdk.service.prov.api.response.QueryResponse;
import com.sap.cloud.sdk.service.prov.api.response.ReadResponse;
import com.sap.cloud.sdk.service.prov.api.response.CreateResponse;
//import com.sap.cloud.sdk.service.prov.api.response.DeleteResponse;
import com.sap.cloud.sdk.service.prov.api.response.UpdateResponse;
//import com.sap.cloud.sdk.service.prov.api.response.DeleteResponse;
import com.sap.cloud.sdk.service.prov.api.request.*;
import com.sap.cloud.sdk.odatav2.connectivity.ODataException;
import java.util.*;
import org.modelmapper.ModelMapper;
public class Service {
	@Query(serviceName = "ProductService", entity = "Products")
	public QueryResponse queryPersons(QueryRequest req) throws ODataException {
System.out.println("Inside @query");
		List<Product> result = new GetAllProductsCommand(new DefaultProductMasterService()).execute();
//	System.out.println(result);
		return QueryResponse.setSuccess().setData(result).response();
	}
	@Read(serviceName = "ProductService", entity = "Products")
	public ReadResponse readPerson(ReadRequest req) throws ODataException {
		String key = String.valueOf(req.getKeys().get("Product"));
		Product result = new GetProductByKeyCommand(new DefaultProductMasterService(), key).execute();
		return ReadResponse.setSuccess().setData(result).response();
	}
	@Update(serviceName = "ProductService", entity = "Products")
	public UpdateResponse updatePerson(UpdateRequest req) throws ODataException {
		Product toUpdate = new ModelMapper().map(req.getMapData(), Product.class);
		System.out.println(req.getMapData());
		System.out.println(toUpdate);
		String key = String.valueOf(req.getKeys().get("Product"));
		toUpdate.setProduct(key);
		System.out.println(toUpdate);
	int s=new UpdateProductCommand(new DefaultProductMasterService(), toUpdate).execute();
	System.out.println(s);
		return UpdateResponse.setSuccess().response();
	}	
}
meenakshi_a_n_
Explorer
0 Kudos

Hi Dennis/Marco,

I am using 1.17.1 version of s/4 hana cloud sdk.Please guide me with further actions to make crud operation work currently in onpremise.

Thanks and Regards,

Meenakshi.

meenakshi_a_n_
Explorer
0 Kudos

Hi Dennis/Marco,

Correction in the version which I am using for s/4 hana cloud sdk.I have not included any dependency for s/4 hana cloud sdk.Here is my pom.xml file.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">;
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.sap.cloud.servicesdk.prov</groupId>
    <artifactId>projects-parent-odatav2</artifactId>
    <version>1.17.1</version>
  </parent>
  <artifactId>SideBySide_ProductMaster-srv</artifactId>
  <groupId>sap</groupId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>
  <name>SideBySide_ProductMaster-srv</name>
  <properties>
    <packageName>my.company</packageName>
  </properties>
  <dependencies>
  <!-- https://mvnrepository.com/artifact/org.modelmapper/modelmapper -->
<dependency>
   <groupId>org.modelmapper</groupId>
   <artifactId>modelmapper</artifactId>
   <version>2.1.1</version>
</dependency>
  </dependencies>
  <build>
    <finalName>${project.artifactId}-${project.version}</finalName>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.6.0</version>
        <configuration>
          <executable>npm</executable>
          <workingDirectory>${project.basedir}/../</workingDirectory>
        </configuration>
        <executions>
          <execution>
            <id>npm install</id>
            <goals>
              <goal>exec</goal>
            </goals>
            <phase>generate-sources</phase>
            <configuration>
              <arguments>
                <argument>install</argument>
              </arguments>
            </configuration>
          </execution>
          <execution>
            <id>npm run build</id>
            <goals>
              <goal>exec</goal>
            </goals>
            <phase>generate-sources</phase>
            <configuration>
              <arguments>
                <argument>run</argument>
                <argument>build</argument>
              </arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <activation>
        <property>
          <name>devmode</name>
          <value>true</value>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.0.0</version>
            <configuration>
              <webResources combine.children="append">
                <resource>
                  <directory>${project.build.sourceDirectory}</directory>
                  <targetPath>sources</targetPath>
                </resource>
              </webResources>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
former_member186608
Active Participant
0 Kudos

As indicated by Dennis already, pls tell us which version of the S/4HANA Cloud SDK you're using. I suspect that you're not using the latest one.

dhem
Active Participant
0 Kudos

Hi,

which version of the SAP S/4HANA Cloud SDK are you using?

Best regards,

Dennis

meenakshi_a_n_
Explorer
0 Kudos

Hi Dahms,

Yes.I have considered Virtual Data Model for OData only. HereBy attaching the entire log file for your perusal.

"msg":"Exception in update Entity","stacktrace":["com.sap.cloud.sdk.service.prov.api.exception.ServiceSDKException: while trying to invoke the method java.lang.Integer.intValue() of a null object returned from my.company.UpdateProductCommand.execute()","\tat com.sap.cloud.sdk.service.prov.api.util.ProcessorHelper.invokeOperation(ProcessorHelper.java:122)","\tat com.sap.cloud.sdk.service.prov.v2.data.provider.CXSDataProvider.updateEntity(CXSDataProvider.java:481)","\tat com.sap.cloud.sdk.service.prov.v2.rt.data.provider.HybridDataProvider.updateEntity(HybridDataProvider.java:284)"

log.txt

Thanks and regards,

Meenakshi

former_member186608
Active Participant
0 Kudos

On a side note: Have you considered using the Virtual Data Model for OData? Is there any particular reason for not using it in your case?

Apart from that:

- Do you see any log entries in the SAP Cloud Connector?

- Do you see any entries in transaction /n/iwfnd/error_log?