Skip to Content
Technical Articles

How to add transient fields in SAP Portfolio and Project Management

This is a continuation of blog post: How to work with field conditions in SAP Portfolio and Project Management.

Introduction

In this blog we will enhance the Project Management application in SAP PPM with a transient (display only) field. We want to show the corresponding Airline Name (from SAP SCARR demo model) next to the Airline ID we added in the previous blog.

Note: In this situation, adding the Airline Name via the SAP recommended enhancement method (like CI_DPR_PROJECT) will result in a new field on the database level. This is wrong, as the source of truth for the name of an Airline is database table SCARR. Also, it will increase the size of table DPR_PROJECT for no reason.

1. Data Dictionary

1.1. Let’s create a new data element for our display field:

Tip: Personally, I prefer creating data elements for each additional field in the ZDPR_TV_* namespace, even if they are already existing in the SAP system. This allows the maintenance of own labels.

1.2. Next, we need to add the new field into the standard structure. We are going to enhance structure DPR_TS_PROJECT_DIS, which is defined as “Non-Modifiable Project Definition Attributes”.

Note: If we analyze the standard, we will see that the transient fields are set, for example, in class CL_DPR_PROJECT in method GET_DATA_EXT. This method exports three different structures, among them, DPR_TS_PROJECT_EXT which includes both changeable and display-only data.

Tip: As recommended in the previous blog, in my experience it is a good practice to group together attributes that belong to a certain enhancement into a structure and include the structure instead. This will make things much easier on the long run for maintenance and other developers to figure out which fields belong to which add-on.

1.3. As we want to display our field in the UI, we also need to enhance the corresponding API structure DPR_TS_API_PROJECT_O. This structure is used by the DPR service manager to retrieve data from the backend.

Note: Here it is much easier if you use the structure include approach as you only have to add the ZZ* fields once.

2. Fill data into the transient field(s)

Before we display the newly added field, we should fill it with the corresponding content.

Unfortunately, unlike method SET_DATA_EXT, method GET_DATA_EXT of class CL_DPR_PROJECT does not contain any standard BAdI where we could add this logic. Therefor we need to add a Post-Exit implementation:

For the sake of simplicity, we will add a very simple coding here:

METHOD ipo_zdpr_project~get_data_ext.
*"------------------------------------------------------------------------*
*" Declaration of POST-method, do not insert any comments here please!
*"
*"methods GET_DATA_EXT
*"  importing
*"    !IV_LANGUAGE type LANGU optional
*"  changing
*"    !ES_PROJECT_CHG type DPR_TS_PROJECT_CHG
*"    !ES_PROJECT_EXT type DPR_TS_PROJECT_EXT
*"    !ES_PROJECT_INT type DPR_TS_PROJECT_INT .
*"------------------------------------------------------------------------*

  IF es_project_ext IS NOT INITIAL.
    IF es_project_ext-extended_attributes-zzairline_id IS NOT INITIAL.
      SELECT SINGLE carrname
        FROM scarr
        INTO es_project_ext-zzairline_name
        WHERE carrid = es_project_ext-extended_attributes-zzairline_id.
    ENDIF.
  ENDIF.

ENDMETHOD.

Tip: Consider buffering these values as method GET_DATA_EXT is called sometimes multiple times within the same dialog process.

3. Enhancing the User Interface

3.1. Next, we will add the new field in Web Dynpro component DPR_DET_DATA_PROJECT_O. We will use the enhancement created in the previous blog.

Here the newly added ZZ* field(s) should already be visible:

Note: As structure DPR_TS_UI_PRJ_DATA already includes the API attributes, we didn’t need to enhance the UI dictionary.

3.2. Navigate to the context tab of view VI_DET_BAS_DPO and update the mappings of node VIEWDATA:

The attribute ZZAIRLINE_NAME should now be visible next to ZZAIRLINE_ID when expanding the node.

3.3. Go to the Layout tab and add a new Transparent Container element directly under the ROOTUIELEMENTCONTAINER:

Note: We need this container in order to group together the Airline ID and the Airline Name. Otherwise the Matrix Layout of the View will move the Airline Name on the second column and display it on the right side with a space in between.

Change the Layout property to MatrixLayout and bind the visible property to the ZZAIRLINE_ID attribute:

3.4. Drag and drop element ZZINP_AIRLINE_ID into the newly created container:

3.5. Add a new TextView element into container ZZTCR_AIRLINE_ID:

And bind the text property to newly added context attribute ZZAIRLINE_NAME:

The complete element structure should look like this:

Note: As we already set the visibility binding of the transparent container to the Airline ID, we don’t need to bind the Airline Name visibility anymore.

Tip: To have a nice alignment in the UI, make sure the vAlign property of the MatrixData is set to middle.

Conclusion

Opening the Project Management application, we can now see the name of the selected Airline ID:

Be the first to leave a comment
You must be Logged on to comment or reply to a post.