Application Development and Automation 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: 
Read only

insert into database

Former Member
0 Likes
2,238

hi gurus,

Iam taking value from the TXT file using GUI_upload into internal table and then inserting the value into the z table.

but it is inserting only the first row of the internal table... I have 150 records in internal table...

so plz help me on this matter..

thanx

man

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,197

Hi Manish Sharma,

Try to Debug your program and see what is happening... Please paste some part of your code what you have written ...

Also check the content of internal table as well..

Are you using loop to process the internal table or not ?

You need to clear header line or work area after INSERT Statement...

Hope it will solve your problem..

Thanks & Regards

ilesh 24x7

ilesh Nandaniya

25 REPLIES 25
Read only

Former Member
0 Likes
2,198

Hi Manish Sharma,

Try to Debug your program and see what is happening... Please paste some part of your code what you have written ...

Also check the content of internal table as well..

Are you using loop to process the internal table or not ?

You need to clear header line or work area after INSERT Statement...

Hope it will solve your problem..

Thanks & Regards

ilesh 24x7

ilesh Nandaniya

Read only

0 Likes
2,197

my code is like that. YEAR1 is the PRIMARY KEY IN IT

itab1-mandt = wa-mandt.

itab1-year1 = wa-year1.

itab1-MATNR = wa-MATNR.

itab1-WERKS = wa-WERKS.

itab1-MENGE = wa-MENGE.

itab1-LGORT = wa-LGORT.

APPEND ITAB1.

clear itab1.

endloop.

LOOP AT ITAB1.

if itab1 is not initial.

insert into ZRG1_APRDATA1 values itab1.

endif.

ENDLOOP.

Its only taking first row of internal table

Edited by: Manish Sharma on Dec 10, 2009 2:09 PM

Edited by: Manish Sharma on Dec 10, 2009 2:12 PM

Read only

0 Likes
2,197

did you check whether you have duplicate entries?

try to delete the duplicate entries based on Primary key and then insert.

You have given only YEAR as primary key.

I feel, you might be having more than 1 entry with same year.

if so change the entries to different year for all the records.

Else, make Material as Primary key and pass diff material.

thanks

Padma

Read only

0 Likes
2,197

IAM ONLY PASSING UNIQUE RECORD

Read only

0 Likes
2,197

>

> LOOP AT ITAB1.

> if itab1 is not initial.

> insert into ZRG1_APRDATA1 values itab1.

> endif.

> ENDLOOP.

>

Instead give like this,

Insert ZRG1_APRDATA1  from table itab1.

thanks,

Padma

Edited by: Padmashree RamMaghenthar on Dec 10, 2009 6:59 PM

Read only

0 Likes
2,197

Hi,

Please paste some records here(may be five records), that will help to solve the issue, as we have data and the code.

Thanks,

Srini.

Read only

0 Likes
2,197

Could you provide a little bit more of your code? Are you sure that you have more than one row in your internal table?

How are you looping to build the internal table?

What is the structure of you custom table?

Is the structure of your internal table the same as the custom (Z) table?

If you leave the "LOOP AT" and single row INSERT, you should be chekcing SY-SUBRC after the INSERT to see if there was problem.

When are you looking at your custom table to see if the inerts are there? Do you code a COMMIT?

Cheers

John

Edited by: John Louk on Dec 10, 2009 7:28 PM

Read only

0 Likes
2,197

Hi Manish,

Updating a database table is not a big issue. As all the experts have given the solutions, you can try with them.

The simplest & best way to update z-table from an internal table is:

INSERT <DBTAB> FROM TABLE <ITAB>.

Plz close the thread if your problem is answered.

Rgds

Prateek

Edited by: Parteek Arora on Dec 11, 2009 7:22 AM

Read only

0 Likes
2,197

my Primary key is year and non primary key field is matnr werks menge.

i want to insert value having same year but different matnr werks and menge.

like 2009 xyz abc 10

2009 xyz1 abc1 10

2010 xyz abc 10

2010 xyz1 abc1 10

but it only inserting first row.... so what i can do in it.. i had tried all logic in it .. but this has not been resolved

so plz help me on this.

Read only

0 Likes
2,197

If you want to store many records of same year then there is no use of using YEAR as a primary key hence remove the primary key (year) otherwise make more primary keys to fulfill the requirement.

Rgds,

Surendr@.

Read only

0 Likes
2,197

Hi Manish,

Make year matnr werks and menge as primary fields. Dont keep year alone as primary key.

Regards,

Swarna Munukoti.

Read only

0 Likes
2,197

weird.. wrong thread

Edited by: Maen Anachronos on Dec 11, 2009 8:37 AM

Read only

0 Likes
2,197

So please delete all entries from the table and set all the four fields as primary key.

This would solve your problem.

Regards,

praveen.

Read only

0 Likes
2,197

Hi

Primary key will accept unique values only.

Eg: 2009 xyz abc 10

2009 xyz1 abc1 10

2010 xyz abc 10

2010 xyz1 abc1 10. your table will not accept these values.

it will accept only

2009 xyz abc 10

2010 xyz abc 10

Reagards,

Manju

Read only

0 Likes
2,197

Hi Manish,

here there are only 2 unique records,

2009 xyz abc 10

2010 xyz abc 10

only these records will be inserted. so out of the 4 records only the 1st and 3rd will be inserted.

and the below 2 records are duplicates, as you have year repeated in these records,

2009 xyz1 abc1 10

2010 xyz1 abc1 10

if you want all these records to be inserted, you better make the MATNR also as the primany key, which

will make all your above 4 records unique.

if you don't want to make MATNR as the primary key, then sort the internal table on year and delete all the duplicates comparing year

which keeps only the unique records and insert will work.

hope this helps.

Read only

0 Likes
2,197

The others have pretty much answered your question. To get what you are after you are going to have to change the primary key of your table. Just note primary keys can only be of type character or NUMC. So, if ME\NGE is a QUAN field then it cannot be part of your primary key.

You do not have to delete the current records from your table. You may ac tually have to delete the table and re-create the table inorder to change the primary key. This will cause the data to be deleted anyway.

Cheers

John

Read only

ThomasZloch
Active Contributor
0 Likes
2,197

Make sure you are using the correct syntax ("insert <dbtab> from table <itab>") and that your DB table has a primary key that allows for storing these 150 different records.

Thomas

Read only

Former Member
0 Likes
2,197

Hi,

Check the primary keys of z-table.

Thanks.

Read only

Former Member
0 Likes
2,197

Hi

Check length is restricted by the length of field of database table in which insertion is done.

Regards,

Tanaya

Edited by: Tanaya A on Dec 10, 2009 6:46 PM

Read only

Former Member
0 Likes
2,197

Hi,

You need to check three things.

1. Your internal table contains multiple records for sure.

2. If yes, then the primary keys of the database table accommodates all the records.

3. You are not using commit work in your code. You need to use this.

If all thee things are OK, then your code should work.

Also One of the big mistakes you are making is accessing database inside the loop.

Press F1 help for INSERT and check the syntax so that you can insert the records in one go.

Regards,

Raveesh

Read only

Former Member
0 Likes
2,197

Close the thread if the issue is resolved.

Regards,

Raveesh

Edited by: raveesh saurabh on Dec 11, 2009 6:48 AM

Read only

Former Member
0 Likes
2,197

example

DATA: VALUE TYPE I,

ITAB TYPE I OCCURS 100 WITH HEADER LINE.

ITAB = 5.

VALUE = 36.

INSERT ITAB INDEX 1.

INSERT VALUE INTO ITAB INDEX 2.

INSERT INITIAL LINE INTO ITAB INDEX 2.

Read only

0 Likes
2,197

i have to insert data into database.. taking value from the excel file to internal table and from internal table to database table

Read only

Former Member
0 Likes
2,197

.

Read only

Former Member
0 Likes
2,197

try this fm FAA_FILE_UPLOAD_TEXTFILE