BAPI: 1. L_TO_SET_SPECIAL
2. L_TO_CREATE_MULTIPLE
事务码: LT0G - 交货返回入库
VL09对交货单冲销之后,使用LT0G将库存退回到仓库
代码样例:
IF lv_wbstk = 'C'.
* CALL FUNCTION 'WS_REVERSE_GOODS_ISSUE'
* EXPORTING
* i_vbeln = i_vbeln
* i_budat = sy-datum
* i_tcode = 'VL09'
* i_vbtyp = 'J'
* IMPORTING
* es_emkpf = ls_emkpf
* TABLES
* t_mesg = lt_mesg
* EXCEPTIONS
* error_reverse_goods_issue = 1
* error_message = 99
* OTHERS = 2.
* IF ls_emkpf IS NOT INITIAL.
REFRESH: bdcdata, messtab.
PERFORM bdc_dynpro USING 'RVV50L09' '1000'.
PERFORM bdc_field USING: 'BDC_OKCODE' '=ONLI',
'I_VBELN-LOW' i_vbeln,
'LF_ANAUS' 'X'.
CALL TRANSACTION 'VL09' USING bdcdata
MODE ctumode "No Dialog
UPDATE 'S' "Synchronous
MESSAGES INTO messtab.
IF sy-subrc = 0.
* CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* wait = 'X'.
WAIT UP TO 1 SECONDS.
CLEAR: lv_lgnum.
SELECT SINGLE lgnum INTO lv_lgnum
FROM likp
WHERE vbeln = i_vbeln.
* REFRESH: bdcdata,
* messtab.
*
* CLEAR: bdcdata,
* messtab.
*
* PERFORM bdc_dynpro USING 'RLLT0G00' '1000'.
* PERFORM bdc_field USING 'BDC_CURSOR'
* 'LGNUM'.
* PERFORM bdc_field USING 'BDC_OKCODE'
* '=ONLI'.
* PERFORM bdc_field USING 'LGNUM'
* lv_lgnum.
* PERFORM bdc_field USING 'VBELN-LOW'
* i_vbeln.
* PERFORM bdc_field USING 'BWLVS-LOW'
* '999'.
* PERFORM bdc_field USING 'P_VBELN'
* 'X'.
* PERFORM bdc_dynpro USING 'SAPMSSY0' '0120'.
* PERFORM bdc_field USING 'BDC_CURSOR'
* '06/78'.
* PERFORM bdc_field USING 'BDC_OKCODE'
* '=MKAL'.
* PERFORM bdc_dynpro USING 'SAPMSSY0' '0120'.
* PERFORM bdc_field USING 'BDC_CURSOR'
* '06/78'.
* PERFORM bdc_field USING 'BDC_OKCODE'
* '=RUEC'.
*
* CALL TRANSACTION 'LT0G' USING bdcdata
* MODE ctumode
* UPDATE cupdate
* MESSAGES INTO messtab.
* LOOP AT messtab WHERE msgtyp = 'A' OR msgtyp = 'E'.
*
* ENDLOOP.
* IF sy-subrc = 0.
* READ TABLE messtab WITH KEY msgtyp = 'E'.
* IF sy-subrc = 0.
* CLEAR: lv_text.
* SELECT SINGLE text FROM t100 INTO lv_text
* WHERE arbgb = messtab-msgid AND msgnr = messtab-msgnr AND sprsl = sy-langu .
* e_msg = lv_text.
* e_code = 'E'.
* ENDIF.
* ELSE.
* e_msg = '冲销成功'.
* e_code = 'S'.
* ENDIF.
* CALL FUNCTION 'ENQUEUE_EVVBLKE'
* EXPORTING
* vbeln = i_vbeln
* EXCEPTIONS
* foreign_lock = 2
* system_failure = 3.
*
*
* CALL FUNCTION 'L_TO_SET_SPECIAL'
* EXPORTING
* i_spezi = 'B'
* i_vbeln = i_vbeln
* EXCEPTIONS
* call_forbidden = 1
* input_wrong = 2
* OTHERS = 3.
DATA: i_nidru TYPE rl03a-nidru,
i_drukz TYPE t329f-drukz,
hlp_tanum TYPE ltak-tanum,
ltap_creat TYPE TABLE OF ltap_creat,
lv_index TYPE i,
lv_nlqnr TYPE ltap-nlqnr,
lv_lqnum TYPE lqua-lqnum.
CLEAR: i_nidru,
i_drukz,
hlp_tanum,
ltap_creat,
ls_ltap_creat,
lv_index,
lv_nlqnr,
lv_lqnum.
SELECT * INTO TABLE lt_lips_t
FROM lips
WHERE vbeln = i_vbeln.
IF lt_lips_t IS NOT INITIAL.
SELECT * INTO TABLE lt_ltap
FROM ltap
FOR ALL ENTRIES IN lt_lips_t
WHERE lgnum = lt_lips_t-lgnum
AND vbeln = lt_lips_t-vbeln
AND posnr = lt_lips_t-posnr
AND nltyp = 'Z99'
AND nlpla = 'Z99'.
SORT lt_ltap BY nlqnr DESCENDING.
* SELECT SINGLE MAX( nlqnr ) INTO lv_nlqnr
* FROM ltap
* WHERE lgnum = lv_lgnum.
* AND nltyp = 'Z99'
* AND nlpla = 'Z99'.
ENDIF.
LOOP AT lt_lips_t INTO ls_lips_t WHERE charg IS NOT INITIAL.
CLEAR: ltap_creat,
ls_ltap_creat,
hlp_tanum.
CALL FUNCTION 'ENQUEUE_EVVBLKE'
EXPORTING
vbeln = i_vbeln
EXCEPTIONS
foreign_lock = 2
system_failure = 3.
CALL FUNCTION 'L_TO_SET_SPECIAL'
EXPORTING
i_spezi = 'B'
i_vbeln = i_vbeln
EXCEPTIONS
call_forbidden = 1
input_wrong = 2
OTHERS = 3.
READ TABLE lt_ltap INTO ls_ltap WITH KEY vbeln = ls_lips_t-vbeln
posnr = ls_lips_t-posnr
nltyp = 'Z99'
nlpla = 'Z99'.
IF sy-subrc = 0.
* lv_index = lv_index + 1.
ls_ltap_creat-matnr = ls_ltap-matnr.
ls_ltap_creat-werks = ls_ltap-werks.
ls_ltap_creat-lgort = ls_ltap-lgort.
ls_ltap_creat-charg = ls_ltap-charg.
ls_ltap_creat-charg = ls_ltap-charg.
ls_ltap_creat-bestq = ls_ltap-bestq.
ls_ltap_creat-sobkz = ls_ltap-sobkz.
ls_ltap_creat-sonum = ls_ltap-sonum.
ls_ltap_creat-anfme = ls_ltap-nista.
ls_ltap_creat-altme = ls_ltap-meins.
CLEAR: lv_lqnum.
SELECT SINGLE lqnum INTO lv_lqnum
FROM lqua
WHERE lgnum = lv_lgnum
AND matnr = ls_ltap-matnr
AND werks = ls_ltap-werks
AND lgort = ls_ltap-lgort
AND charg = ls_ltap-charg
AND lgtyp = 'Z99'
AND lgpla = 'Z99'.
ls_ltap_creat-vlqnr = lv_lqnum.
* ls_ltap_creat-vlenr = ls_ltap-vlenr.
ls_ltap_creat-nlpla = ls_ltap-vlpla.
ls_ltap_creat-nppos = ls_ltap-nppos.
ls_ltap_creat-nltyp = ls_ltap-vltyp.
ls_ltap_creat-nlber = ls_ltap-vlber.
* ls_ltap_creat-ldest = ls_ltap-ldest.
* ls_ltap_creat-squit = 'X'.
ls_ltap_creat-posnr = ls_ltap-posnr.
APPEND ls_ltap_creat TO ltap_creat.
CLEAR: ls_ltap_creat.
CALL FUNCTION 'L_TO_CREATE_MULTIPLE'
EXPORTING
i_lgnum = lv_lgnum
i_bwlvs = '999'
* I_BETYP = ' '
* I_BENUM = ' '
* I_LZNUM = ' '
i_nidru = i_nidru
i_drukz = i_drukz
* I_UPDATE_TASK = ' '
i_commit_work = 'X'
* I_BNAME = SY-UNAME
* I_KOMPL = 'X'
* I_SOLEX = 0
* I_PERNR = 0
* I_MINWM = ' '
IMPORTING
e_tanum = hlp_tanum
TABLES
t_ltap_creat = ltap_creat[]
EXCEPTIONS
error_message = 99.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDIF.
IF hlp_tanum IS NOT INITIAL.
e_msg = '冲销成功'.
e_code = 'S'.
ELSE.
CLEAR: lv_text.
SELECT SINGLE text FROM t100 INTO lv_text
WHERE arbgb = sy-msgid AND msgnr = sy-msgno AND sprsl = sy-langu .
e_msg = lv_text.
e_code = 'E'.
ENDIF.
CALL FUNCTION 'L_TO_RESET_SPECIAL'.
CALL FUNCTION 'DEQUEUE_EVVBLKE'
EXPORTING
vbeln = i_vbeln.
ENDLOOP.
* CALL FUNCTION 'L_TO_CREATE_MULTIPLE'
* EXPORTING
* i_lgnum = lv_lgnum
* i_bwlvs = '999'
** I_BETYP = ' '
** I_BENUM = ' '
** I_LZNUM = ' '
* i_nidru = i_nidru
* i_drukz = i_drukz
** I_UPDATE_TASK = ' '
* i_commit_work = 'X'
** I_BNAME = SY-UNAME
** I_KOMPL = 'X'
** I_SOLEX = 0
** I_PERNR = 0
** I_MINWM = ' '
* IMPORTING
* e_tanum = hlp_tanum
* TABLES
* t_ltap_creat = ltap_creat[]
* EXCEPTIONS
* error_message = 99.
*
* IF sy-subrc <> 0.
** Implement suitable error handling here
* ENDIF.
* IF hlp_tanum IS NOT INITIAL.
* e_msg = '冲销成功'.
* e_code = 'S'.
* ELSE.
* CLEAR: lv_text.
* SELECT SINGLE text FROM t100 INTO lv_text
* WHERE arbgb = sy-msgid AND msgnr = sy-msgno AND sprsl = sy-langu .
* e_msg = lv_text.
* e_code = 'E'.
* ENDIF.
*
* CALL FUNCTION 'L_TO_RESET_SPECIAL'.
* CALL FUNCTION 'DEQUEUE_EVVBLKE'
* EXPORTING
* vbeln = i_vbeln.
ELSE.
CLEAR: lv_text.
SELECT SINGLE text FROM t100 INTO lv_text
WHERE arbgb = ls_emkpf-msgid AND msgnr = ls_emkpf-msgno AND sprsl = sy-langu .
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
e_msg = lv_text.
e_code = 'E'.
ENDIF.
ELSE.
e_msg = '交货单未过帐,请勿重复提交'.
e_code = 'E'.
ENDIF.
注意: 如果在调用BAPI:WS_REVERSE_GOODS_ISSUE做VL09冲销,然后再调函数L_TO_SET_SPECIAL和L_TO_CREATE_MULTIPLE去做LT0G冲销的时候,会提示报错[VL 216: 项目 & 不存在]
如果遇到以上报错的时候,需要将VL09采用BDC的方式处理,然后LT0G使用函数进行处理