fbernaus
14th July 2004, 19:23
We have automated the session "tdinv1101m000" through AFS functions. Now we have a very strange problem. Lets suppose we have the item 1234567 and want to transfer it from the warehouse 111 to the warehouse 222.
Well, the first time we tried the transfer the "find" AFS function does not find the article (in spite of the article exits), but in the consecutive times the article is found and the transfer is made.

Have you had this kind of problem before? Please, help! Really don't know what can be happening. Thanks very much in advance! ;)

Following is the code we employ as far as the article search:

Dim baanobj As Object=CreateObject("Baan4.Application.baanivc4") '501
Dim sesion_baan As String = "tdinv1101m000" 'SESION: Introducir transacciones de stock por artículo

stpapi.put.field(sesion_baan,"tdinv100.item",item_code)
stpapi.put.field(sesion_baan,"tdinv100.cwar",from_what_warehouse)
stpapi.find(sesion_baan)<<<<----- At this point it returns -1, but only the first time!!! :confused:

mark_h
14th July 2004, 23:00
Not seen, but there have been other posts in this forum that mentioned sometimes they had to do two finds. I am not familiar with this session since we use location control so I do not know why the find does not work. With ilc control I actually put the item, warehouse, date and serial number to find the last transaction I did. Is it possible the find requires more data than just item code and warehouse? I say this because the first find may think it found the incorrect record because all the key fields were not provided, then the second find now has these additional fields and so know find thinks it has the correct record. That might be why two finds work.

Mark

fbernaus
15th July 2004, 10:09
Thank you very much, Mark. I have also think about that. It seems the most logical thing to be happening. We'll investigate in that direction and tell you what is the cause of the problem.
Best regards!

fbernaus
15th July 2004, 13:54
Finally we have come to conclusion that the find function is not working because it finds something that does not exist. I mean, in the session tdinv1101m000 ("Enter stock transaction by item") if you trye to find an item that has not been transfered yet you won´t find it. However, if you trie the same with an item that have been transfered you will find it and be able to realize the transfer.

Do you know if the find function admits some parameter to tell it that it must not really find the item, but to create it, instead? Maybe it will be another way to solve this. We would be really grateful if you could lend us a hand! ;)

mark_h
15th July 2004, 16:24
There is no way to use find to create the item. On my session I do not bother with the first find. I just put the fields for tdilc1120m000 and then do the insert command, then a continue. I then get the sequence number that it created. I then finish transferring the item. Once that is complete I then use item,warehouse, input date and sequence to find the transaction to check the status. If status is not complete I delete it and give the user an error message.

My thinking is you do not need to worry about the find if you are just transferring parts. Just start with putting the fields, then the insert and whatever else is needed to process the transaction. I glanced at the form and it looks like it also has sequence in there. So this may work.

Mark

Hitesh Shah
15th July 2004, 17:10
I think return value of -1 means invalid function call. Successful call returns 0,1 or 2 .

I agree with Mark in that u can just start putting fields and insert record without bothering to find.

fbernaus
15th July 2004, 18:15
Yes, it was a mistake, the return value is 0, not -1.
I have tried the put and insert without using the find function, but I am having the same problem. Any ideas?

Thanks for your interest! ;)

mark_h
16th July 2004, 00:10
Are you doing this in VB or are you doing this in a Baan session? I do not see how you could be having the same problem. When you just put the fields and do an insert the record should be there. And then you might need to process it with a continue - since we do not use this session I do not really know.

Mark

Hitesh Shah
16th July 2004, 06:59
It can hel us understand what could be wrong.

fbernaus
16th July 2004, 10:07
Of course, here is the code. This code is the one that we are trying after have tried using the "find" function without success. Thanks for your interest! ;)


Dim baanobj As Object = CreateObject("Baan4.Application.baanivc4")

Dim cod_articulo As String = txt_articulo.Text.Trim()
Dim transfer_quantity As String = "10"

Dim operation as string = "6" ' That value corresponds to a transfer
Dim source_warehouse As String = "001"
Dim destiny_warehouse As String = "012"

Dim TODAY As Date = Now
Dim l_TODAY As Long = Calculo_fecha_baan(TODAY) 'Función de Jon: en Module1
Dim str_TODAY As String = l_TODAY.ToString
Dim save As Long = 1 'commit=true.
Dim errorea As String
Dim resultado_update As Long
Dim sesion_baan As String = "tdinv1101m000"

baanobj.ParseExecFunction("ottstpapihand", "stpapi.put.field(" & Chr(34) & sesion_baan & Chr(34) & "," & Chr(34) & "tdinv100.item" & Chr(34) & "," & Chr(34) & cod_articulo & Chr(34) & ")")

baanobj.ParseExecFunction("ottstpapihand", "stpapi.put.field(" & Chr(34) & sesion_baan & Chr(34) & "," & Chr(34) & "tdinv100.cwar" & Chr(34) & "," & Chr(34) & source_warehouse & Chr(34) & ")")

baanobj.ParseExecFunction("ottstpapihand", "stpapi.put.field(" & Chr(34) & sesion_baan & Chr(34) & "," & Chr(34) & "tdinv100.idat" & Chr(34) & "," & Chr(34) & str_TODAY & Chr(34) & ")")

' We do not make a find here because if the item has not suffered yet a transfer it won´t be found, so we have attempted to not use the "find" function and make the necessaries puts and then an "insert", but this does not work neither! The transfer is not made.

baanobj.ParseExecFunction("ottstpapihand", "stpapi.put.field(" & Chr(34) & sesion_baan & Chr(34) & "," & Chr(34) & "tdinv100.odat" & Chr(34) & "," & Chr(34) & str_TODAY & Chr(34) & ")")

baanobj.ParseExecFunction("ottstpapihand", "stpapi.put.field(" & Chr(34) & sesion_baan & Chr(34) & "," & Chr(34) & "tdinv100.dqan" & Chr(34) & "," & Chr(34) & transfer_quantity & Chr(34) & ")")

baanobj.ParseExecFunction("ottstpapihand", "stpapi.put.field(" & Chr(34) & sesion_baan & Chr(34) & "," & Chr(34) & "tdinv100.dwar" & Chr(34) & "," & Chr(34) & destiny_warehouse & Chr(34) & ")")

baanobj.ParseExecFunction("ottstpapihand", "stpapi.put.field(" & Chr(34) & sesion_baan & Chr(34) & "," & Chr(34) & "tdinv100.trdt" & Chr(34) & "," & Chr(34) & str_TODAY & Chr(34) & ")")


'=====================================================
'>>>> At this point all the necessary fields have put their values >>
'>>>> So we made an "insert" >>>>>>>>>>>


baanobj.ParseExecFunction("ottstpapihand", "stpapi.insert(" & Chr(34) & sesion_baan & Chr(34) & "," & save & "," & Chr(34) & errorea & Chr(34) & ")")


'End the session and free the resources
baanobj.ParseExecFunction("ottstpapihand", "stpapi.end.session(" & Chr(34) & sesion_baan & Chr(34) & ")")
baanobj.Quit()
baanobj = Nothing
MsgBox("Transfer realized!") 'The message appears, but the transfer is not made.



End Sub

mark_h
16th July 2004, 16:33
Well I do not know about tdinv1101m000, but in tdilc1120m000 I have to do a continue after the insert to get it to start processing. My next question is after the insert can you log into Baan and see it? Do you get any error msg back from the insert?

Mark

Hitesh Shah
16th July 2004, 16:48
We too have only ILC companies. Can u try giving stpapi.update after stpapi.insert. Further is there any value errormea variable.

fbernaus
19th July 2004, 13:50
We have the good code. It is not necessary to make a "continue.process". Simple as to put all the necessary fields with the put function and then make an insert!!! :)
Thanks for your help and interest.

Following is the code:
baanobj.ParseExecFunction("ottstpapihand", "stpapi.put.field(" & Chr(34) & sesion_baan & Chr(34) & "," & Chr(34) & "tdinv100.item" & Chr(34) & "," & Chr(34) & cod_articulo & Chr(34) & ")")
baanobj.ParseExecFunction("ottstpapihand", "stpapi.put.field(" & Chr(34) & sesion_baan & Chr(34) & "," & Chr(34) & "tdinv100.cwar" & Chr(34) & "," & Chr(34) & "001" & Chr(34) & ")")
baanobj.ParseExecFunction("ottstpapihand", "stpapi.put.field(" & Chr(34) & sesion_baan & Chr(34) & "," & Chr(34) & "tdinv100.idat" & Chr(34) & "," & Chr(34) & str_HOY & Chr(34) & ")")


tipo_movimiento = "6" 'En el combo hay 6 elementos y aparece el último
baanobj.ParseExecFunction("ottstpapihand", "stpapi.put.field(" & Chr(34) & sesion_baan & Chr(34) & "," & Chr(34) & "tdinv100.kowt" & Chr(34) & "," & Chr(34) & tipo_movimiento & Chr(34) & ")")


'9.FECHA ORDEN
f_orden = l_HOY
baanobj.ParseExecFunction("ottstpapihand", "stpapi.put.field(" & Chr(34) & sesion_baan & Chr(34) & "," & Chr(34) & "tdinv100.odat" & Chr(34) & "," & Chr(34) & CStr(f_orden) & Chr(34) & ")")


'12.CANTIDAD ENTREGADA
baanobj.ParseExecFunction("ottstpapihand", "stpapi.put.field(" & Chr(34) & sesion_baan & Chr(34) & "," & Chr(34) & "tdinv100.dqan" & Chr(34) & "," & Chr(34) & cantidad_entregada & Chr(34) & ")")

'13.ALMACEN DESTINO
almacen_destino = "012"
baanobj.ParseExecFunction("ottstpapihand", "stpapi.put.field(" & Chr(34) & sesion_baan & Chr(34) & "," & Chr(34) & "tdinv100.dwar" & Chr(34) & "," & Chr(34) & almacen_destino & Chr(34) & ")")


'15.ESTADO DE LA TRANSACCION
'estado_transaccion = "Activo" 'por defecto "Activo"
estado_transaccion = "1" 'Hay 2 elementos en este combo siendo el que aparece por def. el primero"
baanobj.ParseExecFunction("ottstpapihand", "stpapi.put.field(" & Chr(34) & sesion_baan & Chr(34) & "," & Chr(34) & "tdinv100.wtst" & Chr(34) & "," & Chr(34) & estado_transaccion & Chr(34) & ")")

'17.FECHA MOVIMIENTO
f_movimiento = l_HOY
baanobj.ParseExecFunction("ottstpapihand", "stpapi.put.field(" & Chr(34) & sesion_baan & Chr(34) & "," & Chr(34) & "tdinv100.trdt" & Chr(34) & "," & Chr(34) & CStr(f_movimiento) & Chr(34) & ")")

'=======================================================================================================================================================
'=======================================================================================================================================================
'>>>>>>>>>>>> Todos los campos ya tienen su valor >>>>>>>>>>
Dim errorea As String

'Ahora, mandamos estos valores al ERP para que los modifique
baanobj.ParseExecFunction("ottstpapihand", "stpapi.insert(" & Chr(34) & sesion_baan & Chr(34) & "," & save & "," & Chr(34) & errorea & Chr(34) & ")")


baanobj.ParseExecFunction("ottstpapihand", "stpapi.end.session(" & Chr(34) & sesion_baan & Chr(34) & ")")
baanobj.Quit()
baanobj = Nothing
MsgBox("Operación realizada!")
Return

If baanobj.ReturnValue <> 1 Then
errorea = baanobj.ParseExecFunction("ottstpapihand", "stpapi.recover(" & Chr(34) & sesion_baan & Chr(34) & "," & Chr(34) & errorea & Chr(34) & ")")
End If
MsgBox("resultado_update: " & resultado_update & "Error es: " & errorea)

'Finalizamos la sesión (automática)
baanobj.ParseExecFunction("ottstpapihand", "stpapi.end.session(" & Chr(34) & sesion_baan & Chr(34) & ")")

'Liberamos recursos
baanobj.Quit()
baanobj = Nothing
MsgBox("Operación realizada!")