转载:https://blogs.sap.com/2014/07/18/implementing-expand-entityentity-set/

Requirement

Considering a basic scenario where i am using  BAPI_PO_GETDETAIL which has multiple output tables and input is PO number

Now we shall start with SAP Gateway

Create Project in SEGW

Create three entity types and Entity Sets

Entity Type-1- Header

Entity Type-2- Item

Entity Type-3- Schedule

Entity Set-1- HeaderSet

Entity Set-2- ItemSet

Entity Set-3- ScheduleSet

Create Association

Association-1 –  AssItem (Without key fields mapping)

Association-2 –  AssSchedule (Without key fields mapping)

Create Navigation

Navigation-1 –  NavItem

Navigation-2 –  NavSchedule

Let’s generate runtime artifacts. Click on generate runtime objects button. It will display

popup . Keep the default class names as-is and click on enter button.

Once generation is successful, you will get 4 classes. 2 for Data provider and 2 for Model provider.

we have to Redefine the method/IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_EXPANDED_ENTITYSET

Code Snippet

METHOD /iwbep/if_mgw_appl_srv_runtime~get_expanded_entityset.

*————————————————————————-*

*             Deep Structure

*————————————————————————-*

DATA:  BEGIN OF ls_order_items.

INCLUDE       TYPE zcl_zproj_982_mpc=>ts_header.

DATA: navitem       TYPE STANDARD TABLE OF zcl_zproj_982_mpc=>ts_item WITH DEFAULTKEY.

DATA: navschedule   TYPE STANDARD TABLE OF zcl_zproj_982_mpc=>ts_schedule WITHDEFAULT KEY,

END OF ls_order_items,

ls_item1       TYPE zcl_zproj_982_mpc=>ts_item,

ls_schedle1    TYPE zcl_zproj_982_mpc=>ts_schedule.

*————————————————————————-*

*             Data Declarations

*————————————————————————-*

DATA :   ls_item                    TYPE zcl_zproj_982_mpc_ext=>ts_item,

lt_item                    TYPE TABLE OF zcl_zproj_982_mpc_ext=>ts_item,

ls_sch                     TYPE zcl_zproj_982_mpc_ext=>ts_schedule,

lt_sch                     TYPE TABLE OF zcl_zproj_982_mpc_ext=>ts_schedule,

ls_header                  TYPE zcl_zproj_982_mpc_ext=>ty_header,

lthead                     TYPE STANDARD TABLE OF bapiekkol,

lshead                     TYPE bapiekkol,

lsitem                     TYPE bapiekpo,

ltitem                     TYPE STANDARD TABLE OF bapiekpo,

lv_filter_str              TYPE string,

lt_filter_select_options   TYPE /iwbep/t_mgw_select_option,

ls_filter                  TYPE /iwbep/s_mgw_select_option,

ls_filter_range            TYPE /iwbep/s_cod_select_option,

ls_expanded_clause1        LIKE LINE OF           et_expanded_tech_clauses,

ls_expanded_clause2        LIKE LINE OF           et_expanded_tech_clauses,

lv_ebeln                   TYPE ebeln,

lt_order_items             LIKE TABLE OF ls_order_items,

ltsch                      TYPE STANDARD TABLE OF bapieket,

lssch                      TYPE bapieket.

*————————————————————————-*

*             Entity Set – HeaderSet

*————————————————————————-*

CASE iv_entity_set_name.

WHEN ‘HeaderSet’.

LOOP AT it_filter_select_options INTO ls_filter.

LOOP AT ls_filter–select_options INTO ls_filter_range.

TRANSLATE ls_filter–property TO UPPER CASE.

CASE ls_filter–property.

WHEN ‘PONUMBER’.

lv_ebeln = ls_filter_range–low.

WHEN OTHERS.

” Log message in the application log

me->/iwbep/if_sb_dpc_comm_services~log_message(

EXPORTING

iv_msg_type   = ‘E’

iv_msg_id     = ‘/IWBEP/MC_SB_DPC_ADM’

iv_msg_number = 020

iv_msg_v1     = ls_filter–property ).

” Raise Exception

RAISE EXCEPTION TYPE /iwbep/cx_mgw_tech_exception

EXPORTING

textid = /iwbep/cx_mgw_tech_exception=>internal_error.

ENDCASE.

ENDLOOP.

ENDLOOP.

*————————————————————————-*

*             Call Method-BAPI_PO_GETDETAIL

*————————————————————————-*

CALL FUNCTION ‘BAPI_PO_GETDETAIL’

EXPORTING

purchaseorder     = lv_ebeln

items             = ‘X’

schedules         = ‘X’

IMPORTING

po_header         = lshead

*         PO_ADDRESS        =

TABLES

*         PO_HEADER_TEXTS   =

po_items          = ltitem

po_item_schedules = ltsch.

*————————————————————————-*

*             Fill Header Values to Deep Structure

*————————————————————————-*

ls_order_items–ponumber = lshead–po_number.

ls_order_items–ccode = lshead–co_code.

ls_order_items–doctype = lshead–doc_type.

*————————————————————————-*

*             Fill Item values to Deep Structure

*————————————————————————-*

LOOP AT ltitem INTO lsitem.

CLEAR ls_item1.

ls_item1–ponumber = lsitem–po_number.

CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_OUTPUT’

EXPORTING

input  = ls_item1–ponumber

IMPORTING

output = ls_item1–ponumber.

ls_item1–poitem = lsitem–po_item.

ls_item1–material = lsitem–material.

APPEND ls_item1 TO ls_order_items–navitem.

ENDLOOP.

*————————————————————————-*

*             Fill Schedule values to Deep Strcture

*————————————————————————-*

LOOP AT ltsch INTO lssch.

CLEAR ls_item1.

*        ls_item1-ponumber = lsitem-po_number.

ls_schedle1–poitem = lssch–po_item.

ls_schedle1–serial = lssch–serial_no.

APPEND ls_schedle1 TO ls_order_items–navschedule.

ENDLOOP.

*————————————————————————-*

*             Assign the Navigation Proprties name to Expanded Tech clauses

*————————————————————————-*

ls_expanded_clause1  = ‘NAVITEM’.

ls_expanded_clause2  = ‘NAVSCHEDULE’.

APPEND ls_expanded_clause1 TO et_expanded_tech_clauses.

APPEND ls_expanded_clause2 TO et_expanded_tech_clauses.

*————————————————————————-*

*             Append Deep Strcture Values to Final Internal Table

*————————————————————————-*

APPEND ls_order_items TO lt_order_items.

*————————————————————————-*

*             Send back Response to Consumer

*————————————————————————-*

copy_data_to_ref(

EXPORTING

is_data = lt_order_items

CHANGING

cr_data = er_entityset ).

WHEN OTHERS.

ENDCASE.

ENDMETHOD.

Coding Part Done….Lets move to Testing

Test Case 1:

URI : /sap/opu/odata/sap/ZPROJ_982_SRV/HeaderSet?$filter=PoNumber eq ‘4500000163’&$expand=NavItem

Test Case 2:

URI : /sap/opu/odata/sap/ZPROJ_982_SRV/HeaderSet?$filter=PoNumber eq ‘4500000163’&$expand=NavItem,NavSchedule

For Expand Entity :-

From the modelling point of view there wont be any changes

but in DPC we need to Redefine the method /iwbep/if_mgw_appl_srv_runtime~get_expanded_entity.

Also there would be a small change in Code , Like Below

*————————————————————————-*

*             Deep Structure

*————————————————————————-*

DATA:  BEGIN OF ls_order_items.

INCLUDE       TYPE zcl_zproj_982_mpc=>ts_header.

DATA: navitem       TYPE STANDARD TABLE OF zcl_zproj_982_mpc=>ts_item WITH DEFAULTKEY.

DATA: navschedule   TYPE STANDARD TABLE OF zcl_zproj_982_mpc=>ts_schedule WITHDEFAULT KEY,

END OF ls_order_items,

ls_item1       TYPE zcl_zproj_982_mpc=>ts_item,

ls_schedle1    TYPE zcl_zproj_982_mpc=>ts_schedule.

copy_data_to_ref(

EXPORTING

is_data = ls_order_items

CHANGING

cr_data = er_entity ).

Hope this Blog now helps you to implement Expand Entity/Entityset

Waiting for your feed back and suggestions and more questions

转载于:https://www.cnblogs.com/ricoo/p/11243763.html

UI5-技术篇-Implementing Expand Entity/Entity Set相关推荐

  1. java dto entity,entity与DTO完全一致时

    完全一致 指的是entity与DTO之间参数名.参数类型.参数个数全部相同的情况 entity代码 package com.hxd.simple.domain.entity; import java. ...

  2. C#代码生成工具:文本模板初体验 使用T4批量修改实体框架(Entity Framework)的类名...

    转自:http://www.cnblogs.com/huangcong/archive/2011/07/20/1931107.html 在之前的文本模板(T4)初体验中我们已经知道了T4的用处,下面就 ...

  3. .net core Entity Framework 与 EF Core

    重点讲 Entity Framework Core ! (一)Entity Framework 它是适用于.NET 的对象关系映射程序 (ORM),现在的EF6已经是久经沙场,并经历重重磨难,获得一致 ...

  4. Entity Framework 代码模板

    各种使用方式 EntityClient+EntitySQL string city = "London"; using (EntityConnection cn = new Ent ...

  5. 成功解决AttributeError: Parent variable ‘<Variable: ID (dtype = numeric)>‘ is not the index of entity En

    成功解决AttributeError: Parent variable '' is not the index of entity En 目录 解决问题 解决思路 解决方法 解决问题 Attribut ...

  6. Cesium原理篇:7最长的一帧之Entity(上)

    之前的最长的一帧系列,我们主要集中在地形和影像服务方面.简单说,之前我们都集中在地球是怎么造出来的,从这一系列开始,我们的目光从GLOBE上解放出来,看看球面上的地物是如何渲染的.本篇也是先开一个头, ...

  7. 史上最全总结!Util、POJO、domain、entity、model、DAO、DTO、view、mapper、service、controller的作用和区别分析

    文章目录 前言 工具类层 Util 数据层 POJO对象 domain entity model view DTO 总结 数据访问层 DAO mapper 业务层 service 控制层 Contro ...

  8. @Entity报错,配置pom.xml

    @Entity需要引用import javax.persistence.Entity; import javax.persistence.Entity; @Entity public class Us ...

  9. Entity Framework 普通操作(复习用)——感觉有点不对,需要撸代码验证

    方式一,使用Attach,并更新某个属性的值(注意,不是所有的属性都作修改) using (var context = new EFContext()) { //方式一 var entity = co ...

最新文章

  1. 10行代码爬取全国所有A股/港股/新三板上市公司信息
  2. heroku能用mysql吗_heroku连接到mysql数据库
  3. 强制删除正在运行的文件_win10系统上怎么强制删除文件
  4. Android官方导航栏ActionBar(二)—— Action View、Action Provider、Navigation Tabs的详细用法...
  5. spring集成mq_使用Spring Integration Java DSL与Rabbit MQ集成
  6. 计算机网络之网络概述:1、基本概念
  7. thinkpadx1mdt 网络启动_联想ThinkPad X1 Carbon 2020如何进入bios设置从U盘启动?
  8. java litjson_仿造 Gson 的自制 json 解析器
  9. 【LOJ10050】The XOR Largest Pair(字典树)
  10. SPOJ Can you answer the Queries系列
  11. Linux基础命令操作
  12. linux dosbox使用教程,在主流Linux操作系统上安装DOSBox的方法
  13. Android轮播换背景,Android实现背景图片轮播
  14. 代码参考--点击文本,即可复制
  15. 基于Domoticz智能家居系统(十四)用ESP8266做MQTT客户端实验
  16. JAVA-初步认识-第五章-数组-常见操作-进制转换(查表法)
  17. 一周侃 | 周末随笔
  18. 关于XML解析的常用方式
  19. 【提问的智慧】-[How To Ask Questions The Smart Way]
  20. 河道水面漂浮物识别检测系统 YOLOv7

热门文章

  1. 论文python爬虫_论的解释|论的意思|汉典“论”字的基本解释
  2. 图片加载未完成时的默认背景图处理(仅限自己封装的图片加载工具)
  3. ADT栈与队列的C语言编程与实现
  4. 分布式专题(六)分布式事物
  5. 一分钟读懂低功耗蓝牙连接数据包
  6. 常用深度学习数据集网址
  7. Autobahn实现WebSocket通信
  8. 浅谈一下光学合成孔径技术的原理(一)
  9. UML建模能力成为对日软件外包首要条件
  10. 【2017戴尔科技峰会剧透】中国智造=人工智能+制造