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
871

Hi gurus,

I created one Ztable with the same structure of internal table.Please can any one tell me How can i insert the data in the internal table into that ZTable.

Thanks in Advance.

Thanks and Regards

Siri...

8 REPLIES 8
Read only

Former Member
0 Likes
849

do this way...


data : itab like ztable occurs 0 with header line,
         w_itab like ztable.

loop at itab.
  w_itab = itab.
   insert into ztable values w_itab.
endloop.  

else


loop at itab.
   modify ztable from table itab.
endloop. 

Edited by: Santosh Kumar Patha on Mar 12, 2008 3:19 PM

Read only

Former Member
0 Likes
849

Hi,

First Loop at internal Table into work area

Then Insert into data base table By

INSERT INTO <DAtabse Table> VALUES <workarea> .

Regards

Sandipan

Read only

Former Member
0 Likes
849

hi ,

In this example, a new airline is added to the database table SCARR.

DATA scarr_wa TYPE scarr.

scarr_wa-carrid = 'FF'.

scarr_wa-carrname = 'Funny Flyers'.

scarr_wa-currcode = 'EUR'.

scarr_wa-url = 'http://www.funnyfly.com'.

INSERT INTO scarr VALUES scarr_wa.

regards,

venkat.

Read only

Former Member
0 Likes
849

Hi

yes you can do like this

MODIFY ztable FROM TABLE internaltable

BEFORE MODIFYING THE DATBASE TABLE YOU NEED TO LOCK THAT TABLE

AND MODIFY IT

AND UNLOCK IT AGAIN

example here

modifying datbase table useing internal table

advises before updating this datbase table plz lock that table to avoid incosistency

write the logic for modifying

Modify the database table as per new dunning procedure

MODIFY fkkvkp FROM TABLE lt_fkkvkp .

and finally unlock the table

example

*To lock table for further operations

constants: lc_tabname TYPE rstable-tabname VALUE 'FKKVKP' . "FKKVKP

CALL FUNCTION 'ENQUEUE_E_TABLE'

EXPORTING

tabname = lc_tabname

EXCEPTIONS

foreign_lock = 1

system_failure = 2

OTHERS = 3.

IF sy-subrc EQ 0.

To fetch all the contract accounts for customers of the segment

Households/SME.

PERFORM fetch_contract_accounts using lc_tabname .

ENDIF. " IF sy-subrc EQ 0.

*wrote the logic

Modify the database table as per new dunning procedure from internal table

MODIFY fkkvkp FROM TABLE lt_fkkvkp .

*unlock the tbale

CALL FUNCTION 'DEQUEUE_E_TABLE'

EXPORTING

TABNAME = uc_tabname .

Read only

Former Member
0 Likes
849

Hi,

You can use insert and modify commands.But modify is best.because modify take care of adding and editing records.

modify will not give any shortdomp

Syntex:

1. modify ztable from <workarea>

2. modify ztable from table <itab>

L.Velu

Read only

Former Member
0 Likes
849

Hi,

You can do as below:



loop at itab into wa.
 INSERT ztable FROM wa.
endloop.

loop at itab into wa.
 MODIFY  ztable  FROM wa.
endloop.

Thanks,

Sriram Ponna.

Read only

Former Member
0 Likes
849

Hi,

simply do like this.


modify ztable from table itab.

rgds,

bharat.

Read only

Former Member
0 Likes
849

Hi,

When you insert a value into a table you should check whether the value is already in the table or not. So use the following code for inerting the values.

Examle, i am going to insert 5 more part munbers in my z-table named zmara. The structure of the internal which is same as the z-table as

MATNR - Part Number,

MAKTX - Part Description.

LOOP AT ITAB INTO WA.

CLEAR ZMARA.

SELECT SINGLE * FROM ZMARA WHERE MATNR = ITAB-MATNR.

IF SY-SUBRC EQ 0.

INSERT ZMARA VALUES ITAB.

ELSE.

UPDATE ZMARA FROM ITAB.

ENDIF.

CLEAR ITAB.

ENDLOOP.

Reward points if it is useful.

Regards,

P.sankar.