Purchase Contract Workflow Custom Development Part – 2.

Estimated read time 7 min read

While the standard workflow template [WS20000079] can be used for many scenarios, there may be specific requirements that necessitate custom development. For a comprehensive guide on building custom workflows,  please refer to the provided link. 

https://community.sap.com/t5/technology-blogs-by-sap/purchase-contract-workflow-custom-development/ba-p/13761664

 Let’s now examine some of the challenges encountered during the development of the purchase contract workflow release strategy.

1) Unexpected Blank Purchase Contract Details: –

After creating a purchase contract and checking the My Inbox Fiori app, you might notice that the work item carrying the purchase contract details is blank.

 

 

Cause of the Issue:

Upon inspection, you’ll likely discover a “duplication resource error”. This error arises because an association within the CDS, C_contractFs –> I_PurchaseContract –> _PurchaseContractItem.PurchasingContractDeletionCode, is being invoked unintentionally. This association retrieves all line items  associated with the purchase contract instead of just the header one. Consequently, multiple line items appear in the header instead of the expected single entry.

Solution:

SAP Note 3391535 [ Manage Purchase Contracts: Duplicate purchase contracts are displayed] addresses this issue. The solution involves removing the association field _PurchaseContractItem.PurchasingContractDeletionCode. This prevents the retrieval of unnecessary data and ensures that only the header purchase contract detail is being displayed in the My Inbox app.

2) Purchase Contract Rejection Issue:

However, even after implementing the BAdI, purchase contract rejection failed. This occurs because the standard implementation utilizes class CL_PO_HEADER_HANDLE_MM (purchase order handler class) for both approving and rejecting purchase contracts. While this class functions as expected for approvals, it doesn’t handle rejections correctly. Even after rejection, the purchase contract remains open in the specific release code where it was rejected.

Proposed Solution:

SAP provides a dedicated handler class for purchase contracts, CL_CTR_HANDLER_MM. This class offers a method called set_rejected that performs the exact actions needed for rejection:

Opening the document in change modeChecking the documentRetrieving header dataSetting the process status to “Release Rejected”

Therefore, to resolve the rejection issue, we can leverage the set_rejected method within class CL_CTR_HANDLER_MM for purchase contract rejections within the BAdI implementation.

3) Approver Comment Retrieval in Release Strategy Workflow

In release strategy workflows for purchase contracts, approver comments are essential. However, the default behaviour doesn’t automatically carry over comments from previous approvers to subsequent levels. This occurs because separate work items are triggered for each approval level / release code in release strategy. While this approach facilitates proper delegation, it presents a challenge regarding comment inheritance.

Solution:

This section outlines a solution to retrieve and transfer comments to new work items within the workflow:

Retrieving Previous Work Item IDs:Leverage tables SWW_WI2OBJ and SWWWIHEAD to identify the work item IDs associated with earlier release codes for the same purchase contract.Extracting Approver Comment:Read the container element named “_DECISION_COMMENT” within the previous work item’s container.Utilize a field symbol for efficient memory usage.

Technical Note on Container Data: The “_DECISION_COMMENT” element holds a 90-character string with the following structure (offset notation):

Offset 52-54: Object type (3 characters)Offset 55-56: Object year (2 characters)Offset 57-68: Object number (12 characters)Parsing Container Data (Optional):Functions like SOODK can be used to extract the folder ID and object ID based on the offsets mentioned above.Reading Approver Comment (Optional):The function module “SO_NOTE_READ” can be employed to retrieve the actual approver comment using the extracted folder ID and object ID.Transferring Comment to New Work Item (Optional):The function module “SAP_WAPI_ATTACHMENT_ADD” allows attaching the retrieved comment to the current work item.Set appropriate parameters:file_type = ‘T’ (Text)file_extension = ‘HTM’ (HTML format for readability) 

​ While the standard workflow template [WS20000079] can be used for many scenarios, there may be specific requirements that necessitate custom development. For a comprehensive guide on building custom workflows,  please refer to the provided link. https://community.sap.com/t5/technology-blogs-by-sap/purchase-contract-workflow-custom-development/ba-p/13761664 Let’s now examine some of the challenges encountered during the development of the purchase contract workflow release strategy.1) Unexpected Blank Purchase Contract Details: -After creating a purchase contract and checking the My Inbox Fiori app, you might notice that the work item carrying the purchase contract details is blank.  Cause of the Issue:Upon inspection, you’ll likely discover a “duplication resource error”. This error arises because an association within the CDS, C_contractFs –> I_PurchaseContract –> _PurchaseContractItem.PurchasingContractDeletionCode, is being invoked unintentionally. This association retrieves all line items  associated with the purchase contract instead of just the header one. Consequently, multiple line items appear in the header instead of the expected single entry.Solution:SAP Note 3391535 [ Manage Purchase Contracts: Duplicate purchase contracts are displayed] addresses this issue. The solution involves removing the association field _PurchaseContractItem.PurchasingContractDeletionCode. This prevents the retrieval of unnecessary data and ensures that only the header purchase contract detail is being displayed in the My Inbox app.2) Purchase Contract Rejection Issue:However, even after implementing the BAdI, purchase contract rejection failed. This occurs because the standard implementation utilizes class CL_PO_HEADER_HANDLE_MM (purchase order handler class) for both approving and rejecting purchase contracts. While this class functions as expected for approvals, it doesn’t handle rejections correctly. Even after rejection, the purchase contract remains open in the specific release code where it was rejected.Proposed Solution:SAP provides a dedicated handler class for purchase contracts, CL_CTR_HANDLER_MM. This class offers a method called set_rejected that performs the exact actions needed for rejection:Opening the document in change modeChecking the documentRetrieving header dataSetting the process status to “Release Rejected”Therefore, to resolve the rejection issue, we can leverage the set_rejected method within class CL_CTR_HANDLER_MM for purchase contract rejections within the BAdI implementation.3) Approver Comment Retrieval in Release Strategy WorkflowIn release strategy workflows for purchase contracts, approver comments are essential. However, the default behaviour doesn’t automatically carry over comments from previous approvers to subsequent levels. This occurs because separate work items are triggered for each approval level / release code in release strategy. While this approach facilitates proper delegation, it presents a challenge regarding comment inheritance.Solution:This section outlines a solution to retrieve and transfer comments to new work items within the workflow:Retrieving Previous Work Item IDs:Leverage tables SWW_WI2OBJ and SWWWIHEAD to identify the work item IDs associated with earlier release codes for the same purchase contract.Extracting Approver Comment:Read the container element named “_DECISION_COMMENT” within the previous work item’s container.Utilize a field symbol for efficient memory usage.Technical Note on Container Data: The “_DECISION_COMMENT” element holds a 90-character string with the following structure (offset notation):Offset 52-54: Object type (3 characters)Offset 55-56: Object year (2 characters)Offset 57-68: Object number (12 characters)Parsing Container Data (Optional):Functions like SOODK can be used to extract the folder ID and object ID based on the offsets mentioned above.Reading Approver Comment (Optional):The function module “SO_NOTE_READ” can be employed to retrieve the actual approver comment using the extracted folder ID and object ID.Transferring Comment to New Work Item (Optional):The function module “SAP_WAPI_ATTACHMENT_ADD” allows attaching the retrieved comment to the current work item.Set appropriate parameters:file_type = ‘T’ (Text)file_extension = ‘HTM’ (HTML format for readability)   Read More Technology Blogs by SAP articles 

#SAP

#SAPTechnologyblog

You May Also Like

More From Author