I thought to write this blog as I couldn’t find a solve with complete information. However there are very few questions asked by many on answers.sap.com but users comments didn’t assist much. So this blog would walk you through on how to automatically generated external-ID Portfolio Item and Initiatives.

Background:

As we know post SPRO configuration Automatically Generated External-ID of Portfolio Objects Set to Read-Only there could be addiotnal ask by customer on it’s behavior

In Portfolio Management the number range object RPM_EXTID is used to determine the next external ID of an object.

The BAdI RPM_OBJECT_SERVICES with method GET_NEXT_NUMBER_FOR_EXTID can be used to make further changes to the external-ID and to determine the external-ID based on customer-logic(KBA note 2183855 for List of BAdIs Portfolio Management). The switch must be activated that the External-ID can be further changed with BAdI RPM_OBJECT_SERVICES with method GET_NEXT_NUMBER_FOR_EXTID. Information can you find in KBA Note 2179188.

BAdI RPM_OBJECT_SERVICES with method GET_NEXT_NUMBER_FOR_EXTID suits perfectly, however the external number would be generated during Create event which is same a SAP behavior.

Requirement:

So what if one would like to generate during Save event which would help not to lose number range in case user plans not to save Portfolio Item and Initiatives?

In order to archive this BAdI RPM_PROJ_CUST_FIELDS method CUST_PROJ_PREPARE_TO_SAVE could assist. However thing to note here is that method CUST_PROJ_PREPARE_TO_SAVE has only importing parameters.

In order to deal with this, we would need to use Master Project Definition class “CL_RPM_PROJECT” along with Project Management Controller “CL_RPM_OBJ_MANAGER”.

METHOD if_ex_rpm_proj_cust_fields~cust_proj_prepare_to_save.
DATA: lv_nr     TYPE nrnr,
      lv_obj    TYPE nrobj,
      lv_prefix TYPE char3.

DATA lt_projects     TYPE rpm_tt_guid_project_defs.
DATA lv_ui_change_mode TYPE boole_d.
DATA or_item           TYPE REF TO cl_rpm_project.
DATA ls_attributes     TYPE rpm_ts_project_int.

*  During SAVE when PPM object is being created
IF is_attributes-external_id NE is_attributes_old-external_id AND
   is_attributes_old-external_id IS INITIAL.
  DATA(lr_manager) = cl_rpm_obj_manager=>get_instance( iv_langu = sy-langu ).
  CALL METHOD lr_manager->load_projects
    EXPORTING
      iv_guid             = is_attributes-guid
    IMPORTING
      et_projects         = lt_projects
      ev_load_change_mode = lv_ui_change_mode.

  TRY.
      DATA(ls_project) = lt_projects[ 1 ].
      or_item = ls_project-reference.

    CATCH cx_sy_itab_line_not_found.
  ENDTRY.

  IF or_item IS BOUND.
* Check your Item and Initiatives Item_Type as per system configuration 
    CASE ls_attributes-rpm_project-item_type.
      WHEN ''. "Initiatives
*              lv_nr   = .
*              lv_obj  = .
*              lv_prefix =   .
      WHEN ''.  "Portfolio Item
*              lv_nr   = .
*              lv_obj  = .
*              lv_prefix =   .
      WHEN OTHERS.
    ENDCASE.

    IF NOT lv_prefix IS INITIAL.
      CALL FUNCTION 'NUMBER_GET_NEXT'
        EXPORTING
          nr_range_nr             = lv_nr
          object                  = lv_obj
          ignore_buffer           = 'X'
        IMPORTING
          number                  = lv_extid
        EXCEPTIONS
          interval_not_found      = 1
          number_range_not_intern = 2
          object_not_found        = 3
          quantity_is_0           = 4
          quantity_is_not_1       = 5
          interval_overflow       = 6
          buffer_overflow         = 7
          OTHERS                  = 8.
      IF sy-subrc <> 0.
*               Implement suitable error handling here
      ENDIF.
      ls_attributes-external_id = |{ lv_prefix }| && |{ '.' }| && |{ lv_extid }|.
      TRY.
          CALL METHOD or_item->set_attributes
            EXPORTING
              is_attributes = ls_attributes.
        CATCH cx_rpm_object_update_error .
        CATCH cx_rpm_configuration_error .
      ENDTRY.
    ENDIF.
  ENDIF.
ENDIF.
ENDMETHOD.

PPM Item:

BAdI Definition Name: RPM_PROJ_CUST_FIELDS, method CUST_PROJ_PREPARE_TO_SAVE to overwrite External ID

PPM Initiative:

BAdI Definition Name: INM_INITIATIVE_O_BADI, method ON_SAVE_REQUESTED to overwrite External ID

Summary:

With above custom code at the right place one could achieve PPM external ID generation on Save event rather than SAP provided on Create event

 

Thank you for reading and would like to hear from you and/or clarifying questions in the comment section.

 

 

Sara Sampaio

Sara Sampaio

Author Since: March 10, 2022

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x