VT01N创建运输单BAPI:BAPI_SHIPMENT_CREATE
DATA:
LS_HEADERDATA TYPE BAPISHIPMENTHEADER,
LT_ITEMDATA TYPE STANDARD TABLE OF BAPISHIPMENTITEM,
LS_ITEMDATA TYPE BAPISHIPMENTITEM,
LT_RETURN TYPE STANDARD TABLE OF BAPIRET2,
LS_RETURN TYPE BAPIRET2,
LV_TKNUM TYPE VTTK-TKNUM,
LS_LIPS TYPE LIPS,
LS_TIME TYPE BAPISHIPMENTSTAGEDEADLINE,
LT_TIME TYPE STANDARD TABLE OF BAPISHIPMENTSTAGEDEADLINE,
LT_HEADLINE TYPE STANDARD TABLE OF BAPISHIPMENTHEADERDEADLINE,
LS_HEADLINE TYPE BAPISHIPMENTHEADERDEADLINE.
IF IT_LIPS[] IS NOT INITIAL .
READ TABLE IT_LIPS INTO LS_LIPS INDEX 1.
SELECT SINGLE ROUTE INTO LS_HEADERDATA-SHIPMENT_ROUTE
FROM LIKP
WHERE VBELN = LS_LIPS-VBELN. "从交货单获取route
LS_HEADERDATA-SHIPMENT_TYPE = 'ZSTU'.
LS_HEADERDATA-TRANS_PLAN_PT = '6500'.
LS_HEADERDATA-SERVICE_AGENT_ID = 'FRT123'.
"TRVAB 表中根据 route去找服务代理
LOOP AT IT_LIPS INTO LS_LIPS.
LS_ITEMDATA-DELIVERY = LS_LIPS-VBELN.
APPEND LS_ITEMDATA TO LT_ITEMDATA.
ENDLOOP .
*以下是确定时间,如果不确定时间的话,后续的运输成本单无法创建
LS_HEADLINE-TIME_TYPE = 'HDRSTPLDT'. "Date of end of planning
CALL FUNCTION 'IB_CONVERT_INTO_TIMESTAMP'
EXPORTING
I_DATLO = SY-DATUM
I_TIMLO = SY-TIMLO
* I_TZONE = SY-ZONLO
IMPORTING
E_TIMESTAMP = LS_HEADLINE-TIME_STAMP_UTC .
LS_HEADLINE-TIME_ZONE = 'UTC'.
APPEND LS_HEADLINE TO LT_HEADLINE.
LS_HEADLINE-TIME_TYPE = 'HDRSTCIADT'. "Actual date of check-in
APPEND LS_HEADLINE TO LT_HEADLINE.
LS_HEADLINE-TIME_TYPE = 'HDRSTLSADT'. "Current date for start of loading
APPEND LS_HEADLINE TO LT_HEADLINE.
LS_HEADLINE-TIME_TYPE = 'HDRSTLEADT'. "Actual date for end of loading
APPEND LS_HEADLINE TO LT_HEADLINE.
CALL FUNCTION 'BAPI_SHIPMENT_CREATE'
EXPORTING
HEADERDATA = LS_HEADERDATA
IMPORTING
TRANSPORT = LV_TKNUM
* SHIPMENTGUID =
TABLES
HEADERDEADLINE = LT_HEADLINE
ITEMDATA = LT_ITEMDATA
* STAGEDATA =
* STAGEDEADLINE = LT_TIME
* ITEMONSTAGE =
* ADDRESS =
* HDUNHEADER =
* HDUNITEM =
RETURN = LT_RETURN.
READ TABLE LT_RETURN INTO LS_RETURN WITH KEY TYPE = 'E'.
IF SY-SUBRC = 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
ENDIF.