cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Add an FK reference using PD scripting

Former Member
0 Likes
1,771

I have the columns defined in the (parent/child) tables.  The parent table has a single column PK.  How do I use PD scripting to add a reference from the child to the parent and to identify one of the existing child table columns to be used in the reference?

Thanks in advance for the help.

View Entire Topic
GeorgeMcGeachie
Active Contributor
0 Likes

Do you want to create many references at once? Rather than scripting, you could use Excel import to create references and select Join attributes.

Former Member
0 Likes

I have 70+ tables needing the same reference.  Each table references the same parent twice.  Hence the request for scripting.

I am not married to scripting, if Excel import can do the same.  Does using Excel need me to enter each and every reference?

GeorgeMcGeachie
Active Contributor
0 Likes

Each row in an Excel import creates or updates an object - 70 references means you need 70 rows. The simplest sheet would only need two columns - Parent Table and Child Table. If you import from this, the FK columns will probably all have the same name as the parent column, unless you have >1 reference between the two tables, or your rolenaming policy is not the standard one (see model options).

You ought to also add a 'Name' column to Excel, using a function to create something like

"Parent_table <--- Child_table" - these names will appear in the PD browser - beware duplicates, though.

Former Member
0 Likes

Thanks George.  I got it working, mostly.  Additional PD wholesale change will bring everything to the level I wanted.  But I thought that I would find out exactly how to get it right 100% as part of the import.

Here is a sample scenario.

  1. Two tables: Parent with column Parent Key (int) as the PK.  Child with columns Father Key (int) and Mother Key (int) and Child Name (varchar(50)).
  2. Here are my Excel sheets:

The import did create references F1 and F2.  "Father Key" at the Child was renamed "Parent Key" and "Mother Key" was renamed "Par_Parent Key".

The child column datatypes remain as "int".  My real data model uses domains.  The resulting domains after the import became "null".

Again, I could use a PD wholesale action and the column names and to change the domains.  But what did I do wrong?

Here are the some of the output lines:

Importing data from table Reference

  2 object(s) created

Importing data from table Reference.Reference Join

Error: Could not set attribute ParentTableColumn for Reference Join 'F1.' with value 'Column 'Parent.Parent Key'' (Cannot set value 'Column 'Parent.Parent Key'' for attribute Parent Table Column of Reference Join 'F1.': Parent Table Column cannot be null.)

Error: Reference Join 'F1.' will not be imported due to missing link extremity

Error: Could not set attribute ParentTableColumn for Reference Join 'F2.' with value 'Column 'Parent.Parent Key'' (Cannot set value 'Column 'Parent.Parent Key'' for attribute Parent Table Column of Reference Join 'F2.': Parent Table Column cannot be null.)

Error: Reference Join 'F2.' will not be imported due to missing link extremity

  no object created or updated

Former Member
0 Likes

This scenario that I reported looked identical to that in the thread http://scn.sap.com/thread/3774419.  I wonder if it is caused by a bug in PD or some additional Excel tabs or columns are need to control the import.

Thanks.