Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member226
Employee
Employee

Introduction/Overview


Very often in projects involving multiple users with complex system integration, it happens that due to some reason BO (Business Object) instance is locked by integration or business user. This causes the update failure.

In case you would like to know the business object instance locking status then you can utilize SAP provided standard Reuse Library “BOAction”. Thanks to jravnik for giving the tip.

 

Note: Reuse Library "BOAction" comes as part of "AP.PlatinumEngineering" namespace which is, in general, not officially supported by SAP. In most cases, they are very well equipped to support key business features like Sending Email, Getting the code list value based on data type and more. But unfortunately, they are not bound to SAP Contractual Support SLAs.

For more details please refer: https://apps.support.sap.com/sap/support/knowledge/public/en/2698916

 

Pre-Requisite



  1. SAP Cloud Application Studio

  2. SAP Cloud for Customer system access with PDI / SDK access

  3. Basic overview about ABSL Script, BO Action and Events.


 

Use Case:


The use case I am defining here is entirely hypothetical and could be easily achieved by standard features.

My requirement is, from the custom BO I would like to validate if opportunity instance associated with custom BO is locked or not. If the opportunity instance is locked by some other user then raise an error message and avoid save of the Custom BO instance.

 

Implementation:


Enough talking, let's see this in action!

 

Create a custom BO with fields and most importantly message definition. Since I want to pass the exact same message which is being returned by SAP Reuse Library hence I kept message definition quite generic.

 

BO Definition for Message Text Definition:
import AP.Common.GDT as apCommonGDT;
import AP.PDI.bo;

[ChangeHistory] businessobject SK_PlayGround raises MSG_Error {

message MSG_Error text "&1": String;

[AlternativeKey] element ID: ID;
element StartDate: Date;
element EndDate: Date;
element ContactTime: Time;
element Note: MEDIUM_Name;
element OpportunityUUID: UUID;
****
****
****
}

 

We want to show the error message as soon as a user saves the custom BO instance. hence I have created ABSL script for Validation-OnSave of Root node for my Custom BO

ABSL Code for reference
import ABSL;
import Common.DataTypes;
import AP.PlatinumEngineering;

var uuid: UUID;
uuid =Library::UUID.ParseFromString(this.OpportunityUUID.content.ToString());// Opp ID 12450
var lock = BOAction.CheckLock("Opportunity","http://sap.com/xi/AP/CRM/Global","Root",uuid);
var messages = lock.MessageTypeItem;
var validationFailed : Indicator = false;

if(!lock.IsInitial() && messages.Count() > 0){
foreach(var message in messages)
{
if(message.MessageSeverityText == "E" && message.MessageID.content.ReplaceRegex("[[:space:]]","") == "AP_ESI_COMMON/101")
{
validationFailed = true;
MSG_Error.Create(message.MessageType, message.Text.content);
break;
}
}
}

return !validationFailed;

 

Testing


Go to generated UIs for your custom BO and create a new instance of your custom Business Object. Fill in the mandatory field and press SAVE. At this moment a call will be fired to the backend SDK (You can also set a breakpoint in the ABSL script to simulate the scenario) and an error will be raised and instance save will be rejected.


 

Conclusion


Using "BOAction" we can not just validate if the Instance is locked but can also check if an action is allowed (IsActionAllowed) and many more.

Further, It's worth noting that AP.PlatinumEngineering namespace, in general, offers many such Reuse Libraries which are neither documented anywhere nor have been discussed. So it's worth spending some time exploring what these libraries can do and share them with the whole community.

 

Hope you like it and let me know your feedback in the comment section.

 

PS: This was my first attempt to write a blog and now I know how "difficult" it is to write down but at the same time how insightful it could be when you actually write it down and find out things which you could have simply ignored in general.

 

Thanks & Regards

Saurabh Kabra
4 Comments