Scrap(Int32,String,String,String,String,String,Nullable<Double>,Nullable<Double>,String,String,String,Nullable<DateTime>,String,String,Nullable<Int32>,String) Method
- Last UpdatedNov 06, 2025
- 6 minute read
The Scrap() method scraps a quantity of item inventory at a storage location.
This overload of the method specifies the storage entity using the entity name and, optionally, the entity site name. It also specifies the item's grade, status, and unit of measure using their descriptions.
'Declaration
Public Overloads Shared Sub Scrap( _
ByVal sessionId As Integer, _
ByVal entName As String, _
ByVal siteName As String, _
ByVal itemId As String, _
ByVal lotNo As String, _
ByVal sublotNo As String, _
ByVal qtyToScrap As Nullable(Of Double), _
ByVal qtyToScrapErp As Nullable(Of Double), _
ByVal scrapUomDesc As String, _
ByVal itemGradeDesc As String, _
ByVal itemStatusDesc As String, _
ByVal dateOutUtc As Nullable(Of Date), _
ByVal woId As String, _
ByVal operId As String, _
ByVal seqNo As Nullable(Of Integer), _
ByVal transferComments As String _
)
'Usage
Dim sessionId As Integer
Dim entName As String
Dim siteName As String
Dim itemId As String
Dim lotNo As String
Dim sublotNo As String
Dim qtyToScrap As Nullable(Of Double)
Dim qtyToScrapErp As Nullable(Of Double)
Dim scrapUomDesc As String
Dim itemGradeDesc As String
Dim itemStatusDesc As String
Dim dateOutUtc As Nullable(Of Date)
Dim woId As String
Dim operId As String
Dim seqNo As Nullable(Of Integer)
Dim transferComments As String
StorageExec.Scrap(sessionId, entName, siteName, itemId, lotNo, sublotNo, qtyToScrap, qtyToScrapErp, scrapUomDesc, itemGradeDesc, itemStatusDesc, dateOutUtc, woId, operId, seqNo, transferComments)
public static void Scrap(
int sessionId,
string entName,
string siteName,
string itemId,
string lotNo,
string sublotNo,
Nullable<double> qtyToScrap,
Nullable<double> qtyToScrapErp,
string scrapUomDesc,
string itemGradeDesc,
string itemStatusDesc,
Nullable<DateTime> dateOutUtc,
string woId,
string operId,
Nullable<int> seqNo,
string transferComments
)
Parameters
- sessionId
- Required. Holds the session ID and thus the user who is making this method call.
- entName
- Required. Holds the name of the storage entity where the quantity is being scrapped from the inventory.
- siteName
- Optional. Holds the site name for this entity.
- itemId
- Optional. Holds the ID of the item.
- lotNo
- Optional. Holds the lot number.
- sublotNo
- Optional. Holds the sublot number.
- qtyToScrap
- Optional. Holds the quantity to be scrapped. The scrap quantity cannot be less than 0. If the value is null or 0, then the full quantity of all inventory records that match the input parameters will be scrapped.
- qtyToScrapErp
- Optional. Holds the quantity to be scrapped that has been reported to an ERP system.
- scrapUomDesc
- Optional. Holds the description of the unit of measure for the quantity to be scrapped. For more information about how this supplied unit of measure is used, see the Remarks below.
- itemGradeDesc
- Optional. If the Log inventory transfers system parameter is set to true, holds the grade description of the item grade to be recorded for the scrapped items in the Item_Transfer record created by this Scrap call.
- itemStatusDesc
- Optional. If the Log inventory transfers system parameter is set to true, holds the state description of the item state to be recorded for the scrapped items in the Item_Transfer record created by this Scrap call.
- dateOutUtc
- Optional. Holds the date and time when this quantity was removed from the storage entity, in UTC.
- woId
- Optional. Holds the ID of the work order that is associated with the scrapped inventory.
- operId
- Optional. Holds the ID of the operation that is associated with the scrapped inventory.
- seqNo
- Optional. Holds the operation sequence number of the job that is associated with the scrapped inventory.
- transferComments
- Optional. Holds comments about the scrapped inventory. The method automatically adds the text "Scrap:" at the beginning of the comment text string.
Observe the following input parameter rules:
- Required non-DB* parameters: Must pass a value. Cannot be empty or null.
- Optional non-DB* parameters: Either enter a value or pass a null. If passing a null and a default value has been defined, the default value will be used for the parameter.
This method first attempts to find an inventory record of the specified entity that also matches the following optional input parameters that act as a filter: itemId, lotNo, sublotNo, woId, operId, seqNo. If such an inventory record exists, then its quantity left value is reduced by the scrapped quantity. If that inventory record's entire quantity is scrapped and there is still remaining quantity to be scrapped, then it is scrapped from the next matching inventory record, and so on.
When updating the inventory records, the qty_left, qty_left_erp, date_out_utc, and date_out_local columns are updated. The values in the remaining columns are retained as they are.
If Inventory Quantity Left Will Be 0 or Negative
If the inventory quantity will be reduced to 0 or less:
- If the storage entity allows the inventory records to be deleted when the quantity reaches 0 (storage_exec.auto_del_zero_inv), then the inventory row is deleted.
- If the storage entity does not allow inventory records to be deleted when the quantity reaches 0 and negative quantities are allowed (storage_exec.allow_neg_qty), the inventory record's quantity will be the resulting negative value.
- If the storage entity does not allow inventory records to be deleted when the quantity reaches 0 and negative quantities are not allowed, then an exception is thrown to the caller.
How Inventory Quantity Left Affects Entity Storage Status
If after scrapping the specified quantity the sum of all inventory record quantities left for the storage entity will be greater than 0, then the storage status for the entity will be set to Used.
If the sum of all quantities left for the storage location will be 0 or less, then:
- If the storage entity is configured to allow the Dirty state, then the storage status for this entity will be set to Dirty.
- If the storage entity does not allow the Dirty state, then the storage status for this entity will be set to Available.
How Scrapped Inventory Unit of Measure Is Handled
If a unit of measure is supplied in the call, then the quantity to be scrapped has a specific unit of measure.
- If the inventory record includes a specific unit of measure and it is different than the one supplied in the Scrap call, then the quantity to be scrapped is converted to the inventory record's unit of measure. For example, say the inventory record's unit of measure is gallons and the unit of measure passed by the Scrap call is liters. If the quantity to be scrapped is 3.78 liters, this is converted to a scrapped quantity of 1 gallon. If the current quantity is 25 gallons, the quantity left in the inventory record after the Scrap call will be 24. The corresponding record in the Item_Transfer table will have a quantity of -1 transferred. If a conversion between liters to gallons does not exist, an exception is thrown.
- If the inventory record does not include a unit of measure, then the supplied quantity in the Scrap call is converted to the item's native unit of measure if their units of measure don't match.
- If the Scrap call does not include a specific unit of measure and the inventory record does, then the quantity to be scrapped is assumed to be in the unit of measure specified in the inventory record. Otherwise, it's assumed to be in the item's native unit of measure.
Logging the Scrapped Inventory as an Inventory Transfer
If the Log inventory transfers system parameter is set to true:
- A record is created in the Item_Transfer table identifying the scrapped inventory as an inventory transfer transaction.
- If provided in the Scrap call, the item grade and state for the scrapped items are included in the Item_Transfer record.
- Any supplied transfer comments will be prefixed with "Scrap:", indicating that the item transfer record was created from a scrap transaction. If no transfer comments are supplied, then the transfer_comments column will simply contain the text "Scrap:".
Conditions for a Successful Scrap Inventory Call
For the Scrap inventory call to succeed, all of the following conditions must be true:
- An inventory record that matches the specified entity and any supplied filter parameters (itemId, lotNo, sublotNo, woId, operId, seqNo) exists.
- The specified entity is capable of storing inventory items (ent.can_store is turned on).
- The quantity to scrap is not less than 0.
- If the entity is not configured to support negative inventory quantities (storage_exec.allow_neg_qty), the remaining inventory quantity after being reduced by the scrapped inventory is not less than 0.
- The entity is not currently in the Dirty state.
- The specified storage entity and if a scrap unit of measure, item grade, or item status are supplied, they must already exist in the database.