Annotation @Environment.systemField

时间:2022-06-23
本文章向大家介绍Annotation @Environment.systemField,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

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.

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 .

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

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