Technology Blog Posts by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
527
  1. Create a table what you want to do CRUD operations, or you can use any table of your choice

BharathKumarVaddepalli_0-1750685661677.png

@EndUserText.label : 'product table'
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table zvb_product {
  key client     : abap.clnt not null;
  key product_id : abap.int4 not null;
  name           : abap.string(256);
  category       : abap.char(40);
  price          : abap.int4;
  currency       : abap.cuky;
  discount       : abap.int4;
}

2. Create a root interface view entity for the table You are going to do CRUD Operations.

BharathKumarVaddepalli_1-1750685661691.png

 

 

 

@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Interface View for Product'
@Metadata.ignorePropagatedAnnotations: true
define root view entity ZI_VBPRODUCT as select from zvb_product
{
  key product_id as Product_id,
  name as Name,
  category as Category,
  price as Price,
  currency as Currency,
  discount as Discount
}

3.   Create a projection view for the view entity created in step 2. And allow metadata extension annotation to be true.

BharathKumarVaddepalli_2-1750685661703.png

@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Consumption View product entity'
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{
    serviceQuality: #X,
    sizeCategory: #S,
    dataClass: #MIXED
}
@Search.searchable: true
@Metadata.allowExtensions: true
define root view entity ZI_VBPRODUCT_ENTITY
as projection on ZI_VBPRODUCT as product
{
   @Consumption.valueHelpDefinition: [
   { entity: {
               name: '/DMO/I_Customer',
               element: 'CustomerID'
       } }
   ]
@Search.defaultSearchElement: true
  key Product_id,
  @Consumption.valueHelpDefinition: [
   { entity: {
               name: '/DMO/I_Customer',
               element: 'FirstName'
       } }
   ]
  Name,
  Category,
  Price,
  Currency,
  Discount
}

Here I have used value help for some fields and searchable true annotation for searching.

4. Create a metadata extension for the Consumption view created in the step 3. Use at least single annotation for each field otherwise you may get an error if not you can continue.

BharathKumarVaddepalli_3-1750685661720.png

@Metadata.layer: #CORE
@UI: {
  headerInfo: {
    typeName: 'Product',
    typeNamePlural: 'Product',
    title: { type: #STANDARD , label: 'Product', value: 'product_id' }
  }
}
annotate view ZI_VBPRODUCT_ENTITY
    with
{
  .facet: [{ id: 'product_id', purpose: #STANDARD, type: #IDENTIFICATION_REFERENCE, label: 'product_id', position: 10 }]
  : { lineItem: [{ position: 10 },{ type: #FOR_ACTION, label: 'Copy', dataAction: 'Copy' }] ,selectionField: [{ position: 20 }],
  identification: [{ position: 10, label: 'Product ID' }] }
    Product_id ;
    : { lineItem: [{ position: 20 }], identification: [{ position: 20, label: 'Name' }], selectionField: [{ position: 30 }] }
    Name;
        : { lineItem: [{ position: 30 }], identification: [{ position: 30, label: 'Category' }],selectionField: [{ position: 40 }]}
    Category;
     : { lineItem: [{ position: 40 }], identification: [{ position: 40,label: 'Price' }],selectionField: [{ position: 50 }]}
    Price;
     : { lineItem: [{ position: 50}], identification: [{ position: 50, label: 'Currency' }],selectionField: [{ position: 60 }]}
    Currency;
    : { lineItem: [{ position: 60 }], identification: [{ position: 60, label: 'Discount' }],selectionField: [{ position: 70 }]}
    Discount;
}

5. Create the Behavior definition for the root view entity.  Make sure the mapping for the crud operations L.H.S will be the names of view and the R.H.S  names of table.

Note: L.H.S. and R.H.S names should not be same .

BharathKumarVaddepalli_4-1750685661728.png

managed implementation in class zbp_i_vbproduct unique;
strict ( 2 ); //Uncomment this line in order to enable strict mode 2. The strict mode has two variants (strict(1), strict(2)) and is prerequisite to be future proof regarding syntax and to be able to release your BO.
define behavior for ZI_VBPRODUCT alias product // alias name can be as you like
persistent table zvb_product
lock master
authorization master ( instance )
//etag master <field_name>
{
  create;
  update;
  delete;
//  field ( readonly ) product_id;
  mapping for zvb_product
{
  Product_id = product_id;
  Name       = name;
  Category   = category;
  Price      = price;
  Currency   = currency;
  Discount   = discount;
}
}

6.   Create the behavior definition for the consumption view entity.

BharathKumarVaddepalli_5-1750685661736.png

7.    Create the class which is in the behavior definition of the root view entity. Just create and activate.

BharathKumarVaddepalli_6-1750685661747.png

CLASS lhc_ZI_VBPRODUCT DEFINITION INHERITING FROM cl_abap_behavior_handler.
  PRIVATE SECTION.
    METHODS get_instance_authorizations FOR INSTANCE AUTHORIZATION
      IMPORTING keys REQUEST requested_authorizations FOR zi_vbproduct RESULT result.
ENDCLASS.
CLASS lhc_ZI_VBPRODUCT IMPLEMENTATION.
  METHOD get_instance_authorizations.
  ENDMETHOD.
ENDCLASS.

8.   Create a service definition.

BharathKumarVaddepalli_7-1750685661754.png

9.    Finally create a service binding and activate it. And click on preview to view the application .

BharathKumarVaddepalli_8-1750685661766.png

FINAL OUTPUT

BharathKumarVaddepalli_9-1750685661769.png

BharathKumarVaddepalli_10-1750685661774.png

CREATE

BharathKumarVaddepalli_11-1750685661777.png

BharathKumarVaddepalli_12-1750685661781.png

BharathKumarVaddepalli_13-1750685661782.png

UPDATE OR EDIT

BharathKumarVaddepalli_14-1750685661786.png

BharathKumarVaddepalli_15-1750685661789.png

BharathKumarVaddepalli_16-1750685661792.png

DELETE

BharathKumarVaddepalli_17-1750685661798.png

BharathKumarVaddepalli_18-1750685661804.png

1 Comment