某项目中,根据客户需求,在VL02N发货过账之前,需要先更改发货单行项目的数量和序列号,下面程序一是VL02N发货过账并更改拣配数量的函数,程序二是程序一的FUNCTION-POOL ,里面有定义的全局变量以及更改发货单行项目数量和序列号的子程序,希望对用到的兄弟有帮助。
程序一:
FUNCTION ZWMS_VL02N.
*"----------------------------------------------------------------------
*"*"Local interface:
*" TABLES
*" INPUT STRUCTURE ZWMS_VL02N_INPUT OPTIONAL
*" INPUT_SN STRUCTURE ZWMS_VL02N_INPUT_SN OPTIONAL
*" INPUT_QN STRUCTURE ZWMS_INPUT_QN OPTIONAL
*" OUTPUT STRUCTURE ZWMS_VL02N_OUTPUT OPTIONAL
*"----------------------------------------------------------------------
DATA:I_VBKOK TYPE VBKOK.
DATA:BEGIN OF I_VBPOK_TAB OCCURS 12.
INCLUDE STRUCTURE VBPOK.
DATA:END OF I_VBPOK_TAB.
DATA:I_EF_ERROR_ANY_0 TYPE XFELD.
DATA:P_FLAG(1),
P_MESSAGE(200).
DATA:G_LIKP LIKE LIKP.
DATA:G_LIPS LIKE LIPS.
DATA GV_14(14) TYPE C.
DATA:P_VBELN LIKE LIKP-VBELN.
DATA:I_PROTT TYPE PROTT OCCURS 0 WITH HEADER LINE .
FREE MEMORY ID 'INPUT'.
EXPORT INPUT TO MEMORY ID 'INPUT'.
FREE MEMORY ID 'INPUT_SN'.
EXPORT INPUT_SN TO MEMORY ID 'INPUT_SN'.
CLEAR P_FLAG.CLEAR P_MESSAGE.
PERFORM FRM_CHANGE_DELIVERY CHANGING P_FLAG
P_MESSAGE.
IF P_FLAG = 'E'.
REFRESH OUTPUT.
CLEAR OUTPUT.
OUTPUT-FLAG = 'E'.
OUTPUT-NOTES = P_MESSAGE.
APPEND OUTPUT.
CLEAR OUTPUT.
ELSE.
CLEAR P_VBELN.
CLEAR INPUT.
READ TABLE INPUT INDEX 1.
IF SY-SUBRC EQ 0.
P_VBELN = INPUT-VBELN.
ENDIF.
CLEAR I_VBKOK.
CLEAR I_EF_ERROR_ANY_0.
MOVE-CORRESPONDING INPUT TO OUTPUT.
* ---交货抬头数据
I_VBKOK-VBELN_VL = P_VBELN. "DELIVERY NUMBER
I_VBKOK-WABUC = 'X'. "AUTOMATIC PGI
I_VBKOK-WADAT_IST = SY-DATUM.
LOOP AT INPUT.
SELECT SINGLE * INTO G_LIPS FROM LIPS
WHERE VBELN = INPUT-VBELN
AND POSNR = INPUT-POSNR.
I_VBPOK_TAB-VBELN_VL = G_LIPS-VBELN. "DELIVERY NUMBER
I_VBPOK_TAB-POSNR_VL = G_LIPS-POSNR.
I_VBPOK_TAB-VBELN = G_LIPS-VBELN.
I_VBPOK_TAB-POSNN = G_LIPS-POSNR.
I_VBPOK_TAB-MATNR = G_LIPS-MATNR.
I_VBPOK_TAB-LFIMG = INPUT-LFIMG.
I_VBPOK_TAB-CHARG = INPUT-CHARG.
I_VBPOK_TAB-LGORT = INPUT-LGORT.
GV_14 = INPUT-LFIMG.
CONDENSE GV_14.
I_VBPOK_TAB-PIKMG = GV_14 .
APPEND I_VBPOK_TAB.
ENDLOOP.
* ---发货过账
REFRESH I_PROTT.
CLEAR I_PROTT.
CALL FUNCTION 'WS_DELIVERY_UPDATE'
EXPORTING
VBKOK_WA = I_VBKOK
COMMIT = 'X'
DELIVERY = P_VBELN
UPDATE_PICKING = 'X'
IMPORTING
EF_ERROR_ANY_0 = I_EF_ERROR_ANY_0
TABLES
VBPOK_TAB = I_VBPOK_TAB
PROT = I_PROTT
EXCEPTIONS
ERROR_MESSAGE = 1
OTHERS = 2.
IF I_EF_ERROR_ANY_0 = 'X'.
LOOP AT I_PROTT WHERE MSGTY = 'E'.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
MSGID = I_PROTT-MSGID
MSGNR = I_PROTT-MSGNO
MSGV1 = I_PROTT-MSGV1
MSGV2 = I_PROTT-MSGV2
MSGV3 = I_PROTT-MSGV3
MSGV4 = I_PROTT-MSGV4
IMPORTING
MESSAGE_TEXT_OUTPUT = OUTPUT-NOTES.
ENDLOOP.
OUTPUT-FLAG = 'E'.
CONCATENATE '发货过账失败:' OUTPUT-NOTES INTO OUTPUT-NOTES.
ELSE.
SELECT MAX( VBELN )
INTO OUTPUT-MBLNR
FROM VBFA
WHERE VBELV = P_VBELN
AND VBTYP_N = 'R'.
IF OUTPUT-MBLNR <> ''.
OUTPUT-FLAG = 'S'.
OUTPUT-NOTES = '发货过账成功!'.
"更新D类物资库存(不合格品库更新)
CALL FUNCTION 'ZWMS_UNQUALIF_DTYPE_UPDATE'
EXPORTING
QNDEX = '1000000000'
TABLES
INPUT = INPUT_QN.
ELSE.
OUTPUT-FLAG = 'E'.
OUTPUT-NOTES = '发货过账失败!'.
ENDIF.
ENDIF.
APPEND OUTPUT.
CLEAR OUTPUT.
ENDIF.
*--------------------------日志信息start--------------------------
*日志信息定义
DATA:LOG1 TYPE TABLE OF ZWMS_LOG013_01 WITH HEADER LINE,
LOG2 TYPE TABLE OF ZWMS_LOG013_02 WITH HEADER LINE,
LOG3 TYPE TABLE OF ZWMS_LOG013_03 WITH HEADER LINE,
LOG4 TYPE TABLE OF ZWMS_LOG013_04 WITH HEADER LINE.
DATA:LV_FKEY(100),
LV_FINDX TYPE I,
LV_UUID TYPE SYSUUID-X,
TM_UUID(100).
CLEAR LV_UUID.CLEAR TM_UUID.
CALL FUNCTION 'SYSTEM_UUID_CREATE'
IMPORTING
UUID = LV_UUID.
TM_UUID = LV_UUID.
CLEAR LV_FKEY.
CONCATENATE SY-UNAME SY-DATUM SY-UZEIT TM_UUID INTO LV_FKEY.
CLEAR LV_FINDX.
REFRESH LOG1.
CLEAR LOG1.
LOOP AT INPUT.
LV_FINDX = LV_FINDX + 1.
MOVE-CORRESPONDING INPUT TO LOG1.
LOG1-FKEY = LV_FKEY.
LOG1-FINDX = LV_FINDX.
APPEND LOG1.
CLEAR LOG1.
ENDLOOP.
CLEAR LV_FINDX.
REFRESH LOG2.
CLEAR LOG2.
LOOP AT INPUT_SN.
LV_FINDX = LV_FINDX + 1.
MOVE-CORRESPONDING INPUT_SN TO LOG2.
LOG2-FKEY = LV_FKEY.
LOG2-FINDX = LV_FINDX.
APPEND LOG2.
CLEAR LOG2.
ENDLOOP.
CLEAR LV_FINDX.
REFRESH LOG3.
CLEAR LOG3.
LOOP AT OUTPUT.
LV_FINDX = LV_FINDX + 1.
MOVE-CORRESPONDING OUTPUT TO LOG3.
LOG3-FKEY = LV_FKEY.
LOG3-FINDX = LV_FINDX.
APPEND LOG3.
CLEAR LOG3.
ENDLOOP.
CLEAR LV_FINDX.
REFRESH LOG4.
CLEAR LOG4.
LOOP AT INPUT_QN.
LV_FINDX = LV_FINDX + 1.
MOVE-CORRESPONDING INPUT_QN TO LOG4.
LOG4-FKEY = LV_FKEY.
LOG4-FINDX = LV_FINDX.
APPEND LOG4.
CLEAR LOG4.
ENDLOOP.
IF LOG1[] IS NOT INITIAL.
MODIFY ZWMS_LOG013_01 FROM TABLE LOG1.
ENDIF.
IF LOG2[] IS NOT INITIAL.
MODIFY ZWMS_LOG013_02 FROM TABLE LOG2.
ENDIF.
IF LOG3[] IS NOT INITIAL.
MODIFY ZWMS_LOG013_03 FROM TABLE LOG3.
ENDIF.
IF LOG4[] IS NOT INITIAL.
MODIFY ZWMS_LOG013_04 FROM TABLE LOG4.
ENDIF.
*--------------------------日志信息end--------------------------
ENDFUNCTION.
程序二:
FUNCTION-POOL ZWMS_VL02N. "MESSAGE-ID ..
函数用到的输入参数(INPUT、INPUT_SN、INPUT_QN)、输出参数(OUTPUT)参数如下图: