cancel
Showing results for 
Search instead for 
Did you mean: 

Table mappings

08-03-2020 4:34 PM
1297 views 4 comments
0 Likes
SAP Managed Tags
Subscribe

Hi,

I have written script for mappings between tables in the one model. I want to create different mappings between different source tables and one common target table. My script is working well, but it concatenates source tables in one mapping, instead of this I want to create separate mapping for different source tables. Is there any way?

Script:

Dim ds, m1, m2 set ds = ActiveModel.DataSources

set nds = ds.Item(0)

im tt_1, ts_1, ts_2

set tt_1 = ActiveModel.FindChildByCode("Target_1", cls_table)

set ts_1 = ActiveModel.FindChildByCode("Source_1", cls_table)

set ts_2 = ActiveModel.FindChildByCode("Source_2", cls_table)

set m1 = nds.CreateMapping(tt_1)

m1.AddSource(ts_1)

m1.SetNameAndCode "MAP_Source_1", "MAP_Source_1"

set m2 = nds.CreateMapping(tt_1)

m2.AddSource(ts_2)

m2.SetNameAndCode "MAP_Source_2", "MAP_Source_2"

Script does this:

I want this:

0 Likes

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member200945
Contributor
0 Likes

All you need do is change

from

nds.CreateMapping(tt_1)

to

nds.CreateMapping(tt_1, nothing, false, true)

GeorgeMcGeachie
Active Contributor
0 Likes

phillip.lam The metamodel documentation doesn't explain what those additional parameters are for. Here's what it says:

CreateMapping(ByVal Object As BaseObject, ByVal Source As BaseObject = Nothing, ByVal SetAsDefault As Boolean = True, ByVal EnforceCreation As Boolean = False) As BaseObject
  Creates a mapping for an object.

Is there anything that describes the method in more detail, please? You've reversed the default values for the last two parameters, and we need to guess what effect that has. In fact, it sounds like the default values are wrong.

With a more complete description of the method, razyapoo wouldn't have needed to start this discussion, and KBA 2792278 probably wouldn't be needed.

GeorgeMcGeachie
Active Contributor
0 Likes

I've noticed that you can use the CreateMapping method on BaseDataSource to create mappings between columns (presumably only if the parents are already mapped). What happens if there is more than one mapping between the two parents? The method has a SetAsDefault parameter - perhaps it would add the sub-object mapping to the 'default' mapping between the parents?

I looked in the metamodel to see if there's a property on BaseObjectMapping that indicates the default, but I can't find it.

I'm just looking for ways to simplify future mapping scripts 🙂