← Back to API List

Defect Stock-In Create

POST MES → ERP
wo.scrap.data.create

When there is defect quantity during work order checkout, send the defect stock-in data to ERP to create a scrap stock-in order. After ERP returns the stock-in order number, MES writes it back to SFT_TRANSORDER_LINE.

Basic Information

API Name
wo.scrap.data.create
Internal Task Name
woScrapDataCreate
Transport Format
JSON (Content-Type: application/json)
Case Number
0189144
API ID
api-2191
TRANSORDERTYPE
58 (Scrap Stock-In)

Trigger Timing

Checkout CheckOut Enter defect qty SCRAPQTY > 0 ? Yes Create Scrap Transfer TRANSORDERTYPE=58 SftTransorderLine Send to ERP wo.scrap.data .create Write Back No. TL011/TL012 No → Skip defect stock-in
Key Condition: Only when SCRAPQTY > 0 (defect quantity greater than zero) during checkout, the system will create a transfer order with TRANSORDERTYPE=58 and call the ERP defect stock-in API.
Trigger Location
After checkout is completed, the TransOrderDataToJson.sentTransOrderDataAgain() method determines the transfer order type; if it's scrap stock-in, it calls woScrapDataCreate.

Request Parameters

HEAD Header Data

Field MES Source ERP Field Type Required Description
Doc Type No. transferType doc_type_no String Required Defect stock-in document type
Transfer No. eMESTransferType-eMESTransferCode source_no String Required MES transfer number (type-number)
Create Date date create_date Date Required Stock-in date (yyyy-MM-dd)
Checkout Workstation moveOutCode workstation_no String Required Checkout workstation code
Factory Code factoryCode factory_no String Required Factory code
Operator create operator_no String Optional Operator
Remark remark remark String Optional Header remark

LINE Line Items

Field MES Source ERP Field Type Required Description
Work Order No. moType-moCode wo_no String Required Work order type-number
Item Code prodCode item_no String Required Product item code
Defect Quantity SCRAPQTY scrap_qty Numeric Required Scrap quantity
Unit unit unit_no String Required Unit of measure
Stock-In Warehouse moveInCode warehouse_no String Required Stock-in warehouse code
Location moveInLocation location_no String Optional Stock-in location
Lot No. batchCode lot_no String Optional Lot number
Remark remark remark String Optional Line remark

Request Example

MES Internal JSON Format

{
  "head": {
    "transferType": "58",
    "eMESTransferType": "SC",
    "eMESTransferCode": "20260319001",
    "date": "2026-03-19",
    "moveOutCode": "WS001",
    "factoryCode": "FACTORY01",
    "create": "USER001",
    "remark": "Defect stock-in"
  },
  "line": [
    {
      "moType": "5101",
      "moCode": "20260319001",
      "prodCode": "ITEM-001",
      "qty": "5",
      "unit": "PCS",
      "moveInCode": "WH-SCRAP",
      "moveInLocation": "A01",
      "batchCode": "BAT001",
      "remark": "Surface defect"
    }
  ]
}

ERP XML Format (WFERP) - SendFormS.java:1773-1804

<parameters>
  <parameter key="enterprise_no" type="string">Company Code</parameter>
  <parameter key="site_no" type="string">Site Code</parameter>

  <parameter key="wo_scrap_data" type="data">
    <data name="wo_scrap">
      <row seq="1">
        <!-- ======== Head ======== -->
        <field name="doc_type_no" type="string">58</field>
        <field name="source_no" type="string">SC-20260319001</field>
        <field name="create_date" type="date">2026-03-19</field>
        <field name="remark" type="string">Defect stock-in</field>
        <field name="workstation_no" type="string">WS001</field>
        <field name="factory_no" type="string">FACTORY01</field>
        <field name="shift_no" type="string"></field>
        <field name="operator_no" type="string">USER001</field>

        <!-- ======== Line ======== -->
        <detail name="wo_scrap_detail">
          <row>
            <field name="seq" type="string"></field>
            <field name="wo_no" type="string">5101-20260319001</field>
            <field name="item_no" type="string">ITEM-001</field>
            <field name="scrap_qty" type="numeric">5</field>
            <field name="unit_no" type="string">PCS</field>
            <field name="remark" type="string">Surface defect</field>
            <field name="machine_no" type="string"></field>
            <field name="warehouse_no" type="string">WH-SCRAP</field>
            <field name="location_no" type="string">A01</field>
            <field name="lot_no" type="string">BAT001</field>
            <field name="damage_qty" type="numeric"></field>
            <field name="stock_in_status" type="string"></field>
          </row>
        </detail>
      </row>
    </data>
  </parameter>
</parameters>

Response Format

Success Response (code=200)

{
  "code": 200,
  "msg": "Defect stock-in order created successfully",
  "ERPMessage": {
    "description": "Processing successful",
    "doc_no": "58-20260319001"
  }
}

Failure Response (code=500)

{
  "code": 500,
  "msg": "Defect stock-in order creation failed",
  "ERPMessage": {
    "description": "Warehouse code does not exist"
  }
}

Response Field Description

Field Type Description
code Integer 200=Success, 500=Failure
msg String Processing message
ERPMessage.doc_no String Defect stock-in order number returned by ERP (type-number)

ERP Write Back Logic

After ERP returns the defect stock-in order number, MES writes it back to the transfer order line:

ERP Response doc_no 58-20260319001 Parse Number TL011=58 TL012=20260319001 SFT_TRANSORDER_LINE TL011 = 58 TL012 = 20260319001 TRANSORDERTYPE = 58

Write Back SQL

-- Update SFT_TRANSORDER_LINE
UPDATE SFT_TRANSORDER_LINE
SET TL011 = '58',
    TL012 = '20260319001'
WHERE TRANSORDERTYPE = '58'
  AND TRANSNO = :TRANSNO
  AND SN = :SN

Related Tables

Table Description Key Fields
SftTransorder Transfer Order Header TRANSTYPE, TRANSNO, TO007, TO008, TO013
SftTransorderLine Transfer Order Line TRANSORDERTYPE(=58), SCRAPQTY, TL011, TL012
SFT_WS_RUN Workstation Execution Record Checkout record, defect quantity source
TRANSORDERTYPE Type Reference
58Scrap Stock-In (Defect Stock-In)
59Outsourcing Stock-In
OtherGeneral Transfer Order

Code Location

Function File Path Line/Method
Calculate Defect Qty on Checkout SFT_core/src/com/dci/sft/update/CheckOut.java doCheckOut()
Transfer Order Creation SFT_core/src/com/dci/sft/jsonMappingHibernate/TransOrderDataToJson.java 595-900
API Route Decision SFT_ERPIntegrate/src/com/dci/sft/erp/XmlToERP_handler.java 94-98
XML Parameter Assembly SFT_ERPIntegrate/src/com/dci/sft/erp/webservice/SendFormS.java 1752-1810

Error Handling

Error Scenario Cause Resolution
Warehouse code does not exist No such warehouse in ERP Confirm defect warehouse is created in ERP
Item code does not exist No such item in ERP Confirm item is synced to ERP
Connection timeout SocketTimeoutException Check ERP server status, manual resend required

LOG Record

// Log file: logs/ERPReturnErrorRec.log

[ERP_SEND_ERROR] taskName=woScrapDataCreate, errorType=SocketTimeoutException, errorMsg=Read timed out
[ERP_SEND_ERROR] Content sent={...JSON...}