The following section shows how to use the SAP Query component of the LINQ to ERP toolbox.

Note: The SAP Query component does not support BW queries.

About the Sample Query #

This example uses the training Query D3 which contains flight information of airplanes. Data that matches certain selection criteria (e.g. airline and date of flight) is fetched and drawn into a DataGrid, see screenshot below.


Look Up a Query #

  1. Drag&Drop the SAP Query component into the LINQ to ERP DataContext. A search window opens.
  2. Enter the name of the SAP Query to be extracted in the field Query Name or enter the name of a User Group in the fields User Group (1). Use wildcards (*) if needed.
  3. Click [Search] (binoculars icon) (2). Search results appear in the preview window.
  4. Select an SAP Query (3) and click [OK] (4) to proceed.

Process a Query #

  1. Optional: Search a variant to apply or edit.
  2. Specify which values need to be accessible in the code by checking Pass (5).
  3. Define variable names for the accessible values. The default names are supplied by SAP.
  4. You can rename the DataContext method in the field Method (6).
    You can also rename the class that represents a single row in the field Object and the class that represents the entire query output in the field Collection.
  5. Navigate to the tab Fields and uncheck unneeded fields and/or rename fields.
  6. The DataContext class now offers a function to execute the query. The parameter values correspond to range objects introduced in the section Calling SAP Queries.

How to Use the Class in your Code #

Save the .erp file that contains the extraction component to trigger the proxy classes code generation in the background.
The following code shows how to use the generated classes in the context of this example:

private void btnGo_Click(object sender, EventArgs e) 
            SAPContext sc = new SAPContext("SAPUser", "Password");
            // Create Query object Query q; 
                QuerySelectionParameter airline = new QuerySelectionParameter();
				QuerySelectionParameter date = new QuerySelectionParameter();
                date.AddRange(Sign.Include, RangeOption.Between, inputStartDate.Text, inputEndDate.Text);

                var MyQueryResult = from res in sc.D3(airline, date) select res;
                this.dataGridView1.DataSource = MyQueryResult.ToList();
            catch (Exception e1)