cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping VB Script: Error -> Object required 0x800A01A8

former_member114438
Discoverer
0 Kudos
1,635

Hello!

I need some help to fix the following error.

I have a script to map the entities and attributes with a excel spreadsheet.

The first and second loop works fine and mapped the entities and attributes. I can see them in the "Mapping Editor". But in the third round i get the following error.

Dim TargetM, SourceM, TargetEnt, SourceEnt, TargetAtt, ds ,m1, NSE 
Dim NTE, NSA, NTA, attm

'Open the Excel Sheet with the mapping information
Set objExcel = CreateObject ("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:/...")

'Open the two Models for mapping
set TargetM = OpenModel ("C:\...")
set SoureM = ActiveModel

'Mapping the two Models
Set ds = SourceM.DataSources.CreateNew(cls_DefaultDataSource)
ds.SetNameandCode "Vorsystem_SAP_GP", "Vorsystem"
ds.AddSource(TargetM)

'Loop to create the mappings between the Entities and Attributes
For j = 2 To 100
	
	Set NSE = objWorkbook.Sheets(2).Cells(j, 4)
	Set NTE = objWorkbook.Sheets(2).Cells(j, 1)
	Set SourceEnt = SourceM.FindChildByName(NSE, PdLDM.cls_entity)
	Set TargetEnt = TargetM.FindChildByName(NTE, PdLDM.cls_entity)

	Set m1 = ds.createMapping(SourceEnt)
	m1.AddSource(TargetEnt)

	Set NSA = objWorkbook.Sheets(2).Cells(j, 5)
	Set NTA = objWorkbook.Sheets(2).Cells(j, 2)
	Set SourceEnt = SourceEnt.FindChildByName(NSE, PdLDM.cls_EntityAttribute)
	Set TargetEnt = TargetEnt.FindChildByName(NTE, PdLDM.cls_EntityAttribute)

	Set attm = ds.createMapping(SourceAtt)
	attm.AddSource(TargetAtt) 'Error

Next


	

Microsoft VBScript runtime error ->Object requierd: 'attm' (0x800A01A8)

any help, advice, corrections or comments are welcomed!

thanks

GeorgeMcGeachie
Active Contributor
0 Kudos

Thanks for the challenge 🙂

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member200945
Contributor
0 Kudos

You do not define SourceAtt in

Set attm = ds.createMapping(SourceAtt)

I guess correct code should be

Set attm = ds.createMapping(SourceEnt)

former_member114438
Discoverer
0 Kudos

Hello,

I found the mistake. The problem is the formatting of the excel cells.

Does anyone know this problem and its solution

?
GeorgeMcGeachie
Active Contributor
0 Kudos

Try this script, based on yours:

Dim TargetM, SourceM, TargetEnt, SourceEnt, TargetAtt, ds ,m1, NSE
Dim NTE, NSA, NTA, attm, wBookName, sourcePath, targetPath, dataSourceName, sheet, range, rangeMax
' from https://answers.sap.com/questions/417299/mapping-vb-script-error-object-required-0x800a01a8.html wBookName = "C:\...\Mappings Import.xlsx"
sourcePath = "C:\...\Source.ldm"
targetPath = "C:\...\Target.ldm"
dataSourceName = "Mapping Test" 'Open the two Models for mapping
output "Opening source model " & sourcePath
set SourceM = OpenModel (sourcePath) output "Opening target model " & targetPath
set TargetM = OpenModel (targetPath) 'Mapping the two Models
output "Creating the Data Source - " & dataSourceName
Set ds = TargetM.DataSources.CreateNew(cls_DefaultDataSource)
ds.Name = dataSourceName
ds.SetNameToCode()
' link to source model
ds.AddSource(SourceM) 'Open the Excel Sheet with the mapping information
output "Opening " & wBookName
Set objExcel = CreateObject ("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open(wBookName)
Set sheet = objWorkbook.worksheets(1)
Set range = sheet.usedrange

'get count for loop
rangeMax = range.rows.Count
output "There are " & rangeMax & " rows in the worksheet" 'Loop to create the mappings between the Entities and Attributes
For j = 2 To rangeMax

'output vbtab & " - Processing row " & j
Set NSE = objWorkbook.Sheets(1).Cells(j, 1)
Set NTE = objWorkbook.Sheets(1).Cells(j, 3)
Set SourceEnt = SourceM.FindChildByName(NSE, PdLDM.cls_entity)
Set TargetEnt = TargetM.FindChildByName(NTE, PdLDM.cls_entity) Set m1 = ds.createMapping(TargetEnt)
m1.Name = "source - " & SourceEnt.Name
m1.SetNameToCode()
m1.AddSource(SourceEnt) Set NSA = objWorkbook.Sheets(1).Cells(j, 2)
Set NTA = objWorkbook.Sheets(1).Cells(j, 4)
Set SourceAtt = SourceEnt.FindChildByName(NSA, PdLDM.cls_EntityAttribute)
Set TargetAtt = TargetEnt.FindChildByName(NTA, PdLDM.cls_EntityAttribute) Set attm = ds.createMapping(TargetAtt)
m1.Name = "source - " & SourceAtt.Name
m1.SetNameToCode()
attm.AddSource(SourceAtt) Next output " ** FINISHED **"
' close the workbook
objExcel.workbooks.Close

former_member114438
Discoverer
0 Kudos

Hello George,

Thank you for your help.

However, the error is still displayed. Did it work for you? It also shows me the same error for the variable SourceEnt.

Do you have another idea to solve the error?