cancel
Showing results for 
Search instead for 
Did you mean: 

Enabling CRUD Operations, Inline Buttons, and Popup Functionality using RAP ABAP

rgupta3
Explorer
0 Kudos

This is how the Output List Page looks like

rgupta3_1-1708102147802.png
Create : CRUD operations are enabled

rgupta3_2-1708102220408.png

rgupta3_3-1708102349519.png

Activate Popup: 

rgupta3_4-1708102419042.png

rgupta3_5-1708102462567.png

rgupta3_6-1708102488902.png

Deactivate:

rgupta3_7-1708102590412.pngrgupta3_8-1708102606594.png


Now Lets talk about how to achieve this:

Step 1:
Create a table in ADT

 

 

@EndUserText.label : 'Test table for value mapping'
@AbapCatalog.enhancement.category : #EXTENSIBLE_ANY
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #ALLOWED
define table ztestgupta04 {

  key mandt       : mandt not null;
  key domain_name : char50 not null;
  domain_values   : char50;

}

 

 

Step 2:
Create a view entity and abstract entity

 

 

@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'value mapping test'
@Metadata.allowExtensions: true
define root view entity ZVEI_TESTGUPTA as select from ztestgupta04
{
  key domain_name as DomainName,
  domain_values as DomainValues,
  active as Active,
  case active 
  when 'X' then 3
  when ' ' then 1
  else 0
  end as activecolor,
  cast('' as abap.char(10)) as action
}

 

 


Abstract entity :

 

 

@EndUserText.label: 'Approval Comment'
@VDM.usage.type: [#ACTION_PARAMETER_STRUCTURE]
define abstract entity TESTD_Approvalcomment{
@UI.multiLineText: true
  Domain_Value : abap.char(30);
}

 

 

Step 3:
Create the Meta data file for the View entity.

 

 

@Metadata.layer: #CORE
@UI: {
 headerInfo: {
    typeName: 'Value Mapping',
    typeNamePlural: 'Value Mappings',
    title: {
        type: #STANDARD, value: 'DomainName'
    }
 }
}

annotate view ZVEI_TESTGUPTA with
{
  @UI.facet: [ { id:              'Valuemapping',
                 purpose:         #STANDARD,
                 type:            #IDENTIFICATION_REFERENCE,
                 label:           'Value Mapping',
                 position:        5 }
                ]
  @UI.selectionField: [{ position : 10  }]
  @UI.lineItem: [{label: 'Domain Name', position : 10 }]
  @Consumption.valueHelpDefinition: [{ entity: { name: 'ZVEI_TESTGUPTA', element: 'DomainName'}}]
  @UI.identification: [{ position : 10 }]
  DomainName;
  @UI.selectionField: [{ position : 20  }]
  @UI.lineItem: [{label: 'Domain Values', position : 20 }]
  @UI.identification: [{ position : 20 }]
  @Consumption.valueHelpDefinition: [{ entity: { name: 'ZVEI_TESTGUPTA', element: 'DomainValues'}}]
  DomainValues;
  @UI.selectionField: [{ position : 30  }]
  @UI: { lineItem: [{ position: 30, label: 'Status', criticality: 'activecolor'} ] }
  @Consumption.valueHelpDefinition: [{ entity: { name: 'ZVEI_TESTGUPTA', element: 'Active'}}]
  @UI.identification: [{ position : 30 }]
  Active;
  @UI.dataPoint.criticality: 'activecolor'
  @UI.lineItem: [{ position: 40, label: 'Status', criticality: 'activecolor', valueQualifier: 'FieldAction', type: #AS_FIELDGROUP } ] 
  @UI.fieldGroup: [ { criticality: 'activecolor',
                      criticalityRepresentation: #WITHOUT_ICON, 
                      type: #FOR_ACTION, dataAction: 'activate' ,  label: 'Activate', inline: true, qualifier: 'FieldAction' },
        {  type: #FOR_ACTION, dataAction: 'deactivate' ,  label: 'Deactivate', inline : true, qualifier: 'FieldAction' }]

  action;
}

 

 

Step 4:
Create the Behaviour definition for the view entity. (Make sure your view entity is root view entity)

 

 

managed implementation in class zcl_valuemapping unique;
//strict ( 2 );

define behavior for ZVEI_TESTGUPTA alias Valuemapping
implementation in class zcl_valuemapping unique
persistent table ztestgupta04
lock master
//authorization master ( instance )
//etag master <field_name>
{
  create;
  update;
  delete;
  field ( readonly : update ) DomainName;
  action ( features : instance ) activate parameter TESTD_Approvalcomment result [1] $self; //TESTD_Approvalcomment
  action ( features : instance ) deactivate result [1] $self; // parameter TESTD_Approvalcomment ;


    mapping for ztestgupta04
    {
    DomainName = domain_name;
    DomainValues = domain_values;
    active = active;
    }
}

 

 


Step 4:
Using the suggestions create the Class and in the local types of class add the below logic.

 

 

CLASS lhc_valuemapping DEFINITION INHERITING FROM cl_abap_behavior_handler.
  PRIVATE SECTION.
    METHODS get_features FOR FEATURES
      IMPORTING keys REQUEST requested_features FOR ValueMapping RESULT result.
    METHODS activate FOR MODIFY
      IMPORTING keys FOR ACTION Valuemapping~activate RESULT result.
    METHODS deactivate FOR MODIFY
      IMPORTING keys FOR ACTION Valuemapping~deactivate RESULT result.
ENDCLASS.

CLASS lhc_valuemapping IMPLEMENTATION.

  METHOD get_features.

    READ ENTITIES OF zvei_testgupta IN LOCAL MODE
      ENTITY Valuemapping
        FIELDS ( active ) WITH CORRESPONDING #( keys )
      RESULT DATA(valueMappings)
      FAILED failed.

  result =
      VALUE #(
        FOR valueMapping IN valueMappings
          LET is_active =       COND #( WHEN valueMapping-Active = abap_true "abap_true
                                    THEN if_abap_behv=>fc-o-disabled
                                    ELSE if_abap_behv=>fc-o-enabled )
              is_deactive =   COND #( WHEN valueMapping-Active = abap_false
                                    THEN if_abap_behv=>fc-o-disabled
                                      ELSE if_abap_behv=>fc-o-enabled )
          IN
            ( %tky                 = valuemapping-%tky
              %action-activate = is_active
              %action-deactivate = is_deactive
             ) ).


  ENDMETHOD.

  METHOD activate.

    MODIFY ENTITIES OF zvei_testgupta IN LOCAL MODE
      ENTITY Valuemapping
         UPDATE
           FIELDS ( Active  DomainValues )
           WITH VALUE #( FOR key IN keys
                           ( %tky         = key-%tky
                             Active = abap_true
                             DomainValues = Key-%param-Domain_Value ) )
*
      FAILED failed
      REPORTED reported.

    " Fill the response table
    READ ENTITIES OF zvei_testgupta IN LOCAL MODE
      ENTITY Valuemapping
        ALL FIELDS WITH CORRESPONDING #( keys )
      RESULT DATA(Valuemappings).

    result = VALUE #( FOR Valuemapping IN Valuemappings
                        ( %tky   = Valuemapping-%tky
                          %param = Valuemapping ) ).
  ENDMETHOD.

  METHOD deactivate.

  MODIFY ENTITIES OF zvei_testgupta IN LOCAL MODE
      ENTITY Valuemapping
         UPDATE
           FIELDS ( Active )
           WITH VALUE #( FOR key IN keys
                           ( %tky         = key-%tky
                             Active = abap_false ) )
      FAILED failed
      REPORTED reported.

    " Fill the response table
    READ ENTITIES OF zvei_testgupta IN LOCAL MODE
      ENTITY Valuemapping
        ALL FIELDS WITH CORRESPONDING #( keys )
      RESULT DATA(Valuemappings).

    result = VALUE #( FOR Valuemapping IN Valuemappings
                        ( %tky   = Valuemapping-%tky
                          %param = Valuemapping ) ).

  ENDMETHOD.

ENDCLASS.

 

 

Step 5:
Create the Service definition and Service Binding.
Service definition:

 

 

@EndUserText.label: 'Service Definiton'
define service TESTSD {
  expose ZVEI_TESTGUPTA;
}

 

 

rgupta3_15-1708103676432.png

Now Preview. 

Let me know if you still face issues. 

This is my first blog so also let me know if you have any suggestions for me.








 




 

Accepted Solutions (0)

Answers (0)