pedromrs
24th October 2002, 14:35
Hi,

I'm working on the tccom0101m000 session using OLE automation.
I was expecting when entering a new employee with an existing ID to get an error message of some kind from Baan.

Also I'm wondering if running all the code in a Baan DLL would be faster. Executing this piece of code is turning out to be slow.
If I want to run a DLL do I need the source code? (I don't have it). If not, how do I compile the dll assuming a Windows NT installation of Baan?


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim BaanObj As Baan4.Baan4
Dim FunctionDLL As String
Dim SessaoEmpg As String
Dim Cmp_emp, Cmp_lg, Cmp_nome, Cmp_dt_ini_cont, Cmp_pais As String
Dim ErrMessage1 As String



'My connection was Automatic since I changed a registry entry to
'run a different .bwc file.
'run Baan Application
BaanObj = CreateObject("Baan4.Application")
BaanObj.Timeout = 60
On Error GoTo BaanAutomationError


FunctionDLL = "ottstpapihand"
SessaoEmpg = "tccom0101m000"

'Campos
Cmp_emp = "tccom001.emno"
Cmp_lg = "tccom001.clan"
Cmp_nome = "tccom001.nama"
Cmp_dt_ini_cont = "tccom001.sdte"
Cmp_pais = "tccom001.ccty"

'Abrir a sessao de empregados tccom0101m000
BaanObj.ParseExecFunction(FunctionDLL, "stpapi.put.field(" & Chr(34) & SessaoEmpg & Chr(34) & "," & Chr(34) & Cmp_emp & Chr(34) & "," & Chr(34) & "4904" & Chr(34) & ")")

BaanObj.ParseExecFunction(FunctionDLL, "stpapi.put.field(" & Chr(34) & SessaoEmpg & Chr(34) & "," & Chr(34) & Cmp_lg & Chr(34) & "," & Chr(34) & "P" & Chr(34) & ")")
BaanObj.ParseExecFunction(FunctionDLL, "stpapi.put.field(" & Chr(34) & SessaoEmpg & Chr(34) & "," & Chr(34) & Cmp_nome & Chr(34) & "," & Chr(34) & "Paulo Capelo" & Chr(34) & ")")
BaanObj.ParseExecFunction(FunctionDLL, "stpapi.put.field(" & Chr(34) & SessaoEmpg & Chr(34) & "," & Chr(34) & Cmp_dt_ini_cont & Chr(34) & "," & Chr(34) & "12102002" & Chr(34) & ")")
BaanObj.ParseExecFunction(FunctionDLL, "stpapi.put.field(" & Chr(34) & SessaoEmpg & Chr(34) & "," & Chr(34) & Cmp_pais & Chr(34) & "," & Chr(34) & "XRT" & Chr(34) & ")")
BaanObj.ParseExecFunction(FunctionDLL, "stpapi.insert(" & Chr(34) & SessaoEmpg & Chr(34) & "," & "1" & "," & Chr(34) & ErrMessage1 & Chr(34) & ")")

If BaanObj.Error <> 0 Then
MsgBox(ErrMessage1)
End If

'BaanObj.ParseExecFunction(FunctionDLL, "stpapi.set.report(" & Chr(34) & SessaoEmpg & Chr(34) & "," & Chr(34) & RapportImpression & Chr(34) & "," & Chr(34) & CodeImprimante & Chr(34) & "," & Chr(34) & ErrMessage1 & Chr(34) & ")")

'Fechar o Baan
If Not BaanObj Is Nothing Then
BaanObj.Quit()
BaanObj = Nothing
End If

Exit Sub

'Não conseguiu criar o objecto Baan
CannotCreateBaan:
MsgBox("Unable to start Baan")
Exit Sub

'Não conseguiu iniciar o Baan
BaanAutomationError:
MsgBox("Baan IV automation error: " & BaanObj.Error)
BaanObj.Quit()
BaanObj = Nothing
Exit Sub

End Sub


Thanks in advance,

Darren Phillips
24th October 2002, 15:16
to compile on NT (no developer licence required)
bic d:\mpsimport.bc -o otudllolemps

d:\mpsimport.bc is the test file with the code and otudllolemps is the name of the object

mark_h
24th October 2002, 15:50
This post (http://www.baanboard.com/baanboard/showthread.php?s=&threadid=5540&highlight=error) may help to explain the errors. And yes it may be quicker to create a Baan dll to run this code. I would give it a try.

Mark

Al Smith
24th October 2002, 17:40
Hi,
When an error is returned from ottstpapihand, it doesn't create a BaanObj error. The error message is in the returned "ErrMessage1" string.
For example, trying to insert an employee that already exists returns:
stpapi.insert("tccom0101m000",0,"Record already exists")
in the function call.

What I use to check if any error is returned is: (VB6)If Right(BaanObj.FunctionCall, 3) <> Chr(34) & Chr(34) & ")" Then
Open "e:\CallError.txt" For Append As #2
Print #2, "Call " & CallNumb & " failed to close."
Print #2, BaanObj.FunctionCall
Close #2
BaanObj.ParseExecFunction "ottstpapihand", "stpapi.recover(" & Chr(34) & "tssma3142m000" & Chr(34) & "," & Chr(34) & Space(50) & Chr(34) & ")"
BaanObj.ParseExecFunction "ottstpapihand", "stpapi.end.session(" & Chr(34) & "tssma3142m000" & Chr(34) & ")"
BaanObj.Quit
Set BaanObj = Nothing
End
End If
If no error is returned the right 3 characters of the FunctionCall is "") or Chr(34) & Chr(34) & ")"
I also note that you don't have a stpapi.end.session in your code.
As for the OLE vs Baan Dll, I'm a proponent of OLE because of the ease that I can interface Baan to Windows applications.
Al.

pedromrs
25th October 2002, 02:42
Hi to all,

Thanks for all the help!
I'm really learning a lot in this forum :)

Thanks once more,