on 08-09-2013 4:42 PM
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!
Hi
After getting related entities
lv_children ?= lv_ent->get_related_entities( iv_relation_name = 'BuilRelationshipRel' ).
lv_size = lv_children->size( ).
If lv_size < 1.
Throw your error. and it means no relations exist for this BP.
else.
Implement your logic here to check the required relationships maintained or not.
endif.
Hope it helps
Thanks
Kumar.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kumar,
I have used your suggestion before creating this post and the size was always 0.
But I have found out why the collection size is 0 - this is because the assignment block was not displayed direct initially, but lazy for an account that has already been created and the relationships exist.
When I make it direct, or when I manually open up the relationship AB, the system loads the BOL entries properly and the collection is filled and the size is not 0 but the actual size.
When I further try to get the child relationship BuilPartnerFunctionRel of BuilRelationshipRel, the same thing happens - the collection size is 0. When I am in edit mode and if I display the information for each relationship, the collection is filled out.
I guess for performance reasons the system loads the necessary BOL objects when requested.
Is there a way to pre-load the relationship objects BuilRelationship and BuilPartnerFunction?
Thanks!
Hi Yordan
Normally when get_related_entities is called system should ideally load the Entities from API's even if they are not present at BOL level as this is the first time you are requesting for them.
May be you can try passing the IV_MODE as BYPASSING_BUFFER and check if this would help you to get the relations.
But try debugging and investigating why it is not loading the entities in Normal Mode.
Regards
Vinod
Hi Yordan,
I have run the same code in ABAP Report and there I am able to get related entities.
Try with core->LOAD_COMPONENT_SET( 'BP_APPL' ) instead of core->start_up( 'BP_APPL' ) if it helps.
Otherwise you need to debug and find out why you are not able to get the relationships.
Thanks
Kumar Gaurav.
Hi Kumar,
Thanks for the suggestion but I was using this statement in my code before.
Instead of the BAdI, I went with redefining the EH_ONSAVE event for the particular view and there the relationships were loading without problems.
The problem is that in the BAdI the behavior is different and I was wondering why. Maybe in the BAdI additional statement is required to load the related entities and I am missing something for sure.
Thanks,
Yordan
Hi Yordan,
The probable reason for not returning anything into lv_children is the BP on which you are trying to get the relations does not have any relations created at all. In such case the collection would be empty.
you can check for the collection size after the get_related entities and exit if it is less than 1 by throwing your error.
Weather this will work or not depends on the time this BAdI is triggered.
Regards
Vinod
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
3 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.