Annotation @Environment.systemField

134 阅读1分钟

The below view declares two argument langauge and system user. The view is used to retrieve product id with description via inner join.

@AbapCatalog.sqlViewName: 'zprdtext'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Jerry product description'
define view Zproductdescription
with parameters
    @Consumption.hidden: true
    @Environment.systemField: #SYSTEM_LANGUAGE
    P_Language              : syLangu,

    @Consumption.hidden: true
    @Environment.systemField : #USER
    p_uname : syst_uname  


as select from comm_product as product inner join comm_prshtext as _text
on product.product_guid = _text.product_guid {
   key product.product_id,
   product.product_type,
   _text.short_text as description
} where product.upname = :p_uname and _text.langu = :p_Language

When we locally preview the view, we are asked to provide the value for these two argument.

clipboard1

In productive use, it is this @Environment.systemField annotation which takes effect. In open SQL we do not need to explicitly pass value to these two parameters.
See following ABAP code: all products created by Jerry are fetched, although no parameter for user name is passed.

data: lt_result TYPE TABLE OF Zproductdescription.

SELECT * FROM Zproductdescription INTO TABLE @lt_result .

clipboard2

You can verify via ST05 that ABAP runtime automatically fills these two parameter for you:

clipboard3

要获取更多Jerry的原创文章,请关注公众号"汪子熙":