← Back to API List

Defective Stock-In Cancel

CANCEL MES → ERP
wo.scrap.data.process

When MES cancels check-out and the transfer order is scrap stock-in type (TRANSORDERTYPE=58), call this API to notify ERP to cancel the corresponding defective stock-in document.

Basic Information

API Name
wo.scrap.data.process
Internal Task Name
woScrapDataProcess
Format
JSON (Content-Type: application/json)
Case Number
0189144
API Number
api-2192
TRANSORDERTYPE
58 (Scrap Stock-In)

Trigger Timing

Cancel Check-out CancelCheckOut User Action Query Transfer Type TRANSORDERTYPE SFT_TRANSORDER_LINE TYPE = 58? Yes woScrapDataProcess Cancel Scrap Stock-In doc_no = TL011-TL012 =59 → outsourcingProcess Other → cancelStockIn

Cancel API Decision Logic

When cancelling check-out, system determines which cancel API to call based on SFT_TRANSORDER_LINE.TRANSORDERTYPE:

TRANSORDERTYPE Document Type API Called Task Name
58 Scrap Stock-In (Defective) wo.scrap.data.process woScrapDataProcess
59 Outsourcing Stock-In outsourcing.process outsourcingProcess
Other General Stock-In stockin.data.process cancelStockIn
Code Location
Decision logic is in GeneralUpdater.excuteDeleteErpTransOrders() method, lines 1577-1592.

Request Parameters

Field ERP Field Name Type Required Description
Company Code enterprise_no String Required Enterprise code
Site Code site_no String Required Factory/site code
Scrap Document No doc_no String Required Stock-in document to cancel (format: TL011-TL012)
Document Number Format
Document number format is TL011-TL012, e.g.: 58-20260319001. This value comes from doc_no returned by ERP when creating scrap stock-in, stored in SFT_TRANSORDER_LINE.

Request Example

JSON Format

{
  "enterprise_no": "COMP01",
  "site_no": "SITE01",
  "doc_no": "58-20260319001"
}

ERP XML Format (WFERP)

<parameters>
  <parameter key="enterprise_no" type="string">COMP01</parameter>
  <parameter key="site_no" type="string">SITE01</parameter>
  <parameter key="doc_no" type="string">58-20260319001</parameter>
</parameters>

Response Format

Success Response (code=200)

{
  "code": 200,
  "msg": "Scrap stock-in cancelled successfully",
  "ERPMessage": {
    "description": "Process successful",
    "doc_no": "58-20260319001"
  }
}

Failure Response (code=500)

{
  "code": 500,
  "msg": "Scrap stock-in cancel failed",
  "ERPMessage": {
    "description": "Stock-in already confirmed, cannot cancel"
  }
}

Response Field Description

Field Type Description
code Integer 200=Success, 500=Failure
msg String Processing message
ERPMessage.description String Detailed message from ERP

MES Clear Logic

After successful scrap stock-in cancellation, MES will clear related transfer order records:

Clear SQL

-- Clear SFT_TRANSORDER_LINE ERP document numbers
UPDATE SFT_TRANSORDER_LINE
SET TL011 = '',
    TL012 = ''
WHERE TRANSORDERTYPE = '58'
  AND TL011 = :TL011
  AND TL012 = :TL012

-- Or delete entire transfer order record (depends on system settings)
DELETE FROM SFT_TRANSORDER_LINE
WHERE TRANSORDERTYPE = '58'
  AND TRANSNO = :TRANSNO

Race Condition Risk

Important Notice
Like other cancel APIs, cancel scrap stock-in also has Race Condition risk:

Scenario: Cancel immediately after check-out, but ERP has not yet returned scrap stock-in document number
Result: TL011/TL012 is empty, cannot call ERP cancel
Consequence: MES has cancelled check-out, but ERP scrap stock-in document still exists

Decision Logic

// GeneralUpdater.java:1571-1575
if(!SftTransorderLine.getTl011().equals("") && !SftTransorderLine.getTl012().equals("")){
    // Only call ERP cancel when TL011/TL012 has value
    String stock_in_no = SftTransorderLine.getTl011() + "-" + SftTransorderLine.getTl012();
    // Determine which API to call based on TRANSORDERTYPE
    ...
} else {
    // TL011/TL012 is empty, skip ERP call
}
Recommended Solutions
  1. Wait for ERP return success before allowing cancel after check-out
  2. Add Lock mechanism to prevent simultaneous operations
  3. Periodically compare MES and ERP scrap stock-in document status
  4. Provide manual supplementary cancel function

Related Database Tables

Table Description Affected Fields
SFT_TRANSORDER_LINE Transfer order details TL011, TL012 (clear or delete entire record)
SftTransorder Transfer order header TO007, TO008 (may need to clear)

Code Location

Function File Path Line Number
Cancel check-out entry SFT_core/src/com/dci/sft/update/GeneralUpdater.java 1550-1612
TRANSORDERTYPE decision SFT_core/src/com/dci/sft/update/GeneralUpdater.java 1577-1592
API routing SFT_ERPIntegrate/src/com/dci/sft/erp/XmlToERP_handler.java 96-98
XML parameter assembly SFT_ERPIntegrate/src/com/dci/sft/erp/webservice/SendFormS.java 1811-1815

Error Handling

Error Scenario ERP Response MES Handling
Stock-in already confirmed code=500, Stock-in confirmed Display error message, requires manual handling
Stock-in does not exist code=500, Stock-in not found Clear MES records, continue cancel flow
Connection timeout SocketTimeoutException Log error, requires manual supplementary cancel

LOG Record

// Log file: logs/ERPReturnErrorRec.log

[ERP_SEND_ERROR] taskName=woScrapDataProcess, errorType=SocketTimeoutException, errorMsg=Read timed out
[ERP_SEND_ERROR] Content sent={"doc_no":"58-20260319001"}