
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.
• 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.
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.
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.
Click on create behavior implementation to create the class.
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.
Same behavior can be achieved with determination with draft as well. But what is the difference ?
Note: Only when draft is enabled in BO above feature can be achieved.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
10 | |
8 | |
7 | |
5 | |
5 | |
4 | |
3 | |
3 | |
3 | |
2 |