11-14-2009 6:08 AM
Hi,
I have to two tables like Dept in which fields are
DEPT
===========
CLNT
DEPTID( PK )
,DEPTNAME.
Another table is EMP, the fields are
EMP
============
CLNT
EMPID(PK)
DEPTID(PK)
EMPNAME.
In this created a foreign key relation ship withEMP-DEPTID = DEPt-Deptid.
In program
I want to insert some records to my custom table EMP.
There It should accept only emp-deptid value if it exists in Dept-deptid.
what statement I should write.
When I write " insert into zEMP values <workarea>.
11-14-2009 6:15 AM
Hi,
Get the data of your table DEPT into internal table.
while inserting the data check if the work area Deptid id is present in the internal table of DEPT.
if yes then insert the record into the EMP table.
11-14-2009 3:05 PM
Hi,
This is very simple...
1.Just before the insert statement READ TABLE DEPT WITH DEPTid = DEPTID.
2. check for sy-subrc value for 0
3.if yes then insert else prompt the erroe message or do nothing depending upon the requirement.
Hope this will solve your problem.
pooja
11-14-2009 3:30 PM
Hi Pooja,
I am not in front of the SAP Login now. So, can't confirm.
Doesn't the table throw an error when there is a foreign key violation??
I didn't know we were supposed to write a check explicitly !!!
@OP
I am not too sure about this. Probably you can check for yourself.
11-14-2009 3:32 PM
Its better that you create a foreign key relationship between these two tables.
Are you using table maintenance to insert data ?
if its from your program just use modify table statement
Check F1 help documentation for modify table
11-14-2009 3:34 PM
Hi Bachi,
Check the existance of record in foregin table and then only insert the record.
or else.
first insert in the foregin key table and then insert your table.
Hope you get it.
11-14-2009 3:37 PM
Are you using table maintenance to insert data ?
before table updation just put a query
like
select single * from table1 where empid =empid.
if sy-subrc = 0.
"True
else.
"false.
endif.
or
You can try function module HELP_VALUES_GET_WITH_CHECKTAB
Also Check F1 help documentation for modify table