二维码

[教程] LITTLE COMPLEX CODING IN EVENT HANDLER

Twilight发表于 2015-12-05 00:30Twilight 最后回复于 2015-12-05 00:30 [复制链接] 2883 0

Go to the event handler of result view EH_ONOBJECTID and do the following modifications to set the data in the custom controller context node.

Logic:
  • We need to find out on which record user has clicked in the result view and we will read that record.
  • Get the instance of custom controller.
  • Add the found record in the first step to the context node of custom controller.

go to the event handler and do the following changes in the code.
  1. METHOD eh_onobjectid.

  2.   DATA:lr_clickedrecord TYPE REF TO cl_crm_bol_entity,
  3.        lr_order TYPE REF TO cl_crm_bol_entity,
  4.        lr_header  TYPE REF TO cl_crm_bol_entity,
  5.        lr_col  TYPE REF TO cl_crm_bol_bo_col,
  6.        lr_custcontroller TYPE REF TO zl_ztutcomp_cucosearch_impl,
  7.        lv_index TYPE i.

  8.   "find out the record index on which user clicked.
  9.   cl_thtmlb_util=>get_event_info( EXPORTING iv_event = htmlb_event_ex
  10.                                   IMPORTING ev_index = lv_index ).
  11.   CHECK lv_index IS NOT INITIAL.

  12.   "based on the index,fetch the record from the result context node.
  13.   lr_clickedrecord ?= me->typed_context->result->collection_wrapper->find( iv_index = lv_index ).
  14.   CHECK lr_clickedrecord IS BOUND.

  15.   "lr_clickedrecord is of type BTQRSrvCon,we need to get BTAdminH from it.
  16.   lr_order ?= lr_clickedrecord->get_related_entity( iv_relation_name = 'BTADVSSrvCon' ).
  17.   CHECK lr_order IS BOUND.
  18.   lr_header ?= lr_order->get_related_entity( iv_relation_name = 'BTOrderHeader' ).
  19.   CHECK lr_header IS BOUND.
  20.   CREATE OBJECT lr_col.
  21.   lr_col->if_bol_bo_col~add( lr_header ).

  22.   "get the custom controller instance.
  23.   lr_custcontroller ?= me->get_custom_controller( 'ZTUTCOMPONENT/CuCoSearch' ).

  24.   "add the found recored to the header context node of custom controller.
  25.   lr_custcontroller->typed_context->header->collection_wrapper->set_collection( lr_col ).

  26.   "calling the outbound plug of the view to start the navigation.
  27.   op_tooverviewpage( ).

  28. ENDMETHOD.
复制代码

Getting correct type record needs understanding the MODEL. In our case, lr_clickedrecord is of type Query Result Object BTQRSrvCon. But in the header view in the over view page and header context node of custom controller, we used BTAdminh entity. So we cannot add BTQRSrvCon directly.

We need to find out the BTAdminh from BTQRSrvCon. In these situations, we will use relationships between entities. We need to take a look at the MODEL. Based on the model, we will have to know what are the relationships that we have to use to fetch the required entities.
COMPLEX CODING 3.jpg

If we observe carefully, from the Query Result Object BTQRSrvCon, there is a relation ‘Association BTADVSSrvCon Child Cardinality 1’ to the Root Object BTOrder.

Again from Root Object BTOrder, there is relation ‘Composition BTOrderHeader Child Cardinality 1’ to the Access Object BTAdminH, which we required.

This is what exactly we have done in the coding. First we fetched the Border and then from the BTOrder, we fetched BTAdminH.

Don’t worry if you scared after reading this. Understanding model and writing code in BOL will require patience and time. The more practice you do , the more you gain.

What we need to remember is, get_related_entity will fetch the required entity from source entity based on the relation name.

We have completed the coding part as well. Go and test the application. Now we can see the data in the header view.
detail data.jpg

If we observe, the title of the page does not suit to the page as we are not searching for any contracts on this screen.

Back button at top right corner is disabled. Once we move from the search to overview page, there is no way to go back. Let us solve this first as it will take less time.
回复

使用道具 举报

快速回帖

本版积分规则
您需要登录后才可以回帖 登录 | 注册有礼

快速回复 返回顶部 返回列表