请问如何使用SAP 外向交货单过账BAPI:BAPI_OUTB_DELIVERY_CONFIRM_DEC,越详细越好,谢谢! 5
2个回答
展开全部
这是05年写过的,基于R4.6,你看一下吧,难得我今天上baidu知道并且有心情。。。。。
REPORT zsdi003 .
TABLES: likp,lips,ekpo,t001l .
DATA: header_data LIKE bapiobdlvhdrcon,
header_control LIKE bapiobdlvhdrctrlcon,
delivery LIKE bapiobdlvhdrcon-deliv_numb,
bapidlvcontrol LIKE bapidlvcontrol.
DATA: datum(8),uzeit(6),timestamp(15),flag,
rate(7) TYPE p DECIMALS 3, ll_wadat LIKE likp-wadat.
DATA: return LIKE bapiret2 OCCURS 0 WITH HEADER LINE.
DATA: item_data LIKE bapiobdlvitemcon OCCURS 0 WITH HEADER LINE,
item_control LIKE bapiobdlvitemctrlcon OCCURS 0 WITH HEADER LINE,
header_deadlines LIKE bapidlvdeadln OCCURS 0 WITH HEADER LINE.
DATA: wa_import LIKE zsd_vtimport,
itab_import LIKE STANDARD TABLE OF zsd_vtimport WITH DEFAULT KEY.
DATA tstamp TYPE timestamp.
DATA: info LIKE soli OCCURS 0 WITH HEADER LINE,
mailtitle LIKE sood1-objdes,
nx TYPE i, nnx(5) TYPE n.
DATA: l_posnr LIKE lips-posnr, l_ebelp LIKE ekpo-ebelp.
START-OF-SELECTION.
SELECT * INTO TABLE itab_import FROM zsd_vtimport WHERE state IN ('','0','X','E','P').
IF itab_import[] IS INITIAL.
EXIT.
ENDIF.
SORT itab_import BY line_no(10) line_no+10(6).
LOOP AT itab_import INTO wa_import.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_import-line_no+10(6)
IMPORTING
output = l_posnr.
SELECT SINGLE * FROM lips WHERE vbeln = wa_import-line_no(10)." AND posnr = l_posnr.
IF sy-subrc <> 0.
wa_import-state = '0'.
wa_import-message = text-001.
CONCATENATE sy-datum sy-uzeit INTO wa_import-importeddate.
MODIFY itab_import FROM wa_import.
CLEAR: wa_import,item_data,ekpo,lips.
CONTINUE.
* ELSEIF lips-lgort IS INITIAL.
* MESSAGE '更新库存地点' TYPE 'S'.
* UPDATE lips SET lgort = wa_import-lgort
* WHERE vbeln = wa_import-vbeln AND
* posnr = l_posnr.
* COMMIT WORK.
* CALL FUNCTION 'ENQUE_SLEEP'
* EXPORTING
* seconds = 1.
ENDIF.
CLEAR lips.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_import-line_no+10(6)
IMPORTING
output = l_posnr.
item_data-fact_unit_nom = ekpo-umrez.
item_data-fact_unit_denom = ekpo-umren.
CLEAR: ekpo,lips.
item_data-dlv_qty_imunit = wa_import-dquan. "lfimg.
item_data-deliv_numb = wa_import-line_no(10). "vbeln.
item_data-deliv_item = l_posnr. "wa_import-posnr.
item_data-batch = wa_import-charg.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_import-matnr
IMPORTING
output = item_data-material.
APPEND item_data.
*----------------------------------------
SELECT SINGLE wadat INTO ll_wadat FROM likp WHERE vbeln = wa_import-line_no(10).
datum = ll_wadat.
uzeit = sy-uzeit.
CONCATENATE datum uzeit INTO timestamp.
header_deadlines-deliv_numb = wa_import-line_no(10).
header_deadlines-timetype = 'WSHDRWADAT'. "Goods issue date (planned)
header_deadlines-timezone = ''.
header_deadlines-timestamp_utc = timestamp.
APPEND header_deadlines.
CLEAR: datum,uzeit,timestamp,ll_wadat.
*----------------------------------------
datum = wa_import-ddate.
uzeit = sy-uzeit.
CONCATENATE datum uzeit INTO timestamp.
header_deadlines-deliv_numb = wa_import-line_no(10).
header_deadlines-timetype = 'WSHDRWADTI'. "Goods issue date (actual)
header_deadlines-timestamp_utc = timestamp.
header_deadlines-timezone = ''.
APPEND header_deadlines.
item_control-deliv_numb = wa_import-line_no(10).
item_control-deliv_item = l_posnr. "wa_import-posnr.
item_control-chg_delqty = 'X'.
APPEND item_control.
bapidlvcontrol-upd_ind = 'X'.
header_data-deliv_numb = wa_import-line_no(10).
header_control-deliv_numb = wa_import-line_no(10).
header_control-post_gi_flg = 'X'.
header_control-gdsi_date_flg = 'X'.
header_control-simulate = 'X'.
AT END OF line_no(10).
flag = 'X'.
ENDAT.
IF flag = 'X'.
CLEAR flag.
CALL FUNCTION 'BAPI_OUTB_DELIVERY_CONFIRM_DEC'
EXPORTING
header_data = header_data
header_control = header_control
delivery = wa_import-line_no(10)
techn_control = bapidlvcontrol
TABLES
header_deadlines = header_deadlines[]
item_data = item_data[]
item_control = item_control[]
return = return.
IF sy-subrc = 0.
COMMIT WORK .
ENDIF.
IF return[] IS NOT INITIAL.
CLEAR wa_import-message.
* LOOP AT return.
READ TABLE return INDEX 1.
SELECT SINGLE text INTO return-message FROM t100
WHERE arbgb = return-id AND
msgnr = return-number AND
sprsl = '1'.
CONCATENATE wa_import-message ',' return-message
',' return-message_v1 ',' return-message_v2
',' return-message_v3 ',' return-message_v4
INTO wa_import-message.
* CLEAR return.
CONDENSE wa_import-message NO-GAPS.
* ENDLOOP.
CLEAR return.
wa_import-state = 'E'.
CONCATENATE sy-datum sy-uzeit INTO wa_import-importeddate.
MODIFY itab_import FROM wa_import
TRANSPORTING state message importeddate
WHERE line_no = wa_import-line_no.
ELSE.
* 成功发货过账
wa_import-state = 'P'.
CONCATENATE sy-datum sy-uzeit INTO wa_import-importeddate.
SELECT SINGLE vbeln INTO wa_import-message FROM vbfa
WHERE vbelv = wa_import-line_no(10) AND
vbtyp_n = 'R'.
IF sy-subrc = 0.
CONCATENATE 'TF在途库存凭证号码' wa_import-message
INTO wa_import-message.
ENDIF.
MODIFY itab_import FROM wa_import
TRANSPORTING state message importeddate
WHERE line_no = wa_import-line_no.
ENDIF.
CLEAR: header_data,header_control,bapidlvcontrol.
REFRESH:header_deadlines,item_data,item_control,return.
ENDIF.
CLEAR: wa_import,item_data.
ENDLOOP.
MODIFY zsd_vtimport FROM TABLE itab_import.
COMMIT WORK.
REPORT zsdi003 .
TABLES: likp,lips,ekpo,t001l .
DATA: header_data LIKE bapiobdlvhdrcon,
header_control LIKE bapiobdlvhdrctrlcon,
delivery LIKE bapiobdlvhdrcon-deliv_numb,
bapidlvcontrol LIKE bapidlvcontrol.
DATA: datum(8),uzeit(6),timestamp(15),flag,
rate(7) TYPE p DECIMALS 3, ll_wadat LIKE likp-wadat.
DATA: return LIKE bapiret2 OCCURS 0 WITH HEADER LINE.
DATA: item_data LIKE bapiobdlvitemcon OCCURS 0 WITH HEADER LINE,
item_control LIKE bapiobdlvitemctrlcon OCCURS 0 WITH HEADER LINE,
header_deadlines LIKE bapidlvdeadln OCCURS 0 WITH HEADER LINE.
DATA: wa_import LIKE zsd_vtimport,
itab_import LIKE STANDARD TABLE OF zsd_vtimport WITH DEFAULT KEY.
DATA tstamp TYPE timestamp.
DATA: info LIKE soli OCCURS 0 WITH HEADER LINE,
mailtitle LIKE sood1-objdes,
nx TYPE i, nnx(5) TYPE n.
DATA: l_posnr LIKE lips-posnr, l_ebelp LIKE ekpo-ebelp.
START-OF-SELECTION.
SELECT * INTO TABLE itab_import FROM zsd_vtimport WHERE state IN ('','0','X','E','P').
IF itab_import[] IS INITIAL.
EXIT.
ENDIF.
SORT itab_import BY line_no(10) line_no+10(6).
LOOP AT itab_import INTO wa_import.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_import-line_no+10(6)
IMPORTING
output = l_posnr.
SELECT SINGLE * FROM lips WHERE vbeln = wa_import-line_no(10)." AND posnr = l_posnr.
IF sy-subrc <> 0.
wa_import-state = '0'.
wa_import-message = text-001.
CONCATENATE sy-datum sy-uzeit INTO wa_import-importeddate.
MODIFY itab_import FROM wa_import.
CLEAR: wa_import,item_data,ekpo,lips.
CONTINUE.
* ELSEIF lips-lgort IS INITIAL.
* MESSAGE '更新库存地点' TYPE 'S'.
* UPDATE lips SET lgort = wa_import-lgort
* WHERE vbeln = wa_import-vbeln AND
* posnr = l_posnr.
* COMMIT WORK.
* CALL FUNCTION 'ENQUE_SLEEP'
* EXPORTING
* seconds = 1.
ENDIF.
CLEAR lips.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_import-line_no+10(6)
IMPORTING
output = l_posnr.
item_data-fact_unit_nom = ekpo-umrez.
item_data-fact_unit_denom = ekpo-umren.
CLEAR: ekpo,lips.
item_data-dlv_qty_imunit = wa_import-dquan. "lfimg.
item_data-deliv_numb = wa_import-line_no(10). "vbeln.
item_data-deliv_item = l_posnr. "wa_import-posnr.
item_data-batch = wa_import-charg.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_import-matnr
IMPORTING
output = item_data-material.
APPEND item_data.
*----------------------------------------
SELECT SINGLE wadat INTO ll_wadat FROM likp WHERE vbeln = wa_import-line_no(10).
datum = ll_wadat.
uzeit = sy-uzeit.
CONCATENATE datum uzeit INTO timestamp.
header_deadlines-deliv_numb = wa_import-line_no(10).
header_deadlines-timetype = 'WSHDRWADAT'. "Goods issue date (planned)
header_deadlines-timezone = ''.
header_deadlines-timestamp_utc = timestamp.
APPEND header_deadlines.
CLEAR: datum,uzeit,timestamp,ll_wadat.
*----------------------------------------
datum = wa_import-ddate.
uzeit = sy-uzeit.
CONCATENATE datum uzeit INTO timestamp.
header_deadlines-deliv_numb = wa_import-line_no(10).
header_deadlines-timetype = 'WSHDRWADTI'. "Goods issue date (actual)
header_deadlines-timestamp_utc = timestamp.
header_deadlines-timezone = ''.
APPEND header_deadlines.
item_control-deliv_numb = wa_import-line_no(10).
item_control-deliv_item = l_posnr. "wa_import-posnr.
item_control-chg_delqty = 'X'.
APPEND item_control.
bapidlvcontrol-upd_ind = 'X'.
header_data-deliv_numb = wa_import-line_no(10).
header_control-deliv_numb = wa_import-line_no(10).
header_control-post_gi_flg = 'X'.
header_control-gdsi_date_flg = 'X'.
header_control-simulate = 'X'.
AT END OF line_no(10).
flag = 'X'.
ENDAT.
IF flag = 'X'.
CLEAR flag.
CALL FUNCTION 'BAPI_OUTB_DELIVERY_CONFIRM_DEC'
EXPORTING
header_data = header_data
header_control = header_control
delivery = wa_import-line_no(10)
techn_control = bapidlvcontrol
TABLES
header_deadlines = header_deadlines[]
item_data = item_data[]
item_control = item_control[]
return = return.
IF sy-subrc = 0.
COMMIT WORK .
ENDIF.
IF return[] IS NOT INITIAL.
CLEAR wa_import-message.
* LOOP AT return.
READ TABLE return INDEX 1.
SELECT SINGLE text INTO return-message FROM t100
WHERE arbgb = return-id AND
msgnr = return-number AND
sprsl = '1'.
CONCATENATE wa_import-message ',' return-message
',' return-message_v1 ',' return-message_v2
',' return-message_v3 ',' return-message_v4
INTO wa_import-message.
* CLEAR return.
CONDENSE wa_import-message NO-GAPS.
* ENDLOOP.
CLEAR return.
wa_import-state = 'E'.
CONCATENATE sy-datum sy-uzeit INTO wa_import-importeddate.
MODIFY itab_import FROM wa_import
TRANSPORTING state message importeddate
WHERE line_no = wa_import-line_no.
ELSE.
* 成功发货过账
wa_import-state = 'P'.
CONCATENATE sy-datum sy-uzeit INTO wa_import-importeddate.
SELECT SINGLE vbeln INTO wa_import-message FROM vbfa
WHERE vbelv = wa_import-line_no(10) AND
vbtyp_n = 'R'.
IF sy-subrc = 0.
CONCATENATE 'TF在途库存凭证号码' wa_import-message
INTO wa_import-message.
ENDIF.
MODIFY itab_import FROM wa_import
TRANSPORTING state message importeddate
WHERE line_no = wa_import-line_no.
ENDIF.
CLEAR: header_data,header_control,bapidlvcontrol.
REFRESH:header_deadlines,item_data,item_control,return.
ENDIF.
CLEAR: wa_import,item_data.
ENDLOOP.
MODIFY zsd_vtimport FROM TABLE itab_import.
COMMIT WORK.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你用的是SAP的哪个产品?R3、A1还是B1?
追问
R3
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询