UI5-技术篇-Expand与Deep 服务测试

1.SEGW创建服务

UI5-技术篇-Expand与Deep 服务测试

2.创建Data Model

UI5-技术篇-Expand与Deep 服务测试

2.1Entity Types

 ZRICO_USR 设置主键、排序字段、过滤字段

UI5-技术篇-Expand与Deep 服务测试

 ZRICO_USRITM设置主键 UI5-技术篇-Expand与Deep 服务测试

2.2Associations

 创建associations,设置主要实体 ZRICO_USR ,依赖实体ZRICO_USRITM,两者对应关系N:M

UI5-技术篇-Expand与Deep 服务测试

UI5-技术篇-Expand与Deep 服务测试

0:0...1 记录可有可无,最多一条记录

1:1必须存在一条记录

M:0..n记录可有可无,可有n条记录

N:1...n至少存在一条记录,可有n条记录

UI5-技术篇-Expand与Deep 服务测试

主表与从表字段关联关系,如上图。

UI5-技术篇-Expand与Deep 服务测试

2.3Navigation Properties

UI5-技术篇-Expand与Deep 服务测试

3.Service Implementation

UI5-技术篇-Expand与Deep 服务测试

4.Runtime Artifacts

UI5-技术篇-Expand与Deep 服务测试

5.类方法重写

 /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_DEEP_ENTITY

UI5-技术篇-Expand与Deep 服务测试
 1   method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_DEEP_ENTITY.
 2 **try.
 3 *CALL METHOD SUPER->/IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_DEEP_ENTITY
 4 *  EXPORTING
 5 **    iv_entity_name          =
 6 **    iv_entity_set_name      =
 7 **    iv_source_name          =
 8 *    IO_DATA_PROVIDER        =
 9 **    it_key_tab              =
10 **    it_navigation_path      =
11 *    IO_EXPAND               =
12 **    io_tech_request_context =
13 **  importing
14 **    er_deep_entity          =
15 *    .
16 ** catch /iwbep/cx_mgw_busi_exception .
17 ** catch /iwbep/cx_mgw_tech_exception .
18 **endtry.
19    data:
20      begin of wa_deep_entity ,
21      mandt   type zrico_usr-mandt,
22      usrid   type zrico_usr-usrid,
23      usrname type zrico_usr-usrname,
24      usraddr type zrico_usr-usraddr,
25      headertoitem type standard table of zrico_usritm with default key.
26    data:end of wa_deep_entity .
27 
28    data:
29      ls_deep_entity like wa_deep_entity,
30      ls_header      type zrico_usr.
31    data:
32      lt_deep_entity like table of wa_deep_entity,
33      lt_items       type table of zrico_usritm.
34 
35    field-symbols:
36      <fs_item>      like line of lt_items.
37 
38    "Get data from front-end
39    io_data_provider->read_entry_data(
40       importing
41          es_data = ls_deep_entity ).
42 
43     "Process data received
44     "Data-action here****************
45     loop at ls_deep_entity-headertoitem assigning <fs_item>.
46       <fs_item>-usrte = '456'.
47     endloop.
48     "Data-action here****************
49 
50     "Returned processed data back to front-end
51     copy_data_to_ref( exporting is_data = ls_deep_entity changing cr_data = er_deep_entity ).
52 
53     clear ls_deep_entity.
54   endmethod.
View Code

 /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_EXPANDED_ENTITYSET

UI5-技术篇-Expand与Deep 服务测试
 1   method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_EXPANDED_ENTITYSET.
 2 **try.
 3 *CALL METHOD SUPER->/IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_EXPANDED_ENTITYSET
 4 **  exporting
 5 **    iv_entity_name           =
 6 **    iv_entity_set_name       =
 7 **    iv_source_name           =
 8 **    it_filter_select_options =
 9 **    it_order                 =
10 **    is_paging                =
11 **    it_navigation_path       =
12 **    it_key_tab               =
13 **    iv_filter_string         =
14 **    iv_search_string         =
15 **    io_expand                =
16 **    io_tech_request_context  =
17 **  importing
18 **    er_entityset             =
19 **    et_expanded_clauses      =
20 **    et_expanded_tech_clauses =
21 **    es_response_context      =
22 *    .
23 ** catch /iwbep/cx_mgw_busi_exception .
24 ** catch /iwbep/cx_mgw_tech_exception .
25 **endtry.
26     data:
27       begin of wa_deep_entity ,
28       mandt   type zrico_usr-mandt,
29       usrid   type zrico_usr-usrid,
30       usrname type zrico_usr-usrname,
31       usraddr type zrico_usr-usraddr,
32       headertoitem type standard table of zrico_usritm with default key.
33     data:end of wa_deep_entity .
34 
35     data:
36       rt_usrid     type range of zrico_usr-usrid.
37     data:
38       lt_deep_stru like table of wa_deep_entity.
39     data:
40       ls_usr       type zcl_zrico_deep_usr_mpc_ext=>ts_zrico_usr,
41       ls_usritm    type zcl_zrico_deep_usr_mpc_ext=>ts_zrico_usritm,
42       ls_filter    type /iwbep/s_mgw_select_option,
43       ls_option    type /iwbep/s_cod_select_option,
44       ls_deep_stru like wa_deep_entity,
45       ls_expand    like line of et_expanded_tech_clauses,
46       ls_range     like line of rt_usrid.
47     data:
48       lv_usrid     type zrico_usr-usrid.
49 
50     "过滤条件
51     loop at it_filter_select_options into ls_filter.
52       loop at ls_filter-select_options into ls_option.
53         translate ls_filter-property to upper case.
54         case ls_filter-property.
55           when 'USRID'.
56             lv_usrid = ls_option-low.
57           when others.
58         endcase.
59       endloop.
60     endloop.
61 
62     if lv_usrid is not initial.
63       ls_range-sign   = 'I'.
64       ls_range-option = 'EQ'.
65       ls_range-low    = lv_usrid.
66       append ls_range to rt_usrid.
67     endif.
68 
69     select *
70       into corresponding fields of ls_deep_stru
71       from zrico_usr
72      where usrid in rt_usrid.
73       if sy-subrc = 0.
74         select *
75           into corresponding fields of table ls_deep_stru-headertoitem
76           from zrico_usritm
77          where usrid = ls_deep_stru-usrid.
78 
79         append ls_deep_stru to lt_deep_stru.
80         clear:ls_deep_stru.
81       endif.
82     endselect.
83 
84     ls_expand = 'HEADERTOITEM'.
85     append ls_expand to et_expanded_tech_clauses.
86 
87     if  iv_entity_set_name = 'ZRICO_USRSet'
88     and io_expand->compare_to_tech_names( 'HEADERTOITEM') EQ io_expand->gcs_compare_result-match_equals .
89 
90       clear:er_entityset.
91 
92       copy_data_to_ref(
93          exporting
94            is_data = lt_deep_stru
95          changing
96            cr_data = er_entityset ).
97 
98    endif.
99   endmethod.
View Code

6.服务注册

UI5-技术篇-Expand与Deep 服务测试

7.Postman服务测试

 7.1GET_EXPANDED_ENTITYSET测试

  UI5-技术篇-Expand与Deep 服务测试

 UI5-技术篇-Expand与Deep 服务测试

 UI5-技术篇-Expand与Deep 服务测试

 7.2CREATE_DEEP_ENTITY测试

 UI5-技术篇-Expand与Deep 服务测试

 获取上一步GET到的TOKEN

 UI5-技术篇-Expand与Deep 服务测试

 BODY赋值,如上图。

 UI5-技术篇-Expand与Deep 服务测试

 

上一篇:一个SAP成都研究院开发工程师 2020 年的所有文章列表


下一篇:UI5-技术篇-SAP UI5数据表进行了比较:sap.m.Table与sap.ui.table.Table