Information Technology

Menu

ABAP Repository & Fiori Application

In this tutorial we are going to integrate some ABAP concepts with SAPUI5 Fiori applications.
Now we will use all the Procurement data model and will be exposed as OData service with associations and navigation between SNWD_AD (Business Partners Address) and SNWD_BPA (Business Partners complementary info), SNWD_SO_INV_HEAD (Sales orders header) and SNWD_SO_INV_ITEMS (Sales orders items).

Core Data Service View

Connect to ABAP project and create a new ABAP Repository Object in the ZTEST Package.

Select Data Definition from Core Data Services folder and press Next.

Set the name ZCDS_BPA, set a description and press Next.

Select the transport “Test Request”, and press Finish.

In the CDS created set this code.

@AbapCatalog.sqlViewName: ‘ZV_CDS_BPA’@AbapCatalog.compiler.compareFilter: true@AccessControl.authorizationCheck: #CHECK@EndUserText.label: ‘Business Partners Main Info’define view zcdsv_bpa as select from snwd_ad as adjoin snwd_bpa as bpaon ad.client = bpa.client and ad.node_key = bpa.address_guid{key ad.client as client_id,key ad.node_key as addres_key,ad.building as building,ad.city as city,ad.country as country,bpa.company_name as company_name,bpa.node_key as company_key,bpa.bp_role as company_role,bpa.currency_code as company_currency}

Create another CDS view named zcds_inv_header with this code

@AbapCatalog.sqlViewName: ‘ZV_CDS_INV_HEAD’@AbapCatalog.compiler.compareFilter: true@AccessControl.authorizationCheck: #CHECK@EndUserText.label: ‘Sales Order Invoices Header’define view zcds_inv_header as select from snwd_so_inv_head as so{key so.client as client_id,key so.buyer_guid as buyer_guid,so.node_key as node_key,so.created_at as created_at,so.gross_amount as gross_amount,so.net_amount as net_amount,so.tax_amount as tax_amount,so.currency_code as currency_code,so.payment_status as payment_status}

Create another CDS view named zcds_inv_items with this code

@AbapCatalog.sqlViewName: ‘ZV_CDS_INV_ITEMS’@AbapCatalog.compiler.compareFilter: true@AccessControl.authorizationCheck: #CHECK@EndUserText.label: ‘Sales Order Invoices Items’define view zcds_inv_items as select from snwd_so_inv_item as it{key it.client as client_id,key it.parent_key as parent_key,it.so_item_guid as so_item_guid,it.gross_amount as gross_amount,it.quantity as net_amount,it.tax_amount as tax_amount,it.currency_code as currency_code,it.product_guid as product_guid}

Save and activate all CDS views.

OData Service

Now we will to create an OData service using our CDS view as data source.
1. Click on Run ABAP Development Object …
2. Set segw.
3. Select SEGW transaction and press OK.
If you have problems with this transaction in eclipse, you can use it with SAP GUI instead.

1. Press on Create Project.
2. Set the values as the image shown.
3. Press OK.

Open the created project and right click on Data Model and select Import / DDIC Structure.

Name: BPA_Info

Select Entity Type

ABAP Structure: ZV_CDS_BPA

Check Create Default Entity Set

Press Next

From Data Source Parameter(s), select all the fields less CLIENT_ID and press Next.

Select ADDRES_KEY as key values. Press Finish.

Repeat the import process for:

Name: INV_HEAD_Info

ABAP Structure: ZV_CDS_INV_HEAD

Key: NodeKey

And

Name: INV_ITEMS_Info

ABAP Structure: ZV_CDS_INV_ITEMS

Key: ParentKey, SoItemGuid

Yours Entities should look like this.

We need to create the association between the entities created. Right click on Associations folder and select Create.

Name: ToSalesOrderInfo

Principal Entity:

Name: BPA_Info

Cardinality: 1

Navigation: ToSalesOrderInfo

Depend Entity:

Name: INV_HEAD_Info

Cardinality: 1..n

Press Next

Principal Key: AddresKey

Dependent Property: BuyerGuid

Press Next

The association should looks like this. Press Finish.

Create another Association:

Name: ToSalesOrderItemsInfo

Principal Entity:

Name: INV_HEAD_Info

Cardinality: 1

Navigation: ToSalesOrderItemsInfo

Depend Entity:

Name: INV_ITEMS_Info

Cardinality: 1..n

Press Next

Principal Key: NodeKey

Dependent Property: ParentKey

Press Next

The second association should looks like this. Press Finish

The associations should looks like this.

Save all the changes and click on Generate Runtime Objects

The system shows you the default names of some objects that will be created (don’t change). Press OK.

Select ZTEST package and save

Select the request “Test Request” and press OK.

You should to see several success messages.

In Service Implementation right click on BPA_InfoSet and select Map to Data Source.

Target: Local

Click on button

Type: Data Dictionary

Model: ZV_CDS_BPA

Your Map should look like this. Press OK

Repeat the Map process to the ZV_CDS_INV_HEAD.

Repeat the Map process to the ZV_CDS_INV_ITEMS.

For each map created is necessary set the ELEMENT in every Property field

For BPA_InfoSet mapping the relationship should looks like this.

For INV_HEAD_InfoSet mapping the relationship should looks like this.

For INV_ITEMS_InfoSet mapping the relationship should looks like this.

Save all the changes and click on Generate Runtime Objects

Double click on Service Maintenance

Select GW_HUB

Press Register

To register your project as service, your info should look like the image shown and the package related is ZTEST. Press OK.

Check the registration status as green.

Press Maintain

You will be redirected to the Services Manager. Press Yes

Select the service. Press on SAP Gateway Client

1. Press Execute.
2. Check the result.Your OData service is working fine.

Fiori Application

You can use your CDS view in yours Fiori application too. In eclipse IDE create a new project. Right click on project explorer view / New / Other

Select Application Project from SAPUI5 Application Development folder. Press Next