RAP - Action Popup: Dynamic Field Control Using Abstract Entity & Annotations

Hello Everyone! 👋

RAP Action Popup: Dynamic Field Control Using Abstract Entity & Annotations

⚠️ Note: Applicable only to SAP Fiori elements for OData V4. The behavior may vary depending on the SAP UI5 version. Observed working in SAP S/4HANA 2023+ (SAP UI5 1.120+).

Step 1: Define the Action in Metadata Extension / Projection View

annotate view ZC_RootEntity with {
  @UI: { 
    lineItem: [ 
      { 
        position: 10, 
        type: #FOR_ACTION, 
        dataAction: 'ActionWithPopup', 
        label: 'Action With Popup' 
      }  
    ]  
  } 
  FieldName;
}
  

Step 2: Create an Abstract Entity (Popup)

@EndUserText.label: 'Action with Popup'
define abstract entity ZD_ActionWithPopup {

  @Consumption.valueHelpDefinition: [
    { entity: { name: 'ZI_ActionPropBehvValue', element: 'Behaviour' } }
  ]
  @EndUserText.label: 'Behaviour'
  Behaviour : abap.char( 1 );
  
  @EndUserText.label: 'Field 1'
  Field : abap.char( 10 );

  // Used as a comparison value (instead of hardcoding in XML)
  @UI.hidden: true
  @UI.defaultValue: 'M'
  mandatoryDefaultValue : abap.char( 1 );
}
  

Step 3: Expose the Action in Behavior Definition (BDEF)

define behavior for ZR_RootEntity alias RootEntity
...
{
  action ActionWithPopup parameter ZD_ActionWithPopup result [0..1] $self;
}
  

Step 4: Expose the Action in Projection BDEF

define behavior for ZC_RootEntity alias RootEntity
...
{
  use action ActionWithPopup;
}
  

Step 5: Create Service Definition & Binding

Create a Service Definition to expose the entity. Then create a Service Binding (OData V4) to make it available for UI consumption.

Step 6: Add Dynamic UI Logic in Annotations.xml

Create a new Fiori application using Fiori App Generator in VS Code or BAS. Then navigate to the annotations file:

project_name/webapp/annotations/annotation.xml

<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="local">
    <Annotations Target="SAP__self.ActionWithPopup/Field">
        <Annotation Term="Common.FieldControl">
            <If>
                <Eq>
                    <Path>Behaviour</Path>
                    <String>R</String>
                </Eq>
                <EnumMember>Common.FieldControlType/ReadOnly</EnumMember>
                <If>
                    <Eq>
                        <Path>Behaviour</Path>
                        <Path>mandatoryDefaultValue</Path>
                    </Eq>
                    <EnumMember>Common.FieldControlType/Mandatory</EnumMember>
                    <EnumMember>Common.FieldControlType/Optional</EnumMember>
                </If>
            </If>
        </Annotation>

        <Annotation Term="UI.Hidden">
            <If>
                <Eq>
                    <Path>Behaviour</Path>
                    <String>H</String>
                </Eq>
                <Bool>true</Bool>
                <Bool>false</Bool>
            </If>
        </Annotation>
    </Annotations>
</Schema>
  

🎥 Demo: Dynamic Field Control Using Abstract Entity & Annotations

🔗 References

Comments

Popular posts from this blog

Fiori URL Generation and Navigation Using CL_LSAPI_MANAGER

RAP - Real Time UI Updates Using Event-Driven Side Effects

ABAP - Create CSV Files Easily Using CL_CSV_FACTORY