Technology Blog Posts by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
910

Ever wondered how to set default values for the object page fields during Create Operation in Fiori using RAP at the projection level?

With an augmentation implementation you can add data or modify incoming requests on the projection layer before data reaches the transactional buffer. You can add data to a modify request or issue additional requests by augmenting the operation before the request is passed to the base business object.

Use case

• Defaulting for incoming requests. For example: Populate default values for fields of object page on create operation in Fiori

• Behavior-enabling denormalized fields, for example enabling editing of language dependent fields.

Definition

Augmentation is defined in the projection behavior definition on the relevant operation with the following syntax: 

define behavior for Entity [alias AliasedName]
  ..
{
  use create (augment);
  use update (augment); 

  use association AssocName { create (augment); }
  ...
}

Below steps will result you how to populate default values for the object page fields on create operation especially at project layer.  That means this default values population is specific to projection not for entire BO. 

  1. In your projection behavior ZC_TRAVEL_PROCESSOR_M_XX definition, define augmentation for the create operation.
use create (augment);

2. Add behavior implementation class to the project behavior.

…
define behavior for ZC_TRAVEL_PROCESSOR_M_XX alias Travel
implementation in class zcl_bp_c_travelm_xx
….​

3. Click the activation button or use the shortcut Ctrl + F3 to activate the behavior definition.

4. The ADT Quick Fix feature can be used to create implementation class for travel entity. 

For this, set the cursor on the class name, and press Ctrl+1 to star the Quick Fix dialog.

pavankumar_reddy90_0-1745219773658.png Click on create behavior implementation to create the class.

pavankumar_reddy90_1-1745221092360.png

Click Next and Finish to create the class. In Local Types of Class you will see a augmentation operation method created where you need to implement logic to populate default values.

5.In the method implementation paste the below code. 

METHOD augment_create.
  
   DATA: travel_create TYPE TABLE FOR CREATE zi_travel_m_xx.

    travel_create = CORRESPONDING #( entities ).
    LOOP AT travel_create ASSIGNING FIELD-SYMBOL(<travel>).
      <travel>-agency_id = '070012'.
      <travel>-status  = 'O'.
      <travel>-%control-agency_id = if_abap_behv=>mk-on.
      <travel>-%control-status = if_abap_behv=>mk-on.
    ENDLOOP.

    MODIFY AUGMENTING ENTITIES OF zi_travel_m_xx ENTITY Travel CREATE FROM travel_create.
  ENDMETHOD.

"MODIFY AUGMENTING ENTITIES"  is a EML statement with which you can modify entities of base business object. In the above example "ZI_TRAVEL_M_XX" is the base business object and "ZC_TRAVEL_PROCESSOR_M_XX" is the project business object.

6. Save and Activate the Class.

7.Test the app now using preview tool. On Click of Create Agency ID and Status fields are defaulted.

pavankumar_reddy90_2-1745221376616.pngpavankumar_reddy90_3-1745221416057.png

Same behavior can be achieved with determination with draft as well. But what is the difference ?

pavankumar_reddy90_0-1745223890753.png

Note: Only when draft is enabled in BO above feature can be achieved. 

 

 

Labels in this area