Purpose
Using a CDS view   

Core Data Services (CDS) were introduced in ABAP with Rel. 7.40 SP08. They extend the concept of a database view by allowing more logic and computations, code pushdown to the HANA database, access control and automatic generation of OData services. S/4HANA Fiori apps often use CDS views for data retrieval.

In GuiXT it can make sense to use CDS views due to these additional features and due to the increasing number of standard CDS views in S/4HANA.

Solution
With the function module /guixt/dbselect we can access CDS views in the same way as database tables and database views.

In addition to the 'where' condition CDS views allow us to pass parameters. This is supported in guixt/dbselect as of version 2018-11-15.

Example
We let the user enter a date interval and display a table of all invoices created during this time.

We read the data via the CDS view "V_SD_CI". For the maintenance of CDS views you need the ABAP Development Tools in Eclipse but the display of the view definition, with parameters and field names, is possible in SE11:

 

The CDS view defines a mandatory parameter P_LANGUAGE which is used to read texts such as the payment description from table TVZBT. We need to set this parameter when we call up the CDS view in our InputScript (see below).
The column names such as Document_ID . Document_Type,  Document_Type_Text,... are also shown in SE11.

In our GuiXT script we define two date input fields and the invoice table:

GuiXT Script

InputField (1,1) "Invoice date between" (1,24) name="date1" -date
InputField (1,36) "and" (1,42) name="date2" -date

Pushbutton (1,59) "Display invoices" process="read_invoices.txt"

if not V[invoicecount]
  Set V[invoicecount] 0
endif

Table (3,1) (32,151) name="invoices" rows="&V[invoicecount]" _
 
title="&V[invoicecount] invoices." fixedcolumns=10

Column "No" size=5 name="No" -readonly
Column "Date" size=12 name="Invoice_Date" -readonly
Column "Type" size=4 name="Invoice_Type" -readonly
Column "DocNumber" size=12 name="Document_ID" -readonly
Column "Customer" size=10 name="Customer_ID" -readonly
Column "Name" size=30 name="Customer_Name" -readonly
Column "Terms" size=6 name="Payment_Terms" -readonly
Column "Payment Terms" size=20 name="Payment_Terms_Text" -readonly
Column "Status" size=20 name="Lifecycle_Status_Text" -readonly
Column "Currency" size=8 name="Currency" -readonly
Column "Net value" size=14 name="Net_Value" -alignright -readonly

 

The InputScript "read_invoices.txt" calls up the CDS view and then fills the table cells with the invoice data read. e

As you see the CDS parameter P_LANGUAGE is passed in parentheses just behind the CDS view name (no space character between is allowed). If there are two or more parameters, separate them by a comma.

The two dates in the where-condition need to be passed in the format YYYYMMDD which is different from the user date format, e.g. MM-DD-YYYY in our example. We use the domname=, domvalue= feature of /guixt/dbselect in order to convert the dates into this internal format.

InputScript "read_invoices.txt"

// clear result table
Clear text[r]


// call CDS view
Call
/guixt/dbselect _
 
in.table="V_SD_CI( P_LANGUAGE = 'E' )" _
  in.fields="Invoice_Date,Invoice_Type,Document_ID,Customer_Id,Customer_Name,
       Payment_Terms,Payment_Terms_Text,Lifecycle_Status_Text,Net_Value,Currency"
_
  in.condition="Invoice_Date between @DATUM.1 and @DATUM.2 " _
  in.domname1="DATUM.1" _
 
in.domvalue1="&V[date1]" _
 
in.domname2="DATUM.2" _
 
in.domvalue2="&V[date2]" _
 
in.orderby="Invoice_Date,Document_ID" _
 
table.values="r"

// put result into table cell variables
Set
V[k] 1
Set V[n] 1

label nextrow

CopyText fromText="r" toString="invoices.cell.Invoice_Date.&V[n]" line="&V[k]"
if Q[ok]

  // row number for table display
  Set V[invoices.cell.No.&V[n]] "&V[n]"

  // cell values from CDS view
  Set V[k] &V[k] + 1
 
CopyText fromText="r" toString="invoices.cell.Invoice_Type.&V[n]" line="&V[k]"
 
Set V[k] &V[k] + 1
 
CopyText fromText="r" toString="invoices.cell.Document_ID.&V[n]" line="&V[k]"
 Set V[k] &V[k] + 1
 
CopyText fromText="r" toString="invoices.cell.Customer_ID.&V[n]" line="&V[k]"
  Set V[k] &V[k] + 1
 
CopyText fromText="r" toString="invoices.cell.Customer_Name.&V[n]" line="&V[k]"
 
Set V[k] &V[k] + 1
 
CopyText fromText="r" toString="invoices.cell.Payment_Terms.&V[n]" line="&V[k]"
 
Set V[k] &V[k] + 1
 
CopyText fromText="r" toString="invoices.cell.Payment_Terms_Text.&V[n]"
                                                                    line=
"&V[k]"
 
Set V[k] &V[k] + 1
 
CopyText fromText="r" toString="invoices.cell.Lifecycle_Status_Text.&V[n]"
                                                                     line=
"&V[k]"
  Set V[k] &V[k] + 1
 
CopyText fromText="r" toString="invoices.cell.Net_Value.&V[n]" line="&V[k]"
  Set V[k] &V[k] + 1
 
CopyText fromText="r" toString="invoices.cell.Currency.&V[n]" line="&V[k]"

  Set V[k] &V[k] + 1
 
Set V[n] &V[n] + 1

  goto nextrow

endif

// invoice row count
Set V[invoicecount] &V[n] - 1

Return

Components
InputAssistant