Series [HANA] [Title VII] SAP HANA XS query using Data Services CDS entity [A]

No public: SAP Technical
Author: Matinal
 

 

The preface

We can focus on my public number, the number public in the layout better, read more comfortable.

Body part

Use SAP HANA XS Data Services (XSDS) library to query CDS entity, similar to JavaScript objects.

What CDS yes, please refer to another article at the following link, or go directly to the official website to see the introduction SAP

Click to enter: SAP HANA XS CDS Profile

Because of the time, but introduce more conceptual content directly say that the process

Import XS DS library and reference it by variable.

1, import XS DS library and reference it by variable.

​
var XSDS = $.import("sap.hana.xs.libs.dbutils", "xsds");

2. Import CDS entity to be queried.

​
var soItem = XSDS.$importEntity("sap.hana.democontent.epm.data",
"EPM.SO.Item");
var soHeader = XSDS.$importEntity("sap.hana.democontent.epm.data",
"EPM.SO.Header", {
 items: {
 $association: {
 $entity: soItem,
 $viaBacklink: "SALESORDERID"
 }
 }
});

​

3, add query. General inquiries related entity is an entity method constructed by calling the constructor $ query ().

​
var qOrders = soHeader.$query();

​

4, optimize queries.

​
qOrders = qOrders.$limit(3);

​

5, execute the query. Use $ execute method to run the query

​
var result = qOrders.$execute();

​

6, specify the query field should be returned.

 

Use $ project () method to create a query that specifies the query field should be returned.

​
var qOrderAndItemTitles = qOrders.$project({
 SALESORDERID: true,
 NETAMOUNT: "TotalNet",
 items: {
 NETAMOUNT: true
 }
});

​

Field is a list of projected JavaScript object, wherein the field is marked by a true or desired text String

​
[{
 "SALESORDERID": "0500000236",
 "TotalNet": 273.9,
 "items": {
 "NETAMOUNT": 29.9
 }
}, {
 "SALESORDERID": "0500000236",
 "TotalNet": 273.9,
 "items": {
 "NETAMOUNT": 102
 }
}, {
 "SALESORDERID": "0500000236",
 "TotalNet": 273.9,
 "items": {
 "NETAMOUNT": 55
 }
}]

​

Associated with the actual database query based on the automatically added to all involved tables you need. In the above example, the generated SQL as follows:

SELECT "t0"."SALESORDERID" AS
 "t0.SALESORDERID",
 "t0"."NETAMOUNT" AS "t0.NETAMOUNT",
 "t0.items"."NETAMOUNT" AS "t0.items.NETAMOUNT"
FROM "Header" "t0"
LEFT OUTER JOIN "Item" "t0.items"
 ON "t0"."SALESORDERID"="t0.items"."SALESORDERID"
LIMIT 10

Today first wrote this, a follow-up to the next update content.

I can focus on the public number.

Guess you like

Origin www.cnblogs.com/SAPmatinal/p/11184375.html