Knowledge prepare:

Topic: Expand in Framework and Data Provider

URI:    Expand in Framework and Data Provider – SAP NetWeaver Gateway – SAP Library

 

A request with a $expand query option enables the reading of entries of an entity together with an associated entity.

 

Below is some blogs posted in SCN about expand, I would like to show my respect to them here.

Step-by-step guide to build an OData Service based on RFCs – Part 3

Ok, now let us start.

1. Create a Entity Name: ApplicationLog

Entity Set Name: ApplicationLogCollection

2. Set ABAP structure and Properties for Entity Name: ApplicationLog.

3. Create Association Name: Task_To_M_ApplicationLog.

click [Next], fill in Referential Constraints

click [Next]–>click [finish].

4.Click [Generate Runtime Object ] and make sure the message with “Runtime Objects for project ‘xxxx’ generated”.

 

5. Test metadata

6.Create class: CL_CRM_ODATA_RT_ApplicationLog  (Runtime Class for ApplicationLog)

Code Snippet:

Class:CL_CRM_ODATA_RT_ApplicationLog

Method: /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_ENTITYSET

DATA: applicationlog_get_entityset TYPE cl_crm_odata_mpc=>tt_applicationlog.

” EntitySet -ApplicationLogCollection

IF iv_entity_set_name = gc_application_log_collection.

applicationlog_get_entityset(

EXPORTING

iv_entity_name = iv_entity_name

iv_entity_set_name = iv_entity_set_name

iv_source_name = iv_source_name

it_filter_select_options = it_filter_select_options

it_order = it_order

is_paging = is_paging

it_navigation_path = it_navigation_path

it_key_tab = it_key_tab

iv_filter_string = iv_filter_string

iv_search_string = iv_search_string

io_tech_request_context = io_tech_request_context

IMPORTING

et_entityset = applicationlog_get_entityset

es_response_context = es_response_context

).

*     Send specific entity data to the caller interface

copy_data_to_ref(

EXPORTING

is_data = applicationlog_get_entityset

CHANGING

cr_data = er_entityset

).

 

Class:CL_CRM_ODATA_RT_ApplicationLog

Method: /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_EXPANDED_ENTITY

 

DATA: lr_bupa_provider TYPE REF TO cl_crm_bp_odata_data_provider,

lv_bupa_supports TYPE abap_bool.

CREATE OBJECT lr_bupa_provider.

lv_bupa_supports = lr_bupa_provider->supports_entity( EXPORTING iv_entity_name = iv_entity_name ).

IF iv_entity_name = GC_TASK.

IF go_task_impl IS NOT BOUND.

CREATE OBJECT go_task_impl

EXPORTING

ir_context = mo_context.

ENDIF.

go_task_impl->get_task_expanded_entity(

EXPORTING

iv_entity_name               = iv_entity_name

iv_entity_set_name           = iv_entity_set_name

iv_source_name               = iv_source_name

it_key_tab                   = it_key_tab

it_navigation_path           = it_navigation_path

io_expand                    = io_expand

io_tech_request_context      = io_tech_request_context

IMPORTING

er_entity                    = er_entity

et_expanded_clauses          = et_expanded_clauses    ” Table of Strings

et_expanded_tech_clauses     = et_expanded_tech_clauses    ” Table of Strings

).

ELSEIF lv_bupa_supports = ‘X’.

CALL METHOD lr_bupa_provider->/iwbep/if_mgw_core_srv_runtime~set_context

EXPORTING

io_context = mo_context.

CALL METHOD lr_bupa_provider->/iwbep/if_mgw_appl_srv_runtime~get_expanded_entity

EXPORTING

iv_entity_name           = iv_entity_name

iv_entity_set_name       = iv_entity_set_name

iv_source_name           = iv_source_name

it_key_tab               = it_key_tab

it_navigation_path       = it_navigation_path

io_expand                = io_expand

io_tech_request_context  = io_tech_request_context

IMPORTING

er_entity                = er_entity

et_expanded_clauses      = et_expanded_clauses

et_expanded_tech_clauses = et_expanded_tech_clauses.

ENDIF.

 

Class:CL_CRM_ODATA_RT_ApplicationLog

Method: APPLICATIONLOG_GET_ENTITYSET

 

TRY.

DATA: lv_obj_guid TYPE crmt_object_guid.

FIELD-SYMBOLS TYPE /iwbep/s_mgw_name_value_pair.

READ TABLE it_key_tab ASSIGNING WITH KEY name = GC_GUID.

IF IS ASSIGNED AND value IS NOT INITIAL.

lv_obj_guid = value.

CALL METHOD gr_task_rt->get_log_data

EXPORTING

iv_object_guid = lv_obj_guid

IMPORTING

et_log         = et_entityset.

ENDIF.

CATCH /iwbep/cx_mgw_busi_exception .

CATCH /iwbep/cx_mgw_tech_exception .

ENDTRY.

7. Then you can test for the entity by below 2 kinds of URIs.

(1)/sap/opu/odata/sap/CRM_ODATA/TaskCollection(guid’xxxxx’)/ApplicationLogs

      (2)/sap/opu/odata/sap/CRM_ODATA/TaskCollection(guid’xxxxx’)/?$expand=ApplicationLogs

8.Finished.

New NetWeaver Information at SAP.com

Very Helpfull

 

 

User Rating: Be the first one !