Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to enabling Actions for OData Consumption on CDS view?

former_member267947
Participant
0 Kudos

Hi all

I've created a CDS view, that is using BOPF for transactional purpose.

On BOPF I've created an action:

and would like to publish as functionsimport for odata consumption.

I've found a guide https://help.sap.com/doc/saphelp_nw75/7.5.5/en-US/07/1a1fd1465749dca2872640cba8d82e/content.htm?load... but I would like to provide on CDS view level instead of field level.

How to do it?

Thanks

4 REPLIES 4

maheshpalavalli
Active Contributor
0 Kudos

Hi zero_coder

You mean that you don't want to pass any data to the backend if the action is called? If yes, is there any reason to do that?

Didn't understand the part where you mentioned as "CDS view level"

BR

Mahesh

former_member267947
Participant
0 Kudos

Sorry, for my bad expression. What I mean is, I would like to provide an action, that defined in teh BOPF for the OData consumption.

The CDS view looks as the following:

@AbapCatalog.sqlViewName: 'ZAMICLASSSEL'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Classification selection'
@VDM.viewType: #COMPOSITE
@ObjectModel: {
   transactionalProcessingEnabled: true,
   writeActivePersistence: 'ZAM_T_CLASS_SEL',
   compositionRoot: true,
   createEnabled: false,
   updateEnabled: false,
   deleteEnabled: false
}
define view ZAM_I_CLASS_SEL
  as select from ZAM_I_CLASS_HEAD
  association [1..1] to ZAM_I_CLASSTYPE   as _ClassType    on $projection.ClassType = _ClassType.ClassType
  association [1..1] to ZAM_I_CLASS_KEYWS as _ClassKeyword on $projection.ClassNum = _ClassKeyword.ClassNum
                                                          and $projection.ClassType = _ClassKeyword.ClassType
{
      @ObjectModel.foreignKey.association: '_ClassType'
      key ClassType,
      @ObjectModel.foreignKey.association: '_ClassKeyword'
      key ClassNum,
      ValidFrom,
      ValidUntil,
      _ClassType,
      _ClassKeyword
}

and the generated node:

and created action on BOPF:

Now, I want to provide the action for consumption as part of OData and do not know, how to do it.

Here is the content of action class:

CLASS zcl_am_a_characteristics DEFINITION
  PUBLIC
  INHERITING FROM /bobf/cl_lib_a_supercl_simple
  FINAL
  CREATE PUBLIC .
  PUBLIC SECTION.
    METHODS /bobf/if_frw_action~execute
        REDEFINITION .
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.
CLASS zcl_am_a_characteristics IMPLEMENTATION.
  METHOD /bobf/if_frw_action~execute.
    BREAK-POINT.
  ENDMETHOD.
ENDCLASS.

When the action get called through the OData, I would like to receive the value from ClassType and ClassNum that is defined on CDS view above. It should be like defining function import with particular import parameters

and another return type like:

I hope, it is more clear, what I am trying to archive.

Thanks

former_member267947
Participant
0 Kudos

Please look at comment below.

maheshpalavalli
Active Contributor
0 Kudos

Hi Anujit Marty,

You need to enable the action in odata consumption view first, see the SAP help example below

https://help.sap.com/viewer/cc0c305d2fab47bd808adcad3ca7ee9d/1809.000/en-US/071a1fd1465749dca2872640...

But make sure you select the exporting type as "Node" in the BOPF action.

Let me know in case of issues.

BR,

Mahesh