Sei sulla pagina 1di 3

6/29/2014 Copy BOL node trees dynamically - CRM - SCN Wiki

http://wiki.scn.sap.com/wiki/display/CRM/Copy+BOL+node+trees+dynamically 1/3
Getting Started Newsletters Store
Search the Community


Welcome, Guest Login Register
Products Services & Support About SCN Downloads
Industries Training & Education Partnership Developer Center
Lines of Business University Alliances Events & Webinars Innovation
Added by Guest, last edited by Van Han Nguyen on May 14, 2012
CRM / / CRM Web Client UI Framework
Copy BOL node trees dynamically
This was developed on CRM 2007 and may work on CRM 4.0
A quite common problem in the last projects was the lack of standard f unctionality to copy trees of BOL nodes dynamically.
This is f or example necessary when editing sales area data of business partners. Sales Area data of ten contains many f ields or tables which have to be maintained f or each Sales Area. The most of the
f ields are however similar f or more than one sales area and it might be interesting to copy the values f rom one Sales Area to another.
This example shall explain how to copy the data f rom one object to another.
Declares the local data:
Gets the components loaded and f etches the sub relations and assignes it to relations table
TYPES:
BEGIN OF ltype_child_object,
parent TYPE crmt_ext_obj_name,
relation TYPE crmt_relation_name,
objects TYPE REF TO if_bol_entity_col,
END OF ltype_child_object.
DATA:
lr_entity TYPE REF TO cl_crm_bol_entity,
lr_obj_to_copy TYPE REF TO cl_crm_bol_entity,
lr_orig_rel TYPE REF TO if_bol_entity_col,
lr_child_ent TYPE REF TO cl_crm_bol_entity,
lr_header TYPE REF TO cl_crm_bol_entity,
lv_index TYPE int4,
ls_sales_area TYPE crmt_bus_sales_area,
lt_return TYPE bapiret2_t,
ls_return TYPE bapiret2,
lr_object_model TYPE REF TO if_genil_obj_model,
lr_object_model_ TYPE REF TO cl_crm_genil_obj_model,
lr_relations TYPE REF TO crmt_relation_name_tab,
lv_rel_name TYPE crmt_relation_name,
lt_relations TYPE crmt_relation_name_tab,
lt_components_loaded TYPE genil_component_tab,
ls_child TYPE ltype_child_object,
lt_children TYPE TABLE OF ltype_child_object,
lr_rel_ent TYPE REF TO cl_crm_bol_entity,
lv_att_struc_name TYPE strukname,
ref_rowtype TYPE REF TO cl_abap_structdescr,
lv_relname TYPE crmt_relation_name,
lv_is_11 TYPE crmt_boolean,
ref_wa TYPE REF TO data.

FIELD-SYMBOLS: <attr> TYPE ANY,
<value> TYPE ANY TABLE.
lr_object_model = cl_crm_genil_model_service=>get_runtime_model( ).
lr_object_model_ ?= lr_object_model.
lt_components_loaded = lr_object_model_->get_components_loaded( ).

6/29/2014 Copy BOL node trees dynamically - CRM - SCN Wiki
http://wiki.scn.sap.com/wiki/display/CRM/Copy+BOL+node+trees+dynamically 2/3
f etch all child objects and append to table
Create a new BuilSalesArrangement object
Bind the newly created object to BP
Now we have to f ill the newly created object and create child objects containing the copied values f rom the original object. In order to do this two loops can be used: First loop through all possible sub
objects and loop in a inner loop throught the entities in the entity collection
lr_relations = lr_object_model->get_modeled_relations( iv_object_name = 'BuilSalesArrangement' ).
ASSIGN lr_relations->* TO <value>.
lt_relations = <value>.
LOOP AT lt_relations INTO lv_rel_name.
CLEAR: ls_child.

ls_child-parent = lr_obj_to_copy->get_name( ).
lr_orig_rel = lr_obj_to_copy->get_related_entities(
iv_mode = cl_crm_bol_entity=>bypassing_buffer
iv_relation_name = lv_rel_name ).

ls_child-relation = lv_rel_name.
ls_child-objects ?= lr_orig_rel.
APPEND ls_child TO lt_children.
ENDLOOP.
TRY.
lr_entity = lr_header->create_related_entity(
iv_relation_name = 'BuilSalesArrangementRel' ).
CATCH cx_crm_genil_model_error cx_crm_genil_duplicate_rel.
* should never happen
ENDTRY.
IF lr_entity IS BOUND.
typed_context->builsalesarrangement->collection_wrapper->add( iv_entity = lr_entity
iv_set_focus = abap_true ).
LOOP AT lt_children INTO ls_child.
lr_rel_ent ?= ls_child-objects->if_bol_entity_col~get_first( ).
WHILE lr_rel_ent IS BOUND.

* get relation name
lr_rel_ent->get_parent_relation(
IMPORTING
ev_relation_name = lv_relname
ev_relation_is_11 = lv_is_11
).

* get the name of the structure of the BOL object and create a new
* field symbol with this type
lv_att_struc_name = lr_rel_ent->get_attr_struct_name( ).
ref_rowtype ?= cl_abap_typedescr=>describe_by_name( lv_att_struc_name ).
CREATE DATA ref_wa TYPE HANDLE ref_rowtype.
ASSIGN ref_wa->* TO <attr>.

* get properties of subobject into field symbol
lr_rel_ent->if_bol_bo_property_access~get_properties(
IMPORTING es_attributes = <attr> ).

* create new subobject for copied sales organization with the
* original values
lr_child_ent = lr_entity->create_related_entity(
iv_relation_name = lv_relname ).
6/29/2014 Copy BOL node trees dynamically - CRM - SCN Wiki
http://wiki.scn.sap.com/wiki/display/CRM/Copy+BOL+node+trees+dynamically 3/3
lr_child_ent->set_properties( <attr> ).

lr_rel_ent = ls_child-objects->if_bol_entity_col~get_next( ).
ENDWHILE.

lv_index = typed_context->builsalesarrangement->collection_wrapper->size( ).

ENDLOOP.

ENDIF.
crm abap bol ui bsp
6 Comments
Guest
Hi,
I f ound your wiki f or copying BOL node trees in the sdn and wanted to do something similar.
Unf ortunately I don't have the type ltype_child_object, available.Is that program supposed to run under CRM 2007 or is it already CRM 7.0?
Thank's f or any hints ...
Regards Gerhard
Guest
Hi Gerhard,
I have used the code in CRM 2007. ltype_child_object is a local type of the f ollowing components and types: PARENT (CRMT_EXT_OBJ_NAME), RELATION (crmt_relation_name), OBJECTS
(TYPEREF TO if _bol_entity_col).
/Florian
Guest
Hi,
thanks f or your help!
Adding the type def inition solved the problem.
Best regards Gerhard
Vigneswararao Vankayala
really thank you..
Guest
Hi,
thanks nice articel on BOL programming.
Guest
Hi Florian,
Wiki is really interesting and helping me a lot.
How do you get an instance of lr_obj_to_copy in your example?
Thanks
Deepak
Follow SCN
Contact Us SAP Help Portal
Privacy Terms of Use Legal Disclosure Copyright

Potrebbero piacerti anche