Search This Blog

Wednesday, June 1, 2011

FOR ALL ENTRIES Command in ABAP

'For All Entries' command is helpful in fetching records and is generally used with the Select statement.

Sample Program :

TABLES : EKKO, EKPO.
DATA: IT_EKKO TYPE STANDARD TABLE OF EKKO,
              WA_EKKO LIKE LINE OF IT_EKKO,

              IT_EKPO TYPE STANDARD TABLE OF EKPO,
              WA_EKPO LIKE LINE OF IT_EKPO.

SELECT *
UP TO 10 ROWS  "ONLY RETURN FIRST 10 HITS
FROM EKKO
INTO TABLE IT_EKKO.

LOOP AT IT_EKKO INTO WA_EKKO.
  WRITE : /  WA_EKKO-EBELN.
ENDLOOP.

IF SY-SUBRC EQ 0.

* THE FOR ALL ENTRIES COMAND ONLY RETRIEVES DATA WHICH MATCHES
* ENTRIES WITHIN A PARTICULAR INTERNAL TABLE.

 SELECT *
 FROM EKPO
 INTO TABLE IT_EKPO
 FOR ALL ENTRIES IN IT_EKKO
 WHERE EBELN EQ IT_EKKO-EBELN.

  WRITE:/ 'FOR ALL ENTRIES COMAND '.

 LOOP AT IT_EKPO INTO WA_EKPO.
    WRITE:/ WA_EKPO-EBELN, WA_EKPO-EBELP.
 ENDLOOP.

ENDIF.