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: 

Using ABAP Function module in CDS view

Former Member

Hello,

Could you please let me know if it is possible to use ABAP function module into CDS ?

The aim here is to convert quantity field with the FM MATERIAL_CONVERT_QUANTITY.

Thanks in advance.

Hicham

1 ACCEPTED SOLUTION

horst_keller
Product and Topic Expert
Product and Topic Expert

Exactly, "CDS view serves to define the structure of an SQL view". How should a SQL view of the database layer call an ABAP FM of the application layer?

8 REPLIES 8

horst_keller
Product and Topic Expert
Product and Topic Expert

Do you have any idea what CDS is? If yes, how should that work?

Former Member
0 Kudos

if i understood correctly, CDS view is defined for existing database tables. this CDS view serves to define the structure of an SQL view and represents a projection onto one or several Dictionary tables.

the question here is if it is possible to add a new column to my cds view for example :

  • converted_value

and convert 1KG to 1000G with MATERIAL_CONVERT_QUANTITY ABAP FM instead of function UNIT_CONVERSION like bellow :

define view demo_cds_unit_conversion
with parameters to_unit:abap.unit(3)
as select from demo_expressions
{ id,
dec3 as original_value,
cast( 'MI' as abap.unit(3) ) as original_unit,
unit_conversion( quantity => dec3,
source_unit => cast( 'MI' as abap.unit(3) ),
target_unit => :to_unit,
error_handling => 'SET_TO_NULL' ) as converted_value,
:to_unit as converted_unit }

Thanks in advance.

Hicham

horst_keller
Product and Topic Expert
Product and Topic Expert

Exactly, "CDS view serves to define the structure of an SQL view". How should a SQL view of the database layer call an ABAP FM of the application layer?

Jelena
Active Contributor

Google -> CDS view unit conversion site:sap.com -> looks like plenty of information

Former Member
0 Kudos

hi,

Did you manage to consume bapi in cds view ?

Hi,

CDS Views are basically designed to interact the DB directly and CDS create entity in DB level so basically we are using native DB quarry in CDS. But for any ABAP function or class method there is a way we can use inside our CDS via AMDP, so we call it CDS view with table functions. for that we have to create AMDP class and method and inside our method we can call Function module or Bapi. Then we can use the AMDP class method in side our CDS view to achive our requarement but compare to other CDS views AMDP uses CDS will decrease your performance.

https://blogs.sap.com/2016/03/25/my-cds-view-self-study-tutorial-part-6-consume-table-function-in-cd...

Thanks,

Suman Sekhar Mohapatra

srahemi
Participant

you can use cds virtual element

(via ABAP class which calls the function module.)