UPDATE statement (merge table content)
I have two tables t1 and t2 with the same structure: an unique primary key and some arbitrary fields. The tables look something like:
pk number
f1 varchar2(10)
f2 varchar2(10)
f3 varchar2(10)
I have some "new" data in the records in t2 that I would like to update the corresponding rows in t1 with.
On a Microsoft SQL server I could use a SQL statement like:
UPDATE t1
SET t1.f1 = new.f1, t1.f2 = new.f2
FROM t1, t2 new
WHERE new.pk = t1.pk;
But this doesn't work with Oracle (8.1.7). Instead I have come up with something like:
UPDATE t1 old
SET (f1, f2) =
(SELECT f1, f2 FROM t2 new WHERE new.pk = old.pk)
WHERE old.pk IN (SELECT pk FROM t2);
The problem here is that the Oracle version performs very poorly (it's obvious why), whereas the MS SQL server version works like a charm.
There must be something I'm missing here - can anybody please enlithen me.
How do you merge the contents of two tables on Oracle.
Regards,
Tom Bjerre
null
I have had two sugestions. Stephan Born from Germany suggests:
update t1 old
set ( f1, f2 ) = ( select f1, f2
from t2 new
where new.pk = old.pk
where exits ( select x
from t2 new
where new.pk = old.pk
When there exists an index for t2.pk this should result in one full-scan on t1 and two index-scans on t2.
Another suggestion from Ian Ledzion was to combine both tables in the first select:
UPDATE (SELECT old.f1 old_f1, new.f1 new_f1, old.f2 old_f2, new.f2 new_f2
FROM t1 old, t2 new
WHERE (old.id = new.id)) a
SET a.old_f1 = a.new_f1, a.old_f2 = a.new_f2;
Both suggestions seems to be faster than my first attempt (usning the IN clause). Can anybody tell which is best? It could depend on the relative size of t1 and t2 (number of records)
Regards, Tom Bjerre
null
Similar Messages
-
Update stats for table in dbstatc
Hello all,
I am very new to administrating SAP on Oracle. My question is. There are some tables in dbstatc with ignore flag. I ran the below query to get that...
select COUNT(*) from sapsr3.dbstatc
where ACTIV = 'I';
Now from my understanding the I flag means...do not update stats for that table...
So i first ran below...which runs the full stats and it did not update or touched those table in dbstats with I flag
brconnect -c -u / -f stats -t all -f collect -p 8
so after researching i found we can update those stats with below .... even after running the below, stats still do not show up as update.... how can i update (forcefully if required) to update stats for a particular table....
brconnect -u / -c -f stats -t SAPSR3.table_name -f allsel -p 4
i query dba_tables at DB level to see if that specific table was analyzed or not. I am on 11.2 oracle version...and this is a BW SAP system....New User:
1) Which objects do you have the INACTIVE flag set for:
col dbobj format a20
select dbobj, activ from sapsr3.dbstatc where activ = 'I' order by 1;
2) Check that you have the correct DBSTATC settings per SAP Note 403704.
If you do not, then I would suggest you update the DBSTATC table following SAP Note 403704, but before you do take a copy of the dbstatc table:
sqlplus sapsr3/<pass.
create table dbstatc_old as select * from dbstatc;
3) To check to see if you have stats on a table:
select table_name, partitioned, last_analyzed, num_rows from dba_tables where table_name = 'TBTCO';
TABLE_NAME PAR LAST_ANALYZED NUM_ROWS
TBTCO NO 19-MAY-11 163030
If the LAST_ANALYZED shows up with NO values, then there are NO stats on the table.
HOWEVER, be careful for partitioned tables in BW because there are stats at the partition level as well:
select TABLE_NAME, PARTITION_NAME, LAST_ANALYZED, NUM_ROWS from dba_tab_partitions where table_name = '<table>';
4) To collect the statistics on a table
brconnect -c -u / -f stats -t <TABLE> -f allsel,collect -g 4 -p 16
5) If the stats are still not collected with the brconnect command, it may be because the stats are locked at the table level from SAP Note 1020260:
SELECT stattype_locked FROM dba_tab_statistics WHERE table_name = '<TABLE>';
If the value is ALL, then the stats may be locked at the table level and may require to unlock the stats before updating.
Good Luck,
Mike Kennedy -
Problem in doing an update statement
Hello all
i should write an update statement,
these tables : country: name,code,population,nextyearr_population ...
nextyear_population is empty,at first i should get population_growth from population table then calculate the next year population according to corrent population and population_growth
population: country(actually is code not name of country) ,population_growth,....
i wrote so and i got this error
Error starting at line 1 in command:
update country c
set c.nextyear_population=(c.population+ ((c.population*(select pop.population_growth from population pop join country co on co.code=pop.code))/100)
where country.code=population.country
Error at Command Line:4 Column:20
Error report:
SQL Error: ORA-00904: "POPULATION"."COUNTRY": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
-- File created - Wednesday-May-15-2013
-- DDL for Table COUNTRY
CREATE TABLE "intern"."COUNTRY" ("NAME" VARCHAR2(40), "CODE" CHAR(2), "CAPITAL" VARCHAR2(40), "PROVINCE" VARCHAR2(40), "POPULATION" NUMBER, "AREA" NUMBER, "NEXTYEAR_POPULATION" NUMBER)
COMMENT ON COLUMN "intern"."COUNTRY"."NAME" IS 'the country name'
COMMENT ON COLUMN "intern"."COUNTRY"."CODE" IS 'the internet country code (two letters)'
COMMENT ON COLUMN "intern"."COUNTRY"."CAPITAL" IS 'the name of the capital'
COMMENT ON COLUMN "intern"."COUNTRY"."PROVINCE" IS 'the province where the capital belongs to'
COMMENT ON COLUMN "intern"."COUNTRY"."POPULATION" IS 'the population number'
COMMENT ON COLUMN "intern"."COUNTRY"."AREA" IS 'the total area'
COMMENT ON TABLE "intern"."COUNTRY" IS 'the countries of the world with some data'
REM INSERTING into intern.COUNTRY
SET DEFINE OFF;
Insert into intern.COUNTRY (NAME,CODE,CAPITAL,PROVINCE,POPULATION,AREA,NEXTYEAR_POPULATION) values ('Andorra','ad','Andorra la Vella','Andorra la Vella',69865,468,null);
Insert into intern.COUNTRY (NAME,CODE,CAPITAL,PROVINCE,POPULATION,AREA,NEXTYEAR_POPULATION) values ('United Arab Emirates','ae','Abu Dhabi','Abu Dhabi',2523915,82880,null);
Insert into intern.COUNTRY (NAME,CODE,CAPITAL,PROVINCE,POPULATION,AREA,NEXTYEAR_POPULATION) values ('Afghanistan','af','Kabul','Kabul',28513677,647500,null);
-- File created - Wednesday-May-15-2013
-- DDL for Table POPULATION
CREATE TABLE "intern"."POPULATION" ("COUNTRY" CHAR(2), "POPULATION_GROWTH" NUMBER, "INFANT_MORTALITY" NUMBER)
COMMENT ON COLUMN "intern"."POPULATION"."COUNTRY" IS 'the country code'
COMMENT ON COLUMN "intern"."POPULATION"."POPULATION_GROWTH" IS 'population growth rate (percentage, per annum)'
COMMENT ON COLUMN "intern"."POPULATION"."INFANT_MORTALITY" IS 'infant mortality (per thousand)'
COMMENT ON TABLE "intern"."POPULATION" IS 'information about the population of the countries'
REM INSERTING into intern.POPULATION
SET DEFINE OFF;
Insert into intern.POPULATION (COUNTRY,POPULATION_GROWTH,INFANT_MORTALITY) values ('ad',0.95,4.05);
Insert into intern.POPULATION (COUNTRY,POPULATION_GROWTH,INFANT_MORTALITY) values ('ae',1.54,14.51);
Insert into intern.POPULATION (COUNTRY,POPULATION_GROWTH,INFANT_MORTALITY) values ('af',4.77,163.07);thank you in advance
im using oracle11g and ubuntu 12
best,davidHi, David,
Thanks for posting the CREATE TABLE and INSERT statements.
Don't forget to post the results you want from thatsample data (that is, the contents of country after everything is finished).
1003209 wrote:
... i wrote so and i got this error
Error starting at line 1 in command:
update country c
set c.nextyear_population=(c.population+ ((c.population*(select pop.population_growth from population pop join country co on co.code=pop.code))/100)
where country.code=population.country
Error at Command Line:4 Column:20
Error report:
SQL Error: ORA-00904: "POPULATION"."COUNTRY": invalid identifier
00904. 00000 - "%s: invalid identifier"
In the UPDATE statement itself (outside of sub-queries) you can only reference the table being UPDATEd, but in the WHERE clause:
where country.code=population.countryyou're trying to reference another table, population. That's what caused the error.
You either need another sub-query, or MERGE, which will probably be simpler and more efficient than UPDATE. -
Change Update stats job creteria
Hi ,
As per my understanding Update statistics job Update stats of table if it has been changed more than 50%.
Please suggest where we can check this value set for job and How can we change it.
Regards,
Shivam MittalHi Shivam,
You can set the "stats_change_threshold" parameter, in "init<DBSID>.sap" file. Check http://help.sap.com/saphelp_bw30b/helpdata/en/02/0ae0c6395911d5992200508b6b8b11/content.htm
Best regards,
Orkun Gedik -
Update columns in Table A based on columns in Table B for more than 500K rows
Guys,
I need to update 9 columns in table A based on value from table B for for more than 500K rows.
So what is best way to achieve this. I am thinking of writing a Procedure with cursor to update the rows of table A.
When i googled about it, they say cursor will decrease the performance. So i have no clue how to go for this.
Rough code which i though
1) Procedure with no parameter
2) Will declare 9 variable to store value from cursor
3) cursor will fetch row by row based on join condition between table a and table b
4) i will pass column values from table B to variables
5) will make an update statement for table A
Please let me know if above method is correct or is there any other way to do this without using cursor.Guys,
Below is the rough code i wrote as per my requirement. Does it look correct? As of now i dont have any platform to test it so any help with the below code is highly appreciated. As i said i need to update more than 500K rows by matching Table
A and Table B. One more thing which i would like to add in below code, is to get log of all the rows that are in table B but not exist in table A. Table A already has more than million data in it.
Also not sure how the loop in below code willl run when @rowcount is become to zero?
Please let me know if i need to consider performance related impact while running the script.
GO
SET SERVEROUTPUT ON
CREATE PROCEDURE ONETIMEUPDATE
DECLARE @cnt INT;
SET @cnt = 1;
DECLARE @MSG varchar(255);
DECLARE @COUNT_VAR INT;
SET @COUNT_VAR=0;
WHILE @cnt > 0
BEGIN
Update TOP (50000) A
Set A.Col1=B.Col1,
A.COL2=B.COL2,
A.COL3=B.COL3,
A.COL4=B.COL4,
A.COL5=B.COL5,
A.COL6=B.COL6,
A.COL7=B.COL7
From TableA A
Inner Join TableB B
on A.ID = B.ID--ID
WHERE A.Col1 <> B.Col1
OR A.Col2 <> B.Col2;
SET @cnt = @@ROWCOUNT;
IF @@ROWCOUNT=25000
@COUNT_VAR=@COUNT_VAR + @@ROWCOUNT
SELECT @MSG = CONVERT(varchar, @COUNT_VAR) + "Rows Updated" -- I WANT TO DISPLAY UPDATE after EVERY 25000 ROWS
PRINT @MSG
IF @@ROWCOUNT=0
BEGIN
COMMIT
END
WAITFOR DELAY '00:00:01' --wait for a second before the next update
END;
END; -
Doubt about UPDATE STAT COLUMN
Hi,
I have a doubt of when to execute update stat:
i create this SQL to generate an SQL script to generate update stat for all my tables:
select 'UPDATE STAT ' || schemaname || '.' || tablename || ' ESTIMATE SAMPLE 20 PERCENT' from tables where schemaname = 'DBUSER' and not tablename like 'JDBC%' AND type = 'TABLE'
and created this SQL to generate an SQL script for update stat for all columns.
select 'UPDATE STAT COLUMN(*) FOR ' || schemaname || '.' || tablename || ' ESTIMATE SAMPLE 20 PERCENT' from tables where schemaname = 'DBUSER' and not tablename like 'JDBC%' AND type = 'TABLE'
my doubt is i really need run that second script? or the UPDATE STAT for table dont UPDATE STAT for all columns?
thanks for any insight
Clóvis> my doubt is i really need run that second script? or the UPDATE STAT for table dont UPDATE STAT for all columns?
Hi Clovis,
hmm... good question.
There are a few things to know about the UPDATE STAT command here.
1) It will always generate statistics for key or indexed columns.
2) The optimizer won't be able to generate a better plan when there are column statistics for non-indexed columns present.
3) The command will also collect column statistics for all columns that already have statistics.
The direct effect of 3) is that by running your second command just once - all column statistics will always be collected.
Since you can easily change the default sample size for your tables via
ALTER TABLE SAMPLE SIZE 20 PERCENT
I would say: drop your script and just use
UPDATE STAT DBUSER.* ESTIMATE
This single command would lead to the same statistics as your script does.
And if you really, really want to leave out the JDBC tables - then just set their default sample size to 0 and they will be ignored by the UPDATE STAT command.
regards,
Lars -
Updating column in table using forms...
Well guyz i had my presentation of the application today..every thing went fine ....but still they wanna add more features i.e wanna gift this application to various PM working in the company on various project ....initailly i was told that u gotta create this application for just our project now they are using my work to give it to other PMsss :( and take all the credit with no ackowledgement for me n u people who helped me a lot in building this application.... ... well they want me to create an application where in they can modify certain columns......i.e over write the existing value present in a column with a new value....
Now suppose i have col1,col2 in table paymast how should i proceed to create trigger for when i press the button the form gets updated for the particular employee number(i mean if enter the respective info for the particular emp as soon as i press the button the old values shud b replaced by new values..
One method that i noe is use DB wizard to create the form n then enter the value for in respective fields for the column to be updated n then press the F6 ......i dont wanna use this function...
i wanna update the application by pressing the button
cheers :)
Edited by: Suhail Faraaz on Nov 15, 2009 12:26 AM
Edited by: Suhail Faraaz on Nov 15, 2009 12:29 AM
Edited by: Suhail Faraaz on Nov 15, 2009 12:30 AM
Edited by: Suhail Faraaz on Nov 15, 2009 2:05 AMhi
Examples:
SELECT TXNID INTO :TXNID FROM SAF
WHERE
NEXT_ATTEMPT=(SELECT MIN(NEXT_ATTEMPT)
FROM SAF
WHERE STATUS!='A' AND NEXT_ATTEMPT<=SYSDATE AND ATTEMPTS<10)
AND
STATUS!='A' AND ATTEMPTS<10 AND
ROWNUM=1 FOR UPDATE;
//processing==success
UPDATE SAF SET ATTEMPTS=ATTEMPTS+1, NEXT_ATTEMPT=NEXT_ATTEMPT+(10/(24*60*60))
WHERE TXNID=:TXNID;
commit;
else
rollback;
Create trigger trigg_name
After update of C on A
For each row
Is
declare
Pragma Autonomous_transaction;
New_val varchar2(27);
Begin
New_val := :new.C;
Dbms_output.put_line(New_val) ;
/* this outputs the new value when
evoking an update statement on Table A (Column C) */
If updating then
update A set D=:new.C where C=:old.C;
/* After compiling the trigger and evoking
an update statement on Table A (Column C)
the D column still not being updated */
Commit;
End;
update t1
Set t1.C1 = (Select t2.c1
From t2
Where t1.c3 = t2.c3),
t1.C2 = (Select t2.c2
From t2
Where t1.c3 = t2.c3)
update t2
Set t2.C1 = (Select t1.c1
From t1
Where t1.c3 = t2.c3),
t2.C2 = (Select t1.c2
From t1
Where t1.c3 = t2.c3)Its Correct/Helpful Please mark it.Thanks.
sarah -
Update statement with joining other tables
Hi ,
I have two table one is containing xml file , basically i need to read from those xml file then update to another table based on some condition.
UPDATE TRCB_XBRL_STG_2 STG
SET PROFIT =
case when xbrl.isconsolidatedacc='Y' and EXTRACTVALUE(XBRL.XBRLFILE,'//PROFIT ', 'xmlns:acra="..."') is not null
THEN EXTRACTVALUE(XBRL.XBRLFILE,'//PROFIT ', 'xmlns:acra="..."')
WHEN XBRL.ISCONSOLIDATEDACC='N' AND EXTRACTVALUE(XBRL.XBRLFILE,'//PROFIT ', 'xmlns:acra="..') IS NOT NULL
THEN extractValue(XBRL.xbrlfile,'//PROFIT ', 'xmlns:acra=".."')
ELSE STG.PROFIT
END,
SET REVENUE=
case when xbrl.isconsolidatedacc='Y' and EXTRACTVALUE(XBRL.XBRLFILE,'//REVENUE', 'xmlns:acra="..."') is not null
THEN EXTRACTVALUE(XBRL.XBRLFILE,'//REVENUE.', 'xmlns:acra="..."')
WHEN XBRL.ISCONSOLIDATEDACC='N' AND EXTRACTVALUE(XBRL.XBRLFILE,'//REVENUE', 'xmlns:acra="..') IS NOT NULL
THEN extractValue(XBRL.xbrlfile,'//REVENUE', 'xmlns:acra="REVENUE"')
ELSE STG.REVENUE
END,
... (around 100 columns)
FROM TRCB_XBRL xbrl ,TRCB_XBRL_STG_2 STG
WHERE STG.XBRL_ID = XBRL.XBRL_ID Number of columns are around 100 , please anyone suggest how to use update statement with joining two tables.Hi,
If all the values needed to update a given row of table_x are coming from the same row of table_y (or from the same row of a result set of a query involving any number of tables), then you can do something like this:
UPDATE table_x x
SET (col1, col2, col3, ...)
= (
SELECT NVL (y.col1, x.col1)
, NVL (y.col2, x.col2)
, NVL (y.col3, x.col3)
FROM table_y y
WHERE x.pkey = y.expr
AND ...
WHERE ...
;If the WHERE clause depends on the same row of table_y, then it will probably be simpler and more efficient to use MERGE instead of UPDATE.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
In the case of a DML operation (such as UPDATE) the sample data should show what the tables are like before the DML, and the results will be the contents of the changed table(s) after the DML.
Explain, using specific examples, how you get those results from that data.
Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
See the forum FAQ {message:id=9360002} -
Can we use where clause in Update on Merge statement?
Hi All,
I tried to execute the following Merge Query:
When this query is executed without ‘Where clause’ in Update statement its working fine. When executed with ‘Where clause’ it throwing the following error:
ORA-00905: missing keyword.
Following is the sample query which I tried to execute:
MERGE INTO TABLE_NAME
USING (SELECT COLUMN FORM TABLES)
ON (CONDITION)
WHEN MATCHED THEN
UPDATE SET
COLUMN UPATES
WHERE CONDITION -- Can we use where clause here?
WHEN NOT MATCHED THEN
INSERT
INSERT VALUES;
Can some one help on this?
Thanks in advance.
DariusYes:
SQL> drop table emp1;
Table dropped.
SQL> create table emp1 as select * from emp where deptno = 30;
Table created.
SQL> update emp1 set sal = sal*2;
6 rows updated.
SQL> commit;
Commit complete.
SQL> select ename,sal from emp1;
ENAME SAL
ALLEN 3200
WARD 2500
MARTIN 2500
BLAKE 5700
TURNER 3000
JAMES 1900
6 rows selected.
SQL> MERGE INTO emp1
2 USING(select * from emp) emp
3 ON (emp1.empno = emp.empno)
4 WHEN MATCHED THEN
5 UPDATE SET sal = emp.sal WHERE ename = 'TURNER'
6 WHEN NOT MATCHED THEN
7 INSERT(ename,sal) VALUES(emp.ename,emp.sal);
9 rows merged.
SQL> select ename,sal from emp1;
ENAME SAL
ALLEN 3200
WARD 2500
MARTIN 2500
BLAKE 5700
TURNER 1500
JAMES 1900
SMITH 800
JONES 2975
CLARK 2450
SCOTT 3000
KING 5000
ENAME SAL
ADAMS 1100
FORD 3000
MILLER 1300
14 rows selected.
SQL> SY. -
OWB trying to create merge when should be update statement
Hi there
Have a problem whereby when set target update type of table to update, OWB trying to create a merge and failing with message merge sttament cannot be generated because column <column_name> is used for both matching and update.
A matching column cannot be updated in a merge statement.
We are trying to only update certain rows in a target table.
What is the best way to do this in a mapping in normal sql we
would do
update table
set cola = 12, col b=14
where cola = 10
Many ThanksHi there
Thanks for this. I get your idea of doing filter on target at start.
However in our situation I'm not certain how to achieve what we require, being new to OWB.
We have a source staging table with various tranasctions (updates, inserts and deletes all flagged with a timestamp. We need to process these as follows:
1) Inserts become inserts on the target table
2) Deletes become updates on target table, expiration date set to timestamp of record on source table. Here we need to limit the update to only update open record thus not changing history for the code concerned. Open record identified as expiration date set to '31/12/4000'
3) Updates become Updates, setting expiration date on current record to timestamp of staging table record, again only updating currently open record which is identified by expiration date set to '31/12/4000'.
What I thought of doing would be mapping
starting with target table going into a filter to get open records '31/12/4000'. This with joiner operator to staging table and the results of joiner to target table load type set to update. This would handle deletes and the update part of updates.
However this wouldn't take care of the inserts and the second part of updates, i.e. the requirement to insert new record to cater for the update.
Thought about two mappings, one with target type of update as above and another for inserts, but problem would be need to process all records in staging table in right order, e.g in one day could have insert then update. Couldn't run insert mapping first as update mapping would then run and close off the inserted record.
Basically looking for advice on best way to achieve the above.
Many Thanks -
How to update the merged customer information in custom tables?
The "Setup merge Dictionary" is provided only to register APIs that would be called to update the merged information for parties.
Is there a similar feature for the account merge?
If anyone has any ideas of how to update the columns like customer_id, cust_acct_site_id etc. in custom tables at the end of customer merge, please let me know. Any sample code would be of great help.
Please let me know ASAP.
Thanks in advance,There is one method which I have used. The crm side uses a file called jtf_hooks_data. There is no guarantee that it will work in the future and you will have to test it. The merge program uses this sql
'SELECT hook_package, hook_api,product_code ' ||
'FROM jtf_hooks_data '||
'WHERE package_name = ''ARP_CMERGE_MASTER'' ' ||
'AND api_name = ''MERGE_PRODUCTS'' ' ||
'AND execute_flag = ''Y'' ' ||
'ORDER BY execution_order ';
Your procedures have to have the same signature as the one being called. Issues the select statement on your system and see what is returned. -
Update vs Merge - Updating one table based on values in another
Hello
I have two tables lets say TAB_A and TAB_B. I altered table B to include a new column from table A
I wrote a merge statement as follows to merge the data
MERGE INTO TAB_A
USING TAB_B
ON (TAB_A.SECURITYPERSONKEY=TAB_B.SECURITYPERSONKEY)
WHEN MATCHED THEN
UPDATE SET TAB_A.PPYACCOUNT=TAB_B.PPYACCOUNT;
I know INSERT is for inserting new records
UPDATE to my knowledge is to modify currently existing records (loosely)
MERGE is one I rarely used, until this particular scenario.
The code works perfectly fine, but I was wondering how could I write an update statement? Or in this scenario should I even be using an update statement?The MERGE is good and performs well, although it malfunctions (sometimes updating data wrongly) if the destination is a view with INSTEAD OF triggers.
The UPDATE with similar performance to the MERGE depends on SECURITYPERSONKEY being a unique or primary key on TAB_B. It is:
update (select TAB_A.PPYACCOUNT a_PPYACCOUNT, TAB_B.PPYACCOUNT b_PPYACCOUNT
from TAB_A JOIN TAB_B on TAB_A.SECURITYPERSONKEY=TAB_B.SECURITYPERSONKEY)
SET A_PPYACCOUNT=B_PPYACCOUNT;
This can set multiple columns. It also currently doesn't work on a view with INSTEAD OF triggers.
Frank's update also works with multiple columns (eg also updating col2 and col2), with this syntax:
UPDATE tab_a
SET (ppyaccount, col2, col3) = (
SELECT ppyaccount, col2, col3
FROM tab_b
WHERE securitypersonkey = tab_a.securitypersonkey
WHERE EXISTS (
SELECT ppyaccount
FROM tab_b
WHERE securitypersonkey = tab_a.securitypersonkey -
Update statement in Internal Table
Plz tell me the syntax and e.g. of update statement in Internal Table program
Moderator message: Welcome to SCN, please research yourself before asking basic questions.
Edited by: Thomas Zloch on Feb 25, 2010 12:47 PMHi,
Use UPDATE statement , check below description from SAP help.
UPDATE dbtab FROM TABLE itab. or UPDATE (dbtabname) FROM TABLE itab.
Effect
Mass update of several lines in a database table.Here, the primary key for identifying the lines tobe updated and the values to be changed are taken from the lines of theinternal table itab.
The system field SY-DBCNT contains the number of updated lines,i.e. the number of lines in the internal table itab which havekey values corresponding to lines in the database table.
Regards
L Appana -
UPDATE statement not working when updating Z table
Hi
I have declared Ztable with fields MANDT, VKORG, VBELN, IDENTCODE and POSNR as key fields, other fields are FKDAT,KUNNR, NETWR, WAERK, SKFBP
First I got the data from presentation server and moved into internal table 'A' and after that declared internal table with structure same as Z table and moving the data from presentation server internal table 'A' into this.
After Endloop I am using statement
UPDATE ZVS_INV FROM TABLE IT_INV.
commit work.
But table is not getting updated and sy-subrc is returning to 4.
What could be the reason...your help appreciated.howcan it make difference if the primary key is defined as per my business requirement
Just because the business requirement 'says so', doesn't mean that's it's right. You appear to be maintaining a Z-table with a subset of billing fields and appear to have 'over-specified' the primary key.
As far as the help files, if you did look at them, I don't think you took the time to understand before just posting your problem here. An UPDATE operation is a very simple operation. You gave the answer to why it didn't work in your comments as Keshav already pointed out... -
Update the database table with the content of the internal table
Hello!
I have the next form:
FORM erase_data.
SELECT * FROM zadrress INTO CORRESPONDING FIELDS OF TABLE itab_adrress.
DELETE TABLE itab_adrress: FROM zadrress,
WITH TABLE KEY adrid = '456'.
WRITE 'The information after the DELETE operation'
COLOR 2.
LOOP AT itab_adrress INTO wa_adrress .
WRITE:/
wa_adrress-adrid COLOR 5,
wa_adrress-name COLOR 7,
wa_adrress-email COLOR 5,
wa_adrress-depart COLOR 7,
wa_adrress-display COLOR 5.
ENDLOOP.
SKIP.
LOOP AT itab_adrress INTO wa_adrress.
MODIFY zadrress FROM wa_adrress.
COMMIT WORK.
IF sy-subrc = 0.
WRITE 'OK !'.
SKIP.
ELSE.
WRITE 'FAIL !'.
SKIP.
ENDIF.
ENDLOOP.
MODIFY zadrress FROM TABLE itab_adrress.
UPDATE zadrress FROM TABLE itab_adrress.
TRANSPORTING adrid, name, email, depart, display.
INSERT zadrress FROM TABLE itab_adrress ACCEPTING DUPLICATE KEYS.
PERFORM display_data .
ENDFORM. "erase_data
I see that my record is deleted when I display the records from my internal table, but
now I want to delete the record from database table.
For that I want to move the content of the modified internal table in the database table. You can see the methods I tried (some of them commented), but nothing seems to work.
Any advice ?
Thank you.FORM erase_data.
SELECT * FROM zadrress INTO CORRESPONDING FIELDS OF TABLE itab_adrress.
DELETE TABLE itab_adrress: FROM zadrress,
WITH TABLE KEY adrid = '456'.
WRITE 'The information after the DELETE operation'
COLOR 2.
LOOP AT itab_adrress INTO wa_adrress .
WRITE:/
wa_adrress-adrid COLOR 5,
wa_adrress-name COLOR 7,
wa_adrress-email COLOR 5,
wa_adrress-depart COLOR 7,
wa_adrress-display COLOR 5.
ENDLOOP.
SKIP.
LOOP AT itab_adrress INTO wa_adrress.
MODIFY zadrress FROM wa_adrress.
COMMIT WORK.
IF sy-subrc = 0.
WRITE 'OK !'.
SKIP.
ELSE.
WRITE 'FAIL !'.
SKIP.
ENDIF.
ENDLOOP.
<b>DELETE FROM zadrress.</b> "Make this change and try
MODIFY zadrress FROM TABLE itab_adrress.
UPDATE zadrress FROM TABLE itab_adrress.
TRANSPORTING adrid, name, email, depart, display.
INSERT zadrress FROM TABLE itab_adrress ACCEPTING DUPLICATE KEYS.
PERFORM display_data .
ENDFORM. "erase_data'.
Maybe you are looking for
-
How to manage multiple users/devices/Apple IDs on a single computer
I got my 8 year old an iPad mini for Christmas and I'm about to set it up but I need some advice on using multiple IDs on one computer. I have an iPhone 4s. I assume I will need another Apple ID for the iPad mini so she can use Facetime. How do you m
-
How to change header status of a sales order
Hi people, can anybody suggest me a FM for changing sales order header status (say from partailly complete to completed). Regards, Sandy
-
Fonts OK in viewer and NTSC monitor, but jagged in canvas and NTSC monitor
I've had this problem before, and this time it's mind-boggling. All name keys created in Livetype 2, upper field dominant. FCP7 sequence is HD 8-bit ProRes422, field dominance set to "none". Outputting via Aja LHi card and HDMI cable. Some keys are p
-
PSD files always imported as one layer QuickTime
Does anyone know how to work around the bug in DVD SP 4.2.1 that formats every imported PSD file to Quick Time format destroying the layer structure? No matter if the file has layers or not, no matter if the file is saved in PSD, TIF, JEPG, etc the f
-
HT6337 Handoff/Instant hotspot requirements for iPhone 4s
HI, Apple updates recently the "HT6337: Connect your iPhone, iPad, iPod touch, and Mac using Continuity" support page which was not very clear. They added some explanations to activate and use each feature. It's better but Handoff/Instant hotspot req