Generic Object Services (GOS) Toolbar Part 7 : Relationship Browser

By | November 18, 2010 | Generic Object Services (GOS) | 7,070 | 0

Relationships in GOS Toolbar

In the series of Generic Object Services(GOS) available in the SAP, we have discussed different usage of the GOS toolbar. You can find all of these discussions at Tutorials > Generic Object Services (GOS).

Today, we’ll see the another concept: Relationship browser. Relationships option is available in the GOS Toolbar at GOS toolbar > Relationships.

This browser could display different linked objects like Sales Documents, Inbound IDOCs, Outbound IDOcs etc.

Now lets see how to add this Relationships in this relationship browser. For this purpose, we can use method CREATE_LINK of the class CL_BINARY_RELATION or the FM BINARY_RELATION_CREATE.

Method CREATE_LINK is an advanced version to create the Link which would be displayed in the Relationship browser. Since the method CREATE_LINK is an improved version to create the links, it doesn’t support all the object models. For the remaining of the object models, we need to use the FM BINARY_RELATION_CREATE. So, the question is how to know when to use FM.

When the relation model is not supported by the method CREATE_LINK, it raises the exception CX_OBL_MODEL_ERROR. So, we’ll call the method CREATE_LINK inside the TRY … CATCH … ENDTRY block.

This Code Snippet shows how to use the method to create links in the relationship browser.

*& Developer: Naimesh Patel
*& Purpose  : To Create Relation between Business Objects
REPORT  zgos_relation_create.
CLASS lcl_relation DEFINITION.
      BEGIN OF ty_related.
            INCLUDE TYPE sibflporb.
        relation TYPE oblreltype,
      END   OF ty_related.
      ty_t_related TYPE STANDARD TABLE OF ty_related.
          obj_no   TYPE sibfboriid
          obj_type TYPE sibftypeid
          obj_cat  TYPE sibfcatid.
          obj_no   TYPE sibfboriid
          obj_type TYPE sibftypeid
          obj_cat  TYPE sibfcatid
          relation TYPE oblreltype.
      t_related TYPE ty_t_related,  "sibflporbt,
      my_prop   TYPE sibflporb.
ENDCLASS.                    "lcl_relation DEFINITION
  METHOD constructor.
*   Set Properties of Referent
    me->my_prop-instid obj_no.
    me->my_prop-typeid obj_type.
    me->my_prop-catid  obj_cat.
  ENDMETHOD.                    "constructor
  METHOD add_relation.
*   Add Referenc
    FIELD-SYMBOLS<lfs_relat> LIKE LINE OF me->t_related.
    APPEND INITIAL LINE TO me->t_related ASSIGNING <lfs_relat>.
    <lfs_relat>-instid obj_no.
    <lfs_relat>-typeid obj_type.
    <lfs_relat>-catid  obj_cat.
    <lfs_relat>-relation relation.
  ENDMETHOD.                    "add_relation
  METHOD create_relations.
    DATAlwa_relate_key TYPE sibflporb.
    FIELD-SYMBOLS<lfs_relat> LIKE LINE OF me->t_related.
      ls_parent   TYPE borident,
      ls_related  TYPE borident,
      lv_relation TYPE binreltyp,
      lx_obl    TYPE REF TO cx_obl,
      lp_errstr TYPE string,
      lv_done TYPE flag.
*   for each relation
    LOOP AT me->t_related ASSIGNING <lfs_relat>.
      MOVE-CORRESPONDING <lfs_relat> TO lwa_relate_key.
*      First try with new method to create the Link
          CALL METHOD cl_binary_relation=>create_link
              is_object_a my_prop
              is_object_b lwa_relate_key
              ip_reltype  <lfs_relat>-relation.
          lv_done 'X'.
*       If the Link can not be handled by this class, call the
*       FM to create the link
        CATCH cx_obl_model_error.
          ls_parent-objkey  me->my_prop-instid.
          ls_parent-objtype me->my_prop-typeid.
          ls_related-objkey  <lfs_relat>-instid.
          ls_related-objtype <lfs_relat>-typeid.
          lv_relation <lfs_relat>-relation.
              obj_rolea      ls_parent
              obj_roleb      ls_related
              relationtype   lv_relation
              no_model       1
              internal_error 2
              unknown        3
              OTHERS         4.
          IF sy-subrc <> 0.
            MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
                    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
            lv_done 'X'.
        CATCH cx_obl INTO lx_obl.
          lp_errstr lx_obl->get_text).
          MESSAGE lp_errstr TYPE 'S'.
      IF lv_done 'X'.
        WRITE'Relation added: '<lfs_relat>-instid(10), <lfs_relat>-relation.
  ENDMETHOD.                    "create_relations
ENDCLASS.                    "lcl_relation IMPLEMENTATION
  DATAo_relation TYPE REF TO lcl_relation.
* Sales Order as the Referent
  CREATE OBJECT o_relation
      obj_no   '1000010010'        " Sales Order Number
      obj_type 'BUS2032'           " Sales Order
      obj_cat  'BO'.
* Add Delivery to Sales Order
    obj_no   '8000020000'
    obj_type 'LIKP'
    obj_cat  'BO'
    relation 'LINK' ).             " Link
* Add IDOC to Sales Order
    obj_no   '1000012345'
    obj_type 'IDOC'
    obj_cat  'BO'
    relation 'IDC0' ).             " IDOC
* Create Relations

After successful program run, it will display the relationship in the browser of the Order.

Like It? Share!!

Don't miss an Update

Get notified of the new post, right into your inbox

Naimesh Patel{271 articles}

I'm SAP ABAP Consultant for more than a decade. I like to experiment with ABAP especially OO. I have been SDN Top Contributor.
Follow :

Explore all of his 271 articles.

Load comments

Comments on this Post are now closed. If you have something important to share, you can always contact me.

You seem to be new here. Subscribe to stay connected.