VL03N查看交货单
交货数量为5,单位是CAR
查看已经开票凭证流:
直接看表 VBFA
开票84 单位EA
冲销76 单位EA
已开 84 - 76 = 8 EA
而咱们看交货单的时候,交货单单位 CAR.
单位转换:
交货单 剩余开票数量 3 CAR,VF01查看
现在要做交货单开票的批导,输入交货单,物料和数量。
那现在为了防止输入数量比未开票数量多,需要校验一下。
获取交货单对应的未开票数量demo函数:
FUNCTION ZSD_GET_VF01_LFIMG.
*"----------------------------------------------------------------------
*"*"本地接口:
*" TABLES
*" CT_DATA STRUCTURE ZSDS_VF01
*"----------------------------------------------------------------------
DATA:LV_MEINS TYPE MEINS.
DATA:LV_LFIMG TYPE EKPO-MENGE.
DATA:LV_LFIMG_VL TYPE EKPO-MENGE.
DATA:LT_LIPS TYPE TABLE OF LIPS.
DATA:LS_LIPS TYPE LIPS.
DATA:LT_VBFA TYPE TABLE OF VBFA.
DATA:LS_VBFA TYPE VBFA.
FIELD-SYMBOLS <LS_DATA> LIKE LINE OF CT_DATA.
CHECK CT_DATA[] IS NOT INITIAL.
SELECT * FROM LIPS INTO TABLE LT_LIPS
FOR ALL ENTRIES IN CT_DATA
WHERE VBELN = CT_DATA-VBELN.
SELECT * FROM VBFA INTO TABLE LT_VBFA
FOR ALL ENTRIES IN CT_DATA
WHERE VBELV = CT_DATA-VBELN
AND VBTYP_N IN ( 'M','N' )
AND VBTYP_V = 'J'.
SORT LT_LIPS BY VBELN POSNR.
LOOP AT CT_DATA ASSIGNING <LS_DATA>.
CLEAR LS_LIPS.
READ TABLE LT_LIPS INTO LS_LIPS
WITH KEY
VBELN = <LS_DATA>-VBELN
POSNR = <LS_DATA>-POSNR BINARY SEARCH.
<LS_DATA>-MATNR = LS_LIPS-MATNR.
<LS_DATA>-LFIMG = LS_LIPS-LFIMG.
<LS_DATA>-MEINS = LS_LIPS-MEINS.
<LS_DATA>-VRKME = LS_LIPS-VRKME.
"检查已经开票数量
CLEAR LV_MEINS.
CLEAR LV_LFIMG.
CLEAR LV_LFIMG_VL.
LOOP AT LT_VBFA INTO LS_VBFA WHERE
VBELV = <LS_DATA>-VBELN AND
POSNV = <LS_DATA>-POSNR
.
IF LS_VBFA-VBTYP_N = 'M'."发票
LV_LFIMG = LV_LFIMG + LS_VBFA-RFMNG.
ELSEIF LS_VBFA-VBTYP_N = 'N'. "冲销
LV_LFIMG = LV_LFIMG - LS_VBFA-RFMNG.
ENDIF.
LV_MEINS = LS_VBFA-MEINS.
ENDLOOP.
"开票单位跟订单单位转换
CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
EXPORTING
I_MATNR = <LS_DATA>-MATNR
I_IN_ME = LV_MEINS
I_OUT_ME = <LS_DATA>-VRKME
I_MENGE = LV_LFIMG
IMPORTING
E_MENGE = LV_LFIMG_VL
EXCEPTIONS
ERROR_IN_APPLICATION = 1
ERROR = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
ENDIF.
<LS_DATA>-LFIMG_POST = LV_LFIMG_VL.
<LS_DATA>-LFIMG_OPEN = <LS_DATA>-LFIMG - <LS_DATA>-LFIMG_POST .
ENDLOOP.
ENDFUNCTION.