Post

Default Function RAP

Learn how to use a default function in ABAP RAP to automatically pre-fill field values when a new record is created.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"Step 1: Define a default function in your Behavior Definition (BDEF)
define behavior for ZR_ROOT_ENTITY alias Travel
....
{
  ...
  create{ default function GetDefaultsForCreate; }
  
}

"Step 2: Implement the logic in the behavior class
METHOD GetDefaultsForCreate.
    result = VALUE #( FOR key IN keys (
          %cid = key-%cid
          %param = VALUE #( CurrencyCode = 'INR'
                            BeginDate = cl_abap_context_info=>get_system_date( )
                            OverallStatus = 'O' ) ) ).
ENDMETHOD.

"Step 3: Use the function in your Projection BDEF(If you defined)
projection;
strict(2);

define behavior for ZC_ROOT_ENTITY alias Travel
...
{
  ...
  use function GetDefaultsForCreate;
}

"Step 4: That’s it! Now when you try to create a new record, the values will be pre-filled automatically 
This post is licensed under CC BY 4.0 by the author.