这里我们做ADT来创建
场景介绍:把hana中的一个底表,创建成ABAP的 CDS VIEW ,在把CDS VIEW 生成 OData 服务。
红框内根据自身情况填写
选择 Define Table Function with Parameters 创建 Data Definition
完整代码,定义 结构
- @EndUserText.label: '财务报表生成ODATA'
- define table function ZDDF_AUTHDATA
- returns {
- MANDT: abap.clnt;
- GSMC : abap.char( 400 );
- GSDM : abap.char( 400 );
- CWDATE: abap.dats;
- ZYYWLR: abap.fltp;
- JZCSYL: abap.fltp;
- KCFJCX: abap.fltp;
- ZYYWSRZZ: abap.fltp;
- JLRZZL: abap.fltp;
- JZCZZL: abap.fltp;
- YSZKZZL: abap.fltp;
- YSZKZZTS:abap.fltp;
- CHZZTS:abap.fltp;
- GDZCZZL: abap.fltp;
- }
- implemented by method zamdp_authdata_002=>GET_ENTITY_SET;
完整代码,定义取数逻辑, return 后边跟的sql 代码 是查询的 HANA 数据库对象表,
注意 AMDT中的 zamdp_authdata_002 是上一步中定义过关联
implemented by method zamdp_authdata_002=>GET_ENTITY_SET;
- class zamdp_authdata_002 definition
- public
- final
- create public .
-
- public section.
- interfaces: IF_AMDP_MARKER_HDB.
- class-methods:
- GET_ENTITY_SET
- for table function ZDDF_AUTHDATA.
- protected section.
- private section.
- endclass.
-
-
-
- class zamdp_authdata_002 implementation.
- method GET_ENTITY_SET by database function
- for hdb language sqlscript
- options read-only.
- return
- SELECT
- '100' as MANDT,
- "GSMC" AS GSMC,
- "GSDM" AS GSDM,
- TO_VARCHAR ("CWDATE", 'YYYYMMDD') AS CWDATE,
- "ZYYWLR",
- "JZCSYL",
- "KCFJCX",
- "ZYYWSRZZ",
- "JLRZZL",
- "JZCZZL",
- "YSZKZZL",
- "YSZKZZTS",
- "CHZZTS",
- "GDZCZZL"
- FROM "_SYS_BIC"."ZAUTHDATA001";
- endmethod.
- endclass.
完整代码 注意:@OData.publish: true 这行是标记该CDS VIEW 可发布成OData服务,
这里注意 必须要指定 KEY ,不然,激活会不成功。
-
- @EndUserText.label: 'CDS View Entity'
- @OData.publish: true
- define view entity ZDD_AUTHDATA as
- select from ZDDF_AUTHDATA as AUT
- {
- @EndUserText.label: '公司名称'
- key AUT.GSMC,
- @EndUserText.label: '公司代码'
- key AUT.GSDM,
- @EndUserText.label: '报表日期'
- key AUT.CWDATE,
- @EndUserText.label: '主营业务利润(元)'
- AUT.ZYYWLR,
- @EndUserText.label: '净资产收益率(%)'
- AUT.JZCSYL,
- @EndUserText.label: '扣除非经常性损益后的净利润(元)'
- AUT.KCFJCX,
- @EndUserText.label: '主营业务收入增长率(%)'
- AUT.ZYYWSRZZ,
- @EndUserText.label: '净利润增长率(%)'
- AUT.JLRZZL,
- @EndUserText.label: '净资产增长率(%)'
- AUT.JZCZZL,
- @EndUserText.label: '应收账款周转率(次)'
- AUT.YSZKZZL,
- @EndUserText.label: '应收账款周转天数(天)'
- AUT.YSZKZZTS,
- @EndUserText.label: '存货周转天数(天)'
- AUT.CHZZTS,
- @EndUserText.label: '固定资产周转率(次)'
- AUT.GDZCZZL
- }
/sap/opu/odata/sap/ZDD_AUTHDATA_CDS/ZDD_AUTHDATA?$top=10&$skip=10
由于底表有21万条数据,需要分页执行OData
元数据