‎2006 Jun 09 5:15 PM
Hi people,
How do I go about to insert columns from an internal table -intab- into an data base table -dbtab-. These tables contain some similar columns, not all.
A code example would be much appriciated!
/Armin
‎2006 Jun 09 5:20 PM
‎2006 Jun 09 5:19 PM
Inserting a column in internal table is nothing by defining a field in your internal table defination.
And before that you might inserted the field in database table.
Am I understood your query ??
Regds
Manohar
‎2006 Jun 09 5:20 PM
Hi Armin,
Use the following statement.
<b>INSERT INTO dbtab VALUES intab.</b>
If you need to update few rows of internal table based on certain condition do as follows::
<b>DATA wa TYPE intab.
LOOP AT intab INTO wa WHERE<condition>.
INSERT INTO dbtab VALUES wa.
CLEAR wa.
ENDLOOP.</b>
Regards,
Vinay
‎2006 Jun 09 5:20 PM
‎2006 Jun 09 5:27 PM
hi armin,
INSERT dbtab FROM TABLE itab. oder
INSERT (dbtabname) FROM TABLE itab.
Extras:
1. ... CLIENT SPECIFIED
2. ... ACCEPTING DUPLICATE KEYS
3. ... CONNECTION con
Effect
Mass insert: All lines of the internal table itab are inserted in one single operation. The lines of itab must fulfill the same conditions as the work area wa in variant 1.
When the command has been executed, the system field SY-DBCNT contains the number of inserted lines.
The Return Code is set as follows:
SY-SUBRC = 0:
All lines successfully inserted. Any other result causes a runtime error.
Note
If the internal table itab is empty, SY-SUBRC and SY-DBCNT are set to 0 after the call.
Addition 1
... CLIENT SPECIFIED
Effect
As with variant 1.
Addition 2
... ACCEPTING DUPLICATE KEYS
Effect
If a line cannot be inserted, the system does not
terminate with a runtime error but only sets the return value SY-SUBRC to 4. All other lines are inserted after the command is executed.
hope this helps,
do reward if it helps,
priya.
‎2006 Jun 09 5:39 PM
Hi Armin,
Do you want to
1)insert new record in all the cases or
2) you want to insert only when its a new record in internal table but if there is a record with same keys already present in the table, then the existing record should be updated with the internal table records.
If first case is true then code will be :
INSERT dbtab FROM TABLE intab.else if the second case is true then code will be :
MODIFY dbtab FROM TABLE intab.Above statements will do mass updates in 1 go but if you want to do it in a loop taking 1 record from intab and inserting it then statement will be :
1)
data : wa_intab type intab.
loop at intab into wa_intab.
INSERT INTO dbtab VALUES wa_intab.
endloop.2) )
data : wa_intab type intab.
loop at intab into wa_intab.
MODIFY dbtab FROM wa_intab.
endloop.Cheers,
Vikram
Pls reward for helpful replies!!
‎2006 Jun 09 6:01 PM
Thanks a lot for your suggestions, but I have allready tryed all the suggested approaches and non of them worked:
1) When trying this approach:
INSERT dbtab FROM TABLE intab.
or:
MODIFY dbtab FROM TABLE intab.
or:
data : wa_intab type intab.
loop at intab into wa_intab.
INSERT INTO dbtab VALUES wa_intab.
endloop.
etc...
I get the error: "The type of the database table and work area (or internal table) are not Unicode convertible.."
2) When trying this approach as suggested by mr. Heilman:
DATA db_wa TYPE dbtab.
LOOP AT intab
INTO wa
WHERE checkboxx = 'X'.
db_wa~stono = wa-stono.
.
.
INSERT INTO dbtab VALUES db_wa.
ENDLOOP.
I get the error: "db_wa unexpected.."
The problem is that the tables have some columns that are the same and others that are not. They are not of the same type!
Has anyone had this prob before and solved it?
Thanks!
‎2006 Jun 09 6:04 PM
Check your program with UCCHECK tcode, this might give you some log.
Regds
Manohar
‎2006 Jun 09 6:16 PM
Never mind guys, Rich's sollution worked. Had some other problems that made me initially think it doesn't work.
So 10 goes to mr. Heilman and rest of you get a strong 2 for the effort!
Thanks guys!
‎2006 Jun 10 8:13 AM
Dear Armin,
Are you able to do that?? Thats surprizing !! could you please explain me how it adds a new column to a DATABASE TABLE from internal table??
regards,
Amiya Shrivastava
‎2006 Jun 10 8:18 AM
I am sorry ..I read the confabulation only superficially, now I am clear with what you had asked!!
Inserting columns values and not adding new columns!!