Skip to Content
Technical Articles

How to check if BO instance is locked in SAP Cloud for Customer PDI/SDK

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 Jürgen Ravnik 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

/
2 Comments
You must be Logged on to comment or reply to a post.
  • Hey Saurabh, great start mate! Keep going!

     

    About Platinum namespace… My POV is that it needs to be documented or should not exist at all. There are so many usefull feautures/libraries there. But without an ability to debug them or read their code, it might be just a time bomb if you’re not certain what this or that library is doing.

     

    I’m also wondering how it works from legal perspective. Having doubts there is any explicit statement regarding this particular namespace in customer’s contract. And not sure that the mentioned KBA is good enough to reduce the support scope and liability.

    • Thanks Andrei!

      Reg documentation of these Platinum Engineering based libraries, I also feel the same that they should be documented. In fact, I raised it as an Idea some 2-3 years back (then idea forum) but it was rejected.

      However, They have really helped me in the past for my project work hence I tend to use them occasionally wherever needed.