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: 

INSERT Statement

Former Member
0 Kudos

Hi guys,

I have a requirement wherein i need to insert rows in a database table from an internal table. But the problem is in my database table there are 5 fields including MANDT field whereas in my internal table there are 4 fields not including MANDT.

How do i go about this??

Thanks and regards,

Frank.

14 REPLIES 14

Former Member
0 Kudos

Hello Frank,

You can go ahead to insert though your mandt field is not present in the internal table. Make sure that the other mandatory fields are present in the internal table and they are unique in each occurance.

Reward Points if useful.

Cheers,

Tej.

former_member404244
Active Contributor
0 Kudos

Hi,

the db table structure and the internal table should be of same structure..so just add one field to internal tabla and insert..now the mandt field will be blank..

else

add one more filed to ur internal table and then

loop at itab.

if itab-mandt = space.

itab-mandt = sy-mandt.

modify itab transporting mandt.

endif.

endloop.

now use insert statement...

Regards,

Nagaraj

Former Member
0 Kudos

Hi Frank,

If you are inserting data from an internal table into the database table, the structure of the internal table must be EXACTLY the same as the database table.

Hence you will have to declare another internal tabel which has same structure (5 fields) as DB table and move contents from original table to new table and INSERT into DB from new table.

In the new table, if MANDT is empty no problem. System defaults it to SY-MANDT. However the structure of internal table and DB must be the same.

Regards,

Aditya

Former Member
0 Kudos

you can set all MANDT field of your internal table :sy-mandt

Former Member
0 Kudos

Hi,

Frank there is no need to insert this mandt value specially u can go ahead with u r existing 4 values in the internal table the remaing field i.e. MANDT takes the default value of present logon client

suppose u r logged on client 800 then tht field will take the value of 800...

plzz reward if this information is usefull to u..

plzz dont forget to reward...

Former Member
0 Kudos

Hi,

MANDT field will automatically updated when run the program depending upon the server.

use this following format:

databasetable-f1 = internaltable-f1.

databasetable-f2 = internaltable-f2.

modify databasetable.

Regards

Debjani

Former Member
0 Kudos

I have tried using the following code.....

INSERT dbtab from table itab.

It gives me a syntax error stating that the work area itab is not long enough.

0 Kudos

Hi frank,

Please read my earlier post again. As I said, the structure of the itab has to be EXACTLY same as that of the database table.

Since your itab is missing MANDT, it has one field less than the DB table and is hence not long enough.

Please read my above post again.

Regards,

Aditya

0 Kudos

Hi Frank

Please check whether you have taken care of below mentioned 2 points,

1) Your work area ITAB is also having 5 fields including MANDT.

2) If your itab is with header line then please make sure to use itab[].

~ Ranganath

0 Kudos

Hi,

Declare an internal table of same type as that of your data base table.

No need to have MANDT field in the internal table. Only thing you need to take care is that the entry which you are trying to insert SHOULD not be there in the Data Base table.

If entry is already there then you would get a DUMP at INSERT statement.

So alternatively you can use MODIFY statement which would server the purpous of Insert/Update both, though not very good in performance.

Reward points if useful.

Regards,

Lalit Kabra

0 Kudos

Hi,

that means the internal table and the dbtable are of differents structures..u have to make them same...

for example if dbtable has 5 fields then internal table also should be 5 fields then only ur query will be correct..in earler versions up to (4.6c) it used to support if internal table and dbtable are of different structures but in new version its not supporting....

plz see my earlier post....

Regards,

nagaraj

Former Member
0 Kudos

But when i get values in my internal table it cannot have mandt field. so the only solution is transferring the contents of this internal table into another internal table having mandt field using the MOVE statement.

Pls confirm?

0 Kudos

Yes Frank ... You have move it to the internal table with MANDT again.

~ Ranganath

0 Kudos

Hi,

Just do one thing...

Declare your itab type dbtab.

Data : Itabl type standard table of dbtab.

Now in this itab pass your 5 fields except Mandt and then use this table itab to insert the data in your database table dbtab.

Should work for you. No need of moving the data again to a new table.

Regards,

Lalit Kabra