SAP ABAP ODATA order of query option parameters

694 Views Asked by At

I have created an odata service for testing purposes in SEGW. My Query string looks like:

/.../ProductsSet?$select=Id,Title,Description,Price,Rating&$filter=startswith(Title,'S')&$inlinecount=allpages&$skip=10&$top=10&$orderby=Rating desc&$format=json

However, I get unexpected weird result sets. Can somebody explain me how the order of e.g filter, skip, top, orderby, select is executed in OdataV2 and v4, in the backend, to reproduce the results? I mean how do the query options influence each other?

1

There are 1 best solutions below

0
MarcL On

ok I think I can reproduce the database logic how it retrieves the data (and in what order of the query parameters).. I got 18 entries after filtering for "S" first (actually its 17, the second entry with small "s" doesnt count"). From there, it got ordered by Rating desc. Then skip the first 10 (skip 10) and get the other 10 (offset 10) entries (which leaves only 7 entries).

enter image description here

This also corresponds to the order of my select statement (maybe its incidentally only). I'm not sure anymore what DB S4/HANA uses, but e.g in SQL Server I remember that its the query-optimizer that makes sure that filtering comes first (to get a smaller subset) etc...

enter image description here

This is the result in json:

{
  "d" : {
    "__count" : "7",
    "results" : [
      {
        "__metadata" : {
          "id" : "http://adeps4p0.saplab.3as-cloud.de:50000/sap/opu/odata/SAP/ZALM_FS_APP_SRV/ProductsSet('00059')",
          "uri" : "http://adeps4p0.saplab.3as-cloud.de:50000/sap/opu/odata/SAP/ZALM_FS_APP_SRV/ProductsSet('00059')",
          "type" : "ZALM_FS_APP_SRV.Products"
        },
        "Id" : "00059",
        "Title" : "Spring and summershoes",
        "Description" : "Comfortable stretch cloth, lightweight body; ,rubber sole, anti-skid wear;",
        "Price" : 20,
        "Rating" : "4.33"
      },
      {
        "__metadata" : {
          "id" : "http://adeps4p0.saplab.3as-cloud.de:50000/sap/opu/odata/SAP/ZALM_FS_APP_SRV/ProductsSet('00036')",
          "uri" : "http://adeps4p0.saplab.3as-cloud.de:50000/sap/opu/odata/SAP/ZALM_FS_APP_SRV/ProductsSet('00036')",
          "type" : "ZALM_FS_APP_SRV.Products"
        },
        "Id" : "00036",
        "Title" : "Sleeve Shirt Womens",
        "Description" : "Cotton Solid Color Professional Wear Sleeve Shirt Womens Work Blouses Wholesale Clothing Casual Plain Custom Top OEM Customized",
        "Price" : 90,
        "Rating" : "4.26"
      },
      {
        "__metadata" : {
          "id" : "http://adeps4p0.saplab.3as-cloud.de:50000/sap/opu/odata/SAP/ZALM_FS_APP_SRV/ProductsSet('00007')",
          "uri" : "http://adeps4p0.saplab.3as-cloud.de:50000/sap/opu/odata/SAP/ZALM_FS_APP_SRV/ProductsSet('00007')",
          "type" : "ZALM_FS_APP_SRV.Products"
        },
        "Id" : "00007",
        "Title" : "Samsung Galaxy Book",
        "Description" : "Samsung Galaxy Book S (2020) Laptop With Intel Lakefield Chip, 8GB of RAM Launched",
        "Price" : 1499,
        "Rating" : "4.25"
      },
      {
        "__metadata" : {
          "id" : "http://adeps4p0.saplab.3as-cloud.de:50000/sap/opu/odata/SAP/ZALM_FS_APP_SRV/ProductsSet('00047')",
          "uri" : "http://adeps4p0.saplab.3as-cloud.de:50000/sap/opu/odata/SAP/ZALM_FS_APP_SRV/ProductsSet('00047')",
          "type" : "ZALM_FS_APP_SRV.Products"
        },
        "Id" : "00047",
        "Title" : "Sneaker shoes",
        "Description" : "Synthetic Leather Casual Sneaker shoes for Women/girls Sneakers For Women",
        "Price" : 120,
        "Rating" : "4.19"
      },
      {
        "__metadata" : {
          "id" : "http://adeps4p0.saplab.3as-cloud.de:50000/sap/opu/odata/SAP/ZALM_FS_APP_SRV/ProductsSet('00003')",
          "uri" : "http://adeps4p0.saplab.3as-cloud.de:50000/sap/opu/odata/SAP/ZALM_FS_APP_SRV/ProductsSet('00003')",
          "type" : "ZALM_FS_APP_SRV.Products"
        },
        "Id" : "00003",
        "Title" : "Samsung Universe 9",
        "Description" : "Samsung's new variant which goes beyond Galaxy to the Universe",
        "Price" : 1249,
        "Rating" : "4.09"
      },
      {
        "__metadata" : {
          "id" : "http://adeps4p0.saplab.3as-cloud.de:50000/sap/opu/odata/SAP/ZALM_FS_APP_SRV/ProductsSet('00070')",
          "uri" : "http://adeps4p0.saplab.3as-cloud.de:50000/sap/opu/odata/SAP/ZALM_FS_APP_SRV/ProductsSet('00070')",
          "type" : "ZALM_FS_APP_SRV.Products"
        },
        "Id" : "00070",
        "Title" : "Stainless Steel Women",
        "Description" : "Fashion Skmei 1830 Shell Dial Stainless Steel Women Wrist Watch Lady Bracelet Watch Quartz Watches Ladies",
        "Price" : 35,
        "Rating" : "4.08"
      },
      {
        "__metadata" : {
          "id" : "http://adeps4p0.saplab.3as-cloud.de:50000/sap/opu/odata/SAP/ZALM_FS_APP_SRV/ProductsSet('00042')",
          "uri" : "http://adeps4p0.saplab.3as-cloud.de:50000/sap/opu/odata/SAP/ZALM_FS_APP_SRV/ProductsSet('00042')",
          "type" : "ZALM_FS_APP_SRV.Products"
        },
        "Id" : "00042",
        "Title" : "Stiched Kurta plus trouser",
        "Description" : "FABRIC: LILEIN CHEST: 21 LENGHT: 37 TROUSER: (38) :ARABIC LILEIN",
        "Price" : 80,
        "Rating" : "4.05"
      }
    ]
  }
}