ABAP-承运单BAPI

创建

constants: begin of gc_time_type,
             stpldt  like bapishipmentheaderdeadline-time_type value 'HDRSTPLDT',
             "Status planned
             stcipdt like bapishipmentheaderdeadline-time_type value 'HDRSTCIPDT',
             "Status checkin plan
             stpladt like bapishipmentheaderdeadline-time_type value 'HDRSTCIADT',
             "Status checkin act
             stlspdt like bapishipmentheaderdeadline-time_type value 'HDRSTLSPDT',
             "Status load start plan
             stlsadt like bapishipmentheaderdeadline-time_type value 'HDRSTLSADT',
             "Status load start act
             stlepdt like bapishipmentheaderdeadline-time_type value 'HDRSTLEPDT',
             "Status load end plan
             stleadt like bapishipmentheaderdeadline-time_type value 'HDRSTLEADT',
             "Status load end act
             stcpdt  like bapishipmentheaderdeadline-time_type value 'HDRSTCPDT',
             "Status complete plan
             stcadt  like bapishipmentheaderdeadline-time_type value 'HDRSTCADT',
             "Status copmlete act
             stsspdt like bapishipmentheaderdeadline-time_type value 'HDRSTSSPDT',
             "Status shipmnt start plan
             stssadt like bapishipmentheaderdeadline-time_type value 'HDRSTSSADT',
             "Status shipmnt start act
             stsepdt like bapishipmentheaderdeadline-time_type value 'HDRSTSEPDT',
             "Status shipmnt end plan
             stseadt like bapishipmentheaderdeadline-time_type value 'HDRSTSEADT',
             "Status shipmnt end act
             tndepdt like bapishipmentheaderdeadline-time_type value 'HDRTNDEPDT',
             "Tendering earliest pick
             tndlpdt like bapishipmentheaderdeadline-time_type value 'HDRTNDLPDT',
             "Tendering latest pick
             tndeddt like bapishipmentheaderdeadline-time_type value 'HDRTNDEDDT',
             "Tendering earliest delivery
             tndlddt like bapishipmentheaderdeadline-time_type value 'HDRTNDLDDT',
             "Tendering latest delivery
             lstpdt  like bapishipmentstagedeadline-time_type value 'STLSTPDT',
             "Stage start plan
             lstadt  like bapishipmentstagedeadline-time_type value 'STLSTADT',
             "Stage start act
             lenpdt  like bapishipmentstagedeadline-time_type value 'STLENDPT',
             "Stage end plan
             lenadt  like bapishipmentstagedeadline-time_type value 'STLENADT',
             "Stage end act
           end of gc_time_type.

"创建
data:ls_header type bapishipmentheader,
     lt_line   type table of bapishipmentheaderdeadline with header line,
     lt_item   type table of bapishipmentitem with header line,
     lt_return type table of bapiret2 with header line.
data:ztspt type bapishipmentids-shipmentnum.

ls_header-trans_plan_pt = '2003'.            
ls_header-shipment_type = 'ZX01'.            "类型
ls_header-service_agent_id = '0000280110'.   "承运商
ls_header-shipping_type = '01'.              "
ls_header-shipment_route = 'Z00001'.         "路线  查询交货单运输路线
ls_header-shipping_cond = '10'.              "装运条件
ls_header-status_plan =    'X'.
ls_header-status_checkin = 'X'.
ls_header-status_load_start = 'X'.
ls_header-status_load_end = 'X'.
ls_header-status_compl = 'X'.
ls_header-status_shpmnt_start = 'X'.

data:lv_zonlo type sy-zonlo value 'UTC+0'."用格林尼治时间 时区 

data v_timestamp type char14.

lt_line-time_type = gc_time_type-stpldt ."计划实际时间
lt_line-time_stamp_utc = sy-datum && sy-uzeit.
lt_line-time_zone = lv_zonlo.
append lt_line .
clear lt_line.

lt_line-time_type = gc_time_type-stpladt ."登记实际
lt_line-time_stamp_utc = sy-datum && sy-uzeit.
lt_line-time_zone = lv_zonlo.
append lt_line .
clear lt_line.

lt_line-time_type = gc_time_type-stlsadt ."装载开始实际
lt_line-time_stamp_utc = sy-datum && sy-uzeit.
lt_line-time_zone = lv_zonlo.
append lt_line .
clear lt_line.

lt_line-time_type = gc_time_type-stleadt ."装载结束实际
lt_line-time_stamp_utc = sy-datum && sy-uzeit.
lt_line-time_zone = lv_zonlo.
append lt_line .
clear lt_line.

lt_line-time_type = gc_time_type-stcadt ."装运完成
lt_line-time_stamp_utc = sy-datum && sy-uzeit.
lt_line-time_zone = lv_zonlo.
append lt_line .
clear lt_line.

lt_line-time_type = gc_time_type-stssadt ."装运开始
lt_line-time_stamp_utc = sy-datum && sy-uzeit.
lt_line-time_zone = lv_zonlo.
append lt_line .
clear lt_line.

lt_item-delivery = '3100000206'.
append lt_item.
clear  lt_item.


call function 'BAPI_SHIPMENT_CREATE'
  exporting
    headerdata     = ls_header
  importing
    transport      = ztspt
  tables
    headerdeadline = lt_line
    itemdata       = lt_item
    return         = lt_return.

read table lt_return with key type = 'E'.
if sy-subrc ne 0.
  call function 'BAPI_TRANSACTION_COMMIT'
    exporting
      wait = 'X'.
  write ztspt.
else.
  call function 'BAPI_TRANSACTION_ROLLBACK'.

  write '失败'.
endif.

删除

data:ls_header type bapishipmentheader,
     ls_action type bapishipmentheaderaction.
data:lt_item       type table of bapishipmentitem with header line,
     lt_itemaction type table of bapishipmentitemaction with header line,
     lt_return     type table of bapiret2 with header line.

ls_header-shipment_num = '0000001009'.
ls_action-shipment_num = 'D'.

lt_item-delivery = '3100000206'.
append lt_item.
clear  lt_item.

lt_itemaction-delivery = 'D'.
lt_itemaction-itenerary = 'D'.
append lt_itemaction.
clear  lt_itemaction.

call function 'BAPI_SHIPMENT_CHANGE'
  exporting
    headerdata       = ls_header
    headerdataaction = ls_action
  tables
    itemdata         = lt_item
    itemdataaction   = lt_itemaction
    return           = lt_return.

read table lt_return with key type = 'E'.
if sy-subrc ne 0.
  call function 'BAPI_TRANSACTION_COMMIT'
    exporting
      wait = 'X'.
  write '成功'.
else.
  call function 'BAPI_TRANSACTION_ROLLBACK'.

  loop at lt_return.
    write lt_return-message.
  endloop.
endif.

你可能感兴趣的:(ABAP-承运单BAPI)