Thursday, August 27, 2015

CRM Web UI GET_RELATED_ENTITY, GET_RELATED_ENTITIES methods




If you need to get entities related (child entities), use GET_RELATED_ENTITY, GET_RELATED_ENTITIES methods

Using GET_RELATED_ENTITY, GET_RELATED_ENTITIES :


    DATA  :  lr_erpadminh     TYPE REF TO cl_crm_bol_entity,
             lr_erpcondh     TYPE REF TO cl_crm_bol_entity,
             lr_condh     TYPE REF TO if_bol_bo_property_access,
             lr_condcol TYPE REF TO if_bol_entity_col,
             lr_iterator TYPE REF TO if_bol_entity_col_iterator,
             lr_rate     TYPE REF TO if_bol_bo_property_access,
             lv_vbeln TYPE string ,
             lv_cond_value TYPE kwert,
             lv_curr TYPE waerk.

    DATA  :  lv_changeable TYPE boolean.

    TYPESBEGIN OF ty_condtype,
              znet_gp TYPE kwert,
              znet_gp_p TYPE kbetr,
              zgp TYPE kwert,
              zgp_p TYPE kbetr,
              zfrc TYPE kwert,
              zd01 TYPE kwert,
              znet_gp_cur TYPE waerk,
              znet_gp_p_cur TYPE waerk,
              zgp_cur TYPE waerk,
              zgp_p_cur TYPE waerk,
              zfrc_cur TYPE waerk,
              zd01_cur TYPE waerk,
              zdel_route TYPE route,
              zccs TYPE kschl,
              zoppt_desp TYPE descr_40,
              zsam_descp TYPE descr_40,
          END OF ty_condtype.

    DATA ls_condtype TYPE ty_condtype.



    lr_erpadminh ?=   me->typed_context->erpadminh->collection_wrapper->get_current).
    CHECK  lr_erpadminh IS BOUND.
    lr_erpadminh->get_property_as_value(  EXPORTING   iv_attr_name =   'VBELN'
                                          IMPORTING   ev_result    =   lv_vbeln .

*    CHECK  lv_vbeln IS NOT INITIAL.
    TRY.
        CALL METHOD lr_erpadminh->get_related_entity
          EXPORTING
            iv_relation_name 'ERPHeaderCondSet'
*           iv_mode          = normal
          RECEIVING
            rv_result        lr_erpcondh.
      CATCH cx_crm_genil_model_error .
    ENDTRY.
    IF lr_erpcondh IS BOUND.
      TRY.
          CALL METHOD lr_erpcondh->get_related_entities
            EXPORTING
              iv_relation_name 'ERPCondHAll'
*             iv_child_name    =
*             iv_mode          = NORMAL
*             iv_owned_only    = ABAP_FALSE
            RECEIVING
              rv_result        lr_condcol.
        CATCH cx_crm_genil_model_error .
      ENDTRY.


      CLEAR  lr_iterator ls_condtype.
      lr_iterator   lr_condcol->get_iterator).

      IF lr_iterator IS BOUND.
*      Reading the Net gross profit values ..
        CLEAR lr_rate.
        CALL METHOD lr_iterator->find_by_property
          EXPORTING
            iv_attr_name 'KSCHL_T'
            iv_value     text-004  "'Net Gross Profit'(004)
          RECEIVING
            rv_result    lr_rate.

        IF lr_rate IS BOUND.
          lr_rate->get_property_as_valueEXPORTING iv_attr_name 'KWERT'
                                          IMPORTING ev_result  lv_cond_value ).
          lr_rate->get_property_as_valueEXPORTING iv_attr_name 'WAERK'
                                                    IMPORTING ev_result  lv_curr ).

          ls_condtype-znet_gp lv_cond_value.
          ls_condtype-znet_gp_cur lv_curr.
        ENDIF.

*      Reading the Net Margin%  values ..
        CLEAR lr_rate ,lv_curr,  lv_cond_value.
        CALL METHOD lr_iterator->find_by_property
          EXPORTING
            iv_attr_name 'KSCHL_T'
            iv_value     text-005   "'Net Margin %'(005)
          RECEIVING
            rv_result    lr_rate.

        IF lr_rate IS BOUND.
          lr_rate->get_property_as_valueEXPORTING iv_attr_name 'KBETR'
                                          IMPORTING ev_result  lv_cond_value ).
          lr_rate->get_property_as_valueEXPORTING iv_attr_name 'WAERK'
                                                    IMPORTING ev_result  lv_curr ).
          ls_condtype-znet_gp_p lv_cond_value.
          ls_condtype-znet_gp_p_cur lv_curr.
        ENDIF.
*      Reading the Gross Profit values ..
        CLEAR lr_rate ,lv_curr,  lv_cond_value.
        CALL METHOD lr_iterator->find_by_property
          EXPORTING
            iv_attr_name 'KSCHL_T'
            iv_value     text-003 " 'Gross Profit'
          RECEIVING
            rv_result    lr_rate.

        IF lr_rate IS BOUND.
          lr_rate->get_property_as_valueEXPORTING iv_attr_name 'KWERT'
                                          IMPORTING ev_result  lv_cond_value ).
          lr_rate->get_property_as_valueEXPORTING iv_attr_name 'WAERK'
                                                    IMPORTING ev_result  lv_curr ).
          ls_condtype-zgp lv_cond_value.
          ls_condtype-zgp_cur lv_curr.
        ENDIF.
*      Reading the Margin% Values ..
        CLEAR lr_rate ,lv_curr,  lv_cond_value..
        CALL METHOD lr_iterator->find_by_property
          EXPORTING
            iv_attr_name 'KSCHL_T'
            iv_value     text-001   "'Margin %'(001)
          RECEIVING
            rv_result    lr_rate.

        IF lr_rate IS BOUND.
          lr_rate->get_property_as_valueEXPORTING iv_attr_name 'KBETR'
                                          IMPORTING ev_result  lv_cond_value ).
          lr_rate->get_property_as_valueEXPORTING iv_attr_name 'WAERK'
                                                    IMPORTING ev_result  lv_curr ).
          ls_condtype-zgp_p lv_cond_value.
          ls_condtype-zgp_p_cur lv_curr.
        ENDIF.

*       Reading the ZFRC Values ..
        CLEAR lr_rate ,lv_curr,  lv_cond_value..
        CALL METHOD lr_iterator->find_by_property
          EXPORTING
            iv_attr_name 'KSCHL'
            iv_value     text-002    "'ZFRC'
          RECEIVING
            rv_result    lr_rate.

        IF lr_rate IS BOUND.
          lr_rate->get_property_as_valueEXPORTING iv_attr_name 'KWERT'
                                          IMPORTING ev_result  lv_cond_value ).
          lr_rate->get_property_as_valueEXPORTING iv_attr_name 'WAERK'
                                                    IMPORTING ev_result  lv_curr ).
          ls_condtype-zfrc lv_cond_value.
          ls_condtype-zfrc_cur lv_curr.
        ENDIF.


*       Reading the ZD01 Values ..
        CLEAR lr_rate ,lv_curr,  lv_cond_value.
        CALL METHOD lr_iterator->find_by_property
          EXPORTING
            iv_attr_name 'KSCHL'
            iv_value     'ZD01'
          RECEIVING
            rv_result    lr_rate.

        IF lr_rate IS BOUND.
          lr_rate->get_property_as_valueEXPORTING iv_attr_name 'KWERT'
                                          IMPORTING ev_result  lv_cond_value ).
          lr_rate->get_property_as_valueEXPORTING iv_attr_name 'WAERK'
                                                    IMPORTING ev_result  lv_curr ).
          ls_condtype-zd01 lv_cond_value.
          ls_condtype-zd01_cur lv_curr.
        ENDIF.

        lr_condh ?=   me->typed_context->condtype->collection_wrapper->get_current).
        IF lr_condh IS BOUND.

          CALL METHOD lr_condh->set_properties
            EXPORTING
              is_attributes ls_condtype.
        ENDIF.
      ENDIF.
    ENDIF.

No comments:

Post a Comment