In the following example, the data from an exemplary query from the area of materials management are extracted. First, with the help of the CreateQuery method from the R3Connection object, the query object is built. Each SAP query is clearly determined by three descriptors: the user area (whether local or global), the user group (in our example /SAPQUERY/MB) and the name of the query itself (MEBESTWERTAN in our case).
Then the ranges are filled. Every parameter has a distinctly technical name. Via the indexer, you can access the parameter’s range collection under the name (e.g. SP$00017) and add a new range with Add. An individual range is determined by a sign (include or exclude), an operator (e.g. equals for parity) and a low or high value (LowValue and HighValue). Because we only use parity in our example, the high value is irrelevant here. Both values are required for special operators (e.g. Between). If you don’t know the technical name of a SelectionParameter, you can directly invoke the selection image in the SAP GUI, place your cursor in the field, press F1 and then press the “technical info” button. The name will be stated at the very bottom, next to the term “Dynprofield”.
When all of the selections have been filled in, the query can be executed with the help of the Execute method. The query output will then be in an ADO.NET DataTable. It can be accessed via the Result attribute of the query object.