Skip to Content
-1

How to call XSODATA service using create with hdbprocedure from SAP Web IDE (Neo)

Hi Experts,

1) I created the .hdbprocedure in SAP Hana Web Development Workbench.

PROCEDURE "TEST"."demo.test01::EmpInsert" (

IN new "demo.test01::Employee",

OUT error "demo_tz.test01::Err" )

LANGUAGE SQLSCRIPT SQL SECURITY INVOKER AS

BEGIN

DECLARE CURSOR c_cursor FOR SELECT EMP_ID, EMP_NAME, DEPARTMENT FROM :new;

SELECT "DEPARTMENT" INTO department FROM :new;

DELETE FROM "TEST"."demo.test01::Employee" WHERE DEPARTMENT= :department;

FOR cur_row as c_cursor DO

emp_id = cur_row.EMP_ID;

emp_name = cur_row.EMP_NAME;

emp_dept = cur_row.DEPARTMENT;

INSERT INTO "TEST"."demo.test01::Employee" VALUES (emp_id, emp_name, emp_dept); END FOR;

END

2) I created the xsodata using that procedure.

service {

"TEST"."demo.test01::Employee" as "Employee"

create using "demo.test01::EmpInsert" ; }

3) I created the SAPUI5 application at Web IDE Neo environment

My requirement is to create new data using xsodata from SAP Web IDE.

I would like to pass the json data array during xsodata service call.

I tried this, but it does not work although I am not sure it is allowed or not.

var oData = [];

oEntry2 ={"EMP_ID":"E0002","EMP_NAME":"Test User1","DEPARTMENT":"IT"};

oEntry2 ={"EMP_ID":"E0002","EMP_NAME":"Test User1","DEPARTMENT":"IT"};

oData.push(oEntry1);

oData.push(oEntry2);

oModel.create(sPath, oData, {success: function (){}, error: function (){});

What actions should I do to achieve the above requirement?

Please kindly provide references/samples.

Best Regards,

Thiri

Add a comment
10|10000 characters needed characters exceeded

  • Hi Experts,

    I haved tried with ajax POST method passing parameters data as JSON.stringfy(data) method.

    It faced the same error code : 400

    Please kindly provide the correct way .

    Here is my code for ajax POST.

    var jsonData = JSON.stringify(oData);

    jQuery.ajax({

    type: "POST",

    url: "/xxxxxxx/Employee.xsodata/Employee",

    data: jsonData,

    contentType: "application/json",

    beforeSend: function(xhr) {

    xhr.setRequestHeader("X-CSRF-Token", token);

    },

    success: function(data, textStatus, jqXHR) {

    result = "Success"; window.alert("success to post");

    },

    error: function (data, xhr, textStatus) {

    result = "Error"; window.alert("fail to post");

    } });

    Best Regards,

    Thiri

  • Hi Florian Pfeffer,

    Thanks for your feedback.

    Here is the error information.

    oError.statusCode "400"

    oError.statusText "Bad Request"

    oError.responseText "Error processing request stream. The request should be a valid top-level resource object."

    Best Regards,

    Thiri

  • Is the post request (by the called create function) visible in the browsers network tab? If yes, do you get an error or any other hint?

Related questions

2 Answers

  • Best Answer
    Posted on Aug 03, 2020 at 07:34 AM

    Ok, thx for the hint regarding the JSON array.

    The create function does only support objects and not arrays; meaning with one call of the create function you can only create one entry. You have to call the create function for each entry you want to create. In case you want to send all the data once to the backend, you can use function createEntry for each of your data objects and then call function submitChanges to transfer it to the backend. Using the groupId and changesetId parameters of the createEntry function, you can steer how the data is "bundled".

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 03, 2020 at 05:33 AM

    According to the error message you posted in the comments above, for me it seems like you are calling a wrong endpoint which is not availabled in the OData Service. Please check (and show here) if your OData model points to the correct OData service and that the path you use for the create operation addresses the "Employee" collection of that OData service.

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Florian Pfeeffer,

      Thanks for your feedback.

      The url is correct because it is okay for one record json data.

      The error is occurred only when passing json data array.

      So, may be passing json data array is not allowed for oModel.create method.

      Best Regards,

      Thiri

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.