cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5 - Insert more than 1 record in sap - service gateway

Former Member
0 Kudos

Hi Experts ,

I have one doubt . I created an application in fiori and I try to submit my data in SAP. The problem is I have a list of items and I want to insert this list in one unic request .

Look at the example :

I have a list with 3 items like :

NameQuantityUnit
A1AU
B2D
C1AU

And what I want to do is to put this three items in same request .

How can I send this 3 items for sap using service gateway with method created in same time?

I think the best way is maybe to send the first line and after send one by one doing the update in the last request I created.
I don't know if are available other options.

Can you help me please ?

thanks very much for your time .
Best Regards

Cristina Rodrigues

Accepted Solutions (1)

Accepted Solutions (1)

maheshgonda
Product and Topic Expert
Product and Topic Expert
0 Kudos

HI ,

use following methods

1.GET_EXPANDED_ENTITYSET : if you want to read multiple records (READ) in single request

2.CREATE_DEEP_ENTITY : To create or/and update multiple records in single request

for more info

$expand Query Option in SAP OData Service - SAP Fiori,SAP HANA,SAPUI5,SAP Netweaver Gateway Tutorial...

Former Member
0 Kudos

Hi Maesh ,

I can't use this methods because I don't have any association. I used a bapi where we inserted many items in only purchase requisition.

How can I sent and read many lines with service gateway ?

I know send one line but more than one I don't know logic.

Can you help me ?

Best Regards

Answers (2)

Answers (2)

maheshgonda
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Cristina Rodrigues,

use batch(i dont know how it works) as @Jun Wu mentioned  or i suggest you to create one navigation for "header structure" with one field(Id) and item structure with n fields and check it !

Header structure

id

==============

Item structure

id

name

description

.....

......

junwu
Active Contributor
0 Kudos

use batch

Former Member
0 Kudos

I saw some tutorials about this, but when I try do the steps we show me the following error : "The request URI is not valid. The segment 'ITEMS' refers to an entity set and not to a single entity."

And I have some difficulties to understand this logic.  How can I send from fiori an array of items for service gateway and use this funcionatilly ($batch) to insert data. I need to read the data and put them in table for passing in bapi.

For me this is very complex 😕

Can you please explain me better please ?


Best Regards

Former Member
0 Kudos

Hi Cristina ,

this is how you will use batch in sapui5 ..

Sample Example :

create batch request :

//Bdata contains data of table

// oBModel is your view odata model

var input;

while(i<Bdata.length)

input = {

     Tabname:tabname,

  Scol01:Bdata[i].Scol01,

  Scol02:Bdata[i].Scol02,

  Scol03:Bdata[i].Scol03,

  Scol04:Bdata[i].Scol04,

  Scol05:Bdata[i].Scol05,

  Scol06:Bdata[i].Scol06,

  Scol10:Bdata[i].Scol10,

  Mcol01:Bdata[i].Mcol01,

  Mcol02:Bdata[i].Mcol02,

  Mcol03:Bdata[i].Mcol03,

  Mcol04:Bdata[i].Mcol04,

  Mcol05:Bdata[i].Mcol05,

  Lcol01:Bdata[i].Lcol01,

  Lcol02:Bdata[i].Lcol02,

  Opr:'L'};

  batchChanges.push(oBModel.createBatchOperation("tabnameSet","POST",input,null));

i = i+1;

}

//telling model to call batch

   oBModel.addBatchChangeOperations(batchChanges);

  oBModel.setUseBatch(true);

  oBModel.submitBatch(function(oData,oResponse,aErrorResponses){

     alert(oResponse);

});

thanks

Viplove

Former Member
0 Kudos

I try use batch in gateway service but I have this message and doesn't appear anything in http response

The http request is copy of the note  , it is a simple request of two entities

Best Regards

Former Member
0 Kudos

hi Cristina,

In this where is your input batch request body

thanks

Viplove

Former Member
0 Kudos

Hi Viplove,

Sorry I never used $batch, what do you mean with my input batch request body ?

Can you show me an example ?


Thanks for your help,

Best Regards

Cristina Rodrigues

Former Member
0 Kudos

hi Cristina,

Refer this for how the batch request payload looks like : $batch Processing - SAP Gateway Foundation (SAP_GWFND) - SAP Library

thanks

Viplove