This article is in two parts, and this is the second part that demonstrates how to use filters and how to combine filter conditions using operators.

It is a continuation of the first part, Part 1: Getting SAP Data into Your Microsoft Excel Application, which demonstrates how to quickly generate code and to modify the generated code for a GWM Excel add-in that presents SAP data in Microsoft Excel.

First, we will show how to add a filter expression to get the data for the SalesOrderID property, with values greater than 0500000050. Later, we will show how to add filter expressions using the configuration file.

TIP: We know that the SalesOrderID property is filterable.

Let’s try it by following the steps below:

  1. From the Solution Explorer, go to the project and open the class, Excel -> ExcelManager -> ExcelDataManager.cs, then find the method, BindExcelTableWithRecords, and then find and comment out the line as shown below :
    //var serviceresponse = serviceContext.SalesOrderCollection.AddQueryOption(“$top”,ExcelSettingManager.MaxRecords).Execute() as QueryOperationResponse<GWDEMO.SalesOrder&gt;;
  2. Insert a new line of code below the commented line as shiwn below:
    var serviceresponse = serviceContext.SalesOrderCollection.AddQueryOption(“$top”, ExcelSettingManager.MaxRecords).AddQueryOption(“$filter”, “SalesOrderID gt ‘0500000050’”).Execute() as QueryOperationResponse<GWDEMO.SalesOrder &gt;;
  3. Rebuild and run the project for your GWM Excel add-in application. From Microsoft Excel, click on the Fetch button, and check that the results are displayed according to the filter.

/wp-content/uploads/2014/05/filterexp_460054.png

Now you use the filter expression in the code below, this shows how to combine filter conditions using the OR operator:
var serviceresponse = serviceContext.SalesOrderSet.AddQueryOption(“$top”, ExcelSettingManager.MaxRecords).AddQueryOption(“$filter”, “SalesOrderID gt ‘0500000065’ or SalesOrderID eq ‘0500000065’”).Execute() as QueryOperationResponse<GWDEMO.SalesOrder &gt;;

Rebuild and run the project for Excel add-in application. In Microsoft Excel, click on the Fetch button, and check that the results are displayed according to the filter.

For more information on how to build filter expressions, see http://www.odata.org/documentation/uri-conventions/#SystemQueryOptions.

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply