Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing External Data →  ABAP Database Access →  ABAP SQL →  ABAP SQL - Operands and Expressions →  ABAP SQL - SQL parameter passing sql_para 

ABAP SQL, Parameter Passing to a CDS View

This example demonstrates a read performed on a CDS view using parameter passing.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA:
      from_distance TYPE s_distance VALUE 2000,
      to_distance   TYPE s_distance VALUE 6000,
      unit          TYPE s_distid   VALUE 'MI'.
    cl_demo_input=>new(
      )->add_field( CHANGING field = from_distance
      )->add_field( CHANGING field = to_distance
      )->add_field( CHANGING field = unit
      )->request( ).

    SELECT *
           FROM demo_cds_parameters( p_distance_l = @from_distance,
                                    p_distance_u = @to_distance,
                                    p_unit       = @unit )
           ORDER BY carrid, connid
           INTO TABLE @DATA(result).
    cl_demo_output=>display( result ).

Description

SELECT is used to access a CDS view with parameters as a data source. Actual parameters are assigned to the input parameters of the view. The values of these actual parameters can be defined by input.

The view in question, demo_cds_parameters, has the following CDS source code with a list of input parameters:

@AbapCatalog.sqlViewName: 'DEMO_CDS_PARA'
@AccessControl.authorizationCheck: #NOT_REQUIRED
@Metadata.allowExtensions
@EndUserText.label: 'Demo für Parameter-View'
define view demo_cds_parameters
  with parameters
    p_distance_l :s_distance,
    p_distance_u :s_distance,
    p_unit       :s_distid
  as select from
    spfli
    {
      key carrid,
      key connid,
          cityfrom,
          cityto,
          distance,
          distid
    }
    where
          distid   =       :p_unit
      and distance between :p_distance_l and :p_distance_u;          

This means that those rows are read from the database table SPFLI whose distance in the passed unit is located between the two passed values.