转载: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

UI5-技术篇-Implementing Expand Entity/Entity Set的更多相关文章

  1. Entity Framework 与 面向对象

    说要分享,我了个*,写了一半放草稿箱了两个星期都快发霉了,趁着周末写完发出来吧. 文章分为五部分: 基础.类讲述的是用到的一些EF与面向对象的基础: 业务是讲怎么划分设计业务: 设计模式和工作模式讲述 ...

  2. ABP源码分析十四:Entity的设计

    IEntity<TPrimaryKey>: 封装了PrimaryKey:Id,这是一个泛型类型 IEntity: 封装了PrimaryKey:Id,这是一个int类型 Entity< ...

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

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

  4. EF架构~linq to entity的随机排序问题

    回到目录 对于从linq to sql迁移过来的开发者,对随机排序不会感到陌生,直接为datacontext添加一个方法再配合反射就可以实现随机排序了,代码如下: /// <summary> ...

  5. Entity Framework 实体框架的形成之旅--数据传输模型DTO和实体模型Entity的分离与联合

    在使用Entity Framework 实体框架的时候,我们大多数时候操作的都是实体模型Entity,这个和数据库操作上下文结合,可以利用LINQ等各种方便手段,实现起来非常方便,一切看起来很美好.但 ...

  6. 基于DDD的.NET开发框架 - ABP的Entity设计思想

    返回ABP系列 ABP是“ASP.NET Boilerplate Project (ASP.NET样板项目)”的简称. ASP.NET Boilerplate是一个用最佳实践和流行技术开发现代WEB应 ...

  7. cocos2d-x开发: 场景实体(entity)管理

    公司现在开新项目,主题的框架部分都是我自己在做,不用受到别人的牵制,所以还算是比较的自由,很好发挥. 游戏并不大,所以需要用到的地方并不多.今天花了一些时间写了场景entity管理的部分代码,还没有完 ...

  8. 【转】What is an entity system framework for game development?

    What is an entity system framework for game development? Posted on 19 January 2012 Last week I relea ...

  9. Entity Framework 6新特性:全局性地自定义Code First约定

    2012年12月11日,Entity Framework已经发布了Entity Framework 6 Alpha2,因项目需要,目前已使用了其中的两个特性,今天就来介绍一下第一个特性:全局性地自定义 ...

随机推荐

  1. 【html】css、js实现网页内容禁止选中

    网页内容不能选中.复制应该如何实现呢? 通过css *{ moz-user-select: -moz-none; -moz-user-select: none; -o-user-select:none ...

  2. 【432】COMP9024,Exercise9

    eulerianCycle.c What determines whether a graph is Eulerian or not? Write a C program that reads a g ...

  3. Linux系统调优——系统整体运行状态排查(七)

    (1).vmstat vmstat命令是最常见的Linux/Unix监控工具,可以展现给定时间间隔的服务器的整体状态值,包括服务器的CPU使用率,MEM内存使用,VMSwap虚拟内存交换情况,IO读写 ...

  4. 123457123456#1#----com.MC.CarWashKidsGames234----前拼后广--洗车游戏mc-mc1111

    com.MC.CarWashKidsGames234----前拼后广--洗车游戏mc-mc1111

  5. LeetCode 429. N叉树的层序遍历(N-ary Tree Level Order Traversal)

    429. N叉树的层序遍历 429. N-ary Tree Level Order Traversal LeetCode429. N-ary Tree Level Order Traversal 题目 ...

  6. java实现根据特定密钥对字符串进行加解密功能

    在项目中我们经常遇到这样的场景,我们避免重要资源泄露需要将一些信息按照特定的方式(密钥)进行加密保存,然后在使用的时候再按照特定的方式(密钥)进行解密读取,以保证信息的相对安全.那么如何对信息进行加解 ...

  7. 解决idea tomcat乱码问题

    解决idea Server Output.TomcatLocalhost Log.Tomcat Catalina Log控制台乱码问题 问题原因:编码不一致,tomcat启动后默认编码UTF-8,而w ...

  8. Python列表生成式测试

    print('*'*50) list1 = list(range(1,6)) print(list1) del(list1) #range(1,20) 按顺序生成列表 list1 = [] for x ...

  9. 03 python 对象笔记

    类的命名方法 1.使用大驼峰命名法:每一个单词的首字母大写(第一个的也要)2.单词之间不需要下划线 对象的内置函数和属性 1.使用dir()函数来获取对象的内置方法和属性.返回值是一个列表.2.返回中 ...

  10. 数据结构-链式队列-C++

    用链表搭建的栈与队列相对简单,队列的特点是先进先出,不啰嗦了,由于代码比较简单,相信光顾的人不会太多,下面直接贴代码. 头文件 #ifndef QUEUELI_H #define QUEUELI_H ...