Q
Problem solve Get help with specific problems with your technologies, process and projects.

Deleting entries from a dynamic table

I have dynamic internal table . How do I delete entries from this table on the basis of some condition.

I have dynamic internal table . How do I delete entries from this table on the basis of some condition?
Well, you can't use DELETE WHERE with dynamic tables, but it is still possible to delete records. Consider a situation where you want to delete all entries in where FIELD1 (one of the fields in the table) is equal to 'X'.

DATA. lp_data TYPE REF TO DATA.
FIELD-SYMBOLS: 
   
     TYPE ANY,
               
    
      TYPE ANY.

CREATE DATA lp_data LIKE LINE OF 
     
      .
ASSIGN lp_data->* to 
      
       .

ASSIGN COMPONENT 'FIELD1' OF STRUCTURE 
       
         TO 
        
         . LOOP AT 
         
           INTO 
          
           . CHECK 
           
             EQ 'X'. DELETE TABLE 
            
              FROM 
             
              . ENDLOOP. 
             
            
           
          
         
        
       
      
     
    
   

Another possibility is to use, for example, with a table that has key fields kf1 and kf2:
DELETE TABLE WITH TABLE KEY ('KF1') = val1 ('KF2') = val2.

With fully specified keys this is very efficient for HASHED tables, somewhat efficient for SORTED tables, and not very efficient, usually, for STANDARD tables.

As ever, what you actually write depends on precisely what you are trying to achieve.

This was last published in April 2008

Dig Deeper on SAP data management

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchERP

SearchOracle

SearchDataManagement

SearchAWS

SearchBusinessAnalytics

SearchContentManagement

SearchHRSoftware

Close