pedromrs
13th February 2006, 18:55
Hello all,
Did anyone have success creating Replenishment orders via AFS?
I have been successfull in creating the header for the order (session tdrpl0110m100).
When I call the subsession I noticed in the AFS.log that it won't collect the necessary information from the main session. When I try to save the line it comes up with something like "Can't find order reference".
Not sure if this is the problem but the tdrpl0110m100 is actually not on the Baan explorer. There's a tdrpl0105m000 that calls tdrpl0110m100.
Here is part of my code:
|Colocar numero de ordem - Serie
stpapi.put.field( "tdrpl0110m100", "tdrpl105.orno", "2" )
|Colocar tipo de ordem
stpapi.put.field( "tdrpl0110m100", "tdrpl105.cotp", "RP1" )
|Colocar armazem de origem
stpapi.put.field( "tdrpl0110m100", "tdrpl105.rwar", "006" )
|Colocar armazem de destino
stpapi.put.field( "tdrpl0110m100", "tdrpl105.dwar", "C6F" )
|Colocar data da ordem
stpapi.put.field( "tdrpl0110m100", "tdrpl105.odat", str$(data) )
|Data prevista de entrega
stpapi.put.field( "tdrpl0110m100", "tdrpl105.pddt", str$(data+10) )
|Data prevista de recepção
stpapi.put.field( "tdrpl0110m100", "tdrpl105.prdt", str$(data+10) )
|Tentar inserir o record
ret=stpapi.insert( "tdrpl0110m100", true, error )
|Verificar se existiu um erro
if (ret=0) then
message(error)
|Fazer o recover
stpapi.recover( "tdrpl0110m100", error )
else
|Vamos buscar o numero da ordem recem-criada
stpapi.get.field( "tdrpl0110m100", "tdrpl105.orno", orno )
|Preparar subsessão de linhas
stpapi.handle.subproc( "tdrpl0110m100", "tdrpl0111s100", "add" )
|Disparar subsessão
stpapi.change.view( "tdrpl0110m100" )
|Colocar numero da ordem
stpapi.put.field( "tdrpl0111s100", "tdrpl100.orno", orno )
|Colocar a posicao
stpapi.put.field( "tdrpl0111s100", "tdrpl100.pono", "1" )
|Colocar tipo de ordem
stpapi.put.field( "tdrpl0110m100", "tdrpl100.cotp", "RP1" )
|Colocar a sequencia
|stpapi.put.field( "tdrpl0111s100", "tdrpl100.srnb", "1" )
|Colocar Item
stpapi.put.field( "tdrpl0111s100", "tdrpl100.item", item )
|Colocar Unidade
stpapi.put.field( "tdrpl0111s100", "tdrpl100.cuni", "Un " )
|Colocar Quantidade
stpapi.put.field( "tdrpl0111s100", "tdrpl100.oqua", str$(qana) )
|Colocar armazem de origem
stpapi.put.field( "tdrpl0111s100", "tdrpl100.rwar", "006" )
|Colocar armazem de destino
stpapi.put.field( "tdrpl0111s100", "tdrpl100.dwar", "C6F" )
|Colocar data da ordem
stpapi.put.field( "tdrpl0111s100", "tdrpl100.odat", str$(data) )
|Data prevista de entrega
stpapi.put.field( "tdrpl0111s100", "tdrpl100.pddt", str$(data+10) )
|Data prevista de recepção
stpapi.put.field( "tdrpl0111s100", "tdrpl100.prdt", str$(data+10) )
|Inserir Record
ret=stpapi.insert( "tdrpl0111s100", true, error )
|ret=stpapi.save( "tdrpl0111s100", error )
if (ret=0) then
message(error)
|Fazer o recover
stpapi.recover( "tdrpl0111s100", error )
else
message("Sucesso Linhas")
endif
|Encerrar sessão de linhas
stpapi.end.session( "tdrpl0111s100" , error )
endif
Thank you,
mark_h
13th February 2006, 19:29
Not sure about your version, but from ours I would expect to see something like this
ret=stpapi.insert( "tdrpl0110m100", true, error )
stpapi.handle.subproc( "tdrpl0110m100", "tdrpl0111s100", "add" )
|To activate lines
stpapi.continue.process( "tdrpl0110m100" )
But then again our tdrpl0110m100 activates tdrpl0111s000, but we do have a tdrpl0111s100 on the system. Not real familiar with these sessions and have not actually done an AFS routine for them.
pedromrs
13th February 2006, 19:39
Mark,
Thanks. That did the trick. I did not try that one because the generated dll from the session didn't brought that one up. As I didn't touch AFS code for over a year now I did not remember to try it.
So my code works for adding replenishment orders if you change the code to reflect Marks suggestion.
Thanks again,
fsamuels
15th March 2006, 21:09
I wonder if some can give me the where I should add the code that did the trick.
I am new on this and I try to convert this code to vba code in excel and it want add items to the replenishment order.
Regards
Fredrik
---------------
Call ConnectBaan
Dim BaanSess As String
Dim SessField As String
Dim sDll As String
Dim sReturnString As String
sReturnString = Space(128)
Dim sValue As String
' |Colocar numero de ordem - Serie
' stpapi.put.field( "tdrpl0110m100", "tdrpl105.orno", "2" )
BaanSess = "tdrpl0110m100"
SessField = "tdrpl105.orno"
sValue = "2"
sDll = "stpapi.put.field(" & Chr(34) & BaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sValue & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
' |Colocar tipo de ordem
' stpapi.put.field( "tdrpl0110m100", "tdrpl105.cotp", "RP1" )
SessField = "tdrpl105.cotp"
sValue = "RP1"
sDll = "stpapi.put.field(" & Chr(34) & BaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sValue & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
' |Colocar armazem de origem
' stpapi.put.field( "tdrpl0110m100", "tdrpl105.rwar", "006" )
SessField = "tdrpl105.rwar"
sValue = "200"
sDll = "stpapi.put.field(" & Chr(34) & BaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sValue & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
' |Colocar armazem de destino
' stpapi.put.field( "tdrpl0110m100", "tdrpl105.dwar", "C6F" )
SessField = "tdrpl105.dwar"
sValue = "21D"
sDll = "stpapi.put.field(" & Chr(34) & BaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sValue & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
' |Colocar data da ordem
' stpapi.put.field( "tdrpl0110m100", "tdrpl105.odat", str$(data) )
SessField = "tdrpl105.odat"
sValue = Date
sDll = "stpapi.put.field(" & Chr(34) & BaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sValue & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
' |Data prevista de entrega
' stpapi.put.field( "tdrpl0110m100", "tdrpl105.pddt", str$(data+10) )
SessField = "tdrpl105.pddt"
sValue = Date + 10
sDll = "stpapi.put.field(" & Chr(34) & BaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sValue & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
' |Data prevista de recepção
' stpapi.put.field( "tdrpl0110m100", "tdrpl105.prdt", str$(data+10) )
SessField = "tdrpl105.prdt"
sValue = Date
sDll = "stpapi.put.field(" & Chr(34) & BaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sValue & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
' |Tentar inserir o record
' ret = stpapi.Insert("tdrpl0110m100", True, Error)
' sDll = "stpapi.Insert(" & Chr(34) & BaanSess & Chr(34) & ",1," & sReturnString & ")"
' Call SendtoBAAN("ottstpapihand", sDll)
Dim sErrMsg As String
Dim ret
sErrMsg = Space(50)
ret = BaanObj.ParseExecFunction("ottstpapihand", "stpapi.insert(" & Chr(34) & BaanSess & Chr(34) & ",1," & Chr(34) & sErrMsg & Chr(34) & ")")
MsgBox ("ret = " & CStr(ret) & Chr(10) & _
"sErrMsg = " & sErrMsg & Chr(10) & _
"BaanObj.Error = " & BaanObj.Error & Chr(10) & _
"BaanObj.ReturnValue = " & BaanObj.returnvalue & Chr(10) & _
"BaanObj.FunctionCall = " & BaanObj.FunctionCall)
If BaanObj.Error <> 0 Then
' Send mail (sometime in the future?)
ret = BaanObj.ParseExecFunction("ottstpapihand", "stpapi.recover( " & Chr(34) & BaanSess & Chr(34) & " ," & Chr(34) & sErrMsg & Chr(34) & ")")
Else
' Else
' |Vamos buscar o numero da ordem recem-criada
' stpapi.get.field( "tdrpl0110m100", "tdrpl105.orno", orno )
Dim sOrno As String
SessField = "tdrpl105.orno"
sDll = "stpapi.get.field(" & Chr(34) & BaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sReturnString & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
sOrno = GetValueFromStapiGet(BaanObj.FunctionCall, BaanSess, SessField)
' |Preparar subsessão de linhas
' stpapi.handle.subproc( "tdrpl0110m100", "tdrpl0111s100", "add" )
SessField = "tdrpl0111s100"
sValue = "add"
sDll = "stpapi.handle.subproc(" & Chr(34) & BaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sValue & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
'
' |Disparar subsessão
' stpapi.Change.View ("tdrpl0110m100")
sErrMsg = Space(50)
ret = BaanObj.ParseExecFunction("ottstpapihand", "stpapi.change.view(" & Chr(34) & BaanSess & Chr(34) & "," & Chr(34) & sErrMsg & Chr(34) & ")")
MsgBox ("ret = " & CStr(ret) & Chr(10) & _
"sErrMsg = " & sErrMsg & Chr(10) & _
"BaanObj.Error = " & BaanObj.Error & Chr(10) & _
"BaanObj.ReturnValue = " & BaanObj.returnvalue & Chr(10) & _
"BaanObj.FunctionCall = " & BaanObj.FunctionCall)
' |Colocar numero da ordem
' stpapi.put.field( "tdrpl0111s100", "tdrpl100.orno", orno )
subBaanSess = "tdrpl0111s100"
SessField = "tdrpl100.orno"
sValue = sOrno
sDll = "stpapi.put.field(" & Chr(34) & subBaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sValue & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
' |Colocar a posicao
' stpapi.put.field( "tdrpl0111s100", "tdrpl100.pono", "1" )
SessField = "tdrpl100.pono"
sValue = "1"
sDll = "stpapi.put.field(" & Chr(34) & subBaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sValue & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
' |Colocar tipo de ordem
' stpapi.put.field( "tdrpl0110m100", "tdrpl100.cotp", "RP1" )
SessField = "tdrpl100.cotp"
sValue = "RP1"
sDll = "stpapi.put.field(" & Chr(34) & BaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sValue & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
'
' |Colocar a sequencia
' |stpapi.put.field( "tdrpl0111s100", "tdrpl100.srnb", "1" )
SessField = "tdrpl100.srnb"
sValue = "1"
sDll = "stpapi.put.field(" & Chr(34) & subBaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sValue & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
' |Colocar Item
' stpapi.put.field( "tdrpl0111s100", "tdrpl100.item", item )
SessField = "tdrpl100.item"
sValue = "LZF083256/1"
sDll = "stpapi.put.field(" & Chr(34) & subBaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sValue & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
' |Colocar Unidade
' stpapi.put.field( "tdrpl0111s100", "tdrpl100.cuni", "Un " )
' SessField = "tdrpl100.cuni"
' sValue = "Un "
' sDll = "stpapi.put.field(" & Chr(34) & subBaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sValue & Chr(34) & ")"
' Call SendtoBAAN("ottstpapihand", sDll)
' |Colocar Quantidade
' stpapi.put.field( "tdrpl0111s100", "tdrpl100.oqua", str$(qana) )
SessField = "tdrpl100.oqua"
sValue = "10"
sDll = "stpapi.put.field(" & Chr(34) & subBaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sValue & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
' |Colocar armazem de origem
' stpapi.put.field( "tdrpl0111s100", "tdrpl100.rwar", "006" )
SessField = "tdrpl100.rwar"
sValue = "200"
sDll = "stpapi.put.field(" & Chr(34) & subBaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sValue & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
' |Colocar armazem de destino
' stpapi.put.field( "tdrpl0111s100", "tdrpl100.dwar", "C6F" )
SessField = "tdrpl100.dwar"
sValue = "21D"
sDll = "stpapi.put.field(" & Chr(34) & subBaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sValue & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
' |Colocar data da ordem
' stpapi.put.field( "tdrpl0111s100", "tdrpl100.odat", str$(data) )
SessField = "tdrpl100.odat"
sValue = Date
sDll = "stpapi.put.field(" & Chr(34) & subBaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sValue & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
'Data prevista de entrega
' stpapi.put.field( "tdrpl0111s100", "tdrpl100.pddt", str$(data+10) )
SessField = "tdrpl100.pddt"
sValue = Date
sDll = "stpapi.put.field(" & Chr(34) & subBaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sValue & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
' |Data prevista de recepção
' stpapi.put.field( "tdrpl0111s100", "tdrpl100.prdt", str$(data+10) )
SessField = "tdrpl100.prdt"
sValue = Date
sDll = "stpapi.put.field(" & Chr(34) & subBaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sValue & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
' |Inserir Record
' ret = stpapi.Insert("tdrpl0111s100", True, Error)
' |ret=stpapi.save( "tdrpl0111s100", error )
'Belive I need this
'SessField = "tdrpl105.orno"
'sValue = sOrno
'sDll = "stpapi.put.field(" & Chr(34) & BaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sValue & Chr(34) & ")"
'Call SendtoBAAN("ottstpapihand", sDll)
sErrMsg = Space(128)
ret = BaanObj.ParseExecFunction("ottstpapihand", "stpapi.insert(" & Chr(34) & subBaanSess & Chr(34) & ",1," & Chr(34) & sErrMsg & Chr(34) & ")")
MsgBox ("ret = " & CStr(ret) & Chr(10) & _
"sErrMsg = " & sErrMsg & Chr(10) & _
"BaanObj.Error = " & BaanObj.Error & Chr(10) & _
"BaanObj.ReturnValue = " & BaanObj.returnvalue & Chr(10) & _
"BaanObj.FunctionCall = " & BaanObj.FunctionCall)
End If
----------------------------------:confused:
pedromrs
16th March 2006, 00:13
Replace the change.view() for the continue.process call
fsamuels
16th March 2006, 08:27
I try that with no success.
sErrMsg = Space(50)
BaanObj.ParseExecFunction "ottstpapihand", "stpapi.continue.process(" & Chr(34) & BaanSess & Chr(34) & "," & Chr(34) & sErrMsg & Chr(34) & ")"
' |Colocar numero da ordem
' stpapi.put.field( "tdrpl0111s100", "tdrpl100.orno", orno )
SessField = "tdrpl100.orno"
sValue = "30991"
sDll = "stpapi.put.field(" & Chr(34) & subBaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sValue & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
It get error -10 then I try to put field with "stpapi.put.field"
Any proposal?
:confused:
fsamuels
16th March 2006, 09:08
It works now but i dont understand why
I add a "stpapi.put.field" before i stpapi.continue.process on the childsession
and now it works
SessField = "tdrpl100.orno"
sValue = "30991"
sDll = "stpapi.put.field(" & Chr(34) & subBaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sValue & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
sErrMsg = Space(50)
sDll = "stpapi.continue.process(" & Chr(34) & subBaanSess & Chr(34) & "," & Chr(34) & sErrMsg & Chr(34) & ")"
ret = BaanObj.ParseExecFunction("ottstpapihand", sDll)
MsgBox ("ret = " & CStr(ret) & Chr(10) & _
"sErrMsg = " & sErrMsg & Chr(10) & _
"BaanObj.Error = " & BaanObj.Error & Chr(10) & _
"BaanObj.ReturnValue = " & BaanObj.returnvalue & Chr(10) & _
"BaanObj.FunctionCall = " & BaanObj.FunctionCall)
Can someone wise explain this for me?
:cool:
mark_h
16th March 2006, 16:21
Sometimes everything essential to a sub-session does not make it from the main session when using API code. So in some cases you may have to work around this problem - put the fields, do a look up, etc. Since I am not familiar with these sessions I really can not say what the problem could be. It could also just be that you need the latest patches on the objects.
vandana
11th January 2007, 06:41
Dear pedromrs
Hi, I would like to have source of AFS of maintining RPL header part from you, can u send me on g_shirsat@yahoo.com
Thanks
Ganesh
fsamuels
12th January 2007, 07:10
'This is my sourcode for this Excel Macro that I was playing with for some time ago.
'Hope you find that you need in this.
'To use this you need a sheet in Excel that is named RO
'Please not ask how it works since I am very busy right now..
'Good luck
Dim BaanObj As Object
Dim dllname As String
Dim dllfunction As String
Option Explicit
Private db As New ADODB.Connection
Dim iFast As Integer
Private Sub connectDb()
On Error Resume Next
db.Open "Provider=sqloledb;Data Source=knasqlcl02\sql02;Initial Catalog=FLS;User Id=******;Password=*****;"
End Sub
Function PopulateBaanField(BaanObj, sSession, sTable, sField, sValue)
' filling the Baan field with the value
Dim s
Dim sTest As String
sTest = Space(128)
FieldName = sTable & "." & sField
s = "stpapi.put.field(" & Chr(34) & sSession & Chr(34) & ", " & _
Chr(34) & sTable & "." & sField & Chr(34) & ", " & _
Chr(34) & sValue & Chr(34) & ")"
Call BaanObj.ParseExecFunction("ottstpapihand", s)
If BaanObj.Error <> 0 Or BaanObj.returnvalue <> "" Then
BaanObj.Quit
End If
'Call BaanObj.ParseExecFunction("ottstpapihand", "stpapi.get.field(" & Chr(34) & sSession & Chr(34) & "," & Chr(34) & sTable & "." & sField & Chr(34) & "," & Chr(34) & sTest & Chr(34) & ")")
'Call BaanObj.ParseExecFunction("ottstpapihand", "stpapi.end.session(" & Chr(34) & sSession & Chr(34) & ")")
' If BaanObj.Error <> 0 Or BaanObj.ReturnValue <> "" Then
' BaanObj.Quit
' End If
'tempstr = BaanObj.ReturnValue
'MsgBox "numRecepción-->> " & sTest
End Function
Function GetValueFromStapiGet(fc As String, sn As String, fd As String)
GetValueFromStapiGet = Mid$(fc, 18 + Len(sn) + 3 + Len(fd) + 4)
GetValueFromStapiGet = Left$(GetValueFromStapiGet, Len(GetValueFromStapiGet) - 2)
GetValueFromStapiGet = Left(GetValueFromStapiGet, Len(GetValueFromStapiGet) - 1)
End Function
Private Sub ConnectBaan()
On Error GoTo CannotCreateBaan
' Baan4
If BaanObj Is Nothing Then
Set BaanObj = CreateObject("Baan4.Application")
Set BaanObj = BaanObj
End If
' Baan5
'Set BaanObj = CreateObject("Baan.Application")
BaanObj.Timeout = 20
Exit Sub
CannotCreateBaan:
MsgBox "Can not connect to Baan"
End
End Sub
Private Sub DisconnectBaan()
If Not BaanObj Is Nothing Then
BaanObj.Quit
Set BaanObj = Nothing
End If
End Sub
Private Sub SendtoBAAN(ByVal dllname As String, ByVal dllfunction As String)
Dim returnvalue As String
If BaanObj Is Nothing Then
ConnectBaan
If BaanObj Is Nothing Then
End
End If
End If
BaanObj.ParseExecFunction dllname, dllfunction
Dim errormsg As String
Dim Errorsw As Boolean
errormsg = ""
If BaanObj.Error <> 0 Then
Select Case BaanObj.Error
Case Is = -1
errormsg = "DLL Unknown"
Case Is = -2
errormsg = "Function Unknown"
Case Is = -3
errormsg = "Syntax Error in Function Call"
End Select
MsgBox "Call to Baan DLL failed, error = " & errormsg & vbNewLine & BaanObj.Error
End If
returnvalue = Val(BaanObj.returnvalue)
Errorsw = False
If returnvalue = False Then
Errorsw = True
End If
Exit Sub
AutomationError:
Cells(2, 3) = "Baan IV automation error: " & BaanObj.Error
End
End Sub
Public Sub RepleinsmentMain()
Dim sAsk As String
sAsk = MsgBox("Do you want to create replenishment order", vbYesNo + vbQuestion)
If sAsk = vbNo Then Exit Sub
'31002
Call ConnectBaan
Dim sReplenishmentorder As String
If Not ReplenishmentHeader("200", "21D", sReplenishmentorder) Then
Call DisconnectBaan
Exit Sub
End If
'For loop later on
Sheets("RO").Select
Cells(1, 2) = sReplenishmentorder
Dim y As Integer
y = 4
Dim sItem As String
Dim iQuantity As Integer
Do While Not Cells(y, 1) = ""
Cells(y, 1).Select
sItem = Cells(y, 1)
iQuantity = Cells(y, 5)
If Not ReplenishmentAdditem(sReplenishmentorder, sItem, iQuantity) Then
Call DisconnectBaan
Exit Sub
DoEvents
End If
DoEvents
y = y + 1
Loop
MsgBox "Done", vbInformation
Call DisconnectBaan
End Sub
Private Function ReplenishmentAdditem(sReplenishmentorder As String, sItem As String, iQuantity As Integer) As Boolean
Dim BaanSess As String
Dim subBaanSess As String
Dim SessField As String
Dim sDll As String
Dim sErrMsg As String
Dim sReturnString As String
sReturnString = Space(128)
Dim sValue As String
subBaanSess = "tdrpl0111s100"
BaanSess = "tdrpl0110m100"
Dim ret As Variant
Dim sOrno As String
SessField = "tdrpl105.orno"
sDll = "stpapi.put.field(" & Chr(34) & BaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sReplenishmentorder & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
sErrMsg = Space(128)
sDll = "stpapi.Find(" & Chr(34) & BaanSess & Chr(34) & "," & Chr(34) & sErrMsg & Chr(34) & ")"
ret = BaanObj.ParseExecFunction("ottstpapihand", sDll)
If BaanObj.returnvalue <> 1 Then
stpapi_End_session (BaanSess)
MsgBox "Replenishmentorder: " & sReplenishmentorder & " not exist"
Exit Function
End If
sValue = "add"
sDll = "stpapi.handle.subproc(" & Chr(34) & BaanSess & Chr(34) & "," & Chr(34) & subBaanSess & Chr(34) & "," & Chr(34) & sValue & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
'This make it possible to stpapi.continue.process downunder
SessField = "tdrpl100.orno"
sDll = "stpapi.put.field(" & Chr(34) & subBaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sReplenishmentorder & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
' |To activate lines
' stpapi.continue.process ("tdrpl0110m100")
sErrMsg = Space(50)
sDll = "stpapi.continue.process(" & Chr(34) & subBaanSess & Chr(34) & "," & Chr(34) & sErrMsg & Chr(34) & ")"
ret = BaanObj.ParseExecFunction("ottstpapihand", sDll)
'MsgBox ("ret = " & CStr(ret) & Chr(10) & _
' "sErrMsg = " & sErrMsg & Chr(10) & _
' "BaanObj.Error = " & BaanObj.Error & Chr(10) & _
' "BaanObj.ReturnValue = " & BaanObj.returnvalue & Chr(10) & _
' "BaanObj.FunctionCall = " & BaanObj.FunctionCall)
'Add Item
SessField = "tdrpl100.item"
sDll = "stpapi.put.field(" & Chr(34) & subBaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sItem & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
' |Colocar Unidade
' stpapi.put.field( "tdrpl0111s100", "tdrpl100.cuni", "Un " )
' SessField = "tdrpl100.cuni"
' sValue = "Un "
' sDll = "stpapi.put.field(" & Chr(34) & subBaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sValue & Chr(34) & ")"
' Call SendtoBAAN("ottstpapihand", sDll)
'Add Quantity
SessField = "tdrpl100.oqua"
sDll = "stpapi.put.field(" & Chr(34) & subBaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & CStr(iQuantity) & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
' |Colocar armazem de origem
' stpapi.put.field( "tdrpl0111s100", "tdrpl100.rwar", "006" )
' SessField = "tdrpl100.rwar"
' sValue = "200"
' sDll = "stpapi.put.field(" & Chr(34) & subBaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sValue & Chr(34) & ")"
' Call SendtoBAAN("ottstpapihand", sDll)
' |Colocar armazem de destino
' stpapi.put.field( "tdrpl0111s100", "tdrpl100.dwar", "C6F" )
' SessField = "tdrpl100.dwar"
' sValue = "21D"
' sDll = "stpapi.put.field(" & Chr(34) & subBaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sValue & Chr(34) & ")"
' Call SendtoBAAN("ottstpapihand", sDll)
' |Colocar data da ordem
' stpapi.put.field( "tdrpl0111s100", "tdrpl100.odat", str$(data) )
' SessField = "tdrpl100.odat"
' sValue = Date
' sDll = "stpapi.put.field(" & Chr(34) & subBaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sValue & Chr(34) & ")"
' Call SendtoBAAN("ottstpapihand", sDll)
'Data prevista de entrega
' stpapi.put.field( "tdrpl0111s100", "tdrpl100.pddt", str$(data+10) )
' SessField = "tdrpl100.pddt"
' sValue = "20070101"
' sDll = "stpapi.put.field(" & Chr(34) & subBaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sValue & Chr(34) & ")"
' Call SendtoBAAN("ottstpapihand", sDll)
' |Data prevista de recepção
' stpapi.put.field( "tdrpl0111s100", "tdrpl100.prdt", str$(data+10) )
' SessField = "tdrpl100.prdt"
' sValue = Date
' sDll = "stpapi.put.field(" & Chr(34) & subBaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sValue & Chr(34) & ")"
' Call SendtoBAAN("ottstpapihand", sDll)
' |Inserir Record
' ret = stpapi.Insert("tdrpl0111s100", True, Error)
' |ret=stpapi.save( "tdrpl0111s100", error )
sErrMsg = Space(128)
ret = BaanObj.ParseExecFunction("ottstpapihand", "stpapi.insert(" & Chr(34) & subBaanSess & Chr(34) & ",1," & Chr(34) & sErrMsg & Chr(34) & ")")
' MsgBox ("ret = " & CStr(ret) & Chr(10) & _
' "sErrMsg = " & sErrMsg & Chr(10) & _
' "BaanObj.Error = " & BaanObj.Error & Chr(10) & _
' "BaanObj.ReturnValue = " & BaanObj.returnvalue & Chr(10) & _
' "BaanObj.FunctionCall = " & BaanObj.FunctionCall)
sDll = "stpapi.End.session(" & Chr(34) & subBaanSess & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
sDll = "stpapi.End.session(" & Chr(34) & BaanSess & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
ReplenishmentAdditem = True
End Function
Private Function stpapi_End_session(sSession As String) As Boolean
Dim sDll As String
sDll = "stpapi.End.session(" & Chr(34) & sSession & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
stpapi_End_session = True
End Function
Private Function ReplenishmentHeader(sMainStorage As String, sPwStorage As String, ByRef sReplenishmentorder As String) As Boolean
Dim BaanSess As String
Dim SessField As String
Dim sDll As String
Dim sReturnString As String
sReturnString = Space(128)
Dim sValue As String
Dim dDate As Date
BaanSess = "tdrpl0110m100"
SessField = "tdrpl105.cotp"
sValue = "RP1"
sDll = "stpapi.put.field(" & Chr(34) & BaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sValue & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
'sMainStorage
SessField = "tdrpl105.rwar"
sDll = "stpapi.put.field(" & Chr(34) & BaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sMainStorage & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
'PwStorage
SessField = "tdrpl105.dwar"
sDll = "stpapi.put.field(" & Chr(34) & BaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sPwStorage & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
Dim sErrMsg As String
sErrMsg = Space(128)
Dim ret As Variant
ret = BaanObj.ParseExecFunction("ottstpapihand", "stpapi.insert(" & Chr(34) & BaanSess & Chr(34) & ",1," & Chr(34) & sErrMsg & Chr(34) & ")")
If BaanObj.Error <> 0 Then
' Send mail (sometime in the future?)
' MsgBox ("ret = " & CStr(ret) & Chr(10) & _
' "sErrMsg = " & sErrMsg & Chr(10) & _
' "BaanObj.Error = " & BaanObj.Error & Chr(10) & _
' "BaanObj.ReturnValue = " & BaanObj.returnvalue & Chr(10) & _
' "BaanObj.FunctionCall = " & BaanObj.FunctionCall)
ret = BaanObj.ParseExecFunction("ottstpapihand", "stpapi.recover( " & Chr(34) & BaanSess & Chr(34) & " ," & Chr(34) & sErrMsg & Chr(34) & ")")
stpapi_End_session (BaanSess)
Exit Function
Else
SessField = "tdrpl105.orno"
sDll = "stpapi.get.field(" & Chr(34) & BaanSess & Chr(34) & "," & Chr(34) & SessField & Chr(34) & "," & Chr(34) & sReturnString & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
sReplenishmentorder = GetValueFromStapiGet(BaanObj.FunctionCall, BaanSess, SessField)
sDll = "stpapi.End.session(" & Chr(34) & BaanSess & Chr(34) & ")"
Call SendtoBAAN("ottstpapihand", sDll)
End If
'31002
ReplenishmentHeader = True
End Function
pedromrs
12th January 2007, 10:36
Vandana,
If you look at my first post that code works with the changes suggested by Mark on the second post.
vandana
13th January 2007, 09:32
Dear Pedros,
Can u please send me ur code for rpl order thru AFS
Thanks
Vandana