Tuesday, June 24, 2014

How to change Purchase Order from 'Closed' status to 'Open'

Sometimes our clients need to open a closed Purchase Order document in SAP B1
       
In order to achieve this we make changes:
1. At row level  LineStatus to open(POR1) and
 2.At header level DocStatus to open(OPOR)

 The following vb.net code shows it


Dim rs As SAPbobsCOM.Recordset = sCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)Dim PODocNum As String = XXXXDim str As String = 

           "UPDATE T0 " & _
           "SET T0.LineStatus = 'O' , " & _
           "    T0.TargetType='-1' " & _
           "FROM DBO.POR1 T0 " & _
           "INNER JOIN DBO.OPOR T1 " & _ 
           "ON T0.DocEntry=T1.DocEntry " & _
           "WHERE T1.DocNum = '" & PODocNum & "'"
 rs.DoQuery(str)
 str = Nothingstr = "UPDATE T0 " & _
      "SET T0.DocStatus = 'O' " & _
      "FROM DBO.OPOR T0 " & _
      "WHERE T0.DocNum = '" + PODocNum.ToString + "'" 
rs.DoQuery(str)