Symptom
Getting syntax error: Executing "Unprivileged SQL" from "MODIFY_FIELDS" violates transactional contract "FUNCTIONAL" in custom logic with the following syntax:
SELECT i_productsalesdelivery~product, productname
FROM i_productsalesdelivery WITH PRIVILEDGED ACCESS
INNER JOIN i_producttext ON i_productsalesdelivery~product = i_producttext~product
FOR ALL ENTRIES IN @delivery_document_items_out
WHERE i_productsalesdelivery~product EQ @delivery_document_item_out-material
AND productsalesorg EQ @delivery_document_item_in-salesorganization
INTO TABLE @DATA(lt_data).
Environment
SAP S/4HANA Cloud
Resolution
From the ABAP Keyword Documentation:
- ABAP - Keyword Documentation - SELECT, FROM data_source
- ABAP - Keyword Documentation - SELECT, PRIVILEGED ACCESS
In the given code section the WITH PRIVILEGED ACCESS is part of the FROM clause and only affects that one CDS Entity in the FROM clause (i_productsalesdelivery). The CDS Entity i_producttext in the INNER JOIN clause is not affected by the WITH PRIVILEGED ACCESS addition.
This is in contrast to the PRIVILEGED ACCESS addition which can be specified at the end of the whole SELECT statement and will affect every CDS Entity and Database Table in the statement.
E.g.
SELECT i_productsalesdelivery~product, productname
FROM i_productsalesdelivery
INNER JOIN i_producttext ON i_productsalesdelivery~product = i_producttext~product
FOR ALL ENTRIES IN @delivery_document_items_out
WHERE i_productsalesdelivery~product EQ @delivery_document_item_out-material
AND productsalesorg EQ @delivery_document_item_in-salesorganization
INTO TABLE @DATA(lt_data)
PRIVILEGED ACCESS.
See Also
ABAP - Keyword Documentation - SELECT, FROM data_source
ABAP - Keyword Documentation - SELECT, PRIVILEGED ACCESS
3398420 - SELECT statement WITH PRIVILEGED ACCESS cannot be specified together with a path expression - SAP S/4HANA Cloud
Keywords
"Unprivileged SQL" from "MODIFY_FIELDS" violates transactional contract "FUNCTIONAL", WITH PRIVILEDGED ACCESS, PRIVILEGED ACCESS, custom logic, SELECT, INNER JOIN , KBA , BC-SRV-APS-EXT-BL , Custom Business Logic , Problem