Skip to Content
avatar image
Former Member

oData: cannot call RFC from backend

Hi Experts,

I created a simple function RFC returning a structure BAPIRET2.

I created all the steps (I guess so) in spro, segw. I succeed calling the SAP Gateway Client.

In SEGW, I created an EntitySet: in it, I created the Read mapping (not the Query).

In NWDS 7.50, I create a a ui5 project with javascript view.

I created a simple table or even a Label to print out the returning string from RFC.

I do not get anything back, not even an error.

This is my code in the onInit of the controller:

var oModel = new sap.ui.model.odata.ODataModel("http://server:port/sap/opu/odata/sap/ZTEST2_SRV/HELLO_WORLD1Set('qwqwqw')", true, "user", "password");

var oTable = sap.ui.getCore().byId("MyTable"); 
oTable.setModel(oModel); 
oTable.bindRows("/EMessage");

Nothing returns.

But, if I create a simple html file on my desktop, I do succeed calling the same RFC using ajax:

var auth = btoa('user:password');

$(document).ready(function () {

$('#get-data').click(function () {

$.ajax({ type: "GET", data: '{}', url: "http://server:port/sap/opu/odata/sap/ZTEST2_SRV/HELLO_WORLD1Set('1111')/EMessage",

headers: { "Authorization": "Basic " + auth },

contentType: "application/json; charset=utf-8",

dataType: "json",

success: function(data) { alert(">>" + JSON.stringify(data)); },

error: function(data) { alert(">>>>>" + JSON.stringify(data)); }, });

});

});

Can someone please help?

Thanks in advance.

Regards.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

7 Answers

  • Best Answer
    avatar image
    Former Member
    Dec 14, 2016 at 11:05 PM

    If you want bind entityset to table, entityset should return arrays.I mean you have to implement Query(OData).

    And change your source code like this..

    oTable.bindRows("EMessage");//Remove /

    In general entityset should bound to table so HELLO_WORLD1Set shoud bound to table,

    and HELLO_WORLD1Set must be implemented a Query not read.

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 11, 2016 at 02:00 PM

    i believe your ui5 is running in java server and the odata is in abap server

    it is not going to work(directly/easily), they have to be in same server.

    Add comment
    10|10000 characters needed characters exceeded

    • do u have any idea about same origin policy?

      odata service and ui5 should be in same server......

      if not, you have to use web dispatcher or proxy at server side to make the call success

  • avatar image
    Former Member
    Dec 12, 2016 at 05:19 AM

    Hi,

    Please share the error screenshot while calling that service.

    It wil help to resolve the prolem

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi,

      I have no error screen shot.

      I printed the oModel, maybe it will help.

      HTML1300: Navigation occurred.
      File: index.html
      2016-12-14 09:47:34 Device API logging initialized - DEVICE
      2016-12-14 09:47:34.471205 registerResourcePath ('', 'resources/') -  sap.ui.ModuleSystem
      2016-12-14 09:47:34.471550 URL prefixes set to: -  sap.ui.ModuleSystem
      2016-12-14 09:47:34.471793   (default) : resources/ -  sap.ui.ModuleSystem
      2016-12-14 09:47:34.711596 registerResourcePath ('test103', './test103/') -  sap.ui.ModuleSystem
      EventProvider sap.ui.model.odata.ODataModel
         {
            [functions]: ,
            __proto__: { },
            aBatchOperations: [ ],
            aBindings: [ ],
            aPendingRequestHandles: [ ],
            aUrlParams: [ ],
            bCache: true,
            bCountSupported: true,
            bDestroyed: false,
            bJSON: true,
            bLegacySyntax: false,
            bLoadAnnotationsJoined: true,
            bLoadMetadataAsync: false,
            bRefreshAfterChange: true,
            bSkipMetadataAnnotationParsing: undefined,
            bTokenHandling: true,
            bUseBatch: false,
            bWithCredentials: false,
            id: "id-1481701654975-0",
            iSizeLimit: 100,
            mContexts: { },
            mCustomHeaders: { },
            mEventRegistry: { },
            mMessages: null,
            mSupportedBindingModes: { },
            oAnnotations: { },
            oData: { },
            oEventPool: { },
            oHandler: { },
            oHeaders: { },
            oMetadata: { },
            oMetadataFailedEvent: null,
            oMetadataLoadEvent: null,
            oRequestQueue: { },
            oServiceData: { },
            pAnnotationsLoaded: { },
            sAnnotationURI: null,
            sDefaultBindingMode: "OneWay",
            sDefaultCountMode: "Both",
            sMaxDataServiceVersion: undefined,
            sPassword: "password",
            sServiceUrl: "/proxy/http/mdxprt01.dev.merkava.gov.il:62000/sap/opu/odata/sap/ZTEST2_SRV/HELLO_WORLD1Set('qwqwqw')",
            sUpdateTimer: null,
            sUser: "user"
         }
      
      
      I tried without the proxy and got the same oModel.
      
      Thanks.
      
      
  • avatar image
    Former Member
    Dec 12, 2016 at 05:19 AM

    Hi,

    Please share the error screenshot while calling that service.

    It wil help to resolve the problem

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 14, 2016 at 09:28 AM

    Your oData model URL might be wrong.

    Try [http://server:port/sap/opu/odata/sap/ZTEST2_SRV] without [HELLO_WORLD1Set('qwqwqw')] .

    And HELLO_WORLD1 is your Entity set that should be bound to the table,

    and EMessage is bound to your list item data, I suppose.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi,

      I tried it but still no data displayed in table and still no error.

      Here is the oModel.

      EventProvider sap.ui.model.odata.ODataModel
         {
            [functions]: ,
            __proto__: { },
            aBatchOperations: [ ],
            aBindings: [ ],
            aPendingRequestHandles: [ ],
            aUrlParams: [ ],
            bCache: true,
            bCountSupported: true,
            bDestroyed: false,
            bJSON: true,
            bLegacySyntax: false,
            bLoadAnnotationsJoined: true,
            bLoadMetadataAsync: false,
            bRefreshAfterChange: true,
            bSkipMetadataAnnotationParsing: undefined,
            bTokenHandling: true,
            bUseBatch: false,
            bWithCredentials: false,
            id: "id-1481715072342-0",
            iSizeLimit: 100,
            mContexts: { },
            mCustomHeaders: { },
            mEventRegistry: { },
            mMessages: null,
            mSupportedBindingModes: { },
            oAnnotations: { },
            oData: {
               [functions]: ,
               __proto__: { }
            },
            oEventPool: { },
            oHandler: { },
            oHeaders: {
               [functions]: ,
               __proto__: { },
               Accept: "application/json",
               Accept-Language: "he-IL",
               DataServiceVersion: "2.0",
               MaxDataServiceVersion: "2.0"
            },
            oMetadata: { },
            oMetadataFailedEvent: null,
            oMetadataLoadEvent: null,
            oRequestQueue: { },
            oServiceData: { },
            pAnnotationsLoaded: { },
            sAnnotationURI: null,
            sDefaultBindingMode: "OneWay",
            sDefaultCountMode: "Both",
            sMaxDataServiceVersion: undefined,
            sPassword: "password",
            sServiceUrl: "http://server:port/sap/opu/odata/sap/ZTEST2_SRV",
            sUpdateTimer: null,
            sUser: "user"
         }
      
      I notide that in oMetadata, the bFailed is set to "true".
      
      Thanks.
      
  • avatar image
    Former Member
    Dec 14, 2016 at 11:38 AM

    It's like it is not even getting to the sap gateway abap server.

    I changed the password and I did not get any "access denied".

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 04, 2017 at 11:54 AM

    Thank you!

    Add comment
    10|10000 characters needed characters exceeded