ABAP - Keyword Documentation → ABAP RAP Business Objects → RAP - Behavior Definitions → RAP - BDL for Behavior Definitions → RAP - Managed and Unmanaged Behavior Definitions → RAP - EntityBehaviorDefinition → RAP - EntityBehaviorBody → RAP - RAP BO Operations → RAP - RAP BO Operation, Additions → 

    RAP - feature control

    Syntax


    ... (features:instance)
      | (features:global) ...

    Description


    Defines feature control for a RAP BO operation. With feature control, operations can be enabled or disabled.

    There are two variants available:

    • Instance feature control
    • Global feature control

    If an operation is disabled by means of instance feature control, it is grayed out on the user interface of an OData application. If an external RAP BO consumer tries to execute a disabled operation with EML, the operation fails and an entry is returned in the failed structure.

    Hints

    Further Information


    • Development guide for the ABAP RESTful Application Programming Model, section Feature Control.

    Variant 1


    ... features:instance

    Description


    Instance feature control enables or disables operations depending on the state of the BO entity instance. Instance feature control can be defined for the following operations:

    Example


    The following example shows a managed BDEF that defines dynamic feature control for the standard operation update.

    managed implementation in class bp_demo_rap_operation_fc unique;
    strict(2);

    define behavior for DEMO_RAP_OPERATION_FC
    persistent table demo_dbtab_field
    lock master
    authorization master (global)
    {
      create;
      update ( features : instance );
      delete;
      field(readonly:update) key_field;
    }

    In the ABAP behavior pool, the following is specified: if field int_field1 > 50, then the update operation is disabled.

    METHOD get_instance_features. 
      READ ENTITIES OF demo_rap_operation_fc IN LOCAL MODE
      ENTITY demo_rap_operation_fc
            FIELDS (  int_field1 int_field2 )
              WITH CORRESPONDING #( keys )
                RESULT DATA(lt_result)
                FAILED failed.
     
      LOOP AT lt_result INTO DATA(ls_so).
     
        result = VALUE #( FOR ls_result IN lt_result
                 ( %key = ls_result-%key
                   %features-%update = COND #(
                                       WHEN ls_so-int_field1 > 50
                                       THEN if_abap_behv=>fc-o-disabled
                                       ELSE if_abap_behv=>fc-o-enabled
                                       ) ) ).
      ENDLOOP.
    ENDMETHOD.

    For the complete implementation, see BP_DEMO_RAP_OPERATION_FC======CCIMP

    The ABAP class CL_DEMO_RAP_FC_OPERATION uses EML to access the RAP business object.

    • First, it inserts two entity instances directly onto the database using ABAP SQL INSERT:
      • One of them has the value '1' for field int_field1.
      • The second one has value '55' for field int_field1. Therefore, it fulfills the condition that triggers feature control: for this instance, the update operation is disabled.
    • An EML UPDATE operation is executed on both instances, which updates field int_field2.
    • Using the ABAP SQL SELECT statement, the content of the underlying database table is displayed.

    Result: the first entity instance is updated successfully. For the second entity instance, the update operation fails and an entry is returned in the failed structure. The update was prevented by the dynamic feature control runtime check.

    figure

    Variant 2


    ... features:global

    Description


    Global feature control enables or disables operations depending on the state of an entity instance. Global feature control can be defined for the following operations:

    Example


    The following example shows an unmanaged BDEF that defines global feature control for the standard operation delete.

    unmanaged implementation in class bp_demo_rap_unmanaged_fc unique;
    strict(2);

    define behavior for DEMO_RAP_UNMANAGED_FC
    lock master
    authorization master ( instance )
    {
      create;
      update;
      delete ( features : global );
      field ( readonly:update ) key_field;
    }

    In the ABAP behavior pool, the following is specified: delete operations are allowed only in the time period between 10 pm and 6 am.

    METHOD get_global_features. 
      DATA(time1) = CONV t( '060000' ).
      DATA(time2) = CONV t( '220000' ).
     
      result = VALUE #( %delete = COND #(
                  WHEN cl_demo_date_time=>get_system_time( )
                    BETWEEN time1 AND time2
                  THEN if_abap_behv=>fc-o-disabled
                  ELSE if_abap_behv=>fc-o-enabled )
                      ).
     
      IF result-%delete = if_abap_behv=>fc-o-disabled.
        APPEND VALUE #( %msg  = new_message_with_text(
              text     = 'Delete is only allowed between 10 pm and 6 am.'
              severity = if_abap_behv_message=>severity-error )
              %global = if_abap_behv=>mk-on )
              TO reported-demo_rap_unmanaged_fc.
      ENDIF.
    ENDMETHOD.

    For the complete implementation, see BP_DEMO_RAP_UNMANAGED_FC======CCIMP

    The ABAP class CL_DEMO_RAP_UNMANAGED_FC uses EML to access the RAP business object.

    • Three entity instances are created.
    • An attempt is made to delete one of the entity instances.
      • In the time period between 10 pm and 6 am (night shift), the delete operation is successful.
      • In the time period between 6 am and 10 pm (day shift), the delete operation is disabled and an error message is returned.

    Result: In this example, the delete operation is not allowed and an error message is returned.

    figure