天天看点

使用 Excel 读取 SAP ABAP CDS View 通过 ODBC 暴露出来的数据

在阅读本文前,请务必先按照在 Excel 内使用 ODBC 消费 SAP ABAP CDS view 介绍的步骤,将 SAP BTP 平台 ABAP 环境下指定的 CDS view,通过 Open Database connectivity API,暴露给 ODBC 消费者使用。

然后打开 Windows10 ODBC data source 应用,创建一条新的 Datasource name 记录:

使用 Excel 读取 SAP ABAP CDS View 通过 ODBC 暴露出来的数据
使用 Excel 读取 SAP ABAP CDS View 通过 ODBC 暴露出来的数据
注意上图的 host 主机名,需要从 SAP BTP ABAP 环境的 Communication arrangement 的 service url 字段获取,不能包含 https://
使用 Excel 读取 SAP ABAP CDS View 通过 ODBC 暴露出来的数据
同时,Windows10 PATH 环境变量下,必须包含下列这三个 dll 文件:
使用 Excel 读取 SAP ABAP CDS View 通过 ODBC 暴露出来的数据

icuuc65.dll

icudt65.dll

icuin65.dll

否则使用 Excel 通过 ODBC 连接 SAP ABAP CDS view 时,会遇到错误消息:

Could not open the ICU common library.

The following files must be in the path described by the environment variable PATH:

使用 Excel 读取 SAP ABAP CDS View 通过 ODBC 暴露出来的数据
一切就绪后,新建一个 Excel 文件,Data -> Get Data-> From other Sources:
使用 Excel 读取 SAP ABAP CDS View 通过 ODBC 暴露出来的数据
从下拉菜单里选择刚才创建好的 Data source name:
使用 Excel 读取 SAP ABAP CDS View 通过 ODBC 暴露出来的数据
点击 Load 按钮,就能将 CDS view 包含的数据,自动插入到 excel 里:
使用 Excel 读取 SAP ABAP CDS View 通过 ODBC 暴露出来的数据
使用 Excel 读取 SAP ABAP CDS View 通过 ODBC 暴露出来的数据
在 Advanced options 里,我们可以自由编写 SQL 语句,将 excel 当成一个简单的 SQL 控制台使用:
使用 Excel 读取 SAP ABAP CDS View 通过 ODBC 暴露出来的数据

SELECT OI.Item, SUM( OI.Amount ) FROM ZORDERS.Orders O INNER JOIN
ZORDERS.Orderitems OI ON O.Id = OI.OrderId GROUP BY ITEM      
使用 Excel 读取 SAP ABAP CDS View 通过 ODBC 暴露出来的数据

上图的 SQL 语句,将订单行项目的金额进行求和,并显示结果到 excel 里:

使用 Excel 读取 SAP ABAP CDS View 通过 ODBC 暴露出来的数据