Hi Folks,

Finally got some time to write a Blog on something which was a common question from a lot of audience here, so doing my bit of help here .. hope this helps a lot of beginners and not for experts 😉

SAP Documentation for Expand Understanding


Some of the Blogs already posted in SCN relevant to Expand and Deep Entity .

Improved Inside-Out Modelling

Step by Step development for CREATE_DEEP_ENTITY operation


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.




Code Snippet

METHOD /iwbep/if_mgw_appl_srv_runtime~get_expanded_entityset.


*             Deep Structure


   DATABEGIN 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 DEFAULT KEY.

   DATA: navschedule   TYPE STANDARD TABLE OF zcl_zproj_982_mpc=>ts_schedule WITH DEFAULT 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_filterselect_options INTO ls_filter_range.

           TRANSLATE ls_filterproperty TO UPPER CASE.

           CASE ls_filterproperty.

             WHEN ‘PONUMBER’.

               lv_ebeln = ls_filter_rangelow.

             WHEN OTHERS.

               ” Log message in the application log



                   iv_msg_type   = ‘E’

                   iv_msg_id     = ‘/IWBEP/MC_SB_DPC_ADM’

                   iv_msg_number = 020

                   iv_msg_v1     = ls_filterproperty ).

               ” Raise Exception

               RAISE EXCEPTION TYPE /iwbep/cx_mgw_tech_exception


                   textid = /iwbep/cx_mgw_tech_exception=>internal_error.





*             Call Method-BAPI_PO_GETDETAIL




           purchaseorder     = lv_ebeln

           items             = ‘X’

           schedules         = ‘X’


           po_header         = lshead

*         PO_ADDRESS        =


*         PO_HEADER_TEXTS   =

           po_items          = ltitem

           po_item_schedules = ltsch.


*             Fill Header Values to Deep Structure


       ls_order_itemsponumber = lsheadpo_number.

       ls_order_itemsccode = lsheadco_code.

       ls_order_itemsdoctype = lsheaddoc_type.


*             Fill Item values to Deep Structure


       LOOP AT ltitem INTO lsitem.

         CLEAR ls_item1.

         ls_item1ponumber = lsitempo_number.



             input  = ls_item1ponumber


             output = ls_item1ponumber.

         ls_item1poitem = lsitempo_item.

         ls_item1material = lsitemmaterial.

         APPEND ls_item1 TO ls_order_itemsnavitem.



*             Fill Schedule values to Deep Strcture


       LOOP AT ltsch INTO lssch.

         CLEAR ls_item1.

*        ls_item1-ponumber = lsitem-po_number.

         ls_schedle1poitem = lsschpo_item.

         ls_schedle1serial = lsschserial_no.

         APPEND ls_schedle1 TO ls_order_itemsnavschedule.



*             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




           is_data = lt_order_items


           cr_data = er_entityset ).




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


   DATABEGIN 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 DEFAULT KEY.

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

        END OF ls_order_items,

        ls_item1       TYPE zcl_zproj_982_mpc=>ts_item,

        ls_schedle1    TYPE zcl_zproj_982_mpc=>ts_schedule.



           is_data = ls_order_items


           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 🙂



To report this post you need to login first.


You must be Logged on to comment or reply to a post.

  1. Andre Fischer

    Hi Sri,


    why are you using the method GET_EXPANDED_ENTITYSET when you are calling the BAPI ‘BAPI_PO_GETDETAIL’ with a single PO number as a key ?


    I would have expected GET_EXPANDED_ENTITYSET to be used when a method BAPI_PO_GETLIST would be called instead?


    Using GET_EXPANDED_ENTITYSET without using a proper filtering can have some unwanted side effects and in a typical UI you would not expand all subnodes of a list but only those of a selected item. For example the items of a purchase order including the schedule or the purchase orders of one business partner.


    Best Regards,


    1. Srikanth Gajula Post author

      Hi Andre,


      Thanks for your comment and Feedback,  Agree on the points mentioned by you


      i just took this as one of the examples and not for BAPI_PO_DEATAIL




  2. Arshad Ansary


    I followed the same method for getting one header (entity type HEADER )+ multiple lines(entity type LINE belonging to the header). But it is throwing error Line entity GET_ENTITYSET is not implemented in Gateway client .


    In debugger I found that its GET_EXPANDED_ENTITYSET is called with LINE entity type also.I returned when entity type is LINE in the method . In that case it was showing only records of Header .


    When I implemented LINE entity type GET_ENTITYSET it works fine. But the thing is I dont waht to make second call to he backend for LINE enitty type. I can get all th data in one go thats why i used GET_EXPANDED_ENTITYSET




  3. dikshith s

    I have implemented the expanded_entity method as per the above code but i haven’t received the dependent (child) details.


    Could you please suggest me what might be the problem?



    1. Ashwin Dutt R

      Hello Dikshith,


      Child details is not seen in the final response is it ? this is wat u mean i am unable to receive details of the child ?


      Please check the deep structure which u created in the DPC/DPC_EXT class.

      Names used while creating this should be as same as the navigation property which u have created while modelling ur GW service.




  4. Phani Vasabattula

    Thanks Sri. I have a question. Can I add filter to the expand entity? For example/sap/opu/odata/sap/ZPROJ_982_SRV/HeaderSet?$filter=PoNumber eq ‘4500000163’&$expand=NavItem?$filter=’XYZ’ eq ‘12345’.

  5. Sathish Kumar

    Hi Sri,

             I followed the same stpes, but for me GET_EXPANDED_ENTITYSETis working fine but GET_EXPANDED_ENTITY not returning any values.


    In the method GET_EXPANDED_ENTITY, the value getting passed to the structure  er_entity.But in the method READ_EXPANDED_ENTITY (/IWBEP/CL_MGW_ABS_DATA) the value not passing to the structure cr_entity.

        IF lr_entity NE cr_entity.

    *—–it isn’t the same ref – required to copy the data to the deep structure ref – deep copy if required



              ir_source_data = lr_entity


              er_target_data = cr_entity


        ENDIF. ( Not working).


    Navigation property & Deep structure name also same.


    Please help me on which case this issue may occur.



    1. Manu Shetty

      Hi Sathish,


      Even i faced the same issue, Pls check if the component names of cr_entity and lr_entity are same while debugging… this can happen when you define declare a deep structure within your get_expanded_entity.

      in my case there was a mismatch in the deep structure name which i had defined within the get_expanded_entity method.


      if you see a mismatch, correct the component name accordingly in the data declaration of get_expanded_entity method.


      Just make sure you keep the following names same : e.g., ORDERTOITEM

      1. Item table name within the deep structure

      2. NAV Property name for Header Key Field.

      3. ABAP Fieldlist name, this you will find when you open the association in the Header(SEGW)

  6. Kavitha Fredrick


    I have similar requirement, I have implemented required code…on debugging I’m able to see all values getting filled in deep structure.

    However, in result, I get only the header properties and all inline feed(items) are not getting filled.


    Can someone help?


Leave a Reply