Fiori-like Prototype (Parallel Processing)

Parallel Processing.

Parallel Processing

SAP SPTA Parallel Processing Framework in ABAP.

SPTA

With the advent of HANA and In-Memory processing, this topic might look mis-timed. But, there are many organizations, which still have no plan to move to HANA within couples of years. As they say, the show must go on and that motivated us to publish this long pending article here for those ABAPers, who still have to deal millions of rows in batch jobs and who feel the “Nights are getting too shorter to execute those batch jobs in SAP” (inspired from a friends blog).

Why parallel processing required?

Parallel processing is required mainly to improve the performance of any ABAP program. Using parallel processing framework we can significantly improve the processing time of any program, particularly where data volume is very high. The basic concept behind the parallel processing framework is to divide the large volume of data into several small work packets and process different work packets into different tasks. So each work process will be processed at the same time in parallels and it will significantly reduce time. Nowadays every distribution-related projects have a large volume of data so invoking parallel processing framework is very useful to reduce time.

Conventional Parallel Processing

We can use parallel processing framework by calling any RFC enabled function module in NEW TASK. In this way, after determining the number of work packets we can create different tasks for each work packets and process them in parallel.

Also Read: bgRFC in SAP

Why SPTA framework required?

SPTA framework is the most sophisticated and secured framework for parallel processing provided by SAP. If we want to handle multiple records and want to update/check multiple database tables in parallel, in that case, using conventional way to invoke parallel processing is difficult and there can be some ABAP memory issue. But in SPTA framework there are build in security for all the ABAP memory related issues so it is very secure. Also, SPTA framework is very easy to implement and all the parallel processing work is handled by SAP we do not need to bother how to handle it. In this way, it is also a very sophisticated framework.

SPTA Parallel Processing Framework

To invoke SPTA framework we need to call function module SPTA_PARA_PROCESS_START_2. This is a standard SAP provided function module. In this function module, we have to use three subroutines to build our own processing logic.

Invoke  SPTA framework

BEFORE_RFC_CALLBACK_FORM: This routine is called by the function module before calling the RFC function module. Here we have to build different work packets which we want to process in the RFC function module.

IN_RFC_CALLBACK_FORM: This routine is called by the function module after work packets are created. In this routine, we can use our own RFC enabled function module or custom code to process each work packets.

AFTER_RFC_CALLBACK_FORM: This routine is called at the end by the function module. After processing of all the work packets, we have to collect all the processed data.

We have mentioned server group also when calling the function module. The server group can be maintained in the RZ12 transaction. But this is BASIS activity.

In the changing parameter, we have to pass our total internal table which contains all the data. From this internal table, we will create different small work packets (i.e. Internal tables) for parallel processing.

In the call back program name, we have to pass the calling program name.

Hope you are not confusing Parallel Processing with Parallel Cursor TechniquePlease read this Graphical and Statistical Analysis of Parallel Cursor Technique in LOOPs.

Now we will discuss the main three subroutines and how to call them in details.

BEFORE_RFC_CALLBACK_FORM: In this routine, we have to create small internal tables which we are referring as work packets for parallel processing in the IN RFC routine. Please refer the below screenshot.

Before RFC

All the parameters which are passed in this subroutine are mandatory. Here first we have to create small work packets. In the above code, it is defined like one work packet will contain 10 records. After creating one work packet I have ENCODE the data for further downstream processing. Also, we have to inform task manager that one RFC can be started by passing ‘X’ in the START_RFC field.

Also Read: What is Passive bgRFC?

IN_RFC_CALLBACK_FORM: In this routine, we have to write own processing logic to process all the data. We can call a RFC enabled function module from this routine or we can write our own logic inside this routine also. For each work packets, different tasks will be created and each task will call this routine for processing of data. Please refer below screenshot.

In RFC

In the above code, I have first decoded the encoded data which is coming from BEFORE_RFC_CALLBACK_FORM routine for each work packets. Then write your own logic or call RFC enabled function module for processing. In the above example, I just sorted the random data. Then again I have encoded data for the downstream processing in AFTER_RFC_CALLBACK_FORM routine.

AFTER_RFC_CALLBACK_FORM: In this routine after processing of all the data we have to collect data. In this routine basically, we have to prepare final internal table after all the data processing. Please refer the attached screenshot.

After RFC

In the above example I have decoded the data again and then displayed all the record. Here if any unit fails during processing in IN_RFC_CALLBACK_FORM no data will be available to collect because if any unit fails we must not prepare final table with less number of valid records. We can catch the failed unit by using IF_RFCSUBRC and IF_RFCMSG.

So by using this function module, we can invoke parallel processing framework in a sophisticated and secure manner.

Please download the code used in the above demonstration from Here.

Please note: We can design our own parallel processing technique without using SPTA Framework. The concept remains the same in the custom design too i.e. Records get processed into multiple different tasks and that runs parallel. So the processing time is reduced manifold.

My friend Partha (whom I referred in the first paragraph) has explained the custom Parallel Processing using a Program. Please check here:Parallel Processing Technique in SAP ABAP and it’s Advantages

Also, check SCN Blog on Two Different Types of Parallel Processing Examples

Here Partha has explained the concept and debugging of SPTA framework in a very illustrative way. Please check the Post on Parallel Processing and Debugging.


Reference:

Two Different types of Parallel Processing examples

Parallel Processing ( ABAP Wiki )

SPTA Parallel Processing Framework in ABAP

SAP ABAP 实现多线程

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 205,236评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,867评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,715评论 0 340
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,899评论 1 278
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,895评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,733评论 1 283
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,085评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,722评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,025评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,696评论 2 323
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,816评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,447评论 4 322
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,057评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,009评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,254评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,204评论 2 352
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,561评论 2 343

推荐阅读更多精彩内容