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

Update Z-table from internal table.

Former Member
0 Likes
7,318

Hi Experts,

I have requirement to update z-table from an internal table.But,If some entries from the internal table exist in z-table then those entries should not get inserted/modified/updated.

I found one solution but it creates performance issue(i think).....

Solution i found::-

Take all records from z-table.

Delete records from internal table which matches above fetched records.

Now,insert remaining records into z-table.

Taking all records from z-table may take huge time.....

What is another feasible solution????

Thanks & Regards,

Abdul

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,798

S/m Abdul,

The approach you are following is absolutely correct but one change.

for all the records you have to insert in table it_insert.

Put a select on Z table with a for all entries in it_insert.

Now loop on the table after select and delete these entries from it_insert.

This way you can also list the records which were duplicate and ignored.

Cheers.

Hi Shahir,

Thanks for your reply but i dont want duplicate entries.I just want to ignore entries which are previously present in z-table....And in MODIFY statement the records get updated if they have same key fields.

Regards,

Abdul

10 REPLIES 10
Read only

former_member209120
Active Contributor
0 Likes
3,798

Hi Abdul Rahiman Nadaf,

Just use insert......

Like this


INSERT YVTABLE FROM TABLE IT_YVTABLE ACCEPTING DUPLICATE KEYS.

for example see this


DATA : WA_YVTABLE TYPE YVTABLE1,
        IT_YVTABLE TYPE TABLE OF YVTABLE1.

  WA_YVTABLE-CARRID = 'TR'.
  WA_YVTABLE-CONNID = '456'.
  WA_YVTABLE-PRICE = '2000'.
  APPEND WA_YVTABLE TO IT_YVTABLE.
  CLEAR WA_YVTABLE.

  WA_YVTABLE-CARRID = 'RT'.
  WA_YVTABLE-CONNID = '456'.
  WA_YVTABLE-PRICE = '2000'.
  APPEND WA_YVTABLE TO IT_YVTABLE.
  CLEAR WA_YVTABLE.

WA_YVTABLE-CARRID = 'RT'.
  WA_YVTABLE-CONNID = '457'.
  WA_YVTABLE-PRICE = '2000'.
  APPEND WA_YVTABLE TO IT_YVTABLE.
  CLEAR WA_YVTABLE.


  WA_YVTABLE-CARRID = 'TS'.
  WA_YVTABLE-CONNID = '459'.
  WA_YVTABLE-PRICE = '2000'.
  APPEND WA_YVTABLE TO IT_YVTABLE.
  CLEAR WA_YVTABLE.

  INSERT YVTABLE1 FROM TABLE IT_YVTABLE ACCEPTING DUPLICATE KEYS.
  WRITE :/ 'NO OF RECORDS INSERTED SUCCESSFULLY', SY-DBCNT COLOR 2.

YVTABLE1



Read only

0 Likes
3,798

Hello Ramesh,

Thanks for your reply but i dont want duplicate entries.I just want to ignore entries which are previously present in z-table....

Regards,

Abdul

Read only

0 Likes
3,798

Hi Abdul,

See above above code it will never allows duplicate entries to modify, it will ignores duplicate entries.

once again please see above code..

I am passing like this

WA_YVTABLE-CARRID = 'RT'.
  WA_YVTABLE-CONNID = '456'.
  WA_YVTABLE-PRICE = '2000'.
  APPEND WA_YVTABLE TO IT_YVTABLE.
  CLEAR WA_YVTABLE.

WA_YVTABLE-CARRID = 'RT'.
  WA_YVTABLE-CONNID = '457'.
  WA_YVTABLE-PRICE = '2000'.
  APPEND WA_YVTABLE TO IT_YVTABLE.
  CLEAR WA_YVTABLE.

RT is keyfiled in ytable.

so it is taken this

WA_YVTABLE-CARRID = 'RT'.
  WA_YVTABLE-CONNID = '456'.
  WA_YVTABLE-PRICE = '2000'.
  APPEND WA_YVTABLE TO IT_YVTABLE.
  CLEAR WA_YVTABLE.

ignoring this, because it is duplicate

WA_YVTABLE-CARRID = 'RT'.
  WA_YVTABLE-CONNID = '457'.
  WA_YVTABLE-PRICE = '2000'.
  APPEND WA_YVTABLE TO IT_YVTABLE.
  CLEAR WA_YVTABLE.


Read only

Former Member
0 Likes
3,798

Hi Abdul,

Use MODIFY statement. It will do the needful.

Check this link:

http://help.sap.com/saphelp_45b/helpdata/en/34/8e73d66df74873e10000009b38f9b8/content.htm

Also check for INSERT:

http://help.sap.com/saphelp_470/helpdata/en/fc/eb3a6d358411d1829f0000e829fbfe/content.htm

It will be helpful

Regards,

Shahir Mirza

Read only

0 Likes
3,798

Hi Shahir,

Thanks for your reply but i dont want duplicate entries.I just want to ignore entries which are previously present in z-table....And in MODIFY statement the records get updated if they have same key fields.

Regards,

Abdul

Read only

Former Member
0 Likes
3,798
Read only

SwadhinGhatuary
Active Contributor
0 Likes
3,798

Hi Abdul,

The solution you find out for your problem is tedious one. definitely  your z-table have primary key(may be single field or addition of more than one field ) by using PK each record are uniquely identified ,updated, deleted and more..  if you thing you don't maintain PK do please maintain so that database inconsistency and redundancy should be avoided .

1) i think first maintain pk if not

2)do changes in Z-table

3)insert record to z table from internal table using where condition .

if any issues fill free to ask.....

With Hope This will help you.

Thanks And Regards
Swadhin.

Moderator message: Please use proper english ( not PK for primary key ). Thanks for posting

Message was edited by: Kesavadas Thekkillath

Read only

rosenberg_eitan
Active Contributor
0 Likes
3,798


Hi,

It seems to me that there is misinterpretation of the addition of
"ACCEPTING DUPLICATE KEYS":

From SAP help:

So I believe that duplicate records will not be inserted to the table. (Same primary or UNIQUE secondary index)

Regards.

Read only

Former Member
0 Likes
3,798

Hi Abdul,

You can use MODIFY statement instead of INSERT.

syntax : MODIFY dbtab FROM TABLE itab.

This statement will insert those line in internal table into the database table which are not present in the database table and will modify those lines in the database table which are present in the internal table.

You can refer the link for reference:

http://help.sap.com/saphelp_45b/helpdata/en/34/8e73d66df74873e10000009b38f9b8/content.htm

Regards.

Read only

Former Member
0 Likes
3,799

S/m Abdul,

The approach you are following is absolutely correct but one change.

for all the records you have to insert in table it_insert.

Put a select on Z table with a for all entries in it_insert.

Now loop on the table after select and delete these entries from it_insert.

This way you can also list the records which were duplicate and ignored.

Cheers.