[ABAP] VL09交货单过账冲销BAPI:WS_REVERSE_GOODS_ISSUE的BUG解决

最近在做一个需求使用VL09交货单过账冲销BAPI:WS_REVERSE_GOODS_ISSUE 做交货单过账冲销时程序总是报VL302消息(交货 不存在);Debug程序发现BAPI行147语句“ PERFORM beleg_lesen(sapmv50a).”调用了sapmv50a的子程序beleg_lesen,在调用之前likp-vbeln有值,调用后值被清空,单独写测试程序执行并无此问题。怀疑是因为程序之前有调用交货单修改BAPI:BAPI_OUTB_DELIVERY_CHANGE也有调用sapmv50a程序的部分,缓存未清空。查找初始化INITIALIZATION函数未找到,使用关键字查询NOTE未查到相关解决方案,使用内存传值的方式增强写入likp-vbeln字段值执行程序依然不能实现功能。最后使用SUBMIT调用外部程序的方式解决。代码如下,欢迎指正。

功能程序代码截取:

   "传入交货单值
    EXPORT lv_vbeln = ls_likp-vbeln TO SHARED BUFFER indx(dn) ID 'ZDN'.
    SUBMIT Z_vl09 AND RETURN.    "调用外部VL09冲销程序

    CLEAR: ls_emkpf.
    "获取执行结果
    IMPORT ls_emkpf FROM SHARED BUFFER indx(dn) ID 'ZDNC'.
    DELETE FROM SHARED BUFFER indx(dn) ID 'ZMM004_DNC'.
    IF ls_emkpf-mblnr IS NOT INITIAL.

    ELSE.
        lv_mess = '交货单' && ls_likp-vbeln && '冲销失败!' && lv_mess .
    ENDIF.

外部VL09冲销交货单过账程序:

*&---------------------------------------------------------------------*
*& Report Z_vl09 
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT Z_vl09 .

DATA: ls_emkpf TYPE emkpf.
DATA: lt_return TYPE TABLE OF mesg WITH HEADER LINE.
DATA: lv_vbeln TYPE likp-vbeln.

CLEAR: lv_vbeln.
IMPORT lv_vbeln FROM SHARED BUFFER indx(dn) ID 'ZDN'.
IF lv_vbeln IS NOT INITIAL.
  CLEAR: lt_return[],ls_emkpf.
  CALL FUNCTION 'WS_REVERSE_GOODS_ISSUE'
    EXPORTING
      i_vbeln                   = lv_vbeln
      i_budat                   = sy-datum
      i_tcode                   = 'VL09'
      i_vbtyp                   = 'J'
    IMPORTING
      es_emkpf                  = ls_emkpf
    TABLES
      t_mesg                    = lt_return
    EXCEPTIONS
      error_reverse_goods_issue = 1
      error_message             = 99
      OTHERS                    = 2.
  EXPORT ls_emkpf = ls_emkpf TO SHARED BUFFER indx(dn) ID 'ZDNC'.
  DELETE FROM SHARED BUFFER indx(dn) ID 'ZDN'.
  IF ls_emkpf-mblnr IS NOT INITIAL.
    COMMIT WORK AND WAIT.
  ELSE.
    ROLLBACK WORK.
  ENDIF.
ENDIF.

你可能感兴趣的:(abap,sap)