I've had a problem assigning a newly created rental space (cut out of a poolspace) to an object group.
I solved it and want to blog it to prevent other real estate developers from running into this mess with assigning rental objects to an object group.
At first, I was trying my luck with CL_REBD_OBJ_ASSIGN_MNGR_BO. But due to the fact, that there is only a interface available with OBJASSTYPE = '10' (Contract=>Object Group),
Table TIVBDOBJASSTYPE:
OBJASSTYPE IMPLIFNAME GUIFMPBO XOBJASSTYPE
10 IF_REBD_OBJ_ASSIGN_MNGR_BO REBD_GUI_OBJASS_BO_PBO Vertrag => Objekt(gruppe)
11 REBD_GUI_OBJASS_BO_PBO Objektgruppe => Objekt (Object Group => Rental Object)
Later I discovered, that the GUI is using using the class CL_RECN_OBJ_ASSIGN_MNGR_CN to accomplish what I wanted to do.
At first, I was not able to apply a method to do just that with objasstype 11.
As you can see in the table, type 11 can only be handled in the GUI PBO Module. That's why I wrote nearly a copy of the code I found there when I debugged the '+' Button to add an object to the object group in the GUI.
Surprisingly there's this simple insert_bus_object-method at the end of the code snippet that does the job.
Everything works fine in the insert_bus_object-method, it quits with sy-subrc = 0:
Code |
---|
METHOD add_rental_space_to_objgroup. * Fügt ein Mietobjekt in eine Objektgruppe ein DATA: lo_obj_assign_mngr_cn TYPE REF TO cl_recn_obj_assign_mngr_cn, lt_obj_assign_bo TYPE re_t_obj_assign_bo, lt_object_objtype TYPE re_t_reca_object_objtype_x, ls_obj_assign TYPE rebd_obj_assign, ls_obj_assign_bo LIKE LINE OF lt_obj_assign_bo, ls_object_objtype LIKE LINE OF lt_object_objtype, ld_objnr TYPE recaobjnr, ld_adjustnumber TYPE rebd_obj_assign_bo_x-adjustnumber, lf_assignonlyinfo TYPE recabool, lo_bo TYPE REF TO if_reca_bus_object, ld_ident TYPE recaident.
* init * Object Assign Manager Contract lo_obj_assign_mngr_cn = io_obj_assign_mngr_cn. CLEAR: lf_assignonlyinfo.
* I. Which object will be added? ld_objnr = iv_objnr.
* II. get allowed object information CLEAR: lt_object_objtype. lt_object_objtype = lo_obj_assign_mngr_cn->get_objtypes_allowed( ). * {lo_obj_assign_mngr muss vom Typ \CLASS=CL_RECN_OBJ_ASSIGN_MNGR_CN sein!}
* set valid from and valid to of assignment ls_obj_assign-validfrom = md_sheet_date. ls_obj_assign-validto = reca0_date-max.
* III. check if object already is present CALL METHOD lo_obj_assign_mngr_cn->get_list_bo EXPORTING id_objnrtrg = ld_objnr if_fix_periods = abap_false IMPORTING et_list = lt_obj_assign_bo.
*--> no entries in this table!
* delete generated entries DELETE lt_obj_assign_bo WHERE ismultiassgen = abap_true.
* if yes use current date for insertion... IF lo_obj_assign_mngr_cn->is_attribute_supported( id_attribute = rebd2_objass_attribute-period ) = abap_true. * => it's not true in my case, scroll down! READ TABLE lt_obj_assign_bo INTO ls_obj_assign_bo WITH KEY objnrtrg = ld_objnr validfrom = ls_obj_assign-validfrom. IF sy-subrc = 0. ls_obj_assign-validfrom = sy-datum. LOOP AT lt_obj_assign_bo INTO ls_obj_assign_bo WHERE objnrtrg = ld_objnr. IF ls_obj_assign_bo-validto > ls_obj_assign-validfrom. IF ls_obj_assign_bo-validto <> reca0_date-max. ls_obj_assign-validfrom = ls_obj_assign_bo-validto + 1. ENDIF."ls_obj_assign_bo-validto <> reca0_date-max. ENDIF."ls_obj_assign_bo-validto > ls_obj_assign-validfrom. ENDLOOP."AT lt_obj_assign_bo INTO ls_obj_assign_bo ENDIF."READ TABLE lt_obj_assign_bo INTO ls_obj_assign_bo
ELSE. READ TABLE lt_obj_assign_bo INTO ls_obj_assign_bo WITH KEY objnrtrg = ld_objnr validfrom = ls_obj_assign-validfrom adjustnumber = ld_adjustnumber. IF sy-subrc = 0. CALL METHOD cf_reca_bus_object=>find_by_objnr EXPORTING id_objnr = ld_objnr RECEIVING ro_instance = lo_bo EXCEPTIONS error = 1 OTHERS = 2. IF sy-subrc <> 0. * mac_symsg_send_as_type 'S'. * CONTINUE. ENDIF."find_by_objnr
* ? CALL METHOD lo_bo->get_ident IMPORTING ed_ident = ld_ident. * MESSAGE s028(rebdoa) WITH ld_ident. * CONTINUE. ENDIF."READ TABLE lt_obj_assign_bo INTO ls_obj_assign_bo ENDIF."go_obj_assign_mngr->is_attribute_supported
************************ * MAIN RUN STARTS HERE * ************************ CLEAR ls_object_objtype. READ TABLE lt_object_objtype INTO ls_object_objtype WITH KEY objtype = ld_objnr(2). "IM
lf_assignonlyinfo = abap_false. * Insert Rental Space to Object Group CALL METHOD lo_obj_assign_mngr_cn->insert_bus_object EXPORTING id_objnr = ld_objnr id_validfrom = ls_obj_assign-validfrom id_validto = ls_obj_assign-validto id_adjustnumber = lc_adjustnr_10 id_assignonlyinfo = lf_assignonlyinfo IMPORTING es_obj_assign = ls_obj_assign EXCEPTIONS error = 1 OTHERS = 2. IF sy-subrc <> 0. * mac_symsg_send_as_type 'S'. * CONTINUE. ENDIF. |
Checking the resulting contract with this rental space delivers in tab Objects the wanted hierarchy Object Group -> Rental Space.
Don't forget to check_all, store and commit your data of the created contract object!
P.S.: I would have expected a method in the Object Group-Interface IF_REBD_OBJECT_GROUP or an Interface in TIVBDOBJASSTYPE like IF_REBD_OBJ_ASSIGN_MNGR_BO with OBJASSTYPE = 11 which does the job!