Skip to Content
Author's profile photo Surendra Garapati

BOPF Creation Using CDS Views & ODATA Publish

In these blog I am going to help you ,

How to create the BOPF Objects automatically using CDS views.

How to Publish Odata Service in the Back End.

Overview of BOPF: https://archive.sap.com/documents/docs/DOC-45425

Overview of CDS: https://blogs.sap.com/2016/09/26/core-data-services-cds-in-sap-s4-hana/

Kindly go through above links to know more about CDS & BOPF

i.e These is the new ABAP Development.

Creating the business object using the cds views to enable ODATA service enabled:

1.Root node creation for example : ZBO_MARA (Root node)

For the root node need to specify the annotation: @ObjectModel.modelCategory: #BUSINESS_OBJECT

Zbo_mara is the Root node and created the associations with zbo_marc and zekpo nodes

@ObjectModel.compositionRoot: true

@ObjectModel.modelCategory: #BUSINESS_OBJECT

@AbapCatalog.sqlViewName: 'zbo_mara1'

@AbapCatalog.compiler.compareFilter: true

@AccessControl.authorizationCheck: #CHECK

@EndUserText.label: 'marac'

@ObjectModel.writeActivePersistence: 'mara'

@ObjectModel.transactionalProcessingEnabled: true

@ObjectModel.createEnabled: true



@ObjectModel.updateEnabled: true

@ObjectModel.deleteEnabled: true

@OData.publish: true



define view Zbo_mara as select from mara as ma

association [0..*] to Zbo_marc as mc on $projection.matnr = mc.matnr

association [0..*] to Zekpo    as ek on $projection.matnr = ek.matnr

{

ma.mandt,

ma.matnr,

ma.pstat,;

/* Associations */

@ObjectModel.association.type:  [#TO_COMPOSITION_CHILD  ]

mc,

ek

}

 

After activation, the CDS, there is a new BOPF. You have to generate the classes and activate it.

Then use CRUD Template in Web IDE.

Business object created in the back end,Please find the attached screen shot:

Double click on the BO , Popup get opens with information message (Business object is generated from the CDS VIEW)

ZBO_MARA  bo got created in the back end:

 

 

2.Child node Node creation zbo_marc association with the root node and zekpo

 

@AbapCatalog.sqlViewName: 'Zbo_marc1'

@AbapCatalog.compiler.compareFilter: true

@AccessControl.authorizationCheck: #NOT_REQUIRED

@EndUserText.label: 'material detail data'



@Search.searchable: true

@ObjectModel.semanticKey:  [ 'Matnr', 'Werks' ]

@ObjectModel.representativeKey: 'Werks'

@ObjectModel.writeActivePersistence: 'marc'

@ObjectModel.createEnabled: true

@ObjectModel.deleteEnabled: true

@ObjectModel.updateEnabled: true

@ObjectModel.transactionalProcessingEnabled: true

define view Zbo_marc as select from marc

association [0..*] to Zbo_mara as _Ma on $projection.matnr = _Ma.matnr

association [0..*] to Zekpo    as ek  on $projection.werks = ek.werks

{

@Search.defaultSearchElement: true

key matnr,

key marc.werks,

@ObjectModel.association.type:  [#TO_COMPOSITION_PARENT,#TO_COMPOSITION_ROOT]

_Ma,

@ObjectModel.association.type:  [#TO_COMPOSITION_CHILD]

ek

}

Child node ZBO_MARC created in the back end with the associated associations to the root node(ZBO_MARA) & parent node(ZBO_MARA)

 

3. Node creation zekpo association with the root node(zbo_mara) and parent node (zbo_marc)

 

@AbapCatalog.sqlViewName: 'zekpo_1'

@AbapCatalog.compiler.compareFilter: true

@AccessControl.authorizationCheck: #CHECK

@EndUserText.label: 'purchase order'



@Search.searchable: true

@ObjectModel.semanticKey:  [ 'matnr' ]

@ObjectModel.representativeKey: 'matnr'

@ObjectModel.writeActivePersistence: 'ekpo'

@ObjectModel.createEnabled: true

@ObjectModel.deleteEnabled: true

@ObjectModel.updateEnabled: true

@ObjectModel.transactionalProcessingEnabled: true

define view Zekpo as select from ekpo

association [0..*] to Zbo_mara as _Mc on $projection.matnr = _Mc.matnr

association [0..*] to Zbo_marc as _mrc on $projection.matnr = _mrc.matnr

{

ebeln,

@Search.defaultSearchElement: true

werks,

matnr,

@ObjectModel.association.type:  [#TO_COMPOSITION_ROOT]

_Mc,

@ObjectModel.association.type:  [#TO_COMPOSITION_PARENT]

_mrc

}

Child node ZEKPO created in the back end with the associated associations to the root node(ZBO_MARA) & parent node(ZBO_MARC)

 

Register the OData service in /iwfnd/maint_service.

 

To register the OData service we need to add the service follow the steps mentioned in the link

https://help.sap.com/saphelp_nw74/helpdata/de/bb/2bfe50645c741ae10000000a423f68/frameset.htm

Assigned Tags

      7 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Kyle Yang
      Kyle Yang

      An excellent example!

       

      Author's profile photo jugal singh
      jugal singh

      Very good blog Surendra!!

      I have a requirement where I have to pass system generated number in post operation.

      How can I achieve through this way....If I am not wrong I need to enhance BOPF methods and pass the value.

      Please let me know where I can put that logic.

      Thanks in Advance..

       

      Jugal

       

      Author's profile photo Surendra Garapati
      Surendra Garapati
      Blog Post Author

      Hello Jugal,

      You can write your logic in the BOPF Determination on Save or BO Action also you can Write.

      Call the action from the Odata Service.

      Regards,

      Surendra

      Author's profile photo jugal singh
      jugal singh

      Thanks Surendra!!

      I got another question here, actually i am working on a requirement where i am inserting records in header and item table.

      in first instance i have updated both header and item table in one go, now i want to insert record only in Item table.

      Can you please suggest how can I achieve this.

      Thanks In Advance...

      Jugal

      Author's profile photo Surendra Garapati
      Surendra Garapati
      Blog Post Author

      Hello Jugal,

      Get the Key of Header and update the Parent key of Item with that it will create new one..

      Regards,

      Surendra

      Author's profile photo Jörg Spilker
      Jörg Spilker

      I tried to follow your example with two custom Z Tables for Orders and Items. However Activation is not possible because Order has association to Item (by associationn.type CHILD) and Item has association to Order (by association.type ROOT,PARENT). How do i solve this?

      Author's profile photo Mantri Shekar
      Mantri Shekar

      HI Surendra,

       

      I am following this blog and trying to implement BOPF am getting below Error.

      Please Kindly help me to solve this error.

       

      Multiple markers at this line:
      - [BO sync] Cannot find target attribute for MATNR in assoc. EK (view ZBO_MARC)
      - View has generated Objects
      - [BO sync] Last synchronisation resulted in errors (view ZBO_MARA)