ABAP Blog Posts
cancel
Showing results for 
Search instead for 
Did you mean: 

Introduction:

When working with draft-enabled RAP applications, you may have noticed a special indicator called %is_draft.

This field is part of BDEF derived types and is used to indicate whether a RAP Business Object instance represents a draft instance or an active instance.

Most of the time, drafts are handled automatically by RAP when users interact with applications through the UI. However, when working with actions or EML, developers can explicitly control how instances are created using this indicator.

In this blog, we will explore what %is_draft represents and how it influences the creation of draft and active instances.

What Can %is_draft Do?

The %is_draft indicator allows us to control how a new instance should be created.

Depending on how it is populated, it can lead to the following scenarios:

  1. Creating a Draft instance from an Active instance

  2. Creating an Active instance from a Draft instance

  3. Creating a Draft instance from a Draft instance

Action Implementation:

Let us first look at the implementation of the action used to copy a Billing Document.

METHOD copyBillingDocument.

    DATA: lt_billingdocuments TYPE TABLE FOR CREATE zbrt_i_bill_header\zbrt_i_bill_header,
          lv_billingdoc       TYPE c LENGTH 10.

    " Get highest existing Billing Document ID
    SELECT FROM zbrt_i_bill_header
      FIELDS MAX( BillId )
      INTO @LV_billingdoc.

    " Generate next Billing Document ID
    lv_billingdoc = lv_billingdoc + 1.

    " Read source Billing Document(s) to copy
    READ ENTITIES OF zbrt_i_bill_header IN LOCAL MODE
      ENTITY zbrt_i_bill_header
      ALL FIELDS WITH CORRESPONDING #( keys )
      RESULT DATA(lt_billdoc).

    LOOP AT lt_billdoc ASSIGNING FIELD-SYMBOL().

      " Prepare data for new Billing Document
      APPEND VALUE #(
          %cid      = keys[ KEY entity %key = -%key ]-%cid
          %is_draft = keys[ KEY entity %key = -%key ]-%param-%is_draft
          %data     = CORRESPONDING #(  EXCEPT BillId )
        )
        TO lt_billingdocuments ASSIGNING FIELD-SYMBOL().

      " Adjust copied values
      -BillId   = CONV #( lv_billingdoc ).
      -BillDate = cl_abap_context_info=>get_system_date( ).

    ENDLOOP.

    " Create new Billing Document
    MODIFY ENTITIES OF zbrt_i_bill_header IN LOCAL MODE
      ENTITY zbrt_i_bill_header
      CREATE
        FIELDS ( BillId BillDate BillType Currency CustomerId NetAmount SalesOrg )
        WITH lt_billingdocuments
      MAPPED DATA(mapped_create).

    " Return mapped instances
    mapped-zbrt_i_bill_header = mapped_create-zbrt_i_bill_header.

ENDMETHOD.

 If you notice the following line in the implementation:

%is_draft = keys[ KEY entity %key = -%key ]-%param-%is_draft

Here we are forwarding the %is_draft value received as an action parameter while creating the new instance.
This indicator determines whether the instance created by the action will be a draft instance or an active instance.

To better understand this behavior, we can execute the action using EML.

Note: You can create a class implementing the interface if_oo_adt_classrun to test the EML execution.

Scenario 1: Create a Draft Instance from an Active Instance

To create a draft instance from an active instance, we pass the key of an active instance and set %param-%is_draft to true.

MODIFY ENTITIES OF zbrt_i_bill_header
  ENTITY zbrt_i_bill_header
    EXECUTE copyBillingDocument
      FROM VALUE #(
        (
          %cid = 'CID_COPY_001'
          %tky = VALUE #(
                   %key-BillId = '1000000004'
                 )
          %param-%is_draft = if_abap_behv=>mk-on
        )
      ).

In this case:

  • The source instance is an active instance

  • The %is_draft parameter is true

  • The newly created instance will be a draft instance

Scenario 2: Create an Active Instance from a Draft Instance

In this scenario, the source instance is a draft instance, but we request the newly created instance to be active.

MODIFY ENTITIES OF zbrt_i_bill_header
  ENTITY zbrt_i_bill_header
    EXECUTE copyBillingDocument
      FROM VALUE #(
        (
          %cid = 'CID_COPY_001'
          %tky = VALUE #(
                   %key-BillId = '1000000003'
                   %is_draft   = if_abap_behv=>mk-on
                 )
          %param-%is_draft = if_abap_behv=>mk-off
        )
      ).

Here:

  • The source instance is a draft instance

  • The %is_draft parameter is false

  • The newly created instance becomes an active instance

Scenario 3: Create a Draft Instance from a Draft Instance

In this scenario, both the source and target instances are draft instances.

MODIFY ENTITIES OF zbrt_i_bill_header
  ENTITY zbrt_i_bill_header
    EXECUTE copyBillingDocument
      FROM VALUE #(
        (
          %cid = 'CID_COPY_001'
          %tky = VALUE #(
                   %key-BillId = '1000000003'
                   %is_draft   = if_abap_behv=>mk-on
                 )
          %param-%is_draft = if_abap_behv=>mk-on
        )
      ).

In this case:

  • The source instance is a draft instance

  • The %is_draft parameter is true

  • The new instance will also be created as a draft instance

Conclusion

The %is_draft indicator gives developers explicit control over how RAP instances are created in draft-enabled applications.

By setting the correct value for %is_draft, we can decide whether the resulting instance should be created as a draft or active instance.

2 Comments
Atul_Joshi85
Active Contributor

Fantastic deep dive! This is one of the clearest explanations I’ve seen on how RAP handles Is Draft during instance creation. The step‑by‑step breakdown really helps demystify what’s happening behind the scenes, especially for developers who often struggle with draft behavior in more complex BO scenarios. Your examples make the lifecycle transitions easy to follow, and the emphasis on understanding the framework rather than just the syntax is spot‑on. Thanks for putting together such a practical and insightful walkthrough — this will definitely help many of us build more predictable and stable RAP applications.

Bikash_R
Participant

Thank you @Atul_Joshi85, for the thoughtful feedback. I’m glad you found the explanation clear and useful. I truly appreciate your kind words and support

Labels in this area