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 z custom table

Former Member
0 Likes
16,611

Hi Experts,

I want to insert records into a custom DB table that has already having values.

It is like, if the table has 100 records, the insert/modify statement should insert the records from 101 onwards without eliminating the previous records.

Thanks,

Micheal

1 ACCEPTED SOLUTION
Read only

dennis_scoville4
Active Contributor
0 Likes
6,787

As long as you know there won't be any key violations on this table, you could do it as follows:


INSERT
  ztable
FROM
  wa_workarea.

9 REPLIES 9
Read only

dennis_scoville4
Active Contributor
0 Likes
6,788

As long as you know there won't be any key violations on this table, you could do it as follows:


INSERT
  ztable
FROM
  wa_workarea.

Read only

Former Member
0 Likes
6,787

Hi micheal,

before inserting in to table ..

select * from ztable.

if sy-subrc = 0.

sy-tabix will contains the number of records..

endif.

next increment the record..

or check the

select max(record) from ztable.

if sy-subrc = 0.

endif.

insert the new record with number record = record + 1.

prabhudas

Read only

Former Member
0 Likes
6,787

Hi,

Take a look at the following code. it will insert the record and display the error message for duplicate records.

DATA: lv_err_flag TYPE c,

lv_recnum(10) TYPE c.

LOOP AT gi_itab INTO wa_itab.

INSERT into ztab values wa_itab.

IF sy-subrc NE 0.

READ TABLE gi_itab INTO wa_itab INDEX sy-tabix.

lv_recnum = sy-tabix.

WRITE: /'Record# '(001) NO-GAP, lv_recnum NO-GAP, 'was not created- '(002), wa_itab.

lv_err_flag = 'X'.

ENDIF.

ENDLOOP.

ULINE.

IF lv_err_flag = 'X'.

WRITE /'Process completed with some error records.'(003).

ELSE.

WRITE /'Process completed successfully.'(004).

ENDIF.

Hope it helps.

Regards,

Rajesh Kumar

Edited by: Rajesh Kumar on Jul 31, 2009 5:41 AM

Read only

Former Member
0 Likes
6,787

hi michal,

According to the Data base concepts duplicate records wond be inserted into the data base table. but ensure that all the values in the record should be differnt then only the record will be inserted. otherwise it wont be inserted into data base table.

eventhough when your inserting the values inserted record will be sorted and placed based onthe order.

Read only

0 Likes
6,787

Hi,

What are all the records you have to inset into the customized table is updated into an internal table

then use this statement to update this internal table values into customized table

INSERT <Z table name> FROM TABLE <internal table name>

Before use this query you have to check the primary key fields.

Thanks,

John Victor

Read only

0 Likes
6,787

Hi,

Could you please let me know whether we need to check the duplicate entries for primary key fields.

Since when I am trying to insert a new record with same entries, I am getting an error. Its working fine.

But when I try to insert a new record with same primary key(onle plant is the key in my table, so i cant change the value everytime when I insert records), its not getting inserted into the table using INSERT dbtab from wa.

Please help me out.

Read only

0 Likes
6,787

If u want to insert more rows with the same plant then u must have more than one fields as the key for ur table. The plant can have the same value then but the combination of plant plus other field must be unique.

Hope this clarifies.

Read only

0 Likes
6,787

If you have declarew primary key in you table then dublictarrecord can not br inserted at any cost becose the functionality

of primary key is removing dublicacy

Read only

manubhutani
Active Contributor
0 Likes
6,787

Fill your record in a work area(WA) and then use

insert into Ztable values WA.

thats it.

let me know if you have any doubt

Regards

Manu