Best Way to Update datbase table in this Scenario

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

Post Reply
shenyonglian
Posts: 85
Joined: Sun Oct 20, 2002 7:35 pm

Best Way to Update datbase table in this Scenario

Post by shenyonglian » Mon Jan 15, 2007 4:31 am

Hi, I got a customer table ZTEST , and a internal table iTAB with same structure as ZTEST.

Currently there is 3 record for example.

Record 1: AAA, BBB, CCC
Record 2: DDD, EEE, FFFF
Record 3: GGG, HHH, III

At beginning of program iTAB is populated from ZTEST, so iTAB get the same 3 records as ZTEST. Then,

iTAB will possilbe get more new records/modify some old recrds/delete some old records, now iTAB is, for example.

Record 1: AAA, BBB, DDD (Changed)
Record 2: DDD, EEE, FFFF (no change)
Record 3: JJJ, KKK, LLL (new record, and the record GGG,HHH, III has been deleted)

So, now I'd the like to make same update tabel ZTEST to make it consistent with iTAB .

Is there any easier / quicker way to do this (combined with INSERT / DELETE / UPDATE)?

Thanks in advanced

ilya
Posts: 2327
Joined: Thu Oct 31, 2002 4:49 am
Contact:

Post by ilya » Mon Jan 15, 2007 5:44 am

You have to save the entries to be deleted in a separate internal table. Then you can use MODIFY and DELETE statements with internal tables as parameter.
ilya

More input data: http://abaplog.wordpress.com
Sapfans ABAP FAQ: viewtopic.php?t=94198
Rich's ABAP Knowledge Corner: http://www.richard-harper.me.uk/Kb/default.html
Function modules documentation: http://www.se37.com

Deeler Stan
Posts: 410
Joined: Thu Mar 31, 2005 3:44 am

Post by Deeler Stan » Mon Jan 15, 2007 7:18 am

Or you colud

select into table itab

itab2[] = itab[].


then do your processing

delete ztest from table itab2.
modify ztest from table itab.
commit work.

skarkada
Posts: 701
Joined: Mon Oct 21, 2002 1:12 pm
Location: Houston, TX, USA

Post by skarkada » Mon Jan 15, 2007 12:34 pm

DELETE FROM ztest. "deletes all records in one shot
INSERT ztest FROM TABLE itab.
COMMIT WORK.

------------------------------
Remember that MODIFY is more expensive than INSERT.
You still have to lock the table, etc.
Assumption is that the number of records is fewer or the ratio of records changed / deleted is high. Otherwise, go with Ilya's suggestion.
Sudhi Karkada

Rich
Posts: 7116
Joined: Thu Oct 31, 2002 4:47 pm
Location: Liverpool
Contact:

Post by Rich » Tue Jan 16, 2007 2:14 am

skarkada wrote:DELETE FROM ztest. "deletes all records in one shot
INSERT ztest FROM TABLE itab.
COMMIT WORK.

------------------------------
Remember that MODIFY is more expensive than INSERT.
You still have to lock the table, etc.
Assumption is that the number of records is fewer or the ratio of records changed / deleted is high. Otherwise, go with Ilya's suggestion.
You'd still need to lock the table in that case, rather than the actual record you are working with. Which would also mean modifying the programs that read this table to use the same lock object. (Which you would also have to do if you locked it row by row).
Regards

Rich

Image
Abap KC:http://www.richard-harper.me.uk/Kb
SFMDR:http://www.se37.com

blueoxygen
Posts: 1
Joined: Tue Jan 16, 2007 1:47 am

Post by blueoxygen » Tue Jan 16, 2007 4:38 am

MODIFY maybe is your answer.

new2sdbilling
Posts: 61
Joined: Mon Mar 13, 2006 9:53 pm

Post by new2sdbilling » Thu Feb 22, 2007 8:35 pm

You have to save the entries to be deleted in a separate internal table.

How to make this?? :cry:

How to save the entries to be deleted in a separate internal table??

I have an input enabled check-box for each line displayed.
  • Aim to select multiple lines using checkbox from the Basic List displayed and then delete those lines in the internal table & delete corresponding lines in database & re-display the List.

    Code: Select all

    WRITE: /2 CHK AS CHECKBOX, 5 ITAB-KUNNR, 16 ITAB-NAME1. 
    
    ........ 
    ........ 


    "To put a delete button on the screen (Fcode = DELETE) with a checkbox on each line.

    Code: Select all

    
    at user-command.                                                    
      case sy-ucomm.                                                    
        when 'DELETE'.                                                  
            do counter times.    " How 'counter 'defined?                                       
                read line sy-index.                                     
                if CHX = 'X'.  
                   ..."How to save the entries in a separate internal table ITAB2??
               endif.                                                  
            enddo.    
        
            delete ztest from table itab2.   
            commit work.      
                              
            perform write_report.                                       
            sy-lsind = 0.                                               
      endcase.                   
NewBie to abap

new2sdbilling
Posts: 61
Joined: Mon Mar 13, 2006 9:53 pm

Post by new2sdbilling » Fri Feb 23, 2007 4:21 am

Does anyone can help me?

Now i understand what this 'counter' means:

Code: Select all

do counter times.    " How 'counter 'defined? 
It means "describe table itab lines counter. "

Any one can tell me how to save the entries to be deleted in a separate internal table??

I use search function to get this thread and it do help me a lot, but i am in face of this new problem now. :cry:

Thanks in advance.
NewBie to abap

Post Reply