Application Development 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: 

validations when inserting records into database using table control?

former_member593554
Participant
0 Kudos

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.

7 REPLIES 7

Former Member
0 Kudos

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.

0 Kudos

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.

0 Kudos

in flow logic PBO write

loop at itab2.

endloop.

reward if useful

0 Kudos

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>

0 Kudos

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.

former_member491305
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

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>