1.此步重点:
1.在创建带参数CDS时,with parameters后面的参数 格式为:
参数名:参数数据类型
所就是说,下面例子中,p_billing_status为传入的参数 名,SNWD_SO_CF_STATUS_CODE是表snwd_so,字段billing_status的数据类型。
2.在ABAP程序中,WHERE 把CDS中定义的参数 作为一个视图字段,做为条件直接填入。
2.操作步骤
2. In the New ABAP Repository Object window, search for DDL source object by typing in search field.Select the DDL Source and hit Next.
3. In the New DDL Source window, enter Name and Description of the CDS View and hit Finish.
4. A new ABAP CDS view editor opens up like below and paste the below code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
@AbapCatalog.sqlViewName: 'Z_CDS_PARAMS' @AbapCatalog.compiler.compareFilter: true @AccessControl.authorizationCheck: #CHECK @EndUserText.label: 'CDS View with Parameters' define view Z_Cds_With_Params with parameters p_billing_status :SNWD_SO_CF_STATUS_CODE, p_delivery_status :SNWD_SO_OR_STATUS_CODE as select from snwd_so join snwd_so_i on snwd_so.node_key = snwd_so_i.parent_key{ snwd_so.so_id as orderno, snwd_so_i.so_item_pos as itemno, snwd_so_i.currency_code as currency, snwd_so_i.gross_amount as grossamount, snwd_so_i.net_amount as netamount, snwd_so_i.tax_amount as taxamount } where snwd_so.billing_status = :p_billing_status and snwd_so.delivery_status = $parameters.p_delivery_status; |
5. Lets observe the code
Line 8-9: We can provide the parameters to the ABAP CDS Views by adding the syntax WITH PARAMETERS p1, p2… Data Dictionary ABAP data types can be used while defining the parameters to the ABAP CDS Views.
Line 19-20: We can use the parameters p1, p2.. in CDS Views using the syntax :p1 or $parameters:p1
6. Now we will see how to call the ABAP CDS views with input parameters in an ABAP program using Open SQL statement. Create an ABAP program in eclipse ADT or SE38-ABAP编辑器 transaction. Below is the code snippet to call the ABAP CDS Views with input parameters.
*程序中的内表LT_RESULT不用先定义,直接使用就行。
1 2 3 4 5 6 7 8 9 |
SELECT ORDERNO, ITEMNO, CURRENCY, GROSSAMOUNT, NETAMOUNT, TAXAMOUNT FROM Z_CDS_PARAMS(P_BILLING_STATUS='P', P_DELIVERY_STATUS='D') INTO TABLE @DATA(LT_RESULT). |