FUNCTION ZRFC_CHECK_ZPB2.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" REFERENCE(IP_VBELN) TYPE VBELN OPTIONAL
*" REFERENCE(LIKP) LIKE LIKP STRUCTURE LIKP OPTIONAL
*" EXPORTING
*" REFERENCE(EX_SUBRC) TYPE SY-SUBRC
*" TABLES
*" LIPS STRUCTURE LIPS OPTIONAL
*" ET_LOG STRUCTURE BAPIRET2 OPTIONAL
*"----------------------------------------------------------------------
INCLUDE ZMV50AFZ1_VAR1.
DATA: LS_LIKP LIKE LIKP.
DATA: V_KNUMH TYPE KNUMH.
DATA: V_KBETR TYPE KBETR_KOND.
DATA: V_KPEIN TYPE KPEIN.
DATA: V_KONWA TYPE KONWA.
DATA: V_KP TYPE P LENGTH 16 DECIMALS 6.
DATA: DTAX TYPE P LENGTH 16 DECIMALS 6.
DATA: V_BUKRS LIKE LIKP-KUNIV.
CLEAR: ET_LOG,ET_LOG[].
EX_SUBRC = 0.
IF LIKP IS NOT INITIAL.
MOVE LIKP TO LS_LIKP.
ENDIF.
IF IP_VBELN IS NOT INITIAL.
SELECT SINGLE VBELN VKORG ERDAT KUNIV INTO CORRESPONDING FIELDS OF LS_LIKP
FROM LIKP WHERE VBELN = IP_VBELN
.
ENDIF.
CHECK LS_LIKP IS NOT INITIAL.
CHECK LS_LIKP-VKORG IN S_VKORG[] AND LS_LIKP-KUNIV IN S_KUNIV[].
MOVE LS_LIKP-KUNIV TO V_BUKRS.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = V_BUKRS
IMPORTING
OUTPUT = V_BUKRS.
IF LIPS[] IS INITIAL.
SELECT VBELN POSNR MATNR WERKS LFIMG
INTO CORRESPONDING FIELDS OF TABLE LIPS FROM LIPS
WHERE VBELN = IP_VBELN.
ENDIF.
LOOP AT LIPS WHERE VBELN = LS_LIKP-VBELN AND WERKS IN S_WERKS AND LFIMG > 0.
CLEAR V_KNUMH .
SELECT SINGLE KNUMH INTO V_KNUMH FROM A055
WHERE VKORGAU = LS_LIKP-VKORG
AND WERKS = LIPS-WERKS
AND MATNR = LIPS-MATNR
AND DATBI >= LS_LIKP-ERDAT
AND KSCHL = 'ZPB2'.
CLEAR :V_KBETR,V_KPEIN,V_KONWA.
SELECT SINGLE KBETR KPEIN KONWA INTO (V_KBETR,V_KPEIN,V_KONWA) FROM KONP WHERE KNUMH = V_KNUMH
AND LOEVM_KO <> 'X'
.
IF V_KBETR <= 0.
EX_SUBRC = 1.
ET_LOG-TYPE = 'E'.
ET_LOG-ID = LS_LIKP-VBELN.
ET_LOG-MESSAGE = '不存在ZPB2价格'.
CONCATENATE LS_LIKP-VBELN '~' LIPS-MATNR ET_LOG-MESSAGE INTO ET_LOG-MESSAGE.
ET_LOG-LOG_NO = LS_LIKP-VBELN.
APPEND ET_LOG.
ENDIF.
ENDLOOP.
IF SY-SUBRC > 0.
CHECK EX_SUBRC = 2.
ET_LOG-TYPE = 'E'.
ET_LOG-ID = LS_LIKP-VBELN.
ET_LOG-MESSAGE = '参数错误'.
CONCATENATE LS_LIKP-VBELN '~' LIPS-MATNR ET_LOG-MESSAGE INTO ET_LOG-MESSAGE.
ET_LOG-LOG_NO = IP_VBELN.
APPEND ET_LOG.
ENDIF.
CHECK EX_SUBRC = 0.
ET_LOG-TYPE = 'I'.
ET_LOG-ID = IP_VBELN.
ET_LOG-MESSAGE = '检查成功'.
* CONCATENATE IP_VBELN '~' LIPS-MATNR ET_LOG-MESSAGE INTO ET_LOG-MESSAGE.
ET_LOG-LOG_NO = LS_LIKP-VBELN.
APPEND ET_LOG.
ENDFUNCTION.