I need to read text stored for invoice, order, etc. In ABAP we can use READ_TEXT function module, but I need to read it within a CDS view. Is there a way to read text from database tables directly in a SELECT statement?
The main problem is converting binary to text, I think. Because, sap script texts are stored in an encoded binary format. There is sap HANA SQL function which is BINTOSTR. It may help. I do not have Hanna platform. Unfortunately, I cannot try it out.
@AbapCatalog.sqlViewName: 'ZMYSELECT'
@AbapCatalog.compiler.CompareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'BinToStr'
define view ztmp_cds_demo
as select from vbak as k
left outer join stxh as h on k.mandt = h.mandt
and h.tdobject = 'VBBK'
and k.vbeln = h.tdname
and h.tdspras= 'T'
inner join stxl as l on h.tdobject = l.tdobject
and h.tdname = l.tdname
and h.tdid = l.tdid
and h.tdspras = l.tdspras {
//cast(BINTOSTR(cast(CLUSTR as binary)) as varchar) as id,
cast(BINTOSTR(cast(CLUSTD as binary)) as varchar) as text
}
NOTE: You may need to change the joins, add some parameters etc. for your case. Useful links: https://blogs.sap.com/2014/02/25/alternative-to-readtext-function-module/
How to convert BLOB to varchar with SAP HANA database using SQL