Monday 24 February 2020

RRI: Jump from BW Reports based on SAP PPM to PPM WebDynpro Applications

In this post I would like to share how to create RRI to Portfolio and Project Management WebDynpro Applications from BW reports. This solution is based on creation a customer target with use of BADI RS_BBS_BADI.

In this post there are 3 custom targets:

◉ Go to item master data details
◉ Go to item financial planning
◉ Go to cProjects master data details

Step-by-step


1. Create implementation of RS_BBS_BADI in SE19.

BW (SAP Business Warehouse), ABAP Development, SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Exam Prep, SAP ABAP Prep

2. All logic is realized in ABAP code below.

BW (SAP Business Warehouse), ABAP Development, SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Exam Prep, SAP ABAP Prep

CLASS ZCL_PPME001_BBS DEFINITION
  public
  final
  create public .

public section.

  interfaces IF_EX_RS_BBS_BADI .
protected section.
private section.
ENDCLASS.

CLASS ZCL_PPME001_BBS IMPLEMENTATION.

  METHOD if_ex_rs_bbs_badi~get_types.

    DATA: ls_handler TYPE rsbbs_s_badi_handler.
    "Technical name of application
    ls_handler-appl = 'ZPPM'.

    "ABAP class with interface IF_RS_BBS_BADI_HANDLER
    create object ls_handler-handler type zcl_ppme001_bbs_ppm.
    INSERT ls_handler INTO TABLE c_th_handler.

    "In addition you can create other target with link to realization class

  ENDMETHOD.
ENDCLASS.
class ZCL_PPME001_BBS_PPM definition
  public
  final
  create public .

public section.

  interfaces IF_RS_BBS_BADI_HANDLER .

  class-methods CLASS_CONSTRUCTOR .
protected section.
private section.
ENDCLASS.

CLASS ZCL_PPME001_BBS_PPM IMPLEMENTATION.

  method CLASS_CONSTRUCTOR.
    "This name will be visible as a target in RSBBS
    if_rs_bbs_badi_handler~n_text = 'RRI in SAP PPM'.
    if_rs_bbs_badi_handler~n_url_call = rs_c_true. "use URL
    if_rs_bbs_badi_handler~n_sapgui_call = rs_c_false.
  endmethod.

  METHOD if_rs_bbs_badi_handler~get_targets.
    TYPE-POOLS: icon.
    DATA: ls_f4_list TYPE rsbbs_s_f4_list.

    "Values visible as RRI targets
    CLEAR: ls_f4_list.
    ls_f4_list-icon = icon_check.
    ls_f4_list-objnm = 'ZPPM_ITEM_DETAILS'.
    ls_f4_list-txtlg = 'Go to item details in PPM'.
    APPEND ls_f4_list TO e_t_f4_list.
    CLEAR: ls_f4_list.
    ls_f4_list-icon = icon_check.
    ls_f4_list-objnm = 'ZPPM_CPROJECTS_FPM'.
    ls_f4_list-txtlg = 'Go to cProjects project in PPM'.
    APPEND ls_f4_list TO e_t_f4_list.
    CLEAR: ls_f4_list.
    ls_f4_list-icon = icon_check.
    ls_f4_list-objnm = 'ZPPM_FIN_PLANNING'.
    ls_f4_list-txtlg = 'Go to financial planning in by item PPM'.
    APPEND ls_f4_list TO e_t_f4_list.

  ENDMETHOD.

  method if_rs_bbs_badi_handler~call_url.

    types: begin of ts_zppm_item_attr,
             zppmidgu type /bic/oizppmidgu, "Item Detail
             zppmbugu type /bic/oizppmbugu, "Item Bucket
             zppmpfgu type /bic/oizppmpfgu, "Item Portfolio
           end of ts_zppm_item_attr,
           tt_zppm_item_attr type standard table of ts_zppm_item_attr
                            with non-unique key zppmidgu.
    data: lt_item_attr       type tt_zppm_item_attr,
          ls_item_attr       type ts_zppm_item_attr,
          lv_object_guid1    type /bic/oizppmidgu,
          lv_parent_guid1    type /bic/oizppmbugu,
          lv_portfolio_guid1 type /bic/oizppmpfgu,
          lv_ppm_mandt       type c length 3.

    data: l_sx_mapping           type rsbbs_sx_mapping,
          l_s_range              type rrrangesid,
          lv_and                 type string value '&',
          lv_url                 type string, "+
          lv_appl                type string value 'sap/bc/webdynpro/sap/rpm_item_details?',
          lv_appl_mode           type string value 'appl_mode=2',
          lv_appl_type           type string value 'appl_type=RPM',
          lv_portfolio_id        type string value 'portfolio_id=',
          lv_portfolio_guid      type string value 'portfolio_guid=', "+
          lv_parent_type         type string value 'parent_type=RBH',
          lv_parent_id           type string value 'parent_id=',
          lv_parent_guid         type string value 'parent_guid=', "+
          lv_object_type         type string value 'object_type=RIH',
          lv_object_id           type string value 'object_id=',
          lv_object_guid         type string value 'object_guid=', "+
          lv_ctx_aprent_type     type string value 'ctx_parent_type=RPH',
          lv_ctx_parent_guid     type string value 'ctx_parent_guid=', "+
          lv_main_portfolio_guid type string value 'main_portfolio_guid=00000000000000000000000000000000',
          lv_portal_role         type string value 'portal_role=RPM_PORT',
          lv_edit_mode           type string value 'edit_mode=2',
          lv_view_temp           type string value 'view_temp=',
          lv_is_status_locked    type string value 'is_status_locked=',
          lv_sap_wd_configid     type string value 'sap-wd-configid=RPM_ITEM_DETAILS_CFG',
          lv_sap_accessibility   type string value 'sap-accessibility=',
          lv_sap_theme           type string value 'sap-theme=sap_belize',
          lv_sap_client          type string value 'sap-client=',
          lv_sap_ie              type string value 'sap-ie=Edge'.


    types: begin of ts_zppm_cguid_attr,
             zppmcguid  type /bic/oizppmcguid,
             cpr_ext_id type /bi0/oicpr_ext_id,
             zppmcobjt  type /bic/oizppmcobjt,
             zppmcproj  type /bic/oizppmcproj,
           end of ts_zppm_cguid_attr,
           tt_zppm_cguid_attr type standard table of ts_zppm_cguid_attr
                   with non-unique key zppmcguid.
    data: lt_cguid_attr type tt_zppm_cguid_attr,
          ls_cguid_attr type ts_zppm_cguid_attr,

          lt_sguid_attr type tt_zppm_cguid_attr,
          ls_sguid_attr type ts_zppm_cguid_attr.


    data: lv_cguid type /bic/oizppmcguid,
          lv_sguid type /bic/oizppmsguid.

    data: lv_url2             type string,
          lv_appl2            type string value 'sap/bc/webdynpro/sap/cprojects_fpm?',
          lv_objevent         type string value 'obj_event=',
          lv_dpo              type string value 'DPO',
          lv_sap_wd_configid2 type string value 'sap-wd-configid=CPROJECTS_FPM'.

    data: lv_url3             type string,
          lv_appl3            type string value 'sap/bc/webdynpro/rpm/fin_cap_planning?',
          lv_sap_wd_configid3 type string value 'sap-wd-configid=%2fRPM%2fWDA_FIN_CAP_PLANNING_CFG'.

    case i_onam.
      when 'ZPPM_ITEM_DETAILS'.

        "Read PPM server info from settings table
        clear: lv_url, r_url.
        select single low into lv_url from tvarvc
          where name = 'ZPPM_SERVER_URL' and
                type = 'P' and
                numb = '0000'.

        "Read PPM mandant from settings table
        clear: lv_ppm_mandt.
        select single low into lv_ppm_mandt from tvarvc
          where name = 'ZPPM_CLIENT' and
                type = 'P' and
                numb = '0000'.
        lv_sap_client = |{ lv_sap_client }{ lv_ppm_mandt }|.

        "Select portfolio
        clear: l_sx_mapping, l_s_range.
        loop at i_thx_mapping into l_sx_mapping
          where fieldnm = 'ZPPMPFGU'.
          read table l_sx_mapping-range into l_s_range index 1.
          if l_s_range-low is not initial.
            lv_portfolio_guid1 = l_s_range-low.
            lv_portfolio_guid = |{ lv_portfolio_guid }{ l_s_range-low }|.
          endif.
        endloop.
        "Select bucket
        clear: l_sx_mapping, l_s_range.
        loop at i_thx_mapping into l_sx_mapping
          where fieldnm = 'ZPPMBUGU'.
          read table l_sx_mapping-range into l_s_range index 1.
          if l_s_range-low is not initial.
            lv_parent_guid1 = l_s_range-low.
            lv_parent_guid = |{ lv_parent_guid }{ l_s_range-low }|.

          endif.
        endloop.
        "Select item detail
        clear: l_sx_mapping, l_s_range.
        loop at i_thx_mapping into l_sx_mapping
          where fieldnm = 'ZPPMIDGU'.
          read table l_sx_mapping-range into l_s_range index 1.
          if l_s_range-low is not initial.
            lv_object_guid1 = l_s_range-low.
            lv_object_guid = |{ lv_object_guid }{ l_s_range-low }|.
          endif.
        endloop.
        "Item should be visible in bw report structure
        if lv_object_guid1 is not initial.
          "If bicket or portfolio are hiden, read them from master data of item detail
          if lv_parent_guid1 is initial or lv_portfolio_guid1 is initial.

            clear:ls_item_attr, lt_item_attr.

            call method zcl_ppme001_read_cv_data=>get_item_attr "read from master data
              exporting
                iv_item_guid = lv_object_guid1
              importing
                et_item_attr = lt_item_attr.

            read table lt_item_attr into ls_item_attr index 1.

            lv_parent_guid = |{ lv_parent_guid }{ ls_item_attr-zppmbugu }|.
            lv_portfolio_guid = |{ lv_portfolio_guid }{ ls_item_attr-zppmpfgu }|.

          endif.

          "Form final URL
          lv_url = |{ lv_url }{ lv_appl }{ lv_appl_mode }|.
          concatenate lv_url lv_appl_type lv_portfolio_id lv_portfolio_guid
                             lv_parent_type lv_parent_id lv_parent_guid
                             lv_object_type lv_object_id lv_object_guid
                             lv_portal_role lv_edit_mode lv_view_temp lv_is_status_locked
                             lv_sap_wd_configid lv_sap_accessibility lv_sap_theme lv_sap_client
                             lv_sap_ie
                             into lv_url
                             separated by lv_and.

          r_url = lv_url.

        endif.

      when 'ZPPM_CPROJECTS_FPM'.

        "Read PPR server info from settings table
        clear: lv_url2, r_url.
        select single low into lv_url2 from tvarvc
          where name = 'ZPPM_SERVER_URL' and
                type = 'P' and
                numb = '0000'.

        "Read PPM mandant from settings table
        clear: lv_ppm_mandt.
        select single low into lv_ppm_mandt from tvarvc
          where name = 'ZPPM_CLIENT' and
                type = 'P' and
                numb = '0000'.
        lv_sap_client = |{ lv_sap_client }{ lv_ppm_mandt }|.

        "Select object
        clear: l_sx_mapping, l_s_range.
        loop at i_thx_mapping into l_sx_mapping
          where fieldnm = 'ZPPMCGUID' and mdflag = 'X'.
          read table l_sx_mapping-range into l_s_range index 1.
          lv_cguid = l_s_range-low.
        endloop.

        "Select object (source)
        clear: l_sx_mapping, l_s_range.
        loop at i_thx_mapping into l_sx_mapping
          where fieldnm = 'ZPPMSGUID' and mdflag = 'X'.
          read table l_sx_mapping-range into l_s_range index 1.
          lv_sguid = l_s_range-low.
        endloop.

        if lv_cguid is not initial.

          clear: ls_cguid_attr, lt_cguid_attr.
          "Find Project DPO
          call method zcl_ppme001_read_cv_data=>get_cguid_attr
            exporting
              iv_cguid      = lv_cguid
            importing
              et_cguid_attr = lt_cguid_attr.

          read table lt_cguid_attr into ls_cguid_attr index 1.

          "Form final URL
          lv_url2 = |{ lv_url2 }{ lv_appl2 }|.
          if ls_cguid_attr-zppmcobjt = 'DPO'.
            lv_objevent = |{ lv_objevent }{ lv_dpo }{ lv_cguid }{ lv_cguid }{ lv_dpo }|.
          else.
            lv_objevent = |{ lv_objevent }{ lv_dpo }{ ls_cguid_attr-zppmcproj }{ ls_cguid_attr-zppmcproj }{ lv_dpo }|.
          endif.

          lv_url2 = |{ lv_url2 }{ lv_objevent }|.
          concatenate lv_url2
                      lv_sap_client
                      lv_sap_theme
                      lv_sap_wd_configid2
                      lv_sap_accessibility
                      lv_sap_ie
                 into lv_url2 separated by lv_and.

          r_url = lv_url2.

        elseif lv_sguid is not initial.

          clear: ls_sguid_attr, lt_sguid_attr.
          call method zcl_ppme001_read_cv_data=>get_cguid_attr
            exporting
              iv_cguid      = lv_sguid
            importing
              et_cguid_attr = lt_sguid_attr.

          read table lt_sguid_attr into ls_sguid_attr index 1.

          "Form final URL
          lv_url2 = |{ lv_url2 }{ lv_appl2 }|.
          if ls_sguid_attr-zppmcobjt = 'DPO'.
            lv_objevent = |{ lv_objevent }{ lv_dpo }{ lv_sguid }{ lv_sguid }{ lv_dpo }|.
          else.
            lv_objevent = |{ lv_objevent }{ lv_dpo }{ ls_sguid_attr-zppmcproj }{ ls_sguid_attr-zppmcproj }{ lv_dpo }|.
          endif.

          lv_url2 = |{ lv_url2 }{ lv_objevent }|.
          concatenate lv_url2
                      lv_sap_client
                      lv_sap_theme
                      lv_sap_wd_configid2
                      lv_sap_accessibility
                      lv_sap_ie
                 into lv_url2 separated by lv_and.

          r_url = lv_url2.


        endif.

      when 'ZPPM_FIN_PLANNING'.

        "Read PPM server from settings table
        clear: lv_url3, r_url.
        select single low into lv_url3 from tvarvc
          where name = 'ZPPM_SERVER_URL' and
                type = 'P' and
                numb = '0000'.

        "Read PPM mandant from settings table
        clear: lv_ppm_mandt.
        select single low into lv_ppm_mandt from tvarvc
          where name = 'ZPPM_CLIENT' and
                type = 'P' and
                numb = '0000'.
        lv_sap_client = |{ lv_sap_client }{ lv_ppm_mandt }|.


        "Select portfolio
        clear: l_sx_mapping, l_s_range.
        loop at i_thx_mapping into l_sx_mapping
          where fieldnm = 'ZPPMPFGU'.
          read table l_sx_mapping-range into l_s_range index 1.
          if l_s_range-low is not initial.
            lv_portfolio_guid1 = l_s_range-low.
            lv_portfolio_guid = |{ lv_portfolio_guid }{ l_s_range-low }|.
          endif.
        endloop.
        "Select bucket
        clear: l_sx_mapping, l_s_range.
        loop at i_thx_mapping into l_sx_mapping
          where fieldnm = 'ZPPMBUGU'.
          read table l_sx_mapping-range into l_s_range index 1.
          if l_s_range-low is not initial.
            lv_parent_guid1 = l_s_range-low.
            lv_parent_guid = |{ lv_parent_guid }{ l_s_range-low }|.

          endif.
        endloop.
        "Select item detail
        clear: l_sx_mapping, l_s_range.
        loop at i_thx_mapping into l_sx_mapping
          where fieldnm = 'ZPPMIDGU'.
          read table l_sx_mapping-range into l_s_range index 1.
          if l_s_range-low is not initial.
            lv_object_guid1 = l_s_range-low.
            lv_object_guid = |{ lv_object_guid }{ l_s_range-low }|.
          endif.
        endloop.
        
        if lv_object_guid1 is not initial.
          
          if lv_parent_guid1 is initial or lv_portfolio_guid1 is initial.

            clear:ls_item_attr, lt_item_attr.

            call method zcl_ppme001_read_cv_data=>get_item_attr
              exporting
                iv_item_guid = lv_object_guid1
              importing
                et_item_attr = lt_item_attr.

            read table lt_item_attr into ls_item_attr index 1.

            lv_parent_guid = |{ lv_parent_guid }{ ls_item_attr-zppmbugu }|.
            lv_portfolio_guid = |{ lv_portfolio_guid }{ ls_item_attr-zppmpfgu }|.

          endif.

          "Form final URL
          lv_url3 = |{ lv_url3 }{ lv_appl3 }{ lv_appl_mode }|.
          concatenate lv_url3 lv_appl_type lv_portfolio_id lv_portfolio_guid
                              lv_parent_type lv_parent_id lv_parent_guid
                              lv_object_type lv_object_id lv_object_guid
                              lv_portal_role lv_edit_mode lv_view_temp lv_is_status_locked
                              lv_sap_wd_configid3 lv_sap_accessibility lv_sap_theme lv_sap_client
                              lv_sap_ie
                             into lv_url3
                             separated by lv_and.
          r_url = lv_url3.

        endif.

    endcase.

  endmethod.

ENDCLASS.

3. Settings in RSBBS based on Infoprovider or query is very simple.

BW (SAP Business Warehouse), ABAP Development, SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Exam Prep, SAP ABAP Prep

No comments:

Post a Comment