变量SQL
IF ESSR_REL-EBELN NE ‘’ AND ESSR_REL-LIFNR EQ ‘’.
SQL = ‘ESSR_REL~EBELN EQ ESSR_REL-EBELN’.
ELSEIF ESSR_REL-EBELN EQ ‘’ AND ESSR_REL-LIFNR NE ‘’.
SQL = ‘ESSR_REL~LIFNR EQ ESSR_REL-LIFNR’.
ELSEIF ESSR_REL-EBELN NE ‘’ AND ESSR_REL-LIFNR NE ‘’.
SQL = ‘ESSR_REL~LIFNR EQ ESSR_REL-LIFNR AND ESSR_REL~EBELN EQ ESSR_REL-EBELN’.
ENDIF.
变量SQL1
IF ESSR_REL-FRGSX = ‘01’.
SQL1 = ‘ESSR_REL~FRGZU = ‘’’’ AND ESSR_REL~FRGSX = ‘‘01’’ '.
ELSEIF ESSR_REL-FRGSX = ‘02’.
SQL1 = ‘(( ESSR_REL~FRGSX = ‘‘01’’ AND ESSR_REL~FRGZU = ‘‘X’’ ) OR ESSR_REL~FRGSX = ‘‘02’’ )’.
ENDIF.
SELECT ESSR_REL~EBELN "采购订单号
ESSR_REL~EBELP "采购订单行号
ESSR_REL~LBLNI "服务条目号
ESSR_REL~BRTWR "合同金额
ESSR_REL~NETWR "本次确认金额
ESSR_REL~LWERT "本次确认总额
ESSR_REL~TXZ01 "服务确认说明
ESSR_REL~BSART "采购订单类型
LFA1~NAME1 "供应商
MSELL~SUB_PACKNO
EKKN~NPLNR
EKKN~SAKTO
EKKN~KOSTL
EKKN~PS_PSP_PNR AS PSPNR
EKKN~AUFNR
INTO CORRESPONDING FIELDS OF TABLE IT_ESSR
FROM ESSR_REL
LEFT JOIN LFA1 ON LFA1~LIFNR = ESSR_REL~LIFNR
LEFT JOIN ESLL AS MSELL ON MSELL~PACKNO = ESSR_REL~PACKNO_P
LEFT JOIN EKKN ON EKKN~EBELP = ESSR_REL~EBELP
AND EKKN~EBELN = ESSR_REL~EBELN
WHERE (SQL)
AND (SQL1)
AND ESSR_REL~FRGGR = ‘SR’
AND ESSR_REL~KZABN = ‘’ AND ESSR_REL~F_LOCK = ‘’
AND ESSR_REL~FRGRL = ‘X’ AND ESSR_REL~PSTYP = ‘9’
AND ESSR_REL~LOEKZ = ‘’ AND ESSR_REL~LOEKZ_H = ‘’
AND ESSR_REL~LOEKZ_P = ‘’
.
SORT IT_ESSR BY EBELN EBELP LBLNI BRTWR NETWR LWERT TXZ01 NAME1.
DELETE ADJACENT DUPLICATES FROM IT_ESSR COMPARING EBELN EBELP LBLNI BRTWR NETWR LWERT TXZ01 NAME1.