07-30-2007 10:01 AM
hi , guru's.
iam inserting records into database table through table control when i press insert i want check which record is existing and which is not . so please give me any sample code
regards,
satheesh.
07-30-2007 10:12 AM
let itab be the internal table(with header lne) containing table control values..
DATA itab2 like table of itab.
select * from dbtab for all entries in itab into itab2
where ........(give all primary key fields here).
loop at itab.
read table itab2 with key......
if sy-subrc = 0.
delete itab.
endif.
endloop.
Now itab2 will have existing entries and itab will have new entries.
07-30-2007 10:29 AM
hi arjun.
thanks for replying my query.
we have data in two internal table ie itab(contains records which are not in data base)
itab2 (contains records which are in data base)
so how can i display the records that contained by itab2.
regards,
satheesh.
07-30-2007 10:37 AM
07-30-2007 12:00 PM
hi , arjun.
please check this code.
WHEN 'INSERT'.
data: g_vcontrol_itab1 like table of zcust_call_rec,
g_vcontrol_wa1 like g_vcontrol_wa.
SELECT * FROM zcust_call_rec
INTO CORRESPONDING FIELDS OF TABLE g_vcontrol_itab1
FOR ALL ENTRIES IN g_vcontrol_itab
WHERE kunnr = g_vcontrol_itab-kunnr AND budat = g_vcontrol_itab-budat.
loop at g_vcontrol_itab into g_vcontrol_wa.
read table g_vcontrol_itab1 into g_vcontrol_wa1
with table key g_vcontrol_wa-kunnr = kunnr and g_vcontrol_wa-budat = budat.
if sy-subrc = 0.
delete g_vcontrol_itab.
endif.
endloop.
LOOP AT g_vcontrol_itab INTO g_vcontrol_wa.
INSERT into zcust_call_rec values g_vcontrol_wa.
ENDLOOP.
with this iam getting error message like this.
<b>g_vcontrol_wa-budat is not expected.</b>
07-30-2007 12:05 PM
Hi,
You have to reverse the statement after 'with key".No need for AND incase of read statement.
loop at g_vcontrol_itab into g_vcontrol_wa.
read table g_vcontrol_itab1 into g_vcontrol_wa1
<b>with key kunnr = g_vcontrol_wa-kunnr budat = g_vcontrol_wa-budat.</b>if sy-subrc = 0.
delete g_vcontrol_itab.
endif.
endloop.
LOOP AT g_vcontrol_itab INTO g_vcontrol_wa.
INSERT into zcust_call_rec values g_vcontrol_wa.
Endloop.
07-30-2007 10:17 AM
Hi,
You can use modify command to insert or edit the table record with a single statement instead of checking each record.
Try with the following code.
<b>Modify ztest from table itab.</b>
Here table ZTEST and internal table ITAB shoul be of SAME Structure.
This will do both insert and Updation of the record into ztest table.
Insert :will happen if the record is not exist in table.
Update: will happen if the record is already exist.
07-30-2007 12:49 PM
hi,
go through this for a understanding about tc, it contains info about display, existance checking and so on..
<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/1499ec90-0201-0010-769f-860989655f7e">https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/1499ec90-0201-0010-769f-860989655f7e</a>