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

table insert from itab

Former Member
0 Likes
915

Hi,

I have all datas in my itab.there are multiple mblnr in single date .but in my 'Z' table i am getting one mblnr.why multiple mblnrs are not inserted.

 LOOP AT ITAB.

         IT_ZTPLSTOCK-MATNR = ITAB-MATNR_I.
         IT_ZTPLSTOCK-WERKS = ITAB-WERKS_I.
         IT_ZTPLSTOCK-MJAHR = ITAB-MJAHR.
         IT_ZTPLSTOCK-BUDAT = ITAB-BUDAT.
   
 IF ITAB-BWART_I = '101'.
      IT_ZTPLSTOCK-MENGE1 = ITAB-MENGE_I.
      IT_ZTPLSTOCK-MEINS1 = ITAB-MEINS_I.
      IT_ZTPLSTOCK-DMBTR1 = ITAB-DMBTR_I.
      IT_ZTPLSTOCK-BWART = ITAB-BWART_I.
      IT_ZTPLSTOCK-MBLNR = ITAB-MBLNR.
    
ELSEIF ITAB-BWART_I = '102'.
      IT_ZTPLSTOCK-MENGE1 = ITAB-MENGE_I.
      IT_ZTPLSTOCK-MEINS1 = ITAB-MEINS_I.
      IT_ZTPLSTOCK-DMBTR1 = ITAB-DMBTR_I.
      IT_ZTPLSTOCK-BWART = ITAB-BWART_I.
      IT_ZTPLSTOCK-MBLNR = ITAB-MBLNR.

    ELSEIF ITAB-BWART_I = '201'.
      IT_ZTPLSTOCK-MENGE2 = ITAB-MENGE_I.
      IT_ZTPLSTOCK-MEINS2 = ITAB-MEINS_I.
      IT_ZTPLSTOCK-DMBTR2 = ITAB-DMBTR_I.
      IT_ZTPLSTOCK-BWART = ITAB-BWART_I.
      IT_ZTPLSTOCK-MBLNR = ITAB-MBLNR.

    ELSEIF ITAB-BWART_I = '202'.
      IT_ZTPLSTOCK-MENGE2 = ITAB-MENGE_I.
      IT_ZTPLSTOCK-MEINS2 = ITAB-MEINS_I.
      IT_ZTPLSTOCK-DMBTR2 = ITAB-DMBTR_I.
      IT_ZTPLSTOCK-BWART = ITAB-BWART_I.
      IT_ZTPLSTOCK-MBLNR = ITAB-MBLNR.

    APPEND IT_ZTPLSTOCK.
    CLEAR IT_ZTPLSTOCK.
  ENDLOOP.
  LOOP AT IT_ztplstock.
    MOVE-CORRESPONDING IT_ztplstock TO ZTPLSTOCK.
    INSERT ZTPLSTOCK.
  ENDLOOP.

suggest some ideas.

with regards,

Bathri

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
895

HI,

Please note that the key in DB table is unique. Hense your key should define a line item uniquely.

Looking at the key fields of your table, I feel it is incomplete.

You can have several documents of same material, plant and date combination.

I think you should add document number i.e MBLNR to the key combination in your Z-Table.

Hope this helps,

RJ

9 REPLIES 9
Read only

Former Member
0 Likes
895

Hi Bathri,

is that you MBLNR is the key field..if so..the INSERT will insert only one MBLNR.

try to do the modify..

like belwo

data IT_ztplstock_final type table of ZTPLSTOCK.

  LOOP AT IT_ztplstock.
    MOVE-CORRESPONDING IT_ztplstock TO  IT_ztplstock_final 
    MODIFY ZTPLSTOCK from IT_ztplstock_final.
  ENDLOOP.

it works

Thanks!!

Read only

0 Likes
895

hi,

mblnr is not a key field,key fields are budat,matnr,mjahr and werks.

Read only

Former Member
0 Likes
895

hi,

it dependce on what are the key fields u r using in u r ztable.check with manually entering the values in u r ztable if it accepting then u r program will wrok .

Read only

Former Member
0 Likes
895

mblnr is the key field of the table.

Use: Accepting Duplicate keys

LOOP AT IT_ztplstock.
    MOVE-CORRESPONDING IT_ztplstock TO ZTPLSTOCK.
    INSERT ZTPLSTOCK Accepting Duplicate keys.
  ENDLOOP.

Regards,

Gurpreet

Read only

Former Member
0 Likes
895

Dear insted of writting this you could have done this

LOOP AT IT_ztplstock.
    MOVE-CORRESPONDING IT_ztplstock TO ZTPLSTOCK.
    INSERT ZTPLSTOCK.
  ENDLOOP.

try to do this

INSERT ZTPLSTOCK FROM TABLE IT_ztplstock.

and check your internal table at that time .

rgds ankit

Read only

0 Likes
895

and for creating a composite key you can also do insert serial number so that it would act as a primary key

Read only

Former Member
0 Likes
896

HI,

Please note that the key in DB table is unique. Hense your key should define a line item uniquely.

Looking at the key fields of your table, I feel it is incomplete.

You can have several documents of same material, plant and date combination.

I think you should add document number i.e MBLNR to the key combination in your Z-Table.

Hope this helps,

RJ

Read only

0 Likes
895

hi,

thanks i put mblnr as key field its working fine.

regards,

Bathri..

Read only

Former Member
0 Likes
895

LOOP AT IT_ztplstock.

MOVE-CORRESPONDING IT_ztplstock TO ZTPLSTOCK.

INSERT ZTPLSTOCK.

ENDLOOP.

instead of this u can use like the below one

LOOP AT IT_ztplstock.

MOVE-CORRESPONDING IT_ztplstock TO ZTPLSTOCK.

modify ztplstock from it_ztplstock with key mblnr

ENDLOOP.