Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Update new records and delete old record? Urgent

Former Member
0 Kudos
955

Iam updating some records from internal table to Data base table.

Please suggest me

INSERT DBTable FROM TABLE itab.

UPDATE DBTable FROM itab.

  • Delete existing records.

DELETE DBTable FROM TABLE itab_old.

Please suggest me

15 REPLIES 15

Former Member
0 Kudos
226

I have collected some data from db and

chaged some dates and update again in data base table

at the same time i need to delete the modified ones

Former Member
0 Kudos
226

Hi,

If you are asking for the sequence..

Better to use UPDATE instead of DELETE and INSERT.

Otherwise..

UPDATE DBTABLE FROM TABLE ITAB..The only thing is you have to have all the table fields in the internal table ITAB..

If you are updating couple of fields..use the following.

UPDATE DBTABLE SET FIELD1 = 'SAP'

WHERE FIELD2 = 'X'.

Same for delete also..The internal table ITAB should have all the key fields of the internal table itab..

Hope this is what you want..

THanks,

Naren

Former Member
0 Kudos
226

Hi,

You want to update the record and then delete the record??Is this what you want..

Thanks,

Naren

Former Member
0 Kudos
226

YES SIR

Former Member
0 Kudos
226

Why do you want to update and then delete that record..You might delete the record directly...

Thanks,

Naren

Former Member
0 Kudos
226

Fist collect data and do some modification and then update

and then delete the old files

Former Member
0 Kudos
226

Please help me it is very urgent

Former Member
0 Kudos
226

Hi,

For the first part..Use UPDATE statement to update the records..

For the second part..Do you want to delete a file or record from a database table??

Is there is any indicator that you have in your database table to indicate that it is a old record..

I am sorry..I am not able to understand your requirement..Please explain in detail..

Thanks,

Naren

Former Member
0 Kudos
226

Iam colecting some records to internal table from Data base table

based on year and month.

Then changing the date and months in interenla table

then inserrting this modified records of internal table into datta base table.

Finaly delete the old records with old dates.

Please suggest me

Former Member
0 Kudos
226

Got you..

Iam colecting some records to internal table from Data base table

based on year and month.

Then changing the date and months in interenla table

then inserrting this modified records of internal table into datta base table.

Finaly delete the old records with old dates.

Here is the suggestion..This is a logic and not the exact code..

DATA: ITAB TYPE STANDARD TABLE OF ZTABLE WITH HEADER LINE.

DATA: ITAB_OLD TYPE STANDARD TABLE OF ZTABLE WITH HEADER LINE.

SELECT * FROM ZTABLE

INTO TABLE ITAB.

ITAB_OLD = ITAB.

ITAB-NEW_DATE = SY-DATUM.

MODIFY ITAB TRANPORTING NEW_DATE WHERE KEY_FIELD = 'DS'.

  • Deletion part.

DELETE ZTABLE FROM TABLE ITAB_OLD.

  • Insertion part

INSERT ZTABLE FROM TABLE ITAB.

Thanks,

Naren

Former Member
0 Kudos
226

Please ignore multiple posts.

Message was edited by: Narendran Muthukumaran

Former Member
0 Kudos
226

Please ignore multiple posts.

Message was edited by: Narendran Muthukumaran

Former Member
0 Kudos
226

Got you..

Here is the suggestion..This is a logic and not the exact code..

DATA: ITAB TYPE STANDARD TABLE OF ZTABLE WITH HEADER LINE.

DATA: ITAB_OLD TYPE STANDARD TABLE OF ZTABLE WITH HEADER LINE.

SELECT * FROM ZTABLE

INTO TABLE ITAB.

ITAB_OLD = ITAB.

ITAB-NEW_DATE = SY-DATUM.

MODIFY ITAB TRANPORTING NEW_DATE WHERE KEY_FIELD = 'DS'.

  • Deletion part.

DELETE ZTABLE FROM TABLE ITAB_OLD.

  • Insertion part

INSERT ZTABLE FROM TABLE ITAB.

Thanks,

Naren

Former Member
0 Kudos
226

Naren thanks for your concern/helping nature. Thank you again.

Just neeed to know the difference between INSERT, UPDATE & MODIFY Commands. Thanks a tonne.

Former Member
0 Kudos
226

Hi,

INSERT is to insert records to the database table..If the record is already there then sy-subrc will be set to 4..

UPDATE is to update existing records to the database table..If the record is not there then sy-subrc will be set to 4..

MODIFY can be used for inserting/updating..If the record is there in the database table it will update the record..If the record is not there then it will insert the record..

Thanks,

Naren