Overview
Disclaimer: I created these objects to mess around with trying to create a set of parallel objects that were easy to use and similar to other languages. There are a number of complexities that may impact their use / function. If you use them then you do so at your own risk! Also I just named them with PRC for consistency, apparently there are some other projects that have this 3 letter combination which I didn't realize till I had done most of the code, it just made the most sense as i was using the term 'process' throughout.
A while ago i was trying to check out some of the asynchronous function stuff that ABAP has to offer and I realized that I really wasn't a fan of the existing methods. Due to this i decided to try and create some objects that felt a little bit more like what i was used to.
Concept
There are two primary categories I developed to attempt to achieve this. One is the 'Process' which is fired off and forgotten about. No one cares about the results of this object. The other type is the 'Completion Process' where we want to know the results of that process at some point during our code. Ideally I wanted it to be as easy to use as possible so I modeled the idea around the 'Runnable' and 'Callable' interfaces from other languages as they make some sense. The idea is not to replicate any functionality, just to make something that makes sense from a developer perspective with the least amount of hoops to jump through in order to achieve the outcome.
Sadly there are a number of limitations to trying this and as many have pointed out before, to use objects they must be serialized / deserialized and passed through shared memory. The overhead is very large and the efficiency suffers from this. Later in the example, you can test that the performance suffers greatly with higher iterations and lower sized calculations, but begins to improve considerably with very large calculations that take a lot of time.
I wont discuss the construction in further detail, rather I will show the solution and leave the exploration up to anyone who wishes to inspect the provided files further.
Using a Process Object
The following is an example of using the process object. The nugget file has two example programs but the following is the simplest example of running process. There are ways to wait for completion if desirable but not shown below.
1) Create a class which implements the ZIF_PRC_RUNNABLE interface
2) Implement the ZIF_PRC_RUNNABLE~RUN method
3) Use the object as follows
Using a Completion Process Object
This is a little more detailed than the previous example but rather than go into too much depth i will just provide the most basic example of this. For a more detailed example check the program packaged in the .nugg file.
1) Create a class which implements the ZIF_PRC_CALLABLE interface
2) Implement the 3 methods, ZIF_PRC_CALLABLE~:IS_OBJECT, GET_RETURN_TYPE, CALL
3) Use the object as follows
Package / Installation
The files can be found in the 'ParallelObjects.nugg' located here.
Additionally if the functions fail to import which they did one time for me they can be found in the 'ParallelObjects_Functions.nugg', found here.
1) Run ZSAPLINK to import the 'ParallelObjects.nugg' file
2) Make sure everything imported is all Green. Then activate the imported objects
4) Check that the function group imported successfully! The following function group should show, make sure everything is active. Note that if they don't show use the ZSAPLINK program to run the 'ParallelObjects_Functions.nugg', and overwrite the function group e.g. 'Yes to All'.
5a) We need to create the shared memory classes in transaction SHMA. Since i provided them in the package you will get the following error if you try to create any. If you get the error delete the thing(using the trash can icon) and redefine per the following steps.
5b) Define the ZCL_PRC_MONITOR_AREA class EXACTLY as shown.
5c) Define the ZCL_PRC_EXECUTOR_AREA class EXACTLY as shown.
Done!
That should be all, though any issues with that hopefully will be obvious otherwise you would need to make a comment. Note that the objects,while easy to use(i hope), require a lot of overhead. If you want to have object results that have object attributes with a completion process you need to make all the objects serializable. The completion process is reasonably less efficient than the regular process, and if there are database modifications happening it is never appropriate to use these objects since a commit will occur due to work process switching.However, with sufficiently slow or time consuming methods efficiency can be gained over running the same process in serial. I attempted to construct a program to illustrate this for the completion process, but you will have to do your own investigation with the regular process.
Example program 'ZPRC_COMPLETION_RUN_TESTS' shows the greater the check number the more efficiency is gained due to the time it takes to complete the operation. The higher the iterations with a low check number the overhead is too great to gain any benefit and efficiency is lost. The default work process use is set to 4, it can be changed , shown in the examples packaged. The code will use as many as available up to the input limit or maximum available work processes depending on which comes first.
Hope you enjoyed reading / checking this out. Bye!