EDUCAÇÃO E TECNOLOGIA

Read Long Texts using ‘READ_TEXT’ in CDS Views

As we all know that ‘READ_TEXT’ is a function module and cannot be used in CDS Views. Only Open SQL with certain capabilities can be used in CDS Views.

Recently I got a requirement to fetch Header Note of PO from an existing CDS View. I have looked for possibilities regarding this. We can use tables STXH and STXB to get data. But the value will be in LRAW. In ABAP CDS View we do not have option to convert LRAW to String. [ I think it may be possibly in Native SQL to use SQL Built in Functions  like TO_NVARCHAR, TO_BINARY, TO_BLOB…I am not sure though]

Then I have come to know about Virtual Elements with CDS. With Virtual elements we can create a virtual element in CDS View and can have an enhancement attached to it. We can then implement the enhancement to fill the virtual element.

In My case I would need  add a virtual element in CDS View and implement an enhancement to fill the virtual element( to get Header Note).

I have added Virtual element here and mentioned implemented  class as “ZCL_MM_PO_HEADER_NOTE”.

Create enhancement Class with interface ‘IF_SADL_EXIT_CALC_ELEMENT_READ’ . Then implement method – IF_SADL_EXIT_CALC_ELEMENT_READ~CALCULATE

Fill out CT_CALCULATED_DATA table with which we need to fill values for Virtual element. In my case I will values with Header note.

Enhancement class will get triggered for each and every record that to be displayed while executing the CDS View.

Conclusion: We can implement any logic in CDS View that can be imeplemented in ABAP using Virtual elements concept.

References: https://blogs.sap.com/2020/01/13/using-virtual-elements-with-cds-in-fiori-elements/