4

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?

Eralper
  • 6,081
  • 2
  • 17
  • 27
  • I believe you can create two CDS views with parameters for the STXH, STXL and STXB tables, one for sap script texts and one for non-sap script texts. However, eventually, you must decompress the text in ABAP. Why do you need it for? If it is about performance issues, you can check the mass reading standard texts, https://archive.sap.com/discussions/message/10063502#10063502 – Oguz Aug 14 '17 at 11:48
  • Merhaba Oguz, I have already a CDS which read data from various tables about invoices. I need to display item texts, etc. Because I cannot read them from tables in CDS view, I have to manipulate the CDS data in ABAP codes, for example catch all into an internal table loop and read with FM. But this type of coding does not match with HANA approach, pushing the data reading to database level – Eralper Aug 14 '17 at 12:18
  • Merhaba Eralper. I am curious about this, is your problem solved? – Oguz Aug 16 '17 at 10:47

2 Answers2

2

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

Oguz
  • 1,621
  • 1
  • 14
  • 23
  • 1
    Merhaba Oğuz, unfortunately when I try the query in CDS view, I got bintostr function is unknown error preventing activation. When I directly execute the query on HANA db, I experience invalid character encoding error. So I could not yet solved the issue – Eralper Aug 22 '17 at 08:46
1

Something that I have done on an ABAP 7.50 system (EHP8) when using CDS for my OData service is just create a separate OData service that is a generic 'Standard Text' reader. Thisis a plain ABAP-based OData service modelled in SEGW.

Then whenever I want to display standard text in my app I make a call to this service. Works well. Seems that in S4 you can do this all in CDS.

Jason Scott
  • 555
  • 3
  • 12
  • Hi Jason, thanks for informing about this option. As I understand, you call function module read_text within OData methods for data which is fetched via CDS, etc. So you probably read per record basis, am I right? What I actually want to do is mass read. Do you think is it possible? – Eralper Oct 23 '17 at 06:59
  • In your own odata service you can do whatever you want... including mass reading standard texts. ;-) – Jason Scott Oct 24 '17 at 08:38
  • In every fm I see for text reading, there it comes to a point where following IMPORT command code block is executed where I want to implement in AMDP or CDS View SELECT statements. I want to learn if there is a way of this? import tline to rt_lines from internal table cluster_tab accepting truncation "important for Unicode->Nonunicode code page into l_cp ignoring conversion errors. – Eralper Oct 25 '17 at 11:55