hariharan_94
1st December 2020, 16:00
Hi
I am trying to automate the BOM Customization, i am new to BAAN OLE
i write below codes , I have no problem to opening session "tipcs2150m000" but when i try to find a particular project there is no response from the VBA.

can anyone help me to solve problem ?
I am using BaaN IV
Here is my code,

Set BaanObj = CreateObject("Baan4.Application.Baan")
BaanObj.Timeout = 2
On Error GoTo BaanAutomationError
i = 2
j = 1
BaanObj.ParseExecFunction "ottstpstandard", "zoom.to.menu(" & Chr(34) & "tipcs2150m000" & Chr(34) & ",2," & Chr(34) & Chr(34) & "," & Chr(34) & Chr(34) & ",0,0)"
BaanObj.ParseExecFunction "ottstpapihand", "stpapi.put.field(" & Chr(34) & "tipcs2150m000" & Chr(34) & "," & Chr(34) & "tipcs022.cprj" & Chr(34) & "," & Chr(34) & "ZB0002" & Chr(34) & ")"
BaanObj.ParseExecFunction "ottstpapihand", "stpapi.put.field(" & Chr(34) & "tipcs2150m000" & Chr(34) & "," & Chr(34) & "tipcs022.mitm" & Chr(34) & "," & Chr(34) & "TEST" & Chr(34) & ")"
BaanObj.ParseExecFunction "ottstpapihand", "stpapi.put.field(" & Chr(34) & "tipcs2150m000" & Chr(34) & "," & Chr(34) & "tipcs022.pono" & Chr(34) & "," & Chr(34) & " " & Chr(34) & ")"
BaanObj.ParseExecFunction "ottstpapihand", "stpapi.find(" & Chr(34) & "tipcs2150m000" & Chr(34) & ")"


Thanks in Advance !!!!
Hari

mark_h
1st December 2020, 18:58
About the only time I tested this is in this thread http://www.baanboard.com/baanboard/showthread.php?t=70381&highlight=OLE+stpapi.find. Not sure why you zoom.to.menu I don't recall having to do anything like that.

vinceco252
1st December 2020, 21:56
I found the best way to use the OLE stuff was to write a custom session to call from VBA that has relatively simple function calls (i.e., pass x number of arguments), then do the more complex processing within the custom sesssion/Baan.

Vince

hariharan_94
10th December 2020, 14:52
About the only time I tested this is in this thread http://www.baanboard.com/baanboard/showthread.php?t=70381&highlight=OLE+stpapi.find. Not sure why you zoom.to.menu I don't recall having to do anything like that.

Thank you Mark !!

I have go through with your example. but there is no reponse from the BaaN. I think i am using the wrong DLL name. I don't know how the get the DLL name for this Session.

Please check my code:

Set BaanObj = CreateObject("Baan4.Application.Baan")
BaanObj.Timeout = 5
On Error GoTo BaanAutomationError
SessionName$ = "tipcs2150m000"
Commessa$ = "tipcs022.cprj"
Commessavalue$ = "ZB0002"
Fathercode$ = "tipcs022.mitm"
Fathercodevalue$ = "TEST"
Position$ = "tipcs022.pono"
Positionvalue$ = "10"
BaanObj.ParseExecFunction "ottstpapihand", "stpapi.put.field(" & Chr(34) & SessionName$ & Chr(34) & "," & Chr(34) & Commessa$ & Chr(34) & "," & Chr(34) & Commessavalue$ & Chr(34) & ")"
BaanObj.ParseExecFunction "ottstpapihand", "stpapi.put.field(" & Chr(34) & SessionName$ & Chr(34) & "," & Chr(34) & Fathercode$ & Chr(34) & "," & Chr(34) & Fathercodevalue$ & Chr(34) & ")"
BaanObj.ParseExecFunction "ottstpapihand", "stpapi.put.field(" & Chr(34) & SessionName$ & Chr(34) & "," & Chr(34) & Position$ & Chr(34) & "," & Chr(34) & Positionvalue$ & Chr(34) & ")"
BaanObj.ParseExecFunction "ottstpapihand", "stpapi.find(" & Chr(34) & SessionName$ & Chr(34) & ")"
BaanAutomationError:
MsgBox "Baan IV automation error: " & BaanObj.Error
BaanObj.Quit
Set BaanObj = Nothing
Exit Sub


Please help me to solve this issue. I am very new to Baan.

Thanks in Advance

mark_h
10th December 2020, 15:58
I am not sure there would be a response. If you look at my sample right after I do a find I basically just get a field. I never really used this method but just played with it a bit - I found it slow and not something my customers could really use with out me doing a whole lot of support. You can try searching excel and ole on this forum to see what others have done in the past.

hariharan_94
10th December 2020, 18:31
I found the best way to use the OLE stuff was to write a custom session to call from VBA that has relatively simple function calls (i.e., pass x number of arguments), then do the more complex processing within the custom sesssion/Baan.

Vince

Hi Vince,

Thanks for your Advice.

Can you please give me any example code for calling custom session ?
I am new to BaaN please help me to understand the concept.

Thanks
Hari

mark_h
10th December 2020, 21:32
See this thread http://www.baanboard.com/baanboard/showthread.php?t=774&highlight=ole+automation - I posted a sample that calls a baan dll.

The dll it calls is this - it basically ran AFS code on a home grown session. This was all tried back in the early 2000's but never used.

|******************************************************************************
|* psfc9475 0 VRC B40C c3 dev
|* Generate Production Hours by Peg by Month
|* hollandv
|* 08-24-99 [07:53]
|******************************************************************************
|* Script Type: 4
|******************************************************************************
|****************************** DECLARATION SECTION ***************************
| Declare api - not needed, just testing.
#pragma used dll ottstpapihand
#pragma nowarnings
#include <bic_tt> |include tools functions
table ttirou001
table tticrp901

| Script Fields
extern string tmp.file.name(1024) | Temp file for input reading.
extern string tmp.rpt.name(1024) | Temp file for output.
extern long inputfile | File handler for inputfile
extern long rpt.temp.file | Temp. report file before download to client
extern long rc | return code/value
extern long reof | return end of file
extern long rec.count | Count records
extern long scan.ret | Return from scan
extern string buff(32) | Record buffer
extern string errmsg(100)

| Fields to read into program.
extern string read.cprj(10),read.prog(10),read.cspa(10)

| Project, program and CCN to run report by.
extern domain tppdm.cprj find.cprj
extern domain tiprog.a find.prog
extern domain tppdm.cspa find.cspa

extern domain tcyrno year.f
extern domain tcyrno year.t
extern domain tcweek date.f
extern domain tcweek date.t
extern domain tiperc effi.rate
extern domain tisfc.dayp salary.perc

function extern domain tcbool sfcdll9475.process.records(
domain tuole.data comp,
domain tccwoc main.f,
domain tccwoc main.t,
domain tccwoc sub.f,
domain tccwoc sub.t,
domain tcyrno year.f,
domain tcyrno year.t,
domain tcweek date.f,
domain tcweek date.t,
domain tiqbm2 effi.rate,
domain tisfc.dayp salary.perc,
string input.file(1024),
string report.file.name(1024),
ref domain tuole.data commmsg)
{
rc = switch.to.company(lval(comp))
input.file = strip$(input.file)
report.file.name = strip$(report.file.name)
|Open input and log files - remember default is the home directory.
if(open_files(input.file)) then
return(true)
endif
| set the parameters
spool.device = "ASCIT" | Append to file
spool.fileout = tmp.rpt.name
|Initialize cound
rec.count = 0
read.a.record()
| Init Variables
while reof=0
| Set error and read record.
scan.ret = string.scan(buff,
"(%s,%s,%s)",
read.cprj,
read.prog,
read.cspa)
if(scan.ret <> 3) then
read.a.record()
continue
endif
rc = tt.align.according.domain(shiftl$(shiftr$(read.cprj)),find.cprj,"tppdm.cprj")
rc = tt.align.according.domain(shiftl$(shiftr$(read.prog)),find.prog,"tiprog.a")
rc = tt.align.according.domain(shiftl$(shiftr$(read.cspa)),find.cspa,"tppdm.cspa")

| Put Data for WC
f9415m000.put.main.f(main.f)
f9415m000.put.main.t(main.t)
f9415m000.put.sub.f(sub.f)
f9415m000.put.sub.t(sub.t)
| Put date range
f9415m000.put.prnt.mnth(tcyesno.yes)
f9415m000.put.year.f(year.f)
f9415m000.put.week.f(date.f)
f9415m000.put.year.t(year.t)
f9415m000.put.week.t(date.t)
| Put efficiency data
f9415m000.put.effi.rate(effi.rate/100)

| Put to and from project
f9415m000.put.cprj.from(find.cprj)
f9415m000.put.cprj.to(find.cprj)

| Put to and from CCN
f9415m000.put.cspa.from(find.cspa)
f9415m000.put.cspa.to(find.cspa)
| To and From program
f9415m000.put.prog.from(find.prog)
f9415m000.put.prog.to(find.prog)
f9415m000.put.salary.perc(salary.perc)
| Continue and init sub-session.
stpapi.set.report("tisfc9415m000","rtisfc941502220",spool.device,errmsg)
if(strip$(errmsg)<>"") then
read.a.record()
continue
endif
f9415m000.continue(errmsg)
if(strip$(errmsg)<>"") then
commmsg = "commmsg:" & errmsg
f9415m000.end()
return(true)
endif
| Go get next record - if it exists
read.a.record()
endwhile
rc = server2client(tmp.rpt.name, report.file.name,1)
if(rc) then
commmsg = "commmsg:Bad destination txt file or location."
else
commmsg="commmsg:Done"
endif
seq.unlink(tmp.rpt.name)
seq.unlink(tmp.file.name)
| Stop and kill subsessions if they exist
f9415m000.end()
return(true)
}
Function read.a.record()
{
reof = 0
reof = seq.gets(buff,30,inputfile)
rec.count = rec.count + 1
}

function domain tcbool open_files( string input.file(1024))
{

inputfile = seq.open(input.file,"r")

| Open PC file to make sure it exists.
inputfile = seq.open.local(input.file,"r",0)
if(inputfile<0) then
| Remove our work file
return(true)
endif
seq.close.local(inputfile)

| Create temporary file to copy the PC file into.
tmp.file.name = creat.tmp.file$(bse.tmp.dir$())
tmp.file.name = strip$(tmp.file.name)

| Copy PC file to server
rc = client2server(input.file,tmp.file.name,0)

| Open Server file for processing.
inputfile = seq.open(tmp.file.name,"r")
if(inputfile<0) then
seq.unlink(tmp.file.name)
return(true)
endif


| Open err file.
| Create temporary file for report.
tmp.rpt.name = creat.tmp.file$(bse.tmp.dir$())
tmp.rpt.name = strip$(tmp.rpt.name)
return(false)
}