Application Development and Automation Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Megastar
Explorer
27,760

Introduction 

ABAP RESTful Application Programming Model (RAP) plays a vital role in developing cloud-         ready and on-premises applications. One of the unique features of RAP is the Draft Table, which   facilitates the concept of draft-enabled business objects, offering a more user-friendly and flexible   data handling approach during transactional processing.

In this blog, we’ll dive deep into what Draft Tables are in RAP ABAP, their importance, and how you can implement them in your RAP application. 

This blog is designed for beginners who want to learn and understand the topic from scratch. 

What is a Draft Table? 

A Draft Table in RAP ABAP allows you to temporarily save incomplete or intermediate user input during transactional processing. This draft data is stored separately from the final, persistent business data, ensuring that users can work on their changes incrementally without immediately committing them to the database. Users can retrieve, modify, and finalize their draft at a later time.

The draft feature is especially useful in complex business processes where users might not have all the necessary data at once or may need to pause their work and continue later. It adds a layer of flexibility by reducing the risk of incomplete or erroneous data being permanently saved. 

Benefits of Using Draft Tables 

  • User Experience: It allows users to work on partially filled forms or records and continue at their convenience, without the fear of losing unsaved changes.
  • Data Integrity: No intermediate or incomplete records are committed directly to the main database tables until the user explicitly saves the data.
  • Flexibility: With draft-enabled objects, users can discard drafts, resume them later, or even share them with other users for collaborative work.

    How Draft Tables Work in RAP ABAP 

    When implementing a business object in RAP, you can enable the draft functionality by defining a separate draft table alongside the root table of your business object. The system automatically manages the draft lifecycle and links it with the main entity. 

    Steps to Implement Draft Tables in RAP ABAP: 

    Step-01: 

    You need to mark your business object as draft-enabled in the behavior definition file. 

    arunkumarn1998_0-1727678791421.png

    After draft enabled, system will suggest that, activating persistent draft table.

    arunkumarn1998_1-1727678840024.png

    Step-02: 

    The draft table keyword specifies that your entity will have a draft table (ZTRAVEL_DRAFT) to handle draft data.

    arunkumarn1998_2-1727678882826.png

    Step-03: 

    Implementing Actions for Draft Handling: RAP automatically provides actions to handle drafts, but you can define custom actions if needed. Here’s a basic example: 

    • Resume: Resumes the draft to continue editing. 
    • Save: Finalizes the draft and saves it to the persistent table. 
    • Discard: Discards the draft and removes it from the draft table. arunkumarn1998_3-1727679053123.pngarunkumarn1998_4-1727679053123.pngarunkumarn1998_5-1727679053124.pngarunkumarn1998_6-1727679101490.png Step-04: 

      For locking the data, when concurrent users access the same data, only one user can edit the data, at the same time for other users can’t access the same data. For this reason, system will suggest defining the key TOTAL ETAG <field Name>

      arunkumarn1998_7-1727679151245.pngarunkumarn1998_8-1727679219718.png

       Step-05: 

      Create draft persistent table for both root entity (ZTRAVEL_DRAFT) and its association (ZBOOKING_DRAFT)

      arunkumarn1998_9-1727679262931.pngarunkumarn1998_10-1727679293465.png 

      Draft table for Root Entity (ZTRAVEL_DRAFT).

      arunkumarn1998_11-1727679331447.png

      Draft Table for child entity (ZBOOKING_DRAFT).

      arunkumarn1998_12-1727679364786.png

      If you have association to child entity, you should define with the with draft

      arunkumarn1998_13-1727679395582.pngarunkumarn1998_14-1727679416024.png

      Step-06: 

      Go to your Projection View, you need use the actions which are defined in the behavior definitions to expose to frontend.

      arunkumarn1998_15-1727679456611.png 

      By default, the system suggests using actions, whatever your defined actions in the behavior definitions.

      arunkumarn1998_16-1727679535220.pngarunkumarn1998_17-1727679535220.pngarunkumarn1998_18-1727679535221.pngarunkumarn1998_19-1727679535221.pngarunkumarn1998_20-1727679535222.png
       

       

      arunkumarn1998_22-1727679628084.pngarunkumarn1998_23-1727679662535.pngarunkumarn1998_24-1727679686937.pngarunkumarn1998_25-1727679711175.pngarunkumarn1998_26-1727679732389.png

       

      Step-07: 

      Go to Service Binding, select your root entity, click on preview. 

      You can see the bellow Draft is added.

      arunkumarn1998_27-1727679759171.png 

      The movement while you are filling the data, by default the system automatically store it in draft table.

      arunkumarn1998_28-1727679787388.png

      Go back and see the data persisted in the draft table. If you don’t want to persist the data, you can discard it by clicking on Discard Draft.

      arunkumarn1998_29-1727679818946.png

      Go to back to your eclipse and execute the draft table, you will find the persisted Draft data.

      arunkumarn1998_30-1727679848085.png 

      Conclusion 

      Draft tables in RAP ABAP provide a robust and flexible way to handle incomplete data in transactional applications. By enabling drafts, you give users more control over their input and ensure data integrity until finalization. Whether you're working with cloud-based or on-premises systems, leveraging draft tables is an excellent way to improve both the user experience and the quality of your data. 

      With the RAP model’s modern development framework, building draft-enabled applications is streamlined and efficient. By following the steps outlined in this blog, you can start implementing draft functionality in your RAP projects and empower your users with a seamless transactional experience.