ABAP "for all entries in" User Guide

Source: Internet
Author: User

Reprinted from: http://www.cnblogs.com/panjun-Donet/archive/2010/10/20/1857100.html

 

During ABAP development, for a clustered table that cannot be joined or an in-select table that needs to be used, we generally use the for all entries in statement to concatenate the table with an in-table,
Query the required data. For example, the bseg clustering table is as follows:
Select bseg ~ Kunnr bseg ~ Lifnr bseg ~ Belnr into Table itab_bseg from bseg for all entries in itab_main
Where bukrs in _ bukrs and (belnr = itab_main-belnr and hkont = itab_main-hkont ).

Because bseg cannot perform inner join with BSIS, put the BSIS content in itab_main first, and then use for all entries in for concatenation.
1-In the WHERE clause, bukrs in _ bukrs indicates that bseg-bukrs exists in select-options of _ bukrs. _ bukrs is not the field of itab_main, so this part is not included in brackets.
Of course, the memory usage will be increased.
In the original condition, operations are performed on the database several times (the number of records in the driving table,
After you use for all entries,
It is equivalent to connecting all values of the condition fields in the driver table with or,
One db operation,
The increase in conditional statements will inevitably increase memory usage.
Select carrid connid price from sflight into Table it_price for all entries in it_sflight
Where carrid = IT_SFLIGHT-CARRID and connid = IT_SFLIGHT-CONNID '.
In the where condition, the IT_SFLIGHT-CARRID and IT_SFLIGHT-CONNID columns are used as placeholders. The result set of the SELECT statement is the union of all result sets of the SELECT statement. These result sets use internal tables.

The result of replacing the placeholder value in it_sflight on each line. In fact, the special variant of the WHERE clause is the simple syntax of the where basic statement below.
Select distinct carrid connid price from sflight into Table it_price
Where (carrid = 'lh 'and connid = '000000') or (carrid = 'sq' and connid = '000000 ') or (carrid = 'lh 'and connid = '000000 ').
2. With this statement, the system automatically deletes duplicate rows for the final result set. Therefore, if you want to retain duplicate Row Records, remember to add enough key-value items in the SELECT statement (add all key-value items if necessary) to ensure

Duplicate items in the certificate result set are not deleted. (For example, when selecting the payment amount, the payment event may be different, but the amount may be the same. Pay attention to this to avoid incorrect deletion of the result record .)
3. If the internal table itab used after for all entries in is empty, the system selects all records under the current client unconditionally. Therefore, to avoid meaningless full-part retrieval, you must determine the internal

Whether the table itab is null. If it is null, the database query containing the statement is not executed.
4. Because itab-F is actually replaced as a placeholder, the internal table itab should not contain header rows (Project ID name rows) to avoid confusion and retrieval errors.
5. the type and length of the item used as a condition replacement in the itab internal table must be the same as that in the Retrieval Database. Otherwise, the compilation fails.
6. the like, between, and in comparison operators cannot be used to replace items in the itab table as conditions. Because these comparison operators are all uncertain comparison operators (set the selection conditions in a range), and for all

The function of the entries in statement is to split all the selection condition blocks and connect them with or. If there is an uncertain range in each or branch, the system performance will be greatly reduced, therefore, the R/3 system prohibits incorrect use of this statement.

Set the comparison operator.
7. When this statement is used, the order by statement and having statement cannot be used.
8. When this statement is used, All Aggregate functions (max, Min, AVG, sum) except count (*) cannot be used.
// Determine whether the internal table is empty

Statement: Describe table itab lines variable. Determine whether the system variable sy-subrc is 0. If it is 0, it indicates that it is not empty. Otherwise, it is empty!
Describe table itab lines variable
If not p_variant is initial.
WX_VARIANT-VARIANT = p_variant.
Endif.
Note: although the use of for all entries in is very convenient in some aspects, it consumes a lot of memory and must be noted during use. It is recommended not to use it unless absolutely necessary.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.