Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use ABAP's new keyword REDUCE to complete the actual task

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to use ABAP's new keyword REDUCE to complete actual work tasks". In daily operation, I believe many people have doubts about how to use ABAP's new keyword REDUCE to complete actual work tasks. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to use ABAP's new keyword REDUCE to complete actual work tasks." Next, please follow the editor to study!

Look at a specific example: a new keyword REDUCE in ABAP 740s. The function of this keyword is similar to the Reduce operation in the "Map-Reduce" programming model, which is widely used in the field of large-scale data set parallel computing, and can be taken literally as "reduction".

The following figure shows the working steps of the Map Reduce framework to count the number of word occurrences in a massive input dataset (for example, greater than 1TB). As ABAP developers, we don't need to know every step of the implementation of the Map Reduce framework, just focus on the input of the framework and the results of the execution.

Go back to the actual work tasks accepted by Jerry. A German colleague asked Jerry to do a statistic on a CRM test system, listing the number of inner table rows in the database table CRM_JSTO, OBTYP (Object Type) and STSMA (Status Schema), with the same value. You can compare "OBTYP and STSMA two inner table rows with the same value" to the repeated words in the figure above.

The following figure shows some lines of CRM_JSTO:

The following figure shows the task completed by Jerry: there are more than 550,000 rows in the inner table on the test system, including 90279 rows, only maintaining OBTYP as TGP, but not maintaining STSMA. In second place was a combination of COH and CRMLEAD, which appeared 78722 times.

Friends who have done a little bit of ABAP development are sure to write the following code immediately:

Use SELECT COUNT to complete the statistical work directly in the database layer. This is also the practice recommended by SAP, the so-called Code pusudown guidelines, that is, operations that can be put into the HANA database level, as far as possible, in order to make full use of the powerful computing power of HANA. Under the premise that the database can complete the computing logic, try to avoid putting the computational logic into the Netweaver ABAP application layer to do.

However, we also need to be aware of the limitations of this approach. Jerry has quoted SAP CTO's famous saying before:

There is no future with ABAP alone

There is no future in SAP without ABAP

The future ABAP will move towards the road of openness and interconnection. Back to this requirement itself, suppose that the input data to be retrieved is not from the ABAP database table, but from the HTTP request, or the IDOC sent by the third-party system. At this time, we can no longer use the SELECT COUNT operation of OPEN SQL itself, but can only solve this problem in the ABAP application layer.

As the so-called technology does not weigh down, Jerry here introduces two ways to accomplish this requirement with ABAP.

The first method is more traditional and is implemented in the method get_result_traditional_way:

ABAP's LOOP AT GROUP BY keyword combination is almost tailor-made for this demand: specify obtyp and stsma columns for GROUP BY, and then LOOP AT will automatically group the row records entered into the table according to the values of these two columns, and the number of row records in each group will be automatically calculated by the keyword GROUP SIZE. The values of each group's respective obtyp and stsma, as well as the number of entries within the group, are stored in the variable group_ref specified by REFERENCE INTO. All the ABAP consultant needs to do is simply store the results in the output table.

The second option, as described in the title of this article, is to use the new REDUCE keyword of ABAP 740:

The above code may seem a little obscure at first glance, but after careful reading, it is found that this approach essentially adopts the same grouping strategy as method-LOOP AT GROUP BY-grouping according to obtyp and stsma, these subgroups are identified by variables, and then accumulated through the REDUCE keyword on line 10. Manually counting the number of entries in this group-- reducing a large input set to smaller subsets according to the criteria specified by GROUP BY, and then calculating each subset-- is the idea that the REDUCE keyword is passed literally to ABAP developers.

Summarize and compare these three implementation methods: when the data source to be counted is ABAP database table, OPEN SQL must be preferred to make the calculation logic completed in the database layer in order to obtain the best performance.

When the data source is not an ABAP database table and the requirement of grouping statistics is a simple counting operation (COUNT), LOOP AT is preferred. GROUP BY... GROUP SIZE, so that the counting operation is completed through GROUP SIZE in ABAP kernel, in order to achieve better performance.

When the data source is not an ABAP database table and the requirement of grouping statistics is custom logic, using the third REDUCE solution introduced in this paper, the custom statistical logic is written after the NEXT keyword in line 11.

The performance of the three solutions decreases in turn, but the applicable situation and the degree of flexibility increase in turn.

LOOP AT... GROUP BY... GROUP SIZE, it took 0.3 seconds to process 550000 records on Jerry's server, while REDUCE took 0.8 seconds.

At this point, the study on "how to use ABAP's new keyword REDUCE to complete the actual work task" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report