Reference Field(s) from Foreign Key
Hello,
I have a trigger that calls a procedure. I am sending an email based only on INSERTS on TABLE_B. I want to include the FIRST_NAME and LAST_NAME from TABLE_A based on 'SEQ_NO'. TABLE_B has 'FK_SEQ_NO' that references TABLE_A 'SEQ_NO'. Once I get the SEQ_NO from TABLE_A I want to get the FIRST_NAME and LAST_NAME to associate it with TABLE B with my logic. I am not sure on how to do this, any help is appreciated; thanks. If needed I can include my trigger but, would rather the logic in the procedure if possible.
CREATE OR REPLACE procedure p_email_detail_from_trigger(
pa_new_fk_seq_no varchar2,
pa_new_item_one varchar2,
pa_new_item_two varchar2
as
v_message varchar2(4000);
begin
--build email message
v_message := 'The following detail has been added for: ';
v_message := v_message || CHR(10)||CHR(13)||CHR(10)||CHR(13)
|| '*** FK Seq No: '
|| pa_new_fk_seq_no
|| CHR(10)||CHR(13)
|| '*** Item One: '
|| pa_new_item_one
|| CHR(10)||CHR(13)
|| '*** Item Two: '
|| pa_new_item_two
|| '';
-- create email
test_utility.p_update_email_table
(v_message,'EMAIL_TRIGGER','TEST_EMAIL');
-- send email
test_utility.p_sendmail
('EMAIL_TRIGGER','TEST_EMAIL');
end p_email_detail_from_trigger;
/
Hi Charles,
I've added a function one_a to your procedure. I have written it such a way that it should easily be moved into a package. Which you should really do; move your procedure and the new fnction into a package. Don't use stand alone stored procedures, they will become a night mare one day.
CREATE OR REPLACE procedure p_email_detail_from_trigger(
pa_new_fk_seq_no varchar2,
pa_new_item_one varchar2,
pa_new_item_two varchar2
as
v_message varchar2(4000);
a table_a%rowtype;
function one_a(p_seq_no in varchar2)
return table_a%rowtype
is
one_rec table_a%rowtype;
begin
select table_a.*
into one_rec
from table_a
where table_a.seq_no = p_seq_no;
return one_rec;
end one_a;
begin
-- get record from table_a
a := one_a(pa_new_fk_seq_no);
-- Now FIRST_NAME can be found in a.FIRST_NAME
--build email message
v_message := 'The following detail has been added for: ';
v_message := v_message || CHR(10)||CHR(13)||CHR(10)||CHR(13)
|| '*** FK Seq No: '
|| pa_new_fk_seq_no
|| CHR(10)||CHR(13)
|| '*** Item One: '
|| pa_new_item_one
|| CHR(10)||CHR(13)
|| '*** Item Two: '
|| pa_new_item_two
|| '';
-- create email
test_utility.p_update_email_table
(v_message,'EMAIL_TRIGGER','TEST_EMAIL');
-- send email
test_utility.p_sendmail
('EMAIL_TRIGGER','TEST_EMAIL');
end p_email_detail_from_trigger;
/Note, not tested.
Regards
Peter
Similar Messages
-
KR Reference Field coming from Earmarked Fund
Hi Experts,
We have distributed our data entry of non PO related invoices out to end users. They data enter and park the invoice. Then Central AP uses their workflow inbox (SBWP) to view and "approve" the document to post it.
This works great EXCEPT when the invoice is charged to an Earmarked Fund (specifially a funds commitment), AP gets an error that "For document type KR, an entry is required on field Reference number" XBLNR is filled in with the Vendor's invoice number on the parked document, but we are told by SAP, that it is our config that is causing the issue.
On the funds commitment (fmz3), we can view that on the Header of the commitment that we have always left the field REFERENCE blank. We did configure under Earmarked Funds and Funds Transfers\Define Rules for account assignment, that the Reference Document Number is Active, but this allows us to fill in field REFBN in other areas for reporting.
When we just post an invoice FB60, we've never had a problem with the funds commitment's REFERENCE field conflicting with the Invoice's Reference field. When I do enter something on the REFERENCE field of the funds commitment, it OVERWRITES what the invoice had in the reference field when we do the Park then POST using workflow (uses FBV0 funcitonality). It does not overwrite it though when I just post using FB60 or FV60.
SAP has stated that they intentially designed their programs differently which is why they behave differently.
So does anyone have any suggestions on how to get the parked document to post BUT to keep the Vendor's Invoice number in the Reference field? Instead of it being overwritten from the Funds Commitment?
Would appreciate your guidance,
CindyHi,
I think your FM analyst got the direction wrong. System will always populate REFBN field in table FMIOI with PO# or other source document number. The configuration you mentioned controls whether you want the system to transfer the value of REFBN to a follow-on document with reference to an earmarked fund - the direction is from FM to FI. For example, when you create an earmarked fund 1234, you will see an entry in table FMIOI with field REFBN populated with 1234; this has nothing to do with the configuration in defining rules for account assignment transfer in earmarked fund. Then, you create an invoice with reference to earmarked fund 1234; this time, system will transfer the values of the fields in document 1234 to the invoice according to the said configuration.
Regards,
Ming -
I have a table which has 3 foreign keys, two of which form the primary key.
I have: ID_Product, ID_Sale, ID_Buy, and also an attribute which tells if its a buy or a sale.
So, if a sale is made, the primary key should consist of ID_Product && ID_Sale, otherwise, it's ID_Product && ID_Buy.
Is there a way to do this in Oracle, and if there is, can you point me to where I can read about this?
thank you in advancetashe,
This is the wrong forum for you question. Try posting here:
PL/SQL
I will say, however, that there are advantages to keeping your primary keys apart from your data - just populating them from a sequence. Also, you may be temped to enforce this via triggers, but read the following first:
http://tkyte.blogspot.com/2008/05/another-of-day.html
Not that you would have a mutating table problem, but the two table solution may help you. Really think the design through.
Regards,
Dan -
I define a customize table (maintenance only by cust., not SAP import).
5 of the fields are the table keys.
When I remove 2 fields from the key and adjust the table I get the following errors
Primary key change not permitted for value table ZT7IL60
Activation of Table ZT7IL60 not possible (please check)
Any clue why and how to remove some fields from the key?hi there,
the reason for this error can be any....
may be you are using that field in the foreign key reference of another table. thats y it is not allowing the change option as it will affect other table's values.
another thing can be the one suggested in the above post.
do reply if any of the methods mentioned helps.
Do reward if helpful./ -
Primary key foreign key remove problem
hi expretrs,
I create 5 tables in ddic.
1. zpr_cmp Company Master
2. zpr_dpt Department Master
3. zpr_dsg Designation Master
4. zpr_emp Employee master.
5. zpr_slm Salary Master.
Foreign key reference in zpr_emp from table 1,2 and 3 created and
table zpr_emp has
cmpcd, Company Code
empcd, Employee Code
dptcd , Department Code
dsgcd Designation Code
as key fields.
I have upload data and create module pool and reports.
My problem that hr person say that we want to change deptcd/dsgcd of employee (zpr_emp) and
dptcd and dsgcd is as key fields in zpr_emp when i change the table zpr_emp and remove
two key fields dptcd/dsgcd and active error display.
I also try with se14 (Activate and Adjust database) but error still.
how can i remove key field from zpr_emp and active table without loss data and without any change of
module pool/reports
pl. helpDiagnosis
ZPR_EMP table is defined as a check table. For reasons of consistency, changes to the primary key of the table are not allowed.
Procedure
If it is essential that you change the primary key, you must delete the relevant foreign keys. Refer to the where-used list to find all tables containing a field that is checked against this table. Delete the foreign keys for these fields.
If necessary, maintain the deleted foreign keys again.
Value table - It's a field in a domain it helps in domain level data validation.
Check table - unlike value table it helps in feild level data validation.
The relational data model contains not only tables, but also relationships between tables. These relationships are defined in the ABAP/4 Dictionary by foreign keys. An important function of foreign keys is to support data integrity in the relational data model. Foreign key fields may assume only those values allowed by the check table, in other words, values occurring in the primary key of the check table.
A foreign key provides a link between two tables, for eg.,T1 and T2 by including a reference in table T1 to the primary key of table T2. For this purpose, Foreign key fields assigned to the primary key fields of T2 are included in T1. Table T1, which is the one being checked, is called a foreign key table, and table T2 is called a check table. The terms dependent (foreign key) table and referenced (check) table are also used.
VALUE TABLE:If the domain of the check field has a value table, this is proposed by the system as check table in the foreign field maintenance. The key fields of the value table are in this case assigned fields of the foreign key table with the same domain. These fields may assume only those values allowed by the value table.
The value range of the domain can be defined by specifying value table.All table fields referring to this domain can then be checked against the corresponding field of this value table.In order the check can be executed, a foreign key must be defined for the value table. -
How to create a Foreign key relationship between 2 user defined tables...
Hi Folks,
I have created two user defined tables... Where in i want to create foriegn key relationship between the 2 tables.... Can anyone guide the step by step procedure to do this scenario...
Any help would be highly appreciated...
ThanksHi
1. In the 2nd table call the field of the 1st table which is a primary key.
2. Give the same field and dataelement name.
3. Select that field and then click on the foreign key field icon which is beside Search Help button.
4. Then give short text, and the 1st table name.
5. Then in the below box give the 2nd table name and 2nd table field name which you have called from 1st table.
6. Then click on copy, then u will be able to see Check table name and check table field name beside foreign key table name.
7. Then again click on copy.
Regards
Haritha. -
Re: Reference field to change red alert message. How?
Hi FICO Consultant,
We are using T-Code: FBL1N, using our com code and execute the report. In this report, we have used the reference field for company purpose key in the same reference no.: (EX: 789100). The same number appeared again on the screen (Reference No.). That time red alert message appeared on the screen or an existing same reference in this field. Any body gives the idea to me in FICO.
We expect the reply from you.
Thank you,
Regards,
Krishnan.The icons are a function of the Alert style: that can only be changed in the property palette. I'don't believe there is any way of substituting your own icons for the Oracle ones short of overwriting the Oracle supplied files with graphics of your own. However, we can set the Alert Title and Message Text programmatically with the SET_ALERT_PROPERTY built-in.
Cheers, APC -
Hi,
i want to have the details like reference tablename,reference volumn name of foreign key for a particular table.
SELECT a.column_name,
c_pk.table_name r_table_name, c_pk.constraint_name r_pk
FROM all_cons_columns a
JOIN all_constraints c ON a.owner = c.owner
AND a.constraint_name = c.constraint_name
JOIN all_constraints c_pk ON c.r_owner = c_pk.owner
AND c.r_constraint_name = c_pk.constraint_name
WHERE c.constraint_type = 'R'
AND a.table_name = :TableNameUsing this query I am getting everything except the reference column name.
Can somebody please help?
ThanxYou need to add another join to ALL_CONS_COLUMNS:
SELECT a.column_name,
c_pk.table_name r_table_name, c_pk.constraint_name r_pk,
c_pk_c.column_name
FROM all_cons_columns a
JOIN all_constraints c ON a.owner = c.owner
AND a.constraint_name = c.constraint_name
JOIN all_constraints c_pk ON c.r_owner = c_pk.owner
AND c.r_constraint_name = c_pk.constraint_name
JOIN all_cons_columns c_pk_c ON c_pk_c.owner = c_pk.owner
AND c_pk_c.constraint_name = c_pk.constraint_name
WHERE c.constraint_type = 'R'
AND a.table_name = :TableName -
How we relate two tables using foreign key(fk)?
hi to all,
what are the conditions has to follow to relate two tables.I.e.,
the two tables have same primary keys(pk). if we relate these two tables in one table the pk and fk will be the same then how that table in active.Hi
To relate two tables..we have foreign key relationship.
In one table v have primary key and in the second table, the same key is foreign key for that table..
To relate two tables, we can use JOINS
If there is already a suitable foreign key between two tables used in the view, these tables can be linked with a join condition from this foreign key.
Create a view on tables TAB1 and TAB2. TAB1 is the primary table of the view. TAB2 is the secondary table of the view. TAB1 is the check table for TAB2. The foreign key fields are assigned to the check table fields as follows:
TAB1-FIELD_A assigned to TAB2-FIELD_1
TAB1-FIELD_A assigned to TAB2-FIELD_1
The join condition of the view generated from the foreign key is then:
CREATE VIEW ... AS SELECT ... WHERE TAB2-FIELD_1 = TAB1-FIELD_A AND TAB2-FIELD_2 = TAB1-FIELD_B.
Join conditions can also be copied from generic and constant foreign keys. If a constant is assigned to a field in the foreign key, it is also assigned to the field in the join condition. There is no join condition for a generic relationship in the foreign key.
The foreign key between tables TAB1 (check table) and TAB2 (foreign key table) is defined as follows:
TAB1-FIELD_A assigned to TAB2-FIELD_1
TAB1-FIELD_B generic
TAB1-FIELD_C assigned to constant C
The join condition for the view generated from the foreign key is in this case:
CREATE VIEW ... AS SELECT ... WHERE TAB2-FIELD_1 = TAB1-FIELD_A AND TAB2-FIELD_2 = C.
Hope it helps
Reward if useful. -
Check no in reference field in F110
Hello,
Is there a way for when the checks are processed to have this automatically populated in reference field of payment document in transaction F110.
Or can we put manually in F110. But I did not find the reference field in F110 to key in.
Regards,
TapanHello!
1. Please review the below note
30380 RFFOUS_C - Check number not stored in document
As per note 30380,
Point 5. As of Release 4.0C Report RFCHKU00 is delivered in the
standard system which copies the check number into a selected
reference field of the document. You can this program.
2. Also review
213551 F110: Reference document not transferred
335893 F110:Fill ref. document no. of payment doc w/
These two notes above mention another to way fill your requirements. But, note 213551 is a modification note and you should read the documentation about modification notes before trying the solution.
REgards,
REnan -
Create Foreign Keys between two Schemata
Hello,
I use Oracle 10g and I trying to create a ForeignKey constraint between two tables in different schemata.
This is my DDL-Script
SQL> CREATE TABLE PROJECT.LOCATION (
ID INTEGER NOT NULL,
MAIN INTEGER,
KURZ VARCHAR(40),
NAME VARCHAR(40),
STRASSE VARCHAR(40),
ORT VARCHAR(40),
TELEFON VARCHAR(40),
FAX VARCHAR(40),
EMAIL VARCHAR(40),
PLZ VARCHAR(40),
CONSTRAINT PK_LOCATION PRIMARY KEY (ID)
Tablespace PROJECT;
CREATE TABLE Diary.Diary (
ID INTEGER NOT NULL,
LOCATION_ID INTEGER NOT NULL,
CONSTRAINT PK_Diary PRIMARY KEY (ID)
Tablespace Diary;
ALTER TABLE Diary.Diary
ADD CONSTRAINT FK_Diary_Has_LOCATION
FOREIGN KEY (LOCATION_ID) REFERENCES PROJECT.LOCATION (ID);
This is the Message that gives my SQLplus :
SQL> ALTER TABLE Diary.Diary
2 ADD CONSTRAINT FK_Diary_Has_LOCATION
3 FOREIGN KEY (LOCATION_ID) REFERENCES PROJECT.LOCATION (ID);
FOREIGN KEY (LOCATION_ID) REFERENCES PROJECT.LOCATION (ID)
FEHLER in Zeile 3:
ORA-00942: Tabelle oder View nicht vorhanden
All Grants (select,alter,references) are given to the User for the tables.
Whats then Problem?You miss some priviledge:
SQL> create user project identified by project;
Utente creato.
SQL> grant connect, resource to project;
Concessione riuscita.
SQL> create user diary identified by diary;
Utente creato.
SQL> grant connect, resource to diary;
Concessione riuscita.
SQL> CREATE TABLE PROJECT.LOCATION (
2 ID INTEGER NOT NULL,
3 MAIN INTEGER,
4 KURZ VARCHAR(40),
5 NAME VARCHAR(40),
6 STRASSE VARCHAR(40),
7 ORT VARCHAR(40),
8 TELEFON VARCHAR(40),
9 FAX VARCHAR(40),
10 EMAIL VARCHAR(40),
11 PLZ VARCHAR(40),
12 CONSTRAINT PK_LOCATION PRIMARY KEY (ID)
13 )
14 ;
Tabella creata.
SQL> CREATE TABLE Diary.Diary (
2 ID INTEGER NOT NULL,
3 LOCATION_ID INTEGER NOT NULL,
4 CONSTRAINT PK_Diary PRIMARY KEY (ID)
5 )
6 ;
Tabella creata.
SQL> ALTER TABLE Diary.Diary
2 ADD CONSTRAINT FK_Diary_Has_LOCATION
3 FOREIGN KEY (LOCATION_ID) REFERENCES PROJECT.LOCATION (ID);
FOREIGN KEY (LOCATION_ID) REFERENCES PROJECT.LOCATION (ID)
ERRORE alla riga 3:
ORA-00942: tabella o vista inesistente
-- DIARY CAN'T SEE PROJECT.LOCATION
SQL> grant select on project.location to diary;
Concessione riuscita.
SQL> ALTER TABLE Diary.Diary
2 ADD CONSTRAINT FK_Diary_Has_LOCATION
3 FOREIGN KEY (LOCATION_ID) REFERENCES PROJECT.LOCATION (ID);
FOREIGN KEY (LOCATION_ID) REFERENCES PROJECT.LOCATION (ID)
ERRORE alla riga 3:
ORA-01031: privilegi insufficienti
-- DIARY CAN SEE PROJECT.LOCATION BUT CAN'T REFERENCE IT
SQL> grant references on project.location to diary;
Concessione riuscita.
SQL> ALTER TABLE Diary.Diary
2 ADD CONSTRAINT FK_Diary_Has_LOCATION
3 FOREIGN KEY (LOCATION_ID) REFERENCES PROJECT.LOCATION (ID);
Tabella modificata.
-- NOW IT'S ALL OK!!Max
[My Italian Oracle blog|http://oracleitalia.wordpress.com/2009/12/18/table-elimination-oppure-join-elimination-lottimizzatore-si-libera-della-zavorra/] -
Reference field value disappears on the Receivables transaction line window
Hi Everybody,
I have below problem while creating the manual invoice from Receivables.
when i am trying to utilize the reference field on the Receivables transaction line,
so that it can be used to enter extra data for manual invoices.
At the moment if you enter data in the file and save it . it was visible.
Again when i re query the transaction then it disappears.
Kindly some one suggest me how to view reference field value from Transaction line and as well as from back end in which column of Trx table i can see the data. Please help me to resolve the issue.
Many Thanks.Pl check the below note.
272428.1
There is an enhancement pending (2660680) for this issue. You may have to check the status of this enhancement with Oracle Crop. -
Foreign key dependency checking
Dear all:
I have a question about foreign key checking.
Let's say I have two Z table, one is master table and one is transaction table.
The master table contains a primary key named CustNo.
The transaction table have two primary keys named CustNo and OrderNo.
The CustNo has foreign key (mandt + CustNo) point to master table, with setting
"Key fields/candidates 1:N"
I expected that, delete record in master table should check if there is any dependency in the transaction table,
but I am wrong. I am able to delete anything in master table even there are records in transaction table using the same CustNo.
My question is, how can I make the dependency check?
Thanks in advance.
Edited by: Hung Kai, Michael Cheng on Nov 3, 2008 5:29 AMHello,
For this u need to change the cardinality.
Below are the list of cardinalities and their functionality.Chack it and use the proper one.
The left side (n) of the cardinality is defined as follows:
n=1: There is exactly one record assigned to the check table for each record of the foreign key table.
n=C: The foreign key table may contain records which do not correspond to any record of the check table because the foreign key field is empty. This can occur for example if the field of the foreign key table is optional, in which case it does not have to be filled.
The right side (m) of the cardinality is defined as follows:
m=1: There is exactly one dependent record for each record of the check table.
m=C: There is at most one dependent record for each record of the check table.
m=N: There is at least one dependent record for each record of the check table.
m=CN: There may be any number of dependent records for each record of the check table.
Shafi -
Dropping data from primary Key.
Hi ,
I am deleting data from foreign key and it is dropping 1900 records in 1 sec.
Query 1
delete from abbr_pay_dtl_stag where pif_file_id=118bur after that when I drop records from primary key, it takes more then 2 minutes.
Query 2
delete from line_stage e where bip_pif_file_id =118When I have looked into the explain plan, Query 1 was using Full table scan and Query 2 is using Range Index Scan so I have put hint in Query 2 to use Full table scan, but it is still the same.
Please advise.I haven't understood which is the master table and which is the detail table for you haven't given any indication of how the foreign key is created.
Still, when you have foreign keys, whenever you delete from the master table, the database has to check the existence of corresponding detail records for any master record deleted, which definitely inposes scanning the index used for the foreign key.
For best performance, you may disable the foreign key constraint, and then enable it, eventually enable novalidate. Still, disabling a constraint would be a bad thing if you are performing those deletes on a system that processes several transactions at the same time, cause one of the other transactions may possibly insert junk in the detail table. -
hi
i created a foreign key for a table .But the foreign key table is accepting all values , not only the check table content. why?Creating Foreign Keys Procedure
In the field maintenance screen of the table, select the check field and choose symbol of KEY
If the domain of the check field has a value table, you can have the system create a proposal with the value table as check table. In this case a proposal will be made for the field assignment in the foreign key.
If the domain does not have a value table or if you reject the proposal, the screen for foreign key maintenance appears without proposals. In this case, enter the check table and save your entries. The check table must have a key field to which the domain of the check field is assigned.
You can then let the system make a proposal for assigning of the foreign key fields to the key fields of the check fields. The system attempts to assign the key fields of the check table to fields of the table with the same domain. If you do not want a proposal, the key fields of the check table are listed and you must assign them to suitable fields of the foreign key table.
Enter an explanatory short text in the field Short text.
The short text provides a technical documentation of the meaning of the foreign key.
Choose Copy. The foreign key is saved and you return to the maintenance screen for the table.
Maybe you are looking for
-
Plugin Problem in Photoshop CS5
I have loaded ImageSkill Background Remover and Magic Sharpener into my new CS5. They appear normally in the filters pull-down menu however when I try to open either one, I get the Microsoft "Photoshop has encountered a problem and must close" msg a
-
Registration with shared services failed.
Hi all, I installed 11.1.1.3 on windows server 2003. I got the problem with "register with shared services is fail" while configuring FDM. I tried with turn off the firewall also, again it throws same error. Can you please suggest me. Thanks&Regards.
-
[SOLVED] jruby upgrade fails: /dev/fd error
Hi, when I try to upgrade jruby (pacaur -y jruby) I get the following error: /dev/fd/63: line 18: syntax error: unexpected end of file AUR Targets (1): jruby Proceed with installation? [Y/n] error: failed to commit transaction (conflicting files) jr
-
I upgraded from LR3 from LR4. I am unable to import photos from my Nikon D700 to LR4. I get an error message that says it cannot find photos or video to import. It shows the photos in the preview windows, then the error message appears, then the prev
-
Program to select material inventory
Hi, I have written a program, that should select the material inventory, increase, outflow in a specific month and show it in an ALV. there should be an option to export the results as a csv file. I have finished the ALV and the csv-file stuff, but I