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 compare OPEN CURSOR and SELECT in ABAP OPEN SQL

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This article shows you how to compare OPEN CURSOR and SELECT in ABAP OPEN SQL. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

I wrote a very simple report verification:

Source code:

OPEN CURSOR lv_cursor FOR SELECT product_guid FROM comm_product.FETCH NEXT CURSOR lv_cursor INTO TABLE lt_selection PACKAGE SIZE size.

Size = 1: the total number of records scanned in table COMM_PRODUCT observed from ST05 at this time is 1447.

The second time is executed with size = 100. PREPARE and OPEN directly become REOPEN, but recs is still 1447.

Press F1 on the field Recs in ST05 to view the description:

How did this 1447 come from? Because I didn't specify any conditions when I OPEN CURSOR, in OPEN CURSOR, DB treats all the records of the entire product table as a result set, and then returns only the number of entries of the specified package size.

So the Recs seen in ST05 refers to the number of records that meet the criteria specified by OPEN CURSOR, not the number of records finally returned to the ABAP layer.

In my test system, the table COMM_PRODUCT contains a total of 1447 records.

Then I generate three new product,COMM_PRODUCT and there are 1450 entry in it.

Repeat the test report. ST05 found that the number of records scanned has increased to 1450, proving that our conclusion is correct.

One more verification: table COMM_PRODUCT contains 3 records whose prefix starts with JERRY06152012:

Modify the above test report to add a WHERE query condition:

OPEN CURSOR lv_cursor FOR SELECT product_guid FROM comm_productWHERE product_id LIKE 'JERRY06152012%'.

Execute size = 1 for the first time

Recs becomes 3, because there are really only 3 records that match the OPEN CURSOR condition.

Size = 100, ST05 result is exactly the same as size = 1, both are 3. 5%.

Conclusion

Maximum Number of Results on WebClient UI (Max hit for short) cannot control the number of records each time OPEN CURSOR goes to DB to find records, which is determined by WHERE CONDITION followed by OPEN CURSOR. Max hit can only control how many entries are returned to ABAP in the result set determined by OPEN CURSOR's WHERE CONDITION.

Through the verification above, this understanding is wrong.

Another function of OPEN SQL's select is UP TO XX ROWS.

Test with the following code:

SELECT product_guid INTO CORRESPONDING FIELDS OF TABLE lt_line FROM comm_product UP TO num ROWS.

Num = 1

Num = 143,

It shows that SELECT UP TO XX ROWS can control how many records are processed in the database table.

But SELECT UP TO XX ROWS cannot be executed repeatedly in a WHILE loop like OPEN CURSOR, and it does not have a mechanism like OPEN CURSOR that allows it to remember the location of the record currently being operated in the result set.

The above is how to compare OPEN CURSOR and SELECT in ABAP OPEN SQL. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

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

Database

Wechat

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

12
Report