cancel
Showing results for 
Search instead for 
Did you mean: 

Gateway and oData POST and GET methods

yanev
Participant
0 Kudos

Hi,

I need a little help for the gateway service in SAP and the oData binding in eclipse.

The request is as follows: Pass parameters on input to the RFC -> get the output table -> bind the data with the table in the view.

I only have 1 function module with 2 tables (in the FM). I use the first table for input and based on that data i make a select in a standard table and extract those records in the 2nd table which I use for output in the FM. I need to display that output table in the view.

I have created 2 entity sets: 1 for the input table and 1 for the output table. The mapping is done only on GetEntitySet for both sets(i don't think i need to map other service implementations, but please correct me if i'm wrong).

I call the service and I'm able to display records in the table if I play in debug in the FM:

This is my table in the view:

Now, I'm not sure how to make the connection with the gateway in order to pass a parameter->extract some records to the output table->get the output table from the FM->bind it with the table from the view.

I found this code here: and it's closest to my scenario.


var Input = {};

  Input.Qmnum = sap.ui.getCore().byId("qmnumtxt").getValue();

OData.request({

  requestUri: "proxy/http/<server>:<port>/sap/opu/odata/sap/ZCS_NT_LIST_SRV_TEST_SRV/TbInputSet",

  method: "GET",

  headers: {    

                "X-Requested-With": "XMLHttpRequest",

                "Content-Type": "application/atom+xml",

                "DataServiceVersion": "2.0",

                "X-CSRF-Token":"Fetch"

  }

  },

  function(data,response){

  header_xcsrf_token = response.headers['x-csrf-token'];

  var oHeaders = {

  "x-csrf-token" : header_xcsrf_token,

  'Accept' : 'application/json'

  };

  OData.request({

  requestUri: "proxy/http/<server>:<port>/sap/opu/odata/sap/ZCS_NT_LIST_SRV_TEST_SRV/TbInputSet",

  headers: oHeaders,

  data:Input

  },

                function(data,request) {                

                    location.reload(true);

        },          function(err) {

                    alert("Error");

        });

}, function(err) {

                    var request = err.request;

                    var response = err.response;

                    alert("Error in Get -- Request " + request + " Response " + response);

        });

But there are 2 wrong points here:

1. It doesn't pass anything to the service(although the Input is valorized)

2.It makes a reload to the page and in my case it goes in the init method again and takes the empty output table from the service.

I'll really appreciate any help whatsoever!

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi

if you use get_entity - return structure(one line), then binding as:

oTable.bindItems("/",template)

in your case properly use get_entity_set, as you appear in the table a lot of records rather than one.

oTable.bindItems("/results",template)

Example requests

Get_Entity_Set - return many row

uUrl:port/sap/opu/odata/sap/U_SRV/NameEntitySet?$filter=Objid eq '123' and Otype eq 'E'

after parameter $filter you can see in abap IT_FILTER_TAB

Get_Entity - always return one row

uUrl:port/sap/opu/odata/sap/U_SRV/NameEntitySet(Objid='50000299',Otype='E')

Objid and Otype this fields at stricture in SEQW, this field must be KEY.

yanev
Participant
0 Kudos

Hi Nik,

I understand that part, but my problem is in passing the parameters to the gateway and getting the metadata in one call. I should pass a parameter to the FM and then get the output table in the metadata.

The binding of the data works, but there's no data to be bound.

0 Kudos

var sPath_cust = "/Customer_DetailsSet(Kunnr='" + custID + "')";

this.oModel.read(sPath_cust,null, null, false, function(oData,
response) {

  var jsonModel = new sap.ui.model.json.JSONModel(oData);

                                                customerForm.setModel(jsonModel);

},

function(oError) {alert(oError); }

);

yanev
Participant
0 Kudos

Yes it is a key in the structure.

I tried your suggestion with $filter but doesn't work as well.

BTW, this is my new service:

I want to make it simple to pass 1 parameter and get the table after extraction based on that input.

I also redefined the methods in the DPC_EXT

0 Kudos

oEntitySet?$filter=

Add ?

yanev
Participant
0 Kudos

Now it gives me 400 (Bad Request) .

Another thing I noticed If I pass it like this: "/oEntitySet?" then I can enter in debug in the FM and doesn't give an error (but like that I'm not sending any input to the server, I only get the output), but if i pass it as you suggest gives back the error and doesn't go in debug (also with the ? ).

Answers (2)

Answers (2)

0 Kudos

please show full url request with filter params(at chrome console).

yanev
Participant
0 Kudos
0 Kudos

in end at url delete )


Example request

Get_Entity_Set

uUrl:port/sap/opu/odata/sap/U_SRV/NameEntitySet?$filter=Objid eq '123'

former_member202253
Participant
0 Kudos

2Hello Sashko,

As you said, there are two table parameter one for input and another for output. But in onInit method I am not able to find any input parameter for service call.

One more thing you can pass HandleError function in Odata.read method and alert response code.

Please find sample code.

 

var sPath_cust = "/Customer_DetailsSet(Kunnr='" + custID + "')";

this.oModel.read(sPath_cust,null, null, false, function(oData,
response) {

  var jsonModel = new sap.ui.model.json.JSONModel(oData);

                                                customerForm.setModel(jsonModel);

},

function(oError) {alert(oError); }

);

You can debug javascript code in chrome. refer below URL/

https://sapui5.hana.ondemand.com/sdk/#docs/guide/1e52fde5444649748809a78fd8a645da.html

Thanks,

Nikhil

yanev
Participant
0 Kudos

Hi Nikhil,

Thanks for your reply. I tried passing a key in the string as you suggested but it gives me a 404 error:

I can't figure out if the problem is in the gateway or not, and if it is, how should the gateway mapping look like?

Thanks

0 Kudos

Hi

in your screenshot url not exist.

1.After create new project you need registrer your service, if status green then good.

2. Full url service and test enity you can see in Sap getaway client test.

select entity and push execute

insert break point in redefine method get entity or get_entity_set

yanev
Participant
0 Kudos

It says that the url doesn't exist only when i pass it like Nikhil suggested ("/Customer_DetailsSet(Kunnr='" + custID + "')";), if I pass it like i did, the url exists. Also i have created and activated a webservice for the gateway project:

and when I test the get method works.

0 Kudos

It says that the url doesn't exist only when i pass it like Nikhil suggested ("/Customer_DetailsSet(Kunnr='" + custID + "')";), if I pass it like i did, the url exists. Also i have created and activated a webservice for the gateway project:

if you read by key, then you must transfer all keys at structure entity at segw

("/Customer_DetailsSet(key1='" + custID + "')",key2='123')


if you read by filter params you must transfer an arbitrary number of parameters.