Selection Options on Associated CDS Views (Exists Operator)

You want to link a CDS view in your output, using factory method CREATE_FOR_CDS( ) (see also Support of Core Data Services (CDS)). This CDS view contains header data and has associations with CDS views that contain further details (for example, items, addresses). When associated CDS views are used, selection conditions in their fields can be created without these fields having to be part of the CDS view with the header data. This means that even with 1:n relationships between entities you can display one line of data for each header if no fields of the associated CDS view are included in the CDS view with the header data.

The example below illustrates this concept.

Using ALV for IDA, sales orders are to be displayed and the following selection conditions made available to the user:
  • Conditions from the sales order header
  • Sales orders that contain items of a specific type (for example, selected products only)
  • Sales orders whose customers are located in selected countries

    The graphic below shows a small entity model and its dependencies: Sales Order represents the CDS view with the header data Customer, Address, and Items, represents the associated CDS views.

A sales order should appear once only in the list.

The system contains CDS view SEPM_CDS_SALES_ORDER. To transfer fields from associated CDS views (for example, SEPM_CDS_SALES_ORDER_ITEM ) into the selection conditions, and to use them as exists operators, dot notations can be passed to parameter IV_NAME of method ADD_RANGES_FOR_NAME of class cl_salv_range_tab_collector. If no dot notation is used, only fields from the linked CDS view can be addressed. For example, if values for the COUNTRY field from an entity model are provided as the selection condition, the association path in parameter IV_NAME is specified as follows: Customer.Address.Country.

Below is an example of source code to transfer selection conditions in fields from the linked CDS view and its associated CDS views:

data(lo_collector) = NEW cl_salv_range_tab_collector( ).
lo_collector-> add_ranges_for_name(    
  iv_name = 'SALES_ORDER_ID'  it_ranges =  salesorderid[] ). 
lo_collector-> add_ranges_for_name(    
  iv_name = 'CUSTOMER.ADDRESS.COUNTRY'  it_ranges =  bupa_address_cntr[] ). 
lo_collector-> add_ranges_for_name(    
  iv_name = 'ITEMS.PRODUCT.ID'    it_ranges =  items_product_id[] ). 
lo_collector-> get_collected_ranges(   
  IMPORTING  et_named_ranges = data( lt_name_range_pairs) ). 
lo_alv_display-> set_select_options(  it_ranges =  lt_name_range_pairs ).

Conditions in different fields are linked with the logical AND; multiple values and ranges are linked with the logical OR.

This behavior follows the standard SELECT OPTIONS links. The AND operator between different values in a field or the OR operator between different fields is not supported.