Advertisement
Guest User

Untitled

a guest
May 10th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.30 KB | None | 0 0
  1. ' ProcessData Function
  2. '
  3. Function Run_VB_Script_Function()
  4.  
  5. Dim oCmpSrv
  6. Dim oPickList
  7. Dim oPickListLines
  8. Dim lRet
  9. Dim lErrCode
  10. Dim sErrMsg
  11. Dim errCode
  12. Dim errDesc
  13. Dim transstate
  14. Dim i
  15. Dim j
  16. Dim k
  17. Dim l
  18. Dim Aux
  19. Dim Cn
  20.  
  21. On Error Resume Next
  22.  
  23. If CStr(ThisStep.RowsProcessed)="0" Then
  24. 'Setup connection To SBO
  25. Set oCmpSrv = CreateObject("SAPbobsCOM.Company")
  26. oCmpSrv.Server = "192.168.21.252:30015"
  27. oCmpSrv.CompanyDB = "SBOFFSCRM"
  28. oCmpSrv.UserName = "manager"
  29. oCmpSrv.Password = "reganam"
  30. oCmpSrv.Language = 3
  31. oCmpSrv.UseTrusted = False
  32. oCmpSrv.DbServerType = 9
  33. oCmpSrv.DbUserName = "SYSTEM"
  34. oCmpSrv.DbPassword = "FFf0r3v3r"
  35. oCmpSrv.LicenseServer = "192.168.21.252:40000"
  36.  
  37. lRet = oCmpSrv.Connect
  38. If lRet <> 0 Then
  39.  
  40. lErrCode = oCmpSrv.GetLastErrorCode
  41. sErrMsg = oCmpSrv.GetLastErrorDescription
  42.  
  43. ThisStep.LogError sErrMsg
  44.  
  45. 'Throw exception
  46. Err.Raise CLng(lErrCode), CStr(sErrMsg)
  47.  
  48. Else
  49. Variables("sboCompany") = oCmpSrv
  50. End If
  51.  
  52. ThisStep.LogInfo "STEP 0 - DATABASE CONNECTED "
  53. Else
  54. oCmpSrv = Variables("sboCompany")
  55. oPickList = Variables("picklistObject")
  56. oPickListLines = Variables("oPickListLines")
  57. End If
  58.  
  59. If Not CInt(Variables("LastDocentry")) = CInt(ThisStep.RecordSource("Id")) Then
  60. Variables("LastDocentry") = CInt(ThisStep.RecordSource("Id"))
  61. Variables("DifLinenum") = CInt(ThisStep.RecordSource("LineNum"))
  62. Variables("currentBinCode")=""
  63. Variables("TotalLinesUsed") = 0
  64.  
  65. oCmpSrv.StartTransaction()
  66.  
  67. Set oPickList = oCmpSrv.GetBusinessObject(156)
  68. oPickListLines = ""
  69.  
  70. oPickList.Remarks = ThisStep.RecordSource("Remarks")
  71. oPickList.PickDate = ThisStep.RecordSource("CurrentDate")
  72. oPickList.UserFields.Fields.Item("U_CBTC").Value = "Y"
  73.  
  74. If Len(ThisStep.RecordSource("PickerName"))>0 Then
  75. oPickList.Name=ThisStep.RecordSource("PickerName")
  76. Else
  77. oPickList.Name=System.Variables("Default_Picker_U_NAME")
  78. End If
  79. If CStr(ThisStep.RecordSource("PickerCode"))<>CStr("-1") Then
  80. oPickList.OwnerCode=ThisStep.RecordSource("PickerCode")
  81. Else
  82. oPickList.OwnerCode=System.Variables("Default_Picker_USERID")
  83. End If
  84.  
  85. End If
  86.  
  87. lRet = 0
  88. If CInt(ThisStep.RecordSource("RowNum")) > 0 Then
  89. If Not CInt(Variables("DifLinenum")) = CInt(ThisStep.RecordSource("LineNum")) Then
  90. oPickList.Lines.Add()
  91. ThisStep.LogInfo "Line added to picklist"
  92. lRet = 1
  93. End If
  94. Else
  95. lRet = 1
  96. End If
  97.  
  98. Variables("TotalLinesUsed") = Variables("TotalLinesUsed") + 1
  99.  
  100. If lRet = 1 Then
  101. oPickList.Lines.SetCurrentLine(oPickList.Lines.Count-1)
  102. oPickList.Lines.BaseObjectType = ThisStep.RecordSource("ObjType")
  103. oPickList.Lines.OrderEntry = ThisStep.RecordSource("DocEntry")
  104. oPickList.Lines.OrderRowID = ThisStep.RecordSource("LineNum")
  105. oPickList.Lines.ReleasedQuantity = ThisStep.RecordSource("Quantity")
  106. End If
  107.  
  108. 'We do need to store each line information in a string. Finally, when it changes to another pick list or it is the last one that pick list will be created using a sap transaction
  109. oPickListLines = oPickListLines & CStr(oPickList.Lines.Count - 1) & "#" & CStr(ThisStep.RecordSource("bincode")) & "#" & CStr(ThisStep.RecordSource("BinPicked")) & ";"
  110.  
  111. If CInt(ThisStep.RecordSource("TotalLines")) = CInt(Variables("TotalLinesUsed")) Then
  112.  
  113. ThisStep.LogInfo "Final Bin Quantities: " & oPickListLines
  114.  
  115. 'In SAP to create a pick list we do need to execute the 'ADD' method and after that the 'UpdateReleasedAllocation'
  116. On Error Resume Next
  117. retVal = oPickList.Add()
  118.  
  119. If retVal <> 0 Then
  120.  
  121. errDesc =oCmpSrv.GetLastErrorDescription
  122. ThisStep.LogInfo "PICKLIST ADD ERROR " & errDesc & ". DocEntry " & CStr(ThisStep.RecordSource("DocEntry"))
  123. oCmpSrv.EndTransaction(1)
  124.  
  125. Set Cn = CreateObject("ADODB.Connection")
  126. Cn.Open "Provider=SQLOLEDB.1;Server=BEIGE\MSSQLSERVERR2;Database=SAPHANA;User Id=sa;Password=logix2020"
  127. Cn.Execute = "exec UpdateInsertEmails 0,"& ThisStep.RecordSource("DocEntry") & ",'" & errDesc & "'"
  128. Cn.Close()
  129.  
  130. Else
  131.  
  132. oPickListLines = Left(oPickListLines,Len(oPickListLines)-1)
  133.  
  134. Set oPickList = oCmpSrv.GetBusinessObject(156)
  135. oPickList.GetByKey(oCmpSrv.GetNewObjectKey())
  136.  
  137. i = Split(oPickListLines ,";")
  138. For Each j in i
  139. k = Split(CStr(j) ,"#")
  140. Aux = 0
  141. For Each l in k
  142. Select Case Aux
  143. Case 0
  144. oPickList.Lines.SetCurrentLine(CInt(l))
  145. If Not oPickList.Lines.BinAllocations.BinAbsEntry = 0 Then
  146. oPickList.Lines.BinAllocations.Add()
  147. ThisStep.LogInfo "BIN ADDED"
  148. End If
  149. oPickList.Lines.BinAllocations.SetCurrentLine(oPickList.Lines.BinAllocations.Count-1)
  150. Case 1
  151. oPickList.Lines.BinAllocations.BinAbsEntry = CInt(l)
  152. oPickList.Lines.BinAllocations.SerialAndBatchNumbersBaseLine = -1
  153. Case 2
  154. oPickList.Lines.BinAllocations.Quantity = l
  155. End Select
  156. Aux = Aux + 1
  157. Next
  158. Next
  159. On Error Resume Next
  160. retVal = oPickList.UpdateReleasedAllocation()
  161.  
  162. Set Cn = CreateObject("ADODB.Connection")
  163. Cn.Open "Provider=SQLOLEDB.1;Server=BEIGE\MSSQLSERVERR2;Database=SAPHANATEST;User Id=sa;Password=logix2020"
  164.  
  165. If retVal <> 0 Then
  166. errDesc =oCmpSrv.GetLastErrorDescription
  167. ThisStep.LogInfo "PICKLIST UPDATE ERROR " & errDesc & ". DocEntry " & CStr(ThisStep.RecordSource("DocEntry"))
  168. oCmpSrv.EndTransaction(1)
  169. Cn.Execute = "exec UpdateInsertEmails 0,"& ThisStep.RecordSource("DocEntry") & ",'" & errDesc & "'"
  170. Else
  171.  
  172. Dim Counter
  173. Dim AnywithDecimal
  174. AnywithDecimal=False
  175. Dim LineInfo
  176.  
  177. For Counter=0 To oPickList.Lines.Count-1
  178. oPickList.Lines.SetCurrentLine(Counter)
  179. ThisStep.LogInfo "CHECKING PICK LIST- DocEntry: " & ThisStep.RecordSource("DocEntry") & " LINE " & Counter
  180. ThisStep.LogInfo "CHECKING PICK LIST- DocEntry: " & ThisStep.RecordSource("DocEntry") & " LINE " & Counter & " For DECIMAL VALUES: Released Quantity(Stnd): " & oPickList.Lines.ReleasedQuantity
  181. ThisStep.LogInfo "CHECKING PICK LIST- DocEntry: " & ThisStep.RecordSource("DocEntry") & " LINE " & Counter & " FOR DECIMAL VALUES: Released Quantity(CInt): " & CInt(oPickList.Lines.ReleasedQuantity)
  182. If oPickList.Lines.ReleasedQuantity <> CInt(oPickList.Lines.ReleasedQuantity) Then
  183. AnywithDecimal = True
  184. LineInfo ="PICKLIST WITH DECIMAL VALUES. Line: " + CStr(oPickList.Lines.LineNumber)+ ". Released quantity: " + CStr(oPickList.Lines.ReleasedQuantity)
  185. ThisStep.LogInfo "CHECKING PICK LIST- DocEntry: " & ThisStep.RecordSource("DocEntry") & " LINE " & Counter & " - Decimal Found"
  186. End If
  187. Next
  188.  
  189. ThisStep.LogInfo "PICKLIST ADDED AND UPDATED " & CStr(oCmpSrv.GetNewObjectKey())
  190.  
  191. If AnywithDecimal Then
  192. ThisStep.LogInfo "ANYWITHDECIMAL - DocEntry: " & ThisStep.RecordSource("DocEntry") & ", LineInfo: " + LineInfo + "'"
  193. 'Uncomment this line to insert the info in the error table when there is a decimal value. But allowing the pick list to be created.
  194. Cn.Execute = "exec UpdateInsertEmailsDecimals 0," & ThisStep.RecordSource("DocEntry") & ",'" + LineInfo + "'"
  195. End If
  196.  
  197. oCmpSrv.EndTransaction(0)
  198.  
  199. End If
  200.  
  201. Cn.Close()
  202.  
  203. End If
  204.  
  205. oPickListLines = ""
  206.  
  207. Else
  208. ThisStep.LogInfo "Partial Bin Quantities: " & oPickListLines
  209. End If
  210.  
  211. Variables("picklistObject") = oPickList
  212. Variables("oPickListLines") = oPickListLines
  213. Variables("DifLinenum") = ThisStep.RecordSource("LineNum")
  214.  
  215. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement