@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.
@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.
@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.
@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 .
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.
7. Create the class which is in the behavior definition of the root view entity. Just create and activate.
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.
9. Finally create a service binding and activate it. And click on preview to view the application .
FINAL OUTPUT
CREATE
UPDATE OR EDIT
DELETE
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
14 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 |