Sap me 15.3 库存查询 库存接受

         

Sap me 15.3 库存查询 库存接受_第1张图片

--库存查询

SELECT INV.ITEM_BO,

ITEM_T.DESCRIPTION ITEM_DESC,

ITEM.UNIT_OF_MEASURE,

SUM(NVL(OQNA.ORIGINAL_QTY_NA, 0)) ORIGINAL_QTY_NA,

SUM(NVL(INV.QTY_ON_HAND, 0)) QTY_ON_HAND,

SUM(NVL(OQA.ORIGINAL_QTY_A, 0)) ORIGINAL_QTY_A,

SL.STORAGE_LOCATION L_STORAGE_LOCATION,

SL.DESCRIPTION STORAGE_LOCATION_DESC

FROM INVENTORY INV

LEFT JOIN ITEM

ON INV.ITEM_BO = ITEM.HANDLE

LEFT JOIN ITEM_T

ON ITEM.HANDLE = ITEM_T.ITEM_BO

AND ITEM_T.LOCALE = 'zh'

LEFT JOIN (SELECT INV.HANDLE, NVL(INV.ORIGINAL_QTY, 0) ORIGINAL_QTY_NA

FROM INVENTORY INV, INVENTORY_ASSY_DATA IAD

WHERE INV.HANDLE = IAD.INVENTORY_BO

AND IAD.DATA_FIELD = 'INVENTORY_STATUS'

AND IAD.DATA_ATTR != 'A') OQNA

ON INV.HANDLE = OQNA.HANDLE

LEFT JOIN (SELECT INV.HANDLE, NVL(INV.ORIGINAL_QTY, 0) ORIGINAL_QTY_A

FROM INVENTORY INV, INVENTORY_ASSY_DATA IAD

WHERE INV.HANDLE = IAD.INVENTORY_BO

AND IAD.DATA_FIELD = 'INVENTORY_STATUS'

AND IAD.DATA_ATTR = 'A') OQA

ON OQA.HANDLE = INV.HANDLE

LEFT JOIN STORAGE_LOCATION SL

ON INV.STORAGE_LOCATION_BO = SL.HANDLE

WHERE INV.SITE = '1130'

AND INV.STORAGE_LOCATION_BO IN

(SELECT SL.HANDLE

FROM WORK_CENTER WC

JOIN WORK_CENTER_MEMBER WCM

ON WC.HANDLE = WCM.WORK_CENTER_BO

AND WC.WC_CATEGORY = 'LEVEL3'

JOIN WORK_CENTER WC1

ON WC1.HANDLE = WCM.WORK_CENTER_OR_RESOURCE_GBO

AND WC1.WC_CATEGORY = 'LEVEL2'

JOIN STORAGE_LOCATION_MEMBER SLM

ON WCM.WORK_CENTER_OR_RESOURCE_GBO = SLM.WORK_CENTER_BO

JOIN STORAGE_LOCATION SL

ON SL.HANDLE = SLM.STORAGE_LOCATION_BO

WHERE WC.HANDLE = 'WorkCenterBO:1130,11300501')

GROUP BY (INV.ITEM_BO, ITEM_T.DESCRIPTION, ITEM.UNIT_OF_MEASURE,

SL.STORAGE_LOCATION, SL.DESCRIPTION)

Sap me 15.3 库存查询 库存接受_第2张图片

--查询所有待接收库存

SELECT INV.HANDLE, NVL(INV.ORIGINAL_QTY, 0) ORIGINAL_QTY_A

FROM INVENTORY INV, INVENTORY_ASSY_DATA IAD

WHERE INV.HANDLE = IAD.INVENTORY_BO

AND IAD.DATA_FIELD = 'INVENTORY_STATUS' AND IAD.DATA_ATTR = 'A'

Sap me 15.3 库存查询 库存接受_第3张图片

Sap me 15.3 库存查询 库存接受_第4张图片

Sap me 15.3 库存查询 库存接受_第5张图片

 Q环境

 --查库存

SELECT x.*,x.ROWID FROM WIPDBA.INVENTORY x

WHERE x.INVENTORY_ID = 'TSW10000357605720512310003'

 Sap me 15.3 库存查询 库存接受_第6张图片

     --查库存亏扩展字段

SELECT x.*, x.ROWID

FROM WIPDBA.INVENTORY_ASSY_DATA x

WHERE x.INVENTORY_BO = 'InventoryBO:1120,TSW10000357605720512310003'

Sap me 15.3 库存查询 库存接受_第7张图片

 

 

   接收:点击接收按钮,将显示出来的所有条码(INVENTORY_ID)的状态变为可用状态,通过INVENTORY_BO关联表INVENTORY和表INVENTORY_ASSY_DATA,检索INVENTORY_ID对应字段DATA_FIELD为INVENTORY_STATUS的DATA_ATTR字段是否为A(待接收状态),若为A,则将对应的值变为B(可用状态),且将对应字段DATA_FIELD为ACTUAL_RECEIVE_TIME的DATA_ATTR字段填入当前时间;

若为其他状态,则提示报错"存在不是待接收状态的条码,请检查!"

不管是点击拒收还是接收按钮之后,执行以下逻辑:

找到上述INVENTORY_ID的单据(表INVENTORY_ASSY_DATA中的字段DATA_FIELD为INSTRUCTION_CODE对应的字段DATA_ATTR的值,多条去重),记为X,取其在单据头表Z_INSTRUCTION_DOC的字段INSTRUCTION_STATUS,判断值是否为D(取消状态),若为D,则跳过;

若不为D,执行以下逻辑:

继续判断INSTRUCTION_STATUS的值是否为A(下达状态):

若不为A,则提示报错:单据xxxxx不是下达状态,请检查!

若为A,则继续执行以下逻辑:

筛选表INVENTORY_ASSY_DATA中的字段DATA_FIELD为INSTRUCTION_CODE对应的字段DATA_ATTR的值为上述X的数据且库存状态为可用(DATA_FIELD='INVENTORY_STATUS',DATA_ATTR='B')的库存标识,取其字段INVENTORY_BO,

INVENTORY_ASSY_DATA.INVENTOY_BO=INVENTORY.HANDLE,按照INVENTORY表中字段ITEM_BO和字段ORIGINAL_QTY汇总,并与表Z_INSTRUCTION_SUM中字段INSTRUCTION_DOC_BO为上段逻辑查到的单据号且字段ITEM_CODE的数据进行对比,当且仅当汇总的数量大于等于单据行表的字段ITEM_QTY时(按照料号分别对比),将单据状态变为B(完成);

   

    

你可能感兴趣的:(Sap me 15.3 库存查询 库存接受)