Skip to Content
Technical Articles

Business Logic Extensions for Enterprise Projects

This blog post aims at explaining different business logic extensions that can be performed using Cloud BAdIs for enterprise projects and its elements. The content is applicable for SAP S/4HANA Cloud CE20008 release onwards.

During master data maintenance of enterprise projects, you can apply rules to validate or determine field values of enterprise project header and project element attributes (work packages) by implementing custom logic using the below four cloud BAdIs.

This post covers the following scenarios:

  • Prevent Project/Work Package release without budget allocation
  • Allow only dedicated users to release Project/Work Package

Prevent Project (or) Work Package Release without Budget Allocation

When there is no allocated budget for the project or work package, you can prevent a user from releasing it. To make sure there are no performance issues because of this validation, run the below code only when:

  • Active status of the project/work package is in created status ‘00’.
  • Current processing status of the project/work package is ‘10’ during release.

This can be fetched from the CDS views I_EnterpriseProject / I_EnterpriseProjectelement for project or work package respectively. Following the fetch, the respective Project Internal ID / Work Package Internal ID is sent to CDS View I_FinancialPlanningEntryItem for the budget data of the planning category (for example planning category = ‘BUDGET02’)

To check the allocated budget for the project/work package and if the budget amount is ‘zero’ (KSL = 0.00), you can custom the corresponding error message (See section Custom Code List below).

For example, ‘Project cannot release without budget’ or ‘Work Package cannot release without budget’ as shown in the below screenshot can be used.

Please note that the planning category is updated with “BUDGET02”. You can custom this code with your own planning category.

Project Header Code Implementation

SELECT SINGLE PROCESSINGSTATUS FROM I_ENTERPRISEPROJECT INTO @DATA(LV_STATUS_IN)
WHERE PROJECT = @ENTERPRISEPROJECT-PROJECT.

IF LV_STATUS_IN = '00' OR LV_STATUS_IN IS INITIAL.	“active status
IF ENTERPRISEPROJECT-PROCESSINGSTATUS = '10'.	“current processing status
SELECT SINGLE * FROM I_FINANCIALPLANNINGENTRYITEM
INTO @DATA(LS_FIN) WHERE PLANNINGCATEGORY = 'BUDGET02' AND PROJECTINTERNALID = @ENTERPRISEPROJECT-PROJECTINTERNALID.

IF SY-SUBRC = 0.
DATA : LV_KSL TYPE I.
LV_KSL = LS_FIN-AMOUNTINGLOBALCURRENCY.
ELSEIF LV_KSL IS INITIAL.
 LS_VALIDATIONMESSAGE-SYSTEMMESSAGECLASS   = '/S4PPM/VAL_DET'.
 LS_VALIDATIONMESSAGE-SYSTEMMESSAGETYPE    = 'E'.
 LS_VALIDATIONMESSAGE-SYSTEMMESSAGENUMBER  = '000'.
 LS_VALIDATIONMESSAGE-SYSTEMMESSAGEVARIABLE1 = 'PROJECT CANNOT RELEASE WITHOUT BUDGET'.
 APPEND LS_VALIDATIONMESSAGE TO VALIDATIONMESSAGES.
 CLEAR LS_VALIDATIONMESSAGE.
ENDIF.
ENDIF.
ENDIF.

 

Project Element Code Implementation

SELECT SINGLE PROCESSINGSTATUS FROM I_ENTERPRISEPROJECTELEMENT INTO @DATA(LV_STATUS_IN)
WHERE PROJECTELEMENT = @ENTERPRISEPROJECTELEMENT-PROJECTELEMENT.

IF LV_STATUS_IN = '00' OR LV_STATUS_IN IS INITIAL.		“active status
IF ENTERPRISEPROJECTELEMENT-PROCESSINGSTATUS = '10'.	“current processing status
SELECT SINGLE AMOUNTINGLOBALCURRENCY FROM I_FINANCIALPLANNINGENTRYITEM
INTO @DATA(LV_KSL) WHERE PLANNINGCATEGORY = 'BUDGET02' AND WBSELEMENTINTERNALID = @ENTERPRISEPROJECTELEMENT-WBSELEMENTINTERNALID.

IF LV_KSL IS INITIAL.
LS_VALIDATIONMESSAGE-SYSTEMMESSAGECLASS   = '/S4PPM/VAL_DET'.
LS_VALIDATIONMESSAGE-SYSTEMMESSAGETYPE    = 'E'.
LS_VALIDATIONMESSAGE-SYSTEMMESSAGENUMBER  = '000'.
LS_VALIDATIONMESSAGE-SYSTEMMESSAGEVARIABLE1 = 'WORKPACKAGE CANNOT RELEASE WITHOUT BUDGET'.
APPEND LS_VALIDATIONMESSAGE TO VALIDATIONMESSAGES.
CLEAR LS_VALIDATIONMESSAGE.
ENDIF.
ENDIF.
ENDIF.

Only Permitted Users can release Project (or) Work package

You can restrict a user who does not have permissions from releasing the project or work package.

To restrict or deny a transaction to a user, you can create a custom business object with a list of User IDs who can release a project or work package. This list is used to validate the logged in user for permissions to release the project/work package.

If in case, a different user tries to release the project, you can restrict the release using an error message (See section Custom Code List below).

Get Current user details using below code:

DATA(CURRENT_USER) = CL_ABAP_CONTEXT_INFO=>GET_USER_TECHNICAL_NAME( ).

Project Header Code Implementation

SELECT SINGLE * FROM YY1_USERID INTO @DATA(LV_USER) WHERE USERDATA = @CURRENT_USER. “YY1_USERID IS CDS
IF SY-SUBRC <> 0.
IF ENTERPRISEPROJECT-PROCESSINGSTATUS = '10'.
LS_VALIDATIONMESSAGE-SYSTEMMESSAGECLASS   = '/S4PPM/VAL_DET'.
LS_VALIDATIONMESSAGE-SYSTEMMESSAGETYPE    = 'E'.
LS_VALIDATIONMESSAGE-SYSTEMMESSAGENUMBER  = '000'.
LS_VALIDATIONMESSAGE-SYSTEMMESSAGEVARIABLE1 = 'USER IS NOT AUTHORIZED TO RELEASE THE PROJECT'.
APPEND LS_VALIDATIONMESSAGE TO VALIDATIONMESSAGES.
CLEAR LS_VALIDATIONMESSAGE.
ENDIF.
ENDIF.

Project Element Code Implementation

DATA(CURRENT_USER) = CL_ABAP_CONTEXT_INFO=>GET_USER_TECHNICAL_NAME( )."
SELECT SINGLE * FROM YY1_USERID INTO @DATA(LV_USER) WHERE USERDATA = @CURRENT_USER.
IF SY-SUBRC <> 0.
IF ENTERPRISEPROJECTELEMENT-PROCESSINGSTATUS = '10'.
LS_VALIDATIONMESSAGE-SYSTEMMESSAGECLASS   =  '/S4PPM/VAL_DET'.
LS_VALIDATIONMESSAGE-SYSTEMMESSAGETYPE    = 'E'.
LS_VALIDATIONMESSAGE-SYSTEMMESSAGENUMBER  = '000'.
LS_VALIDATIONMESSAGE-SYSTEMMESSAGEVARIABLE1 = 'USER IS NOT AUTHORIZED TO RELEASE THE WORKPACKAGE'.
APPEND LS_VALIDATIONMESSAGE TO VALIDATIONMESSAGES.
CLEAR LS_VALIDATIONMESSAGE.
ENDIF.
ENDIF.

Please note for performance reasons, make sure that the below implementation only runs when the Processing Status is Released i.e., 10.

Custom Code List

You can maintain your own custom error messages in Custom Reusable Elements App.

To custom an error message, on creating a custom code list in the Custom Reusable Elements app, a CDS view is generated automatically. This generated CDS view can then be queried in BAdI implementation using the code value to fetch the text (description). This text is then passed as validation messages of BADI.

SELECT SINGLE * FROM YY1_VALIDATIONMESSAGE INTO @DATA(LV_MSG) WHERE CODE = '001'.
“YY1_VALIDATIONMESSAGE IS CDS OF CUSTOM CODE LIST
 LS_VALIDATIONMESSAGE-SYSTEMMESSAGETYPE    = 'E'.
 LS_VALIDATIONMESSAGE-SYSTEMMESSAGENUMBER  = '000'.
 LS_VALIDATIONMESSAGE-SYSTEMMESSAGEVARIABLE1 = LV_MSG-DESCRIPTION.
APPEND LS_VALIDATIONMESSAGE TO VALIDATIONMESSAGES.
CLEAR LS_VALIDATIONMESSAGE.

 

Related Product Documentation

 

Got a question? Ask here.

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