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: 
2,089

How to enable Multi-Input Field on the Object Page using RAP?

Lets take a example of Procurement Project Business Object. In the BO there is a field "Company Code" for which multi-input needs to enabled in object page. 

pavankumar_reddy90_0-1745925601110.png

pavankumar_reddy90_1-1745952492661.png

Below are the steps to enable above functionality using RAP:

1. Create a custom table with fields "company code" (here companycode is the field of root entity project ) and "procurementprojectuuid" ( here project uuid is the key field of root entity  project)

@EndUserText.label : 'Procurement Project Company Code'
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table zprocproj_cc {
  key client             : abap.clnt not null;
  key companycode        : bukrs not null;
  procurementprojectuuid : vdm_procurementprojectuuid;

}

2. Create a Interface view for custom table create at step 1.

@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Company COde'
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{
    serviceQuality: #X,
    sizeCategory: #S,
    dataClass: #MIXED
}
define view entity ZI_Company_Code_XX
  as select from zprocproj_cc
  association to parent ZI_PROC_PROJ_XX as _procproj on $projection.procurementprojectuuid = _procproj.Procurementprojectuuid
{
  key companycode,
      procurementprojectuuid,
      _procproj



}

Here "ZI_Company_Code_XX" is the Interface View for CompanyCode custom table and "ZI_PROC_PROJ_XX" is the Root Interface View for Procurement Project BO.

You can also find association to parent relationship from companycode Interface view to root view procurement project.

3. Create 1:N composition relation from root entity to company code interface view which is created in step 2

@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Procument Project Interface View'
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{
    serviceQuality: #X,
    sizeCategory: #S,
    dataClass: #MIXED
}
define root view entity ZI_PROC_PROJ_XX
  as select from mmprocmtproj
  composition [0..*] of zi_proc_plant_xx as _plant
  composition [0..*] of ZI_Company_Code_XX as _CompanyCode
{
  key procurementprojectuuid       as Procurementprojectuuid,
      procurementproject           as Procurementproject,
      procurementprojectname       as Procurementprojectname,
      externalprojectreference     as Externalprojectreference,
      companycode                  as Companycode,
      @Semantics.user.createdBy: true
      createdbyuser                as Createdbyuser,
      @Semantics.user.lastChangedBy: true
      lastchangedbyuser            as Lastchangedbyuser,
      @Semantics.systemDateTime.createdAt: true
      creationdatetime             as Creationdatetime,
      @Semantics.systemDateTime.lastChangedAt: true
      lastchangedatetime           as Lastchangedatetime,
      procurementprojectactvtnsts  as Procurementprojectactvtnsts,
      procmtplanningsubprojectuuid as Procmtplanningsubprojectuuid,
      sourcingorigin               as Sourcingorigin,
      sourcingscenario             as Sourcingscenario,
      iseopblocked                 as Iseopblocked,

      _plant,
      _CompanyCode

}

Here root entity is ZI_PROC_PROJ_XX and it has 1:N composition relationship to child entity ZI_Company_Code_XX.

Make sure you activate ZI_PROC_PROJ_XX and ZI_Company_Code_XX together when you form the business object relationship.

4. Enhance  ZI_Company_Code_XX behavior in base BO ZI_PROC_PROJ_XX

managed implementation in class zbp_i_proc_proj_xx unique;
strict ( 2 );
with draft;

define behavior for ZI_PROC_PROJ_XX alias Project
persistent table mmprocmtproj
draft table zprocproj_dxx
lock master
total etag Lastchangedatetime
authorization master ( instance, global )
etag master Lastchangedatetime
with additional save
early numbering
{

  create;
  update;
  delete ( features : global );

  draft action Edit;
  draft action Discard;
  draft action Resume;
  draft action Activate;
  draft determine action Prepare
  {

    validation validate_companycode;
  }



  //field ( numbering : managed ) Procurementprojectuuid;


  //  field ( mandatory ) Companycode;
  field ( readonly : update ) Externalprojectreference;
  field ( readonly ) Sourcingscenario;
  //field ( mandatory : create, readonly : update ) Procurementproject;  //V4

  field ( features : instance ) Procurementproject;

  association _plant { create; with draft; }
  association _CompanyCode { create; with draft; }

  action ( features : instance ) setactive parameter zabstract_project_xx result [1] $self;


  validation validate_companycode on save { field Companycode; }

  determination set_status on modify { create; }

  determination set_project_key on save { create; }

  mapping for mmprocmtproj corresponding
  {
    Lastchangedatetime = lastchangedatetime;
  }
}

define behavior for zi_proc_plant_xx alias Plant
//persistent table mmpprojplant
draft table zprocplantd_xx
lock dependent by _project
authorization dependent by _project
//etag master <field_name>
with unmanaged save
{
  update;
  delete;

  field ( numbering : managed ) procmtprojectplantuuid;
  field ( readonly ) Procurementprojectuuid;
  association _project { with draft; }
}

define behavior for ZI_Company_Code_XX alias CompanyCode
persistent table zprocproj_cc
draft table zprocproj_ccd
lock dependent by _procproj
authorization dependent by _procproj
{
  update;
  delete;
  field ( readonly ) Procurementprojectuuid;

  association _procproj { with draft; }
}

 What additions are added in the above behavior:

1. define behavior for ZI_Company_Code_XX

2. association _CompanyCode { create; with draft; } in root behavior ZI_PROC_PROJ_XX

3. draft table zprocproj_ccd created using quick fix.

 

5. Create a projection view ZC_PROC_CC_XX for interface view ZI_Company_Code_XX  created in step 2

@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Procement Project CC Projection View'
@Metadata.ignorePropagatedAnnotations: true
define view entity ZC_PROC_CC_XX as projection on ZI_Company_Code_XX
{
    key companycode,
    procurementprojectuuid,
    /* Associations */
    _procproj : redirected to parent ZC_PROC_PROJ_XX
    
}

Here "_procproj : redirected to parent ZC_PROC_PROJ_XX" relation is formed to root projection entity ZC_PROC_PROJ_XX

6. Create a relation from root project projection view ZC_PROC_PROJ_XX to  company code project view zc_proc_cc_xx.

_CompanyCode : redirected to composition child zc_proc_cc_xx,

Make sure you activate ZC_PROC_PROJ_XX and zc_proc_cc_xx together when you form the business object relationship.


7.  Enhance projection Company code behavior ZC_PROC_CC_XX in projection

projection;
strict ( 2 );
use draft;
define behavior for ZC_PROC_PROJ_XX //alias <alias_name>
implementation in class zcl_proc_proj_c_xx unique
use etag
{
  use create ( augment, precheck );
  use update;
  use delete;


  use action Edit;
  use action Resume;
  use action Activate;
  use action Prepare;
  use action Discard;

  use action setactive;

  use association _plant { create; with draft; }
  use association _CompanyCode { create; with draft; }
}

define behavior for ZC_PROC_PLANT_XX //alias <alias_name>
{
  use update;
  use delete;

  use association _project { with draft; }
}

define behavior for ZC_PROC_CC_XX
{
  use update;
  use delete;
  use association _procproj { with draft; }

}

What additions are added in the above behavior:

1. define behavior for ZC_PROC_CC_XX

2. use association _CompanyCode { create; with draft; } in root behavior ZC_PROC_PROJ_XX

 

8. Expose company code projection view ZC_PROC_CC_XX service definition.

@EndUserText.label: 'Service Binding for Procurement Project'
define service ZSD_PROC_PROJ_XX {
  expose ZC_PROC_PROJ_XX as ProcurementProject;
  expose ZC_PROC_PLANT_XX as ProcurementPlant;
  expose ZC_PROC_CC_XX as ProcurementCC;
}

Here  "expose ZC_PROC_CC_XX as ProcurementCC;" added.

9. Enhance the metadata extension of root view ZC_PROC_PROJ_XX 

  : { lineItem:       [ { position: 70, importance: #HIGH, value: '_CompanyCode.companycode' }
                 ] }
  .identification: [{ position: 70, importance: #HIGH, value: '_CompanyCode.companycode' }]
  _CompanyCode;

Here association _CompanyCode; is exposed in metadata extension and value property '_CompanyCode.companycode'  is added to @ui.linetem and @ui.identification annotation.

10. Now preview the UI.

Now multi-input is enabled for company code field in Object page.

pavankumar_reddy90_0-1745951665376.png

On save in display mode it appears like below:

pavankumar_reddy90_1-1745951839802.png

In list page field it displays like below:

pavankumar_reddy90_2-1745951925181.png

 

 

 

2 Comments