ABAP - Keyword Documentation → ABAP RAP Business Objects → RAP - Behavior Definitions → RAP - BDL for Behavior Definitions → RAP - Managed and Unmanaged Behavior Definitions → RAP - EntityBehaviorDefinition → RAP - EntityBehaviorCharacteristics → RAP - draft table → 

    RAP - query

    Syntax


    ... query DraftQueryView

    Description


    Defines a draft query view DraftQueryView for a RAP draft table. query is an optional addition that can be specified directly after the RAP draft table draft table DraftTableName.

    The draft query view DraftQueryView must be a CDS view entity or a CDS DDIC-based view (obsolete) that specifies the RAP draft table as data source after FROM. It must contain all fields from the draft table including administrative fields. Otherwise, a syntax check warning occurs.

    A draft query view can be used to define read access limitations to the draft data using data control language (DCL). The DCL access restrictions defined for the CDS view entities selecting from the active database table are not applied to the draft data. A draft query view allows the definition of read access restrictions for draft data.

    Availability


    Hint

    A draft query view is a prerequisite for classifying a RAP BO with the C0 contract for extensibility in the context of RAP extensibility. For further details, see the topic C0 Contract Rules for Providers of RAP Behavior Definitions.

    Further Information


    Development guide for the ABAP RESTful Application Programming Model, topic Draft Query Views.

    Example


    The following example shows a managed and draft-enabled RAP BO.

    • It is based on the CDS view entity DEMO_RAP_MANAGED_DRAFT_QUERY. This CDS view entity has read access restrictions defined in the DCL source DEMO_RAP_DRAFT_QUERY.
    • It specifies the CDS view entity DEMO_RAP_DRAFT_QUERY_VIEW as draft query view. This draft query view has read access restrictions defined in the DCL source DEMO_RAP_DCL_DRAFT.

    Note: This example is intentionally kept short and simple and serves demonstration purposes only. The RAP handler methods are not implemented in the ABAP behavior pool here.

    managed implementation in class bp_demo_rap_managed_draft_quer unique;
    strict ( 2 );
    with draft;

    define behavior for DEMO_RAP_MANAGED_DRAFT_QUERY alias RootEntity
    persistent table demo_dbtab_root
    draft table demo_dbtab_draft query DEMO_RAP_DRAFT_QUERY_VIEW
    lock master
    total etag Timestamp
    authorization master ( global )

    {
      create;
      update;
      delete;

      field ( readonly : update ) KeyFieldRoot;
      field ( readonly ) Timestamp;

      draft action Activate optimized;
      draft action Discard;
      draft action Edit;
      draft action Resume;
      draft determine action Prepare;
      mapping for demo_dbtab_root
        {
          KeyFieldRoot  = key_field;
          DataFieldRoot = data_field;
          CharFieldRoot = char_field;
          Timestamp     = crea_date_time;
          LastChangedAt = lchg_date_time;
        }

    }

    The class CL_DEMO_RAP_DRAFT_QUERY_VIEW accesses the business object using EML and ABAP SQL and performs the following operations:

    • It creates four active entity instances using the EML statement MODIFY ENTITIES CREATE.
    • It reads these active instances, first with the EML statement READ ENTITIES, and afterwards with ABAP SQL SELECT. In the EML read, the DCL access condition is applied and the result set is filtered according to the access condition. Some data sets are filtered out. By contrast, the ABAP SQL SELECT displays all instances that were saved on the database.
    • It creates four draft instances using the EML statement MODIFY ENTITIES CREATE.
    • It reads these draft instances, first with the EML statement READ ENTITIES, and afterwards with ABAP SQL SELECT. In the EML read, the DCL access condition attached to the draft query view is applied and the result set is filtered according to the access condition. Some data sets are filtered out. By contrast, the ABAP SQL SELECT displays all instances that were saved in the RAP draft table.
    • Finally, the RAP draft table is cleared using the draft action Discard.

    Executable Example


    The example above is explained in detail in the executable example RAP BDL - RAP BO with DCL Access Control.

    Continue