Work Order Update (Quantity/Date Adjustment)

wo.update
PUT JSON Sync ERP → MES

1. Basic Information

ItemDescription
API Chinese NameWork Order Update (Quantity/Date Adjustment)
API English NameWork Order Update
API Codewo.update
Case Number0189142
REST EndpointPOST /ESB/API/upModetail
Call DirectionERP → MES
Trigger TimingWhen ERP modifies order quantity or dates, sync to MES
Main Business ScenarioERP adjusts order quantity or schedule dates, sync update MES order and lot data
Request FormatJSON (Content-Type: application/json)
Sync/AsyncSynchronous call
Transaction ControlRequired
Call Direction Note
This API is ERP → MES one-way push.
OperationType = 2 indicates modify operation.

2. Business Flow

ERP System MES System 1. Modify Order (wo.update) 2. Qty Validation (WoUpdate) 3. Update Order (MODETAIL) 4. Adjust Lot (LOT) Complete Quantity Validation Logic newQTY vs (MOQTY - MODIQTY) Increase: Directly add LOTSIZE Decrease: Check changeable allowance Code Location: WoUpdate.java → RegularESB.upModetail():1243-1472
Code Reference
  • API Entry: WoUpdate.java:59-100
  • Qty Validation: RegularESB.java:1234-1319
  • LOT Update: RegularESB.java:1243-1472
  • Process Recalc: SFT_OP_REALRUN.sqlUpdate_RecalculateAll()

3. Request Specification

Format: JSON
Content-Type: application/json

3.1 Outer Structure

FieldTypeRequiredDescription
CompanyIDstringYCompany code
OperationTypeintYOperation type (2=Modify)
contentarrayYWork order data array

3.2 content Array Contents

FieldTypeRequiredDescriptionAffected Field
wo_nostringYWork order number (type-number)Condition field
item_nostringYItem numberITEMID
unit_nostringYUnit codeUNIT
plan_date_sstringYPlanned start datePLANPROCESSST
plan_date_estringYPlanned end dateDUEDATETIME
wo_qtydecimalYNew planned quantityQTY / PLANRELEASEQTY / LOT.LOTSIZE
so_nostringNSales order numberDOID
so_seqstringNSales order lineSEQUENCE
factory_nostringYFactory codeFACTORYID
warehouse_nostringNWarehouse codeWAREHOUSEID
remarkstringNRemarksDESCRIPTION
prioritystringNPriorityMO032

4. Response Specification

FieldTypeDescription
codestring200=Success, 500=Failure
msgstringProcessing result message
queryarrayQuery result

Success Behavior

5. Quantity Validation Logic

Key Variable Definitions
  • MOQTY: MODETAIL.PLANRELEASEQTY (Original planned release qty)
  • MOREQTY: MODETAIL.RELEASEDQTY (Already released qty)
  • LOTQTY: LOT.LOTSIZE (Pending release qty)
  • newQTY: New quantity from ERP
  • MODIQTY: SFT_MO_MODI sum (Supplementary release qty)
  • BATQTY: SFT_BATCH_REC sum (Split batch qty)

5.1 Increase Quantity Scenario

newQTY > (MOQTY - MODIQTY)

// Increase quantity - directly add
Increase amount = newQTY - (MOQTY - MODIQTY)

IF LOT exists THEN
    UPDATE LOT SET LOTSIZE += increase amount
ELSE
    INSERT LOT (create new lot record)
END IF

UPDATE MODETAIL SET PLANRELEASEQTY += increase amount

5.2 Decrease Quantity Scenario

newQTY < (MOQTY - MODIQTY)

// Decrease quantity - need to check changeable allowance
Max changeable amount = MOQTY - MOREQTY - BATQTY
This change amount = MOQTY - newQTY - MODIQTY

IF Max changeable amount >= This change amount THEN
    // Can decrease
    IF LOTQTY - This change amount > 0 THEN
        UPDATE LOT SET LOTSIZE -= This change amount
    ELSE
        DELETE FROM LOT  // Qty becomes zero or negative after decrease
    END IF
    UPDATE MODETAIL SET PLANRELEASEQTY -= This change amount
ELSE
    // Cannot decrease - already released or split batch exceeds allowance
    Throw Exception("JS_0126_00060")
END IF
Important Restriction
If MES side released qty + split batch qty > new qty, cannot decrease, throws error JS_0126_00060.

5.3 Flow Diagram

newQTY vs (MOQTY-MODIQTY) Increase Qty Directly add LOTSIZE > Changeable sufficient? < Decrease Qty Reduce LOTSIZE Yes Throw Error JS_0126_00060 No Code Location: RegularESB.java:1234-1319

6. Error Codes

CodeMessageDescription
JS_0126_00060Change qty less than pending release qty, not allowedDecrease amount exceeds changeable allowance
JS_0096_00058Item number does not existItem not found in ITEM table
JS_0016_00134Unit does not exist, please confirmUnit not found in UnitBasis
JS_0016_00115Factory code does not existFactory not found in FACTORY
JS_0135_00036Warehouse code does not existWarehouse not found in WAREHOUSE
remind_002Data does not existOrder number does not exist

7. JSON Examples

Request (Increase Quantity)

{
  "CompanyID": "COMP01",
  "OperationType": 2,  // 2=Modify
  "content": [{
    "wo_no": "5101-20260319001",
    "item_no": "FG-A001-001",
    "unit_no": "PCS",
    "plan_date_s": "2026-03-19 08:00:00",
    "plan_date_e": "2026-03-21 17:00:00",
    "wo_qty": 1500,  // Original 1000, increase 500
    "factory_no": "P001",
    "remark": "Additional order"
  }]
}

Request (Decrease Quantity)

{
  "CompanyID": "COMP01",
  "OperationType": 2,
  "content": [{
    "wo_no": "5101-20260319001",
    "item_no": "FG-A001-001",
    "unit_no": "PCS",
    "plan_date_s": "2026-03-19 08:00:00",
    "plan_date_e": "2026-03-20 17:00:00",
    "wo_qty": 800,  // Original 1000, decrease 200
    "factory_no": "P001",
    "remark": "Customer reduced order"
  }]
}

Response (Success)

{
  "code": "200",
  "msg": "success",
  "query": []
}

Response (Failure - Cannot Decrease)

{
  "code": "500",
  "msg": "JS_0126_00060",  // Released qty exceeds new qty
  "query": []
}

8. Database Update SQL

8.1 UPDATE MODETAIL (Update Order Master)

UPDATE MODETAIL SET
    PLANPROCESSST = :PLANPROCESSST,      -- Planned start date
    DUEDATETIME = :DUEDATETIME,          -- Planned end date
    DOID = :DOID,                        -- Sales order number
    SEQUENCE = :SEQUENCE,                -- Sales order line
    FACTORYID = :FACTORYID,              -- Factory code
    WAREHOUSEID = :WAREHOUSEID,          -- Warehouse code
    DESCRIPTION = :DESCRIPTION,          -- Remarks
    MO032 = :MO032,                      -- Priority
    LASTMAINTAINUSER = :userid,
    LASTMAINTAINDATETIME = N'{current_time}',
    FLAG = (SELECT MAX(FLAG)+1 FROM MODETAIL WHERE CMOID = :CMOID)
WHERE CMOID = :CMOID

8.2 Increase Quantity (UPDATE LOT)

-- Increase amount = newQTY - (MOQTY - MODIQTY)
UPDATE LOT SET
    LOTSIZE = LOTSIZE + {increase amount}
WHERE MOID = :CMOID

-- Also update MODETAIL planned release qty
UPDATE MODETAIL SET
    PLANRELEASEQTY = PLANRELEASEQTY + {increase amount},
    QTY = :newQTY
WHERE CMOID = :CMOID

8.3 Decrease Quantity (UPDATE/DELETE LOT)

-- Decrease amount = MOQTY - newQTY - MODIQTY
-- First check changeable allowance
Max changeable amount = MOQTY - MOREQTY - BATQTY

IF LOTQTY - decrease amount > 0 THEN
    -- Still has remaining after decrease
    UPDATE LOT SET
        LOTSIZE = LOTSIZE - {decrease amount}
    WHERE MOID = :CMOID
ELSE
    -- Qty becomes zero or negative after decrease, delete lot
    DELETE FROM LOT WHERE MOID = :CMOID
END IF

-- Also update MODETAIL planned release qty
UPDATE MODETAIL SET
    PLANRELEASEQTY = PLANRELEASEQTY - {decrease amount},
    QTY = :newQTY
WHERE CMOID = :CMOID

8.4 Recalculate Process

-- Recalculate all processes after update
SFT_OP_REALRUN.sqlUpdate_RecalculateAll("updateMODETAIL")
Quantity Validation Related Tables
  • MODETAIL.PLANRELEASEQTY: Planned release qty (MOQTY)
  • MODETAIL.RELEASEDQTY: Already released qty (MOREQTY)
  • LOT.LOTSIZE: Pending release qty (LOTQTY)
  • SFT_MO_MODI: Supplementary release qty (MODIQTY)
  • SFT_BATCH_REC: Split batch qty (BATQTY)
Code Location
Qty Validation: RegularESB.java:1234-1319
LOT Update: RegularESB.java:1243-1472