Get Example source ABAP code based on a different SAP table
Using the Addition PRIVILEGED> with an ABAP_EML Statement This example demonstrates ABAP_EML MODIFY> statements executing an action> with and without the addition PRIVILEGED> using a managed RAP BO>. Data model> The CDS data model consists of the root entity DEMO_MANAGED_PRIVILEGED>. DDLS DEMO_MANAGED_PRIVILEGED Behavior definition> The RAP behavior definition> DEMO_MANAGED_PRIVILEGED>> is defined in RAP BDL> as follows: BDEF DEMO_MANAGED_PRIVILEGED Behavior implementation> For the above RAP behavior definition, there is an ABAP behavior pool (ABP)> available. The global class of the behavior pool is BP_DEMO_MANAGED_PRIVILEGED>>. This global class implements the local handler class LHC_DEMO_MANAGED_PRIVILEGED>. The actual implementation takes place in the BP_DEMO_MANAGED_PRIVILEGED====CCIMP>> . The following method is relevant for the example:
check_privileged> First, the privileged mode is checked. The privileged mode can be queried by the RAP BO provider> using the method GET_CURRENT_CONTEXT> of the class CL_ABAP_BEHV_AUX>>. If the privileged mode is active, a flag is set appropriately. For demonstration purposes in this implementation, the flag for the privileged mode is stored in a variable of the global class of the behavior pool so that the RAP BO consumer> (another class or program) can access it. As a next step, an authority check for demonstrating the privileged mode is carried out using the statement AUTHORITY-CHECK OBJECT>>. Like the flag for the privileged mode, the value of sy-subrc> is stored in a variable in the global class. After the check, a loop is run across the imported key fields. In this implementation, only the RAP response parameters are manually filled ( failed> and reported>). In case the authorization is not granted, both failed> and reported> are filled. In the other case, only the reported> structure is filled with a success message.
ABAP_SOURCE_CODE DEMO CL_DEMO_RAP_EML_PRIVILEGED
ABAP_DESCRIPTION The source code above uses EML> to access the RAP business object from an ABAP class. There are two ABAP_EML modify requests: ABAP_EML modify request without using the addition PRIVILEGED> The action check_privileged> is executed based on two key fields. The output includes the sy-subrc> value that is set when calling the method and carrying out the authority check. Here, it shows the value 12> indicating that the authorization has not been granted. It also shows a phrase indicating whether the privileged mode is active or not based on a flag that has been set during the method call. For the modify request, the response parameters for failed> and reported> are filled and are output too. In this case, they include all instances for which the authorization has not been granted and a failure message. ABAP_EML modify request with using the addition PRIVILEGED> Same as above, the action check_privileged> is executed based on two key fields. The output demonstrates the effect of the addition PRIVILEGED> that circumvents authority checks. Here, the sy-subrc> value is 0> indicating that the authorization has been granted. For this request, only the response parameter for reported> is filled with a success message.