Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' ProcessData Function
- '
- Function Run_VB_Script_Function()
- Dim oCmpSrv
- Dim oPickList
- Dim oPickListLines
- Dim lRet
- Dim lErrCode
- Dim sErrMsg
- Dim errCode
- Dim errDesc
- Dim transstate
- Dim i
- Dim j
- Dim k
- Dim l
- Dim Aux
- Dim Cn
- On Error Resume Next
- If CStr(ThisStep.RowsProcessed)="0" Then
- 'Setup connection To SBO
- Set oCmpSrv = CreateObject("SAPbobsCOM.Company")
- oCmpSrv.Server = "192.168.21.252:30015"
- oCmpSrv.CompanyDB = "SBOFFSCRM"
- oCmpSrv.UserName = "manager"
- oCmpSrv.Password = "reganam"
- oCmpSrv.Language = 3
- oCmpSrv.UseTrusted = False
- oCmpSrv.DbServerType = 9
- oCmpSrv.DbUserName = "SYSTEM"
- oCmpSrv.DbPassword = "FFf0r3v3r"
- oCmpSrv.LicenseServer = "192.168.21.252:40000"
- lRet = oCmpSrv.Connect
- If lRet <> 0 Then
- lErrCode = oCmpSrv.GetLastErrorCode
- sErrMsg = oCmpSrv.GetLastErrorDescription
- ThisStep.LogError sErrMsg
- 'Throw exception
- Err.Raise CLng(lErrCode), CStr(sErrMsg)
- Else
- Variables("sboCompany") = oCmpSrv
- End If
- ThisStep.LogInfo "STEP 0 - DATABASE CONNECTED "
- Else
- oCmpSrv = Variables("sboCompany")
- oPickList = Variables("picklistObject")
- oPickListLines = Variables("oPickListLines")
- End If
- If Not CInt(Variables("LastDocentry")) = CInt(ThisStep.RecordSource("Id")) Then
- Variables("LastDocentry") = CInt(ThisStep.RecordSource("Id"))
- Variables("DifLinenum") = CInt(ThisStep.RecordSource("LineNum"))
- Variables("currentBinCode")=""
- Variables("TotalLinesUsed") = 0
- oCmpSrv.StartTransaction()
- Set oPickList = oCmpSrv.GetBusinessObject(156)
- oPickListLines = ""
- oPickList.Remarks = ThisStep.RecordSource("Remarks")
- oPickList.PickDate = ThisStep.RecordSource("CurrentDate")
- oPickList.UserFields.Fields.Item("U_CBTC").Value = "Y"
- If Len(ThisStep.RecordSource("PickerName"))>0 Then
- oPickList.Name=ThisStep.RecordSource("PickerName")
- Else
- oPickList.Name=System.Variables("Default_Picker_U_NAME")
- End If
- If CStr(ThisStep.RecordSource("PickerCode"))<>CStr("-1") Then
- oPickList.OwnerCode=ThisStep.RecordSource("PickerCode")
- Else
- oPickList.OwnerCode=System.Variables("Default_Picker_USERID")
- End If
- End If
- lRet = 0
- If CInt(ThisStep.RecordSource("RowNum")) > 0 Then
- If Not CInt(Variables("DifLinenum")) = CInt(ThisStep.RecordSource("LineNum")) Then
- oPickList.Lines.Add()
- ThisStep.LogInfo "Line added to picklist"
- lRet = 1
- End If
- Else
- lRet = 1
- End If
- Variables("TotalLinesUsed") = Variables("TotalLinesUsed") + 1
- If lRet = 1 Then
- oPickList.Lines.SetCurrentLine(oPickList.Lines.Count-1)
- oPickList.Lines.BaseObjectType = ThisStep.RecordSource("ObjType")
- oPickList.Lines.OrderEntry = ThisStep.RecordSource("DocEntry")
- oPickList.Lines.OrderRowID = ThisStep.RecordSource("LineNum")
- oPickList.Lines.ReleasedQuantity = ThisStep.RecordSource("Quantity")
- End If
- '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
- oPickListLines = oPickListLines & CStr(oPickList.Lines.Count - 1) & "#" & CStr(ThisStep.RecordSource("bincode")) & "#" & CStr(ThisStep.RecordSource("BinPicked")) & ";"
- If CInt(ThisStep.RecordSource("TotalLines")) = CInt(Variables("TotalLinesUsed")) Then
- ThisStep.LogInfo "Final Bin Quantities: " & oPickListLines
- 'In SAP to create a pick list we do need to execute the 'ADD' method and after that the 'UpdateReleasedAllocation'
- On Error Resume Next
- retVal = oPickList.Add()
- If retVal <> 0 Then
- errDesc =oCmpSrv.GetLastErrorDescription
- ThisStep.LogInfo "PICKLIST ADD ERROR " & errDesc & ". DocEntry " & CStr(ThisStep.RecordSource("DocEntry"))
- oCmpSrv.EndTransaction(1)
- Set Cn = CreateObject("ADODB.Connection")
- Cn.Open "Provider=SQLOLEDB.1;Server=BEIGE\MSSQLSERVERR2;Database=SAPHANA;User Id=sa;Password=logix2020"
- Cn.Execute = "exec UpdateInsertEmails 0,"& ThisStep.RecordSource("DocEntry") & ",'" & errDesc & "'"
- Cn.Close()
- Else
- oPickListLines = Left(oPickListLines,Len(oPickListLines)-1)
- Set oPickList = oCmpSrv.GetBusinessObject(156)
- oPickList.GetByKey(oCmpSrv.GetNewObjectKey())
- i = Split(oPickListLines ,";")
- For Each j in i
- k = Split(CStr(j) ,"#")
- Aux = 0
- For Each l in k
- Select Case Aux
- Case 0
- oPickList.Lines.SetCurrentLine(CInt(l))
- If Not oPickList.Lines.BinAllocations.BinAbsEntry = 0 Then
- oPickList.Lines.BinAllocations.Add()
- ThisStep.LogInfo "BIN ADDED"
- End If
- oPickList.Lines.BinAllocations.SetCurrentLine(oPickList.Lines.BinAllocations.Count-1)
- Case 1
- oPickList.Lines.BinAllocations.BinAbsEntry = CInt(l)
- oPickList.Lines.BinAllocations.SerialAndBatchNumbersBaseLine = -1
- Case 2
- oPickList.Lines.BinAllocations.Quantity = l
- End Select
- Aux = Aux + 1
- Next
- Next
- On Error Resume Next
- retVal = oPickList.UpdateReleasedAllocation()
- Set Cn = CreateObject("ADODB.Connection")
- Cn.Open "Provider=SQLOLEDB.1;Server=BEIGE\MSSQLSERVERR2;Database=SAPHANATEST;User Id=sa;Password=logix2020"
- If retVal <> 0 Then
- errDesc =oCmpSrv.GetLastErrorDescription
- ThisStep.LogInfo "PICKLIST UPDATE ERROR " & errDesc & ". DocEntry " & CStr(ThisStep.RecordSource("DocEntry"))
- oCmpSrv.EndTransaction(1)
- Cn.Execute = "exec UpdateInsertEmails 0,"& ThisStep.RecordSource("DocEntry") & ",'" & errDesc & "'"
- Else
- Dim Counter
- Dim AnywithDecimal
- AnywithDecimal=False
- Dim LineInfo
- For Counter=0 To oPickList.Lines.Count-1
- oPickList.Lines.SetCurrentLine(Counter)
- ThisStep.LogInfo "CHECKING PICK LIST- DocEntry: " & ThisStep.RecordSource("DocEntry") & " LINE " & Counter
- ThisStep.LogInfo "CHECKING PICK LIST- DocEntry: " & ThisStep.RecordSource("DocEntry") & " LINE " & Counter & " For DECIMAL VALUES: Released Quantity(Stnd): " & oPickList.Lines.ReleasedQuantity
- ThisStep.LogInfo "CHECKING PICK LIST- DocEntry: " & ThisStep.RecordSource("DocEntry") & " LINE " & Counter & " FOR DECIMAL VALUES: Released Quantity(CInt): " & CInt(oPickList.Lines.ReleasedQuantity)
- If oPickList.Lines.ReleasedQuantity <> CInt(oPickList.Lines.ReleasedQuantity) Then
- AnywithDecimal = True
- LineInfo ="PICKLIST WITH DECIMAL VALUES. Line: " + CStr(oPickList.Lines.LineNumber)+ ". Released quantity: " + CStr(oPickList.Lines.ReleasedQuantity)
- ThisStep.LogInfo "CHECKING PICK LIST- DocEntry: " & ThisStep.RecordSource("DocEntry") & " LINE " & Counter & " - Decimal Found"
- End If
- Next
- ThisStep.LogInfo "PICKLIST ADDED AND UPDATED " & CStr(oCmpSrv.GetNewObjectKey())
- If AnywithDecimal Then
- ThisStep.LogInfo "ANYWITHDECIMAL - DocEntry: " & ThisStep.RecordSource("DocEntry") & ", LineInfo: " + LineInfo + "'"
- '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.
- Cn.Execute = "exec UpdateInsertEmailsDecimals 0," & ThisStep.RecordSource("DocEntry") & ",'" + LineInfo + "'"
- End If
- oCmpSrv.EndTransaction(0)
- End If
- Cn.Close()
- End If
- oPickListLines = ""
- Else
- ThisStep.LogInfo "Partial Bin Quantities: " & oPickListLines
- End If
- Variables("picklistObject") = oPickList
- Variables("oPickListLines") = oPickListLines
- Variables("DifLinenum") = ThisStep.RecordSource("LineNum")
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement