*&---------------------------------------------------------------------*
*& Form FRM_CREATE_PRODORD
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_CREATE_PRODORD CHANGING P_FW_OUTPUT STRUCTURE GS_OUTPUT.
DATA:LS_ORDERDATA TYPE BAPI_PP_ORDER_CREATE.
DATA:LS_RETURN TYPE BAPIRET2,
LV_ORDER_NUMBER TYPE BAPI_ORDER_KEY-ORDER_NUMBER.
CLEAR:LS_ORDERDATA.
LS_ORDERDATA-MATERIAL_LONG = P_FW_OUTPUT-MATNR.
LS_ORDERDATA-PLANT = P_FW_OUTPUT-DWERK.
LS_ORDERDATA-ORDER_TYPE = 'ZP02'.
LS_ORDERDATA-QUANTITY = P_FW_OUTPUT-ZXDSL.
* LS_ORDERDATA-BASIC_START_DATE = '20160101' ."SY-DATUM. "
LS_ORDERDATA-BASIC_START_DATE = SY-DATUM ."SY-DATUM. "
LS_ORDERDATA-BASIC_END_DATE = P_FW_OUTPUT-ZDDJQ.
LS_ORDERDATA-STORAGE_LOCATION = P_FW_OUTPUT-LGORT.
* LS_ORDERDATA-UNLOADING_POINT = P_FW_OUTPUT-ZHTBM.
CALL FUNCTION 'BAPI_PRODORD_CREATE'
EXPORTING
ORDERDATA = LS_ORDERDATA
* FSH_PRODORD_SEASON =
IMPORTING
RETURN = LS_RETURN
ORDER_NUMBER = LV_ORDER_NUMBER
* ORDER_TYPE =
.
IF LS_RETURN-TYPE = 'E'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ROLLBACK WORK.
CONCATENATE '创建生产订单报错:' LS_RETURN-MESSAGE INTO P_FW_OUTPUT-MESSAGE.
MOVE GC_LIGHT_R TO P_FW_OUTPUT-STATUS.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
P_FW_OUTPUT-AUFNR = LV_ORDER_NUMBER.
P_FW_OUTPUT-WENGE = P_FW_OUTPUT-WENGE + P_FW_OUTPUT-ZDDJQ."已下单数量
P_FW_OUTPUT-MENGE = P_FW_OUTPUT-MENGE - P_FW_OUTPUT-ZDDJQ."未下单数量
IF P_FW_OUTPUT-MENGE < 0.
P_FW_OUTPUT-MENGE = 0.
ENDIF.
MOVE GC_LIGHT_G TO P_FW_OUTPUT-STATUS.
MOVE '生产订单创建成功' TO P_FW_OUTPUT-MESSAGE.
ENDIF.
ENDFORM.