是否可以获取允许当前用户查看的所有BUKRS的列表?
我想将此列表用作开放sql中的过滤器。想象一下我搜索的方法的结果将结果存储在bk_list
中。然后我可以像这样使用bk_list
:
SELECT * FROM some_table WHERE bukrs IN bk_list
答案 0 :(得分:7)
另一种实现方法,基于类CL_AUTH_OBJECTS_TO_SQL
(> = 7.50),此处程序从已获得授权的航空公司读取航班:
DATA(authsql) = cl_auth_objects_to_sql=>create_for_open_sql( ).
authsql->add_authorization_object( EXPORTING
iv_authorization_object = 'S_CARRID'
it_activities = VALUE #( ( auth_field = 'ACTVT' value = '03' ) )
it_field_mapping = VALUE #(
( auth_field = 'CARRID'
view_field = VALUE #( table_ddic_name = 'SFLIGHT' field_name = 'CARRID' ) ) ) ).
DATA(where) = authsql->get_sql_condition( ).
SELECT * FROM sflight INTO TABLE @data(sflights) WHERE (where).
答案 1 :(得分:4)
恐怕您只能一一做到。大概是:
SELECT bukrs
INTO TABLE @DATA(lt_t001)
FROM t001
WHERE ... . "Selection critera, if necessary
LOOP AT lt_t001
ASSIGNING FIELD-SYMBOL(<ls_t001>).
DATA(lv_tabix) = sy-tabix.
AUTHORITY-CHECK OBJECT 'F_BKPF_BUK'
ID 'BUKRS' FIELD <ls_t001>-bukrs
ID 'ACTVT' FIELD '03'. "Here you need the proper activity (display '03' /change '02' / etc.)
IF sy-subrc <> 0. "Auth check failed
DELETE lt_t001 INDEX lv_tabix.
ENDIF.
ENDLOOP.
最后lt_t001仅包含用户授权的公司代码。