We can help. Together we learn....

Info - For all select

by Voice | Tuesday, May 05, 2009 in |

1. Before doing a for all select, just make sure the internal table you are using for all select is not empty (INITIAL). If it is empty then for all select will fetch all the records in the database and thay may be a problem. So be careful.


2. Mechanism of for all select: SAP first fetches all the record and then it sort the records found and then it does a delete duplicates comparing all the fields. So, if you want to retrieve all the records, you MUST select all the key fields or else you will lose some records.

Try it for youself:
Check the number of records present in the database table and the number of records present in internal table.


REPORT  Z000_TEST_FOR_ALL_SELECT.

types: begin of ty_dd02l,
         tabname type tabname,
       end of ty_dd02l,

       begin of ty_dd03l,
         tabname type tabname,
         KEYFLAG type KEYFLAG,
       end of ty_dd03l.

data: i_dd02l type standard table of ty_dd02l initial size 0,
      i_dd03l type standard table of ty_dd03l initial size 0.

data: v_tabname type dd02l-tabname.
select-options s_table for v_tabname.

select TABNAME
   from dd02l
  into table i_dd02l
  where tabname in s_table.

IF sy-subrc = 0.
  select TABNAME
         KEYFLAG
    from dd03l
    into table i_dd03l
    for all entries in i_dd02l
    where tabname = i_dd02l-tabname.

  IF sy-subrc = 0.

  ENDIF.
ENDIF.


0 comments:

Categories