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

Doubt on insert statement

Former Member
0 Likes
874

Hi gurus,

I have duplicate records in my internal table.I need to update these duplicate records into ztable.I created Ztable with out having the key value.I put only MANDT as key value , all other fields are non key values.I need to insert these duplicate records into Ztable.

When i am using insert statement it inserts only the last record. I am snding my piece of code here. Please any one suggest me on this.

loop at t_ltap into s_ltap.

wa_tab-lgort = s_ltap-lgort.

wa_tab-wdatu = s_ltap-wdatu.

wa_tab-matnr = s_ltap-matnr.

wa_tab-maktx = s_ltap-maktx.

wa_tab-nsola = s_ltap-nsola.

wa_tab-text = s_ltap-text.

append wa_tab to it_tab.

clear wa_tab.

endloop.

loop at it_tab into wa_tab.

insert ztab_ltap from wa_tab.

endloop.

Thanks in Advance....

Thanks and Regards

siri......

8 REPLIES 8
Read only

Former Member
0 Likes
853

Hi,

Try this piece of code for inserting.


loop at t_ltap into s_ltap.
  wa_tab-lgort = s_ltap-lgort.
  wa_tab-wdatu = s_ltap-wdatu.
  wa_tab-matnr = s_ltap-matnr.
  wa_tab-maktx = s_ltap-maktx.
  wa_tab-nsola = s_ltap-nsola.
  wa_tab-text = s_ltap-text.
  append wa_tab to it_tab.
  clear wa_tab.
  clear it_tab.
endloop.

loop at it_tab into wa_tab.
  insert ztab_ltap from wa_tab ACCEPTING DUPLICATE KEYS
endloop.

Thanks,

Sriram Ponna.

Read only

0 Likes
853

Hi sriram,

When i give accepting duplicate keys it gives the error.

please check it and suggest me please.

Thanks in advance

Thanks and Regards

siri...

Read only

0 Likes
853

Hi,

what is the error you are getting?

Please refer to the example code:


TABLES SCUSTOM.
SCUSTOM-ID        = '12400177'.
SCUSTOM-NAME      = 'Robinson'.
SCUSTOM-POSTCODE  = '69542'.
SCUSTOM-CITY      = 'Heidelberg'.
SCUSTOM-CUSTTYPE  = 'P'.
SCUSTOM-DISCOUNT  = '003'.
SCUSTOM-TELEPHONE = '06201/44889'.

INSERT INTO SCUSTOM VALUES SCUSTOM.

Thanks,

Sriram Ponna.

Read only

0 Likes
853

Hi sriram,

When i wrote u r code like ,

insert ztab_ltap from wa_tab accepting duplicate keys.

the error comes as '.' required after wa_tab.

Please check it out and suggest me..

Thanks and Regards

Siri...

Read only

0 Likes
853

Hi,

Accepting duplicates will not work with area, that is the reason it is throwing an error:

Try like this :



loop at t_ltap into s_ltap.
wa_tab-lgort = s_ltap-lgort.
wa_tab-wdatu = s_ltap-wdatu.
wa_tab-matnr = s_ltap-matnr.
wa_tab-maktx = s_ltap-maktx.
wa_tab-nsola = s_ltap-nsola.
wa_tab-text = s_ltap-text.
append wa_tab to it_tab.
clear wa_tab.
endloop.

INSERT <ztablename> FROM TABLE it_tab. 

Thanks,

Sriram Ponna.

Read only

0 Likes
853

Keep '.' after duplicates key statement

Read only

roger_gomez
Active Participant
0 Likes
853

Hi Abinava,

Maybe you can add a numeric field (i.e. NUMC10) as key field in your Z table together with MANDT.

In your program you build a counter and increase it per each register in it_tab.

The insert statemanet should no cause errors with this.

Reward points if useful

Roger

Read only

Former Member
0 Likes
853

insert ztab_ltap from wa_tab.

commit work.

Try this out.