Skip to Content
0
Former Member
Aug 09, 2013 at 03:42 PM

Get Related Entities

1251 Views

Hello Experts,

I am trying to implement a BAdI IF_EX_BUPA_FURTHER_CHECKS~CHECK_CENTRAL that checks whether mandatory relationships have been maintained when creating new account on save. The BAdI triggers just fine.

I am trying to implement this check by accessing the BOL model BP_APPL from the BAdI.

DATA: lv_ent TYPE REF TO cl_crm_bol_entity,

ent_rel TYPE REF TO cl_crm_bol_entity,

query TYPE REF TO cl_crm_bol_query_service,

result TYPE REF TO if_bol_bo_col,

ev_reltype type string,

lv_children TYPE Ref TO if_bol_entity_col,

lv_result TYPE REF TO CL_CRM_BOL_ENTITY_COL.

DATA: core TYPE REF TO cl_crm_bol_core.

core = cl_crm_bol_core=>get_instance( ).

core->start_up( 'BP_APPL' ).

* Get Parent Entity Details (BP):

query = cl_crm_bol_query_service=>get_instance( 'BuilHeaderSearch' ).

query->set_property( iv_attr_name = 'PARTNER'

iv_value = iv_partner ).

result ?= query->get_query_result( ).

lv_ent ?= result->get_first( ).

IF lv_ent IS BOUND.

lv_children ?= lv_ent->get_related_entities( iv_relation_name = 'BuilRelationshipRel' ).

ent_rel ?= lv_children->GET_FIRST( ).

* Here is where I was thinking of getting the relationship category name

* WHILE lv_children is bound.

* if ent_rel is bound.

* ev_reltype = ent_rel->GET_PROPERTY_AS_STRING( 'RELATIONSHIPCATEGORY' ).

* endif.

I was planning to throw an error if the relationship category was not found and prevent the account from saving:

CALL FUNCTION 'BALW_BAPIRETURN_GET2'

EXPORTING

type = 'E'

cl = /my message class/

number = /my message no/

IMPORTING

return = ls_return.

append ls_return to et_return.

For some reason the collection lv_children does not return any entities. Can anybody tell me what I am doing wrong and most importantly will this logic do the job?

Thanks!