For all entries usage

Source: Internet
Author: User
For tables that cannot be joined, use the for all entries in statement to concatenate the table with the internal table.

Select bseg ~ Kunnr

Bseg ~ Lifnr

Bseg ~ Belnr

Into Table itab_bseg

From bseg

For all entries in itab_main

Where bukrs in _ bukrs

& (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.

 

1. 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 the result sets of the SELECT statement. These result sets Replace the placeholder results with the corresponding values in the it_sflight internal table on each row. 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 keep repeated Row Records, remember to add enough key-value items in the SELECT statement (add all key-value items if necessary ), to ensure that repeated items in the 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 whether the itab in the internal table is empty before using this statement. If it is null, the Database Retrieval Processing containing this 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. These comparison operators are all uncertain comparison operators (the selection condition is set within a range), and the function of the for all entries in statement is equivalent to concatenating all the selection condition blocks and connecting them with or, if the range of each or branch is uncertain, the system performance will be greatly reduced. Therefore, the R/3 system prohibits the use of uncertain comparison operators when using this statement.

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.

-------------------------------------------------------------------------

 

I. Notes for using for all entries in select statements
In ABAP programming, using for all entries in is an essential statement. I believe everyone has used it. For example:

Data: Begin of ig_bseg occurs 0,
Werks like bseg-werks,
Belnr like bseg-belnr,
Gjahr like bseg-gjahr,
Dmbtr like bseg-dmbtr,
End of ig_mseg.
If not ig_bkpf [] is initial.
Select werks belnr gjahr dmbtr into corresponding fields of table ig_bseg
From bseg for all entries in ig_bkpf
Where werks = ig_bkpf-werks and belnr = ig_bkpf-belnr and gjahr = ig_bkpf-gjahr.
Endif.

Pay attention to the following issues:
1. First, you must determine whether the internal table after for all entries in is null. If it is null, therefore, the results of comparing fields in the where condition with the internal table are all true, that is, all the conditions are met. This results in a large amount of data being retrieved, which greatly affects the system performance.
2. For the above example, all the line items of a credential can be retrieved by logical analysis, but the actual situation will be different from what you expected, if the dmbtr values of multiple row items of a credential are the same, you will only get one row of record in the ig_bseg of the internal table, instead of multiple rows. It automatically uses distinct, or you can delete duplicate rows.ProgramLogical errors are difficult to find. The solution is to ensure that the data retrieved from the ig_bseg must have a primary key field. In this example, you need to add the buzei field.

Ii. Notes for self-built tables and data import from outside the system
1. When creating text fields (creating domain by yourself) in a self-built table, be sure to allow the fields to retain the text case. Otherwise, all fields are converted to uppercase letters by default.
2. for various credential encoding fields, such as material credennr NR, kunnr, lifnr, and belnr, when importing data to a self-built table, pay attention to the supplement of leading 0, otherwise, the imported data may not contain leading 0. The function that supplements leading 0 is conversion_exit_alpha_input. In addition, when creating a self-built table, convert the domain corresponding to this field to convers. routine: Set to Alpha.

 

In addition, I think this is suitable for internal tables with less data. Although it means getting data from the database at once, the number of database connections is reduced, but it causes a great burden on the database.

----------------------------------------------------

 

Duplicates are discarded from the result set. If the internal table itab does not contain any entries, the system treats the statement as though there wereNoWhere cond condition, and selects all records.

In the above sap help description for all entries, I did not pay attention to the first note. As a result, the program was written with an inexplicable error. Sometimes the calculated results are rare and sometimes correct, I have been searching for a long time and do not know why. When using for all entries in the future, the fields retrieved must include the primary key of the table, so there is no problem.

 

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.