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
VishnAndr
Active Contributor

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.

former_member226
Employee
Employee
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.
Aichaaz
Explorer
0 Kudos

Hi Saurabh,

 

Thank you for this blog.

 

We have a requirement where we need to update the customer's ABC classification from the "CustomerQuote-beforeSave" event (the value depends on related sales orders), but sometimes our code is run at the same time where the customer is being updated by incoming information from ERP.

so to make sure the code is executed as it should, I used your suggestion on how to check if a BO is locked before triggering the change in the Customer BO.

The code is supposed to keep checking if the BO is locked every 5 seconds (at least) until the BO is not locked anymore, and then proceed with the update of the ABC Classification.

 

Here is the code I'm using:

if(customer.IsSet()) {

	var uuid: UUID;

	var lock: MessageList;

	

	var oldMessageCount = 0;

	var objectLocked = true;

	while(objectLocked) {

		uuid =Library::UUID.ParseFromString(customer.UUID.content.ToString());// Customer UUID

		lock = BOAction.CheckLock("Customer","http://sap.com/xi/AP/FO/BusinessPartner/Global","Root",uuid);

		var messages = lock.MessageTypeItem;

		

		if(!lock.IsInitial() && messages.Count() > 0){

			// I noticed that the new message is added to old messages, so I'm comparing the messages count;

			// in case the number is not increasing, this means the object is not locked anymore

			if(messages.Count() > oldMessageCount) { 

				foreach(var message in messages)

				{

					if(message.MessageSeverityText == "E" && message.MessageID.content.ReplaceRegex("[[:space:]]","") == "AP_ESI_COMMON/101")

					{

						var check_now = Context.GetCurrentGlobalDateTime();

						var duration = ABSL: Duration.ParseFromString("PT5S");

						var check_end = check_now.AddDuration(duration);

						// looping for 5 seconds before checking the lock again

						while (check_now < check_end)

						{

							check_now = Context.GetCurrentGlobalDateTime();

						}

					}

				}

				oldMessageCount = messages.Count();

			} else {

				objectLocked = false;

			}

		} else {

			objectLocked = false;

		}

	}

	

	//then trigger modfication in Customer BO

}

 

To test it (in the test system), I lock the Customer from the UI, and then do some modification (from UI) on one of its Sales Orders; The code seems to work just fine during my tests, the loop is running until I unlock the Customer from the UI, and then the rest of the code is executed, we also tried do simultaneous updates from ERP and seemed to work fine (but I couldn't debug this because it's done by technical user)

But this doesn't seem to work well in our PROD system, the ABC Classification is not updated as it should when there is concurrent access to the customer BO.

So, I'm wondering if there is something wrong with my code.

Can you please check it and give me your feedback?

Update : my code is in fact working like a charm (my issue wasn't linked to concurrent access).

 

Best regards,

Aicha.

anant_acharya
Advisor
Advisor
saurabhkabra2009 - Could you please guide here? Aicha has some implementation query on the instance locking issue for Customer BO.