Skip to Content

scripting mapping between Physical data models

Hello!

I am looking at a script to create mappings within PowerDesigner. There is an example in the Help that looks like this:

'Create a mapping between C1 and T6 set m1 = ds.CreateMapping(MyOOM.FindChildByName("Class1",cls_class))

m1.AddSource MyPDM.FindChildByName("Table6",cls_table)

I have been able to make this work to achieve a mapping between tables in a Target Physical data model and a Source Physical data Model. However what I really want to do is map between columns - I have a spreadsheet with all the mappings defined and rather than manually create them one by one, I thought i could save time and script it (generating the code in Excel and then pasting into the execute window in PD).

I have not yet found any example for mapping by column (in Help or on the Internet) and am failing to get it to work.

I have used the CanCreateMapping() method and it shows a positive for a column object, but it then fails on the CreateMapping method.

HERE IS MY CODE:

dim ds1 : dim tab1 : dim m1: dim col1 : dim map1 : dim map2

'set the active model object

set m1 = ActiveModel

'set the source model object

Set m2 = OpenModel("C:\users\jfraser\my documents\freshfields\powerdesigner\SAP_Extracts.pdm")

'set the datasource object

set ds1 = m1.findchildbyname("SAP_Extract",PDPDM.cls_datasource)

'set the target table object

set tab1 = m1.FindChildByName("DM_ACTION",PDPDM.cls_table)

'output to screen (shows correct value)

output tab1.name

'set the target column object

set col1 = tab1.FindChildByName("DWH_ACTION_KEY",PDPDM.cls_column)

'output to screen (shows correct value)

output col1.name

'test the objects as valid for mapping (both show as true)

output ds1.cancreatemapping(tab1)

output ds1.cancreatemapping(col1)

'set the mapping objects

set map1 = ds1.CreateMapping(tab1)

set map2 = ds1.CreateMapping(tab1, col1)

' test the mapping objects (map1 is fine, map2 fails with "object doesn't support this property or method: 'name'")

output map1.name

output map2.name

any help, advice, corrections or comments are welcomed!

thanks

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • Jun 01, 2015 at 02:33 PM

    aha looks like I need to use ColumnMapping - anyone have any examples or advice on this?

    Add comment
    10|10000 characters needed characters exceeded

  • Jun 02, 2015 at 12:05 AM

    This is my OOM example.

    My first OOM has a class Human which has two attributes:

    Owner

    Age

    The second OOM has a class Animal which has two attributes:

    dog

    cat

    The goal is to map dog to Age.

    set m1=OpenModel("D:\cases\myOOMSource.oom")

    Set ds1 = m1.DataSources.CreateNew()
    ds1.setNameandCode "myOOMSource", "myOOMSource"

    set m2=OpenModel("D:\cases\myOOMTarget.oom")

    ds1.AddSource m2

    set SourceTab=m1.findchildbyname("Human", PDOOM.cls_Class)
    set TargetTab=m2.findchildbyname("Animal",PDOOM.cls_Class)

    set SourceCol=SourceTab.findchildbyname("Age", PDOOM.cls_Attribute)
    set TargetCol=TargetTab.findchildbyname("dog", PDOOM.cls_Attribute)

    set map=ds1.CreateMapping(SourceCol)
    map.addSource(TargetCol)

    Add comment
    10|10000 characters needed characters exceeded