cancel
Showing results for 
Search instead for 
Did you mean: 

How to schedule mass data run programmaticaly in ABSL

abelousov
Active Participant
0 Kudos

Dear community,

Could you please explain me the following example of scheduling a mass data run via ABSL:

https://archive.sap.com/discussions/thread/3925665

---------------------------- cut ------------------------------------------

import AP.PlatinumEngineering;

var QueryParam : QueryParameter;

var MDRO_ID : XPEString;

MDRO_ID = TaskUUID.content.ToString();

  1. MDRO.CreateInstance("MDR_ExecuteTask", "", MDRO_ID);
  2. QueryParam.ParameterName = "SelectByTaskUUIDContent";
  3. QueryParam.Sign = "I";
  4. QueryParam.Option = "EQ";
  5. QueryParam.Low = TaskUUID.content.ToString();
  6. MDRO.AddSelectionParameter("MDR_ExecuteTask", "","SelectByTaskUUIDContent", MDRO_ID, QueryParam);

var currentTime = Context.GetCurrentGlobalDateTime();

var StartDuration = Library::Duration.Create(0,0,0,0,0,NrOfSeconds);

var startTime = currentTime.AddDuration(StartDuration);

  1. MDRO.ExecuteDateTime("MDR_ExecuteTask", "", startTime, MDROID);

----------------------------- cut -----------------------------------------------------

I made the same for my BO:

----------------------------- cut -----------------------------------------------------

import AP.Common.GDT as apCommonGDT;

import AP.PlatinumEngineering;

businessobject BO {

element UUID : UUID;

element Text : LANGUAGEINDEPENDENT_LONG_Text;

element Number : NumberValue;

action MyAction1;

action MyAction2;

}

----------------------------- cut -----------------------------------------------------

MyAction1:

----------------------------- cut -----------------------------------------------------

import ABSL;

import AP.PlatinumEngineering;

var QueryParam : QueryParameter;

var MDRO_ID : XPEString;

var MessageList : MessageList;

MDRO_ID = "Aleksei";

MessageList = MDRO.CreateInstance ( "BOMDR", "", MDRO_ID );

QueryParam.Clear();

QueryParam.ParameterName = "SelectByText";

QueryParam.Sign = "I";

QueryParam.Option = "EQ";

QueryParam.Low = "Filip";

MessageList = MDRO.AddSelectionParameter ( "BOMDR", "", "SelectByText", MDRO_ID, QueryParam );

var currentTime = Context.GetCurrentGlobalDateTime();

var StartDuration = Library::Duration.Create ( 0, 0, 0, 0, 0, 20 ); // in 20 sec

var startTime = currentTime.AddDuration ( StartDuration );

MessageList = MDRO.ExecuteDateTime ( "BOMDR", "", startTime, MDRO_ID );

return;

----------------------------- cut -----------------------------------------------------

MyAction2:

----------------------------- cut -----------------------------------------------------

import ABSL;

this.Text = this.Text + " Hallo";

return;

----------------------------- cut -----------------------------------------------------

But it seems it does not work, the MyAction2 in BOMDR does not launch.

It works, though, when I schedule and start BOMDR manually via Work Center.

Where can be a mistake?

Thank you.

Accepted Solutions (1)

Accepted Solutions (1)

abelousov
Active Participant

Finally, I implemented the MDR recurrence process via ABSL.

I also coped with the second issue - the error message in the log disappeared when I stopped setting the condition in the Query on starting a regular run (MDRO.ExecuteDataTime). Actually, it is enough to set the condition the only first time, when you start the recurrence process. The first run does not raise the error message.

So, the whole recurrence process based on three actions:

Action 1. Create a MDR instance (with the Query condition) and call the Action 2.

Action 2. Schedule a run

Action 3. BO action - do some useful work over BO and call the Action 2

An example of proper ABSL code is

----------------------- BO --------------------------

import AP.Common.GDT as apCommonGDT;

businessobject BO {

element Text : LANGUAGEINDEPENDENT_LONG_Text;

element Number : NumberValue;

action MyAction1; // Create MDR Recurrence process

action MyAction2; // Schedule MDR

action MyAction3; // Process Data

}

-------------------------------------------------------

----------------------- MyAction1 --------------------------

// Start MDR recurrence process

import ABSL;

import AP.PlatinumEngineering;

var MDRO_ID : XPEString;

var QueryParam : QueryParameter;

var ParameterName : QueryParameter.ParameterName;

var MessageList : MessageList;

var MessageText1 : MessageType.Text.content;

var MessageText2 : MessageType.Text.content;

MDRO_ID.Clear();

MDRO_ID = "ZZZ";

Trace.Info ( "--- Start MDR Recurrence process" );

if ( this.Number <= 0 ) {

Trace.Info ( "--- Stop MDR Recurrence process" );

return;

}

// Create (or Check existing) MDR Instance

MessageList.Clear();

MessageList = MDRO.CreateInstance ( "MDR", "", MDRO_ID );

MessageText1.Clear();

if ( MessageList.MessageTypeItem.Count() > 0 ) {

MessageText1 = MessageList.MessageTypeItem.GetFirst().Text.content;

Trace.Info ( "--- Info: " + MessageText1 );

}

// Set a Selection condition (to select the current BO Instance)

if ( MessageList.IsInitial() ) {

QueryParam.Clear();

QueryParam.Sign = "I";

QueryParam.Option = "EQ";

QueryParam.Low = this.Text;

MessageList.Clear();

MessageList = MDRO.AddSelectionParameter ( "MDR", "", "SelectByText", MDRO_ID, QueryParam );

} else {

MessageList.Clear();

MessageList = MDRO.SetSelectionLowParameter ( "MDR", "", "SelectByText", "LowerBoundaryText", this.Text, MDRO_ID );

}

MessageText2.Clear();

if ( MessageList.MessageTypeItem.Count() > 0 ) {

MessageText2 = MessageList.MessageTypeItem.GetFirst().Text.content;

Trace.Info ( "--- Info: " + MessageText2 );

}

// Schedule the first MDR

this.MyAction2();

return;

----------------------- -------------- --------------------------

----------------------- MyAction2 --------------------------

// Schedule MDR

import ABSL;

import AP.PlatinumEngineering;

var MDRO_ID : XPEString;

var MessageList : MessageList;

var MessageText : MessageType.Text.content;

Trace.Info ( "--- Schedule MDR" );

MDRO_ID.Clear();

MDRO_ID = "ZZZ";

// Calculate Start Data/Time (UTC)

var currentTime = Context.GetCurrentGlobalDateTime();

var StartDuration = Library::Duration.Create ( 0, 0, 0, 0, 0, 5 ); // 5 sec

var startTime = currentTime.AddDuration ( StartDuration );

// Schedule MDR (start asynchronously with 5 sec timeout)

MessageList = MDRO.ExecuteDateTime ( "MDR", "", startTime, MDRO_ID );

MessageText.Clear();

if ( MessageList.MessageTypeItem.Count() > 0 ) {

MessageText = MessageList.MessageTypeItem.GetFirst().Text.content;

Trace.Info ( "--- Info: " + MessageText );

}

return;

----------------------- -------------- --------------------------

----------------------- MyAction3 --------------------------

// BO action import ABSL;

import AP.PlatinumEngineering;

var MDRO_ID : XPEString;

if ( this.Number <= 0 ) {

Trace.Info ( "--- Stop MDR Recurrence process" );

return;

}

MDRO_ID.Clear();

MDRO_ID = "ZZZ";

Trace.Info ( "--- JobStatus: " + MDRO.GetJobStatus ( "MDR", "", MDRO_ID ) );

// Update Values (Do some useful work)

var Query = BO.QueryByElements;

var SelectionParams = Query.CreateSelectionParams();

var BOs = Query.Execute ( SelectionParams );

Trace.Info ( "--- Process Data" );

foreach ( var bo in BOs ) {

if ( this.Text == bo.Text ) {

bo.Number = bo.Number - 1;

} else {

bo.Number = bo.Number + 1;

}

if ( this.Text == bo.Text ) {

this.Number = bo.Number;

}

}

if ( this.Number <= 0 ) {

Trace.Info ( "--- Stop MDR Recurrence process" );

return;

}

// Schedule the next MDR

this.MyAction2();

return;

----------------------- -------------- --------------------------

Please notice the creating MDR instance "ZZZ" is correspondent to Run ID.

In the example, the custom Query is bound to MyAction3 and uses field Text in the query condition.

Button Schedule triggers MyAction1 that launches MDR recurrence process.

Values in column Text should be unique. The field Number of selected row is used as a counter so please set there a wishing number of runs. The rest values in column Number increase on 1 each run.

After all, we chose an other way to implement the MDR recurrence process. We managed to create our own MDR owl screen where we just use regular screens and navigation among them.

Best regards,

Aleksei

Answers (3)

Answers (3)

abelousov
Active Participant
0 Kudos

In addition, it appeared that intervals between runs were not exactly equal to 5 sec. In this case they varied from 5 to 61 sec.

Best regards,

Aleksei

abelousov
Active Participant
0 Kudos

Hello Horst!

Thank you for your attention.

In fact there were no problems to start MDR manually.

Of course the MDRO_ID exists. (after first run)

I was stuck on starting MDR programmatically with the MDR code in ABSL.

By now I have already found out the cause - there was one detail:

There is the MDR code in MyAction1 and it started to work just after I turned on "Save After Execution" checkbox.

I believe that when MDR runs MyAction2 (data updating there), after that all the updates must be saved what the checkbox does.

Next issue I am now solving is a certain error message in logs - "failed create notifications raised".

It looks like some system message tries to appear (maybe over saving?). It is probably impossible in background where MyAction2 executes asynchronously.

Besides that, break-points and custom messages do not work in the background as well. The error is not fatal, though. All updates are done properly.

I would like to implement recurrence in the same way as setTimeout() in JavaScript works, that is, MyAction1 calls (schedules with MDR) MyAction2. MyAction2 does some work and calls MyAction1 and so forth.

Thank you,

Aleksei

HorstSchaude
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Aleksei,

If you trigger the execution of a MDRO manually in ABSL the MDRO with the given ID must already exist.

Is this ensured?

Bye,
. Horst