Select for all entries in SAP ABAP


Select for all entries in SAP ABAP, What are the advantages of select for all entries in SAP ABAP programming

A+ A-

SELECT FOR ALL ENTRIES is the best alternative for SELECT WITH JOINS, this statement is very helpful for reading data from more than 2 tables.
The load on database will be very less.
Syntax : 

SELECT <FIELDS> FROM <DBTABLE1> INTO TABLE <ITAB1>
WHERE <CONDITION>.
SELECT <FIELDS> FROM <DBTABLE2> INTO <ITAB2> FOR ALL ENTRIES IN <ITAB1>
WHERE <FIELD1> = <ITAB1>-FIELD1.
**HERE WE ARE READING DATA 2 DATABASE TABLES, SEE WHERE CONDITIONS OF SECOND SELECT STATEMENT

Ensure before using SELECT FOR ALL ENTRIES

  • Parent internal table must not be empty ( If it is empty, where condition fails and it will get all records from database).
  • Remove all duplicate entries in parent internal table.

Here is the example of using SELECT FOR ALL ENTRIES in real-time applications

DATA: it_mara TYPE TABLE OF mara,
      wa_mara TYPE mara.
DATA: it_makt TYPE TABLE OF makt,
      wa_makt TYPE makt.
SELECT *
  FROM mara
  INTO TABLE it_mara
  WHERE mtart = 'FERT'.
IF it_mara IS NOT INITIAL.
  SELECT *
    FROM makt
    INTO TABLE it_makt
    FOR ALL ENTRIES IN it_mara
    WHERE matnr = it_mara-matnr.
ENDIF.


Was this lesson helpful to you? Yes No 78 People out of 93 think this lesson helpful

Lesson Navigation

←Previous Chapter
Next Chapter →