Sap Abap On Hana-2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

SAP ABAP on HANA

Revolutionizing Inventory Management Integrating SAP ABAP RAP for Enhanced Efficiency
Revolutionizing Inventory Management Integrating SAP ABAP RAP for Enhanced Efficiency

-----------------------------------------------------------------------------------------------------------------------------------

As businesses navigate the complexities of inventory management, the integration of advanced


technologies becomes crucial. This guide delves into the intricacies of employing SAP ABAP's Restful
Application Programming model to transform inventory management processes. We start by
establishing a solid database structure, encompassing everything from product details to supplier
relationships. The journey then progresses to populating these databases with initial data, setting the
stage for advanced data manipulation and retrieval using Core Data Services views. Document aims to
provide a comprehensive roadmap for enhancing inventory management through the innovative
application of SAP ABAP RAP.

Following steps for implementing inventory management using SAP ABAP RAP:

1. Database Table Creation: Create tables for products (zproduct_01), suppliers (zsuppliers_01),
purchase orders (zpurchase_01), and stock levels (zstocklevel_01). Each table includes essential
fields like client, product_id, supplier_id, and more, with appropriate data types.
2. Data Generation: Implement an ABAP class (zcl_populate_inventory) to populate these tables
with initial data, with methods for creating products, stock levels, suppliers, and purchase
orders.
3. Define CDS Views: Develop CDS views to join and filter data from multiple tables, enabling
efficient data retrieval and analysis.
4. Create Projection View with UI Annotation: Develop a projection view (ZC_INVENTORY_01)
with UI annotations to enhance data representation in SAP Fiori apps.
5. Create Service Definition and Bindings: Develop a service definition for the business objects
and create service bindings to expose them as OData services.

For tracking stock levels, product details, supplier information, and managing purchase orders.

The document provides detailed instructions for creating database tables in SAP ABAP RAP

Here's a summary of the table creation code:

1. ZTABLE_PRODUCT_DETAILS (zproduct_01):
o Fields: client (key), product_id (key), name, description, category.
o Annotations and properties are specified, such as @EndUserText.label,
@AbapCatalog.tableCategory, and field definitions.
2. ZTABLE_SUPPLIER_INFO (zsuppliers_01):
o Fields: client (key), supplier_id (key), name, contact_info.
o Includes similar annotations and field definitions as the product table.
3. ZTABLE_PURCHASE_ORDERS (zpurchase_01):
o Fields: client (key), order_id (key), product_id, supplier_id, order_quantity, order_date,
status.
o Follows the same structure with specific fields for purchase order management.
4. ZTABLE_STOCK_LEVELS (zstocklevel_01):
o Fields: client (key), product_id (key), quantity.
o Designed for tracking stock levels, with a simple structure focusing on quantity.

Prepared by [email protected]
Each table has its fields and types defined according to its purpose, adhering to SAP ABAP RAP
standards for database design.

Design tables for storing

○ product details,
○ stock levels,
○ supplier information, and
○ purchase orders.

Each table should have fields relevant to its purpose.

For example, the product table might include fields for product ID, name, description, and category.

Please write the below code with Z tables

For tracking stock levels, product details, supplier information, and managing purchase orders.

Design tables for storing

○ product details,
○ stock levels,
○ supplier information, and
○ purchase orders.

Each table should have fields relevant to its purpose.

For example, the product table might include fields for product ID, name, description, and category.

Please write the below code with Z tables

Prepared by [email protected]
Step 1 :DataBase table Creation

Prepared by [email protected]
Create a Transport Request and Click ‘Finish’.

In alignment with the previous step, I kindly request the creation of three additional tables. The
necessary code is provided below for your reference

Source Code for Table 1

@EndUserText.label : 'Product'
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table zproduct_01 {
key client : abap.clnt not null;
key product_id : abap.char(10) not null;
name : abap.char(40);
description : abap.char(80);
category : abap.char(20);
}

Prepared by [email protected]
Source Code for Table 2

@EndUserText.label : 'Supplier Information'


@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table zsuppliers_01 {
key client : abap.clnt not null;
key supplier_id : abap.char(10) not null;
name : abap.char(40);
contact_info : abap.char(80);
}
Source Code for Table 3

@EndUserText.label : 'Purchase Order'


@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table zpurchase_01 {
key client : abap.clnt not null;
key order_id : abap.char(10) not null;
product_id : abap.char(10);
supplier_id : abap.char(10);
order_quantity : abap.int4;
order_date : abap.dats;
status : abap.char(20);
}
Source Code for Table 4

@EndUserText.label : 'Stock Level'


@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table zstocklevel_01 {
key client : abap.clnt not null;
key product_id : abap.char(10) not null;
quantiy : abap.int4;
}
These table definitions include essential fields for managing products, stock levels, supplier details, and
purchase orders. You can adapt these examples according to your specific requirements, such as field
lengths and types.

Prepared by [email protected]
Step 2 :Data Generation
Create ABAP class to populate the tables product, stock levels, suppliers, and purchase orders with
initial data.

CLASS zcl_populate_inventory DEFINITION


PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES:if_oo_adt_classrun.
PROTECTED SECTION.
PRIVATE SECTION.
CLASS-METHODS:create_products,
create_stock_levels,
create_suppliers,
create_purchase_orders,
load_inventory_data.
ENDCLASS.
CLASS zcl_populate_inventory IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
load_inventory_data( ).
ENDMETHOD.
METHOD create_products.
TYPES:TT_Product_01 TYPE STANDARD TABLE OF
zproduct_01
WITH EMPTY KEY.
DATA(lt_product_01) = VALUE tt_product_01(
( product_id = 'P1001'
name = 'Laptop'
description = '15-inch-Laptop'
category = 'Electronics')
( product_id = 'P1002 '
name = 'Desk Chair'
description = 'Ergonimic office chair'
category = 'Furniture') ).
DELETE FROM zproduct_01.
INSERT zproduct_01 FROM TABLE @lt_product_01.
CLEAR :lt_product_01.
ENDMETHOD.
METHOD create_purchase_orders.
TYPES:tt_purchase TYPE STANDARD TABLE OF zpurchase_01
WITH EMPTY KEY.

Prepared by [email protected]
DATA(lt_purchase) = VALUE tt_purchase(
( order_id = '01001' product_id = 'P1001'
supplier_id = 'S1001' order_quantity = 10
order_date = '20230301' status = 'Ordered' )
( order_id = '01002' product_id = 'P1002'
supplier_id = 'S1002' order_quantity = 5
order_date = '20230305' status = 'Delivered' ) ).
DELETE FROM zpurchase_01.
INSERT zpurchase_01 FROM TABLE @lt_purchase.
CLEAR lt_purchase.
ENDMETHOD.
METHOD create_stock_levels.
TYPES:tt_stocklevel TYPE STANDARD TABLE OF zstocklevel_01
WITH EMPTY KEY.
DATA(lt_stocklevel) = VALUE tt_stocklevel(
( product_id = 'P1001' quantiy = 50 )
( product_id = 'P1002' quantiy = 30 ) ).
DELETE FROM zstocklevel_01.
INSERT zstocklevel_01 FROM TABLE @lt_stocklevel.
ENDMETHOD.
METHOD create_suppliers.
TYPES:tt_supplier TYPE STANDARD TABLE OF zsuppliers_01
WITH EMPTY KEY.
DATA(lt_suppliers) = VALUE tt_supplier(
( supplier_id = 'S1001' name = 'TECHSourceA01'
contact_info = '[email protected]' )
( supplier_id = 'S1002' name = 'OfficeSourceA01'
contact_info = '[email protected]' ) ).
DELETE FROM zsuppliers_01.
INSERT zsuppliers_01 FROM TABLE @lt_suppliers.
CLEAR lt_suppliers.
ENDMETHOD.
METHOD load_inventory_data.
create_products( ).
create_stock_levels( ).
create_suppliers( ).
create_purchase_orders( ).
ENDMETHOD.
ENDCLASS.
This class contains methods to insert initial data into each of the defined tables. Modify the data as
necessary to fit your specific requirements or scenarios.

Please verify the table records

Prepared by [email protected]
To gain an overview of the data contained in the tables listed above, please select the respective table,
right-click, and choose the option to preview the table records

Product Table

Supplier Table

Purchase Order Table

Prepared by [email protected]
Stock Table

Step 3 :Define CDS based Stock Inventory


Develop the CDS Views that effectively join and filter data from multiple tables, enabling seamless data
retrieval and analysis.

Prepared by [email protected]
Prepared by [email protected]
and Click ‘Finish’.

@AbapCatalog.sqlViewName: 'ZVINVENT01'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Stock Level Inventory'
define root view ZI_INVENTORY_01
as select from zproduct_01
left outer join zstocklevel_01 on zproduct_01.product_id = zstocklevel_01.product_id
left outer join zpurchase_01 on zproduct_01.product_id = zpurchase_01.product_id
left outer join zsuppliers_01 on zpurchase_01.supplier_id = zsuppliers_01.supplier_id
{
key zproduct_01.product_id as ProductId,
zproduct_01.name as Name,
zproduct_01.description as Description,
zproduct_01.category as Category,
zstocklevel_01.quantiy as Quantiy,

Prepared by [email protected]
zsuppliers_01.supplier_id as SupplierId,
zsuppliers_01.name as supplier_name,
zpurchase_01.order_id as OrderId,
zpurchase_01.order_quantity as OrderQuantity,
zpurchase_01.status as Status
}
Please find the below output after activating the CDS View.Please run with ‘ABAP Application’

Output

Step 4:Create the projection view with UI annotation


● Open your ABAP development tools (like SAP ADT in Eclipse).
● Navigate to the package where you want to create the projection view.
● Right-click and choose to create a new Data Definition.
● Name your projection view (e.g., ZC_INVENTORY_01) and provide a description.

Prepared by [email protected]
Prepared by [email protected]
Click ‘Finish’ and Copy the below code.

Initial Source Code for Projection View- Version 1:

@EndUserText.label: 'Project view for inventory CDS View'


@AccessControl.authorizationCheck: #NOT_REQUIRED
@UI:{
headerInfo:
{
typeName : 'Product',
typeNamePlural: 'Products',
title : { type : #STANDARD,
value: 'ProductId'
}
}
}
@Search.searchable: true
define root view entity ZC_INVENTORY_01 as
projection on ZI_INVENTORY_01

Prepared by [email protected]
{
@UI.facet:
[{ id : 'Product',
purpose : #STANDARD,
type : #IDENTIFICATION_REFERENCE,
label : 'Product',
position: 10
}]
@UI:{
lineItem:[ { position :10, importance: #HIGH }],
identification:[ { position:10,label: 'Product ID' }]
}
@Search.defaultSearchElement: true
key ProductId,
@UI:{
lineItem :[{ position:20, importance: #HIGH}],
identification:[{ position:20 }],
selectionField:[{ position:20 }]

}
Name,
@UI:{
lineItem :[{ position:30, importance: #MEDIUM}],
identification:[{ position:30 }]
}
Description,
@UI:{
lineItem:[{ position:40, importance: #MEDIUM}],
identification:[{ position:40 }]
}
Category,
@UI:{
lineItem:[{ position:50,importance: #HIGH}],
identification:[{ position:50 }]
}
Quantiy,
@UI:{
lineItem:[{ position:60,importance: #HIGH}],
identification:[{ position:60 }]
}
SupplierId,
@UI:{
lineItem:[{ position:70,importance: #HIGH}],

Prepared by [email protected]
identification:[{ position:70 }]
}
supplier_name,
@UI:{
lineItem:[{ position:80,importance: #HIGH}],
identification:[{ position:80 }]
}
OrderId,
@UI:{
lineItem:[{ position:90,importance: #HIGH}],
identification:[{ position:90 }]
}
OrderQuantity,
@UI:{
lineItem:[{ position:100,importance: #HIGH}],
identification:[{ position:100 }]
}
Status
}

Step 5 :Create “Service Definition” and “Service Bindings”


Develop a service definition for your business objects and create service bindings to expose them as
OData services.

Prepared by [email protected]
and Click ‘Finish’.Now We can create ‘Service Binding’.

Prepared by [email protected]
Prepared by [email protected]
Activate the service binding and publish it.

Then Click the preview to view the output.

and Click ‘Finish’.

Output 1

Prepared by [email protected]
Enhance the Projection View with more annotations:

● Change the column Name


● Group the column Name logically
● Indicate the critical fields
● Improve the data representation in list reports and object pages

How do we achieve it?

● Added an additional facet for 'Order Information' to further segment the data.
● Utilized @UI.fieldGroup to logically group fields under the 'Supplier Details' and 'Order
Information' facets. This creates a more structured layout in the Fiori app.
● Enhanced the @UI.lineItem and @UI.identification annotations with more detailed labels and
importance levels to improve data representation in list reports and object pages.
● Included @UI.criticalityLabels to add visual indicators in the UI for critical fields like 'Product
Quantity'.

Revised Version 2 Output

Revised Version 2 Source Code

@EndUserText.label: 'Project view for inventory CDS View'


@AccessControl.authorizationCheck: #NOT_REQUIRED
@UI:{
headerInfo:
{
typeName : 'Product',

Prepared by [email protected]
typeNamePlural: 'Products',
title : { type : #STANDARD,
value: 'ProductId'
}
}
}
@Search.searchable: true
define root view entity ZC_INVENTORY_01
as projection on ZI_INVENTORY_01
{
@UI.facet:
[{ id : 'ProductDetails',
purpose : #STANDARD,
type : #IDENTIFICATION_REFERENCE,
label : 'Product Details',
position: 10
},
{ id :'SupplierDetails',
purpose : #STANDARD,
type :#FIELDGROUP_REFERENCE,
label :'Supplier Details',
position:20
},
{
id :'OrderInfo',
purpose : #STANDARD,
type : #FIELDGROUP_REFERENCE,
label :'Order Information',
position : 30
}
]
@UI:{
lineItem:[ { position :10, importance: #HIGH ,label: 'Product ID'}],
identification:[ { position:10 }]
}
@Search.defaultSearchElement: true
key ProductId,
@UI:{
lineItem :[{ position:20, importance: #HIGH,label:'Product Name'}],
identification:[{ position:20 }],
selectionField:[{ position:20 }]
}
Name,

Prepared by [email protected]
@UI:{
lineItem :[{ position:30, importance: #MEDIUM,label:'Product Description'}],
identification:[{ position:30 }]
}
Description,
@UI:{
lineItem:[{ position:40, importance: #MEDIUM,label:'Product Category'}],
identification:[{ position:40 }]
}
Category,
@UI:{
lineItem:[{ position:50,importance: #HIGH,label:'Product Quantity'}],
identification:[{ position:50 }],
criticalityLabels: [{criticality: #CRITICAL}]
}
Quantiy,
@UI:{
lineItem:[{ position:60,importance: #HIGH,label:'Supplier ID'}],
identification:[{ position:60 }],
fieldGroup:[{ qualifier: 'SupplierDetails',label:'Supplier ID'}]
}
SupplierId,
@UI:{
lineItem:[{ position:70,importance: #HIGH,label:'Supplier Name'}],
identification:[{ position:70 }],
fieldGroup: [{ qualifier: 'SupplierDetails',label:'Supplier Name' }]
}
supplier_name,
@UI:{
lineItem:[{ position:80,importance: #HIGH,label:'Order ID' }],
identification:[{ position:80 }],
fieldGroup:[{ qualifier: 'OrderInfo',label:'Order ID'}]
}

OrderId,
@UI:{
lineItem:[{ position:90,importance: #HIGH,label: 'Order Quantity'}],
identification:[{ position:90 }],
fieldGroup:[{ qualifier:'OrderInfo',label:'Order Quantity'}]
}
OrderQuantity,
@UI:{
lineItem:[{ position:100,importance: #HIGH,label: 'Order Status'}],

Prepared by [email protected]
identification:[{ position:100 }],
fieldGroup:[{ qualifier:'OrderInfo',label:'Order Status'}]
}
Status
}

Important Annotations used in above projection view

Annotation Syntax Example Usage Description

@UI.lineItem: [{ @UI.lineItem: [{ Used for configuring


position: <Integer>, position: 10, how fields are
@UI.lineItem
importance: <Enum>, importance: #HIGH, displayed in table
label: <String>, ... }] label: 'Product ID' }] views or lists.

@UI.identification: [{ @UI.identification: [{ Sets up fields in a


@UI.identificatio
position: <Integer>, position: 10, label: detailed view, like
n
label: <String>, ... }] 'Product ID' }] on an object page.

Indicates that a field


@UI.selectionFiel @UI.selectionField: [{ @UI.selectionField: [{
should be used as a
d position: <Integer> }] position: 20 }]
selection criterion.

Customizes the
@UI.dataField: [{ @UI.dataField: [{
@UI.dataField representation of a
label: <String> }] label: 'Name' }]
data field.

Defines how text


@UI.textArrange @UI.textArrangement @UI.textArrangement: descriptions are
ment : #<Enum> #TEXT_LAST displayed in relation
to key fields.

@UI.fieldGroup: [{
@UI.fieldGroup: [{ qualifier: Groups related
@UI.fieldGroup qualifier: <String>, 'CategoryGroup', fields under a
label: <String> }] label: 'Category common label.
Details' }]

Prepared by [email protected]
@UI.dataFieldFor: @UI.dataFieldFor:
Assigns fields to a
@UI.dataFieldFor ['<Qualifier>', ['CategoryGroup',
specific group.
'<Field>'] 'Category']

Denotes the
@UI.criticality:
@UI.criticality @UI.criticality: #HIGH importance or
#<Enum>
criticality of a field.

Indicates that the


field should be
@Search.defaultS @Search.defaultSearc @Search.defaultSearc
considered as a
earchElement hElement: <Boolean> hElement: true
default element in
search operations.

@EndUserText.label: Provides a human-


@EndUserText.la @EndUserText.label:
'Project view for readable label for
bel '<String>'
inventory CDS View' the CDS view.

Determines
whether
@AccessControl.a @AccessControl.auth @AccessControl.autho
authorization
uthorizationChec orizationCheck: rizationCheck:
checks are required
k #<Enum> #NOT_REQUIRED
for accessing the
data.

Marks the view as


@Search.searcha @Search.searchable: @Search.searchable:
searchable in Fiori
ble <Boolean> true
applications.

@UI.headerInfo: {
Defines the header
typeName: 'Product',
@UI.headerInfo: information of the
typeNamePlural:
@UI.headerInfo {<Header Info view, including the
'Products', title: { type:
Attributes>} type name and title
#STANDARD, value:
field.
'ProductId' } }

Prepared by [email protected]

You might also like